branch: master commit 074d670be4b5709bd7b6443b6b318a8d78b2e5c5 Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
Add yasnippet-unload-function * yasnippet.el (yasnippet-unload-function): New function. * yasnippet-debug.el (yas-exterminate-package): Remove, it was only doing a partial job of undoing modes, and uninterning is entirely not needed. * yasnippet-tests.el (yas-unload): New test. --- yasnippet-debug.el | 8 -------- yasnippet-tests.el | 28 ++++++++++++++++++++++++++++ yasnippet.el | 25 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/yasnippet-debug.el b/yasnippet-debug.el index 8125675..2d186d4 100644 --- a/yasnippet-debug.el +++ b/yasnippet-debug.el @@ -347,14 +347,6 @@ buffer-locally, otherwise install it globally. If HOOK is (when command-line-args-left (yas-debug-process-command-line)) -(defun yas-exterminate-package () - (interactive) - (yas-global-mode -1) - (yas-minor-mode -1) - (mapatoms #'(lambda (atom) - (when (string-match "yas[-/]" (symbol-name atom)) - (unintern atom obarray))))) - (provide 'yasnippet-debug) ;; Local Variables: ;; indent-tabs-mode: nil diff --git a/yasnippet-tests.el b/yasnippet-tests.el index e40c6fd..5751a06 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -1225,6 +1225,34 @@ hello ${1:$(when (stringp yas-text) (funcall func yas-text))} foo${1:$$(concat \ (yas-should-not-expand '("sc" "dolist" "ert-deftest")))) +;;; Unloading +(ert-deftest yas-unload () + "Test unloading and reloading." + (with-temp-buffer + (let ((status (call-process + (concat invocation-directory invocation-name) + nil '(t t) nil + "-Q" "--batch" "-L" yas--loaddir "-l" "yasnippet" + "--eval" + (prin1-to-string + '(condition-case err + (progn + (yas-minor-mode +1) + (unload-feature 'yasnippet) + ;; Unloading leaves `yas-minor-mode' bound, + ;; harmless, though perhaps surprising. + (when (bound-and-true-p yas-minor-mode) + (error "`yas-minor-mode' still enabled")) + (when (fboundp 'yas-minor-mode) + (error "`yas-minor-mode' still fboundp")) + (require 'yasnippet) + (unless (fboundp 'yas-minor-mode) + (error "Failed to reload"))) + (error (message "%S" (error-message-string err)) + (kill-emacs 1))))))) + (ert-info ((buffer-string)) (should (eq status 0)))))) + + ;;; Menu ;;; (defmacro yas-with-even-more-interesting-snippet-dirs (&rest body) diff --git a/yasnippet.el b/yasnippet.el index 092ac55..7c8905a 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -4815,6 +4815,31 @@ and return the directory. Return nil if not found." (directory-file-name file)))) (setq file nil)))) root)))) + +;;; Unloading + +(defvar unload-function-defs-list) ; loadhist.el + +(defun yasnippet-unload-function () + "Disable minor modes when calling `unload-feature'." + ;; Disable `yas-minor-mode' everywhere it's enabled. + (yas-global-mode -1) + (save-current-buffer + (dolist (buffer (buffer-list)) + (set-buffer buffer) + (when yas-minor-mode + (yas-minor-mode -1)))) + ;; Remove symbol properties of all our functions, this avoids + ;; Bug#25088 in Emacs 25.1, where the compiler macro on + ;; `cl-defstruct' created functions hang around in the symbol plist + ;; and cause errors when loading again (we don't *need* to clean + ;; *all* symbol plists, but it's easier than being precise). + (dolist (def unload-function-defs-list) + (when (eq (car-safe def) 'defun) + (setplist (cdr def) nil))) + ;; Return nil so that `unload-feature' will take of undefining + ;; functions, and changing any buffers using `snippet-mode'. + nil) ;;; Backward compatibility to yasnippet <= 0.7