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:
Noam Postavsky 2016-05-18 07:41:53 -04:00
parent 9c9547a628
commit 203df22e26

View File

@ -1332,20 +1332,17 @@ Returns (TEMPLATES START END). This function respects
(defun yas--eval-for-string (form) (defun yas--eval-for-string (form)
"Evaluate FORM and convert the result to string." "Evaluate FORM and convert the result to string."
(let ((eval-saving-stuff (let ((debug-on-error (and (not (memq yas-good-grace '(t inline)))
(lambda (form) debug-on-error)))
(save-excursion (condition-case oops
(save-restriction (save-excursion
(save-match-data (save-restriction
(widen) (save-match-data
(let ((result (eval form))) (widen)
(when result (let ((result (eval form)))
(format "%s" result))))))))) (when result
(if (memq yas-good-grace '(t inline)) (format "%s" result))))))
(condition-case oops ((debug error) (cdr oops)))))
(funcall eval-saving-stuff form)
(error (cdr oops)))
(funcall eval-saving-stuff form))))
(defun yas--eval-for-effect (form) (defun yas--eval-for-effect (form)
;; FIXME: simulating lexical-binding. ;; FIXME: simulating lexical-binding.
@ -3334,15 +3331,14 @@ This renders the snippet as ordinary text."
(setq yas--snippets-to-move nil)) (setq yas--snippets-to-move nil))
(defun yas--safely-run-hook (hook) (defun yas--safely-run-hook (hook)
(let ((run-the-hook (lambda (hook) (funcall hook)))) (let ((debug-on-error (and (not (memq yas-good-grace '(t hooks)))
(if (memq yas-good-grace '(t hooks)) debug-on-error)))
(funcall run-the-hook hook) (condition-case error
(condition-case error (funcall hook)
(funcall run-the-hook hook) ((debug error)
(error (yas--message 2 "Error running %s: %s"
(yas--message 2 "Error running %s: %s" (if (symbolp hook) hook "a hook")
(if (symbolp hook) hook "a hook") (error-message-string error))))))
(error-message-string error)))))))
(defun yas--check-commit-snippet () (defun yas--check-commit-snippet ()