[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel 5242ebb37f: Simplify, use tempel--inhibit-hooks
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel 5242ebb37f: Simplify, use tempel--inhibit-hooks variable |
Date: |
Sun, 13 Feb 2022 14:58:03 -0500 (EST) |
branch: externals/tempel
commit 5242ebb37fbf14f60c8eecf4461091ee22389912
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Simplify, use tempel--inhibit-hooks variable
---
tempel.el | 88 ++++++++++++++++++++++++++++++---------------------------------
1 file changed, 42 insertions(+), 46 deletions(-)
diff --git a/tempel.el b/tempel.el
index 15c0aa3f1c..93397e80c7 100644
--- a/tempel.el
+++ b/tempel.el
@@ -111,6 +111,9 @@ must return a list of templates which apply to the buffer
or context."
(defvar tempel--history nil
"Completion history used by `tempel-insert'.")
+(defvar tempel--inhibit-hooks nil
+ "Inhibit tempel modification change hooks from running.")
+
(defvar-local tempel--active nil
"List of active templates.
Each template state is a pair, where the car is a list of overlays and
@@ -135,15 +138,6 @@ may be named with `tempel--name' or carry an evaluatable
Lisp expression
map)
"Keymap to navigate across template fields.")
-(defmacro tempel--inhibit-hooks (&rest body)
- "Inhibit tempel hooks from running in BODY.
-We don't use `inhibit-modification-hooks' since this also prevents hooks
-from other packages from running."
- (declare (indent 0))
- `(cl-letf (((symbol-function #'tempel--field-modified) #'ignore)
- ((symbol-function #'tempel--range-modified) #'ignore))
- ,@body))
-
(defun tempel--print-element (elt)
"Return string representation of template ELT."
(pcase elt
@@ -188,7 +182,7 @@ REGION are the current region bouns"
(defun tempel--range-modified (ov &rest _)
"Range overlay OV modified."
- (when (= (overlay-start ov) (overlay-end ov))
+ (when (and (not tempel--inhibit-hooks) (= (overlay-start ov) (overlay-end
ov)))
(let ((st (overlay-get ov 'tempel--range)))
(setq tempel--active (cons st (delq st tempel--active)))
(tempel--disable))))
@@ -197,23 +191,24 @@ REGION are the current region bouns"
"Update field overlay OV.
AFTER is non-nil after the modification.
BEG and END are the boundaries of the modification."
- (cond
- ;; Erase default before modification if at beginning or end
- ((and (not after) (overlay-get ov 'tempel--default)
- (or (= beg (overlay-start ov)) (= end (overlay-end ov))))
- (delete-region (overlay-start ov) (overlay-end ov)))
- ;; Update field after modification
- (after
- (let ((st (overlay-get ov 'tempel--field)))
- (unless undo-in-progress
- (move-overlay ov (overlay-start ov) (max end (overlay-end ov))))
- (when-let (name (overlay-get ov 'tempel--name))
- (setf (alist-get name (cdr st))
- (buffer-substring-no-properties
- (overlay-start ov) (overlay-end ov))))
- (unless undo-in-progress
- (tempel--synchronize-fields st ov)))))
- (tempel--update-mark ov))
+ (unless tempel--inhibit-hooks
+ (cond
+ ;; Erase default before modification if at beginning or end
+ ((and (not after) (overlay-get ov 'tempel--default)
+ (or (= beg (overlay-start ov)) (= end (overlay-end ov))))
+ (delete-region (overlay-start ov) (overlay-end ov)))
+ ;; Update field after modification
+ (after
+ (let ((st (overlay-get ov 'tempel--field)))
+ (unless undo-in-progress
+ (move-overlay ov (overlay-start ov) (max end (overlay-end ov))))
+ (when-let (name (overlay-get ov 'tempel--name))
+ (setf (alist-get name (cdr st))
+ (buffer-substring-no-properties
+ (overlay-start ov) (overlay-end ov))))
+ (unless undo-in-progress
+ (tempel--synchronize-fields st ov)))))
+ (tempel--update-mark ov)))
(defun tempel--synchronize-fields (st current)
"Synchronize fields of ST, except CURRENT overlay."
@@ -239,15 +234,15 @@ If OV is alive, move it."
(unless (eq buffer-undo-list t)
(push (list 'apply #'tempel--replace beg (+ beg (length str)) ov old)
buffer-undo-list))
- (let ((buffer-undo-list t))
- (tempel--inhibit-hooks
- (save-excursion
- (goto-char beg)
- (delete-char (- end beg))
- (insert str)
- (when ov
- (move-overlay ov beg (point))
- (tempel--update-mark ov))))))))
+ (let ((buffer-undo-list t)
+ (tempel--inhibit-hooks t))
+ (save-excursion
+ (goto-char beg)
+ (delete-char (- end beg))
+ (insert str)
+ (when ov
+ (move-overlay ov beg (point))
+ (tempel--update-mark ov)))))))
(defun tempel--update-mark (ov)
"Update field mark and face of OV."
@@ -355,16 +350,17 @@ PROMPT is the optional prompt/default value."
(when (and (<= (overlay-start ov) (point)) (>= (overlay-end ov)
(point)))
(setf (overlay-end ov) (point)))))
;; Activate template
- (let ((st (cons nil nil)) (range (point)))
- (tempel--inhibit-hooks
- (while (and template (not (keywordp (car template))))
- (tempel--element st region (pop template)))
- (setq range (make-overlay range (point) nil t))
- (push range (car st))
- (overlay-put range 'modification-hooks (list
#'tempel--range-modified))
- (overlay-put range 'tempel--range st)
- ;;(overlay-put range 'face 'region) ;; TODO debug
- (push st tempel--active))))
+ (let ((st (cons nil nil))
+ (range (point))
+ (tempel--inhibit-hooks t))
+ (while (and template (not (keywordp (car template))))
+ (tempel--element st region (pop template)))
+ (setq range (make-overlay range (point) nil t))
+ (push range (car st))
+ (overlay-put range 'modification-hooks (list #'tempel--range-modified))
+ (overlay-put range 'tempel--range st)
+ ;;(overlay-put range 'face 'region) ;; TODO debug
+ (push st tempel--active)))
(cond
((cl-loop for ov in (caar tempel--active)
never (overlay-get ov 'tempel--field))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/tempel 5242ebb37f: Simplify, use tempel--inhibit-hooks variable,
ELPA Syncer <=