Mercurial > hg > xemacs-beta
annotate lisp/autoload.el @ 4694:2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
2009-09-20 Aidan Kehoe <kehoea@parhasard.net>
* help.el (function-arglist):
Show the double-quotes in the sample output, correctly.
Bind print-gensym to nil, now we're using uninterned symbols.
Don't #'mapcar + #'intern to create uppercase symbols, use #'loop
and #'make-symbol instead.
* cl-macs.el (cl-upcase-arg):
Don't intern the upcased symbols we're using for cosmetic reasons.
Trust #'true-list-p in #'cl-function-arglist to detect
circularity.
(cl-function-arglist): Bind print-gensym to nil, now we're
printing uninterned symbols and would prefer to avoid the gensym
syntax.
(cl-transform-lambda): Only add the Common Lisp lambda list:
argument information when that differs frmo the normal argument
information.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 20 Sep 2009 21:41:22 +0100 |
parents | bfb8a26de3cb |
children | fee33ab25966 |
rev | line source |
---|---|
1232 | 1 ;;; autoload.el --- maintain autoloads in auto-autoloads files. |
428 | 2 |
1753 | 3 ;; Copyright (C) 1991-1994, 1997, 2003 Free Software Foundation, Inc. |
428 | 4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. |
2548 | 5 ;; Copyright (C) 1996, 2000, 2002, 2003, 2004 Ben Wing. |
428 | 6 |
2548 | 7 ;; Original Author: Roland McGrath <roland@gnu.ai.mit.edu> |
8 ;; Heavily Modified: XEmacs Maintainers | |
428 | 9 ;; Keywords: maint |
10 | |
11 ;; This file is part of XEmacs. | |
12 | |
13 ;; XEmacs is free software; you can redistribute it and/or modify it | |
14 ;; under the terms of the GNU General Public License as published by | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
18 ;; XEmacs is distributed in the hope that it will be useful, but | |
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 ;; General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
26 ;; 02111-1307, USA. | |
27 | |
2548 | 28 ;;; Synched up with: FSF 21.2 by Ben Wing. |
29 ;;; Note that update-file-autoloads is seriously modified and not really | |
30 ;;; syncable. | |
428 | 31 |
32 ;;; Commentary: | |
33 | |
1232 | 34 ;; This code keeps auto-autoloads.el files up to date. It interprets |
35 ;; magic cookies (of the form ";;;###autoload" in Lisp source files | |
36 ;; and "/* ###autoload */" in C source files) in various useful ways. | |
2548 | 37 ;; It is also used to maintain custom-defines.el files, since most of |
38 ;; the logic for computing them is the same as for auto-autoloads.el. | |
1232 | 39 |
40 ;; Usage | |
41 ;; ===== | |
42 | |
43 ;; Recommended usage for this library, as implemented in the core | |
44 ;; build process, is | |
45 | |
46 ;; xemacs -no-packages -batch \ | |
2548 | 47 ;; -l autoload -f batch-update-directory-autoloads PREFIX DIRECTORY |
1232 | 48 |
49 ;; which causes XEmacs to update the file named by PATH from the .el | |
50 ;; files in DIRECTORY (but not recursing into subdirectories) and (if | |
51 ;; the autoload file is not already protected with a feature test) add | |
52 ;; a check and provide for 'PREFIX-autoloads. Currently there is no | |
53 ;; sanity check for the provided feature; it is recommended that you | |
54 ;; nuke any existing auto-autoloads.el before running the command. | |
55 | |
56 ;; There is not yet a recommended API for updating multiple directories | |
57 ;; into a single auto-autoloads file. Using the recipe above for each | |
58 ;; DIRECTORY with the same PATH should work but has not been tested. | |
59 ;; There is no API for recursing into subdirectories. There probably | |
60 ;; won't be; given the wide variety of ways that existing Lisp packages | |
61 ;; arrange their files, and the fact that source packages and installed | |
62 ;; packages have a somewhat different directory structure, this seems far | |
63 ;; too risky. Use a script or a Lisp library with an explicit list of | |
64 ;; PATHs; see update-elc.el for how to do this without recursive invocation | |
65 ;; of XEmacs). | |
66 | |
67 ;; The probable next step is to fix up the packages to use the | |
2548 | 68 ;; `batch-update-directory-autoloads' API. However, for backward |
1232 | 69 ;; compatibility with XEmacs 21.4 and 21.1, this can't be done quickly. |
70 | |
71 ;; For backward compatibility the API used in the packages/XEmacs.rules: | |
72 | |
73 ;; xemacs -vanilla -batch -eval "$(AUTOLOAD_PACKAGE_NAME)" \ | |
2548 | 74 ;; -l autoload -f batch-update-autoloads $(AUTOLOAD_PATH) |
1232 | 75 |
76 ;; is supported, and the implementation is unchanged. However, | |
77 ;; revision of the API (in a backward compatible way) and the | |
78 ;; implementation are planned, and until those stabilize it is too | |
79 ;; risky to use this version of XEmacs for package releases. | |
80 | |
81 ;; Implementation: | |
82 ;; =============== | |
83 | |
84 ;; #### This section should be moved to the Internals manual, or | |
85 ;; (maybe) the Lispref, and integrated with the information above. | |
86 ;; Don't believe anything written here; the code is still a mess, and | |
87 ;; this is a lot of guesswork. | |
88 | |
89 ;; Autoloads are used in a number of contexts, including core Lisp, | |
90 ;; packaged Lisp, and ELLs (dynamically loadable compiled objects | |
91 ;; providing Lisp functionality). There two general strategies for | |
92 ;; collecting autoloads. The first is to put autoloads for a package | |
93 ;; in a package-specific auto-autoloads file. This is easy to | |
94 ;; implement, and allows packages to be distributed with prebuilt | |
95 ;; auto-autoloads files. The second is to collect all the autoloads | |
96 ;; in a single global auto-autoloads file. This is alleged to speed | |
97 ;; up initialization significantly, but requires care to ensure that | |
98 ;; auto-autoloads files remain synchronized with the libraries. | |
99 | |
100 ;; The traditional logic for determining where to put autoload | |
101 ;; definitions is complex and is now deprecated. The special variable | |
102 ;; `generated-autoload-file' is used to hold the path to the file, and | |
103 ;; is initialized to the traditional (well, it's a new tradition with | |
104 ;; XEmacs 20) $blddir/lisp/auto-autoloads.el. However, this variable | |
105 ;; may be bound by calling code, or may be generated at collect time | |
106 ;; and I'm not even sure the initialized value was ever used any more. | |
107 | |
108 ;; Because there may be multiple auto-autoloads files in use (in XEmacs | |
109 ;; 21.x with a full complement of packages there are dozens), and they may | |
110 ;; contain initializations that would be dangerous to reexecute, each is | |
111 ;; protected by a feature test. By convention, the feature symbol is of | |
112 ;; the form "NAME-autoloads". For packages, the special variable | |
113 ;; `autoload-package-name' is used to determine NAME. In the core, | |
114 ;; autoloads are defined in the modules (all of which are collected in a | |
115 ;; single auto-autoloads file), using NAME=modules, in the lisp directory | |
116 ;; using NAME=lisp, and in the lisp/mule directory, using NAME=mule, for | |
117 ;; the autoloads feature. These latter are computed by the autoloads | |
118 ;; function at collect time. | |
428 | 119 |
120 ;; ChangeLog: | |
121 | |
1232 | 122 ;; See ./ChangeLog. |
428 | 123 |
124 ;;; Code: | |
125 | |
2548 | 126 ;; Need to load easy-mmode because we expand macro calls to easy-mmode |
127 ;; macros in make-autoloads below. | |
128 (require 'easy-mmode) | |
129 | |
1232 | 130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
131 ;; Standard file and directory names | |
132 | |
133 ;; `autoload-file-name' is defvar'd and initialized in packages.el, | |
134 ;; which is loaded (and dumped) very early. If you find it isn't, you | |
135 ;; know what you're doing. | |
136 | |
137 (defconst autoload-target-directory "../lisp/" | |
138 "Standard directory containing autoload declaration file. | |
139 | |
140 Use `generated-autoload-file' (q.v.) to change its installation location.") | |
141 | |
142 ;; Dynamic variables for communication among functions | |
143 | |
2548 | 144 ;; FSF 21.2: |
145 ;; The autoload file is assumed to contain a trailer starting with a FormFeed | |
146 ;; character. | |
147 | |
1232 | 148 (defvar generated-autoload-file |
149 (expand-file-name autoload-file-name lisp-directory) | |
150 "*File `update-file-autoloads' puts autoloads into. | |
151 A .el file can set this in its local variables section to make its | |
152 autoloads go somewhere else. | |
153 | |
154 Note that `batch-update-directory' binds this variable to its own value, | |
155 generally the file named by `autoload-file-name' in the directory being | |
156 updated. XEmacs.rules setq's this variable for package autoloads.") | |
157 | |
2548 | 158 (defvar generate-autoload-function |
159 #'generate-file-autoloads | |
160 "Function to generate the autoloads for a file and insert at point. | |
161 Called with one argument, the file.") | |
162 | |
1232 | 163 (define-obsolete-variable-alias 'autoload-package-name |
164 'autoload-feature-prefix) | |
165 (defvar autoload-feature-prefix nil | |
166 "If non-nil, use this string to prefix the autoload feature name. | |
167 | |
168 Usually a package name (from AUTOLOAD_PACKAGE_NAME, defined in XEmacs.rules | |
169 in the top of the package hierarchy), or \"auto\" (reserved for the core Lisp | |
170 auto-autoloads file). Highest priority candidate except for an explicit | |
171 argument to `autoload-make-feature-name' (q.v.).") | |
172 | |
2548 | 173 (defvar autoload-feature-suffix "-autoloads" |
174 "String added to `autoload-feature-prefix' to create the autoload feature name.") | |
175 | |
1232 | 176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
177 ;; Magic strings in source files | |
178 | |
179 (defconst generate-autoload-cookie ";;;###autoload" | |
180 "Magic comment indicating the following form should be autoloaded. | |
181 Used by `update-file-autoloads'. This string should be | |
182 meaningless to Lisp (e.g., a comment). | |
183 | |
184 This string is used: | |
185 | |
186 ;;;###autoload | |
187 \(defun function-to-be-autoloaded () ...) | |
188 | |
189 If this string appears alone on a line, the following form will be | |
190 read and an autoload made for it. If it is followed by the string | |
191 \"immediate\", then the form on the following line will be copied | |
192 verbatim. If there is further text on the line, that text will be | |
193 copied verbatim to `generated-autoload-file'.") | |
194 | |
195 (defconst generate-c-autoload-cookie "/* ###autoload" | |
196 "Magic C comment indicating the following form should be autoloaded. | |
197 Used by `update-file-autoloads'. This string should be | |
198 meaningless to C (e.g., a comment). | |
199 | |
200 This string is used: | |
201 | |
202 /* ###autoload */ | |
203 DEFUN (\"function-to-be-autoloaded\", ... ) | |
204 | |
205 If this string appears alone on a line, the following form will be | |
206 read and an autoload made for it. If there is further text on the line, | |
207 that text will be copied verbatim to `generated-autoload-file'.") | |
208 | |
209 (defconst generate-c-autoload-module "/* ###module" | |
210 "Magic C comment indicating the module containing autoloaded functions. | |
211 Since a module can consist of multiple C files, the module name may not be | |
212 the same as the C source file base name. In that case, use this comment to | |
213 indicate the actual name of the module from which to autoload functions.") | |
214 | |
215 (defconst generate-autoload-section-header "\f\n;;;### " | |
216 "String inserted before the form identifying | |
217 the section of autoloads for a file.") | |
218 | |
219 (defconst generate-autoload-section-trailer "\n;;;***\n" | |
220 "String which indicates the end of the section of autoloads for a file.") | |
221 | |
2548 | 222 (defconst generate-autoload-section-continuation ";;;;;; " |
223 "String to add on each continuation of the section header form.") | |
224 | |
1232 | 225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
226 ;; Parsing the source file text. | |
2548 | 227 ;; Autoloads in C source differ from those in Lisp source. |
1232 | 228 |
4425
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
229 ; Add operator definitions to autoload-operators.el in the xemacs-base |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
230 ; package. |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
231 (ignore-errors (require 'autoload-operators)) |
4352
d2f4dd8611d9
Factor out lists of operators specially treated by 'make-autoload'.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4332
diff
changeset
|
232 |
4425
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
233 ; As autoload-operators is new, provide stopgap measure for a while. |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
234 (if (not (boundp 'autoload-make-autoload-operators)) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
235 (progn |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
236 (defvar autoload-make-autoload-operators |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
237 '(defun define-skeleton defmacro define-derived-mode define-generic-mode |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
238 easy-mmode-define-minor-mode easy-mmode-define-global-mode |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
239 define-minor-mode defun* defmacro*) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
240 "`defun'-like operators that use `autoload' to load the library.") |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
241 |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
242 (defvar autoload-make-autoload-complex-operators |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
243 '(easy-mmode-define-minor-mode easy-mmode-define-global-mode |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
244 define-minor-mode) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
245 "`defun'-like operators to macroexpand before using `autoload'.") |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
246 |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
247 (put 'autoload 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
248 (put 'defun 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
249 (put 'defun* 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
250 (put 'defvar 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
251 (put 'defcustom 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
252 (put 'defconst 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
253 (put 'defmacro 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
254 (put 'defmacro* 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
255 (put 'defsubst 'doc-string-elt 3) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
256 (put 'define-skeleton 'doc-string-elt 2) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
257 (put 'define-derived-mode 'doc-string-elt 4) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
258 (put 'easy-mmode-define-minor-mode 'doc-string-elt 2) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
259 (put 'define-minor-mode 'doc-string-elt 2) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
260 (put 'define-generic-mode 'doc-string-elt 7) |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
261 ;; defin-global-mode has no explicit docstring. |
bfb8a26de3cb
Move autoload operator definitions to xemacs-base.
Mike Sperber <sperber@deinprogramm.de>
parents:
4352
diff
changeset
|
262 (put 'easy-mmode-define-global-mode 'doc-string-elt 1000))) |
4352
d2f4dd8611d9
Factor out lists of operators specially treated by 'make-autoload'.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4332
diff
changeset
|
263 |
428 | 264 (defun make-autoload (form file) |
2548 | 265 "Turn FORM into an autoload or defvar for source file FILE. |
266 Returns nil if FORM is not a special autoload form (i.e. a function definition | |
267 or macro definition or a defcustom)." | |
268 (let ((car (car-safe form)) expand) | |
269 (cond | |
270 ;; For complex cases, try again on the macro-expansion. | |
4352
d2f4dd8611d9
Factor out lists of operators specially treated by 'make-autoload'.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4332
diff
changeset
|
271 ((and (memq car autoload-make-autoload-complex-operators) |
2548 | 272 (setq expand (let ((load-file-name file)) (macroexpand form))) |
273 (eq (car expand) 'progn) | |
274 (memq :autoload-end expand)) | |
275 (let ((end (memq :autoload-end expand))) | |
276 ;; Cut-off anything after the :autoload-end marker. | |
277 (setcdr end nil) | |
278 (cons 'progn | |
279 (mapcar (lambda (form) (make-autoload form file)) | |
280 (cdr expand))))) | |
281 | |
282 ;; For special function-like operators, use the `autoload' function. | |
4352
d2f4dd8611d9
Factor out lists of operators specially treated by 'make-autoload'.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4332
diff
changeset
|
283 ((memq car autoload-make-autoload-operators) |
2548 | 284 (let* ((macrop (memq car '(defmacro defmacro*))) |
285 (name (nth 1 form)) | |
286 (body (nthcdr (get car 'doc-string-elt) form)) | |
287 (doc (if (stringp (car body)) (pop body)))) | |
288 ;; `define-generic-mode' quotes the name, so take care of that | |
289 (list 'autoload (if (listp name) name (list 'quote name)) file doc | |
290 (or (and (memq car '(define-skeleton define-derived-mode | |
291 define-generic-mode | |
292 easy-mmode-define-global-mode | |
293 easy-mmode-define-minor-mode | |
294 define-minor-mode)) t) | |
295 (eq (car-safe (car body)) 'interactive)) | |
296 (if macrop (list 'quote 'macro) nil)))) | |
297 | |
298 ;; Convert defcustom to a simpler (and less space-consuming) defvar, | |
299 ;; but add some extra stuff if it uses :require. | |
300 ((eq car 'defcustom) | |
301 (let ((varname (car-safe (cdr-safe form))) | |
302 (init (car-safe (cdr-safe (cdr-safe form)))) | |
303 (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form))))) | |
304 (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form)))))) | |
305 (if (not (plist-get rest :require)) | |
306 `(defvar ,varname ,init ,doc) | |
307 `(progn | |
308 (defvar ,varname ,init ,doc) | |
309 (custom-add-to-group ,(plist-get rest :group) | |
310 ',varname 'custom-variable) | |
311 (custom-add-load ',varname | |
312 ,(plist-get rest :require)))))) | |
4303 | 313 ;; Coding systems. #### Would be nice to handle the docstring here too. |
314 ((memq car '(make-coding-system make-8-bit-coding-system)) | |
315 `(autoload-coding-system ,(nth 1 form) '(load ,file))) | |
2548 | 316 ;; nil here indicates that this is not a special autoload form. |
317 (t nil)))) | |
428 | 318 |
996 | 319 (defun make-c-autoload (module) |
320 "Make an autoload list for the DEFUN at point in MODULE. | |
321 Returns nil if the DEFUN is malformed." | |
322 (and | |
323 ;; Match the DEFUN | |
324 (search-forward "DEFUN" nil t) | |
325 ;; Match the opening parenthesis | |
326 (progn | |
327 (skip-syntax-forward " ") | |
328 (eq (char-after) ?\()) | |
329 ;; Match the opening quote of the Lisp function name | |
330 (progn | |
331 (forward-char) | |
332 (skip-syntax-forward " ") | |
333 (eq (char-after) ?\")) | |
334 ;; Extract the Lisp function name, interactive indicator, and docstring | |
335 (let* ((func-name (let ((begin (progn (forward-char) (point)))) | |
336 (search-forward "\"" nil t) | |
337 (backward-char) | |
338 (intern (buffer-substring begin (point))))) | |
339 (interact (progn | |
340 (search-forward "," nil t 4) | |
341 (skip-syntax-forward " ") | |
342 (not (eq (char-after) ?0)))) | |
343 (begin (progn | |
344 (search-forward "/*" nil t) | |
345 (forward-line 1) | |
346 (point)))) | |
347 (search-forward "*/" nil t) | |
348 (goto-char (match-beginning 0)) | |
349 (skip-chars-backward " \t\n\f") | |
350 (list 'autoload (list 'quote func-name) module | |
351 (buffer-substring begin (point)) interact nil)))) | |
352 | |
1232 | 353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
354 ;; Generating autoloads for a single file | |
428 | 355 |
356 ;;;###autoload | |
2548 | 357 (defun generate-file-autoloads (file) |
1232 | 358 "Insert at point an autoload section for FILE. |
428 | 359 autoloads are generated for defuns and defmacros in FILE |
360 marked by `generate-autoload-cookie' (which see). | |
361 If FILE is being visited in a buffer, the contents of the buffer | |
362 are used." | |
363 (interactive "fGenerate autoloads for file: ") | |
1232 | 364 (cond ((string-match "\\.el$" file) |
2548 | 365 (generate-autoload-type-section |
1298 | 366 file |
367 (replace-in-string (file-name-nondirectory file) "\\.elc?$" "") | |
2548 | 368 nil #'generate-lisp-file-autoloads-1)) |
1232 | 369 ;; #### jj, are C++ modules possible? |
370 ((string-match "\\.c$" file) | |
2548 | 371 (generate-autoload-type-section |
1298 | 372 file |
373 (replace-in-string (file-name-nondirectory file) "\\.c$" "") | |
2548 | 374 t #'generate-c-file-autoloads-1)) |
1232 | 375 (t |
376 (error 'wrong-type-argument file "not a C or Elisp source file")))) | |
428 | 377 |
2548 | 378 (defun* generate-autoload-type-section (file load-name literal fun-to-call) |
1298 | 379 "Insert at point an autoload-type section for FILE. |
2548 | 380 LOAD-NAME is the non-directory portion of the name, with the final .el, .elc |
381 or .c section removed. If LITERAL, open the file literally, without decoding. | |
382 Calls FUN-TO-CALL to compute the autoloads, with the loaded file in the | |
383 current buffer, passing it OUTBUF (where to write the autoloads), LOAD-NAME, | |
384 and TRIM-NAME (result of calling `autoload-trim-file-name' on FILE)." | |
428 | 385 (let ((outbuf (current-buffer)) |
1298 | 386 (trim-name (autoload-trim-file-name file)) |
428 | 387 (autoloads-done '()) |
388 (print-length nil) | |
389 (print-readably t) ; XEmacs | |
390 (float-output-format nil) | |
1298 | 391 (visited (get-file-buffer file)) |
2548 | 392 suppress-form |
428 | 393 ;; (done-any nil) |
394 output-end) | |
395 | |
396 ;; If the autoload section we create here uses an absolute | |
397 ;; pathname for FILE in its header, and then Emacs is installed | |
398 ;; under a different path on another system, | |
399 ;; `update-autoloads-here' won't be able to find the files to be | |
400 ;; autoloaded. So, if FILE is in the same directory or a | |
401 ;; subdirectory of the current buffer's directory, we'll make it | |
402 ;; relative to the current buffer's directory. | |
403 (setq file (expand-file-name file)) | |
2548 | 404 ;; #### FSF 21.2. Do we want this? |
405 ; (let* ((source-truename (file-truename file)) | |
406 ; (dir-truename (file-name-as-directory | |
407 ; (file-truename default-directory))) | |
408 ; (len (length dir-truename))) | |
409 ; (if (and (< len (length source-truename)) | |
410 ; (string= dir-truename (substring source-truename 0 len))) | |
411 ; (setq file (substring source-truename len)))) | |
412 | |
413 ;; Check for suppression form (XEmacs) | |
414 (let* ((dir (file-name-directory file)) | |
415 (_pkg (expand-file-name "_pkg.el" dir)) | |
416 (pkg-vis (get-file-buffer _pkg)) | |
417 pkg-buf) | |
418 (save-excursion | |
419 (when (file-readable-p _pkg) | |
420 (unwind-protect | |
421 (progn | |
422 (let ((find-file-hooks nil) | |
423 (enable-local-variables nil)) | |
424 (set-buffer (or pkg-vis (find-file-noselect _pkg))) | |
425 (set-syntax-table emacs-lisp-mode-syntax-table)) | |
426 (save-excursion | |
427 (save-restriction | |
428 (widen) | |
429 (goto-char (point-min)) | |
430 (block nil | |
431 (while (search-forward "(package-suppress" nil t) | |
432 ;; skip over package-name | |
433 (forward-sexp 1) | |
434 (let ((supfile (read (current-buffer)))) | |
435 (when (equal supfile load-name) | |
436 (setq suppress-form (eval (read (current-buffer)))) | |
437 (return)))))))) | |
438 (unless pkg-vis | |
439 ;; We created this buffer, so we should kill it. | |
440 (if pkg-buf (kill-buffer pkg-buf))))))) | |
428 | 441 |
442 (save-excursion | |
443 (unwind-protect | |
444 (progn | |
2548 | 445 (let (;(find-file-hooks nil) |
446 ;(enable-local-variables nil) | |
447 ) | |
1298 | 448 (set-buffer (or visited (find-file-noselect file literal literal |
449 ))) | |
450 ;; This doesn't look right for C files, but it is. The only | |
451 ;; place we need the syntax table is when snarfing the Lisp | |
452 ;; function name. | |
460 | 453 (set-syntax-table emacs-lisp-mode-syntax-table)) |
2548 | 454 ; (if visited |
455 ; (set-buffer visited) | |
456 ; ;; It is faster to avoid visiting the file. | |
457 ; (set-buffer (get-buffer-create " *generate-autoload-file*")) | |
458 ; (kill-all-local-variables) | |
459 ; (erase-buffer) | |
460 ; (setq buffer-undo-list t | |
461 ; buffer-read-only nil) | |
462 ; ;; This doesn't look right for C files, but it is. The only | |
463 ; ;; place we need the syntax table is when snarfing the Lisp | |
464 ; ;; function name. | |
465 ; (emacs-lisp-mode) | |
466 ; (if literal | |
467 ; (insert-file-contents-literally file nil) | |
468 ; (insert-file-contents file nil))) | |
1298 | 469 (unless (setq autoloads-done |
2548 | 470 (funcall fun-to-call outbuf load-name trim-name)) |
471 (return-from generate-autoload-type-section)) | |
1298 | 472 ) |
428 | 473 (unless visited |
1298 | 474 ;; We created this buffer, so we should kill it. |
475 (kill-buffer (current-buffer))) | |
428 | 476 (set-buffer outbuf) |
477 (setq output-end (point-marker)))) | |
478 (if t ;; done-any | |
479 ;; XEmacs -- always do this so that we cache the information | |
480 ;; that we've processed the file already. | |
481 (progn | |
2548 | 482 ;; Insert the section-header line |
483 ;; which lists the file name and which functions are in it, etc. | |
428 | 484 (insert generate-autoload-section-header) |
2548 | 485 (prin1 (list 'autoloads autoloads-done load-name trim-name |
486 ;; In FSF 21.2. Also in FSF 19.30. Presumably | |
487 ;; deleted from XEmacs. | |
488 ;; (nth 5 (file-attributes file)) | |
489 ) | |
428 | 490 outbuf) |
491 (terpri outbuf) | |
2548 | 492 ;; #### Alas, we will have to think about this. Adding this means |
493 ;; that, once we have created or maintained an auto-autoloads file, | |
494 ;; we alone and our successors can update the file. The file itself | |
495 ;; will work fine in older XEmacsen, but they won't be able to | |
496 ;; update autoloads -- hence, to build. | |
497 ; ;; Break that line at spaces, to avoid very long lines. | |
498 ; ;; Make each sub-line into a comment. | |
499 ; (with-current-buffer outbuf | |
500 ; (save-excursion | |
501 ; (forward-line -1) | |
502 ; (while (not (eolp)) | |
503 ; (move-to-column 64) | |
504 ; (skip-chars-forward "^ \n") | |
505 ; (or (eolp) | |
506 ; (insert "\n" generate-autoload-section-continuation))))) | |
507 ;; XEmacs: This was commented out before. #### Correct? | |
508 ; (insert ";;; Generated autoloads from " | |
509 ; (autoload-trim-file-name file) "\n") | |
510 ;; XEmacs -- handle suppression | |
511 (when suppress-form | |
512 (insert "\n;;; Suppress form from _pkg.el\n") | |
513 (insert "(unless " (prin1-to-string suppress-form) "\n\n")) | |
428 | 514 (goto-char output-end) |
2548 | 515 ;; XEmacs -- handle suppression |
516 (when suppress-form | |
517 (insert "\n) ;; unless (suppressed)\n")) | |
428 | 518 (insert generate-autoload-section-trailer))) |
2548 | 519 )) |
520 | |
428 | 521 |
2548 | 522 (defun process-one-lisp-autoload (autoloads-done outbuf load-name) |
523 "Process a single autoload at point and write to OUTBUF. | |
524 Point should be just after a magic cookie string (e.g. ;;;###autoload). | |
525 Updates AUTOLOADS-DONE and returns the new value." | |
526 (skip-chars-forward " \t") | |
527 ;; (setq done-any t) | |
528 (if (eolp) | |
529 ;; Read the next form and make an autoload. | |
530 (let* ((form (prog1 (read (current-buffer)) | |
531 (or (bolp) (forward-line 1)))) | |
532 (autoload (make-autoload form load-name))) | |
533 (if autoload | |
534 (setq autoloads-done (cons (nth 1 form) | |
535 autoloads-done)) | |
536 (setq autoload form)) | |
537 (autoload-print-form autoload outbuf "")) | |
538 ;; Copy the rest of the line to the output. | |
539 (cond ((looking-at "immediate\\s *$") ; XEmacs | |
540 ;; This is here so that you can automatically | |
541 ;; have small hook functions copied to | |
542 ;; auto-autoloads.el so that it's not necessary | |
543 ;; to load a whole file just to get a two-line | |
544 ;; do-nothing find-file-hook... --Stig | |
545 (forward-line 1) | |
546 (let ((begin (point))) | |
547 (forward-sexp) | |
548 (forward-line 1) | |
4332
6ad202d453cb
Insert <immediate> into section header for immediate autoloads.
Mike Sperber <sperber@deinprogramm.de>
parents:
4303
diff
changeset
|
549 (princ (buffer-substring begin (point)) outbuf)) |
6ad202d453cb
Insert <immediate> into section header for immediate autoloads.
Mike Sperber <sperber@deinprogramm.de>
parents:
4303
diff
changeset
|
550 (setq autoloads-done (cons '<immediate> autoloads-done))) |
2548 | 551 (t |
552 (princ (buffer-substring | |
553 (progn | |
554 ;; Back up over whitespace, to preserve it. | |
555 (skip-chars-backward " \f\t") | |
556 (if (= (char-after (1+ (point))) ? ) | |
557 ;; Eat one space. | |
558 (forward-char 1)) | |
559 (point)) | |
560 (progn (forward-line 1) (point))) | |
561 outbuf)))) | |
562 autoloads-done) | |
563 | |
564 (defun* generate-lisp-file-autoloads-1 (outbuf load-name trim-name) | |
565 "Insert at point in OUTBUF an autoload section for an Elisp file. | |
566 The file is assumed to be already loaded and in the current buffer. | |
567 autoloads are generated for defuns and defmacros marked by | |
568 `generate-autoload-cookie' (which see)." | |
1298 | 569 (let ((autoloads-done '()) |
570 ) | |
571 (save-excursion | |
572 (save-restriction | |
573 (widen) | |
574 (goto-char (point-min)) | |
575 (unless (search-forward generate-autoload-cookie nil t) | |
576 (message "No autoloads found in %s" trim-name) | |
2548 | 577 (return-from generate-lisp-file-autoloads-1 nil)) |
1298 | 578 |
579 (message "Generating autoloads for %s..." trim-name) | |
580 (goto-char (point-min)) | |
2548 | 581 (while (not (eobp)) |
582 (skip-chars-forward " \t\n\f") | |
1298 | 583 (cond |
2548 | 584 ((looking-at (regexp-quote generate-autoload-cookie)) |
585 (search-forward generate-autoload-cookie) | |
586 (setq autoloads-done | |
587 (process-one-lisp-autoload autoloads-done outbuf load-name))) | |
1298 | 588 ((looking-at ";") |
589 ;; Don't read the comment. | |
590 (forward-line 1)) | |
591 (t | |
592 (forward-sexp 1) | |
593 (forward-line 1))) | |
2548 | 594 ))) |
595 (or noninteractive ; XEmacs: only need one line in -batch mode. | |
596 (message "Generating autoloads for %s...done" trim-name)) | |
1298 | 597 autoloads-done)) |
598 | |
2548 | 599 (defun* generate-c-file-autoloads-1 (outbuf load-name trim-name |
600 &optional funlist) | |
1232 | 601 "Insert at point an autoload section for the C file FILE. |
1048 | 602 autoloads are generated for defuns and defmacros in FILE |
996 | 603 marked by `generate-c-autoload-cookie' (which see). |
604 If FILE is being visited in a buffer, the contents of the buffer | |
605 are used." | |
1733 | 606 (let ((exists-p-format |
607 "(when (locate-file \"%s\" module-load-path module-extensions)\n") | |
608 autoloads-done) | |
996 | 609 (save-excursion |
1298 | 610 (save-restriction |
611 (widen) | |
612 (goto-char (point-min)) | |
613 ;; Is there a module name comment? | |
614 (when (search-forward generate-c-autoload-module nil t) | |
615 (skip-chars-forward " \t") | |
616 (let ((begin (point))) | |
617 (skip-chars-forward "^ \t\n\f") | |
618 (setq load-name (buffer-substring begin (point))))) | |
619 (if funlist | |
620 (progn | |
621 (message "Generating autoloads for %s..." trim-name) | |
1733 | 622 (princ (format exists-p-format load-name) outbuf) |
1298 | 623 (dolist (arg funlist) |
996 | 624 (goto-char (point-min)) |
1298 | 625 (re-search-forward |
626 (concat "DEFUN (\"" | |
627 (regexp-quote (symbol-name arg)) | |
628 "\"")) | |
629 (goto-char (match-beginning 0)) | |
630 (let ((autoload (make-c-autoload load-name))) | |
631 (when autoload | |
632 (push (nth 1 (nth 1 autoload)) autoloads-done) | |
2548 | 633 (autoload-print-form autoload outbuf " ")))) |
1298 | 634 ;; close the princ'd `when' form |
635 (princ ")" outbuf)) | |
636 (goto-char (point-min)) | |
637 (let ((match | |
638 (search-forward generate-c-autoload-cookie nil t))) | |
639 (unless match | |
640 (message "No autoloads found in %s" trim-name) | |
641 (return-from generate-c-file-autoloads-1 nil)) | |
642 | |
643 (message "Generating autoloads for %s..." trim-name) | |
1733 | 644 (princ (format exists-p-format load-name) outbuf) |
1298 | 645 (while match |
646 (forward-line 1) | |
647 (let ((autoload (make-c-autoload load-name))) | |
648 (when autoload | |
649 (push (nth 1 (nth 1 autoload)) autoloads-done) | |
2548 | 650 (autoload-print-form autoload outbuf " "))) |
1298 | 651 (setq match |
652 (search-forward generate-c-autoload-cookie nil t))) | |
653 ;; close the princ'd `when' form | |
654 (princ ")" outbuf))))) | |
2548 | 655 (or noninteractive ; XEmacs: only need one line in -batch mode. |
656 (message "Generating autoloads for %s...done" trim-name)) | |
1298 | 657 autoloads-done)) |
996 | 658 |
2548 | 659 ;;;###autoload |
660 (defun generate-custom-defines (file) | |
661 "Insert at point a custom-define section for FILE. | |
662 If FILE is being visited in a buffer, the contents of the buffer | |
663 are used." | |
664 (interactive "fGenerate custom defines for file: ") | |
665 (cond ((string-match "\\.el$" file) | |
666 (generate-autoload-type-section | |
667 file | |
668 (replace-in-string (file-name-nondirectory file) "\\.elc?$" "") | |
669 nil #'generate-custom-defines-1)) | |
670 ((string-match "\\.c$" file) | |
671 ;; no way to generate custom-defines for C files (currently?), | |
672 ;; but cannot signal an error. | |
673 nil) | |
674 (t | |
675 (error 'wrong-type-argument file "not a C or Elisp source file")))) | |
1232 | 676 |
2548 | 677 (defun* generate-custom-defines-1 (outbuf load-name trim-name) |
678 "Insert at point in OUTBUF a custom-define section for an Elisp file. | |
679 This contains all defcustoms and defgroups in the file. | |
680 The file is assumed to be already loaded and in the current buffer." | |
681 (let* ((search-regexp-1 "^(\\(defcustom\\|defgroup\\) ") | |
682 (search-string-2 ";;;###custom-define") | |
683 (search-regexp-2 (regexp-quote search-string-2)) | |
684 (autoloads-done '())) | |
685 (save-excursion | |
686 (save-restriction | |
687 (widen) | |
688 (goto-char (point-min)) | |
689 (unless (or (re-search-forward search-regexp-1 nil t) | |
690 (re-search-forward search-regexp-2 nil t)) | |
691 (message "No custom defines found in %s" trim-name) | |
692 (return-from generate-custom-defines-1 nil)) | |
693 (message "Generating custom defines for %s..." trim-name) | |
694 (princ "(defconst custom-define-current-source-file " outbuf) | |
695 (prin1 (file-relative-name (buffer-file-name) | |
696 (symbol-value-in-buffer 'default-directory | |
697 outbuf)) outbuf) | |
698 (princ ")\n" outbuf) | |
699 | |
700 (goto-char (point-min)) | |
701 (while (not (eobp)) | |
702 (skip-chars-forward " \t\n\f") | |
703 (cond | |
704 ((looking-at search-regexp-1) | |
705 ;; Read the next form and copy it to make an autoload. | |
706 (let* ((form (prog1 (read (current-buffer)) | |
707 (or (bolp) (forward-line 1)))) | |
708 (autoload form ;(make-autoload form load-name) | |
709 )) | |
710 (if autoload | |
711 (setq autoloads-done (cons (nth 1 form) | |
712 autoloads-done)) | |
713 (setq autoload form)) | |
714 (autoload-print-form autoload outbuf "")) | |
715 ) | |
716 ((looking-at search-regexp-2) | |
717 (search-forward search-string-2) | |
718 (beep) | |
719 (setq autoloads-done | |
720 (process-one-lisp-autoload autoloads-done outbuf load-name))) | |
721 ((looking-at ";") | |
722 ;; Don't read the comment. | |
723 (forward-line 1)) | |
724 (t | |
725 (forward-sexp 1) | |
726 (forward-line 1))) | |
727 ))) | |
728 (or noninteractive ; XEmacs: only need one line in -batch mode. | |
729 (message "Generating custom defines for %s...done" trim-name)) | |
730 autoloads-done)) | |
731 | |
732 ;; Assorted utilities for generating autoloads and pieces thereof | |
733 | |
734 (defun autoload-print-form (form outbuf margin) | |
996 | 735 "Print an autoload form, handling special characters. |
736 In particular, print docstrings with escapes inserted before left parentheses | |
737 at the beginning of lines and ^L characters." | |
2548 | 738 (cond |
739 ;; If the form is a sequence, recurse. | |
740 ((eq (car form) 'progn) | |
741 (mapcar #'(lambda (x) (autoload-print-form x outbuf margin)) | |
742 (cdr form))) | |
743 ;; Symbols at the toplevel are meaningless. | |
744 ((symbolp form) nil) | |
745 (t | |
746 (let ((doc-string-elt (get (car-safe form) 'doc-string-elt))) | |
747 (if (and doc-string-elt (stringp (nth doc-string-elt form))) | |
748 ;; We need to hack the printing because the doc-string must be | |
749 ;; printed specially for make-docfile (sigh). | |
750 (let* ((p (nthcdr (1- doc-string-elt) form)) | |
751 (elt (cdr p)) | |
752 (start-string (format "\n%s(" margin))) | |
753 (setcdr p nil) | |
754 (princ start-string outbuf) | |
755 ;; XEmacs change: don't let ^^L's get into | |
756 ;; the file or sorting is hard. | |
757 (let ((print-escape-newlines t) | |
758 ;;#### FSF 21.2 (print-escape-nonascii t) | |
759 (p (point outbuf)) | |
760 p2) | |
761 (mapcar #'(lambda (elt) | |
762 (prin1 elt outbuf) | |
763 (princ " " outbuf)) | |
764 form) | |
765 (with-current-buffer outbuf | |
766 (setq p2 (point-marker)) | |
767 (goto-char p) | |
768 (save-match-data | |
769 (while (search-forward "\^L" p2 t) | |
770 (delete-char -1) | |
771 (insert "\\^L"))) | |
772 (goto-char p2))) | |
773 (princ "\"\\\n" outbuf) | |
774 (let ((begin (point outbuf))) | |
775 (princ (substring (prin1-to-string (car elt)) 1) outbuf) | |
776 ;; Insert a backslash before each ( that appears at the beginning | |
777 ;; of a line in the doc string. | |
778 (with-current-buffer outbuf | |
779 (save-excursion | |
780 (while (search-backward start-string begin t) | |
781 (forward-char 1) | |
782 (insert "\\")))) | |
783 (if (null (cdr elt)) | |
784 (princ ")" outbuf) | |
785 (princ " " outbuf) | |
786 (princ (substring (prin1-to-string (cdr elt)) 1) outbuf)) | |
787 (terpri outbuf) | |
788 (princ margin outbuf))) | |
789 ;; XEmacs change: another ^L hack | |
790 (let ((p (point outbuf)) | |
791 (print-escape-newlines t) | |
792 ;;#### FSF 21.2 (print-escape-nonascii t) | |
996 | 793 p2) |
2548 | 794 (print form outbuf) |
795 (with-current-buffer outbuf | |
996 | 796 (setq p2 (point-marker)) |
797 (goto-char p) | |
798 (save-match-data | |
799 (while (search-forward "\^L" p2 t) | |
800 (delete-char -1) | |
801 (insert "\\^L"))) | |
2548 | 802 (goto-char p2)))))))) |
996 | 803 |
1232 | 804 (defun autoload-trim-file-name (file) |
805 "Returns relative pathname of FILE including the last directory. | |
428 | 806 |
1232 | 807 Hard-codes the directory separator as a forward slash." |
808 (setq file (expand-file-name file)) | |
809 (replace-in-string | |
810 (file-relative-name file (file-name-directory | |
811 (directory-file-name | |
812 (file-name-directory file)))) | |
813 ;; #### is this a good idea? | |
814 "\\\\" "/")) | |
428 | 815 |
2548 | 816 (defun autoload-read-section-header () |
817 "Read a section header form. | |
818 Since continuation lines have been marked as comments, | |
819 we must copy the text of the form and remove those comment | |
820 markers before we call `read'." | |
821 (save-match-data | |
822 (let ((beginning (point)) | |
823 string) | |
824 (forward-line 1) | |
825 (while (looking-at generate-autoload-section-continuation) | |
826 (forward-line 1)) | |
827 (setq string (buffer-substring beginning (point))) | |
828 (with-current-buffer (get-buffer-create " *autoload*") | |
829 (erase-buffer) | |
830 (insert string) | |
831 (goto-char (point-min)) | |
832 (while (search-forward generate-autoload-section-continuation nil t) | |
833 (replace-match " ")) | |
834 (goto-char (point-min)) | |
835 (read (current-buffer)))))) | |
836 | |
428 | 837 ;;;###autoload |
838 (defun update-file-autoloads (file) | |
839 "Update the autoloads for FILE in `generated-autoload-file' | |
840 \(which FILE might bind in its local variables). | |
1232 | 841 This function is a no-op for an autoloads file (ie, a file whose name is |
842 equal to `autoload-file-name')." | |
428 | 843 (interactive "fUpdate autoloads for file: ") |
844 (setq file (expand-file-name file)) | |
845 (when (and (file-newer-than-file-p file generated-autoload-file) | |
846 (not (member (file-name-nondirectory file) | |
847 (list autoload-file-name)))) | |
848 | |
849 (let ((load-name (replace-in-string (file-name-nondirectory file) | |
996 | 850 "\\.\\(elc?\\|c\\)$" |
428 | 851 "")) |
852 (trim-name (autoload-trim-file-name file)) | |
853 section-begin form) | |
854 (save-excursion | |
2548 | 855 ;; FSF has: [[ We want to get a value for generated-autoload-file |
856 ;; from the local variables section if it's there. ]] Not | |
857 ;; applicable in XEmacs, since we always keep the autoloads | |
858 ;; up-to-date. | |
859 | |
860 ;; #### FSF 21.2 adds: [[ We must read/write the file without any | |
861 ;; code conversion, but still decode EOLs. ]] Not clear if we need | |
862 ;; this. --ben | |
863 ;; (let ((coding-system-for-read 'raw-text)) | |
428 | 864 (let ((find-file-hooks nil)) |
865 (set-buffer (or (get-file-buffer generated-autoload-file) | |
866 (find-file-noselect generated-autoload-file)))) | |
2548 | 867 ;; FSF 21.2 says: |
868 | |
869 ;; [[ This is to make generated-autoload-file have Unix EOLs, so | |
870 ;; that it is portable to all platforms. ]] | |
871 ;; (setq buffer-file-coding-system 'raw-text-unix)) | |
872 ;; Not applicable in XEmacs, since we always keep the autoloads | |
873 ;; up-to-date and recompile when we build. | |
874 | |
875 ;; FSF 21.2: [not applicable to XEmacs] | |
876 ; (or (> (buffer-size) 0) | |
877 ; (error "Autoloads file %s does not exist" buffer-file-name)) | |
878 ; (or (file-writable-p buffer-file-name) | |
879 ; (error "Autoloads file %s is not writable" buffer-file-name)) | |
880 | |
881 ;; NOTE: The rest of this function is totally changed from FSF. | |
882 ;; Hence, not synched. | |
883 | |
428 | 884 ;; Make sure we can scribble in it. |
885 (setq buffer-read-only nil) | |
886 ;; First delete all sections for this file. | |
887 (goto-char (point-min)) | |
888 (while (search-forward generate-autoload-section-header nil t) | |
889 (setq section-begin (match-beginning 0)) | |
2548 | 890 (setq form (autoload-read-section-header)) |
428 | 891 (when (string= (nth 2 form) load-name) |
892 (search-forward generate-autoload-section-trailer) | |
893 (delete-region section-begin (point)))) | |
894 | |
895 ;; Now find insertion point for new section | |
896 (block find-insertion-point | |
897 (goto-char (point-min)) | |
898 (while (search-forward generate-autoload-section-header nil t) | |
2548 | 899 (setq form (autoload-read-section-header)) |
428 | 900 (when (string< trim-name (nth 3 form)) |
901 ;; Found alphabetically correct insertion point | |
902 (goto-char (match-beginning 0)) | |
903 (return-from find-insertion-point)) | |
904 (search-forward generate-autoload-section-trailer)) | |
905 (when (eq (point) (point-min)) ; No existing entries? | |
906 (goto-char (point-max)))) ; Append. | |
907 | |
908 ;; Add in new sections for file | |
2548 | 909 (funcall generate-autoload-function file)) |
428 | 910 |
911 (when (interactive-p) (save-buffer))))) | |
912 | |
1232 | 913 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
914 ;; Utilities for batch updates | |
915 | |
916 ;;;###autoload | |
2548 | 917 (defun batch-update-directory-autoloads () |
1232 | 918 "Update the autoloads for a directory, using a specified feature prefix. |
919 Must be used only with -batch. The feature prefix and directory to update | |
920 are taken from the first and second elements of `command-line-args-left', | |
921 respectively, and they are then removed from `command-line-args-left'. | |
922 | |
923 Runs `update-file-autoloads' on each file in the given directory. Always | |
924 rewrites the autoloads file, even if unchanged. Makes a feature name by | |
925 applying `autoload-make-feature-name' to the specified feature prefix. | |
926 | |
927 #### The API and semantics of this function are subject to change." | |
928 (unless noninteractive | |
2548 | 929 (error "batch-update-directory-autoloads: may be used only with -batch")) |
930 (update-autoload-files (list (cadr command-line-args-left)) | |
931 (car command-line-args-left) nil t) | |
932 (setq command-line-args-left (cddr command-line-args-left))) | |
1232 | 933 |
934 ;;;###autoload | |
2548 | 935 (defun batch-update-directory-custom-defines () |
936 "Update the custom defines for a directory, using a specified feature prefix. | |
937 Must be used only with -batch. The feature prefix and directory to update | |
938 are taken from the first and second elements of `command-line-args-left', | |
939 respectively, and they are then removed from `command-line-args-left'. | |
940 | |
941 Runs `update-file-autoloads' on each file in the given directory. Always | |
942 rewrites the autoloads file, even if unchanged. Makes a feature name by | |
943 applying `autoload-make-feature-name' to the specified feature prefix. | |
944 | |
945 #### The API and semantics of this function are subject to change." | |
946 (unless noninteractive | |
947 (error "batch-update-directory-custom-defines: may be used only with -batch")) | |
948 (update-custom-define-files (list (cadr command-line-args-left)) | |
949 (car command-line-args-left) nil t) | |
950 (setq command-line-args-left (cddr command-line-args-left))) | |
951 | |
952 ;;;###autoload | |
953 (defun update-autoload-files (files-or-dirs feature-prefix | |
954 &optional into-file force) | |
1232 | 955 "Update all the autoload files associated with FILES-OR-DIRS. |
956 FILES-OR-DIRS is a list of files and/or directories to be processed. | |
957 | |
958 An appropriate autoload file is chosen and a feature constructed for | |
959 each element of FILES-OR-DIRS. Fixup code testing for the autoload file's | |
960 feature and to provide the feature is added. | |
961 | |
2548 | 962 If optional INTO-FILE is non-`nil', it should specify a file into which |
963 the autoloads will be placed. Otherwise, the autoloads will be placed into | |
964 a file named `auto-autoloads.el' in the directory of each element in | |
965 FILES-OR-DIRS. | |
966 | |
967 FEATURE-PREFIX should be set to an appropriate prefix which will | |
968 be concatenated with \"-autoloads\" to produce the feature name. Otherwise | |
969 the appropriate autoload file for each file or directory (located in that | |
970 directory, or in the directory of the specified file) will be updated with | |
971 the directory's or file's autoloads and the protective forms will be added, | |
972 and the files will be saved. Use of the default here is unreliable, and | |
973 therefore deprecated. | |
1232 | 974 |
975 Note that if some of FILES-OR-DIRS are directories, recursion goes only | |
976 one level deep. | |
977 | |
978 If FORCE is non-nil, always save out the autoload files even if unchanged." | |
2548 | 979 (or (listp files-or-dirs) (setq files-or-dirs (list files-or-dirs))) |
1232 | 980 (let ((defdir (directory-file-name default-directory)) |
981 ;; value for all-into-one-file | |
2548 | 982 (autoload-feature-name (autoload-make-feature-name feature-prefix)) |
983 (enable-local-eval nil) ; Don't query in batch mode. | |
984 (autoload-feature-prefix feature-prefix) | |
985 ;; protect from change | |
986 (generated-autoload-file generated-autoload-file)) | |
1232 | 987 (dolist (arg files-or-dirs) |
988 (setq arg (expand-file-name arg defdir)) | |
989 (cond | |
990 ((file-directory-p arg) | |
2548 | 991 (setq generated-autoload-file |
992 (or into-file (expand-file-name autoload-file-name arg))) | |
1232 | 993 (message "Updating autoloads for directory %s..." arg) |
2548 | 994 (let ((simple-dir (file-name-as-directory |
995 (file-name-nondirectory | |
996 (directory-file-name arg)))) | |
997 (enable-local-eval nil)) | |
998 (save-excursion | |
999 (let ((find-file-hooks nil)) | |
1000 (set-buffer (find-file-noselect generated-autoload-file))) | |
1001 (goto-char (point-min)) | |
1002 (while (search-forward generate-autoload-section-header nil t) | |
1003 (let* ((begin (match-beginning 0)) | |
1004 (form (autoload-read-section-header)) | |
1005 (file (nth 3 form))) | |
1006 (when (and (stringp file) | |
1007 (string= (file-name-directory file) simple-dir) | |
1008 (not (file-exists-p | |
1009 (expand-file-name | |
1010 (file-name-nondirectory file) arg)))) | |
1011 ;; Remove the obsolete section. | |
1012 (search-forward generate-autoload-section-trailer) | |
1013 (delete-region begin (point))))) | |
1014 ;; Update or create autoload sections for existing files. | |
1015 (mapcar 'update-file-autoloads | |
1016 (directory-files arg t "^[^=].*\\.\\(el\\|c\\)$"))))) | |
1232 | 1017 ((file-exists-p arg) |
2548 | 1018 (setq generated-autoload-file |
1019 (or into-file (expand-file-name autoload-file-name | |
1020 (file-name-directory arg)))) | |
1232 | 1021 (update-file-autoloads arg)) |
1022 (t (error "No such file or directory: %s" arg))) | |
2548 | 1023 (when (not into-file) |
1232 | 1024 (autoload-featurep-protect-autoloads |
1025 (autoload-make-feature-name | |
2548 | 1026 (or feature-prefix |
1027 (file-name-nondirectory (directory-file-name arg))))) | |
1232 | 1028 (if force (set-buffer-modified-p |
1029 t (find-file-noselect generated-autoload-file))))) | |
2548 | 1030 (when into-file |
1232 | 1031 (autoload-featurep-protect-autoloads autoload-feature-name) |
1032 (if force (set-buffer-modified-p | |
2548 | 1033 t (find-file-noselect into-file)))) |
1232 | 1034 (save-some-buffers t) |
1035 )) | |
1036 | |
428 | 1037 ;;;###autoload |
2548 | 1038 (defun update-custom-define-files (files-or-dirs feature-prefix |
1039 &optional into-file force) | |
1040 "Update all the custom-define files associated with FILES-OR-DIRS. | |
1041 Works just like `update-file-autoloads'." | |
1042 (let* ((autoload-feature-suffix "-custom-defines") | |
1043 (autoload-file-name "custom-defines.el") | |
1044 (generate-autoload-function #'generate-custom-defines)) | |
1045 (update-autoload-files files-or-dirs feature-prefix into-file force))) | |
428 | 1046 |
1232 | 1047 (defun autoload-featurep-protect-autoloads (sym) |
428 | 1048 (save-excursion |
1049 (set-buffer (find-file-noselect generated-autoload-file)) | |
1050 (goto-char (point-min)) | |
2548 | 1051 (cond ((eq (point-min) (point-max)) nil) |
1052 ;; if there's some junk in the file but no sections, just | |
1053 ;; delete everything. the junk might be stuff inserted by | |
1054 ;; an older version of this function. | |
1055 ((not (search-forward generate-autoload-section-header nil t)) | |
1056 (delete-region (point-min) (point-max))) | |
1057 (t | |
1058 (goto-char (point-min)) | |
1059 (when (looking-at ";;; DO NOT MODIFY THIS FILE") | |
1060 (delete-region (point-min) | |
1061 (progn | |
1062 (search-forward generate-autoload-section-header) | |
1063 (match-beginning 0)))) | |
1064 ;; Determine and set the coding system for the file if under Mule. | |
1065 ;; If there are any extended characters in the input file, use | |
1066 ;; `escape-quoted' to make sure that both binary and extended | |
1067 ;; characters are output properly and distinguished properly. | |
1068 ;; Otherwise, use `raw-text' for maximum portability with non-Mule | |
1069 ;; Emacsen. | |
1070 (if (or (featurep '(not mule)) ;; Don't scan if no Mule support | |
1071 (progn | |
1072 (goto-char (point-min)) | |
1073 ;; mrb- There must be a better way than skip-chars-forward | |
1074 (skip-chars-forward (concat (char-to-string 0) "-" | |
1075 (char-to-string 255))) | |
1076 (eq (point) (point-max)))) | |
1077 (setq buffer-file-coding-system 'raw-text-unix) | |
1078 (setq buffer-file-coding-system 'escape-quoted)) | |
1079 (goto-char (point-min)) | |
1080 (insert ";;; DO NOT MODIFY THIS FILE") | |
1081 ;; NOTE: XEmacs prior to 21.5.12 or so had a bug in that it | |
1082 ;; recognized only one of the two magic-cookie styles (the -*- kind) | |
1083 ;; in find-file, but both of them in load. We go ahead and put both | |
1084 ;; in, just to be safe. | |
1085 (when (eq buffer-file-coding-system 'escape-quoted) | |
1086 (insert " -*- coding: escape-quoted; -*- | |
1087 \(or (featurep 'mule) (error \"Loading this file requires Mule support\")) | |
1088 ;;;###coding system: escape-quoted")) | |
1089 (insert "\n(if (featurep '" sym ")") | |
1090 (insert " (error \"Feature " sym " already loaded\"))\n") | |
1091 (goto-char (point-max)) | |
1092 (save-excursion | |
1093 (forward-line -1) | |
1094 (when (looking-at "(provide") | |
1095 (delete-region (point) (point-max)))) | |
1096 (unless (bolp) (insert "\n")) | |
1097 (unless (eq (char-before (1- (point))) ?\^L) | |
1098 (insert "\^L\n")) | |
1099 (insert "(provide '" sym ")\n"))))) | |
428 | 1100 |
1232 | 1101 (defun autoload-make-feature-name (&optional prefix) |
1102 "Generate the feature name to protect this auto-autoloads file from PREFIX. | |
428 | 1103 |
1232 | 1104 If PREFIX is nil, it defaults to the value of `autoload-feature-prefix' if |
1105 that is non-nil. | |
1106 | |
1107 The feature name must be globally unique for this version of XEmacs, | |
1108 including packages. | |
528 | 1109 |
1232 | 1110 For backward compatibility, if PREFIX and `autoload-feature-prefix' are both |
1111 `nil', PREFIX is computed as the last directory component of | |
1112 `generated-autoload-file'. This is likely to result in non-uniqueness, so | |
1113 do not use this feature." | |
1114 (concat | |
1115 (cond (prefix) | |
1116 (autoload-feature-prefix) | |
1117 ((stringp generated-autoload-file) | |
1118 (message "Warning: autoload computing feature prefix. | |
1119 You should specify it as an argument to `autoload-make-feature-name'.") | |
1120 (file-name-nondirectory | |
1121 (directory-file-name | |
1122 (file-name-directory generated-autoload-file)))) | |
1123 (t (error 'invalid-argument | |
1124 "Could not compute a feature name"))) | |
2548 | 1125 autoload-feature-suffix)) |
1232 | 1126 |
1127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1128 ;; Deprecated entry points | |
1129 | |
1130 ;; A grep of the core and packages shows use of `batch-update-autoloads' | |
1131 ;; by XEmacs.rules, pcomplete, eshell, oort-gnus; `batch-update-directory' | |
2548 | 1132 ;; by liece. The other two entry points (`batch-update-one-directory', |
1133 ;; `batch-force-update-one-directory') were not used at all. | |
1134 ;; | |
1135 ;; All except the first are now history. liece has been updated. | |
1136 ;; XEmacs.rules has been updated. The others will be, eventually. | |
528 | 1137 |
2548 | 1138 ;; There don't seem to be very many packages that use the first one (the |
1139 ;; "all-into-one-file" variety), and do they actually rely on this | |
1140 ;; functionality? --ben | |
1141 | |
1232 | 1142 ;; but XEmacs.rules does, though maybe it doesn't "rely" on it, and |
1143 ;; modules do now, and that relies on it. --sjt | |
528 | 1144 |
1145 ;;;###autoload | |
1146 (defun batch-update-autoloads () | |
1147 "Update the autoloads for the files or directories on the command line. | |
1148 Runs `update-file-autoloads' on files and `update-directory-autoloads' | |
1149 on directories. Must be used only with -batch, and kills Emacs on completion. | |
1150 Each file will be processed even if an error occurred previously. | |
1151 For example, invoke `xemacs -batch -f batch-update-autoloads *.el'. | |
1152 The directory to which the auto-autoloads.el file must be the first parameter | |
1153 on the command line." | |
1154 (unless noninteractive | |
1155 (error "batch-update-autoloads is to be used only with -batch")) | |
3431 | 1156 (update-autoload-files command-line-args-left autoload-feature-prefix |
1157 generated-autoload-file t) | |
528 | 1158 (kill-emacs 0)) |
442 | 1159 |
1232 | 1160 ;; Declare obsolescence |
1161 | |
1162 (make-obsolete-variable 'autoload-target-directory | |
1163 "Don't use this. Bind `generated-autoload-file' to an absolute path.") | |
1164 (make-obsolete 'batch-update-autoloads | |
1165 'autoload-update-directory-autoloads) | |
1166 | |
428 | 1167 (provide 'autoload) |
1168 | |
1169 ;;; autoload.el ends here |