[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel 09a0e3bfb0 19/82: Improve annotations
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel 09a0e3bfb0 19/82: Improve annotations |
Date: |
Sun, 9 Jan 2022 20:58:42 -0500 (EST) |
branch: externals/tempel
commit 09a0e3bfb0fb780d6e096ad6791f907fb25a84c0
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Improve annotations
---
tempel.el | 51 ++++++++++++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 15 deletions(-)
diff --git a/tempel.el b/tempel.el
index 1c0b308642..f5d6996c3e 100644
--- a/tempel.el
+++ b/tempel.el
@@ -44,9 +44,17 @@
:prefix "tempel-")
(defcustom tempel-file (expand-file-name "templates" user-emacs-directory)
- "Path to the template file"
+ "Path to the template file."
:type 'string)
+(defcustom tempel-insert-annotation 40
+ "Annotation width for `tempel-insert'."
+ :type '(choice (const nil integer)))
+
+(defcustom tempel-expand-annotation 20
+ "Annotation width for `tempel-expand'."
+ :type '(choice (const nil integer)))
+
(defface tempel-field '((t :inherit highlight))
"Face used for fields.")
@@ -76,8 +84,9 @@
(goto-char (point-min))
(read (current-buffer))))
-(defun tempel--annotate (templates sep name)
- "Annotate template NAME given the list of TEMPLATES and SEP."
+(defun tempel--annotate (templates width ellipsis sep name)
+ "Annotate template NAME given the list of TEMPLATES.
+WIDTH, SEP and ELLIPSIS configure the formatting."
(when-let* ((name (intern-soft name))
(def (cdr (assoc name templates))))
(concat
@@ -88,13 +97,19 @@
(propertize
(replace-regexp-in-string
"\\s-+" " "
- (mapconcat (lambda (x) (pcase x
- ((pred stringp) x)
- ((or 'n 'n>) " ")
- (_ "_")))
+ (mapconcat (lambda (x)
+ (pcase x
+ ('nil nil)
+ (`(q . ,_) nil)
+ ((pred stringp) x)
+ (`(s ,name) (symbol-name name))
+ (`(,(or 'p 'P) ,_ ,name . ,noinsert)
+ (and (not (car noinsert)) (symbol-name name)))
+ ((or 'n 'n>) " ")
+ (_ "_")))
def ""))
'face 'completions-annotations))
- 20 0 ?\s))))
+ width 0 ?\s ellipsis))))
(defun tempel--replace-field (ov str)
"Replace OV content with STR."
@@ -293,10 +308,14 @@ If INTERACTIVE is nil the function acts like a capf."
(cons (point) (point)))))
(list (car bounds) (cdr bounds) templates
:exclusive 'no
- :exit-function (lambda (name _status)
- (delete-region (max (point-min) (- (point)
(length name))) (point))
- (tempel--insert templates name region))
- :annotation-function (apply-partially #'tempel--annotate
templates " "))))))
+ :company-kind (lambda (_) 'snippet)
+ :exit-function
+ (lambda (name _status)
+ (delete-region (max (point-min) (- (point) (length name)))
(point))
+ (tempel--insert templates name region))
+ :annotation-function
+ (and tempel-expand-annotation
+ (apply-partially #'tempel--annotate templates
tempel-expand-annotation nil " ")))))))
;;;###autoload
(defun tempel-insert ()
@@ -305,9 +324,11 @@ If INTERACTIVE is nil the function acts like a capf."
(let* ((templates (or (tempel--templates)
(error "Tempel: No templates for %s" major-mode)))
(completion-extra-properties
- (list :annotation-function
- (apply-partially #'tempel--annotate templates
- #(" " 1 2 (display (space :align-to (+ left
20)))))))
+ (and tempel-insert-annotation
+ (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))))
- [elpa] externals/tempel 507e9ed4de 40/82: Improve field initialization, (continued)
- [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, 2022/01/09
- [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 <=
- [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
- [elpa] externals/tempel 11cfbe239d 36/82: Fix undo, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel ffdf2c792a 77/82: Document the abbrev modes (See #14), ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 460f8fe806 81/82: Fix the MELPA issues, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel aec4f10253 82/82: Addition to GNU ELPA, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel d4bd649645 59/82: Minor renaming, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 2cff879181 30/82: Do not call modification hooks from forms, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 1222c59b30 39/82: Update README, ELPA Syncer, 2022/01/09