[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tempel 6299d31773: Add tempel-field-end, tempel-field-b
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tempel 6299d31773: Add tempel-field-end, tempel-field-beginning, tempel-kill-field |
Date: |
Thu, 13 Jan 2022 09:57:44 -0500 (EST) |
branch: externals/tempel
commit 6299d317735a58c378009694f150edb612a34149
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add tempel-field-end, tempel-field-beginning, tempel-kill-field
---
README.org | 2 +-
tempel.el | 52 +++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/README.org b/README.org
index 1149d390f0..a42a4122c8 100644
--- a/README.org
+++ b/README.org
@@ -30,7 +30,7 @@ For the completion at point commands ~tempel-complete~ and
~tempel-expand~, you
want to give my [[https://github.com/minad/corfu][Corfu]] completion at point
popup UI a try. After inserting the
template you can move between the visible template fields with the keys ~M-{~,
~M-}~
or ~C-up/down~ which are normally bound to ~forward/backward-paragraph~. Tempel
-temporarily remaps these commands to ~tempel-next~ and ~tempel-previous~. The
key
+temporarily remaps these commands to ~tempel-next-field/previous-field~. The
key
bindings are defined in the ~tempel-map~ keymap. You can customize them there.
As
soon as you move before (behind) the first (last) field, the fields are
finalized.
diff --git a/tempel.el b/tempel.el
index 3a68acc528..b692922497 100644
--- a/tempel.el
+++ b/tempel.el
@@ -124,14 +124,17 @@ may be named with `tempel--name' or carry an evaluatable
Lisp expression
(defvar tempel-map
(let ((map (make-sparse-keymap)))
- (define-key map [remap beginning-of-buffer] #'tempel-beginning)
- (define-key map [remap end-of-buffer] #'tempel-end)
- (define-key map [remap forward-paragraph] #'tempel-next)
- (define-key map [remap backward-paragraph] #'tempel-previous)
+ (define-key map [remap beginning-of-buffer] #'tempel-template-beginning)
+ (define-key map [remap end-of-buffer] #'tempel-template-end)
+ (define-key map [remap forward-paragraph] #'tempel-next-field)
+ (define-key map [remap backward-paragraph] #'tempel-previous-field)
+ (define-key map [remap backward-sentence] #'tempel-field-beginning)
+ (define-key map [remap forward-sentence] #'tempel-field-end)
+ (define-key map [remap kill-sentence] #'tempel-kill-field)
(define-key map [remap keyboard-quit] #'tempel-abort)
(define-key map [remap keyboard-escape-quit] #'tempel-abort)
map)
- "Keymap to navigate across template markers.")
+ "Keymap to navigate across template fields.")
(defun tempel--print-element (elt)
"Return string representation of template ELT."
@@ -341,7 +344,7 @@ PROMPT is the optional prompt/default value."
thereis (and (overlay-get ov 'tempel--state)
(eq (point) (overlay-start ov))))
;; Jump to first field
- (tempel-next 1))
+ (tempel-next-field 1))
;; Disable right away
(goto-char (overlay-start (caaar tempel--active)))
(tempel--disable)))
@@ -415,19 +418,46 @@ PROMPT is the optional prompt/default value."
((and (< dir 0) (< stop pt))
(setq next (max (or next -1) stop)))))))))
-(defun tempel-beginning ()
+(defun tempel-template-beginning ()
"Move to beginning of the template."
(interactive)
(when-let (pos (tempel--beginning))
(if (= pos (point)) (tempel-done) (goto-char pos))))
-(defun tempel-end ()
+(defun tempel-template-end ()
"Move to end of the template."
(interactive)
(when-let (pos (tempel--end))
(if (= pos (point)) (tempel-done) (goto-char pos))))
-(defun tempel-next (arg)
+(defun tempel--field-at-point ()
+ "Return the field overlay at point."
+ (cl-loop for ov in (overlays-in (max (point-min) (1- (point)))
+ (min (point-max) (1+ (point))))
+ thereis (and (overlay-get ov 'tempel--state) ov)))
+
+(defun tempel-field-beginning ()
+ "Move to beginning of the field."
+ (interactive)
+ (if-let (ov (tempel--field-at-point))
+ (goto-char (overlay-start ov))
+ (move-beginning-of-line nil)))
+
+(defun tempel-field-end ()
+ "Move to end of the field."
+ (interactive)
+ (if-let (ov (tempel--field-at-point))
+ (goto-char (overlay-end ov))
+ (move-end-of-line nil)))
+
+(defun tempel-kill-field ()
+ "Kill the field contents."
+ (interactive)
+ (if-let (ov (tempel--field-at-point))
+ (kill-region (overlay-start ov) (overlay-end ov))
+ (kill-sentence nil)))
+
+(defun tempel-next-field (arg)
"Move ARG fields forward and quit at the end."
(interactive "p")
(cl-loop for i below (abs arg) do
@@ -435,10 +465,10 @@ PROMPT is the optional prompt/default value."
(tempel-done)
(cl-return))))
-(defun tempel-previous (arg)
+(defun tempel-previous-field (arg)
"Move ARG fields backward and quit at the beginning."
(interactive "p")
- (tempel-next (- arg)))
+ (tempel-next-field (- arg)))
(defun tempel--beginning ()
"Return beginning of template markers."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/tempel 6299d31773: Add tempel-field-end, tempel-field-beginning, tempel-kill-field,
ELPA Syncer <=