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

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

[elpa] master 4ccf133 114/177: Merge pull request #476 from npostavs/cc-


From: João Távora
Subject: [elpa] master 4ccf133 114/177: Merge pull request #476 from npostavs/cc-fontify2
Date: Sat, 28 Mar 2015 15:41:19 +0000

branch: master
commit 4ccf133d49088b9914ab65fcd9694f641e45a082
Merge: 4d9eee9 599a262
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Merge pull request #476 from npostavs/cc-fontify2
    
    Avoid changing buffer while narrowed
---
 yasnippet-tests.el |   74 ++++++++++++++++++++++++---------------------------
 yasnippet.el       |    3 +-
 2 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 02bf10c..f87b3d4 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -204,60 +204,56 @@
       (ert-simulate-command `(yas-mock-insert "bbb"))
       (should (string= (yas--buffer-contents) "if 
condition\naaa\nelse\nbbb\nend")))))
 
+(defmacro yas--with-font-locked-temp-buffer (&rest body)
+  "Like `with-temp-buffer', but ensure `font-lock-mode'."
+  (declare (indent 0) (debug t))
+  (let ((temp-buffer (make-symbol "temp-buffer")))
+    ;; NOTE: buffer name must not start with a space, otherwise
+    ;; `font-lock-mode' doesn't turn on.
+    `(let ((,temp-buffer (generate-new-buffer "*yas-temp*")))
+       (with-current-buffer ,temp-buffer
+         ;; pretend we're interactive so `font-lock-mode' turns on
+         (let ((noninteractive nil)
+               ;; turn on font locking after major mode change
+               (change-major-mode-after-body-hook #'font-lock-mode))
+           (unwind-protect
+               (progn (require 'font-lock)
+                      ;; turn on font locking before major mode change
+                      (font-lock-mode +1)
+                      ,@body)
+             (and (buffer-name ,temp-buffer)
+                  (kill-buffer ,temp-buffer))))))))
+
+(ert-deftest example-for-issue-474 ()
+  (yas--with-font-locked-temp-buffer
+    (c-mode)
+    (yas-minor-mode 1)
+    (insert "#include <foo>\n")
+    (let ((yas-good-grace nil)) (yas-expand-snippet "`(insert \"TODO: \")`"))
+    (should (string= (yas--buffer-contents) "#include <foo>\nTODO: "))))
+
 (ert-deftest example-for-issue-404 ()
-  (with-temp-buffer
+  (yas--with-font-locked-temp-buffer
     (c++-mode)
     (yas-minor-mode 1)
     (insert "#include <foo>\n")
-    (let ((snippet "main"))
-      (let ((yas-good-grace nil)) (yas-expand-snippet snippet))
-      (should (string= (yas--buffer-contents) "#include <foo>\nmain")))))
+    (let ((yas-good-grace nil)) (yas-expand-snippet "main"))
+    (should (string= (yas--buffer-contents) "#include <foo>\nmain"))))
 
 (ert-deftest example-for-issue-404-c-mode ()
-  (with-temp-buffer
+  (yas--with-font-locked-temp-buffer
     (c-mode)
     (yas-minor-mode 1)
     (insert "#include <foo>\n")
-    (let ((snippet "main"))
-      (let ((yas-good-grace nil)) (yas-expand-snippet snippet))
-      (should (string= (yas--buffer-contents) "#include <foo>\nmain")))))
-
-(ert-deftest example-for-issue-404-external-emacs ()
-  :tags '(:external)
-  (let ((fixture-el-file (make-temp-file "yas-404-fixture" nil ".el")))
-    (with-temp-buffer
-      (insert (pp-to-string
-               `(condition-case _
-                    (progn
-                      (require 'yasnippet-tests)
-                      (yas-with-snippet-dirs
-                        '((".emacs.d/snippets"
-                           ("c-mode"
-                            ("main" . "int main ()"))))
-                        (yas-global-mode)
-                        (switch-to-buffer "foo.c")
-                        (c-mode)
-                        (insert "#include <iostream>\nmain")
-                        (setq yas-good-grace nil)
-                        (yas-expand)
-                        (should (string= (buffer-string)
-                                         "#include <iostream>\nint main ()"))
-                        (kill-emacs 0)))
-                  (error (kill-emacs -1)))))
-      (write-file fixture-el-file))
-    (should (= 0
-               (call-process (concat invocation-directory invocation-name)
-                             nil nil nil
-                             "-Q"  "--batch"
-                             "-L" "." "-l" fixture-el-file)))))
+    (let ((yas-good-grace nil)) (yas-expand-snippet "main"))
+    (should (string= (yas--buffer-contents) "#include <foo>\nmain"))))
 
 (ert-deftest middle-of-buffer-snippet-insertion ()
   (with-temp-buffer
     (yas-minor-mode 1)
     (insert "beginning")
     (save-excursion (insert "end"))
-    (let ((snippet "-middle-"))
-      (yas-expand-snippet snippet))
+    (yas-expand-snippet "-middle-")
     (should (string= (yas--buffer-contents) "beginning-middle-end"))))
 
 (ert-deftest another-example-for-issue-271 ()
diff --git a/yasnippet.el b/yasnippet.el
index 252083a..e2dbca0 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -3907,7 +3907,8 @@ With optional string TEXT do it in string instead of the 
buffer."
 with their evaluated value into `yas--backquote-markers-and-strings'."
   (while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
     (let ((current-string (match-string-no-properties 1)) transformed)
-      (delete-region (match-beginning 0) (match-end 0))
+      (save-restriction (widen)
+                        (delete-region (match-beginning 0) (match-end 0)))
       (setq transformed (yas--eval-lisp (yas--read-lisp (yas--restore-escapes 
current-string '(?`)))))
       (goto-char (match-beginning 0))
       (when transformed



reply via email to

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