branch: master
commit 316435e03eb296aec15605390cde04dc5bf8a525
Author: João Távora <[email protected]>
Commit: João Távora <[email protected]>
Closes #562: Deleting inner numberless snippet causes error
* yasnippet.el (yas--field-probably-deleted-p): Protect against
nil `yas--field-number'.
* yasnippet-tests.el (delete-numberless-inner-snippet-issue-562): New test
---
yasnippet-tests.el | 11 +++++++++++
yasnippet.el | 3 ++-
2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 7499640..150e1d0 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -112,6 +112,17 @@
(ert-simulate-command `(yas-mock-insert "abc"))
(should (string= (yas--buffer-contents) "abcabcabcabc"))))
+(ert-deftest delete-numberless-inner-snippet-issue-562 ()
+ (with-temp-buffer
+ (yas-minor-mode 1)
+ (yas-expand-snippet "${3:${test}bla}$0${2:ble}")
+ (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))
+ (should (looking-at "ble"))
+ (should (null (yas--snippets-at-point)))))
+
;; (ert-deftest in-snippet-undo ()
;; (with-temp-buffer
;; (yas-minor-mode 1)
diff --git a/yasnippet.el b/yasnippet.el
index 8c9212c..2a2254b 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -3016,7 +3016,8 @@ through the field's start point"
;; the field numbered 0, just before the exit marker, should
;; never be skipped
;;
- (not (zerop (yas--field-number field)))))
+ (not (and (yas--field-number field)
+ (zerop (yas--field-number field))))))
(defun yas--snippets-at-point (&optional all-snippets)
"Return a sorted list of snippets at point.