mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
* enhanced good grace and fixed `yas/trigger-in-field' bug
This commit is contained in:
parent
5c7e870891
commit
c15f037874
37
yasnippet.el
37
yasnippet.el
@ -186,7 +186,9 @@ can be overriden on a per-snippet basis."
|
|||||||
(defcustom yas/good-grace nil
|
(defcustom yas/good-grace nil
|
||||||
"If non-nil, don't raise errors in inline elisp evaluation.
|
"If non-nil, don't raise errors in inline elisp evaluation.
|
||||||
|
|
||||||
The erorr string is instead returned."
|
An error string \"[yas] error\" is returned instead."
|
||||||
|
|
||||||
|
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'yasnippet)
|
:group 'yasnippet)
|
||||||
|
|
||||||
@ -503,6 +505,7 @@ a list of modes like this to help the judgement."
|
|||||||
;; TODO: This is a possible optimization point, the expression could
|
;; TODO: This is a possible optimization point, the expression could
|
||||||
;; be stored in cons format instead of string,
|
;; be stored in cons format instead of string,
|
||||||
"Evaluate STRING and convert the result to string."
|
"Evaluate STRING and convert the result to string."
|
||||||
|
(let ((retval (catch 'yas/exception
|
||||||
(condition-case err
|
(condition-case err
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(save-restriction
|
(save-restriction
|
||||||
@ -512,10 +515,13 @@ a list of modes like this to help the judgement."
|
|||||||
(when result
|
(when result
|
||||||
(format "%s" result))))))
|
(format "%s" result))))))
|
||||||
(error (if yas/good-grace
|
(error (if yas/good-grace
|
||||||
(format "([yas] elisp error: %s"
|
"[yas] elisp error!"
|
||||||
(error-message-string err))
|
(error (format "[yas] elisp error: %s"
|
||||||
(error (format "([yas] elisp error: %s"
|
(error-message-string err)))))))))
|
||||||
(error-message-string err)))))))
|
(when (and (consp retval)
|
||||||
|
(eq 'yas/exception (car retval)))
|
||||||
|
(error (cdr retval)))
|
||||||
|
retval))
|
||||||
|
|
||||||
(defun yas/snippet-table (mode)
|
(defun yas/snippet-table (mode)
|
||||||
"Get the snippet table corresponding to MODE."
|
"Get the snippet table corresponding to MODE."
|
||||||
@ -927,10 +933,14 @@ when the condition evaluated to non-nil."
|
|||||||
(symbolp (cdr local-condition))
|
(symbolp (cdr local-condition))
|
||||||
(cdr local-condition))))
|
(cdr local-condition))))
|
||||||
|
|
||||||
(defun yas/expand ()
|
(defun yas/expand (&optional field)
|
||||||
"Expand a snippet."
|
"Expand a snippet."
|
||||||
(interactive)
|
(interactive)
|
||||||
(multiple-value-bind (templates start end) (yas/current-key)
|
(multiple-value-bind (templates start end) (if field
|
||||||
|
(save-restriction
|
||||||
|
(narrow-to-region (yas/field-start field) (yas/field-end field))
|
||||||
|
(yas/current-key))
|
||||||
|
(yas/current-key))
|
||||||
(if templates
|
(if templates
|
||||||
(let ((template-content (or (and (rest templates) ;; more than one
|
(let ((template-content (or (and (rest templates) ;; more than one
|
||||||
(yas/prompt-for-template-content (mapcar #'cdr templates)))
|
(yas/prompt-for-template-content (mapcar #'cdr templates)))
|
||||||
@ -973,9 +983,12 @@ to `yas/prompt-function'."
|
|||||||
(funcall fn "Choose: " possibilities))
|
(funcall fn "Choose: " possibilities))
|
||||||
yas/prompt-functions))
|
yas/prompt-functions))
|
||||||
|
|
||||||
|
(defun yas/throw (text)
|
||||||
|
(throw 'yas/exception (cons 'yas/exception text)))
|
||||||
|
|
||||||
(defun yas/verify-value (&rest possibilities)
|
(defun yas/verify-value (&rest possibilities)
|
||||||
(when (and yas/moving-away (notany #'(lambda (pos) (string= pos yas/text)) possibilities))
|
(when (and yas/moving-away (notany #'(lambda (pos) (string= pos yas/text)) possibilities))
|
||||||
(error "field only allows " possibilities)))
|
(yas/throw (format "[yas] field only allows %s" possibilities))))
|
||||||
|
|
||||||
(defun yas/field-value (number)
|
(defun yas/field-value (number)
|
||||||
(let ((snippet (car (yas/snippets-at-point)))
|
(let ((snippet (car (yas/snippets-at-point)))
|
||||||
@ -1100,8 +1113,10 @@ inserted first."
|
|||||||
delegate to `yas/next-field'."
|
delegate to `yas/next-field'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(if yas/triggers-in-field
|
(if yas/triggers-in-field
|
||||||
(let ((yas/fallback-behavior 'return-nil))
|
(let ((yas/fallback-behavior 'return-nil)
|
||||||
(unless (yas/expand)
|
(active-field (overlay-get yas/active-field-overlay 'yas/field)))
|
||||||
|
(when active-field
|
||||||
|
(unless (yas/expand active-field))
|
||||||
(yas/next-field)))
|
(yas/next-field)))
|
||||||
(yas/next-field)))
|
(yas/next-field)))
|
||||||
|
|
||||||
@ -1911,7 +1926,7 @@ When multiple expressions are found, only the last one counts."
|
|||||||
("}"
|
("}"
|
||||||
(0 font-lock-keyword-face)))))
|
(0 font-lock-keyword-face)))))
|
||||||
|
|
||||||
(define-derived-mode yas/snippet-editing-mode emacs-lisp-mode "YASnippet"
|
(define-derived-mode yas/snippet-editing-mode fundamental-mode "YASnippet"
|
||||||
"A mode for editing yasnippets"
|
"A mode for editing yasnippets"
|
||||||
(setq font-lock-defaults '(yas/font-lock-keywords)))
|
(setq font-lock-defaults '(yas/font-lock-keywords)))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user