emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 0d9afb2 31/63: Fix mirror transformation error with expand


From: Noam Postavsky
Subject: [elpa] master 0d9afb2 31/63: Fix mirror transformation error with expand-env
Date: Mon, 17 Jul 2017 22:54:15 -0400 (EDT)

branch: master
commit 0d9afb2c69214db3f1fc64d18f3dd336a6096233
Author: Etienne <address@hidden>
Commit: Noam Postavsky <address@hidden>

    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))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]