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

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

[elpa] externals/tempel b45dcc25ac 3/4: Overhaul tempel-key: Accepts bot


From: ELPA Syncer
Subject: [elpa] externals/tempel b45dcc25ac 3/4: Overhaul tempel-key: Accepts both name and template
Date: Mon, 10 Jan 2022 12:57:45 -0500 (EST)

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

    Overhaul tempel-key: Accepts both name and template
---
 tempel.el | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/tempel.el b/tempel.el
index 7281ba0981..5d7ff699f1 100644
--- a/tempel.el
+++ b/tempel.el
@@ -533,15 +533,20 @@ If called interactively, select a template with 
`completing-read'."
    (tempel--region)))
 
 ;;;###autoload
-(defmacro tempel-key (key name &optional map)
-  "Bind KEY to NAME in MAP."
-  (let ((cmd (intern (format "tempel-insert-%s" name))))
-    `(progn
-       (defun ,cmd ()
-         ,(format "Insert template %s in the current buffer." name)
-         (interactive)
-         (tempel-insert ',name))
-       (define-key ,(or map 'global-map) ,(kbd key) #',cmd))))
+(defmacro tempel-key (key template-or-name &optional map)
+  "Bind KEY to TEMPLATE-OR-NAME in MAP."
+  `(define-key ,(or map 'global-map) ,(kbd key)
+     ,(if (consp template-or-name)
+          `(lambda ()
+             (interactive)
+             (tempel-insert ',template-or-name))
+        (let ((cmd (intern (format "tempel-insert-%s" template-or-name))))
+          `(prog1 ',cmd
+             (defun ,cmd ()
+               ,(format "Insert template %s in the current buffer."
+                        template-or-name)
+               (interactive)
+               (tempel-insert ',template-or-name)))))))
 
 (defun tempel--abbrev-hook (name template)
   "Abbreviation expansion hook for TEMPLATE with NAME."



reply via email to

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