emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/tempel 8afb9dc566 1/2: Support list of multiple modes i


From: ELPA Syncer
Subject: [elpa] externals/tempel 8afb9dc566 1/2: Support list of multiple modes in templates file (Fix #30)
Date: Thu, 3 Feb 2022 14:57:46 -0500 (EST)

branch: externals/tempel
commit 8afb9dc566d5690c153263323918c3b66ca074f9
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Support list of multiple modes in templates file (Fix #30)
    
    mode1 mode2
    (template1 ...)
    (template2 ...)
---
 README.org |  4 ++++
 tempel.el  | 25 +++++++++++++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/README.org b/README.org
index b71fdc481b..611fde4eab 100644
--- a/README.org
+++ b/README.org
@@ -118,6 +118,10 @@ the template. Behind the name, the Tempo syntax elements 
follow.
   (enumerate "\\begin{enumerate}\n\\item " r> n> "\\end{enumerate}")
   (itemize "\\begin{itemize}\n\\item " r> n> "\\end{itemize}")
 
+  lisp-mode emacs-lisp-mode ;; Specify multiple modes
+
+  (lambda "(lambda (" p ")" n> r> ")")
+
   emacs-lisp-mode
 
   (lambda "(lambda (" p ")" n> r> ")")
diff --git a/tempel.el b/tempel.el
index ee8e8b8b93..714fc9d2b6 100644
--- a/tempel.el
+++ b/tempel.el
@@ -360,13 +360,15 @@ PROMPT is the optional prompt/default value."
     (goto-char (point-min))
     (let ((data (read (current-buffer))) result)
       (while data
-        (let ((mode (pop data)) plist templates)
+        (let (modes plist templates)
+          (while (and (symbolp (car data)) (not (keywordp (car data))))
+            (push (pop data) modes))
           (while (keywordp (car data))
             (push (pop data) plist)
             (push (pop data) plist))
           (while (consp (car data))
             (push (pop data) templates))
-          (push `(,mode ,(nreverse plist) . ,(nreverse templates)) result)))
+          (push `(,modes ,(nreverse plist) . ,(nreverse templates)) result)))
       result)))
 
 (defun tempel-file-templates ()
@@ -377,14 +379,17 @@ PROMPT is the optional prompt/default value."
     (unless (equal tempel--file-modified mod)
       (setq tempel--file-templates (tempel--file-read tempel-file)
             tempel--file-modified mod)))
-  (cl-loop for (mode plist . templates) in tempel--file-templates
-           if (and (or (derived-mode-p mode) (eq mode #'fundamental-mode))
-                   (or (not (plist-member plist :condition))
-                       (save-excursion
-                         (save-restriction
-                           (save-match-data
-                             (eval (plist-get plist :condition) 'lexical))))))
-           append templates))
+  (cl-loop
+   for (modes plist . templates) in tempel--file-templates
+   if (and
+       (cl-loop for m in modes
+                thereis (or (derived-mode-p m) (eq m #'fundamental-mode)))
+       (or (not (plist-member plist :condition))
+           (save-excursion
+             (save-restriction
+               (save-match-data
+                 (eval (plist-get plist :condition) 'lexical))))))
+   append templates))
 
 (defun tempel--templates ()
   "Return templates for current mode."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]