Require CL when compiling.
[emacs.git] / lisp / eshell / esh-module.el
blobec1345f95613cbd1cb7b800f30872cd9b1169e4a
1 ;;; esh-module --- Eshell modules
3 ;; Copyright (C) 1999, 2000 Free Sofware Foundation
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Keywords: processes
7 ;; X-URL: http://www.emacs.org/~johnw/eshell.html
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 (provide 'esh-module)
28 (eval-when-compile (require 'esh-maint) (require 'cl))
30 (defgroup eshell-module nil
31 "The `eshell-module' group is for Eshell extension modules, which
32 provide optional behavior which the user can enable or disable by
33 customizing the variable `eshell-modules-list'."
34 :tag "Extension modules"
35 :group 'eshell)
37 ;;; Commentary:
39 (require 'esh-util)
41 (defun eshell-load-defgroups (&optional directory)
42 "Load `defgroup' statements from Eshell's module files."
43 (with-current-buffer
44 (find-file-noselect (expand-file-name "esh-groups.el" directory))
45 (erase-buffer)
46 (insert ";;; do not modify this file; it is auto-generated\n\n")
47 (let ((files (directory-files (or directory
48 (car command-line-args-left))
49 nil "\\`em-.*\\.el\\'")))
50 (while files
51 (message "Loading defgroup from `%s'" (car files))
52 (let (defgroup)
53 (catch 'handled
54 (with-current-buffer (find-file-noselect (car files))
55 (goto-char (point-min))
56 (while t
57 (forward-sexp)
58 (if (eobp) (throw 'handled t))
59 (backward-sexp)
60 (let ((begin (point))
61 (defg (looking-at "(defgroup")))
62 (forward-sexp)
63 (if defg
64 (setq defgroup (buffer-substring begin (point))))))))
65 (if defgroup
66 (insert defgroup "\n\n")))
67 (setq files (cdr files))))
68 (save-buffer)))
70 ;; load the defgroup's for the standard extension modules, so that
71 ;; documentation can be provided when the user customize's
72 ;; `eshell-modules-list'.
73 (eval-when-compile
74 (when (equal (file-name-nondirectory byte-compile-current-file)
75 "esh-module.el")
76 (let* ((directory (file-name-directory byte-compile-current-file))
77 (elc-file (expand-file-name "esh-groups.elc" directory)))
78 (eshell-load-defgroups directory)
79 (if (file-exists-p elc-file) (delete-file elc-file)))))
81 (load "esh-groups" t t)
83 ;;; User Variables:
85 (defcustom eshell-module-unload-hook
86 '(eshell-unload-extension-modules)
87 "*A hook run when `eshell-module' is unloaded."
88 :type 'hook
89 :group 'eshell-module)
91 (defcustom eshell-modules-list
92 '(eshell-alias
93 eshell-banner
94 eshell-basic
95 eshell-cmpl
96 eshell-dirs
97 eshell-glob
98 eshell-hist
99 eshell-ls
100 eshell-pred
101 eshell-prompt
102 eshell-script
103 eshell-term
104 eshell-unix)
105 "*A list of optional add-on modules to be loaded by Eshell.
106 Changes will only take effect in future Eshell buffers."
107 :type (append
108 (list 'set ':tag "Supported modules")
109 (mapcar
110 (function
111 (lambda (modname)
112 (let ((modsym (intern modname)))
113 (list 'const
114 ':tag (format "%s -- %s" modname
115 (get modsym 'custom-tag))
116 ':link (caar (get modsym 'custom-links))
117 ':doc (concat "\n" (get modsym 'group-documentation)
118 "\n ")
119 modsym))))
120 (sort (mapcar 'symbol-name
121 (eshell-subgroups 'eshell-module))
122 'string-lessp))
123 '((repeat :inline t :tag "Other modules" symbol)))
124 :group 'eshell-module)
126 ;;; Code:
128 (defsubst eshell-using-module (module)
129 "Return non-nil if a certain Eshell MODULE is in use.
130 The MODULE should be a symbol corresponding to that module's
131 customization group. Example: `eshell-cmpl' for that module."
132 (memq module eshell-modules-list))
134 (defun eshell-unload-extension-modules ()
135 "Unload any memory resident extension modules."
136 (eshell-for module (eshell-subgroups 'eshell-module)
137 (if (featurep module)
138 (ignore-errors
139 (message "Unloading %s..." (symbol-name module))
140 (unload-feature module)
141 (message "Unloading %s...done" (symbol-name module))))))
143 ;;; esh-module.el ends here