[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 6e9b7f9 30/63: Fix running hook variable set as buffer-loc
From: |
Noam Postavsky |
Subject: |
[elpa] master 6e9b7f9 30/63: Fix running hook variable set as buffer-local |
Date: |
Mon, 17 Jul 2017 22:54:15 -0400 (EDT) |
branch: master
commit 6e9b7f9432a87122cf9bb80a505be2fd9811a9cf
Author: Etienne <address@hidden>
Commit: Noam Postavsky <address@hidden>
Fix running hook variable set as buffer-local
* yasnippet.el (yas--eval-for-effect): Use `yas--safely-call-fun'
instead of `yas--safely-run-hook'.
(yas--safely-call-fun): Display the called argument (even a lambda) on
errors.
(yas--safely-run-hook): Take a hook variable instead of the hook value
itself. Use `run-hooks' to take buffer-local values into account.
This means it’s no longer possible to warn which hook function had an
error.
(yas--check-commit-snippet): Refactor to conform to
`yas--safely-run-hooks'.
* yasnippet-tests.el (snippet-exit-hooks-bindings): New test that
checks for buffer-local, global and env hooks support.
---
yasnippet-tests.el | 32 ++++++++++++++++++++++++++++++++
yasnippet.el | 22 +++++++++++++---------
2 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index dc0c43c..1c7c94f 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -583,6 +583,38 @@ SUB"))))
(ert-simulate-command '(yas-next-field))
(should (eq yas--ran-exit-hook t)))))))
+(ert-deftest snippet-exit-hooks-bindings ()
+ "Check that `yas-after-exit-snippet-hook' is handled correctly
+in the case of a buffer-local variable and being overwritten by
+the expand-env field."
+ (defvar yas--ran-exit-hook)
+ (with-temp-buffer
+ (yas-saving-variables
+ (let ((yas--ran-exit-hook nil)
+ (yas-triggers-in-field t)
+ (yas-after-exit-snippet-hook nil))
+ (yas-with-snippet-dirs
+ '((".emacs.d/snippets"
+ ("emacs-lisp-mode"
+ ("foo" . "foobar\n")
+ ("baz" . "\
+# expand-env: ((yas-after-exit-snippet-hook (lambda () (setq
yas--ran-exit-hook 'letenv))))
+# --
+foobaz\n"))))
+ (yas-reload-all)
+ (emacs-lisp-mode)
+ (yas-minor-mode +1)
+ (add-hook 'yas-after-exit-snippet-hook (lambda () (push 'global
yas--ran-exit-hook)))
+ (add-hook 'yas-after-exit-snippet-hook (lambda () (push 'local
yas--ran-exit-hook)) nil t)
+ (insert "baz")
+ (ert-simulate-command '(yas-expand))
+ (should (eq 'letenv yas--ran-exit-hook))
+ (insert "foo")
+ (ert-simulate-command '(yas-expand))
+ (should (eq 'global (nth 0 yas--ran-exit-hook)))
+ (should (eq 'local (nth 1 yas--ran-exit-hook))))))))
+
+
(defvar yas--barbaz)
(defvar yas--foobarbaz)
diff --git a/yasnippet.el b/yasnippet.el
index 7b871b9..76e1d25 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -1352,7 +1352,7 @@ Returns (TEMPLATES START END). This function respects
((debug error) (cdr oops)))))
(defun yas--eval-for-effect (form)
- (yas--safely-run-hook (apply-partially #'eval form)))
+ (yas--safely-call-fun (apply-partially #'eval form)))
(defun yas--read-lisp (string &optional nil-on-error)
"Read STRING as a elisp expression and return it.
@@ -3336,18 +3336,19 @@ This renders the snippet as ordinary text."
(setq yas--snippets-to-move nil))
(defun yas--safely-call-fun (fun)
+ "Call FUN and catch any errors."
(condition-case error
(funcall fun)
((debug error)
- (yas--message 2 "Error running %s: %s"
- (if (symbolp fun) fun "a hook")
+ (yas--message 2 "Error running %s: %s" fun
(error-message-string error)))))
(defun yas--safely-run-hook (hook)
+ "Call HOOK's functions.
+HOOK should be a symbol, a hook variable, as in `run-hooks'."
(let ((debug-on-error (and (not (memq yas-good-grace '(t hooks)))
debug-on-error)))
- (if (functionp hook) (yas--safely-call-fun hook)
- (mapc #'yas--safely-call-fun hook))))
+ (yas--safely-call-fun (apply-partially #'run-hooks hook))))
(defun yas--check-commit-snippet ()
"Check if point exited the currently active field of the snippet.
@@ -3355,7 +3356,9 @@ This renders the snippet as ordinary text."
If so cleans up the whole snippet up."
(let* ((snippets (yas-active-snippets 'all))
(snippets-left snippets)
- (snippet-exit-transform nil)
+ (snippet-exit-transform)
+ ;; Record the custom snippet `yas-after-exit-snippet-hook'
+ ;; set in the expand-env field.
(snippet-exit-hook yas-after-exit-snippet-hook))
(dolist (snippet snippets)
(let ((active-field (yas--snippet-active-field snippet)))
@@ -3383,9 +3386,10 @@ If so cleans up the whole snippet up."
(t
nil)))))
(unless (or (null snippets) snippets-left)
- (if snippet-exit-transform
- (yas--eval-for-effect snippet-exit-transform))
- (yas--safely-run-hook snippet-exit-hook))))
+ (when snippet-exit-transform
+ (yas--eval-for-effect snippet-exit-transform))
+ (let ((yas-after-exit-snippet-hook snippet-exit-hook))
+ (yas--safely-run-hook 'yas-after-exit-snippet-hook)))))
;; Apropos markers-to-points:
;;
- [elpa] master ac26024 20/63: Rework error handling, (continued)
- [elpa] master ac26024 20/63: Rework error handling, Noam Postavsky, 2017/07/17
- [elpa] master c3a9447 43/63: Fix condition timestamps in key filter functions, Noam Postavsky, 2017/07/17
- [elpa] master 82818e5 48/63: Don't delete snippets more than once., Noam Postavsky, 2017/07/17
- [elpa] master 63f44b4 33/63: Ensure inhibit-modification-hooks is nil while modifying buffer, Noam Postavsky, 2017/07/17
- [elpa] master 0041efe 17/63: Make snippets work in org source blocks, Noam Postavsky, 2017/07/17
- [elpa] master 47f37f7 42/63: Fix ${0:soon-to-be-deleted} with no other fields, Noam Postavsky, 2017/07/17
- [elpa] master e8ed276 52/63: Make sure tests don't rely on running order, Noam Postavsky, 2017/07/17
- [elpa] master 2a3a0cd 61/63: Update CONTRIBUTING.md information, Noam Postavsky, 2017/07/17
- [elpa] master b0e729b 58/63: Optionally add undo list to debug info, Noam Postavsky, 2017/07/17
- [elpa] master 274406e 55/63: Provide command line interface from yasnippet-debug.el, Noam Postavsky, 2017/07/17
- [elpa] master 6e9b7f9 30/63: Fix running hook variable set as buffer-local,
Noam Postavsky <=
- [elpa] master 7f337f4 32/63: Fix nested snippet expansion, Noam Postavsky, 2017/07/17
- [elpa] master 1bf7a4c 47/63: Fix field parsing in modes that use the `syntax-table' property, Noam Postavsky, 2017/07/17
- [elpa] master 8797a31 45/63: * doc/snippet-expansion.org: Complete sentence fragment., Noam Postavsky, 2017/07/17
- [elpa] master c87afe0 26/63: Merge: snippet-local exit hook; error handling improvements, Noam Postavsky, 2017/07/17
- [elpa] master 1043b6c 49/63: Restore syntax-propertize-function before indenting mirrors, Noam Postavsky, 2017/07/17
- [elpa] master 65952e3 53/63: Allow customizing overlay priority, Noam Postavsky, 2017/07/17
- [elpa] master 1a860bd 51/63: Fix undo information recording for multiline snippets, Noam Postavsky, 2017/07/17
- [elpa] master 22eeb1e 36/63: Fix interaction with c auto-fill, Noam Postavsky, 2017/07/17
- [elpa] master 0311fe2 15/63: Use :filter instead of yas--fallback, Noam Postavsky, 2017/07/17
- [elpa] master 1babe81 40/63: * yasnippet.el (yas-about): Fix compile warnings in previous commit., Noam Postavsky, 2017/07/17