]> code.delx.au - gnu-emacs-elpa/commitdiff
Merge pull request #424 from ljos/de/activate-extra-mode
authorJoão Távora <joaotavora@gmail.com>
Thu, 31 Oct 2013 13:28:26 +0000 (06:28 -0700)
committerJoão Távora <joaotavora@gmail.com>
Thu, 31 Oct 2013 13:28:26 +0000 (06:28 -0700)
Feature: de/activate-extra-mode

Rakefile
yasnippet-tests.el
yasnippet.el

index fe25bcccd76e15fa130b914b7309815f73a33e72..b7eb238b128f666fb763225050b3c3689d01f1d7 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -13,7 +13,9 @@ FileUtils.mkdir_p('pkg')
 
 desc "run tests in batch mode"
 task :tests do
-  sh "#{$EMACS} -Q -L . -l yasnippet-tests.el -nw --batch -e yas-batch-run-tests"
+  batch_run_line = "(yas-batch-run-tests t)"
+  sh "#{$EMACS} -Q -L . -l yasnippet-tests.el -nw" +
+    " --batch --eval '#{batch_run_line}'"
 end
 
 desc "convert some textmate bundles to yasnippets"
index dbd610dac49771c1e7e77337b6d06bb8aaa4f112..1d770b47f5637c5bf55ec5bdb490be36f80ac493 100644 (file)
     (yas-minor-mode 1)
     (insert "#include <foo>\n")
     (let ((snippet "main"))
-      (yas-expand-snippet snippet)
+      (let ((yas-good-grace nil)) (yas-expand-snippet snippet))
+      (should (string= (yas--buffer-contents) "#include <foo>\nmain")))))
+
+(ert-deftest example-for-issue-404-c-mode ()
+  (with-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)
+                      (yas-global-mode)
+                      (switch-to-buffer "foo.c")
+                      (c-mode)
+                      (insert "#include <iostream>\nmain")
+                      (setq yas-good-grace nil)
+                      (yas-expand)
+                      (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)))))
+
 (ert-deftest middle-of-buffer-snippet-insertion ()
   (with-temp-buffer
     (yas-minor-mode 1)
@@ -597,14 +629,14 @@ buffer."
 \f
 ;;; Helpers
 ;;;
-(defun yas-batch-run-tests ()
+(defun yas-batch-run-tests (&optional also-external)
   (interactive)
   (with-temp-buffer
     (yas--with-temporary-redefinitions
-        ((message (&rest _args) nil))
-      (ert t (buffer-name (current-buffer)))
-      (princ (buffer-string)))))
-
+     ((message (&rest _args) nil))
+     (ert (or (and also-external t)
+              '(not (tag :external))) (buffer-name (current-buffer)))
+    (princ (buffer-string)))))
 
 (defun yas-should-expand (keys-and-expansions)
   (dolist (key-and-expansion keys-and-expansions)
index a4bd6fbe43c1b0086141fdd69545c46d6cc1e7a6..eb7afc6b4cca1e386903f3126756aae1ed0b976b 100644 (file)
@@ -867,7 +867,8 @@ Honour `yas-dont-activate', which see."
                         (when (third ent)
                           (define-key map (third ent) (second ent)))
                         (vector (first ent) (second ent) t))
-                    '(("Load this snippet" yas-load-snippet-buffer "\C-c\C-c")
+                    '(("Load this snippet" yas-load-snippet-buffer "\C-c\C-l")
+                      ("Load and quit window" yas-load-snippet-buffer-and-close "\C-c\C-c")
                       ("Try out this snippet" yas-tryout-snippet "\C-c\C-t")))))
     map)
   "The keymap used when `snippet-mode' is active.")
@@ -2556,8 +2557,7 @@ neither do the elements of PARENTS."
 
 TABLE is a symbol naming a passed to `yas--table-get-create'.
 
-When called interactively, prompt for the table name and
-whether (and where) to save the snippet, then quit the window."
+When called interactively, prompt for the table name."
   (interactive (list (yas--read-table) t))
   (cond
    ;;  We have `yas--editing-template', this buffer's content comes from a
@@ -2576,9 +2576,25 @@ whether (and where) to save the snippet, then quit the window."
       (set (make-local-variable 'yas--editing-template)
            (yas--define-snippets-1 (yas--parse-template buffer-file-name)
                                   table)))))
+  (when interactive
+    (yas--message 3 "Snippet \"%s\" loaded for %s."
+                  (yas--template-name yas--editing-template)
+                  (yas--table-name (yas--template-table yas--editing-template)))))
+
+(defun yas-load-snippet-buffer-and-close (table &optional kill)
+  "Load the snippet with `yas-load-snippet-buffer', possibly
+  save, then `quit-window' if saved.
+
+If the snippet is new, ask the user whether (and where) to save
+it. If the snippet already has a file, just save it.
 
-  (when (and interactive
-             (or
+The prefix argument KILL is passed to `quit-window'.
+
+Don't use this from a Lisp program, call `yas-load-snippet-buffer'
+and `kill-buffer' instead."
+  (interactive (list (yas--read-table) current-prefix-arg))
+  (yas-load-snippet-buffer table t)
+  (when (and (or
               ;; Only offer to save this if it looks like a library or new
               ;; snippet (loaded from elisp, from a dir in `yas-snippet-dirs'
               ;; which is not the first, or from an unwritable file)
@@ -2601,11 +2617,9 @@ whether (and where) to save the snippet, then quit the window."
                               (read-from-minibuffer (format "File name to create in %s? " chosen)
                                                     default-file-name)))
           (setf (yas--template-file yas--editing-template) buffer-file-name)))))
-  (when interactive
-    (yas--message 3 "Snippet \"%s\" loaded for %s."
-                  (yas--template-name yas--editing-template)
-                  (yas--table-name (yas--template-table yas--editing-template)))
-    (quit-window interactive)))
+  (when buffer-file-name
+    (save-buffer)
+    (quit-window kill)))
 
 (defun yas-tryout-snippet (&optional debug)
   "Test current buffer's snippet template in other buffer."
@@ -3835,7 +3849,7 @@ Meant to be called in a narrowed buffer, does various passes"
     (yas--calculate-adjacencies snippet)
     ;; Delete $-constructs
     ;;
-    (yas--delete-regions yas--dollar-regions)
+    (save-restriction (widen) (yas--delete-regions yas--dollar-regions))
     ;; restore backquoted expression values
     ;;
     (yas--restore-backquotes)