]> code.delx.au - gnu-emacs-elpa/commitdiff
Add yas-longest-key-from-whitespace
authorNoam Postavsky <npostavs@users.sourceforge.net>
Sun, 10 Aug 2014 17:07:43 +0000 (13:07 -0400)
committerNoam Postavsky <npostavs@users.sourceforge.net>
Sun, 10 Aug 2014 18:05:25 +0000 (14:05 -0400)
Example yas-key-syntaxes function.

* yasnippet.el (yas-longest-key-from-whitespace): new function.
* yasnippet-tests.el (complicated-yas-key-syntaxes): test it.

yasnippet-tests.el
yasnippet.el

index 12ca61528d16a2f68bae322da7b9ee877f20e8ec..d090c511dd884253385c74d30cb21647be5a545c 100644 (file)
@@ -349,7 +349,9 @@ TODO: correct this bug!"
                               ("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"))))))))
+         (yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK")))
+         (setq yas-key-syntaxes '(yas-longest-key-from-whitespace))
+         (yas-should-expand '(("foo-barbaz" . "OKfoo-barbazOK"))))))))
 
 \f
 ;;; Loading
index 93eceb24a247c93e6154b9e89155028738af7196..dcf6bf0575e3b409cd666b568199e781e046163f 100644 (file)
@@ -2746,6 +2746,19 @@ element of `yas-key-syntaxes'."
   (when (/= (skip-chars-backward "^[:space:]\n" (1- (point))) 0)
     'again))
 
+(defun yas-longest-key-from-whitespace (start-point)
+  "Go back to nearest whitespace, then go forward and return `again' until at START-POINT.
+
+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'."
+  (if (= (point) start-point)
+      (yas-try-key-from-whitespace start-point)
+    (forward-char))
+  (unless (= original (1+ (point)))
+    'again))
+
+
 \f
 ;;; User convenience functions, for using in snippet definitions