[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7f337f4 32/63: Fix nested snippet expansion
From: |
Noam Postavsky |
Subject: |
[elpa] master 7f337f4 32/63: Fix nested snippet expansion |
Date: |
Mon, 17 Jul 2017 22:54:15 -0400 (EDT) |
branch: master
commit 7f337f4488da6e3ea4b92057ca1576d17bc51743
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Fix nested snippet expansion
* yasnippet.el (yas--place-overlays): Don't move active field overlays
unless we're working on the innermost snippet.
(yas--move-to-field): Keep `yas--active-field-overlay's `yas--snippet'
property in sync with its `yas--field' property.
* yasnippet-tests.el (nested-snippet-expansion-1): Rename from
nested-snippet-expansion-1.
(nested-snippet-expansion-2, nested-snippet-expansion-3): New tests.
---
yasnippet-tests.el | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
yasnippet.el | 7 ++++++-
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 432d77d..555249a 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -678,7 +678,7 @@ hello ${1:$(when (stringp yas-text) (funcall func
yas-text))} foo${1:$$(concat \
(yas-should-expand '(("foo-barbaz" . "OKfoo-barbazOK")
("foo " . "foo "))))))))
-(ert-deftest nested-snippet-expansion ()
+(ert-deftest nested-snippet-expansion-1 ()
(with-temp-buffer
(yas-minor-mode +1)
(let ((yas-triggers-in-field t))
@@ -689,6 +689,52 @@ hello ${1:$(when (stringp yas-text) (funcall func
yas-text))} foo${1:$$(concat \
(should (= (length (yas--snippet-fields (nth 0 snippets))) 2))
(should (= (length (yas--snippet-fields (nth 1 snippets))) 1))))))
+(ert-deftest nested-snippet-expansion-2 ()
+ (let ((yas-triggers-in-field t))
+ (yas-with-snippet-dirs
+ '((".emacs.d/snippets"
+ ("text-mode"
+ ("nest" . "one($1:$1) two($2).$0"))))
+ (yas-reload-all)
+ (text-mode)
+ (yas-minor-mode +1)
+ (insert "nest")
+ (ert-simulate-command '(yas-expand))
+ (yas-mock-insert "nest")
+ (ert-simulate-command '(yas-expand))
+ (yas-mock-insert "x")
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (yas-mock-insert "y")
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (yas-mock-insert "z")
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (should (string= (buffer-string)
+ "one(one(x:x) two(y).:one(x:x) two(y).) two(z).")))))
+
+(ert-deftest nested-snippet-expansion-3 ()
+ (let ((yas-triggers-in-field t))
+ (yas-with-snippet-dirs
+ '((".emacs.d/snippets"
+ ("text-mode"
+ ("rt" . "\
+\\sqrt${1:$(if (string-equal \"\" yas/text) \"\" \"[\")}${1:}${1:$(if
(string-equal \"\" yas/text) \"\" \"]\")}{$2}$0"))))
+ (yas-reload-all)
+ (text-mode)
+ (yas-minor-mode +1)
+ (insert "rt")
+ (ert-simulate-command '(yas-expand))
+ (yas-mock-insert "3")
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (yas-mock-insert "rt")
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (yas-mock-insert "5")
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (yas-mock-insert "2")
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (ert-simulate-command '(yas-next-field-or-maybe-expand))
+ (should (string= (buffer-string) "\\sqrt[3]{\\sqrt[5]{2}}")))))
+
;;; Loading
;;;
diff --git a/yasnippet.el b/yasnippet.el
index 2645121..092ea6a 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -3166,7 +3166,11 @@ If there's none, exit the snippet."
(defun yas--place-overlays (snippet field)
"Correctly place overlays for SNIPPET's FIELD."
(yas--make-move-field-protection-overlays snippet field)
- (yas--make-move-active-field-overlay snippet field))
+ ;; Only move active field overlays if this is field is from the
+ ;; innermost snippet.
+ (when (eq snippet (car (yas-active-snippets (1- (yas--field-start field))
+ (1+ (yas--field-end field)))))
+ (yas--make-move-active-field-overlay snippet field)))
(defun yas--move-to-field (snippet field)
"Update SNIPPET to move to field FIELD.
@@ -3174,6 +3178,7 @@ If there's none, exit the snippet."
Also create some protection overlays"
(goto-char (yas--field-start field))
(yas--place-overlays snippet field)
+ (overlay-put yas--active-field-overlay 'yas--snippet snippet)
(overlay-put yas--active-field-overlay 'yas--field field)
(let ((number (yas--field-number field)))
;; check for the special ${0: ...} field
- [elpa] master c3a9447 43/63: Fix condition timestamps in key filter functions, (continued)
- [elpa] master c3a9447 43/63: Fix condition timestamps in key filter functions, Noam Postavsky, 2017/07/17
- [elpa] master 82818e5 48/63: Don't delete snippets more than once., Noam Postavsky, 2017/07/17
- [elpa] master 63f44b4 33/63: Ensure inhibit-modification-hooks is nil while modifying buffer, Noam Postavsky, 2017/07/17
- [elpa] master 0041efe 17/63: Make snippets work in org source blocks, Noam Postavsky, 2017/07/17
- [elpa] master 47f37f7 42/63: Fix ${0:soon-to-be-deleted} with no other fields, Noam Postavsky, 2017/07/17
- [elpa] master e8ed276 52/63: Make sure tests don't rely on running order, Noam Postavsky, 2017/07/17
- [elpa] master 2a3a0cd 61/63: Update CONTRIBUTING.md information, Noam Postavsky, 2017/07/17
- [elpa] master b0e729b 58/63: Optionally add undo list to debug info, Noam Postavsky, 2017/07/17
- [elpa] master 274406e 55/63: Provide command line interface from yasnippet-debug.el, Noam Postavsky, 2017/07/17
- [elpa] master 6e9b7f9 30/63: Fix running hook variable set as buffer-local, Noam Postavsky, 2017/07/17
- [elpa] master 7f337f4 32/63: Fix nested snippet expansion,
Noam Postavsky <=
- [elpa] master 1bf7a4c 47/63: Fix field parsing in modes that use the `syntax-table' property, Noam Postavsky, 2017/07/17
- [elpa] master 8797a31 45/63: * doc/snippet-expansion.org: Complete sentence fragment., Noam Postavsky, 2017/07/17
- [elpa] master c87afe0 26/63: Merge: snippet-local exit hook; error handling improvements, Noam Postavsky, 2017/07/17
- [elpa] master 1043b6c 49/63: Restore syntax-propertize-function before indenting mirrors, Noam Postavsky, 2017/07/17
- [elpa] master 65952e3 53/63: Allow customizing overlay priority, Noam Postavsky, 2017/07/17
- [elpa] master 1a860bd 51/63: Fix undo information recording for multiline snippets, Noam Postavsky, 2017/07/17
- [elpa] master 22eeb1e 36/63: Fix interaction with c auto-fill, Noam Postavsky, 2017/07/17
- [elpa] master 0311fe2 15/63: Use :filter instead of yas--fallback, Noam Postavsky, 2017/07/17
- [elpa] master 1babe81 40/63: * yasnippet.el (yas-about): Fix compile warnings in previous commit., Noam Postavsky, 2017/07/17
- [elpa] master 2f5cb2e 56/63: Make yas-debug-process-command-line easier to debug, Noam Postavsky, 2017/07/17