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

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

[elpa] master 04062d8 14/51: Don't set yas-selected-text to non-selected


From: Noam Postavsky
Subject: [elpa] master 04062d8 14/51: Don't set yas-selected-text to non-selected text
Date: Sun, 13 May 2018 13:11:41 -0400 (EDT)

branch: master
commit 04062d8b4f7391069058345e1efd673add0357f8
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Don't set yas-selected-text to non-selected text
    
    * yasnippet.el (yas-expand-snippet): Only use the `to-delete' text if
    `region-active-p' return true.
    * yasnippet-tests.el (expand-with-unused-yas-selected-text): New test.
---
 yasnippet-tests.el | 13 +++++++++++++
 yasnippet.el       |  6 ++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 4101454..a773def 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -625,6 +625,19 @@ mapconcat #'(lambda (arg)
     (yas-expand-snippet "${1:$$(if (not yas-modified-p) \"a\")}")
     (yas-expand-snippet "\\\\alpha")))
 
+(ert-deftest expand-with-unused-yas-selected-text ()
+  (with-temp-buffer
+    (yas-with-snippet-dirs
+      '((".emacs.d/snippets"
+         ("emacs-lisp-mode"
+          ("foo" . "expanded `yas-selected-text`foo"))))
+      (yas-reload-all)
+      (emacs-lisp-mode)
+      (yas-minor-mode +1)
+      (insert "foo")
+      (ert-simulate-command '(yas-expand))
+      (should (equal (buffer-string) "expanded foo")))))
+
 (ert-deftest example-for-issue-271 ()
   (with-temp-buffer
     (yas-minor-mode 1)
diff --git a/yasnippet.el b/yasnippet.el
index 52001ed..67a915d 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -3779,8 +3779,10 @@ considered when expanding the snippet."
          (to-delete (and (> end start)
                          (buffer-substring-no-properties start end)))
          (yas-selected-text
-          (or yas-selected-text
-              (if (not clear-field) to-delete)))
+          (cond (yas-selected-text)
+                ((and (region-active-p)
+                      (not clear-field))
+                 to-delete)))
          snippet)
     (goto-char start)
     (setq yas--indent-original-column (current-column))



reply via email to

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