branch: master
commit de34d91a3c149993526370f98cf36eb6da565976
Author: Noam Postavsky <[email protected]>
Commit: Noam Postavsky <[email protected]>
Closes #470, handle non-whitespace newlines
Many modes put newlines in comment ender class because they have line
comments.
* yasnippet.el (yas-try-key-from-whitespace): new function.
(yas-key-syntaxes): use it in place of "^ ".
* yasnippet-tests.el (complicated-yas-key-syntaxes): test it.
---
yasnippet-tests.el | 12 ++++++++----
yasnippet.el | 14 +++++++++++++-
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index f40ed25..ae7a8d1 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -322,12 +322,13 @@ TODO: correct this bug!"
(yas-saving-variables
(yas-with-snippet-dirs
'((".emacs.d/snippets"
- ("text-mode"
+ ("emacs-lisp-mode"
("foo-barbaz" . "# condition: yas--foobarbaz\n# --\nOKfoo-barbazOK")
("barbaz" . "# condition: yas--barbaz\n# --\nOKbarbazOK")
- ("baz" . "OKbazOK"))))
+ ("baz" . "OKbazOK")
+ ("'quote" . "OKquoteOK"))))
(yas-reload-all)
- (text-mode)
+ (emacs-lisp-mode)
(yas-minor-mode-on)
(let ((yas-key-syntaxes '("w" "w_")))
(let ((yas--barbaz t))
@@ -342,7 +343,10 @@ TODO: correct this bug!"
'again))
yas-key-syntaxes))
(yas--foobarbaz t))
- (yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK")))))))))
+ (yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK")))))
+ (let ((yas-key-syntaxes '(yas-try-key-from-whitespace)))
+ (yas-should-expand '(("xxx\n'quote" . "xxx\nOKquoteOK")
+ ("xxx 'quote" . "xxx OKquoteOK"))))))))
;;; Loading
diff --git a/yasnippet.el b/yasnippet.el
index fc5d36b..741ab61 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -388,7 +388,8 @@ the trigger key itself."
map)
"The active keymap while a snippet expansion is in progress.")
-(defvar yas-key-syntaxes (list "w" "w_" "w_." "w_.()" "^ ")
+(defvar yas-key-syntaxes (list "w" "w_" "w_." "w_.()"
+ #'yas-try-key-from-whitespace)
"Syntaxes and functions to help look for trigger keys before point.
Each element in this list specifies how to skip buffer positions
@@ -2726,6 +2727,17 @@ and `kill-buffer' instead."
+;;; User convenience functions, for using in `yas-key-syntaxes'
+
+(defun yas-try-key-from-whitespace ()
+ "Go back to nearest whitespace.
+
+A newline will be considered whitespace even if the mode syntax
+marks it as something else (typically comment ender). Use as
+element of `yas-key-syntaxes'."
+ (skip-chars-backward "^[:space:]\n"))
+
+
;;; User convenience functions, for using in snippet definitions
(defvar yas-modified-p nil