[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel bdf04d8c48 05/82: Improved field movement
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel bdf04d8c48 05/82: Improved field movement |
Date: |
Sun, 9 Jan 2022 20:58:39 -0500 (EST) |
branch: externals/tempel
commit bdf04d8c48fe115ef7df5cd282eff1190a4bef4a
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Improved field movement
---
README.org | 4 ++--
tempel.el | 55 +++++++++++++++++++++++++++++++++----------------------
2 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/README.org b/README.org
index 15a6a8b1ce..eaefca0d53 100644
--- a/README.org
+++ b/README.org
@@ -19,9 +19,9 @@ provides a modernized UI on top of Tempo, in the form of two
commands:
(Capf). You may want to use my [[https://github.com/minad/corfu][Corfu]]
completion at point UI.
+ ~tempel-insert~: Select a template by name and insert it into the current
buffer.
-After inserting a template you can move between the visible template markers
+After inserting a template you can move between the visible template fields
with keys ~M-left/right~ as defined in the ~tempel-map~ keymap. As soon as you
move
-before (behind) the first (last) marker, the markers will be removed.
+before (behind) the first (last) field, the fields are removed.
Note that this package is not a competitor to the mature and widely used
YASnippet library. Try Tempel only if your snippet and templating requirements
diff --git a/tempel.el b/tempel.el
index 057a9374cb..158c2e4e0c 100644
--- a/tempel.el
+++ b/tempel.el
@@ -43,12 +43,12 @@
(defvar tempel--modified nil)
(defvar tempel--current nil)
(defvar tempel--history nil)
-(defvar-local tempel--overlays nil)
+(defvar-local tempel--fields nil)
(defvar tempel-map
(let ((map (make-sparse-keymap)))
- (define-key map [M-right] #'tempel-forward-mark)
- (define-key map [M-left] #'tempel-backward-mark)
+ (define-key map [M-right] #'tempel-next-field)
+ (define-key map [M-left] #'tempel-previous-field)
map)
"Keymap to navigate across template markers.")
@@ -93,13 +93,14 @@
(template (cdr (assoc name templates))))
(setf (alist-get 'tempo-marks minor-mode-overriding-map-alist) tempel-map)
(let ((tempel--current template))
- (mapc #'delete-overlay tempel--overlays)
- (setq tempel--overlays nil)
+ (mapc #'delete-overlay tempel--fields)
+ (setq tempel--fields nil)
(tempo-insert-template 'tempel--current region)
(dolist (x tempo-marks)
- (let ((ov (make-overlay x x)))
+ (let ((ov (make-overlay x x nil nil t)))
+ (overlay-put ov 'face 'highlight)
(overlay-put ov 'before-string #(" " 0 1 (face highlight display
(space :width (1)))))
- (push ov tempel--overlays))))))
+ (push ov tempel--fields))))))
(defun tempel--save ()
"Save Tempo file buffer."
@@ -116,27 +117,37 @@
tempel--modified mod)))
(cdr (seq-find (lambda (x) (derived-mode-p (car x))) tempel--templates)))
-(defun tempel-forward-mark ()
- "Move to next template mark and quit at the end."
- (interactive)
- (when-let (mark (car (last tempo-marks)))
- (when (>= (point) mark) (tempel-done)))
- (tempo-forward-mark))
-
-(defun tempel-backward-mark ()
- "Move to previous template mark and quit at the beginning."
- (interactive)
- (when-let (mark (car tempo-marks))
- (when (<= (point) mark) (tempel-done)))
- (tempo-backward-mark))
+(defun tempel-next-field (arg)
+ "Move to next template field and quit at the end."
+ (interactive "p")
+ (catch 'tempel--break
+ (cond
+ ((> arg 0)
+ (dolist (ov (reverse tempel--fields))
+ (when (> (overlay-start ov) (point))
+ (if (> arg 1) (cl-decf arg)
+ (goto-char (overlay-start ov))
+ (throw 'tempel--break nil)))))
+ ((< arg 0)
+ (dolist (ov tempel--fields)
+ (when (< (overlay-end ov) (point))
+ (if (< arg -1) (cl-incf arg)
+ (goto-char (overlay-start ov))
+ (throw 'tempel--break nil))))))
+ (tempel-done)))
+
+(defun tempel-previous-field (arg)
+ "Move to previous template field and quit at the beginning."
+ (interactive "p")
+ (tempel-next-field (- arg)))
(defun tempel-done ()
"Template completion is done."
(interactive)
(dolist (mark tempo-marks) (set-marker mark nil))
- (mapc #'delete-overlay tempel--overlays)
+ (mapc #'delete-overlay tempel--fields)
(setq tempo-marks nil
- tempel--overlays nil
+ tempel--fields nil
minor-mode-overriding-map-alist
(delq (assq-delete-all 'tempo-marks minor-mode-overriding-map-alist)
minor-mode-overriding-map-alist)))
- [elpa] externals/tempel d9efb707b3 20/82: Improve undo behavior, (continued)
- [elpa] externals/tempel d9efb707b3 20/82: Improve undo behavior, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 4bc75c1aba 52/82: Use the more subtle face colors from Modus, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 52d8556c05 57/82: Improve annotation function, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 675e759bde 64/82: Add special prompt treatment, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel e6aa1892af 14/82: README: Simplify template, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 2ba940809a 42/82: Add temple-abort (Fix #2), ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 5521546f48 10/82: README: Add header, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel d2d5566282 65/82: Improve description of PROMPT/DEFAULT value, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel e529887d5d 70/82: tempel-expand: Fix exit function, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel 349e9735ac 08/82: Remove global temple-region variable, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel bdf04d8c48 05/82: Improved field movement,
ELPA Syncer <=
- [elpa] externals/tempel 76a5ab120b 15/82: Add customization variables, ELPA Syncer, 2022/01/09
- [elpa] externals/tempel f7990f528b 11/82: README update, ELPA Syncer, 2022/01/09
- [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