(top-level): Revert previous change: require cl when compiling.
[emacs.git] / lisp / eshell / esh-module.el
blob805f38dda4e81fe70a893ea5d42dd288275ffb48
1 ;;; esh-module.el --- Eshell modules
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: John Wiegley <johnw@gnu.org>
7 ;; Keywords: processes
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 3 of the License, or
14 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Code:
26 (provide 'esh-module)
28 (eval-when-compile
29 (require 'cl)
30 (require 'esh-util))
32 (require 'esh-util)
34 (defgroup eshell-module nil
35 "The `eshell-module' group is for Eshell extension modules, which
36 provide optional behavior which the user can enable or disable by
37 customizing the variable `eshell-modules-list'."
38 :tag "Extension modules"
39 :group 'eshell)
41 (eval-and-compile
42 (defun eshell-load-defgroups (&optional directory)
43 "Load `defgroup' statements from Eshell's module files."
44 (let ((vc-handled-backends nil)) ; avoid VC fucking things up
45 (with-current-buffer
46 (find-file-noselect (expand-file-name "esh-groups.el" directory))
47 (erase-buffer)
48 (insert ";;; do not modify this file; it is auto-generated -*- no-byte-compile: t -*-\n\n")
49 (let ((files (directory-files (or directory
50 (car command-line-args-left))
51 nil "\\`em-.*\\.el\\'")))
52 (while files
53 (message "Loading defgroup from `%s'" (car files))
54 (let (defgroup)
55 (catch 'handled
56 (with-current-buffer (find-file-noselect (car files))
57 (goto-char (point-min))
58 (while t
59 (forward-sexp)
60 (if (eobp) (throw 'handled t))
61 (backward-sexp)
62 (let ((begin (point))
63 (defg (looking-at "(defgroup")))
64 (forward-sexp)
65 (if defg
66 (setq defgroup (buffer-substring begin (point))))))))
67 (if defgroup
68 (insert defgroup "\n\n")))
69 (setq files (cdr files))))
70 ;; Don't make backups, to avoid prompting the user if there are
71 ;; excess backup versions.
72 (save-buffer 0)))))
74 ;; load the defgroup's for the standard extension modules, so that
75 ;; documentation can be provided when the user customize's
76 ;; `eshell-modules-list'.
77 (eval-when-compile
78 (when (and (boundp 'byte-compile-current-file)
79 byte-compile-current-file
80 (or
81 (equal (file-name-nondirectory byte-compile-current-file)
82 "esh-module.el")
83 ;; When eshell file names are expanded from a wildcard
84 ;; or by reading the Eshell directory, e.g. when they
85 ;; say "make recompile" in the lisp directory, Emacs on
86 ;; MS-DOS sees a truncated name "esh-modu.el" instead of
87 ;; "esh-module.el".
88 (and (fboundp 'msdos-long-file-names)
89 (null (msdos-long-file-names))
90 (equal (file-name-nondirectory byte-compile-current-file)
91 "esh-modu.el"))))
92 (let* ((directory (file-name-directory byte-compile-current-file))
93 (elc-file (expand-file-name "esh-groups.elc" directory)))
94 (eshell-load-defgroups directory)
95 (if (file-exists-p elc-file) (delete-file elc-file)))))
97 (load "esh-groups" t t)
99 ;;; User Variables:
101 (defcustom eshell-module-unload-hook
102 '(eshell-unload-extension-modules)
103 "*A hook run when `eshell-module' is unloaded."
104 :type 'hook
105 :group 'eshell-module)
107 (defcustom eshell-modules-list
108 '(eshell-alias
109 eshell-banner
110 eshell-basic
111 eshell-cmpl
112 eshell-dirs
113 eshell-glob
114 eshell-hist
115 eshell-ls
116 eshell-pred
117 eshell-prompt
118 eshell-script
119 eshell-term
120 eshell-unix)
121 "*A list of optional add-on modules to be loaded by Eshell.
122 Changes will only take effect in future Eshell buffers."
123 :type (append
124 (list 'set ':tag "Supported modules")
125 (mapcar
126 (function
127 (lambda (modname)
128 (let ((modsym (intern modname)))
129 (list 'const
130 ':tag (format "%s -- %s" modname
131 (get modsym 'custom-tag))
132 ':link (caar (get modsym 'custom-links))
133 ':doc (concat "\n" (get modsym 'group-documentation)
134 "\n ")
135 modsym))))
136 (sort (mapcar 'symbol-name
137 (eshell-subgroups 'eshell-module))
138 'string-lessp))
139 '((repeat :inline t :tag "Other modules" symbol)))
140 :group 'eshell-module)
142 ;;; Code:
144 (defsubst eshell-using-module (module)
145 "Return non-nil if a certain Eshell MODULE is in use.
146 The MODULE should be a symbol corresponding to that module's
147 customization group. Example: `eshell-cmpl' for that module."
148 (memq module eshell-modules-list))
150 (defun eshell-unload-extension-modules ()
151 "Unload any memory resident extension modules."
152 (eshell-for module (eshell-subgroups 'eshell-module)
153 (if (featurep module)
154 (ignore-errors
155 (message "Unloading %s..." (symbol-name module))
156 (unload-feature module)
157 (message "Unloading %s...done" (symbol-name module))))))
159 ;; arch-tag: 97a3fa16-9d08-40e6-bc2c-36bd70986507
160 ;;; esh-module.el ends here