[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel 65a3eb0458 76/82: Improve abbreviation expansion
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel 65a3eb0458 76/82: Improve abbreviation expansion |
Date: |
Sun, 9 Jan 2022 20:58:46 -0500 (EST) |
branch: externals/tempel
commit 65a3eb045888960499c95a56728f89f4422f691b
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Improve abbreviation expansion
---
tempel.el | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/tempel.el b/tempel.el
index 6dabefd3bf..3aca899994 100644
--- a/tempel.el
+++ b/tempel.el
@@ -154,6 +154,12 @@ WIDTH, SEP and ELLIPSIS configure the formatting."
'face 'completions-annotations))
width 0 ?\s ellipsis))))
+(defun tempel--delete-word (word)
+ "Delete WORD before point."
+ (let ((beg (max (point-min) (- (point) (length word)))))
+ (when (save-excursion (search-backward word beg 'noerror))
+ (delete-region beg (point)))))
+
(defun tempel--exit (templates region name status)
"Exit function for completion for template NAME and STATUS.
TEMPLATES is the list of templates.
@@ -161,7 +167,7 @@ REGION are the current region bouns"
(unless (eq status 'exact)
(when-let* ((sym (intern-soft name))
(template (alist-get sym templates)))
- (delete-region (max (point-min) (- (point) (length name))) (point))
+ (tempel--delete-word name)
(tempel--insert template region))))
(defun tempel--field-modified (ov after beg end &optional _len)
@@ -494,6 +500,11 @@ If called interactively, select a template with
`completing-read'."
(tempel-insert ',name))
(define-key ,(or map 'global-map) ,(kbd key) #',cmd))))
+(defun tempel--abbrev-hook (name template)
+ "Abbreviation expansion hook for TEMPLATE with NAME."
+ (tempel--delete-word name)
+ (tempel--insert template nil))
+
;;;###autoload
(define-minor-mode tempel-abbrev-mode
"Install Tempel templates as abbrevs."
@@ -501,13 +512,14 @@ If called interactively, select a template with
`completing-read'."
:global nil
(setq-local abbrev-minor-mode-table-alist
(assq-delete-all 'tempel-abbrev-mode
abbrev-minor-mode-table-alist))
- (when (eq abbrev-minor-mode-table-alist (default-value
'abbrev-minor-mode-table-alist))
+ (when (eq abbrev-minor-mode-table-alist
+ (default-value 'abbrev-minor-mode-table-alist))
(kill-local-variable 'abbrev-minor-mode-table-alist))
(when tempel-abbrev-mode
(let ((table (make-abbrev-table)))
(dolist (template (tempel--templates))
- (define-abbrev table (symbol-name (car template)) ""
- (apply-partially #'tempel--insert (cdr template) nil)
+ (define-abbrev table (symbol-name (car template)) 'Template
+ (apply-partially #'tempel--abbrev-hook (symbol-name (car template))
(cdr template))
:system t))
(setq-local abbrev-minor-mode-table-alist
(cons `(tempel-abbrev-mode . ,table)
- [elpa] externals/tempel d4bd649645 59/82: Minor renaming, (continued)
- [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
- [elpa] externals/tempel 07d16fded7 67/82: Update fields when new field is inserted, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel f0df571f66 17/82: Respect derived modes, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel bf95b3f1c2 31/82: Add support for (q (FORM ...) var), ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 64f896d782 44/82: Fix jump to first field, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 9948c6889d 43/82: Add tempel-form-prefix and tempel-field-prefix, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel ad71c25632 32/82: Add syntax extension (p (FORM...) <NAME>), ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 5dbdc76eb2 74/82: Specify the completion category tempel, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 65a3eb0458 76/82: Improve abbreviation expansion,
ELPA Syncer <=
- [elpa] externals/tempel 57bbc5e681 78/82: README update, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel ac3df540a4 69/82: Remove underlines from faces, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 7cf25bd795 71/82: Simplify templates data structure at load time, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 69f7cb3212 06/82: Reimplement without Tempo for more flexibility, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel fbef94d77d 48/82: Minor cleanup, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 01e7430343 27/82: Add docstrings, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel a03c36c8dd 02/82: Improve behavior when templates are nested, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel db6847a7f9 56/82: Make temple-key a macro, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 0e618cd169 23/82: Do not sort overlays, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 04d4f6c055 55/82: Use named key function, ELPA Syncer, 2022/01/09