mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
Refactor yas-good-grace error handling
* yasnippet.el (yas--handle-error): New function. (yas--eval-lisp-no-saves, yas--eval-lisp): Use it.
This commit is contained in:
parent
4ccf133d49
commit
a80033d142
16
yasnippet.el
16
yasnippet.el
@ -1246,6 +1246,12 @@ yasnippet keeps a list of modes like this to help the judgment."
|
|||||||
(or (fboundp mode)
|
(or (fboundp mode)
|
||||||
(find mode yas--known-modes)))
|
(find mode yas--known-modes)))
|
||||||
|
|
||||||
|
(defun yas--handle-error (err)
|
||||||
|
"Handle error depending on value of `yas-good-grace'."
|
||||||
|
(let ((msg (yas--format "elisp error: %s" (error-message-string err))))
|
||||||
|
(if yas-good-grace msg
|
||||||
|
(error msg))))
|
||||||
|
|
||||||
(defun yas--eval-lisp (form)
|
(defun yas--eval-lisp (form)
|
||||||
"Evaluate FORM and convert the result to string."
|
"Evaluate FORM and convert the result to string."
|
||||||
(let ((retval (catch 'yas--exception
|
(let ((retval (catch 'yas--exception
|
||||||
@ -1257,10 +1263,7 @@ yasnippet keeps a list of modes like this to help the judgment."
|
|||||||
(let ((result (eval form)))
|
(let ((result (eval form)))
|
||||||
(when result
|
(when result
|
||||||
(format "%s" result))))))
|
(format "%s" result))))))
|
||||||
(error (if yas-good-grace
|
(error (yas--handle-error err))))))
|
||||||
(yas--format "elisp error! %s" (error-message-string err))
|
|
||||||
(error (yas--format "elisp error: %s"
|
|
||||||
(error-message-string err)))))))))
|
|
||||||
(when (and (consp retval)
|
(when (and (consp retval)
|
||||||
(eq 'yas--exception (car retval)))
|
(eq 'yas--exception (car retval)))
|
||||||
(error (cdr retval)))
|
(error (cdr retval)))
|
||||||
@ -1269,10 +1272,7 @@ yasnippet keeps a list of modes like this to help the judgment."
|
|||||||
(defun yas--eval-lisp-no-saves (form)
|
(defun yas--eval-lisp-no-saves (form)
|
||||||
(condition-case err
|
(condition-case err
|
||||||
(eval form)
|
(eval form)
|
||||||
(error (if yas-good-grace
|
(error (yas--handle-error err))))
|
||||||
(yas--format "elisp error! %s" (error-message-string err))
|
|
||||||
(error (yas--format "elisp error: %s"
|
|
||||||
(error-message-string err)))))))
|
|
||||||
|
|
||||||
(defun yas--read-lisp (string &optional nil-on-error)
|
(defun yas--read-lisp (string &optional nil-on-error)
|
||||||
"Read STRING as a elisp expression and return it.
|
"Read STRING as a elisp expression and return it.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user