Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

jit-loading: some minor refactoring and better tests

  • Loading branch information...
commit fcb4dfe43d05a64a172f8a5bf7bb1717b4b250cc 1 parent 584d1d8
@capitaomorte authored
Showing with 45 additions and 38 deletions.
  1. +32 −32 yasnippet-tests.el
  2. +13 −6 yasnippet.el
View
64 yasnippet-tests.el
@@ -130,43 +130,43 @@ TODO: correct this bug!"
(ert-deftest basic-jit-loading ()
"Test basic loading and expansion of snippets"
- (yas/basic-jit-loading-1))
+ (with-some-interesting-snippet-dirs
+ (yas/reload-all)
+ (yas/basic-jit-loading-1)))
(ert-deftest basic-jit-loading-with-compiled-snippets ()
"Test basic loading and expansion of snippets"
- (yas/basic-jit-loading-1 'compile))
+ (with-some-interesting-snippet-dirs
+ (yas/reload-all)
+ (yas/recompile-all)
+ (flet ((yas/load-directory-2
+ (&rest dummies)
+ (ert-fail "yas/load-directory-2 shouldn't be called when snippets have been compiled")))
+ (yas/reload-all)
+ (yas/basic-jit-loading-1))))
(defun yas/basic-jit-loading-1 (&optional compile)
- (yas/saving-variables
- (with-snippet-dirs
- '((".emacs.d/snippets"
- ("c-mode"
- (".yas-parents" . "cc-mode")
- ("printf" . "printf($1);"))
- ("emacs-lisp-mode" ("ert-deftest" . "(ert-deftest ${1:name} () $0)"))
- ("lisp-interaction-mode" (".yas-parents" . "emacs-lisp-mode")))
- ("library/snippets"
- ("c-mode" (".yas-parents" . "c++-mode"))
- ("cc-mode" ("def" . "# define"))
- ("emacs-lisp-mode" ("dolist" . "(dolist)"))
- ("lisp-interaction-mode" ("sc" . "brother from another mother"))))
- (yas/reload-all)
- (with-temp-buffer
- (should (= 4 (hash-table-count yas/scheduled-jit-loads)))
- (should (= 0 (hash-table-count yas/tables)))
- (lisp-interaction-mode) (yas/minor-mode 1) ;; either one will load two tables depending on yas/global-mode (FIXME)
- (should (= 2 (hash-table-count yas/scheduled-jit-loads)))
- (should (= 2 (hash-table-count yas/tables)))
- (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'lisp-interaction-mode yas/tables)))))
- (should (= 2 (hash-table-count (yas/table-uuidhash (gethash 'emacs-lisp-mode yas/tables)))))
- (yas/should-expand '(("sc" . "brother from another mother")
- ("dolist" . "(dolist)")
- ("ert-deftest" . "(ert-deftest name () )")))
- (c-mode)
- (yas/minor-mode 1)
- (yas/should-expand '(("printf" . "printf();")
- ("def" . "# define")))
- (yas/should-not-expand '("sc" "dolist" "ert-deftest"))))))
+ (with-temp-buffer
+ (should (= 4 (hash-table-count yas/scheduled-jit-loads)))
+ (should (= 0 (hash-table-count yas/tables)))
+ (lisp-interaction-mode)
+ (yas/minor-mode 1)
+ (should (= 2 (hash-table-count yas/scheduled-jit-loads)))
+ (should (= 2 (hash-table-count yas/tables)))
+ (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'lisp-interaction-mode yas/tables)))))
+ (should (= 2 (hash-table-count (yas/table-uuidhash (gethash 'emacs-lisp-mode yas/tables)))))
+ (yas/should-expand '(("sc" . "brother from another mother")
+ ("dolist" . "(dolist)")
+ ("ert-deftest" . "(ert-deftest name () )")))
+ (c-mode)
+ (yas/minor-mode 1)
+ (should (= 0 (hash-table-count yas/scheduled-jit-loads)))
+ (should (= 4 (hash-table-count yas/tables)))
+ (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'c-mode yas/tables)))))
+ (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'cc-mode yas/tables)))))
+ (yas/should-expand '(("printf" . "printf();")
+ ("def" . "# define")))
+ (yas/should-not-expand '("sc" "dolist" "ert-deftest"))))
;;; Helpers
;;;
View
19 yasnippet.el
@@ -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\\\\!\""

0 comments on commit fcb4dfe

Please sign in to comment.
Something went wrong with that request. Please try again.