branch: master commit 280ece2af4be2b51629557944feb4f6e36b751f3 Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
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. --- yasnippet-tests.el | 5 ++++- yasnippet.el | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index ae7a8d1..8a845dc 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -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 diff --git a/yasnippet.el b/yasnippet.el index 741ab61..e006d52 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -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