branch: master commit 0d9afb2c69214db3f1fc64d18f3dd336a6096233 Author: Etienne <noteti...@users.noreply.github.com> Commit: Noam Postavsky <github.10.npost...@spamgourmet.com>
Fix mirror transformation error with expand-env * yasnippet.el (yas-expand-snippet): Use the snippet's bindings when moving to the first field. This prevents getting an error when using a variable defined in expand-env. * yasnippet-tests.el (snippet-mirror-bindings): New test, check if mirror transformations have access to variables defined in the snippet environment. --- yasnippet-tests.el | 20 ++++++++++++++++++++ yasnippet.el | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index 1c7c94f..432d77d 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -614,6 +614,26 @@ foobaz\n")))) (should (eq 'global (nth 0 yas--ran-exit-hook))) (should (eq 'local (nth 1 yas--ran-exit-hook)))))))) +(ert-deftest snippet-mirror-bindings () + "Check that variables defined with the expand-env field are +accessible from mirror transformations." + (with-temp-buffer + (yas-saving-variables + (let ((yas-triggers-in-field t) + (yas-good-grace nil)) + (yas-with-snippet-dirs + '((".emacs.d/snippets" + ("emacs-lisp-mode" + ("baz" . "\ +# expand-env: ((func #'upcase)) +# -- +hello ${1:$(when (stringp yas-text) (funcall func yas-text))} foo${1:$$(concat \"baz\")}$0")))) + (yas-reload-all) + (emacs-lisp-mode) + (yas-minor-mode +1) + (insert "baz") + (ert-simulate-command '(yas-expand)) + (should (string= (yas--buffer-contents) "hello BAZ foobaz\n"))))))) (defvar yas--barbaz) (defvar yas--foobarbaz) diff --git a/yasnippet.el b/yasnippet.el index 76e1d25..2645121 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3731,7 +3731,8 @@ considered when expanding the snippet." (let ((first-field (car (yas--snippet-fields snippet)))) (when first-field (sit-for 0) ;; fix issue 125 - (yas--move-to-field snippet first-field))) + (yas--letenv (yas--snippet-expand-env snippet) + (yas--move-to-field snippet first-field)))) (yas--message 4 "snippet expanded.") t))))