[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4f78d03 01/42: Close #937: Officially support automaticall
From: |
Noam Postavsky |
Subject: |
[elpa] master 4f78d03 01/42: Close #937: Officially support automatically moving to next field |
Date: |
Sun, 22 Dec 2019 17:37:55 -0500 (EST) |
branch: master
commit 4f78d03f85ca020468fd69ee9fcaf35b6ba409e1
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Close #937: Officially support automatically moving to next field
* yasnippet-tests.el (auto-next-field): New test.
(yas-saving-variables): Move up in the file.
* yasnippet.el (yas--auto-next): New helper.
(yas-auto-next): New user-visible snippet helper.
* doc/snippet-development.org (Choosing fields value from a list
and other tricks): Add mention of yas-auto-next.
---
doc/snippet-development.org | 15 +++++++++++++--
yasnippet-tests.el | 28 ++++++++++++++++++++++++----
yasnippet.el | 12 ++++++++++++
3 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/doc/snippet-development.org b/doc/snippet-development.org
index 9112cd0..1a7ad49 100644
--- a/doc/snippet-development.org
+++ b/doc/snippet-development.org
@@ -420,8 +420,19 @@ The [[sym:yas-choose-value][=yas-choose-value=]] does this
work for you. For exa
</div>
#+END_SRC
-See the definition of [[sym:yas-choose-value][=yas-choose-value=]] to see how
it was written using
-the two variables.
+See the definition of [[sym:yas-choose-value][=yas-choose-value=]] to see how
it was written
+using the two variables. If you're really lazy :) and can't spare a
+tab keypress, you can automatically move to the next field (or exit)
+after choosing the value with [[sym:yas-auto-next][=yas-auto-next=]]. The
snippet above
+becomes:
+
+#+BEGIN_SRC snippet
+ <div align="${2:$$(yas-auto-next
+ (yas-choose-value
+ '("right" "center" "left")))}">
+ $0
+ </div>
+#+END_SRC
Here's another use, for LaTeX-mode, which calls reftex-label just as you
enter snippet field 2. This one makes use of
[[sym:yas-modified-p][=yas-modified-p=]] directly.
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 6048467..fb4bc0f 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -603,6 +603,30 @@ mapconcat #'(lambda (arg)
(ert-simulate-command '(yas-next-field))
(should (looking-at (concat "blo" expected))))))
+(defmacro yas-saving-variables (&rest body)
+ (declare (debug t))
+ `(yas-call-with-saving-variables #'(lambda () ,@body)))
+
+(ert-deftest auto-next-field ()
+ "Automatically exit a field after evaluating its transform."
+ (with-temp-buffer
+ (yas-saving-variables
+ (yas-with-snippet-dirs
+ `((".emacs.d/snippets"
+ ("ruby-mode" ("snip" . ,(concat "foo ${1:$$"
+ (prin1-to-string '(yas-auto-next
+ (yas-choose-value
+ "bar" "foo")))
+ "} baz ${2:quinn} quinn")))))
+ (yas-reload-all)
+ (ruby-mode)
+ (yas-minor-mode 1)
+ (set (make-local-variable 'yas-prompt-functions) `(yas-no-prompt))
+ (yas-mock-insert "snip")
+ (ert-simulate-command '(yas-expand))
+ (yas-mock-insert "quux")
+ (should (equal "foo bar baz quux quinn" (buffer-string)))))))
+
;;; Snippet expansion and character escaping
;;; Thanks to @zw963 (Billy) for the testing
@@ -754,10 +778,6 @@ mapconcat #'(lambda (arg)
(and (buffer-name ,temp-buffer)
(kill-buffer ,temp-buffer))))))))
-(defmacro yas-saving-variables (&rest body)
- (declare (debug t))
- `(yas-call-with-saving-variables #'(lambda () ,@body)))
-
(ert-deftest example-for-issue-474 ()
(yas--with-font-locked-temp-buffer
(c-mode)
diff --git a/yasnippet.el b/yasnippet.el
index d478073..eeeb33f 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -2987,6 +2987,18 @@ The last element of POSSIBILITIES may be a list of
strings."
(funcall fn "Choose: " possibilities))
yas-prompt-functions)))
+(defun yas--auto-next ()
+ "Helper for `yas-auto-next'."
+ (remove-hook 'post-command-hook #'yas--auto-next t)
+ (yas-next-field))
+
+(defmacro yas-auto-next (&rest body)
+ "Automatically advance to next field after eval'ing BODY."
+ (declare (indent 0) (debug t))
+ `(unless yas-moving-away-p
+ (prog1 ,@body
+ (add-hook 'post-command-hook #'yas--auto-next nil t))))
+
(defun yas-key-to-value (alist)
(unless (or yas-moving-away-p
yas-modified-p)
- [elpa] master updated (2604824 -> 32f3512), Noam Postavsky, 2019/12/22
- [elpa] master 4af3354 02/42: Make less garbage in overlay heavy buffers, Noam Postavsky, 2019/12/22
- [elpa] master e67592c 03/42: Don't use overlays to find active snippets, Noam Postavsky, 2019/12/22
- [elpa] master 79b90c9 04/42: Remove compatibility code for Emacs 22 and earlier, Noam Postavsky, 2019/12/22
- [elpa] master d3bb879 05/42: Remove last-buffer-undo-list compat definition, Noam Postavsky, 2019/12/22
- [elpa] master 4f78d03 01/42: Close #937: Officially support automatically moving to next field,
Noam Postavsky <=
- [elpa] master 1e71360 06/42: Per #947: fix typo in README.md, Noam Postavsky, 2019/12/22
- [elpa] master 7a178a2 07/42: Remove spurious change of before-change-functions, Noam Postavsky, 2019/12/22
- [elpa] master 8328c38 08/42: Fix another failure of cc-mode indentation, Noam Postavsky, 2019/12/22
- [elpa] master eeb05f0 10/42: Handle field adjust of pending active fields, Noam Postavsky, 2019/12/22
- [elpa] master 8452227 13/42: Consider fundamental-mode as ultimate ancestor, Noam Postavsky, 2019/12/22
- [elpa] master fb253ac 15/42: New public function yas-maybe-expand-abbrev-key-filter, Noam Postavsky, 2019/12/22
- [elpa] master bceb65b 16/42: Make backspace/DEL clear field (#957), Noam Postavsky, 2019/12/22
- [elpa] master 3c0be40 11/42: Update FAQ, Noam Postavsky, 2019/12/22
- [elpa] master 8b25d62 20/42: * doc/snippet-development.org: Fix typos., Noam Postavsky, 2019/12/22
- [elpa] master 7612bc1 24/42: Don't check this-command in yas-not-string-or-comment-condition, Noam Postavsky, 2019/12/22