]> code.delx.au - gnu-emacs-elpa/commitdiff
jit-loading: some minor refactoring and better tests
authorJoão Távora <joaotavora@gmail.com>
Sun, 29 Apr 2012 11:43:42 +0000 (12:43 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sun, 29 Apr 2012 11:43:42 +0000 (12:43 +0100)
yasnippet-tests.el
yasnippet.el

index 157debb8265f50f6c66c85bbf91964446e26eaec..007d125e4b86991012f8a7fb25738604d8cc98d2 100755 (executable)
@@ -130,43 +130,43 @@ TODO: correct this bug!"
 \r
 (ert-deftest basic-jit-loading ()\r
   "Test basic loading and expansion of snippets"\r
-  (yas/basic-jit-loading-1))\r
+  (with-some-interesting-snippet-dirs\r
+   (yas/reload-all)\r
+   (yas/basic-jit-loading-1)))\r
 \r
 (ert-deftest basic-jit-loading-with-compiled-snippets ()\r
   "Test basic loading and expansion of snippets"\r
-  (yas/basic-jit-loading-1 'compile))\r
+  (with-some-interesting-snippet-dirs\r
+   (yas/reload-all)\r
+   (yas/recompile-all)\r
+   (flet ((yas/load-directory-2\r
+           (&rest dummies)\r
+           (ert-fail "yas/load-directory-2 shouldn't be called when snippets have been compiled")))\r
+     (yas/reload-all)\r
+     (yas/basic-jit-loading-1))))\r
 \r
 (defun yas/basic-jit-loading-1 (&optional compile)\r
-  (yas/saving-variables\r
-   (with-snippet-dirs\r
-    '((".emacs.d/snippets"\r
-       ("c-mode"\r
-        (".yas-parents" . "cc-mode")\r
-        ("printf" . "printf($1);"))\r
-       ("emacs-lisp-mode" ("ert-deftest" . "(ert-deftest ${1:name} () $0)"))\r
-       ("lisp-interaction-mode" (".yas-parents" . "emacs-lisp-mode")))\r
-      ("library/snippets"\r
-       ("c-mode" (".yas-parents" . "c++-mode"))\r
-       ("cc-mode" ("def" . "# define"))\r
-       ("emacs-lisp-mode" ("dolist" . "(dolist)"))\r
-       ("lisp-interaction-mode" ("sc" . "brother from another mother"))))\r
-    (yas/reload-all)\r
-    (with-temp-buffer\r
-      (should (= 4 (hash-table-count yas/scheduled-jit-loads)))\r
-      (should (= 0 (hash-table-count yas/tables)))\r
-      (lisp-interaction-mode) (yas/minor-mode 1) ;; either one will load two tables depending on yas/global-mode (FIXME)\r
-      (should (= 2 (hash-table-count yas/scheduled-jit-loads)))\r
-      (should (= 2 (hash-table-count yas/tables)))\r
-      (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'lisp-interaction-mode yas/tables)))))\r
-      (should (= 2 (hash-table-count (yas/table-uuidhash (gethash 'emacs-lisp-mode yas/tables)))))\r
-      (yas/should-expand '(("sc" . "brother from another mother")\r
-                           ("dolist" . "(dolist)")\r
-                           ("ert-deftest" . "(ert-deftest name () )")))\r
-      (c-mode)\r
-      (yas/minor-mode 1)\r
-      (yas/should-expand '(("printf" . "printf();")\r
-                           ("def" . "# define")))\r
-      (yas/should-not-expand '("sc" "dolist" "ert-deftest"))))))\r
+  (with-temp-buffer\r
+    (should (= 4 (hash-table-count yas/scheduled-jit-loads)))\r
+    (should (= 0 (hash-table-count yas/tables)))\r
+    (lisp-interaction-mode)\r
+    (yas/minor-mode 1)\r
+    (should (= 2 (hash-table-count yas/scheduled-jit-loads)))\r
+    (should (= 2 (hash-table-count yas/tables)))\r
+    (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'lisp-interaction-mode yas/tables)))))\r
+    (should (= 2 (hash-table-count (yas/table-uuidhash (gethash 'emacs-lisp-mode yas/tables)))))\r
+    (yas/should-expand '(("sc" . "brother from another mother")\r
+                         ("dolist" . "(dolist)")\r
+                         ("ert-deftest" . "(ert-deftest name () )")))\r
+    (c-mode)\r
+    (yas/minor-mode 1)\r
+    (should (= 0 (hash-table-count yas/scheduled-jit-loads)))\r
+    (should (= 4 (hash-table-count yas/tables)))\r
+    (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'c-mode yas/tables)))))\r
+    (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'cc-mode yas/tables)))))\r
+    (yas/should-expand '(("printf" . "printf();")\r
+                         ("def" . "# define")))\r
+    (yas/should-not-expand '("sc" "dolist" "ert-deftest"))))\r
 \r
 ;;; Helpers\r
 ;;;\r
index 736cfa0cb10629beee8a00404cf08d8e86f774e2..677353ad9e97f0ba25a6a734b8e4462c14bbd8ba 100644 (file)
@@ -815,12 +815,7 @@ Key bindings:
              (set (make-local-variable name) t)))
          ;; Perform JIT loads
          ;;
-         (dolist (mode (yas/modes-to-activate))
-           (let ((forms (gethash mode yas/scheduled-jit-loads)))
-             (dolist (form forms)
-               (message  "[yas] Loading snippets for %s, just in time: %s!" mode form)
-               (eval form))
-             (remhash mode yas/scheduled-jit-loads))))
+         (yas/load-pending-jits))
         (t
          ;; Uninstall the direct keymaps and the post-command hook
          ;;
@@ -1709,6 +1704,18 @@ Below TOP-LEVEL-DIR each directory is a mode name."
     (yas/direct-keymaps-reload)
     (yas/message 3 "Reloaded everything...%s." (if errors " (some errors, check *Messages*)" ""))))
 
+(defun yas/load-pending-jits ()
+  (when yas/minor-mode 
+    (dolist (mode (yas/modes-to-activate))
+      (let ((forms (gethash mode yas/scheduled-jit-loads)))
+        (dolist (form forms)
+          (yas/message  3 "Loading snippets for %s, just in time: %s!" mode form)
+          (eval form))
+        (remhash mode yas/scheduled-jit-loads)))))
+
+;; (when (<= emacs-major-version 22)
+;;   (add-hook 'after-change-major-mode-hook 'yas/load-pending-jits))
+
 (defun yas/quote-string (string)
   "Escape and quote STRING.
 foo\"bar\\! -> \"foo\\\"bar\\\\!\""