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.
This commit is contained in:
Noam Postavsky 2018-01-20 18:20:56 -05:00
parent e35c031410
commit 074d670be4
3 changed files with 53 additions and 8 deletions

View File

@ -347,14 +347,6 @@ buffer-locally, otherwise install it globally. If HOOK is
(when command-line-args-left (when command-line-args-left
(yas-debug-process-command-line)) (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) (provide 'yasnippet-debug)
;; Local Variables: ;; Local Variables:
;; indent-tabs-mode: nil ;; indent-tabs-mode: nil

View File

@ -1224,6 +1224,34 @@ hello ${1:$(when (stringp yas-text) (funcall func yas-text))} foo${1:$$(concat \
("def" . "# define"))) ("def" . "# define")))
(yas-should-not-expand '("sc" "dolist" "ert-deftest")))) (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 ;;; Menu
;;; ;;;

View File

@ -4815,6 +4815,31 @@ and return the directory. Return nil if not found."
(directory-file-name file)))) (directory-file-name file))))
(setq file nil)))) (setq file nil))))
root)))) 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 ;;; Backward compatibility to yasnippet <= 0.7