[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 074d670 26/51: Add yasnippet-unload-function
From: |
Noam Postavsky |
Subject: |
[elpa] master 074d670 26/51: Add yasnippet-unload-function |
Date: |
Sun, 13 May 2018 13:11:43 -0400 (EDT) |
branch: master
commit 074d670be4b5709bd7b6443b6b318a8d78b2e5c5
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
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
- [elpa] master 6066631 28/51: Fix typos in "Writing Templates" documentation, (continued)
- [elpa] master 6066631 28/51: Fix typos in "Writing Templates" documentation, Noam Postavsky, 2018/05/13
- [elpa] master b0aa5c2 48/51: Tweak bug-reporting information slightly, Noam Postavsky, 2018/05/13
- [elpa] master fe9f8b6 21/51: ; yasnippet-debug.el: Update yas-debug-snippets arg for previous change., Noam Postavsky, 2018/05/13
- [elpa] master caf3dba 30/51: Don't use global variable for backquote expression locations, Noam Postavsky, 2018/05/13
- [elpa] master ff26e3b 19/51: Close #824: Simple fields can be parented like other fields or mirrors, Noam Postavsky, 2018/05/13
- [elpa] master ff8e833 23/51: ; yasnippet-debug.el: Fix deprecation warning., Noam Postavsky, 2018/05/13
- [elpa] master a0d2cff 44/51: ; Don't enter debugger for kill-all-local-variables case, Noam Postavsky, 2018/05/13
- [elpa] master 5170f05 42/51: Don't indent first and only line of expanded snippet, Noam Postavsky, 2018/05/13
- [elpa] master 5a29fe6 50/51: Release 0.13.0, Noam Postavsky, 2018/05/13
- [elpa] master 8b421bc 20/51: Reinstate the old debug behaviour for yas-tryout-snippet, Noam Postavsky, 2018/05/13
- [elpa] master 074d670 26/51: Add yasnippet-unload-function,
Noam Postavsky <=
- [elpa] master d364425 38/51: * yasnippet.el (yas-field-value): Fix docstring., Noam Postavsky, 2018/05/13
- [elpa] master 05ac1da 31/51: ; yasnippet-tests.el (yas-no-memory-of-bad-snippet): Fix docstring., Noam Postavsky, 2018/05/13
- [elpa] master 3032337 37/51: Improve rendering of docstrings in manual's reference section, Noam Postavsky, 2018/05/13
- [elpa] master ae95810 43/51: ; Try to get more info about 873/919, Noam Postavsky, 2018/05/13
- [elpa] master 15761e8 41/51: Adjust previous fix, Noam Postavsky, 2018/05/13
- [elpa] master 0afc638 35/51: Fix docs for new org mode, Noam Postavsky, 2018/05/13
- [elpa] master 1668607 46/51: Don't add to disabled undo list, Noam Postavsky, 2018/05/13
- [elpa] master f9231b0 47/51: Work around Emacs Bug#30931 (Misc_Free in undo list), Noam Postavsky, 2018/05/13
- [elpa] master 4755aa9 49/51: Clarify behavior of mirror transforms, Noam Postavsky, 2018/05/13
- [elpa] master e261832 36/51: Add some styling to doc, improve top menu, Noam Postavsky, 2018/05/13