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
|
428
|
229 (defun make-autoload (form file)
|
2548
|
230 "Turn FORM into an autoload or defvar for source file FILE.
|
|
231 Returns nil if FORM is not a special autoload form (i.e. a function definition
|
|
232 or macro definition or a defcustom)."
|
|
233 (let ((car (car-safe form)) expand)
|
|
234 (cond
|
|
235 ;; For complex cases, try again on the macro-expansion.
|
|
236 ((and (memq car '(easy-mmode-define-global-mode
|
|
237 easy-mmode-define-minor-mode define-minor-mode))
|
|
238 (setq expand (let ((load-file-name file)) (macroexpand form)))
|
|
239 (eq (car expand) 'progn)
|
|
240 (memq :autoload-end expand))
|
|
241 (let ((end (memq :autoload-end expand)))
|
|
242 ;; Cut-off anything after the :autoload-end marker.
|
|
243 (setcdr end nil)
|
|
244 (cons 'progn
|
|
245 (mapcar (lambda (form) (make-autoload form file))
|
|
246 (cdr expand)))))
|
|
247
|
|
248 ;; For special function-like operators, use the `autoload' function.
|
|
249 ((memq car '(defun define-skeleton defmacro define-derived-mode
|
|
250 define-generic-mode easy-mmode-define-minor-mode
|
|
251 easy-mmode-define-global-mode
|
|
252 define-minor-mode defun* defmacro*))
|
|
253 (let* ((macrop (memq car '(defmacro defmacro*)))
|
|
254 (name (nth 1 form))
|
|
255 (body (nthcdr (get car 'doc-string-elt) form))
|
|
256 (doc (if (stringp (car body)) (pop body))))
|
|
257 ;; `define-generic-mode' quotes the name, so take care of that
|
|
258 (list 'autoload (if (listp name) name (list 'quote name)) file doc
|
|
259 (or (and (memq car '(define-skeleton define-derived-mode
|
|
260 define-generic-mode
|
|
261 easy-mmode-define-global-mode
|
|
262 easy-mmode-define-minor-mode
|
|
263 define-minor-mode)) t)
|
|
264 (eq (car-safe (car body)) 'interactive))
|
|
265 (if macrop (list 'quote 'macro) nil))))
|
|
266
|
|
267 ;; Convert defcustom to a simpler (and less space-consuming) defvar,
|
|
268 ;; but add some extra stuff if it uses :require.
|
|
269 ((eq car 'defcustom)
|
|
270 (let ((varname (car-safe (cdr-safe form)))
|
|
271 (init (car-safe (cdr-safe (cdr-safe form))))
|
|
272 (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form)))))
|
|
273 (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form))))))
|
|
274 (if (not (plist-get rest :require))
|
|
275 `(defvar ,varname ,init ,doc)
|
|
276 `(progn
|
|
277 (defvar ,varname ,init ,doc)
|
|
278 (custom-add-to-group ,(plist-get rest :group)
|
|
279 ',varname 'custom-variable)
|
|
280 (custom-add-load ',varname
|
|
281 ,(plist-get rest :require))))))
|
|
282
|
|
283 ;; nil here indicates that this is not a special autoload form.
|
|
284 (t nil))))
|
428
|
285
|
996
|
286 (defun make-c-autoload (module)
|
|
287 "Make an autoload list for the DEFUN at point in MODULE.
|
|
288 Returns nil if the DEFUN is malformed."
|
|
289 (and
|
|
290 ;; Match the DEFUN
|
|
291 (search-forward "DEFUN" nil t)
|
|
292 ;; Match the opening parenthesis
|
|
293 (progn
|
|
294 (skip-syntax-forward " ")
|
|
295 (eq (char-after) ?\())
|
|
296 ;; Match the opening quote of the Lisp function name
|
|
297 (progn
|
|
298 (forward-char)
|
|
299 (skip-syntax-forward " ")
|
|
300 (eq (char-after) ?\"))
|
|
301 ;; Extract the Lisp function name, interactive indicator, and docstring
|
|
302 (let* ((func-name (let ((begin (progn (forward-char) (point))))
|
|
303 (search-forward "\"" nil t)
|
|
304 (backward-char)
|
|
305 (intern (buffer-substring begin (point)))))
|
|
306 (interact (progn
|
|
307 (search-forward "," nil t 4)
|
|
308 (skip-syntax-forward " ")
|
|
309 (not (eq (char-after) ?0))))
|
|
310 (begin (progn
|
|
311 (search-forward "/*" nil t)
|
|
312 (forward-line 1)
|
|
313 (point))))
|
|
314 (search-forward "*/" nil t)
|
|
315 (goto-char (match-beginning 0))
|
|
316 (skip-chars-backward " \t\n\f")
|
|
317 (list 'autoload (list 'quote func-name) module
|
|
318 (buffer-substring begin (point)) interact nil))))
|
|
319
|
1232
|
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
321 ;; Generating autoloads for a single file
|
428
|
322
|
|
323 ;;;###autoload
|
2548
|
324 (defun generate-file-autoloads (file)
|
1232
|
325 "Insert at point an autoload section for FILE.
|
428
|
326 autoloads are generated for defuns and defmacros in FILE
|
|
327 marked by `generate-autoload-cookie' (which see).
|
|
328 If FILE is being visited in a buffer, the contents of the buffer
|
|
329 are used."
|
|
330 (interactive "fGenerate autoloads for file: ")
|
1232
|
331 (cond ((string-match "\\.el$" file)
|
2548
|
332 (generate-autoload-type-section
|
1298
|
333 file
|
|
334 (replace-in-string (file-name-nondirectory file) "\\.elc?$" "")
|
2548
|
335 nil #'generate-lisp-file-autoloads-1))
|
1232
|
336 ;; #### jj, are C++ modules possible?
|
|
337 ((string-match "\\.c$" file)
|
2548
|
338 (generate-autoload-type-section
|
1298
|
339 file
|
|
340 (replace-in-string (file-name-nondirectory file) "\\.c$" "")
|
2548
|
341 t #'generate-c-file-autoloads-1))
|
1232
|
342 (t
|
|
343 (error 'wrong-type-argument file "not a C or Elisp source file"))))
|
428
|
344
|
2548
|
345 (defun* generate-autoload-type-section (file load-name literal fun-to-call)
|
1298
|
346 "Insert at point an autoload-type section for FILE.
|
2548
|
347 LOAD-NAME is the non-directory portion of the name, with the final .el, .elc
|
|
348 or .c section removed. If LITERAL, open the file literally, without decoding.
|
|
349 Calls FUN-TO-CALL to compute the autoloads, with the loaded file in the
|
|
350 current buffer, passing it OUTBUF (where to write the autoloads), LOAD-NAME,
|
|
351 and TRIM-NAME (result of calling `autoload-trim-file-name' on FILE)."
|
428
|
352 (let ((outbuf (current-buffer))
|
1298
|
353 (trim-name (autoload-trim-file-name file))
|
428
|
354 (autoloads-done '())
|
|
355 (print-length nil)
|
|
356 (print-readably t) ; XEmacs
|
|
357 (float-output-format nil)
|
1298
|
358 (visited (get-file-buffer file))
|
2548
|
359 suppress-form
|
428
|
360 ;; (done-any nil)
|
|
361 output-end)
|
|
362
|
|
363 ;; If the autoload section we create here uses an absolute
|
|
364 ;; pathname for FILE in its header, and then Emacs is installed
|
|
365 ;; under a different path on another system,
|
|
366 ;; `update-autoloads-here' won't be able to find the files to be
|
|
367 ;; autoloaded. So, if FILE is in the same directory or a
|
|
368 ;; subdirectory of the current buffer's directory, we'll make it
|
|
369 ;; relative to the current buffer's directory.
|
|
370 (setq file (expand-file-name file))
|
2548
|
371 ;; #### FSF 21.2. Do we want this?
|
|
372 ; (let* ((source-truename (file-truename file))
|
|
373 ; (dir-truename (file-name-as-directory
|
|
374 ; (file-truename default-directory)))
|
|
375 ; (len (length dir-truename)))
|
|
376 ; (if (and (< len (length source-truename))
|
|
377 ; (string= dir-truename (substring source-truename 0 len)))
|
|
378 ; (setq file (substring source-truename len))))
|
|
379
|
|
380 ;; Check for suppression form (XEmacs)
|
|
381 (let* ((dir (file-name-directory file))
|
|
382 (_pkg (expand-file-name "_pkg.el" dir))
|
|
383 (pkg-vis (get-file-buffer _pkg))
|
|
384 pkg-buf)
|
|
385 (save-excursion
|
|
386 (when (file-readable-p _pkg)
|
|
387 (unwind-protect
|
|
388 (progn
|
|
389 (let ((find-file-hooks nil)
|
|
390 (enable-local-variables nil))
|
|
391 (set-buffer (or pkg-vis (find-file-noselect _pkg)))
|
|
392 (set-syntax-table emacs-lisp-mode-syntax-table))
|
|
393 (save-excursion
|
|
394 (save-restriction
|
|
395 (widen)
|
|
396 (goto-char (point-min))
|
|
397 (block nil
|
|
398 (while (search-forward "(package-suppress" nil t)
|
|
399 ;; skip over package-name
|
|
400 (forward-sexp 1)
|
|
401 (let ((supfile (read (current-buffer))))
|
|
402 (when (equal supfile load-name)
|
|
403 (setq suppress-form (eval (read (current-buffer))))
|
|
404 (return))))))))
|
|
405 (unless pkg-vis
|
|
406 ;; We created this buffer, so we should kill it.
|
|
407 (if pkg-buf (kill-buffer pkg-buf)))))))
|
428
|
408
|
|
409 (save-excursion
|
|
410 (unwind-protect
|
|
411 (progn
|
2548
|
412 (let (;(find-file-hooks nil)
|
|
413 ;(enable-local-variables nil)
|
|
414 )
|
1298
|
415 (set-buffer (or visited (find-file-noselect file literal literal
|
|
416 )))
|
|
417 ;; This doesn't look right for C files, but it is. The only
|
|
418 ;; place we need the syntax table is when snarfing the Lisp
|
|
419 ;; function name.
|
460
|
420 (set-syntax-table emacs-lisp-mode-syntax-table))
|
2548
|
421 ; (if visited
|
|
422 ; (set-buffer visited)
|
|
423 ; ;; It is faster to avoid visiting the file.
|
|
424 ; (set-buffer (get-buffer-create " *generate-autoload-file*"))
|
|
425 ; (kill-all-local-variables)
|
|
426 ; (erase-buffer)
|
|
427 ; (setq buffer-undo-list t
|
|
428 ; buffer-read-only nil)
|
|
429 ; ;; This doesn't look right for C files, but it is. The only
|
|
430 ; ;; place we need the syntax table is when snarfing the Lisp
|
|
431 ; ;; function name.
|
|
432 ; (emacs-lisp-mode)
|
|
433 ; (if literal
|
|
434 ; (insert-file-contents-literally file nil)
|
|
435 ; (insert-file-contents file nil)))
|
1298
|
436 (unless (setq autoloads-done
|
2548
|
437 (funcall fun-to-call outbuf load-name trim-name))
|
|
438 (return-from generate-autoload-type-section))
|
1298
|
439 )
|
428
|
440 (unless visited
|
1298
|
441 ;; We created this buffer, so we should kill it.
|
|
442 (kill-buffer (current-buffer)))
|
428
|
443 (set-buffer outbuf)
|
|
444 (setq output-end (point-marker))))
|
|
445 (if t ;; done-any
|
|
446 ;; XEmacs -- always do this so that we cache the information
|
|
447 ;; that we've processed the file already.
|
|
448 (progn
|
2548
|
449 ;; Insert the section-header line
|
|
450 ;; which lists the file name and which functions are in it, etc.
|
428
|
451 (insert generate-autoload-section-header)
|
2548
|
452 (prin1 (list 'autoloads autoloads-done load-name trim-name
|
|
453 ;; In FSF 21.2. Also in FSF 19.30. Presumably
|
|
454 ;; deleted from XEmacs.
|
|
455 ;; (nth 5 (file-attributes file))
|
|
456 )
|
428
|
457 outbuf)
|
|
458 (terpri outbuf)
|
2548
|
459 ;; #### Alas, we will have to think about this. Adding this means
|
|
460 ;; that, once we have created or maintained an auto-autoloads file,
|
|
461 ;; we alone and our successors can update the file. The file itself
|
|
462 ;; will work fine in older XEmacsen, but they won't be able to
|
|
463 ;; update autoloads -- hence, to build.
|
|
464 ; ;; Break that line at spaces, to avoid very long lines.
|
|
465 ; ;; Make each sub-line into a comment.
|
|
466 ; (with-current-buffer outbuf
|
|
467 ; (save-excursion
|
|
468 ; (forward-line -1)
|
|
469 ; (while (not (eolp))
|
|
470 ; (move-to-column 64)
|
|
471 ; (skip-chars-forward "^ \n")
|
|
472 ; (or (eolp)
|
|
473 ; (insert "\n" generate-autoload-section-continuation)))))
|
|
474 ;; XEmacs: This was commented out before. #### Correct?
|
|
475 ; (insert ";;; Generated autoloads from "
|
|
476 ; (autoload-trim-file-name file) "\n")
|
|
477 ;; XEmacs -- handle suppression
|
|
478 (when suppress-form
|
|
479 (insert "\n;;; Suppress form from _pkg.el\n")
|
|
480 (insert "(unless " (prin1-to-string suppress-form) "\n\n"))
|
428
|
481 (goto-char output-end)
|
2548
|
482 ;; XEmacs -- handle suppression
|
|
483 (when suppress-form
|
|
484 (insert "\n) ;; unless (suppressed)\n"))
|
428
|
485 (insert generate-autoload-section-trailer)))
|
2548
|
486 ))
|
|
487
|
428
|
488
|
2548
|
489 (defun process-one-lisp-autoload (autoloads-done outbuf load-name)
|
|
490 "Process a single autoload at point and write to OUTBUF.
|
|
491 Point should be just after a magic cookie string (e.g. ;;;###autoload).
|
|
492 Updates AUTOLOADS-DONE and returns the new value."
|
|
493 (skip-chars-forward " \t")
|
|
494 ;; (setq done-any t)
|
|
495 (if (eolp)
|
|
496 ;; Read the next form and make an autoload.
|
|
497 (let* ((form (prog1 (read (current-buffer))
|
|
498 (or (bolp) (forward-line 1))))
|
|
499 (autoload (make-autoload form load-name)))
|
|
500 (if autoload
|
|
501 (setq autoloads-done (cons (nth 1 form)
|
|
502 autoloads-done))
|
|
503 (setq autoload form))
|
|
504 (autoload-print-form autoload outbuf ""))
|
|
505 ;; Copy the rest of the line to the output.
|
|
506 (cond ((looking-at "immediate\\s *$") ; XEmacs
|
|
507 ;; This is here so that you can automatically
|
|
508 ;; have small hook functions copied to
|
|
509 ;; auto-autoloads.el so that it's not necessary
|
|
510 ;; to load a whole file just to get a two-line
|
|
511 ;; do-nothing find-file-hook... --Stig
|
|
512 (forward-line 1)
|
|
513 (let ((begin (point)))
|
|
514 (forward-sexp)
|
|
515 (forward-line 1)
|
|
516 (princ (buffer-substring begin (point)) outbuf)))
|
|
517 (t
|
|
518 (princ (buffer-substring
|
|
519 (progn
|
|
520 ;; Back up over whitespace, to preserve it.
|
|
521 (skip-chars-backward " \f\t")
|
|
522 (if (= (char-after (1+ (point))) ? )
|
|
523 ;; Eat one space.
|
|
524 (forward-char 1))
|
|
525 (point))
|
|
526 (progn (forward-line 1) (point)))
|
|
527 outbuf))))
|
|
528 autoloads-done)
|
|
529
|
|
530 (defun* generate-lisp-file-autoloads-1 (outbuf load-name trim-name)
|
|
531 "Insert at point in OUTBUF an autoload section for an Elisp file.
|
|
532 The file is assumed to be already loaded and in the current buffer.
|
|
533 autoloads are generated for defuns and defmacros marked by
|
|
534 `generate-autoload-cookie' (which see)."
|
1298
|
535 (let ((autoloads-done '())
|
|
536 )
|
|
537 (save-excursion
|
|
538 (save-restriction
|
|
539 (widen)
|
|
540 (goto-char (point-min))
|
|
541 (unless (search-forward generate-autoload-cookie nil t)
|
|
542 (message "No autoloads found in %s" trim-name)
|
2548
|
543 (return-from generate-lisp-file-autoloads-1 nil))
|
1298
|
544
|
|
545 (message "Generating autoloads for %s..." trim-name)
|
|
546 (goto-char (point-min))
|
2548
|
547 (while (not (eobp))
|
|
548 (skip-chars-forward " \t\n\f")
|
1298
|
549 (cond
|
2548
|
550 ((looking-at (regexp-quote generate-autoload-cookie))
|
|
551 (search-forward generate-autoload-cookie)
|
|
552 (setq autoloads-done
|
|
553 (process-one-lisp-autoload autoloads-done outbuf load-name)))
|
1298
|
554 ((looking-at ";")
|
|
555 ;; Don't read the comment.
|
|
556 (forward-line 1))
|
|
557 (t
|
|
558 (forward-sexp 1)
|
|
559 (forward-line 1)))
|
2548
|
560 )))
|
|
561 (or noninteractive ; XEmacs: only need one line in -batch mode.
|
|
562 (message "Generating autoloads for %s...done" trim-name))
|
1298
|
563 autoloads-done))
|
|
564
|
2548
|
565 (defun* generate-c-file-autoloads-1 (outbuf load-name trim-name
|
|
566 &optional funlist)
|
1232
|
567 "Insert at point an autoload section for the C file FILE.
|
1048
|
568 autoloads are generated for defuns and defmacros in FILE
|
996
|
569 marked by `generate-c-autoload-cookie' (which see).
|
|
570 If FILE is being visited in a buffer, the contents of the buffer
|
|
571 are used."
|
1733
|
572 (let ((exists-p-format
|
|
573 "(when (locate-file \"%s\" module-load-path module-extensions)\n")
|
|
574 autoloads-done)
|
996
|
575 (save-excursion
|
1298
|
576 (save-restriction
|
|
577 (widen)
|
|
578 (goto-char (point-min))
|
|
579 ;; Is there a module name comment?
|
|
580 (when (search-forward generate-c-autoload-module nil t)
|
|
581 (skip-chars-forward " \t")
|
|
582 (let ((begin (point)))
|
|
583 (skip-chars-forward "^ \t\n\f")
|
|
584 (setq load-name (buffer-substring begin (point)))))
|
|
585 (if funlist
|
|
586 (progn
|
|
587 (message "Generating autoloads for %s..." trim-name)
|
1733
|
588 (princ (format exists-p-format load-name) outbuf)
|
1298
|
589 (dolist (arg funlist)
|
996
|
590 (goto-char (point-min))
|
1298
|
591 (re-search-forward
|
|
592 (concat "DEFUN (\""
|
|
593 (regexp-quote (symbol-name arg))
|
|
594 "\""))
|
|
595 (goto-char (match-beginning 0))
|
|
596 (let ((autoload (make-c-autoload load-name)))
|
|
597 (when autoload
|
|
598 (push (nth 1 (nth 1 autoload)) autoloads-done)
|
2548
|
599 (autoload-print-form autoload outbuf " "))))
|
1298
|
600 ;; close the princ'd `when' form
|
|
601 (princ ")" outbuf))
|
|
602 (goto-char (point-min))
|
|
603 (let ((match
|
|
604 (search-forward generate-c-autoload-cookie nil t)))
|
|
605 (unless match
|
|
606 (message "No autoloads found in %s" trim-name)
|
|
607 (return-from generate-c-file-autoloads-1 nil))
|
|
608
|
|
609 (message "Generating autoloads for %s..." trim-name)
|
1733
|
610 (princ (format exists-p-format load-name) outbuf)
|
1298
|
611 (while match
|
|
612 (forward-line 1)
|
|
613 (let ((autoload (make-c-autoload load-name)))
|
|
614 (when autoload
|
|
615 (push (nth 1 (nth 1 autoload)) autoloads-done)
|
2548
|
616 (autoload-print-form autoload outbuf " ")))
|
1298
|
617 (setq match
|
|
618 (search-forward generate-c-autoload-cookie nil t)))
|
|
619 ;; close the princ'd `when' form
|
|
620 (princ ")" outbuf)))))
|
2548
|
621 (or noninteractive ; XEmacs: only need one line in -batch mode.
|
|
622 (message "Generating autoloads for %s...done" trim-name))
|
1298
|
623 autoloads-done))
|
996
|
624
|
2548
|
625 ;;;###autoload
|
|
626 (defun generate-custom-defines (file)
|
|
627 "Insert at point a custom-define section for FILE.
|
|
628 If FILE is being visited in a buffer, the contents of the buffer
|
|
629 are used."
|
|
630 (interactive "fGenerate custom defines for file: ")
|
|
631 (cond ((string-match "\\.el$" file)
|
|
632 (generate-autoload-type-section
|
|
633 file
|
|
634 (replace-in-string (file-name-nondirectory file) "\\.elc?$" "")
|
|
635 nil #'generate-custom-defines-1))
|
|
636 ((string-match "\\.c$" file)
|
|
637 ;; no way to generate custom-defines for C files (currently?),
|
|
638 ;; but cannot signal an error.
|
|
639 nil)
|
|
640 (t
|
|
641 (error 'wrong-type-argument file "not a C or Elisp source file"))))
|
1232
|
642
|
2548
|
643 (defun* generate-custom-defines-1 (outbuf load-name trim-name)
|
|
644 "Insert at point in OUTBUF a custom-define section for an Elisp file.
|
|
645 This contains all defcustoms and defgroups in the file.
|
|
646 The file is assumed to be already loaded and in the current buffer."
|
|
647 (let* ((search-regexp-1 "^(\\(defcustom\\|defgroup\\) ")
|
|
648 (search-string-2 ";;;###custom-define")
|
|
649 (search-regexp-2 (regexp-quote search-string-2))
|
|
650 (autoloads-done '()))
|
|
651 (save-excursion
|
|
652 (save-restriction
|
|
653 (widen)
|
|
654 (goto-char (point-min))
|
|
655 (unless (or (re-search-forward search-regexp-1 nil t)
|
|
656 (re-search-forward search-regexp-2 nil t))
|
|
657 (message "No custom defines found in %s" trim-name)
|
|
658 (return-from generate-custom-defines-1 nil))
|
|
659 (message "Generating custom defines for %s..." trim-name)
|
|
660 (princ "(defconst custom-define-current-source-file " outbuf)
|
|
661 (prin1 (file-relative-name (buffer-file-name)
|
|
662 (symbol-value-in-buffer 'default-directory
|
|
663 outbuf)) outbuf)
|
|
664 (princ ")\n" outbuf)
|
|
665
|
|
666 (goto-char (point-min))
|
|
667 (while (not (eobp))
|
|
668 (skip-chars-forward " \t\n\f")
|
|
669 (cond
|
|
670 ((looking-at search-regexp-1)
|
|
671 ;; Read the next form and copy it to make an autoload.
|
|
672 (let* ((form (prog1 (read (current-buffer))
|
|
673 (or (bolp) (forward-line 1))))
|
|
674 (autoload form ;(make-autoload form load-name)
|
|
675 ))
|
|
676 (if autoload
|
|
677 (setq autoloads-done (cons (nth 1 form)
|
|
678 autoloads-done))
|
|
679 (setq autoload form))
|
|
680 (autoload-print-form autoload outbuf ""))
|
|
681 )
|
|
682 ((looking-at search-regexp-2)
|
|
683 (search-forward search-string-2)
|
|
684 (beep)
|
|
685 (setq autoloads-done
|
|
686 (process-one-lisp-autoload autoloads-done outbuf load-name)))
|
|
687 ((looking-at ";")
|
|
688 ;; Don't read the comment.
|
|
689 (forward-line 1))
|
|
690 (t
|
|
691 (forward-sexp 1)
|
|
692 (forward-line 1)))
|
|
693 )))
|
|
694 (or noninteractive ; XEmacs: only need one line in -batch mode.
|
|
695 (message "Generating custom defines for %s...done" trim-name))
|
|
696 autoloads-done))
|
|
697
|
|
698 ;; Assorted utilities for generating autoloads and pieces thereof
|
|
699
|
|
700 (defun autoload-print-form (form outbuf margin)
|
996
|
701 "Print an autoload form, handling special characters.
|
|
702 In particular, print docstrings with escapes inserted before left parentheses
|
|
703 at the beginning of lines and ^L characters."
|
2548
|
704 (cond
|
|
705 ;; If the form is a sequence, recurse.
|
|
706 ((eq (car form) 'progn)
|
|
707 (mapcar #'(lambda (x) (autoload-print-form x outbuf margin))
|
|
708 (cdr form)))
|
|
709 ;; Symbols at the toplevel are meaningless.
|
|
710 ((symbolp form) nil)
|
|
711 (t
|
|
712 (let ((doc-string-elt (get (car-safe form) 'doc-string-elt)))
|
|
713 (if (and doc-string-elt (stringp (nth doc-string-elt form)))
|
|
714 ;; We need to hack the printing because the doc-string must be
|
|
715 ;; printed specially for make-docfile (sigh).
|
|
716 (let* ((p (nthcdr (1- doc-string-elt) form))
|
|
717 (elt (cdr p))
|
|
718 (start-string (format "\n%s(" margin)))
|
|
719 (setcdr p nil)
|
|
720 (princ start-string outbuf)
|
|
721 ;; XEmacs change: don't let ^^L's get into
|
|
722 ;; the file or sorting is hard.
|
|
723 (let ((print-escape-newlines t)
|
|
724 ;;#### FSF 21.2 (print-escape-nonascii t)
|
|
725 (p (point outbuf))
|
|
726 p2)
|
|
727 (mapcar #'(lambda (elt)
|
|
728 (prin1 elt outbuf)
|
|
729 (princ " " outbuf))
|
|
730 form)
|
|
731 (with-current-buffer outbuf
|
|
732 (setq p2 (point-marker))
|
|
733 (goto-char p)
|
|
734 (save-match-data
|
|
735 (while (search-forward "\^L" p2 t)
|
|
736 (delete-char -1)
|
|
737 (insert "\\^L")))
|
|
738 (goto-char p2)))
|
|
739 (princ "\"\\\n" outbuf)
|
|
740 (let ((begin (point outbuf)))
|
|
741 (princ (substring (prin1-to-string (car elt)) 1) outbuf)
|
|
742 ;; Insert a backslash before each ( that appears at the beginning
|
|
743 ;; of a line in the doc string.
|
|
744 (with-current-buffer outbuf
|
|
745 (save-excursion
|
|
746 (while (search-backward start-string begin t)
|
|
747 (forward-char 1)
|
|
748 (insert "\\"))))
|
|
749 (if (null (cdr elt))
|
|
750 (princ ")" outbuf)
|
|
751 (princ " " outbuf)
|
|
752 (princ (substring (prin1-to-string (cdr elt)) 1) outbuf))
|
|
753 (terpri outbuf)
|
|
754 (princ margin outbuf)))
|
|
755 ;; XEmacs change: another ^L hack
|
|
756 (let ((p (point outbuf))
|
|
757 (print-escape-newlines t)
|
|
758 ;;#### FSF 21.2 (print-escape-nonascii t)
|
996
|
759 p2)
|
2548
|
760 (print form outbuf)
|
|
761 (with-current-buffer outbuf
|
996
|
762 (setq p2 (point-marker))
|
|
763 (goto-char p)
|
|
764 (save-match-data
|
|
765 (while (search-forward "\^L" p2 t)
|
|
766 (delete-char -1)
|
|
767 (insert "\\^L")))
|
2548
|
768 (goto-char p2))))))))
|
996
|
769
|
1232
|
770 ;;; Forms which have doc-strings which should be printed specially.
|
|
771 ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is
|
|
772 ;;; the doc-string in FORM.
|
|
773 ;;;
|
2548
|
774 ;;; There used to be the following note here:
|
|
775 ;;; ;;; Note: defconst and defvar should NOT be marked in this way.
|
|
776 ;;; ;;; We don't want to produce defconsts and defvars that
|
|
777 ;;; ;;; make-docfile can grok, because then it would grok them twice,
|
|
778 ;;; ;;; once in foo.el (where they are given with ;;;###autoload) and
|
|
779 ;;; ;;; once in loaddefs.el.
|
|
780 ;;;
|
|
781 ;;; Counter-note: Yes, they should be marked in this way.
|
|
782 ;;; make-docfile only processes those files that are loaded into the
|
|
783 ;;; dumped Emacs, and those files should never have anything
|
|
784 ;;; autoloaded here. The above-feared problem only occurs with files
|
1232
|
785 ;;; which have autoloaded entries *and* are processed by make-docfile;
|
|
786 ;;; there should be no such files.
|
428
|
787
|
1232
|
788 (put 'autoload 'doc-string-elt 3)
|
|
789 (put 'defun 'doc-string-elt 3)
|
|
790 (put 'defun* 'doc-string-elt 3)
|
|
791 (put 'defvar 'doc-string-elt 3)
|
2548
|
792 (put 'defcustom 'doc-string-elt 3)
|
1232
|
793 (put 'defconst 'doc-string-elt 3)
|
|
794 (put 'defmacro 'doc-string-elt 3)
|
|
795 (put 'defmacro* 'doc-string-elt 3)
|
2548
|
796 (put 'defsubst 'doc-string-elt 3)
|
|
797 (put 'define-skeleton 'doc-string-elt 2)
|
1232
|
798 (put 'define-derived-mode 'doc-string-elt 4)
|
2548
|
799 (put 'easy-mmode-define-minor-mode 'doc-string-elt 2)
|
|
800 (put 'define-minor-mode 'doc-string-elt 2)
|
|
801 (put 'define-generic-mode 'doc-string-elt 7)
|
|
802 ;; defin-global-mode has no explicit docstring.
|
|
803 (put 'easy-mmode-define-global-mode 'doc-string-elt 1000)
|
442
|
804
|
1232
|
805 (defun autoload-trim-file-name (file)
|
|
806 "Returns relative pathname of FILE including the last directory.
|
428
|
807
|
1232
|
808 Hard-codes the directory separator as a forward slash."
|
|
809 (setq file (expand-file-name file))
|
|
810 (replace-in-string
|
|
811 (file-relative-name file (file-name-directory
|
|
812 (directory-file-name
|
|
813 (file-name-directory file))))
|
|
814 ;; #### is this a good idea?
|
|
815 "\\\\" "/"))
|
428
|
816
|
2548
|
817 (defun autoload-read-section-header ()
|
|
818 "Read a section header form.
|
|
819 Since continuation lines have been marked as comments,
|
|
820 we must copy the text of the form and remove those comment
|
|
821 markers before we call `read'."
|
|
822 (save-match-data
|
|
823 (let ((beginning (point))
|
|
824 string)
|
|
825 (forward-line 1)
|
|
826 (while (looking-at generate-autoload-section-continuation)
|
|
827 (forward-line 1))
|
|
828 (setq string (buffer-substring beginning (point)))
|
|
829 (with-current-buffer (get-buffer-create " *autoload*")
|
|
830 (erase-buffer)
|
|
831 (insert string)
|
|
832 (goto-char (point-min))
|
|
833 (while (search-forward generate-autoload-section-continuation nil t)
|
|
834 (replace-match " "))
|
|
835 (goto-char (point-min))
|
|
836 (read (current-buffer))))))
|
|
837
|
428
|
838 ;;;###autoload
|
|
839 (defun update-file-autoloads (file)
|
|
840 "Update the autoloads for FILE in `generated-autoload-file'
|
|
841 \(which FILE might bind in its local variables).
|
1232
|
842 This function is a no-op for an autoloads file (ie, a file whose name is
|
|
843 equal to `autoload-file-name')."
|
428
|
844 (interactive "fUpdate autoloads for file: ")
|
|
845 (setq file (expand-file-name file))
|
|
846 (when (and (file-newer-than-file-p file generated-autoload-file)
|
|
847 (not (member (file-name-nondirectory file)
|
|
848 (list autoload-file-name))))
|
|
849
|
|
850 (let ((load-name (replace-in-string (file-name-nondirectory file)
|
996
|
851 "\\.\\(elc?\\|c\\)$"
|
428
|
852 ""))
|
|
853 (trim-name (autoload-trim-file-name file))
|
|
854 section-begin form)
|
|
855 (save-excursion
|
2548
|
856 ;; FSF has: [[ We want to get a value for generated-autoload-file
|
|
857 ;; from the local variables section if it's there. ]] Not
|
|
858 ;; applicable in XEmacs, since we always keep the autoloads
|
|
859 ;; up-to-date.
|
|
860
|
|
861 ;; #### FSF 21.2 adds: [[ We must read/write the file without any
|
|
862 ;; code conversion, but still decode EOLs. ]] Not clear if we need
|
|
863 ;; this. --ben
|
|
864 ;; (let ((coding-system-for-read 'raw-text))
|
428
|
865 (let ((find-file-hooks nil))
|
|
866 (set-buffer (or (get-file-buffer generated-autoload-file)
|
|
867 (find-file-noselect generated-autoload-file))))
|
2548
|
868 ;; FSF 21.2 says:
|
|
869
|
|
870 ;; [[ This is to make generated-autoload-file have Unix EOLs, so
|
|
871 ;; that it is portable to all platforms. ]]
|
|
872 ;; (setq buffer-file-coding-system 'raw-text-unix))
|
|
873 ;; Not applicable in XEmacs, since we always keep the autoloads
|
|
874 ;; up-to-date and recompile when we build.
|
|
875
|
|
876 ;; FSF 21.2: [not applicable to XEmacs]
|
|
877 ; (or (> (buffer-size) 0)
|
|
878 ; (error "Autoloads file %s does not exist" buffer-file-name))
|
|
879 ; (or (file-writable-p buffer-file-name)
|
|
880 ; (error "Autoloads file %s is not writable" buffer-file-name))
|
|
881
|
|
882 ;; NOTE: The rest of this function is totally changed from FSF.
|
|
883 ;; Hence, not synched.
|
|
884
|
428
|
885 ;; Make sure we can scribble in it.
|
|
886 (setq buffer-read-only nil)
|
|
887 ;; First delete all sections for this file.
|
|
888 (goto-char (point-min))
|
|
889 (while (search-forward generate-autoload-section-header nil t)
|
|
890 (setq section-begin (match-beginning 0))
|
2548
|
891 (setq form (autoload-read-section-header))
|
428
|
892 (when (string= (nth 2 form) load-name)
|
|
893 (search-forward generate-autoload-section-trailer)
|
|
894 (delete-region section-begin (point))))
|
|
895
|
|
896 ;; Now find insertion point for new section
|
|
897 (block find-insertion-point
|
|
898 (goto-char (point-min))
|
|
899 (while (search-forward generate-autoload-section-header nil t)
|
2548
|
900 (setq form (autoload-read-section-header))
|
428
|
901 (when (string< trim-name (nth 3 form))
|
|
902 ;; Found alphabetically correct insertion point
|
|
903 (goto-char (match-beginning 0))
|
|
904 (return-from find-insertion-point))
|
|
905 (search-forward generate-autoload-section-trailer))
|
|
906 (when (eq (point) (point-min)) ; No existing entries?
|
|
907 (goto-char (point-max)))) ; Append.
|
|
908
|
|
909 ;; Add in new sections for file
|
2548
|
910 (funcall generate-autoload-function file))
|
428
|
911
|
|
912 (when (interactive-p) (save-buffer)))))
|
|
913
|
1232
|
914 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
915 ;; Utilities for batch updates
|
|
916
|
|
917 ;;;###autoload
|
2548
|
918 (defun batch-update-directory-autoloads ()
|
1232
|
919 "Update the autoloads for a directory, using a specified feature prefix.
|
|
920 Must be used only with -batch. The feature prefix and directory to update
|
|
921 are taken from the first and second elements of `command-line-args-left',
|
|
922 respectively, and they are then removed from `command-line-args-left'.
|
|
923
|
|
924 Runs `update-file-autoloads' on each file in the given directory. Always
|
|
925 rewrites the autoloads file, even if unchanged. Makes a feature name by
|
|
926 applying `autoload-make-feature-name' to the specified feature prefix.
|
|
927
|
|
928 #### The API and semantics of this function are subject to change."
|
|
929 (unless noninteractive
|
2548
|
930 (error "batch-update-directory-autoloads: may be used only with -batch"))
|
|
931 (update-autoload-files (list (cadr command-line-args-left))
|
|
932 (car command-line-args-left) nil t)
|
|
933 (setq command-line-args-left (cddr command-line-args-left)))
|
1232
|
934
|
|
935 ;;;###autoload
|
2548
|
936 (defun batch-update-directory-custom-defines ()
|
|
937 "Update the custom defines for a directory, using a specified feature prefix.
|
|
938 Must be used only with -batch. The feature prefix and directory to update
|
|
939 are taken from the first and second elements of `command-line-args-left',
|
|
940 respectively, and they are then removed from `command-line-args-left'.
|
|
941
|
|
942 Runs `update-file-autoloads' on each file in the given directory. Always
|
|
943 rewrites the autoloads file, even if unchanged. Makes a feature name by
|
|
944 applying `autoload-make-feature-name' to the specified feature prefix.
|
|
945
|
|
946 #### The API and semantics of this function are subject to change."
|
|
947 (unless noninteractive
|
|
948 (error "batch-update-directory-custom-defines: may be used only with -batch"))
|
|
949 (update-custom-define-files (list (cadr command-line-args-left))
|
|
950 (car command-line-args-left) nil t)
|
|
951 (setq command-line-args-left (cddr command-line-args-left)))
|
|
952
|
|
953 ;;;###autoload
|
|
954 (defun update-autoload-files (files-or-dirs feature-prefix
|
|
955 &optional into-file force)
|
1232
|
956 "Update all the autoload files associated with FILES-OR-DIRS.
|
|
957 FILES-OR-DIRS is a list of files and/or directories to be processed.
|
|
958
|
|
959 An appropriate autoload file is chosen and a feature constructed for
|
|
960 each element of FILES-OR-DIRS. Fixup code testing for the autoload file's
|
|
961 feature and to provide the feature is added.
|
|
962
|
2548
|
963 If optional INTO-FILE is non-`nil', it should specify a file into which
|
|
964 the autoloads will be placed. Otherwise, the autoloads will be placed into
|
|
965 a file named `auto-autoloads.el' in the directory of each element in
|
|
966 FILES-OR-DIRS.
|
|
967
|
|
968 FEATURE-PREFIX should be set to an appropriate prefix which will
|
|
969 be concatenated with \"-autoloads\" to produce the feature name. Otherwise
|
|
970 the appropriate autoload file for each file or directory (located in that
|
|
971 directory, or in the directory of the specified file) will be updated with
|
|
972 the directory's or file's autoloads and the protective forms will be added,
|
|
973 and the files will be saved. Use of the default here is unreliable, and
|
|
974 therefore deprecated.
|
1232
|
975
|
|
976 Note that if some of FILES-OR-DIRS are directories, recursion goes only
|
|
977 one level deep.
|
|
978
|
|
979 If FORCE is non-nil, always save out the autoload files even if unchanged."
|
2548
|
980 (or (listp files-or-dirs) (setq files-or-dirs (list files-or-dirs)))
|
1232
|
981 (let ((defdir (directory-file-name default-directory))
|
|
982 ;; value for all-into-one-file
|
2548
|
983 (autoload-feature-name (autoload-make-feature-name feature-prefix))
|
|
984 (enable-local-eval nil) ; Don't query in batch mode.
|
|
985 (autoload-feature-prefix feature-prefix)
|
|
986 ;; protect from change
|
|
987 (generated-autoload-file generated-autoload-file))
|
1232
|
988 (dolist (arg files-or-dirs)
|
|
989 (setq arg (expand-file-name arg defdir))
|
|
990 (cond
|
|
991 ((file-directory-p arg)
|
2548
|
992 (setq generated-autoload-file
|
|
993 (or into-file (expand-file-name autoload-file-name arg)))
|
1232
|
994 (message "Updating autoloads for directory %s..." arg)
|
2548
|
995 (let ((simple-dir (file-name-as-directory
|
|
996 (file-name-nondirectory
|
|
997 (directory-file-name arg))))
|
|
998 (enable-local-eval nil))
|
|
999 (save-excursion
|
|
1000 (let ((find-file-hooks nil))
|
|
1001 (set-buffer (find-file-noselect generated-autoload-file)))
|
|
1002 (goto-char (point-min))
|
|
1003 (while (search-forward generate-autoload-section-header nil t)
|
|
1004 (let* ((begin (match-beginning 0))
|
|
1005 (form (autoload-read-section-header))
|
|
1006 (file (nth 3 form)))
|
|
1007 (when (and (stringp file)
|
|
1008 (string= (file-name-directory file) simple-dir)
|
|
1009 (not (file-exists-p
|
|
1010 (expand-file-name
|
|
1011 (file-name-nondirectory file) arg))))
|
|
1012 ;; Remove the obsolete section.
|
|
1013 (search-forward generate-autoload-section-trailer)
|
|
1014 (delete-region begin (point)))))
|
|
1015 ;; Update or create autoload sections for existing files.
|
|
1016 (mapcar 'update-file-autoloads
|
|
1017 (directory-files arg t "^[^=].*\\.\\(el\\|c\\)$")))))
|
1232
|
1018 ((file-exists-p arg)
|
2548
|
1019 (setq generated-autoload-file
|
|
1020 (or into-file (expand-file-name autoload-file-name
|
|
1021 (file-name-directory arg))))
|
1232
|
1022 (update-file-autoloads arg))
|
|
1023 (t (error "No such file or directory: %s" arg)))
|
2548
|
1024 (when (not into-file)
|
1232
|
1025 (autoload-featurep-protect-autoloads
|
|
1026 (autoload-make-feature-name
|
2548
|
1027 (or feature-prefix
|
|
1028 (file-name-nondirectory (directory-file-name arg)))))
|
1232
|
1029 (if force (set-buffer-modified-p
|
|
1030 t (find-file-noselect generated-autoload-file)))))
|
2548
|
1031 (when into-file
|
1232
|
1032 (autoload-featurep-protect-autoloads autoload-feature-name)
|
|
1033 (if force (set-buffer-modified-p
|
2548
|
1034 t (find-file-noselect into-file))))
|
1232
|
1035 (save-some-buffers t)
|
|
1036 ))
|
|
1037
|
428
|
1038 ;;;###autoload
|
2548
|
1039 (defun update-custom-define-files (files-or-dirs feature-prefix
|
|
1040 &optional into-file force)
|
|
1041 "Update all the custom-define files associated with FILES-OR-DIRS.
|
|
1042 Works just like `update-file-autoloads'."
|
|
1043 (let* ((autoload-feature-suffix "-custom-defines")
|
|
1044 (autoload-file-name "custom-defines.el")
|
|
1045 (generate-autoload-function #'generate-custom-defines))
|
|
1046 (update-autoload-files files-or-dirs feature-prefix into-file force)))
|
428
|
1047
|
1232
|
1048 (defun autoload-featurep-protect-autoloads (sym)
|
428
|
1049 (save-excursion
|
|
1050 (set-buffer (find-file-noselect generated-autoload-file))
|
|
1051 (goto-char (point-min))
|
2548
|
1052 (cond ((eq (point-min) (point-max)) nil)
|
|
1053 ;; if there's some junk in the file but no sections, just
|
|
1054 ;; delete everything. the junk might be stuff inserted by
|
|
1055 ;; an older version of this function.
|
|
1056 ((not (search-forward generate-autoload-section-header nil t))
|
|
1057 (delete-region (point-min) (point-max)))
|
|
1058 (t
|
|
1059 (goto-char (point-min))
|
|
1060 (when (looking-at ";;; DO NOT MODIFY THIS FILE")
|
|
1061 (delete-region (point-min)
|
|
1062 (progn
|
|
1063 (search-forward generate-autoload-section-header)
|
|
1064 (match-beginning 0))))
|
|
1065 ;; Determine and set the coding system for the file if under Mule.
|
|
1066 ;; If there are any extended characters in the input file, use
|
|
1067 ;; `escape-quoted' to make sure that both binary and extended
|
|
1068 ;; characters are output properly and distinguished properly.
|
|
1069 ;; Otherwise, use `raw-text' for maximum portability with non-Mule
|
|
1070 ;; Emacsen.
|
|
1071 (if (or (featurep '(not mule)) ;; Don't scan if no Mule support
|
|
1072 (progn
|
|
1073 (goto-char (point-min))
|
|
1074 ;; mrb- There must be a better way than skip-chars-forward
|
|
1075 (skip-chars-forward (concat (char-to-string 0) "-"
|
|
1076 (char-to-string 255)))
|
|
1077 (eq (point) (point-max))))
|
|
1078 (setq buffer-file-coding-system 'raw-text-unix)
|
|
1079 (setq buffer-file-coding-system 'escape-quoted))
|
|
1080 (goto-char (point-min))
|
|
1081 (insert ";;; DO NOT MODIFY THIS FILE")
|
|
1082 ;; NOTE: XEmacs prior to 21.5.12 or so had a bug in that it
|
|
1083 ;; recognized only one of the two magic-cookie styles (the -*- kind)
|
|
1084 ;; in find-file, but both of them in load. We go ahead and put both
|
|
1085 ;; in, just to be safe.
|
|
1086 (when (eq buffer-file-coding-system 'escape-quoted)
|
|
1087 (insert " -*- coding: escape-quoted; -*-
|
|
1088 \(or (featurep 'mule) (error \"Loading this file requires Mule support\"))
|
|
1089 ;;;###coding system: escape-quoted"))
|
|
1090 (insert "\n(if (featurep '" sym ")")
|
|
1091 (insert " (error \"Feature " sym " already loaded\"))\n")
|
|
1092 (goto-char (point-max))
|
|
1093 (save-excursion
|
|
1094 (forward-line -1)
|
|
1095 (when (looking-at "(provide")
|
|
1096 (delete-region (point) (point-max))))
|
|
1097 (unless (bolp) (insert "\n"))
|
|
1098 (unless (eq (char-before (1- (point))) ?\^L)
|
|
1099 (insert "\^L\n"))
|
|
1100 (insert "(provide '" sym ")\n")))))
|
428
|
1101
|
1232
|
1102 (defun autoload-make-feature-name (&optional prefix)
|
|
1103 "Generate the feature name to protect this auto-autoloads file from PREFIX.
|
428
|
1104
|
1232
|
1105 If PREFIX is nil, it defaults to the value of `autoload-feature-prefix' if
|
|
1106 that is non-nil.
|
|
1107
|
|
1108 The feature name must be globally unique for this version of XEmacs,
|
|
1109 including packages.
|
528
|
1110
|
1232
|
1111 For backward compatibility, if PREFIX and `autoload-feature-prefix' are both
|
|
1112 `nil', PREFIX is computed as the last directory component of
|
|
1113 `generated-autoload-file'. This is likely to result in non-uniqueness, so
|
|
1114 do not use this feature."
|
|
1115 (concat
|
|
1116 (cond (prefix)
|
|
1117 (autoload-feature-prefix)
|
|
1118 ((stringp generated-autoload-file)
|
|
1119 (message "Warning: autoload computing feature prefix.
|
|
1120 You should specify it as an argument to `autoload-make-feature-name'.")
|
|
1121 (file-name-nondirectory
|
|
1122 (directory-file-name
|
|
1123 (file-name-directory generated-autoload-file))))
|
|
1124 (t (error 'invalid-argument
|
|
1125 "Could not compute a feature name")))
|
2548
|
1126 autoload-feature-suffix))
|
1232
|
1127
|
|
1128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1129 ;; Deprecated entry points
|
|
1130
|
|
1131 ;; A grep of the core and packages shows use of `batch-update-autoloads'
|
|
1132 ;; by XEmacs.rules, pcomplete, eshell, oort-gnus; `batch-update-directory'
|
2548
|
1133 ;; by liece. The other two entry points (`batch-update-one-directory',
|
|
1134 ;; `batch-force-update-one-directory') were not used at all.
|
|
1135 ;;
|
|
1136 ;; All except the first are now history. liece has been updated.
|
|
1137 ;; XEmacs.rules has been updated. The others will be, eventually.
|
528
|
1138
|
2548
|
1139 ;; There don't seem to be very many packages that use the first one (the
|
|
1140 ;; "all-into-one-file" variety), and do they actually rely on this
|
|
1141 ;; functionality? --ben
|
|
1142
|
1232
|
1143 ;; but XEmacs.rules does, though maybe it doesn't "rely" on it, and
|
|
1144 ;; modules do now, and that relies on it. --sjt
|
528
|
1145
|
|
1146 ;;;###autoload
|
|
1147 (defun batch-update-autoloads ()
|
|
1148 "Update the autoloads for the files or directories on the command line.
|
|
1149 Runs `update-file-autoloads' on files and `update-directory-autoloads'
|
|
1150 on directories. Must be used only with -batch, and kills Emacs on completion.
|
|
1151 Each file will be processed even if an error occurred previously.
|
|
1152 For example, invoke `xemacs -batch -f batch-update-autoloads *.el'.
|
|
1153 The directory to which the auto-autoloads.el file must be the first parameter
|
|
1154 on the command line."
|
|
1155 (unless noninteractive
|
|
1156 (error "batch-update-autoloads is to be used only with -batch"))
|
2548
|
1157 (update-autoload-files command-line-args-left generated-autoload-file)
|
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
|