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

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

[elpa] externals/tempel c11044954a 1/2: Add support for template conditi


From: ELPA Syncer
Subject: [elpa] externals/tempel c11044954a 1/2: Add support for template conditions (Fix #21)
Date: Sun, 16 Jan 2022 15:57:47 -0500 (EST)

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

    Add support for template conditions (Fix #21)
---
 README.org | 13 +++++++++----
 tempel.el  | 23 ++++++++++++++---------
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/README.org b/README.org
index 339523fc6e..37ea2f79b3 100644
--- a/README.org
+++ b/README.org
@@ -92,10 +92,10 @@ In the following we show an example configuration, which 
relies on on
 * Template file format
 
 The templates are defined in a Lisp file which is stored by default in the
-~user-emacs-directory~ (=~/.config/emacs/templates=). The templates are 
written as
-lists in the concise form of the Emacs Tempo syntax. The first element of the
-list is the name of the template. Behind the name, the Tempo syntax elements
-follow.
+~user-emacs-directory~ (=~/.config/emacs/templates=). The templates are 
grouped by
+major mode with an optional ~:condition~. Each template is a list in the 
concise
+form of the Emacs Tempo syntax. The first element of each list is the name of
+the template. Behind the name, the Tempo syntax elements follow.
 
 #+begin_src emacs-lisp
   ;; -*- mode: lisp -*-
@@ -149,6 +149,11 @@ follow.
 
   (class "public class " (p (file-name-base (or (buffer-file-name) 
(buffer-name)))) " {" n> r> n "}")
 
+  c-mode :condition (bolp)
+
+  (inc "#include <" (p (concat (file-name-base (or (buffer-file-name) 
(buffer-name))) ".h")) ">")
+  (incc "#include \"" (p (concat (file-name-base (or (buffer-file-name) 
(buffer-name))) ".h")) "\"")
+
   org-mode
 
   (title "#+title: " p n "#+author: Daniel Mendler" n "#+language: en" n n)
diff --git a/tempel.el b/tempel.el
index 038e5b9e27..3a056f2325 100644
--- a/tempel.el
+++ b/tempel.el
@@ -359,12 +359,15 @@ PROMPT is the optional prompt/default value."
     (goto-char (point-max))
     (insert "\n)")
     (goto-char (point-min))
-    (let ((templates (read (current-buffer))) result)
-      (while (and templates (symbolp (car templates)))
-        (let ((mode (pop templates)) list)
-          (while (and templates (consp (car templates)))
-            (push (pop templates) list))
-          (push (cons mode (nreverse list)) result)))
+    (let ((data (read (current-buffer))) result)
+      (while data
+        (let ((mode (pop data)) plist templates)
+          (while (keywordp (car data))
+            (push (pop data) plist)
+            (push (pop data) plist))
+          (while (consp (car data))
+            (push (pop data) templates))
+          (push (list mode (nreverse plist) (nreverse templates)) result)))
       result)))
 
 (defun tempel-file-templates ()
@@ -375,9 +378,11 @@ 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 x in tempel--file-templates
-           if (or (derived-mode-p (car x)) (eq (car x) 'fundamental-mode))
-           append (cdr x)))
+  (cl-loop for (mode plist templates) in tempel--file-templates
+           if (or (derived-mode-p mode) (eq mode #'fundamental-mode))
+           if (or (not (plist-member plist :condition))
+                  (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]