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