[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e60e8b5 136/177: Merge pull request #503 from npostavs/key
From: |
João Távora |
Subject: |
[elpa] master e60e8b5 136/177: Merge pull request #503 from npostavs/key-syntaxes |
Date: |
Sat, 28 Mar 2015 15:41:27 +0000 |
branch: master
commit e60e8b55518ede19b995c5b49ba69873ee4dc1d3
Merge: faed106 d982b70
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Merge pull request #503 from npostavs/key-syntaxes
More yas-key-syntaxes functions
---
yasnippet-tests.el | 20 +++++++++++++++-----
yasnippet.el | 44 ++++++++++++++++++++++++++++++++++++--------
2 files changed, 51 insertions(+), 13 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index f40ed25..4b3a440 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))
@@ -336,13 +337,22 @@ TODO: correct this bug!"
(let ((yas--foobarbaz t))
(yas-should-expand '(("foo-barbaz" . "OKfoo-barbazOK"))))
(let ((yas-key-syntaxes
- (cons #'(lambda ()
+ (cons #'(lambda (_start-point)
(unless (looking-back "-")
(backward-char)
'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"))))
+ (let ((yas-key-syntaxes '(yas-shortest-key-until-whitespace))
+ (yas--foobarbaz t) (yas--barbaz t))
+ (yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK")))
+ (setq yas-key-syntaxes '(yas-longest-key-from-whitespace))
+ (yas-should-expand '(("foo-barbaz" . "OKfoo-barbazOK")
+ ("foo " . "foo "))))))))
;;; Loading
diff --git a/yasnippet.el b/yasnippet.el
index fc5d36b..ea5fe33 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -388,21 +388,22 @@ 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
backwards and look for the start of a trigger key.
-Each element can be either a string or a functino of no
-arguments. A string element is simply passed to
-`skip-syntax-backward' whereas a function element is called with
-no arguments and should also place point before the original
+Each element can be either a string or a function receiving the
+original point as an argument. A string element is simply passed
+to `skip-syntax-backward' whereas a function element is called
+with no arguments and should also place point before the original
position.
The string between the resulting buffer position and the original
-point.in the is matched against the trigger keys in the active
-snippet tables.
+point is matched against the trigger keys in the active snippet
+tables.
If no expandable snippets are found, the next element is the list
is tried, unless a function element returned the symbol `again',
@@ -1238,7 +1239,7 @@ Returns (TEMPLATES START END). This function respects
(skip-syntax-backward method)
(setq methods (cdr methods)))
((functionp method)
- (unless (eq (funcall method)
+ (unless (eq (funcall method original)
'again)
(setq methods (cdr methods))))
(t
@@ -2726,6 +2727,33 @@ and `kill-buffer' instead."
+;;; User convenience functions, for using in `yas-key-syntaxes'
+
+(defun yas-try-key-from-whitespace (_start-point)
+ "As `yas-key-syntaxes' element, look for whitespace delimited key.
+
+A newline will be considered whitespace even if the mode syntax
+marks it as something else (typically comment ender)."
+ (skip-chars-backward "^[:space:]\n"))
+
+(defun yas-shortest-key-until-whitespace (_start-point)
+ "Like `yas-longest-key-from-whitespace' but take the shortest key."
+ (when (/= (skip-chars-backward "^[:space:]\n" (1- (point))) 0)
+ 'again))
+
+(defun yas-longest-key-from-whitespace (start-point)
+ "As `yas-key-syntaxes' element, look for longest key between point and
whitespace.
+
+A newline will be considered whitespace even if the mode syntax
+marks it as something else (typically comment ender)."
+ (if (= (point) start-point)
+ (yas-try-key-from-whitespace start-point)
+ (forward-char))
+ (unless (<= start-point (1+ (point)))
+ 'again))
+
+
+
;;; User convenience functions, for using in snippet definitions
(defvar yas-modified-p nil
- [elpa] master 7761dee 128/177: Closes #497: Allow functions as elements in yas-key-syntaxes, (continued)
- [elpa] master 7761dee 128/177: Closes #497: Allow functions as elements in yas-key-syntaxes, João Távora, 2015/03/28
- [elpa] master faed106 129/177: * yasnippet.el (yas-key-syntaxes): Improve documentation., João Távora, 2015/03/28
- [elpa] master de34d91 130/177: Closes #470, handle non-whitespace newlines, João Távora, 2015/03/28
- [elpa] master 6b04dad 120/177: Document type directive, João Távora, 2015/03/28
- [elpa] master 10ecde1 132/177: Pass start point to yas-key-syntaxes functions, João Távora, 2015/03/28
- [elpa] master 47a3d5f 134/177: Fix yas-key-syntaxes example functions docstrings., João Távora, 2015/03/28
- [elpa] master d982b70 135/177: Fix edge case in yas-longest-key-from-whitespace, João Távora, 2015/03/28
- [elpa] master 5d10b5d 133/177: Add yas-longest-key-from-whitespace, João Távora, 2015/03/28
- [elpa] master f7ef023 137/177: Prevent disabling errors from recent `yas-current-syntaxes` logic, João Távora, 2015/03/28
- [elpa] master 1d4618b 138/177: Closes #504: Correctly discover buffers needing snippets immediately, João Távora, 2015/03/28
- [elpa] master e60e8b5 136/177: Merge pull request #503 from npostavs/key-syntaxes,
João Távora <=
- [elpa] master 5b59b80 139/177: Closes #495: Allow symbols as aliases in `yas-snippet-dirs', João Távora, 2015/03/28
- [elpa] master be2f815 140/177: Closes #508: Ensure original point when evaluating conditions, João Távora, 2015/03/28
- [elpa] master 241465c 141/177: move eof footer to the actual eof, João Távora, 2015/03/28
- [elpa] master 70de821 143/177: enforce use of spaces for indentation, João Távora, 2015/03/28
- [elpa] master 41cb5f5 145/177: Update snippets submodule, João Távora, 2015/03/28
- [elpa] master cc64ff6 144/177: Merge pull request #514 from tarsius/master, João Távora, 2015/03/28
- [elpa] master 8e9bf3c 147/177: Merge pull request #518 from rnkn/master, João Távora, 2015/03/28
- [elpa] master 6f7c915 146/177: Compatibility with custom-unlispify-remove-prefixes, João Távora, 2015/03/28
- [elpa] master 783cc33 148/177: Use cl-incf instead of cl, João Távora, 2015/03/28
- [elpa] master 08b044e 149/177: Merge pull request #519 from syohex/use-cl-macro, João Távora, 2015/03/28