[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 1d4618b 138/177: Closes #504: Correctly discover buffers n
From: |
João Távora |
Subject: |
[elpa] master 1d4618b 138/177: Closes #504: Correctly discover buffers needing snippets immediately |
Date: |
Sat, 28 Mar 2015 15:41:28 +0000 |
branch: master
commit 1d4618b022bb1cea6781f50f5009e68b7689a1cd
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Closes #504: Correctly discover buffers needing snippets immediately
* yasnippet-tests.el (issue-504-tricky-jit): New test.
* yasnippet.el (yas-load-directory): Use a new `impatient-buffers'
local and call `yas--load-pending-juts' in all those at the end.
* yasnippet.el (cl-lib): Don't need `eval-and-compile'.
---
yasnippet-tests.el | 17 ++++++++++++
yasnippet.el | 71 ++++++++++++++++++++++++++++-----------------------
2 files changed, 56 insertions(+), 32 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 4b3a440..7653d31 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -485,6 +485,23 @@ TODO: correct this bug!"
(should (= (length expected)
(length observed)))))))
+(ert-deftest issue-504-tricky-jit ()
+ (define-derived-mode yas--test-mode c-mode "Just a test mode")
+ (define-derived-mode yas--another-test-mode c-mode "Another test mode")
+ (yas-with-snippet-dirs
+ '((".emacs.d/snippets"
+ ("yas--another-test-mode"
+ (".yas-parents" . "yas--test-mode"))
+ ("yas--test-mode")))
+ (let ((b (with-current-buffer (generate-new-buffer "*yas-test*")
+ (yas--another-test-mode)
+ (current-buffer))))
+ (unwind-protect
+ (progn
+ (yas-reload-all)
+ (should (= 0 (hash-table-count yas--scheduled-jit-loads))))
+ (kill-buffer b)))))
+
(defun yas--basic-jit-loading-1 ()
(with-temp-buffer
(should (= 4 (hash-table-count yas--scheduled-jit-loads)))
diff --git a/yasnippet.el b/yasnippet.el
index 821e748..adcd44d 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -130,8 +130,7 @@
;;; Code:
(require 'cl)
-(eval-and-compile
- (require 'cl-lib))
+(require 'cl-lib)
(require 'easymenu)
(require 'help-mode)
@@ -1736,36 +1735,44 @@ With prefix argument USE-JIT do jit-loading of
snippets."
current-prefix-arg t))
(unless yas-snippet-dirs
(setq yas-snippet-dirs top-level-dir))
- (dolist (dir (yas--subdirs top-level-dir))
- (let* ((major-mode-and-parents (yas--compute-major-mode-and-parents
- (concat dir "/dummy")))
- (mode-sym (car major-mode-and-parents))
- (parents (cdr major-mode-and-parents)))
- ;; Attention: The parents and the menus are already defined
- ;; here, even if the snippets are later jit-loaded.
- ;;
- ;; * We need to know the parents at this point since entering a
- ;; given mode should jit load for its parents
- ;; immediately. This could be reviewed, the parents could be
- ;; discovered just-in-time-as well
- ;;
- ;; * We need to create the menus here to support the `full'
- ;; option to `yas-use-menu' (all known snippet menus are shown to the
user)
- ;;
- (yas--define-parents mode-sym parents)
- (yas--menu-keymap-get-create mode-sym)
- (let ((fun `(lambda () ;; FIXME: Simulating lexical-binding.
- (yas--load-directory-1 ',dir ',mode-sym))))
- (if (and use-jit
- (not (some #'(lambda (buffer)
- (with-current-buffer buffer
- ;; FIXME: Shouldn't this use derived-mode-p?
- (when (eq major-mode mode-sym)
- (yas--message 3 "Discovered there was
already %s in %s" buffer mode-sym)
- t)))
- (buffer-list))))
- (yas--schedule-jit mode-sym fun)
- (funcall fun)))))
+ (let ((impatient-buffers))
+ (dolist (dir (yas--subdirs top-level-dir))
+ (let* ((major-mode-and-parents (yas--compute-major-mode-and-parents
+ (concat dir "/dummy")))
+ (mode-sym (car major-mode-and-parents))
+ (parents (cdr major-mode-and-parents)))
+ ;; Attention: The parents and the menus are already defined
+ ;; here, even if the snippets are later jit-loaded.
+ ;;
+ ;; * We need to know the parents at this point since entering a
+ ;; given mode should jit load for its parents
+ ;; immediately. This could be reviewed, the parents could be
+ ;; discovered just-in-time-as well
+ ;;
+ ;; * We need to create the menus here to support the `full'
+ ;; option to `yas-use-menu' (all known snippet menus are shown to
the user)
+ ;;
+ (yas--define-parents mode-sym parents)
+ (yas--menu-keymap-get-create mode-sym)
+ (let ((fun `(lambda () ;; FIXME: Simulating lexical-binding.
+ (yas--load-directory-1 ',dir ',mode-sym))))
+ (if use-jit
+ (yas--schedule-jit mode-sym fun)
+ (funcall fun)))
+ ;; Look for buffers that are already in `mode-sym', and so
+ ;; need the new snippets immediately...
+ ;;
+ (when use-jit
+ (cl-loop for buffer in (buffer-list)
+ do (with-current-buffer buffer
+ (when (eq major-mode mode-sym)
+ (yas--message 3 "Discovered there was already %s in
%s" buffer mode-sym)
+ (push buffer impatient-buffers)))))))
+ ;; ...after TOP-LEVEL-DIR has been completely loaded, call
+ ;; `yas--load-pending-jits' in these impatient buffers.
+ ;;
+ (cl-loop for buffer in impatient-buffers
+ do (with-current-buffer buffer (yas--load-pending-jits))))
(when interactive
(yas--message 3 "Loaded snippets from %s." top-level-dir)))
- [elpa] master 0b7b34a 127/177: Closes #492, closes #494: Consider defalias when calculating parent modes, (continued)
- [elpa] master 0b7b34a 127/177: Closes #492, closes #494: Consider defalias when calculating parent modes, João Távora, 2015/03/28
- [elpa] master 7761dee 128/177: Closes #497: Allow functions as elements in yas-key-syntaxes, João Távora, 2015/03/28
- [elpa] master faed106 129/177: * yasnippet.el (yas-key-syntaxes): Improve documentation., João Távora, 2015/03/28
- [elpa] master de34d91 130/177: Closes #470, handle non-whitespace newlines, João Távora, 2015/03/28
- [elpa] master 6b04dad 120/177: Document type directive, João Távora, 2015/03/28
- [elpa] master 10ecde1 132/177: Pass start point to yas-key-syntaxes functions, João Távora, 2015/03/28
- [elpa] master 47a3d5f 134/177: Fix yas-key-syntaxes example functions docstrings., João Távora, 2015/03/28
- [elpa] master d982b70 135/177: Fix edge case in yas-longest-key-from-whitespace, João Távora, 2015/03/28
- [elpa] master 5d10b5d 133/177: Add yas-longest-key-from-whitespace, João Távora, 2015/03/28
- [elpa] master f7ef023 137/177: Prevent disabling errors from recent `yas-current-syntaxes` logic, João Távora, 2015/03/28
- [elpa] master 1d4618b 138/177: Closes #504: Correctly discover buffers needing snippets immediately,
João Távora <=
- [elpa] master e60e8b5 136/177: Merge pull request #503 from npostavs/key-syntaxes, João Távora, 2015/03/28
- [elpa] master 5b59b80 139/177: Closes #495: Allow symbols as aliases in `yas-snippet-dirs', João Távora, 2015/03/28
- [elpa] master be2f815 140/177: Closes #508: Ensure original point when evaluating conditions, João Távora, 2015/03/28
- [elpa] master 241465c 141/177: move eof footer to the actual eof, João Távora, 2015/03/28
- [elpa] master 70de821 143/177: enforce use of spaces for indentation, João Távora, 2015/03/28
- [elpa] master 41cb5f5 145/177: Update snippets submodule, João Távora, 2015/03/28
- [elpa] master cc64ff6 144/177: Merge pull request #514 from tarsius/master, João Távora, 2015/03/28
- [elpa] master 8e9bf3c 147/177: Merge pull request #518 from rnkn/master, João Távora, 2015/03/28
- [elpa] master 6f7c915 146/177: Compatibility with custom-unlispify-remove-prefixes, João Távora, 2015/03/28
- [elpa] master 783cc33 148/177: Use cl-incf instead of cl, João Távora, 2015/03/28