[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel e4839df533 53/82: Add temple-key
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel e4839df533 53/82: Add temple-key |
Date: |
Sun, 9 Jan 2022 20:58:44 -0500 (EST) |
branch: externals/tempel
commit e4839df53314ff0e4f89c7724d8a4239e359938f
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add temple-key
See #8
---
tempel.el | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/tempel.el b/tempel.el
index aef2a72c46..b692a4972d 100644
--- a/tempel.el
+++ b/tempel.el
@@ -269,14 +269,8 @@ INIT is the optional initial input."
;; TEMPEL EXTENSION: Evaluate forms
(_ (tempel--form st element))))
-(defun tempel--insert (templates name region)
- "Insert template NAME given the list of TEMPLATES and the current REGION."
- (when-let* ((name (intern-soft name))
- (template (cdr (assoc name templates))))
- (tempel--enable template region)))
-
-(defun tempel--enable (template region)
- "Enable TEMPLATE given the current REGION."
+(defun tempel--insert (template region)
+ "Insert TEMPLATE given the current REGION."
;; TODO do we want to have the ability to reactivate snippets?
(unless (eq buffer-undo-list t)
(push (list 'apply #'tempel--disable) buffer-undo-list))
@@ -402,17 +396,20 @@ If INTERACTIVE is nil the function acts like a capf."
:company-kind (lambda (_) 'snippet)
:exit-function
(lambda (name _status)
- (delete-region (max (point-min) (- (point) (length name)))
(point))
- (tempel--insert templates name region))
+ (when-let* ((sym (intern-soft name))
+ (template (alist-get sym templates)))
+ (delete-region (max (point-min) (- (point) (length name)))
(point))
+ (tempel--insert template region)))
:annotation-function
(and tempel-expand-annotation
(apply-partially #'tempel--annotate
templates tempel-expand-annotation nil "
")))))))
;;;###autoload
-(defun tempel-insert ()
- "Insert template using `completing-read'."
- (interactive)
+(defun tempel-insert (name)
+ "Insert template by NAME.
+If called interactively, select a template with `completing-read'."
+ (interactive (list nil))
(let* ((templates (or (tempel--templates)
(error "Tempel: No templates for %s" major-mode)))
(completion-extra-properties
@@ -420,9 +417,19 @@ If INTERACTIVE is nil the function acts like a capf."
(list :annotation-function
(apply-partially
#'tempel--annotate templates tempel-insert-annotation t
- #(" " 1 2 (display (space :align-to (+ left 20))))))))
- (name (completing-read "Template: " templates nil t nil
'tempel--history)))
- (tempel--insert templates name (tempel--region))))
+ #(" " 1 2 (display (space :align-to (+ left 20)))))))))
+ (unless name
+ (setq name (intern-soft (completing-read "Template: " templates
+ nil t nil 'tempel--history))))
+ (tempel--insert (or (alist-get name templates)
+ (user-error "Template %s not found" name))
+ (tempel--region))))
+
+;;;###autoload
+(defun tempel-key (key name &optional map)
+ "Bind KEY to NAME in MAP."
+ (define-key (or map global-map) (kbd key)
+ (lambda () (interactive) (tempel-insert name))))
(provide 'tempel)
;;; tempel.el ends here
- [elpa] branch externals/tempel created (now aec4f10253), ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 20589b8a6a 18/82: Simplify, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 507e9ed4de 40/82: Improve field initialization, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 11301795d8 51/82: Fix commentary, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 3aa1a7fca8 01/82: Initial commit, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel e4839df533 53/82: Add temple-key,
ELPA Syncer <=
- [elpa] externals/tempel 4a6fc2d0ab 46/82: Fix customization type, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 0aa4e8c37f 63/82: Only erase default value if the point is at the beginning or end, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel def7a1ca3f 07/82: README: Update links, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 311f310b82 72/82: Remove todo, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 9cf5cc35b3 16/82: Use insert-file-contents, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel db24ec0c9e 22/82: Reevaluate forms when arbitrary fields are modified, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 09a0e3bfb0 19/82: Improve annotations, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 16b0fa274a 09/82: Rename commands, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 73cee5feb6 12/82: Update comments, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel b54036f1fa 21/82: Add comment, ELPA Syncer, 2022/01/09