mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
Use debug-on-error to simplify error handling
* yasnippet.el (yas--eval-for-string, yas--safely-run-hook: Let-bind `debug-on-error' according to `yas-good-grace' and add `debug' to condition handler to deduplicate evaluation.
This commit is contained in:
parent
9c9547a628
commit
203df22e26
24
yasnippet.el
24
yasnippet.el
@ -1332,20 +1332,17 @@ Returns (TEMPLATES START END). This function respects
|
||||
|
||||
(defun yas--eval-for-string (form)
|
||||
"Evaluate FORM and convert the result to string."
|
||||
(let ((eval-saving-stuff
|
||||
(lambda (form)
|
||||
(let ((debug-on-error (and (not (memq yas-good-grace '(t inline)))
|
||||
debug-on-error)))
|
||||
(condition-case oops
|
||||
(save-excursion
|
||||
(save-restriction
|
||||
(save-match-data
|
||||
(widen)
|
||||
(let ((result (eval form)))
|
||||
(when result
|
||||
(format "%s" result)))))))))
|
||||
(if (memq yas-good-grace '(t inline))
|
||||
(condition-case oops
|
||||
(funcall eval-saving-stuff form)
|
||||
(error (cdr oops)))
|
||||
(funcall eval-saving-stuff form))))
|
||||
(format "%s" result))))))
|
||||
((debug error) (cdr oops)))))
|
||||
|
||||
(defun yas--eval-for-effect (form)
|
||||
;; FIXME: simulating lexical-binding.
|
||||
@ -3334,15 +3331,14 @@ This renders the snippet as ordinary text."
|
||||
(setq yas--snippets-to-move nil))
|
||||
|
||||
(defun yas--safely-run-hook (hook)
|
||||
(let ((run-the-hook (lambda (hook) (funcall hook))))
|
||||
(if (memq yas-good-grace '(t hooks))
|
||||
(funcall run-the-hook hook)
|
||||
(let ((debug-on-error (and (not (memq yas-good-grace '(t hooks)))
|
||||
debug-on-error)))
|
||||
(condition-case error
|
||||
(funcall run-the-hook hook)
|
||||
(error
|
||||
(funcall hook)
|
||||
((debug error)
|
||||
(yas--message 2 "Error running %s: %s"
|
||||
(if (symbolp hook) hook "a hook")
|
||||
(error-message-string error)))))))
|
||||
(error-message-string error))))))
|
||||
|
||||
|
||||
(defun yas--check-commit-snippet ()
|
||||
|
Loading…
x
Reference in New Issue
Block a user