Mercurial > hg > xemacs-beta
comparison lisp/autoload.el @ 1232:c08a6fa181d1
[xemacs-hg @ 2003-01-23 11:38:56 by stephent]
commit notice <87lm1cksms.fsf@tleepslib.sk.tsukuba.ac.jp>
autoloads patch <87lm1ig654.fsf@tleepslib.sk.tsukuba.ac.jp>
Martin's info.el patch <877kd5je7e.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Thu, 23 Jan 2003 11:39:01 +0000 |
parents | edc95b5fe4cb |
children | 1b4bc72f433e |
comparison
equal
deleted
inserted
replaced
1231:3f6adebda25c | 1232:c08a6fa181d1 |
---|---|
1 ;;; autoload.el --- maintain autoloads in loaddefs.el. | 1 ;;; autoload.el --- maintain autoloads in auto-autoloads files. |
2 | 2 |
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. | 4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. |
5 ;; Copyright (C) 1996, 2000, 2002 Ben Wing. | 5 ;; Copyright (C) 1996, 2000, 2002 Ben Wing. |
6 | 6 |
26 | 26 |
27 ;;; Synched up with: Not synched with FSF. | 27 ;;; Synched up with: Not synched with FSF. |
28 | 28 |
29 ;;; Commentary: | 29 ;;; Commentary: |
30 | 30 |
31 ;; This code helps XEmacs maintainers keep the loaddefs.el file up to | 31 ;; This code keeps auto-autoloads.el files up to date. It interprets |
32 ;; date. It interprets magic cookies of the form ";;;###autoload" in | 32 ;; magic cookies (of the form ";;;###autoload" in Lisp source files |
33 ;; lisp source files in various useful ways. To learn more, read the | 33 ;; and "/* ###autoload */" in C source files) in various useful ways. |
34 ;; source; if you're going to use this, you'd better be able to. | 34 |
35 ;; Usage | |
36 ;; ===== | |
37 | |
38 ;; Recommended usage for this library, as implemented in the core | |
39 ;; build process, is | |
40 | |
41 ;; xemacs -no-packages -batch \ | |
42 ;; -eval "(setq generated-autoload-file \"PATH\")" \ | |
43 ;; -l autoload -f autoload-update-directory-autoloads PREFIX DIRECTORY | |
44 | |
45 ;; which causes XEmacs to update the file named by PATH from the .el | |
46 ;; files in DIRECTORY (but not recursing into subdirectories) and (if | |
47 ;; the autoload file is not already protected with a feature test) add | |
48 ;; a check and provide for 'PREFIX-autoloads. Currently there is no | |
49 ;; sanity check for the provided feature; it is recommended that you | |
50 ;; nuke any existing auto-autoloads.el before running the command. | |
51 | |
52 ;; There is not yet a recommended API for updating multiple directories | |
53 ;; into a single auto-autoloads file. Using the recipe above for each | |
54 ;; DIRECTORY with the same PATH should work but has not been tested. | |
55 ;; There is no API for recursing into subdirectories. There probably | |
56 ;; won't be; given the wide variety of ways that existing Lisp packages | |
57 ;; arrange their files, and the fact that source packages and installed | |
58 ;; packages have a somewhat different directory structure, this seems far | |
59 ;; too risky. Use a script or a Lisp library with an explicit list of | |
60 ;; PATHs; see update-elc.el for how to do this without recursive invocation | |
61 ;; of XEmacs). | |
62 | |
63 ;; The probable next step is to fix up the packages to use the | |
64 ;; `autoload-update-directory-autoloads' API. However, for backward | |
65 ;; compatibility with XEmacs 21.4 and 21.1, this can't be done quickly. | |
66 | |
67 ;; For now the API used in update-elc-2.el: | |
68 | |
69 ;; (let* ((dir "DIRECTORY") | |
70 ;; (generated-autoload-file (expand-file-name "auto-autoloads.el" dir)) | |
71 ;; (autoload-package-name "PREFIX")) | |
72 ;; (update-autoload-files (list muledir)) | |
73 ;; (byte-recompile-file generated-autoload-file 0)) | |
74 | |
75 ;; is available, but this ugly kludge is deprecated. It will be removed | |
76 ;; in favor of using proper arguments instead of special variables. | |
77 | |
78 ;; For backward compatibility the API used in the packages/XEmacs.rules: | |
79 | |
80 ;; xemacs -vanilla -batch -eval "$(AUTOLOAD_PACKAGE_NAME)" \ | |
81 ;; -l autoload -f batch-update-directory $(AUTOLOAD_PATH) | |
82 | |
83 ;; is supported, and the implementation is unchanged. However, | |
84 ;; revision of the API (in a backward compatible way) and the | |
85 ;; implementation are planned, and until those stabilize it is too | |
86 ;; risky to use this version of XEmacs for package releases. | |
87 | |
88 ;; Implementation: | |
89 ;; =============== | |
90 | |
91 ;; #### This section should be moved to the Internals manual, or | |
92 ;; (maybe) the Lispref, and integrated with the information above. | |
93 ;; Don't believe anything written here; the code is still a mess, and | |
94 ;; this is a lot of guesswork. | |
95 | |
96 ;; Autoloads are used in a number of contexts, including core Lisp, | |
97 ;; packaged Lisp, and ELLs (dynamically loadable compiled objects | |
98 ;; providing Lisp functionality). There two general strategies for | |
99 ;; collecting autoloads. The first is to put autoloads for a package | |
100 ;; in a package-specific auto-autoloads file. This is easy to | |
101 ;; implement, and allows packages to be distributed with prebuilt | |
102 ;; auto-autoloads files. The second is to collect all the autoloads | |
103 ;; in a single global auto-autoloads file. This is alleged to speed | |
104 ;; up initialization significantly, but requires care to ensure that | |
105 ;; auto-autoloads files remain synchronized with the libraries. | |
106 | |
107 ;; The traditional logic for determining where to put autoload | |
108 ;; definitions is complex and is now deprecated. The special variable | |
109 ;; `generated-autoload-file' is used to hold the path to the file, and | |
110 ;; is initialized to the traditional (well, it's a new tradition with | |
111 ;; XEmacs 20) $blddir/lisp/auto-autoloads.el. However, this variable | |
112 ;; may be bound by calling code, or may be generated at collect time | |
113 ;; and I'm not even sure the initialized value was ever used any more. | |
114 | |
115 ;; Because there may be multiple auto-autoloads files in use (in XEmacs | |
116 ;; 21.x with a full complement of packages there are dozens), and they may | |
117 ;; contain initializations that would be dangerous to reexecute, each is | |
118 ;; protected by a feature test. By convention, the feature symbol is of | |
119 ;; the form "NAME-autoloads". For packages, the special variable | |
120 ;; `autoload-package-name' is used to determine NAME. In the core, | |
121 ;; autoloads are defined in the modules (all of which are collected in a | |
122 ;; single auto-autoloads file), using NAME=modules, in the lisp directory | |
123 ;; using NAME=lisp, and in the lisp/mule directory, using NAME=mule, for | |
124 ;; the autoloads feature. These latter are computed by the autoloads | |
125 ;; function at collect time. | |
35 | 126 |
36 ;; ChangeLog: | 127 ;; ChangeLog: |
37 | 128 |
38 ;; Jun-25-2002: Jerry James added code for processing C files, to | 129 ;; See ./ChangeLog. |
39 ;; support modularization | |
40 ;; Sep-26-1997: slb removed code dealing with customization. | |
41 | 130 |
42 ;;; Code: | 131 ;;; Code: |
132 | |
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
134 ;; Standard file and directory names | |
135 | |
136 ;; `autoload-file-name' is defvar'd and initialized in packages.el, | |
137 ;; which is loaded (and dumped) very early. If you find it isn't, you | |
138 ;; know what you're doing. | |
139 | |
140 (defconst autoload-target-directory "../lisp/" | |
141 "Standard directory containing autoload declaration file. | |
142 | |
143 Use `generated-autoload-file' (q.v.) to change its installation location.") | |
144 | |
145 ;; Dynamic variables for communication among functions | |
146 | |
147 (defvar generated-autoload-file | |
148 (expand-file-name autoload-file-name lisp-directory) | |
149 "*File `update-file-autoloads' puts autoloads into. | |
150 A .el file can set this in its local variables section to make its | |
151 autoloads go somewhere else. | |
152 | |
153 Note that `batch-update-directory' binds this variable to its own value, | |
154 generally the file named by `autoload-file-name' in the directory being | |
155 updated. XEmacs.rules setq's this variable for package autoloads.") | |
156 | |
157 (define-obsolete-variable-alias 'autoload-package-name | |
158 'autoload-feature-prefix) | |
159 (defvar autoload-feature-prefix nil | |
160 "If non-nil, use this string to prefix the autoload feature name. | |
161 | |
162 Usually a package name (from AUTOLOAD_PACKAGE_NAME, defined in XEmacs.rules | |
163 in the top of the package hierarchy), or \"auto\" (reserved for the core Lisp | |
164 auto-autoloads file). Highest priority candidate except for an explicit | |
165 argument to `autoload-make-feature-name' (q.v.).") | |
166 | |
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
168 ;; Magic strings in source files | |
169 | |
170 (defconst generate-autoload-cookie ";;;###autoload" | |
171 "Magic comment indicating the following form should be autoloaded. | |
172 Used by `update-file-autoloads'. This string should be | |
173 meaningless to Lisp (e.g., a comment). | |
174 | |
175 This string is used: | |
176 | |
177 ;;;###autoload | |
178 \(defun function-to-be-autoloaded () ...) | |
179 | |
180 If this string appears alone on a line, the following form will be | |
181 read and an autoload made for it. If it is followed by the string | |
182 \"immediate\", then the form on the following line will be copied | |
183 verbatim. If there is further text on the line, that text will be | |
184 copied verbatim to `generated-autoload-file'.") | |
185 | |
186 (defconst generate-c-autoload-cookie "/* ###autoload" | |
187 "Magic C comment indicating the following form should be autoloaded. | |
188 Used by `update-file-autoloads'. This string should be | |
189 meaningless to C (e.g., a comment). | |
190 | |
191 This string is used: | |
192 | |
193 /* ###autoload */ | |
194 DEFUN (\"function-to-be-autoloaded\", ... ) | |
195 | |
196 If this string appears alone on a line, the following form will be | |
197 read and an autoload made for it. If there is further text on the line, | |
198 that text will be copied verbatim to `generated-autoload-file'.") | |
199 | |
200 (defconst generate-c-autoload-module "/* ###module" | |
201 "Magic C comment indicating the module containing autoloaded functions. | |
202 Since a module can consist of multiple C files, the module name may not be | |
203 the same as the C source file base name. In that case, use this comment to | |
204 indicate the actual name of the module from which to autoload functions.") | |
205 | |
206 (defconst generate-autoload-section-header "\f\n;;;### " | |
207 "String inserted before the form identifying | |
208 the section of autoloads for a file.") | |
209 | |
210 (defconst generate-autoload-section-trailer "\n;;;***\n" | |
211 "String which indicates the end of the section of autoloads for a file.") | |
212 | |
213 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
214 ;; Parsing the source file text. | |
215 ;; Autoloads in C source differ from those in Lisp source. For historical | |
216 ;; reasons, functions handling only Lisp don't have "lisp" in their names; | |
217 ;; maybe this should be changed. | |
43 | 218 |
44 (defun make-autoload (form file) | 219 (defun make-autoload (form file) |
45 "Turn a definition generator FORM into an autoload for source file FILE. | 220 "Turn a definition generator FORM into an autoload for source file FILE. |
46 Returns nil if FORM is not a defun, defun*, defmacro, defmacro*, | 221 Returns nil if FORM is not a defun, defun*, defmacro, defmacro*, |
47 define-skeleton, or define-derived-mode." | 222 define-skeleton, or define-derived-mode." |
102 (goto-char (match-beginning 0)) | 277 (goto-char (match-beginning 0)) |
103 (skip-chars-backward " \t\n\f") | 278 (skip-chars-backward " \t\n\f") |
104 (list 'autoload (list 'quote func-name) module | 279 (list 'autoload (list 'quote func-name) module |
105 (buffer-substring begin (point)) interact nil)))) | 280 (buffer-substring begin (point)) interact nil)))) |
106 | 281 |
107 (defvar generate-autoload-cookie ";;;###autoload" | 282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
108 "Magic comment indicating the following form should be autoloaded. | 283 ;; Generating autoloads for a single file |
109 Used by `update-file-autoloads'. This string should be | |
110 meaningless to Lisp (e.g., a comment). | |
111 | |
112 This string is used: | |
113 | |
114 ;;;###autoload | |
115 \(defun function-to-be-autoloaded () ...) | |
116 | |
117 If this string appears alone on a line, the following form will be | |
118 read and an autoload made for it. If it is followed by the string | |
119 \"immediate\", then the form on the following line will be copied | |
120 verbatim. If there is further text on the line, that text will be | |
121 copied verbatim to `generated-autoload-file'.") | |
122 | |
123 (defvar generate-c-autoload-cookie "/* ###autoload" | |
124 "Magic C comment indicating the following form should be autoloaded. | |
125 Used by `update-file-autoloads'. This string should be | |
126 meaningless to C (e.g., a comment). | |
127 | |
128 This string is used: | |
129 | |
130 /* ###autoload */ | |
131 DEFUN (\"function-to-be-autoloaded\", ... ) | |
132 | |
133 If this string appears alone on a line, the following form will be | |
134 read and an autoload made for it. If there is further text on the line, | |
135 that text will be copied verbatim to `generated-autoload-file'.") | |
136 | |
137 (defvar generate-c-autoload-module "/* ###module" | |
138 "Magic C comment indicating the module containing autoloaded functions. | |
139 Since a module can consist of multiple C files, the module name may not be | |
140 the same as the C source file base name. In that case, use this comment to | |
141 indicate the actual name of the module from which to autoload functions.") | |
142 | |
143 (defvar generate-autoload-section-header "\f\n;;;### " | |
144 "String inserted before the form identifying | |
145 the section of autoloads for a file.") | |
146 | |
147 (defvar generate-autoload-section-trailer "\n;;;***\n" | |
148 "String which indicates the end of the section of autoloads for a file.") | |
149 | |
150 (defvar autoload-package-name nil) | |
151 | |
152 ;;; Forms which have doc-strings which should be printed specially. | |
153 ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is | |
154 ;;; the doc-string in FORM. | |
155 ;;; | |
156 ;;; There used to be the following note here: | |
157 ;;; ;;; Note: defconst and defvar should NOT be marked in this way. | |
158 ;;; ;;; We don't want to produce defconsts and defvars that | |
159 ;;; ;;; make-docfile can grok, because then it would grok them twice, | |
160 ;;; ;;; once in foo.el (where they are given with ;;;###autoload) and | |
161 ;;; ;;; once in loaddefs.el. | |
162 ;;; | |
163 ;;; Counter-note: Yes, they should be marked in this way. | |
164 ;;; make-docfile only processes those files that are loaded into the | |
165 ;;; dumped Emacs, and those files should never have anything | |
166 ;;; autoloaded here. The above-feared problem only occurs with files | |
167 ;;; which have autoloaded entries *and* are processed by make-docfile; | |
168 ;;; there should be no such files. | |
169 | |
170 (put 'autoload 'doc-string-elt 3) | |
171 (put 'defun 'doc-string-elt 3) | |
172 (put 'defun* 'doc-string-elt 3) | |
173 (put 'defvar 'doc-string-elt 3) | |
174 (put 'defconst 'doc-string-elt 3) | |
175 (put 'defmacro 'doc-string-elt 3) | |
176 (put 'defmacro* 'doc-string-elt 3) | |
177 (put 'define-skeleton 'doc-string-elt 3) | |
178 (put 'define-derived-mode 'doc-string-elt 4) | |
179 | |
180 (defun autoload-trim-file-name (file) | |
181 "Returns a relative pathname of FILE including the last directory." | |
182 (setq file (expand-file-name file)) | |
183 (replace-in-string | |
184 (file-relative-name file (file-name-directory | |
185 (directory-file-name | |
186 (file-name-directory file)))) | |
187 "\\\\" "/")) | |
188 | 284 |
189 ;;;###autoload | 285 ;;;###autoload |
190 (defun generate-file-autoloads (file &optional funlist) | 286 (defun generate-file-autoloads (file &optional funlist) |
191 "Insert at point a loaddefs autoload section for FILE. | 287 "Insert at point an autoload section for FILE. |
192 autoloads are generated for defuns and defmacros in FILE | 288 autoloads are generated for defuns and defmacros in FILE |
193 marked by `generate-autoload-cookie' (which see). | 289 marked by `generate-autoload-cookie' (which see). |
194 If FILE is being visited in a buffer, the contents of the buffer | 290 If FILE is being visited in a buffer, the contents of the buffer |
195 are used." | 291 are used." |
196 (interactive "fGenerate autoloads for file: ") | 292 (interactive "fGenerate autoloads for file: ") |
197 (if (string-match "\\.el$" file) | 293 (cond ((string-match "\\.el$" file) |
198 (generate-file-autoloads-1 file funlist) | 294 (generate-file-autoloads-1 file funlist)) |
199 (generate-c-file-autoloads-1 file funlist))) | 295 ;; #### jj, are C++ modules possible? |
296 ((string-match "\\.c$" file) | |
297 (generate-c-file-autoloads-1 file funlist)) | |
298 (t | |
299 (error 'wrong-type-argument file "not a C or Elisp source file")))) | |
200 | 300 |
201 (defun* generate-file-autoloads-1 (file funlist) | 301 (defun* generate-file-autoloads-1 (file funlist) |
202 "Insert at point a loaddefs autoload section for FILE. | 302 "Insert at point an autoload section for FILE. |
203 autoloads are generated for defuns and defmacros in FILE | 303 autoloads are generated for defuns and defmacros in FILE |
204 marked by `generate-autoload-cookie' (which see). | 304 marked by `generate-autoload-cookie' (which see). |
205 If FILE is being visited in a buffer, the contents of the buffer | 305 If FILE is being visited in a buffer, the contents of the buffer |
206 are used." | 306 are used." |
207 (let ((outbuf (current-buffer)) | 307 (let ((outbuf (current-buffer)) |
277 (let ((begin (point))) | 377 (let ((begin (point))) |
278 ;; (terpri outbuf) | 378 ;; (terpri outbuf) |
279 (cond ((looking-at "immediate\\s *$") ; XEmacs | 379 (cond ((looking-at "immediate\\s *$") ; XEmacs |
280 ;; This is here so that you can automatically | 380 ;; This is here so that you can automatically |
281 ;; have small hook functions copied to | 381 ;; have small hook functions copied to |
282 ;; loaddefs.el so that it's not necessary to | 382 ;; auto-autoloads.el so that it's not necessary |
283 ;; load a whole file just to get a two-line | 383 ;; to load a whole file just to get a two-line |
284 ;; do-nothing find-file-hook... --Stig | 384 ;; do-nothing find-file-hook... --Stig |
285 (forward-line 1) | 385 (forward-line 1) |
286 (setq begin (point)) | 386 (setq begin (point)) |
287 (forward-sexp) | 387 (forward-sexp) |
288 (forward-line 1)) | 388 (forward-line 1)) |
310 (prin1 (list 'autoloads autoloads-done load-name trim-name) | 410 (prin1 (list 'autoloads autoloads-done load-name trim-name) |
311 outbuf) | 411 outbuf) |
312 (terpri outbuf) | 412 (terpri outbuf) |
313 ;;;; (insert ";;; Generated autoloads from " | 413 ;;;; (insert ";;; Generated autoloads from " |
314 ;;;; (autoload-trim-file-name file) "\n") | 414 ;;;; (autoload-trim-file-name file) "\n") |
315 ;; Warn if we put a line in loaddefs.el | 415 ;; Warn if we put a line in auto-autoloads.el |
316 ;; that is long enough to cause trouble. | 416 ;; that is long enough to cause trouble. |
317 (when (< output-end (point)) | 417 (when (< output-end (point)) |
318 (setq output-end (point-marker))) | 418 (setq output-end (point-marker))) |
319 (while (< (point) output-end) | 419 (while (< (point) output-end) |
320 ;; (let ((beg (point))) | 420 ;; (let ((beg (point))) |
331 (insert generate-autoload-section-trailer))) | 431 (insert generate-autoload-section-trailer))) |
332 (or noninteractive ; XEmacs: only need one line in -batch mode. | 432 (or noninteractive ; XEmacs: only need one line in -batch mode. |
333 (message "Generating autoloads for %s...done" file)))) | 433 (message "Generating autoloads for %s...done" file)))) |
334 | 434 |
335 (defun* generate-c-file-autoloads-1 (file funlist) | 435 (defun* generate-c-file-autoloads-1 (file funlist) |
336 "Insert at point a loaddefs autoload section for the C file FILE. | 436 "Insert at point an autoload section for the C file FILE. |
337 autoloads are generated for defuns and defmacros in FILE | 437 autoloads are generated for defuns and defmacros in FILE |
338 marked by `generate-c-autoload-cookie' (which see). | 438 marked by `generate-c-autoload-cookie' (which see). |
339 If FILE is being visited in a buffer, the contents of the buffer | 439 If FILE is being visited in a buffer, the contents of the buffer |
340 are used." | 440 are used." |
341 (let ((outbuf (current-buffer)) | 441 (let ((outbuf (current-buffer)) |
342 (autoloads-done '()) | 442 (autoloads-done '()) |
343 (load-name (replace-in-string (file-name-nondirectory file) | 443 (load-name (replace-in-string (file-name-nondirectory file) |
344 "\\.c?$" | 444 "\\.c?$" |
345 "")) | 445 "")) |
446 (exists-p-format | |
447 "(file-exists-p (expand-file-name \"%s.%s\" module-directory))") | |
346 (trim-name (autoload-trim-file-name file)) | 448 (trim-name (autoload-trim-file-name file)) |
347 (print-length nil) | 449 (print-length nil) |
348 (print-readably t) | 450 (print-readably t) |
349 (float-output-format nil) | 451 (float-output-format nil) |
350 ;; (done-any nil) | 452 ;; (done-any nil) |
380 (skip-chars-forward "^ \t\n\f") | 482 (skip-chars-forward "^ \t\n\f") |
381 (setq load-name (buffer-substring begin (point))))) | 483 (setq load-name (buffer-substring begin (point))))) |
382 (if funlist | 484 (if funlist |
383 (progn | 485 (progn |
384 (message "Generating autoloads for %s..." trim-name) | 486 (message "Generating autoloads for %s..." trim-name) |
385 (princ "(when (or\n" outbuf) | 487 (princ "(when (or\n " outbuf) |
386 (princ (format | 488 (princ (format exists-p-format load-name "ell") outbuf) |
387 " (file-exists-p (expand-file-name \"%s.ell\" module-directory))\n" | 489 (princ "\n " outbuf) |
388 load-name) outbuf) | 490 (princ (format exists-p-format load-name "dll") outbuf) |
389 (princ (format | 491 (princ "\n " outbuf) |
390 " (file-exists-p (expand-file-name \"%s.dll\" module-directory))\n" | 492 (princ (format exists-p-format load-name "so") outbuf) |
391 load-name) outbuf) | 493 ;; close the princ'd `or' form |
392 (princ (format | 494 (princ ")\n " outbuf) |
393 " (file-exists-p (expand-file-name \"%s.so\" module-directory)))\n" | |
394 load-name) outbuf) | |
395 (dolist (arg funlist) | 495 (dolist (arg funlist) |
396 (goto-char (point-min)) | 496 (goto-char (point-min)) |
397 (re-search-forward | 497 (re-search-forward |
398 (concat "DEFUN (\"" | 498 (concat "DEFUN (\"" |
399 (regexp-quote (symbol-name arg)) | 499 (regexp-quote (symbol-name arg)) |
401 (goto-char (match-beginning 0)) | 501 (goto-char (match-beginning 0)) |
402 (let ((autoload (make-c-autoload load-name))) | 502 (let ((autoload (make-c-autoload load-name))) |
403 (when autoload | 503 (when autoload |
404 (push (nth 1 (nth 1 autoload)) autoloads-done) | 504 (push (nth 1 (nth 1 autoload)) autoloads-done) |
405 (print-autoload autoload 3 outbuf " ")))) | 505 (print-autoload autoload 3 outbuf " ")))) |
506 ;; close the princ'd `when' form | |
406 (princ ")" outbuf)) | 507 (princ ")" outbuf)) |
407 (goto-char (point-min)) | 508 (goto-char (point-min)) |
408 (let ((match | 509 (let ((match |
409 (search-forward generate-c-autoload-cookie nil t))) | 510 (search-forward generate-c-autoload-cookie nil t))) |
410 (unless match | 511 (unless match |
411 (message "No autoloads found in %s" trim-name) | 512 (message "No autoloads found in %s" trim-name) |
412 (return-from generate-c-file-autoloads-1)) | 513 (return-from generate-c-file-autoloads-1)) |
413 | 514 |
414 (message "Generating autoloads for %s..." trim-name) | 515 (message "Generating autoloads for %s..." trim-name) |
415 (princ "(when (or\n" outbuf) | 516 (princ "(when (or\n " outbuf) |
416 (princ (format | 517 (princ (format exists-p-format load-name "ell") outbuf) |
417 " (file-exists-p (expand-file-name \"%s.ell\" module-directory))\n" | 518 (princ "\n " outbuf) |
418 load-name) outbuf) | 519 (princ (format exists-p-format load-name "dll") outbuf) |
419 (princ (format | 520 (princ "\n " outbuf) |
420 " (file-exists-p (expand-file-name \"%s.dll\" module-directory))\n" | 521 (princ (format exists-p-format load-name "so") outbuf) |
421 load-name) outbuf) | 522 ;; close the princ'd `or' form |
422 (princ (format | 523 (princ ")\n " outbuf) |
423 " (file-exists-p (expand-file-name \"%s.so\" module-directory)))\n" | |
424 load-name) outbuf) | |
425 (while match | 524 (while match |
426 (forward-line 1) | 525 (forward-line 1) |
427 (let ((autoload (make-c-autoload load-name))) | 526 (let ((autoload (make-c-autoload load-name))) |
428 (when autoload | 527 (when autoload |
429 (push (nth 1 (nth 1 autoload)) autoloads-done) | 528 (push (nth 1 (nth 1 autoload)) autoloads-done) |
430 (print-autoload autoload 3 outbuf " "))) | 529 (print-autoload autoload 3 outbuf " "))) |
431 (setq match | 530 (setq match |
432 (search-forward generate-c-autoload-cookie nil t))) | 531 (search-forward generate-c-autoload-cookie nil t))) |
532 ;; close the princ'd `when' form | |
433 (princ ")" outbuf)))))) | 533 (princ ")" outbuf)))))) |
434 (unless visited | 534 (unless visited |
435 ;; We created this buffer, so we should kill it. | 535 ;; We created this buffer, so we should kill it. |
436 (kill-buffer (current-buffer))) | 536 (kill-buffer (current-buffer))) |
437 (set-buffer outbuf) | 537 (set-buffer outbuf) |
443 (setq output-end (point-marker))) | 543 (setq output-end (point-marker))) |
444 (goto-char output-end) | 544 (goto-char output-end) |
445 (insert generate-autoload-section-trailer) | 545 (insert generate-autoload-section-trailer) |
446 (or noninteractive ; XEmacs: only need one line in -batch mode. | 546 (or noninteractive ; XEmacs: only need one line in -batch mode. |
447 (message "Generating autoloads for %s...done" trim-name)))) | 547 (message "Generating autoloads for %s...done" trim-name)))) |
548 | |
549 ;; Assorted utilities for generating autoloads and pieces thereof | |
448 | 550 |
449 (defun print-autoload (autoload doc-string-elt outbuf margin) | 551 (defun print-autoload (autoload doc-string-elt outbuf margin) |
450 "Print an autoload form, handling special characters. | 552 "Print an autoload form, handling special characters. |
451 In particular, print docstrings with escapes inserted before left parentheses | 553 In particular, print docstrings with escapes inserted before left parentheses |
452 at the beginning of lines and ^L characters." | 554 at the beginning of lines and ^L characters." |
512 (while (search-forward "\^L" p2 t) | 614 (while (search-forward "\^L" p2 t) |
513 (delete-char -1) | 615 (delete-char -1) |
514 (insert "\\^L"))) | 616 (insert "\\^L"))) |
515 (goto-char p2))))) | 617 (goto-char p2))))) |
516 | 618 |
517 | 619 ;;; Forms which have doc-strings which should be printed specially. |
518 (defconst autoload-file-name "auto-autoloads.el" | 620 ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is |
519 "Generic filename to put autoloads into. | 621 ;;; the doc-string in FORM. |
520 Unless you are an XEmacs maintainer, it is probably unwise to change this.") | 622 ;;; |
521 | 623 ;;; defvar and defconst should be also be marked in this way. There is |
522 (defvar autoload-target-directory "../lisp/" | 624 ;;; no interference from make-docfile, which only processes those files |
523 "Directory to put autoload declaration file into. | 625 ;;; that are loaded into the dumped Emacs, and those files should |
524 Unless you know what you're doing, don't mess with this.") | 626 ;;; never have anything autoloaded here. Problems only occur with files |
525 | 627 ;;; which have autoloaded entries *and* are processed by make-docfile; |
526 (defvar generated-autoload-file | 628 ;;; there should be no such files. |
527 (expand-file-name (concat autoload-target-directory | 629 |
528 autoload-file-name) | 630 (put 'autoload 'doc-string-elt 3) |
529 data-directory) | 631 (put 'defun 'doc-string-elt 3) |
530 "*File `update-file-autoloads' puts autoloads into. | 632 (put 'defun* 'doc-string-elt 3) |
531 A .el file can set this in its local variables section to make its | 633 (put 'defvar 'doc-string-elt 3) |
532 autoloads go somewhere else. | 634 (put 'defconst 'doc-string-elt 3) |
533 | 635 (put 'defmacro 'doc-string-elt 3) |
534 Note that `batch-update-directory' binds this variable to its own value, | 636 (put 'defmacro* 'doc-string-elt 3) |
535 generally the file named `autoload-file-name' in the directory being | 637 (put 'define-skeleton 'doc-string-elt 3) |
536 updated.") | 638 (put 'define-derived-mode 'doc-string-elt 4) |
537 | 639 |
538 (defconst cusload-file-name "custom-load.el" | 640 (defun autoload-trim-file-name (file) |
539 "Generic filename to put custom loads into. | 641 "Returns relative pathname of FILE including the last directory. |
540 Unless you are an XEmacs maintainer, it is probably unwise to change this.") | 642 |
643 Hard-codes the directory separator as a forward slash." | |
644 (setq file (expand-file-name file)) | |
645 (replace-in-string | |
646 (file-relative-name file (file-name-directory | |
647 (directory-file-name | |
648 (file-name-directory file)))) | |
649 ;; #### is this a good idea? | |
650 "\\\\" "/")) | |
541 | 651 |
542 ;;;###autoload | 652 ;;;###autoload |
543 (defun update-file-autoloads (file) | 653 (defun update-file-autoloads (file) |
544 "Update the autoloads for FILE in `generated-autoload-file' | 654 "Update the autoloads for FILE in `generated-autoload-file' |
545 \(which FILE might bind in its local variables). | 655 \(which FILE might bind in its local variables). |
546 This function refuses to update autoloads files." | 656 This function is a no-op for an autoloads file (ie, a file whose name is |
657 equal to `autoload-file-name')." | |
547 (interactive "fUpdate autoloads for file: ") | 658 (interactive "fUpdate autoloads for file: ") |
548 (setq file (expand-file-name file)) | 659 (setq file (expand-file-name file)) |
549 (when (and (file-newer-than-file-p file generated-autoload-file) | 660 (when (and (file-newer-than-file-p file generated-autoload-file) |
550 (not (member (file-name-nondirectory file) | 661 (not (member (file-name-nondirectory file) |
551 (list autoload-file-name)))) | 662 (list autoload-file-name)))) |
636 (search-forward generate-autoload-section-trailer) | 747 (search-forward generate-autoload-section-trailer) |
637 (delete-region begin (point)))) | 748 (delete-region begin (point)))) |
638 (if (stringp file) | 749 (if (stringp file) |
639 (generate-file-autoloads file))))))) | 750 (generate-file-autoloads file))))))) |
640 | 751 |
752 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
753 ;; Utilities for batch updates | |
754 | |
755 ;;;###autoload | |
756 (defun autoload-update-directory-autoloads () | |
757 "Update the autoloads for a directory, using a specified feature prefix. | |
758 Must be used only with -batch. The feature prefix and directory to update | |
759 are taken from the first and second elements of `command-line-args-left', | |
760 respectively, and they are then removed from `command-line-args-left'. | |
761 | |
762 Runs `update-file-autoloads' on each file in the given directory. Always | |
763 rewrites the autoloads file, even if unchanged. Makes a feature name by | |
764 applying `autoload-make-feature-name' to the specified feature prefix. | |
765 | |
766 #### The API and semantics of this function are subject to change." | |
767 (unless noninteractive | |
768 (error "autoload-batch-update-autoloads: may be used only with -batch")) | |
769 (let* ((autoload-feature-prefix (car command-line-args-left)) | |
770 (dir (cadr command-line-args-left)) | |
771 (generated-autoload-file (expand-file-name autoload-file-name dir))) | |
772 (update-autoload-files (list dir) t t) | |
773 (setq command-line-args-left (cddr command-line-args-left)))) | |
774 | |
775 ;;;###autoload | |
776 (defun update-autoload-files (files-or-dirs &optional all-into-one-file force) | |
777 "Update all the autoload files associated with FILES-OR-DIRS. | |
778 FILES-OR-DIRS is a list of files and/or directories to be processed. | |
779 | |
780 An appropriate autoload file is chosen and a feature constructed for | |
781 each element of FILES-OR-DIRS. Fixup code testing for the autoload file's | |
782 feature and to provide the feature is added. | |
783 | |
784 If optional ALL-INTO-ONE-FILE is non-`nil', `generated-autoload-file' | |
785 should be set to the name of an autoload file and all autoloads will be | |
786 placed in that file. `autoload-feature-prefix' should be set to an | |
787 appropriate prefix which will be concatenated with \"-autoloads\" to | |
788 produce the feature name. Otherwise the appropriate autoload file for | |
789 each file or directory (located in that directory, or in the directory of | |
790 the specified file) will be updated with the directory's or file's | |
791 autoloads and the protective forms will be added, and the files will be | |
792 saved. Use of the default here is unreliable, and therefore deprecated. | |
793 | |
794 Note that if some of FILES-OR-DIRS are directories, recursion goes only | |
795 one level deep. | |
796 | |
797 If FORCE is non-nil, always save out the autoload files even if unchanged." | |
798 (let ((defdir (directory-file-name default-directory)) | |
799 ;; value for all-into-one-file | |
800 (autoload-feature-name (autoload-make-feature-name)) | |
801 (enable-local-eval nil)) ; Don't query in batch mode. | |
802 (dolist (arg files-or-dirs) | |
803 (setq arg (expand-file-name arg defdir)) | |
804 (cond | |
805 ((file-directory-p arg) | |
806 (message "Updating autoloads for directory %s..." arg) | |
807 (update-autoloads-from-directory arg)) | |
808 ((file-exists-p arg) | |
809 (update-file-autoloads arg)) | |
810 (t (error "No such file or directory: %s" arg))) | |
811 (when (not all-into-one-file) | |
812 (autoload-featurep-protect-autoloads | |
813 (autoload-make-feature-name | |
814 (file-name-nondirectory (directory-file-name arg)))) | |
815 (if force (set-buffer-modified-p | |
816 t (find-file-noselect generated-autoload-file))))) | |
817 (when all-into-one-file | |
818 (autoload-featurep-protect-autoloads autoload-feature-name) | |
819 (if force (set-buffer-modified-p | |
820 t (find-file-noselect generated-autoload-file)))) | |
821 (save-some-buffers t) | |
822 )) | |
823 | |
641 ;;;###autoload | 824 ;;;###autoload |
642 (defun update-autoloads-from-directory (dir) | 825 (defun update-autoloads-from-directory (dir) |
643 "Update `generated-autoload-file' with all the current autoloads from DIR. | 826 "Update `generated-autoload-file' with all the current autoloads from DIR. |
644 This runs `update-file-autoloads' on each .el and .c file in DIR. | 827 This runs `update-file-autoloads' on each .el and .c file in DIR. |
645 Obsolete autoload entries for files that no longer exist are deleted. | 828 Obsolete autoload entries for files that no longer exist are deleted. |
650 `update-autoload-files' instead." | 833 `update-autoload-files' instead." |
651 (interactive "DUpdate autoloads for directory: ") | 834 (interactive "DUpdate autoloads for directory: ") |
652 (setq dir (expand-file-name dir)) | 835 (setq dir (expand-file-name dir)) |
653 (let ((simple-dir (file-name-as-directory | 836 (let ((simple-dir (file-name-as-directory |
654 (file-name-nondirectory | 837 (file-name-nondirectory |
655 (directory-file-name dir)))) | 838 (directory-file-name dir)))) |
656 (enable-local-eval nil)) | 839 (enable-local-eval nil)) |
657 (save-excursion | 840 (save-excursion |
658 (let ((find-file-hooks nil)) | 841 (let ((find-file-hooks nil)) |
659 (set-buffer (find-file-noselect generated-autoload-file))) | 842 (set-buffer (find-file-noselect generated-autoload-file))) |
660 (goto-char (point-min)) | 843 (goto-char (point-min)) |
676 (mapcar 'update-file-autoloads | 859 (mapcar 'update-file-autoloads |
677 (directory-files dir t "^[^=].*\\.\\(el\\|c\\)$")) | 860 (directory-files dir t "^[^=].*\\.\\(el\\|c\\)$")) |
678 (unless noninteractive | 861 (unless noninteractive |
679 (save-buffer))))) | 862 (save-buffer))))) |
680 | 863 |
681 (defun fixup-autoload-buffer (sym) | 864 (defun autoload-featurep-protect-autoloads (sym) |
682 (save-excursion | 865 (save-excursion |
683 (set-buffer (find-file-noselect generated-autoload-file)) | 866 (set-buffer (find-file-noselect generated-autoload-file)) |
684 (goto-char (point-min)) | 867 (goto-char (point-min)) |
685 (if (and (not (= (point-min) (point-max))) | 868 (if (and (not (= (point-min) (point-max))) |
686 (not (looking-at ";;; DO NOT MODIFY THIS FILE"))) | 869 (not (looking-at ";;; DO NOT MODIFY THIS FILE"))) |
689 (insert "(if (featurep '" sym ")") | 872 (insert "(if (featurep '" sym ")") |
690 (insert " (error \"Already loaded\"))\n") | 873 (insert " (error \"Already loaded\"))\n") |
691 (goto-char (point-max)) | 874 (goto-char (point-max)) |
692 (insert "\n(provide '" sym ")\n"))))) | 875 (insert "\n(provide '" sym ")\n"))))) |
693 | 876 |
694 (defvar autoload-package-name nil) | 877 (defun autoload-make-feature-name (&optional prefix) |
695 | 878 "Generate the feature name to protect this auto-autoloads file from PREFIX. |
696 ;;;###autoload | 879 |
697 (defun update-autoload-files (files-or-dirs &optional all-into-one-file force) | 880 If PREFIX is nil, it defaults to the value of `autoload-feature-prefix' if |
698 "Update all the autoload files associated with FILES-OR-DIRS. | 881 that is non-nil. |
699 FILES-OR-DIRS should be a list of files or directories to be | 882 |
700 processed. If ALL-INTO-ONE-FILE is not given, the appropriate | 883 The feature name must be globally unique for this version of XEmacs, |
701 autoload file for each file or directory (located in that directory, | 884 including packages. |
702 or in the directory of the specified file) will be updated with the | 885 |
703 directory's or file's autoloads, some additional fixup text will be | 886 For backward compatibility, if PREFIX and `autoload-feature-prefix' are both |
704 added, and the files will be saved. If ALL-INTO-ONE-FILE is given, | 887 `nil', PREFIX is computed as the last directory component of |
705 `generated-autoload-file' should be set to the name of the autoload | 888 `generated-autoload-file'. This is likely to result in non-uniqueness, so |
706 file into which the autoloads will be generated, and the autoloads | 889 do not use this feature." |
707 for all files and directories will go into that same file. | 890 (concat |
708 | 891 (cond (prefix) |
709 If FORCE is non-nil, always save out the autoload files even if unchanged." | 892 (autoload-feature-prefix) |
710 (let ((defdir (directory-file-name default-directory)) | 893 ((stringp generated-autoload-file) |
711 (enable-local-eval nil)) ; Don't query in batch mode. | 894 (message "Warning: autoload computing feature prefix. |
712 ;; (message "Updating autoloads in %s..." generated-autoload-file) | 895 You should specify it as an argument to `autoload-make-feature-name'.") |
713 (dolist (arg files-or-dirs) | 896 (file-name-nondirectory |
714 (setq arg (expand-file-name arg defdir)) | 897 (directory-file-name |
715 (let ((generated-autoload-file | 898 (file-name-directory generated-autoload-file)))) |
716 (if all-into-one-file generated-autoload-file | 899 (t (error 'invalid-argument |
717 (expand-file-name autoload-file-name | 900 "Could not compute a feature name"))) |
718 (if (file-directory-p arg) arg | 901 "-autoloads")) |
719 (file-name-directory arg)))))) | 902 |
720 (cond | 903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
721 ((file-directory-p arg) | 904 ;; Deprecated entry points |
722 (message "Updating autoloads for directory %s..." arg) | 905 |
723 (update-autoloads-from-directory arg)) | 906 ;; A grep of the core and packages shows use of `batch-update-autoloads' |
724 ((file-exists-p arg) | 907 ;; by XEmacs.rules, pcomplete, eshell, oort-gnus; `batch-update-directory' |
725 (update-file-autoloads arg)) | 908 ;; by liece. |
726 (t (error "No such file or directory: %s" arg))) | |
727 (when (not all-into-one-file) | |
728 (fixup-autoload-buffer (concat (if autoload-package-name | |
729 autoload-package-name | |
730 (file-name-nondirectory defdir)) | |
731 "-autoloads")) | |
732 (if force (set-buffer-modified-p | |
733 t (find-file-noselect generated-autoload-file)))))) | |
734 (when all-into-one-file | |
735 (fixup-autoload-buffer (concat (if autoload-package-name | |
736 autoload-package-name | |
737 (file-name-nondirectory defdir)) | |
738 "-autoloads")) | |
739 (if force (set-buffer-modified-p | |
740 t (find-file-noselect generated-autoload-file)))) | |
741 (save-some-buffers t) | |
742 ;; (message "Done") | |
743 )) | |
744 | 909 |
745 ;; #### these entry points below are a big mess, especially the | 910 ;; #### these entry points below are a big mess, especially the |
746 ;; first two. there don't seem to be very many packages that use the | 911 ;; first two. there don't seem to be very many packages that use the |
747 ;; first one (the "all-into-one-file" variety), and do they actually | 912 ;; first one (the "all-into-one-file" variety), and do they actually |
748 ;; rely on this functionality? --ben | 913 ;; rely on this functionality? --ben |
914 ;; but XEmacs.rules does, though maybe it doesn't "rely" on it, and | |
915 ;; modules do now, and that relies on it. --sjt | |
749 | 916 |
750 ;;;###autoload | 917 ;;;###autoload |
751 (defun batch-update-autoloads () | 918 (defun batch-update-autoloads () |
752 "Update the autoloads for the files or directories on the command line. | 919 "Update the autoloads for the files or directories on the command line. |
753 Runs `update-file-autoloads' on files and `update-directory-autoloads' | 920 Runs `update-file-autoloads' on files and `update-directory-autoloads' |
763 | 930 |
764 ;;;###autoload | 931 ;;;###autoload |
765 (defun batch-update-directory () | 932 (defun batch-update-directory () |
766 "Update the autoloads for the directories on the command line. | 933 "Update the autoloads for the directories on the command line. |
767 Runs `update-file-autoloads' on each file in the given directory, and must | 934 Runs `update-file-autoloads' on each file in the given directory, and must |
768 be used only with -batch." | 935 be used only with -batch. |
936 | |
937 Uses and removes the first element of `command-line-args-left'." | |
769 (unless noninteractive | 938 (unless noninteractive |
770 (error "batch-update-directory is to be used only with -batch")) | 939 (error "batch-update-directory is to be used only with -batch")) |
771 (update-autoload-files command-line-args-left) | 940 (update-autoload-files command-line-args-left) |
772 ;; (kill-emacs 0) | 941 ;; (kill-emacs 0) |
773 (setq command-line-args-left nil)) | 942 (setq command-line-args-left nil)) |
776 (defun batch-update-one-directory () | 945 (defun batch-update-one-directory () |
777 "Update the autoloads for a single directory on the command line. | 946 "Update the autoloads for a single directory on the command line. |
778 Runs `update-file-autoloads' on each file in the given directory, and must | 947 Runs `update-file-autoloads' on each file in the given directory, and must |
779 be used only with -batch." | 948 be used only with -batch." |
780 (unless noninteractive | 949 (unless noninteractive |
781 (error "batch-update-directory is to be used only with -batch")) | 950 (error "batch-update-one-directory is to be used only with -batch")) |
782 (let ((arg (car command-line-args-left))) | 951 (let ((arg (car command-line-args-left))) |
783 (setq command-line-args-left (cdr command-line-args-left)) | 952 (setq command-line-args-left (cdr command-line-args-left)) |
784 (update-autoload-files (list arg)))) | 953 (update-autoload-files (list arg)))) |
785 | 954 |
786 ;;;###autoload | 955 ;;;###autoload |
787 (defun batch-force-update-one-directory () | 956 (defun batch-force-update-one-directory () |
788 "Update the autoloads for a single directory on the command line. | 957 "Update the autoloads for a single directory on the command line. |
789 Runs `update-file-autoloads' on each file in the given directory, and must | 958 Runs `update-file-autoloads' on each file in the given directory, and must |
790 be used only with -batch. Always rewrite the autoloads file, even if | 959 be used only with -batch. Always rewrites the autoloads file, even if |
791 unchanged." | 960 unchanged. |
961 | |
962 Uses and removes the first element of `command-line-args-left'." | |
792 (unless noninteractive | 963 (unless noninteractive |
793 (error "batch-update-directory is to be used only with -batch")) | 964 (error "batch-force-update-directory is to be used only with -batch")) |
794 (let ((arg (car command-line-args-left))) | 965 (let ((arg (car command-line-args-left))) |
795 (setq command-line-args-left (cdr command-line-args-left)) | 966 (setq command-line-args-left (cdr command-line-args-left)) |
796 (update-autoload-files (list arg) nil t))) | 967 (update-autoload-files (list arg) nil t))) |
797 | 968 |
969 ;; Declare obsolescence | |
970 | |
971 (make-obsolete-variable 'autoload-target-directory | |
972 "Don't use this. Bind `generated-autoload-file' to an absolute path.") | |
973 (make-obsolete 'batch-update-autoloads | |
974 'autoload-update-directory-autoloads) | |
975 (make-obsolete 'batch-update-directory | |
976 'autoload-update-directory-autoloads) | |
977 (make-obsolete 'batch-update-one-directory | |
978 'autoload-update-directory-autoloads) | |
979 (make-obsolete 'batch-force-update-one-directory | |
980 'autoload-update-directory-autoloads) | |
981 | |
798 (provide 'autoload) | 982 (provide 'autoload) |
799 | 983 |
800 ;;; autoload.el ends here | 984 ;;; autoload.el ends here |