[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel 7a7813e531 26/82: Maintain list of active templa
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel 7a7813e531 26/82: Maintain list of active templates |
Date: |
Sun, 9 Jan 2022 20:58:42 -0500 (EST) |
branch: externals/tempel
commit 7a7813e5315315048e5e5e5cc2a99b38f5a18b08
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Maintain list of active templates
---
tempel.el | 68 ++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 37 insertions(+), 31 deletions(-)
diff --git a/tempel.el b/tempel.el
index 1821594831..56a275a83e 100644
--- a/tempel.el
+++ b/tempel.el
@@ -66,7 +66,7 @@
(defvar tempel--templates nil)
(defvar tempel--modified nil)
(defvar tempel--history nil)
-(defvar-local tempel--overlays nil)
+(defvar-local tempel--active nil)
(defvar tempel-map
(let ((map (make-sparse-keymap)))
@@ -151,7 +151,6 @@ BEG and END are the boundaries of the modification."
(overlay-put ov 'insert-behind-hooks (list #'tempel--update-field))
(overlay-put ov 'tempel--state st)
(push ov (car st))
- (push ov tempel--overlays)
ov))
(defun tempel--named (st name)
@@ -211,26 +210,31 @@ BEG and END are the boundaries of the modification."
(_ (tempel--form st element))))
(defun tempel--insert (templates name region)
- "Insert template NAME given the list of TEMPLATES and the REGION."
+ "Insert template NAME given the list of TEMPLATES and the current REGION."
(when-let* ((name (intern-soft name))
(template (cdr (assoc name templates))))
- (setf (alist-get 'tempel--overlays minor-mode-overriding-map-alist)
tempel-map)
- (unless (eq buffer-undo-list t)
- (push (list 'apply #'tempel-done) buffer-undo-list))
- (save-excursion
- ;; Split existing overlays, do not expand within existing field.
- (dolist (ov tempel--overlays)
+ (tempel--activate template region)))
+
+(defun tempel--activate (template region)
+ "Activate TEMPLATE given the current REGION."
+ (setf (alist-get 'tempel--active minor-mode-overriding-map-alist) tempel-map)
+ (unless (eq buffer-undo-list t)
+ (push (list 'apply #'tempel-done) buffer-undo-list))
+ (save-excursion
+ ;; Split existing overlays, do not expand within existing field.
+ (dolist (st tempel--active)
+ (dolist (ov (car st))
(when (and (<= (overlay-start ov) (point)) (>= (overlay-end ov)
(point)))
- (setf (overlay-end ov) (point))))
- ;; Begin marker
- (push (make-overlay (point) (point)) tempel--overlays)
- (let ((st (cons nil nil))
- (inhibit-modification-hooks t))
- (dolist (x template) (tempel--element st x region)))
- ;; End marker
- (push (make-overlay (point) (point) nil nil t) tempel--overlays))
- ;; Jump to first field
- (tempel-next 1)))
+ (setf (overlay-end ov) (point)))))
+ ;; Activate template
+ (let ((st (cons nil nil))
+ (inhibit-modification-hooks t))
+ (push (make-overlay (point) (point)) (car st))
+ (dolist (x template) (tempel--element st x region))
+ (push (make-overlay (point) (point) nil nil t) (car st))
+ (push st tempel--active)))
+ ;; Jump to first field
+ (tempel-next 1))
(defun tempel--save ()
"Save template file buffer."
@@ -263,15 +267,15 @@ BEG and END are the boundaries of the modification."
"Find next overlay in DIR."
(let ((pt (point))
(next nil))
- (if (> dir 0)
- (cl-loop for ov in tempel--overlays do
- (when (and (not (overlay-get ov 'tempel--form)) ;; Skip form
- (> (overlay-start ov) pt))
- (setq next (min (or next most-positive-fixnum) (overlay-end
ov)))))
- (cl-loop for ov in tempel--overlays do
- (when (and (not (overlay-get ov 'tempel--form)) ;; Skip form
- (< (overlay-end ov) pt))
- (setq next (max (or next most-negative-fixnum) (overlay-end
ov))))))
+ (dolist (st tempel--active)
+ (dolist (ov (car st))
+ (if (> dir 0)
+ (when (and (not (overlay-get ov 'tempel--form)) ;; Skip form
+ (> (overlay-start ov) pt))
+ (setq next (min (or next most-positive-fixnum) (overlay-end
ov))))
+ (when (and (not (overlay-get ov 'tempel--form)) ;; Skip form
+ (< (overlay-end ov) pt))
+ (setq next (max (or next most-negative-fixnum) (overlay-end
ov)))))))
next))
(defun tempel-next (arg)
@@ -291,10 +295,12 @@ BEG and END are the boundaries of the modification."
(defun tempel-done ()
"Template completion is done."
(interactive)
- (mapc #'delete-overlay tempel--overlays)
- (setq tempel--overlays nil
+ ;; TODO disable only the topmost template?
+ (dolist (st tempel--active)
+ (mapc #'delete-overlay (car st)))
+ (setq tempel--active nil
minor-mode-overriding-map-alist
- (delq (assq-delete-all 'tempel--overlays
minor-mode-overriding-map-alist)
+ (delq (assq-delete-all 'tempel--active minor-mode-overriding-map-alist)
minor-mode-overriding-map-alist)))
;;;###autoload
- [elpa] externals/tempel 5807ca4d28 33/82: Use remappings, (continued)
- [elpa] externals/tempel 5807ca4d28 33/82: Use remappings, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 9291904a84 24/82: Simplify overlay updates, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 5e1a864123 68/82: Add tempel-abbrev to define an abbrev, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 6c288c32a2 80/82: README: Document Capf setup (Fix #14), ELPA Syncer, 2022/01/09
- [elpa] externals/tempel b5cea7ac67 03/82: Add template markers, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 545b929a28 45/82: README: Fix formatting, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 1ef2d76dd1 35/82: Add screenshots, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel fcfb19e134 47/82: Improve undo, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 36a7977702 62/82: Use cyan color for default values, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel bcf135f993 66/82: Bind lexical environment for prompt eval, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 7a7813e531 26/82: Maintain list of active templates,
ELPA Syncer <=
- [elpa] externals/tempel 934bf35f4b 37/82: Set deleted overlays to nil, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel a5dde06576 75/82: Add tempel-abbrev-mode and tempel-global-abbrev-mode, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 49ba6e795e 79/82: README update, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 72a31055cc 41/82: Fix movement commands, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 29ca4b424d 13/82: README formatting, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 931ea613cb 49/82: Remove faces, reduce visual noise, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 49f779027c 38/82: Minor corrections, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel c8bd4d7e95 61/82: Add special treatment for default values, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 23443415c6 29/82: README: add more examples, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 566fbe15da 50/82: Add back faces, improve undo, ELPA Syncer, 2022/01/09