mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
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:
parent
e35c031410
commit
074d670be4
@ -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
|
||||||
|
@ -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
|
||||||
;;;
|
;;;
|
||||||
|
25
yasnippet.el
25
yasnippet.el
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user