[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ba73f20 27/51: Bind field skip and clear command condition
From: |
Noam Postavsky |
Subject: |
[elpa] master ba73f20 27/51: Bind field skip and clear command conditionally |
Date: |
Sun, 13 May 2018 13:11:43 -0400 (EDT) |
branch: master
commit ba73f20bc305570391a151fa353188803b01f855
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Bind field skip and clear command conditionally
Rather than embedding the conditionality inside the function body, and
hardcoding fallback to `delete-char'. This allows users who want, for
example, to use backspace for field skipping to simply do
(define-key yas-minor-mode-map (kbd "DEL")
yas-maybe-skip-and-clear-field)
* yasnippet.el (yas-skip-and-clear-field, yas-current-field)
(yas--maybe-clear-field-filter): New command and function, extracted
from yas-skip-and-clear-or-delete-char.
(yas-skip-and-clear-or-delete-char): Mark obsolete.
(yas-maybe-skip-and-clear-field): New constant, for conditional
binding.
(yas-keymap): Bind it to `C-d' instead of
`yas-skip-and-clear-or-delete-char'.
* yasnippet-tests.el (delete-numberless-inner-snippet-issue-562): Use
`yas-skip-and-clear-field' instead of
`yas-skip-and-clear-or-delete-char'.
---
yasnippet-tests.el | 2 +-
yasnippet.el | 47 +++++++++++++++++++++++++++++++++++------------
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 5751a06..c82d1b0 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -274,7 +274,7 @@ attention to case differences."
(ert-simulate-command '(yas-next-field-or-maybe-expand))
(should (looking-at "testblable"))
(ert-simulate-command '(yas-next-field-or-maybe-expand))
- (ert-simulate-command '(yas-skip-and-clear-or-delete-char))
+ (ert-simulate-command '(yas-skip-and-clear-field))
(should (looking-at "ble"))
(should (null (yas-active-snippets)))))
diff --git a/yasnippet.el b/yasnippet.el
index 7c8905a..94d8632 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -396,13 +396,21 @@ It must be set to nil before loading yasnippet to take
effect."
;;; User-visible variables
+(defconst yas-maybe-skip-and-clear-field
+ '(menu-item "" yas-skip-and-clear-field
+ :filter yas--maybe-clear-field-filter)
+ "A conditional key definition.
+This can be used as a key definition in keymaps to bind a key to
+`yas-skip-and-clear-field' only when at the beginning of an
+unmodified snippey field.")
+
(defvar yas-keymap (let ((map (make-sparse-keymap)))
(define-key map [(tab)]
'yas-next-field-or-maybe-expand)
(define-key map (kbd "TAB")
'yas-next-field-or-maybe-expand)
(define-key map [(shift tab)] 'yas-prev-field)
(define-key map [backtab] 'yas-prev-field)
(define-key map (kbd "C-g") 'yas-abort-snippet)
- (define-key map (kbd "C-d")
'yas-skip-and-clear-or-delete-char)
+ (define-key map (kbd "C-d")
yas-maybe-skip-and-clear-field)
map)
"The active keymap while a snippet expansion is in progress.")
@@ -3547,22 +3555,37 @@ holds the keymap."
(overlay-put overlay 'yas--snippet snippet)
overlay))
+(defun yas-current-field ()
+ "Return the currently active field."
+ (and yas--active-field-overlay
+ (overlay-buffer yas--active-field-overlay)
+ (overlay-get yas--active-field-overlay 'yas--field)))
+
+(defun yas--maybe-clear-field-filter (cmd)
+ "Return CMD if at start of unmodified snippet field.
+Use as a `:filter' argument for a conditional keybinding."
+ (let ((field (yas-current-field)))
+ (when (and field
+ (not (yas--field-modified-p field))
+ (eq (point) (marker-position (yas--field-start field))))
+ cmd)))
+
+(defun yas-skip-and-clear-field (&optional field)
+ "Clears unmodified FIELD if at field start, skips to next tab."
+ (interactive)
+ (yas--skip-and-clear (or field (yas-current-field)))
+ (yas-next-field 1))
+
(defun yas-skip-and-clear-or-delete-char (&optional field)
"Clears unmodified field if at field start, skips to next tab.
Otherwise deletes a character normally by calling `delete-char'."
(interactive)
- (let ((field (or field
- (and yas--active-field-overlay
- (overlay-buffer yas--active-field-overlay)
- (overlay-get yas--active-field-overlay 'yas--field)))))
- (cond ((and field
- (not (yas--field-modified-p field))
- (eq (point) (marker-position (yas--field-start field))))
- (yas--skip-and-clear field)
- (yas-next-field 1))
- (t
- (call-interactively 'delete-char)))))
+ (declare (obsolete "Bind to `yas-maybe-skip-and-clear-field' instead."
"0.13"))
+ (cond ((yas--maybe-clear-field-filter t)
+ (yas--skip-and-clear (or field (yas-current-field)))
+ (yas-next-field 1))
+ (t (call-interactively 'delete-char))))
(defun yas--skip-and-clear (field &optional from)
"Deletes the region of FIELD and sets it's modified state to t.
- [elpa] master ee81da9 11/51: Allow "# --" end-of-header marker to have trailing space, (continued)
- [elpa] master ee81da9 11/51: Allow "# --" end-of-header marker to have trailing space, Noam Postavsky, 2018/05/13
- [elpa] master b1ca219 12/51: Remove submodules (snippet and yasmate), Noam Postavsky, 2018/05/13
- [elpa] master 35a4df7 03/51: Let whitespace-global-mode work in new snippet buffers, Noam Postavsky, 2018/05/13
- [elpa] master d806b04 15/51: * yasnippet.el (snippet-mode): Derive from prog-mode., Noam Postavsky, 2018/05/13
- [elpa] master 1292cd2 10/51: Refactor undo tests, Noam Postavsky, 2018/05/13
- [elpa] master 203059a 17/51: * yasnippet.el (yas-key-syntaxes): Prefer the longest key., Noam Postavsky, 2018/05/13
- [elpa] master 7ea1305 09/51: Fix undo when first line indentation moves snippet forward, Noam Postavsky, 2018/05/13
- [elpa] master 6ffd1c7 22/51: ; .travis.yml: Test with 25.3 and 26 prelease., Noam Postavsky, 2018/05/13
- [elpa] master 2e69471 24/51: ; yasnippet-debug.el: macroexp-progn is not avaiable in Emacs 23., Noam Postavsky, 2018/05/13
- [elpa] master 3d7cafc 34/51: Make yas-snippet-mode-buffer-p robust against symlinks, Noam Postavsky, 2018/05/13
- [elpa] master ba73f20 27/51: Bind field skip and clear command conditionally,
Noam Postavsky <=
- [elpa] master ce11fd6 13/51: * yasnippet.el (yas-reload-all): Mention if no snippets were found., Noam Postavsky, 2018/05/13
- [elpa] master e200a3b 08/51: Let snippet insertion trigger active field clearing., Noam Postavsky, 2018/05/13
- [elpa] master 04062d8 14/51: Don't set yas-selected-text to non-selected text, Noam Postavsky, 2018/05/13
- [elpa] master ad3a4d1 16/51: Don't use prog-mode in older Emacs, Noam Postavsky, 2018/05/13
- [elpa] master 16c2b38 18/51: Update `yas--take-care-of-redo' call in buffer undo list, Noam Postavsky, 2018/05/13
- [elpa] master e35c031 25/51: * yasnippet.el (yas--guess-snippet-directories): Guess major mode first., Noam Postavsky, 2018/05/13
- [elpa] master 4467e93 40/51: Use fancy field adjustment for fixed indent too, Noam Postavsky, 2018/05/13
- [elpa] master 7c9edb5 29/51: ; doc/snippet-development.org: Further copy edit., Noam Postavsky, 2018/05/13
- [elpa] master cf23537 33/51: Fix expansion of commands snippet, Noam Postavsky, 2018/05/13
- [elpa] master fa6a71c 45/51: ; Wait until post-command, or bad auto-fill call to print stacktrace, Noam Postavsky, 2018/05/13