Add yas-shortest-key-until-whitespace

Example yas-key-syntaxes function.

* yasnippet.el (yas-shortest-key-until-whitespace): new function.
* yasnippet-tests.el (complicated-yas-key-syntaxes): test it.
This commit is contained in:
Noam Postavsky 2014-08-10 12:47:22 -04:00
parent de34d91a3c
commit 280ece2af4
2 changed files with 13 additions and 1 deletions

View File

@ -346,7 +346,10 @@ TODO: correct this bug!"
(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"))))))))
("xxx 'quote" . "xxx OKquoteOK"))))
(let ((yas-key-syntaxes '(yas-shortest-key-until-whitespace))
(yas--foobarbaz t) (yas--barbaz t))
(yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK"))))))))
;;; Loading

View File

@ -2737,6 +2737,15 @@ marks it as something else (typically comment ender). Use as
element of `yas-key-syntaxes'."
(skip-chars-backward "^[:space:]\n"))
(defun yas-shortest-key-until-whitespace ()
"Return `again' until at 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'."
(when (/= (skip-chars-backward "^[:space:]\n" (1- (point))) 0)
'again))
;;; User convenience functions, for using in snippet definitions