[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 26dab6b 10/14: Support `unload-feature'
From: |
Phil |
Subject: |
[elpa] master 26dab6b 10/14: Support `unload-feature' |
Date: |
Sat, 11 Jul 2020 00:57:56 -0400 (EDT) |
branch: master
commit 26dab6b9738c095eb2c9aea212abc04a04d856bc
Author: Phil Sainty <psainty@orcon.net.nz>
Commit: Phil Sainty <psainty@orcon.net.nz>
Support `unload-feature'
---
delight.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 49 insertions(+), 4 deletions(-)
diff --git a/delight.el b/delight.el
index 3d44253..5e6526d 100644
--- a/delight.el
+++ b/delight.el
@@ -96,6 +96,7 @@
;; 1.7 (2020-07-11)
;; - Add `delight-version'.
;; - Support loading newer versions over the top of older versions.
+;; - Support `unload-feature'.
;; - Rename `delighted-modes' to `delight-delighted-modes'.
;; - Rename `delight--inhibit' to `delight-mode-name-inhibit', and
;; document its uses.
@@ -192,10 +193,11 @@ to prevent the mode being treated as a minor mode."
(add-to-list 'delight-delighted-modes (list mode value file))
(unless (eq file :major)
(eval-after-load (if (eq file t) 'emacs (or file mode))
- `(let ((minor-delight (assq ',mode minor-mode-alist)))
- (when minor-delight
- (setcar (cdr minor-delight) ',value)
- (delight-mode-line-mode-menu ',mode ',value)))))))))
+ `(when (featurep 'delight)
+ (let ((minor-delight (assq ',mode minor-mode-alist)))
+ (when minor-delight
+ (setcar (cdr minor-delight) ',value)
+ (delight-mode-line-mode-menu ',mode ',value))))))))))
(defun delight-mode-line-mode-menu (mode value)
"Delight `mode-line-mode-menu' (the \"Toggle minor modes\" menu)
@@ -253,6 +255,11 @@ unless `delight-mode-name-inhibit' is bound and nil."
(define-obsolete-variable-alias 'delight--inhibit
'delight-mode-name-inhibit "delight-1.7")
+(makunbound 'delight-mode-name-inhibit)
+;; We explicitly call `makunbound' first because our `delight-unload-function'
+;; workaround for dealing with any remaining delighted `mode-name' values is
+;; simply to redefine `delight-mode-name-inhibit' with a non-nil default value.
+
(defvar delight-mode-name-inhibit)
;; This variable determines whether the `mode-name' set by `delight-major-mode'
;; will render as the original name or the delighted name. For the purposes of
@@ -306,6 +313,44 @@ Delighted major modes should exhibit their original
`mode-name' when
(advice-add 'format-mode-line :around #'delight--format-mode-line)
+(defun delight-unload-function ()
+ "Handler for `unload-feature'."
+ (condition-case err
+ (progn
+ (defvar unload-function-defs-list)
+ ;; Remove hook.
+ (remove-hook 'after-change-major-mode-hook #'delight-major-mode)
+ ;; Remove advice.
+ (advice-remove 'format-mode-line #'delight--format-mode-line)
+ ;; Revert the `mode-name' changes (for the normal/expected cases).
+ ;; We're not concerned with reversing ALL changes made, but we make
+ ;; the effort for `mode-name' as it might prevent conflicts with
+ ;; code which wasn't expecting a non-string mode line construct as
+ ;; a value (e.g. Emacs bug 2034).
+ (dolist (buf (buffer-list))
+ (with-current-buffer buf
+ (when (and (consp mode-name)
+ (symbolp (car mode-name))
+ (eq (indirect-variable (car mode-name))
+ 'delight-mode-name-inhibit))
+ (setq mode-name (cadr mode-name)))))
+ ;; We keep `delight-mode-name-inhibit' around (with delighted values
+ ;; permanently inhibited) for any unexpected cases (e.g. where our
+ ;; modified `mode-name' was further manipulated by something else,
+ ;; and no longer matched the format expected above).
+ (defconst delight-mode-name-inhibit t)
+ (dolist (var '(delight-mode-name-inhibit ;; and its aliases
+ delight--inhibit
+ inhibit-mode-name-delight))
+ (setq unload-function-defs-list
+ (delq var unload-function-defs-list)))
+ ;; Return nil if unloading was successful. Refer to `unload-feature'.
+ nil)
+ ;; If any error occurred, return non-nil.
+ (error (progn
+ (message "Error unloading delight: %S %S" (car err) (cdr err))
+ t))))
+
;; Live upgrades, for when a newer version is loaded over an older one.
(when (version< delight-version delight--latest-version)
;; Perform each update in sequence, as necessary.
- [elpa] master updated (b8c9fbb -> 2a774d1), Phil, 2020/07/11
- [elpa] master 05ef4d7 03/14: Fix quote character in `delight' docstring in Emacs 25+, Phil, 2020/07/11
- [elpa] master d2cc2fc 02/14: Use GNU ELPA version number formatting, Phil, 2020/07/11
- [elpa] master e3bd4c2 01/14: * delight.el: Fix copyright, Phil, 2020/07/11
- [elpa] master 8ec8a5b 05/14: Use cl-lib, nadvice, and lexical-binding, Phil, 2020/07/11
- [elpa] master 6d4a5aa 06/14: Use double-spaced sentence formatting, Phil, 2020/07/11
- [elpa] master 17cce66 04/14: Re-format the Change Log, Phil, 2020/07/11
- [elpa] master a763ec1 07/14: Rename `delight--inhibit' to `delight-mode-name-inhibit', Phil, 2020/07/11
- [elpa] master da63492 08/14: Rename `delighted-modes' to `delight-delighted-modes', Phil, 2020/07/11
- [elpa] master 088aae0 09/14: Support live updates from earlier versions, Phil, 2020/07/11
- [elpa] master 26dab6b 10/14: Support `unload-feature',
Phil <=
- [elpa] master 989eed2 11/14: Add to after-change-major-mode-hook at load time, Phil, 2020/07/11
- [elpa] master 2a774d1 14/14: Merge commit '5a0cd5ccb650d7bba1c1ea02cf67b71d7cfa6e9a' from delight, Phil, 2020/07/11
- [elpa] master 5a0cd5c 12/14: Documentation, Phil, 2020/07/11
- [elpa] master a1b7e94 13/14: * externals-list: Use https for "delight" subtree URL, Phil, 2020/07/11