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.
This commit is contained in:
Noam Postavsky 2014-08-10 12:21:47 -04:00
parent faed1062a2
commit de34d91a3c
2 changed files with 21 additions and 5 deletions

View File

@ -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

View File

@ -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
@ -2725,6 +2726,17 @@ and `kill-buffer' instead."
groups-hash)))
;;; 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