[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel db24ec0c9e 22/82: Reevaluate forms when arbitrar
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel db24ec0c9e 22/82: Reevaluate forms when arbitrary fields are modified |
Date: |
Sun, 9 Jan 2022 20:58:42 -0500 (EST) |
branch: externals/tempel
commit db24ec0c9e964c59075225f315ce0cfea5520df6
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Reevaluate forms when arbitrary fields are modified
See discussion in #2
---
tempel.el | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/tempel.el b/tempel.el
index 1fe4de76cc..cc90affe52 100644
--- a/tempel.el
+++ b/tempel.el
@@ -113,11 +113,12 @@ WIDTH, SEP and ELLIPSIS configure the formatting."
(defun tempel--replace-field (ov str)
"Replace OV content with STR."
- (let ((beg (overlay-start ov)))
- (goto-char beg)
- (delete-char (- (overlay-end ov) beg))
- (insert str)
- (move-overlay ov beg (point))))
+ (save-excursion
+ (let ((beg (overlay-start ov)))
+ (goto-char beg)
+ (delete-char (- (overlay-end ov) beg))
+ (insert str)
+ (move-overlay ov beg (point)))))
(defun tempel--update-field (ov after beg end &optional _len)
"Update field overlay OV.
@@ -132,17 +133,21 @@ BEG and END are the boundaries of the modification."
;; with an invalid undo state after tempel-done.
(with-silent-modifications
(move-overlay ov (overlay-start ov) (max end (overlay-end ov)))
- (when-let (name (overlay-get ov 'tempel--name))
- (let ((state (overlay-get ov 'tempel--state))
- (str (buffer-substring-no-properties (overlay-start ov)
(overlay-end ov))))
- (setf (alist-get name (cddr state)) str)
- ;; Update other fields
- (dolist (other (alist-get name (car state)))
- (unless (eq other ov)
- (tempel--replace-field other str)))
- ;; Update evaluated forms
- (dolist (other (cadr state))
- (tempel--replace-field other (eval (overlay-get other
'tempel--form) (cddr state))))))))))
+ (let ((state (overlay-get ov 'tempel--state)))
+ ;; Update other named fields
+ (when-let (name (overlay-get ov 'tempel--name))
+ (let ((str (buffer-substring-no-properties (overlay-start ov)
(overlay-end ov))))
+ (setf (alist-get name (cddr state)) str)
+ (dolist (other (alist-get name (car state)))
+ (unless (eq other ov)
+ (tempel--replace-field other str)))))
+ ;; Update evaluated form fields
+ (dolist (other (cadr state))
+ (tempel--replace-field
+ other
+ (save-excursion
+ (goto-char (overlay-start other))
+ (eval (overlay-get other 'tempel--form) (cddr state))))))))))
(defun tempel--field (&optional face)
"Create template field with FACE."
@@ -152,6 +157,7 @@ BEG and END are the boundaries of the modification."
(overlay-put ov 'before-string (propertize " " 'face face 'display '(space
:width (1))))
(overlay-put ov 'modification-hooks (list #'tempel--update-field))
(overlay-put ov 'insert-behind-hooks (list #'tempel--update-field))
+ (overlay-put ov 'tempel--state tempel--state)
(push ov tempel--overlays)
ov))
@@ -159,7 +165,6 @@ BEG and END are the boundaries of the modification."
"Create template field named NAME."
(let ((ov (tempel--field)))
(overlay-put ov 'tempel--name name)
- (overlay-put ov 'tempel--state tempel--state)
(push ov (alist-get name (car tempel--state)))
(when-let (str (alist-get name (cddr tempel--state)))
(insert str)
- [elpa] externals/tempel 20589b8a6a 18/82: Simplify, (continued)
- [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, 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 <=
- [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
- [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