]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/tempo.el (tempo-insert): Use `pcase` and `dolist`
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 8 Sep 2023 23:41:28 +0000 (19:41 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 8 Sep 2023 23:41:28 +0000 (19:41 -0400)
lisp/tempo.el

index 98521c54eb9618cb7f7333d6305fae328ff93d75..45dc24dcc9710258410b059b313e65c3ae52987a 100644 (file)
@@ -321,72 +321,57 @@ elements are replaced with the current region.
 
 See documentation for `tempo-define-template' for the kind of elements
 possible."
-  (cond ((stringp element) (tempo-process-and-insert-string element))
-       ((and (consp element)
-             (eq (car element) 'p)) (tempo-insert-prompt-compat
-                                     (cdr element)))
-       ((and (consp element)
-             (eq (car element) 'P)) (let ((tempo-interactive t))
-                                      (tempo-insert-prompt-compat
-                                       (cdr element))))
-;;;    ((and (consp element)
-;;;          (eq (car element) 'v)) (tempo-save-named
-;;;                                  (nth 1 element)
-;;;                                  nil
-;;;                                  (nth 2 element)))
-       ((and (consp element)
-             (eq (car element) 'r)) (if on-region
-                                        (goto-char tempo-region-stop)
-                                      (tempo-insert-prompt-compat
-                                       (cdr element))))
-        ((and (consp element)
-              (eq (car element) 'r>)) (if on-region
-                                          (progn
-                                            (goto-char tempo-region-stop)
-                                            (indent-region (mark) (point) nil))
-                                        (tempo-insert-prompt-compat
-                                         (cdr element))))
-       ((and (consp element)
-             (eq (car element) 's)) (tempo-insert-named (car (cdr element))))
-       ((and (consp element)
-              (eq (car element) 'l)) (mapcar (lambda (elt)
-                                               (tempo-insert elt on-region))
-                                            (cdr element)))
-       ((eq element 'p) (tempo-insert-mark (point-marker)))
-       ((eq element 'r) (if on-region
-                            (goto-char tempo-region-stop)
-                          (tempo-insert-mark (point-marker))))
-       ((eq element 'r>) (if on-region
-                             (progn
-                               (goto-char tempo-region-stop)
-                               (indent-region (mark) (point) nil))
-                           (tempo-insert-mark (point-marker))))
-       ((eq element '>) (indent-according-to-mode))
-       ((eq element '&) (if (not (or (= (current-column) 0)
-                                     (save-excursion
-                                       (re-search-backward
-                                        "^\\s-*\\=" nil t))))
-                            (insert "\n")))
-       ((eq element '%) (if (not (or (eolp)
-                                     (save-excursion
-                                       (re-search-forward
-                                        "\\=\\s-*$" nil t))))
-                            (insert "\n")))
-       ((eq element 'n) (insert "\n"))
-       ((eq element 'n>) (insert "\n") (indent-according-to-mode))
-       ;; Bug: If the 'o is the first element in a template, strange
-       ;; things can happen when the template is inserted at the
-       ;; beginning of a line.
-       ((eq element 'o) (if (not (or on-region
-                                     (eolp)
-                                     (save-excursion
-                                       (re-search-forward
-                                        "\\=\\s-*$" nil t))))
-                            (open-line 1)))
-       ((null element))
-       (t (tempo-insert (or (tempo-is-user-element element)
-                            (eval element t))
-                        on-region))))
+  (pcase element
+    ((pred stringp) (tempo-process-and-insert-string element))
+    (`(p . ,rest) (tempo-insert-prompt-compat rest))
+    (`(P . ,rest) (let ((tempo-interactive t))
+                    (tempo-insert-prompt-compat rest)))
+    ;; (`(v ,name ,data) (tempo-save-named name nil data))
+    (`(r . ,rest) (if on-region
+                     (goto-char tempo-region-stop)
+                   (tempo-insert-prompt-compat rest)))
+    (`(r> . ,rest) (if on-region
+                       (progn
+                         (goto-char tempo-region-stop)
+                         (indent-region (mark) (point) nil))
+                       (tempo-insert-prompt-compat rest)))
+    (`(s ,name) (tempo-insert-named name))
+    (`(l . ,rest) (dolist (elt rest) (tempo-insert elt on-region)))
+    ('p (tempo-insert-mark (point-marker)))
+    ('r (if on-region
+           (goto-char tempo-region-stop)
+         (tempo-insert-mark (point-marker))))
+    ('r> (if on-region
+            (progn
+              (goto-char tempo-region-stop)
+              (indent-region (mark) (point) nil))
+          (tempo-insert-mark (point-marker))))
+    ('> (indent-according-to-mode))
+    ('& (if (not (or (= (current-column) 0)
+                    (save-excursion
+                      (re-search-backward
+                       "^\\s-*\\=" nil t))))
+           (insert "\n")))
+    ('% (if (not (or (eolp)
+                    (save-excursion
+                      (re-search-forward
+                       "\\=\\s-*$" nil t))))
+           (insert "\n")))
+    ('n (insert "\n"))
+    ('n> (insert "\n") (indent-according-to-mode))
+    ;; Bug: If the 'o is the first element in a template, strange
+    ;; things can happen when the template is inserted at the
+    ;; beginning of a line.
+    ('o (if (not (or on-region
+                    (eolp)
+                    (save-excursion
+                      (re-search-forward
+                       "\\=\\s-*$" nil t))))
+           (open-line 1)))
+    ('nil nil)
+    (_ (tempo-insert (or (tempo-is-user-element element)
+                        (eval element t))
+                    on-region))))
 
 ;;;
 ;;; tempo-insert-prompt