summaryrefslogtreecommitdiff
path: root/lisp/eshell/esh-module.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2023-02-12 23:25:59 -0800
committerJim Porter <jporterbugs@gmail.com>2023-02-15 17:31:52 -0800
commit8051be9ac204583e0641779763eb0803c730b4bf (patch)
treeec8fe5f6d10438e8d412f991013f4e149c2877b6 /lisp/eshell/esh-module.el
parent324a1d83c99f6641fa0460fe8c91fa9afad8a4eb (diff)
Allow unloading Eshell
* lisp/eshell/em-extpipe.el (eshell-extpipe): * lisp/eshell/esh-opt.el (eshell-opt): New groups. Eshell uses these to identify modules to unload. * lisp/eshell/em-hist.el (eshell-hist-unload-hook): * lisp/eshell/em-ls.el (eshell-ls-unload-hook): * lisp/eshell/em-smart.el (eshell-smart-unload-hook): * lisp/eshell/eshell.el (eshell-unload-hook): Make obsolete and move to... * lisp/eshell/em-smart.el (em-smart-unload-function): * lisp/eshell/em-hist.el (em-hist-unload-function): * lisp/eshell/em-ls.el (em-ls-unload-function): * lisp/eshell/eshell.el (eshell-unload-function): ... these. * lisp/eshell/esh-mode.el (eshell-mode-unload-hook): * lisp/eshell/esh-module.el (eshell-module-unload-hook): Make obsolete. * lisp/eshell/em-ls (eshell-ls-enable-in-dired, eshell-ls-disable-in-dired): New functions... (eshell-ls-use-in-dired): ... use them. * lisp/eshell/esh-module.el (eshell-module--feature-name, eshell-unload-modules): New functions. (eshell-unload-extension-modules): Use 'eshell-unload-modules'. * lisp/eshell/eshell.el (eshell-unload-all-modules): Remove. * test/lisp/eshell/eshell-tests-unload.el: New file. * doc/misc/eshell.texi (Bugs and ideas): Remove item about unloading Eshell not working. * etc/NEWS: Announce this change (bug#61501).
Diffstat (limited to 'lisp/eshell/esh-module.el')
-rw-r--r--lisp/eshell/esh-module.el32
1 files changed, 25 insertions, 7 deletions
diff --git a/lisp/eshell/esh-module.el b/lisp/eshell/esh-module.el
index 651e793ad98..7fc74d38796 100644
--- a/lisp/eshell/esh-module.el
+++ b/lisp/eshell/esh-module.el
@@ -47,6 +47,7 @@ customizing the variable `eshell-modules-list'."
"A hook run when `eshell-module' is unloaded."
:type 'hook
:group 'eshell-module)
+(make-obsolete-variable 'eshell-module-unload-hook nil "30.1")
(defcustom eshell-modules-list
'(eshell-alias
@@ -85,20 +86,37 @@ Changes will only take effect in future Eshell buffers."
;;; Code:
+(defsubst eshell-module--feature-name (module &optional kind)
+ "Get the feature name for the specified Eshell MODULE."
+ (let ((module-name (symbol-name module))
+ (prefix (cond ((eq kind 'core) "esh-")
+ ((memq kind '(extension nil)) "em-")
+ (t (error "unknown module kind %s" kind)))))
+ (if (string-match "^eshell-\\(.*\\)" module-name)
+ (concat prefix (match-string 1 module-name))
+ (error "Invalid Eshell module name: %s" module))))
+
(defsubst eshell-using-module (module)
"Return non-nil if a certain Eshell MODULE is in use.
The MODULE should be a symbol corresponding to that module's
customization group. Example: `eshell-cmpl' for that module."
(memq module eshell-modules-list))
+(defun eshell-unload-modules (modules &optional kind)
+ "Try to unload the specified Eshell MODULES."
+ (dolist (module modules)
+ (let ((module-feature (intern (eshell-module--feature-name module kind))))
+ (when (featurep module-feature)
+ (message "Unloading %s..." (symbol-name module))
+ (condition-case-unless-debug _
+ (progn
+ (unload-feature module-feature)
+ (message "Unloading %s...done" (symbol-name module)))
+ (error (message "Unloading %s...failed" (symbol-name module))))))))
+
(defun eshell-unload-extension-modules ()
- "Unload any memory resident extension modules."
- (dolist (module (eshell-subgroups 'eshell-module))
- (if (featurep module)
- (ignore-errors
- (message "Unloading %s..." (symbol-name module))
- (unload-feature module)
- (message "Unloading %s...done" (symbol-name module))))))
+ "Try to unload all currently-loaded Eshell extension modules."
+ (eshell-unload-modules (eshell-subgroups 'eshell-module)))
(provide 'esh-module)
;;; esh-module.el ends here