branch: master
commit 1cf723a408800b489a5f74bd14219a74b665a7f3
Author: Sharif Nassar <[email protected]>
Commit: Noam Postavsky <[email protected]>
Ignore trailing spaces in snippet definitions
Probably nobody wants a snippet `key` with a trailing space. It can
be hard to differentiate from a `key` without trailing space. The
default `<TAB>` behavior of yasnippet will never expand these.
* yasnippet.el (yas--parse-template): Ignore trailing spaces in snippet
definitions.
* yasnippet-tests.el (deftest ignore-trailing-whitespace): New test for
new behavior.
Copyright-paperwork-exempt: yes
---
yasnippet-tests.el | 9 +++++++++
yasnippet.el | 2 +-
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index b71ea7e..9a1e2c2 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -123,6 +123,15 @@
(should (looking-at "ble"))
(should (null (yas--snippets-at-point)))))
+(ert-deftest ignore-trailing-whitespace ()
+ (should (equal
+ (with-temp-buffer
+ (insert "# key: foo\n# --\nfoo")
+ (yas--parse-template))
+ (with-temp-buffer
+ (insert "# key: foo \n# --\nfoo")
+ (yas--parse-template)))))
+
;; (ert-deftest in-snippet-undo ()
;; (with-temp-buffer
;; (yas-minor-mode 1)
diff --git a/yasnippet.el b/yasnippet.el
index ef6a763..c456247 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -1448,7 +1448,7 @@ Here's a list of currently recognized directives:
(point-max)))
(setq bound (point))
(goto-char (point-min))
- (while (re-search-forward "^# *\\([^ ]+?\\) *: *\\(.*\\)$"
bound t)
+ (while (re-search-forward "^# *\\([^ ]+?\\) *:
*\\(.*?\\)[[:space:]]*$" bound t)
(when (string= "uuid" (match-string-no-properties 1))
(setq uuid (match-string-no-properties 2)))
(when (string= "type" (match-string-no-properties 1))