* Fix issue with escaping "(", thanks Sebastian

* Add `yas/expand-only-for-last-commands', thanks Erik Postma.
* Fix an issue with primary field transformation after revision 600.
This commit is contained in:
capitaomorte 2010-04-28 08:41:09 +00:00
parent 71af878b70
commit 54c4b7db00

View File

@ -395,7 +395,7 @@ An error string \"[yas] error\" is returned instead."
(defcustom yas/ignore-filenames-as-triggers nil (defcustom yas/ignore-filenames-as-triggers nil
"If non-nil, don't derive tab triggers from filenames. "If non-nil, don't derive tab triggers from filenames.
This means a snippet without a \"# key:'\ directive wont have a This means a snippet without a \"# key:'\ directive won't have a
tab trigger." tab trigger."
:type 'boolean :type 'boolean
:group 'yasnippet) :group 'yasnippet)
@ -407,6 +407,22 @@ This cafn only work when snippets are loaded from files."
:type 'boolean :type 'boolean
:group 'yasnippet) :group 'yasnippet)
(defcustom yas/expand-only-for-last-commands nil
"List of `last-command' values to restrict tab-triggering to, or nil.
Leave this set at nil (the default) to be able to trigger an
expansion simply by placing the cursor after a valid tab trigger,
using whichever commands.
Optionallly, set this to something like '(self-insert-command) if
you to wish restrict expansion to only happen when the last
letter of the snippet tab trigger was typed immediately before
the trigger key itself."
:type '(repeat function)
:group 'yasnippet)
;; Only two faces, and one of them shouldn't even be used...
;;
(defface yas/field-highlight-face (defface yas/field-highlight-face
'((t (:inherit 'region))) '((t (:inherit 'region)))
"The face used to highlight the currently active field of a snippet" "The face used to highlight the currently active field of a snippet"
@ -537,7 +553,7 @@ snippet itself contains a condition that returns the symbol
"A list of mode which is well known but not part of emacs.") "A list of mode which is well known but not part of emacs.")
(defvar yas/escaped-characters (defvar yas/escaped-characters
'(?\\ ?` ?' ?$ ?} ) '(?\\ ?` ?' ?$ ?} ?\( ?\))
"List of characters which *might* need to be escaped.") "List of characters which *might* need to be escaped.")
(defconst yas/field-regexp (defconst yas/field-regexp
@ -2120,14 +2136,20 @@ Optional argument FIELD is for non-interactive use and is an
object satisfying `yas/field-p' to restrict the expansion to." object satisfying `yas/field-p' to restrict the expansion to."
(interactive) (interactive)
(setq yas/condition-cache-timestamp (current-time)) (setq yas/condition-cache-timestamp (current-time))
(multiple-value-bind (templates start end) (if field (let (templates-and-pos)
(save-restriction (unless (and yas/expand-only-for-last-commands
(narrow-to-region (yas/field-start field) (not (member last-command yas/expand-only-for-last-commands)))
(yas/field-end field)) (setq templates-and-pos (if field
(yas/current-key)) (save-restriction
(yas/current-key)) (narrow-to-region (yas/field-start field)
(if templates (yas/field-end field))
(yas/expand-or-prompt-for-template templates start end) (yas/current-key))
(yas/current-key))))
(if (and templates-and-pos
(first templates-and-pos))
(yas/expand-or-prompt-for-template (first templates-and-pos)
(second templates-and-pos)
(third templates-and-pos))
(yas/fallback 'trigger-key)))) (yas/fallback 'trigger-key))))
(defun yas/expand-from-keymap () (defun yas/expand-from-keymap ()
@ -2726,7 +2748,9 @@ Otherwise throw exception."
(yas/throw (format "[yas] field only allows %s" possibilities)))) (yas/throw (format "[yas] field only allows %s" possibilities))))
(defun yas/field-value (number) (defun yas/field-value (number)
"A primary field transformation..." "Get the string for field with NUMBER.
Use this in primary and mirror transformations to tget."
(let* ((snippet (car (yas/snippets-at-point))) (let* ((snippet (car (yas/snippets-at-point)))
(field (and snippet (field (and snippet
(yas/snippet-find-field snippet number)))) (yas/snippet-find-field snippet number))))
@ -2824,9 +2848,13 @@ Otherwise throw exception."
marker marker
next) next)
(defun yas/apply-transform (field-or-mirror field) (defun yas/apply-transform (field-or-mirror field &optional empty-on-nil-p)
"Calculate the value of the field/mirror. If there's a transform "Calculate transformed string for FIELD-OR-MIRROR from FIELD.
for this field, apply it. Otherwise, returned nil."
If there is no transform for ht field, return nil.
If there is a transform but it returns nil, return the empty
string iff EMPTY-ON-NIL-P is true."
(let* ((yas/text (yas/field-text-for-display field)) (let* ((yas/text (yas/field-text-for-display field))
(text yas/text) (text yas/text)
(yas/modified-p (yas/field-modified-p field)) (yas/modified-p (yas/field-modified-p field))
@ -2841,7 +2869,7 @@ for this field, apply it. Otherwise, returned nil."
(save-excursion (save-excursion
(goto-char start-point) (goto-char start-point)
(let ((ret (yas/eval-lisp transform))) (let ((ret (yas/eval-lisp transform)))
(or ret "")))))) (or ret (and empty-on-nil-p "")))))))
transformed)) transformed))
(defsubst yas/replace-all (from to &optional text) (defsubst yas/replace-all (from to &optional text)
@ -4030,7 +4058,7 @@ When multiple expressions are found, only the last one counts."
(let* ((mirror-parent-field (yas/mirror-parent-field mirror)) (let* ((mirror-parent-field (yas/mirror-parent-field mirror))
(reflection (and (not (and mirror-parent-field (reflection (and (not (and mirror-parent-field
(yas/field-modified-p mirror-parent-field))) (yas/field-modified-p mirror-parent-field)))
(or (yas/apply-transform mirror field) (or (yas/apply-transform mirror field 'empty-on-nil)
(yas/field-text-for-display field))))) (yas/field-text-for-display field)))))
(when (and reflection (when (and reflection
(not (string= reflection (buffer-substring-no-properties (yas/mirror-start mirror) (not (string= reflection (buffer-substring-no-properties (yas/mirror-start mirror)