(help-argument-name): Don't autoload.
[bpt/emacs.git] / lisp / emacs-lisp / autoload.el
CommitLineData
56eebc29 1;; autoload.el --- maintain autoloads in loaddefs.el
c0274f38 2
b7a45ee1 3;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003,
3731a850 4;; 2004, 2005 Free Software Foundation, Inc.
b578f267 5
5762abec 6;; Author: Roland McGrath <roland@gnu.org>
e9571d2a 7;; Keywords: maint
e5167999 8
b578f267
EN
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
0231f2dc 25
07b3798c 26;;; Commentary:
e41b2db1 27
00ee57f3 28;; This code helps GNU Emacs maintainers keep the loaddefs.el file up to
e41b2db1
ER
29;; date. It interprets magic cookies of the form ";;;###autoload" in
30;; lisp source files in various useful ways. To learn more, read the
31;; source; if you're going to use this, you'd better be able to.
32
e5167999
ER
33;;; Code:
34
b0daab9a 35(require 'lisp-mode) ;for `doc-string-elt' properties.
890df022 36(require 'help-fns) ;for help-add-fundoc-usage.
6826a134 37(eval-when-compile (require 'cl))
b0daab9a 38
0ceb5fe0
RS
39(defvar generated-autoload-file "loaddefs.el"
40 "*File \\[update-file-autoloads] puts autoloads into.
41A `.el' file can set this in its local variables section to make its
c8aca7d1
KH
42autoloads go somewhere else. The autoload file is assumed to contain a
43trailer starting with a FormFeed character.")
0ceb5fe0
RS
44
45(defconst generate-autoload-cookie ";;;###autoload"
46 "Magic comment indicating the following form should be autoloaded.
47Used by \\[update-file-autoloads]. This string should be
48meaningless to Lisp (e.g., a comment).
49
50This string is used:
51
52;;;###autoload
53\(defun function-to-be-autoloaded () ...)
54
55If this string appears alone on a line, the following form will be
56read and an autoload made for it. If there is further text on the line,
57that text will be copied verbatim to `generated-autoload-file'.")
58
59(defconst generate-autoload-section-header "\f\n;;;### "
2336b6a9 60 "String that marks the form at the start of a new file's autoload section.")
0ceb5fe0
RS
61
62(defconst generate-autoload-section-trailer "\n;;;***\n"
63 "String which indicates the end of the section of autoloads for a file.")
64
2336b6a9
KH
65(defconst generate-autoload-section-continuation ";;;;;; "
66 "String to add on each continuation of the section header form.")
67
0231f2dc 68(defun make-autoload (form file)
ceaa3695 69 "Turn FORM into an autoload or defvar for source file FILE.
e8139c11
SM
70Returns nil if FORM is not a special autoload form (i.e. a function definition
71or macro definition or a defcustom)."
72 (let ((car (car-safe form)) expand)
73 (cond
74 ;; For complex cases, try again on the macro-expansion.
1b39b493 75 ((and (memq car '(easy-mmode-define-global-mode define-global-minor-mode
e8139c11
SM
76 easy-mmode-define-minor-mode define-minor-mode))
77 (setq expand (let ((load-file-name file)) (macroexpand form)))
78 (eq (car expand) 'progn)
79 (memq :autoload-end expand))
80 (let ((end (memq :autoload-end expand)))
81 ;; Cut-off anything after the :autoload-end marker.
82 (setcdr end nil)
83 (cons 'progn
84 (mapcar (lambda (form) (make-autoload form file))
85 (cdr expand)))))
86
87 ;; For special function-like operators, use the `autoload' function.
88 ((memq car '(defun define-skeleton defmacro define-derived-mode
bec34fb0 89 define-compilation-mode
e8139c11
SM
90 define-generic-mode easy-mmode-define-minor-mode
91 easy-mmode-define-global-mode
74312ddc
CW
92 define-minor-mode defun* defmacro*))
93 (let* ((macrop (memq car '(defmacro defmacro*)))
e8139c11 94 (name (nth 1 form))
6826a134
SM
95 (args (case car
96 ((defun defmacro defun* defmacro*) (nth 2 form))
97 ((define-skeleton) '(&optional str arg))
bec34fb0
TTN
98 ((define-generic-mode define-derived-mode
99 define-compilation-mode) nil)
6826a134 100 (t)))
e8139c11
SM
101 (body (nthcdr (get car 'doc-string-elt) form))
102 (doc (if (stringp (car body)) (pop body))))
890df022
SM
103 (when (listp args)
104 ;; Add the usage form at the end where describe-function-1
105 ;; can recover it.
106 (setq doc (help-add-fundoc-usage doc args)))
e8139c11
SM
107 ;; `define-generic-mode' quotes the name, so take care of that
108 (list 'autoload (if (listp name) name (list 'quote name)) file doc
109 (or (and (memq car '(define-skeleton define-derived-mode
110 define-generic-mode
111 easy-mmode-define-global-mode
112 easy-mmode-define-minor-mode
113 define-minor-mode)) t)
114 (eq (car-safe (car body)) 'interactive))
115 (if macrop (list 'quote 'macro) nil))))
116
d49298d9 117 ;; Convert defcustom to less space-consuming data.
e8139c11
SM
118 ((eq car 'defcustom)
119 (let ((varname (car-safe (cdr-safe form)))
120 (init (car-safe (cdr-safe (cdr-safe form))))
121 (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form)))))
d49298d9
MR
122 ;; (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form)))))
123 )
124 `(progn
125 (defvar ,varname ,init ,doc)
b7a45ee1
SM
126 (custom-autoload ',varname ,file)
127 ;; The use of :require in a defcustom can be annoying, especially
128 ;; when defcustoms are moved from one file to another between
129 ;; releases because the :require arg gets placed in the user's
130 ;; .emacs. In order for autoloaded minor modes not to need the
131 ;; use of :require, we arrange to store their :setter.
132 ,(let ((setter (condition-case nil
133 (cadr (memq :set form))
134 (error nil))))
135 (if (equal setter ''custom-set-minor-mode)
136 `(put ',varname 'custom-set 'custom-set-minor-mode))))))
e8139c11
SM
137
138 ;; nil here indicates that this is not a special autoload form.
139 (t nil))))
0231f2dc 140
890df022
SM
141;; Forms which have doc-strings which should be printed specially.
142;; A doc-string-elt property of ELT says that (nth ELT FORM) is
143;; the doc-string in FORM.
144;; Those properties are now set in lisp-mode.el.
fc89daee 145
0231f2dc 146
72c19d97 147(defun autoload-trim-file-name (file)
8d3e5475 148 ;; Returns a relative file path for FILE
1eb0a345
RS
149 ;; starting from the directory that loaddefs.el is in.
150 ;; That is normally a directory in load-path,
151 ;; which means Emacs will be able to find FILE when it looks.
152 ;; Any extra directory names here would prevent finding the file.
72c19d97
RM
153 (setq file (expand-file-name file))
154 (file-relative-name file
1eb0a345 155 (file-name-directory generated-autoload-file)))
72c19d97 156
2336b6a9
KH
157(defun autoload-read-section-header ()
158 "Read a section header form.
159Since continuation lines have been marked as comments,
160we must copy the text of the form and remove those comment
161markers before we call `read'."
162 (save-match-data
163 (let ((beginning (point))
164 string)
165 (forward-line 1)
166 (while (looking-at generate-autoload-section-continuation)
167 (forward-line 1))
168 (setq string (buffer-substring beginning (point)))
169 (with-current-buffer (get-buffer-create " *autoload*")
170 (erase-buffer)
171 (insert string)
172 (goto-char (point-min))
173 (while (search-forward generate-autoload-section-continuation nil t)
174 (replace-match " "))
175 (goto-char (point-min))
176 (read (current-buffer))))))
177
ac644d50
JB
178(defvar autoload-print-form-outbuf nil
179 "Buffer which gets the output of `autoload-print-form'.")
4a3c5b3a 180
a8add29d 181(defun autoload-print-form (form)
4a3c5b3a
RS
182 "Print FORM such that `make-docfile' will find the docstrings.
183The variable `autoload-print-form-outbuf' specifies the buffer to
184put the output in."
a8add29d
SM
185 (cond
186 ;; If the form is a sequence, recurse.
187 ((eq (car form) 'progn) (mapcar 'autoload-print-form (cdr form)))
188 ;; Symbols at the toplevel are meaningless.
189 ((symbolp form) nil)
190 (t
4a3c5b3a
RS
191 (let ((doc-string-elt (get (car-safe form) 'doc-string-elt))
192 (outbuf autoload-print-form-outbuf))
a8add29d
SM
193 (if (and doc-string-elt (stringp (nth doc-string-elt form)))
194 ;; We need to hack the printing because the
195 ;; doc-string must be printed specially for
196 ;; make-docfile (sigh).
197 (let* ((p (nthcdr (1- doc-string-elt) form))
198 (elt (cdr p)))
199 (setcdr p nil)
200 (princ "\n(" outbuf)
201 (let ((print-escape-newlines t)
202 (print-escape-nonascii t))
7dab57b6
RS
203 (dolist (elt form)
204 (prin1 elt outbuf)
205 (princ " " outbuf)))
a8add29d
SM
206 (princ "\"\\\n" outbuf)
207 (let ((begin (with-current-buffer outbuf (point))))
208 (princ (substring (prin1-to-string (car elt)) 1)
209 outbuf)
210 ;; Insert a backslash before each ( that
211 ;; appears at the beginning of a line in
212 ;; the doc string.
213 (with-current-buffer outbuf
214 (save-excursion
890df022 215 (while (re-search-backward "\n[[(]" begin t)
a8add29d
SM
216 (forward-char 1)
217 (insert "\\"))))
218 (if (null (cdr elt))
219 (princ ")" outbuf)
220 (princ " " outbuf)
221 (princ (substring (prin1-to-string (cdr elt)) 1)
222 outbuf))
223 (terpri outbuf)))
224 (let ((print-escape-newlines t)
225 (print-escape-nonascii t))
226 (print form outbuf)))))))
227
a273d3e0
GM
228(defun autoload-ensure-default-file (file)
229 "Make sure that the autoload file FILE exists and if not create it."
230 (unless (file-exists-p file)
231 (write-region
232 (concat ";;; " (file-name-nondirectory file)
233 " --- automatically extracted autoloads\n"
234 ";;\n"
235 ";;; Code:\n\n"
236 "\f\n;; Local Variables:\n"
237 ";; version-control: never\n"
238 ";; no-byte-compile: t\n"
239 ";; no-update-autoloads: t\n"
240 ";; End:\n"
241 ";;; " (file-name-nondirectory file)
4994a50d 242 " ends here\n")
a273d3e0
GM
243 nil file))
244 file)
245
246(defun autoload-insert-section-header (outbuf autoloads load-name file time)
247 "Insert the section-header line,
248which lists the file name and which functions are in it, etc."
249 (insert generate-autoload-section-header)
250 (prin1 (list 'autoloads autoloads load-name
251 (if (stringp file) (autoload-trim-file-name file) file)
252 time)
253 outbuf)
254 (terpri outbuf)
255 ;; Break that line at spaces, to avoid very long lines.
256 ;; Make each sub-line into a comment.
257 (with-current-buffer outbuf
258 (save-excursion
259 (forward-line -1)
260 (while (not (eolp))
261 (move-to-column 64)
262 (skip-chars-forward "^ \n")
263 (or (eolp)
264 (insert "\n" generate-autoload-section-continuation))))))
265
0231f2dc
JB
266(defun generate-file-autoloads (file)
267 "Insert at point a loaddefs autoload section for FILE.
268autoloads are generated for defuns and defmacros in FILE
da8826b4 269marked by `generate-autoload-cookie' (which see).
0231f2dc
JB
270If FILE is being visited in a buffer, the contents of the buffer
271are used."
272 (interactive "fGenerate autoloads for file: ")
273 (let ((outbuf (current-buffer))
0231f2dc
JB
274 (autoloads-done '())
275 (load-name (let ((name (file-name-nondirectory file)))
a85e4d58 276 (if (string-match "\\.elc?\\(\\.\\|$\\)" name)
0231f2dc
JB
277 (substring name 0 (match-beginning 0))
278 name)))
279 (print-length nil)
72c19d97 280 (print-readably t) ; This does something in Lucid Emacs.
aa7ea8bd 281 (float-output-format nil)
0231f2dc 282 (done-any nil)
7e4263eb 283 (visited (get-file-buffer file))
0231f2dc 284 output-end)
daa37602
JB
285
286 ;; If the autoload section we create here uses an absolute
8d3e5475 287 ;; file name for FILE in its header, and then Emacs is installed
daa37602
JB
288 ;; under a different path on another system,
289 ;; `update-autoloads-here' won't be able to find the files to be
290 ;; autoloaded. So, if FILE is in the same directory or a
e5d77022 291 ;; subdirectory of the current buffer's directory, we'll make it
daa37602
JB
292 ;; relative to the current buffer's directory.
293 (setq file (expand-file-name file))
1265394f
RM
294 (let* ((source-truename (file-truename file))
295 (dir-truename (file-name-as-directory
296 (file-truename default-directory)))
297 (len (length dir-truename)))
298 (if (and (< len (length source-truename))
299 (string= dir-truename (substring source-truename 0 len)))
300 (setq file (substring source-truename len))))
daa37602 301
0231f2dc 302 (message "Generating autoloads for %s..." file)
6798a385
JB
303 (save-excursion
304 (unwind-protect
305 (progn
66fc2bf5
RM
306 (if visited
307 (set-buffer visited)
308 ;; It is faster to avoid visiting the file.
309 (set-buffer (get-buffer-create " *generate-autoload-file*"))
310 (kill-all-local-variables)
311 (erase-buffer)
b59c7256
RM
312 (setq buffer-undo-list t
313 buffer-read-only nil)
314 (emacs-lisp-mode)
66fc2bf5 315 (insert-file-contents file nil))
6798a385
JB
316 (save-excursion
317 (save-restriction
318 (widen)
319 (goto-char (point-min))
320 (while (not (eobp))
321 (skip-chars-forward " \t\n\f")
322 (cond
323 ((looking-at (regexp-quote generate-autoload-cookie))
324 (search-forward generate-autoload-cookie)
325 (skip-chars-forward " \t")
326 (setq done-any t)
9ed4d64f
RM
327 (if (eolp)
328 ;; Read the next form and make an autoload.
329 (let* ((form (prog1 (read (current-buffer))
a8add29d
SM
330 (or (bolp) (forward-line 1))))
331 (autoload (make-autoload form load-name)))
9ed4d64f
RM
332 (if autoload
333 (setq autoloads-done (cons (nth 1 form)
334 autoloads-done))
335 (setq autoload form))
4a3c5b3a
RS
336 (let ((autoload-print-form-outbuf outbuf))
337 (autoload-print-form autoload)))
a1506d29 338
a8add29d 339 ;; Copy the rest of the line to the output.
6e21af56
RM
340 (princ (buffer-substring
341 (progn
342 ;; Back up over whitespace, to preserve it.
343 (skip-chars-backward " \f\t")
344 (if (= (char-after (1+ (point))) ? )
345 ;; Eat one space.
346 (forward-char 1))
347 (point))
348 (progn (forward-line 1) (point)))
349 outbuf)))
72c19d97
RM
350 ((looking-at ";")
351 ;; Don't read the comment.
352 (forward-line 1))
353 (t
354 (forward-sexp 1)
355 (forward-line 1)))))))
6798a385
JB
356 (or visited
357 ;; We created this buffer, so we should kill it.
358 (kill-buffer (current-buffer)))
359 (set-buffer outbuf)
360 (setq output-end (point-marker))))
0231f2dc
JB
361 (if done-any
362 (progn
2336b6a9
KH
363 ;; Insert the section-header line
364 ;; which lists the file name and which functions are in it, etc.
a273d3e0
GM
365 (autoload-insert-section-header outbuf autoloads-done load-name file
366 (nth 5 (file-attributes file)))
72c19d97
RM
367 (insert ";;; Generated autoloads from "
368 (autoload-trim-file-name file) "\n")
0231f2dc
JB
369 (goto-char output-end)
370 (insert generate-autoload-section-trailer)))
371 (message "Generating autoloads for %s...done" file)))
e2b6138f 372\f
0231f2dc 373;;;###autoload
f7ed02ac 374(defun update-file-autoloads (file &optional save-after)
0231f2dc 375 "Update the autoloads for FILE in `generated-autoload-file'
a273d3e0 376\(which FILE might bind in its local variables).
f7ed02ac
RS
377If SAVE-AFTER is non-nil (which is always, when called interactively),
378save the buffer too.
379
380Return FILE if there was no autoload cookie in it, else nil."
381 (interactive "fUpdate autoloads for file: \np")
0231f2dc 382 (let ((load-name (let ((name (file-name-nondirectory file)))
a85e4d58 383 (if (string-match "\\.elc?\\(\\.\\|$\\)" name)
0231f2dc
JB
384 (substring name 0 (match-beginning 0))
385 name)))
d55e3ff0 386 (found nil)
a273d3e0
GM
387 (existing-buffer (get-file-buffer file))
388 (no-autoloads nil))
0231f2dc
JB
389 (save-excursion
390 ;; We want to get a value for generated-autoload-file from
391 ;; the local variables section if it's there.
b59c7256
RM
392 (if existing-buffer
393 (set-buffer existing-buffer))
9e3366e4
EZ
394 ;; We must read/write the file without any code conversion,
395 ;; but still decode EOLs.
396 (let ((coding-system-for-read 'raw-text))
68521d61 397 (set-buffer (find-file-noselect
a273d3e0
GM
398 (autoload-ensure-default-file
399 (expand-file-name generated-autoload-file
400 (expand-file-name "lisp"
401 source-directory)))))
9e3366e4
EZ
402 ;; This is to make generated-autoload-file have Unix EOLs, so
403 ;; that it is portable to all platforms.
404 (setq buffer-file-coding-system 'raw-text-unix))
0b33ec46
RS
405 (or (> (buffer-size) 0)
406 (error "Autoloads file %s does not exist" buffer-file-name))
407 (or (file-writable-p buffer-file-name)
408 (error "Autoloads file %s is not writable" buffer-file-name))
0231f2dc
JB
409 (save-excursion
410 (save-restriction
411 (widen)
412 (goto-char (point-min))
d55e3ff0
RM
413 ;; Look for the section for LOAD-NAME.
414 (while (and (not found)
415 (search-forward generate-autoload-section-header nil t))
2336b6a9 416 (let ((form (autoload-read-section-header)))
d55e3ff0
RM
417 (cond ((string= (nth 2 form) load-name)
418 ;; We found the section for this file.
419 ;; Check if it is up to date.
420 (let ((begin (match-beginning 0))
421 (last-time (nth 4 form))
422 (file-time (nth 5 (file-attributes file))))
423 (if (and (or (null existing-buffer)
424 (not (buffer-modified-p existing-buffer)))
425 (listp last-time) (= (length last-time) 2)
66dc9a0f 426 (not (time-less-p last-time file-time)))
d55e3ff0 427 (progn
d5aa62ec
RM
428 (if (interactive-p)
429 (message "\
430Autoload section for %s is up to date."
431 file))
d55e3ff0
RM
432 (setq found 'up-to-date))
433 (search-forward generate-autoload-section-trailer)
434 (delete-region begin (point))
435 (setq found t))))
436 ((string< load-name (nth 2 form))
437 ;; We've come to a section alphabetically later than
438 ;; LOAD-NAME. We assume the file is in order and so
439 ;; there must be no section for LOAD-NAME. We will
440 ;; insert one before the section here.
441 (goto-char (match-beginning 0))
72c19d97 442 (setq found 'new)))))
0f09bac6
RM
443 (or found
444 (progn
445 (setq found 'new)
446 ;; No later sections in the file. Put before the last page.
447 (goto-char (point-max))
5a161ab5 448 (search-backward "\f" nil t)))
72c19d97 449 (or (eq found 'up-to-date)
0f09bac6 450 (and (eq found 'new)
72c19d97
RM
451 ;; Check that FILE has any cookies before generating a
452 ;; new section for it.
453 (save-excursion
b59c7256
RM
454 (if existing-buffer
455 (set-buffer existing-buffer)
456 ;; It is faster to avoid visiting the file.
457 (set-buffer (get-buffer-create " *autoload-file*"))
458 (kill-all-local-variables)
459 (erase-buffer)
460 (setq buffer-undo-list t
461 buffer-read-only nil)
462 (emacs-lisp-mode)
463 (insert-file-contents file nil))
72c19d97 464 (save-excursion
b59c7256
RM
465 (save-restriction
466 (widen)
467 (goto-char (point-min))
468 (prog1
f0646ca0
RM
469 (if (re-search-forward
470 (concat "^" (regexp-quote
471 generate-autoload-cookie))
b59c7256
RM
472 nil t)
473 nil
474 (if (interactive-p)
75632953 475 (message "%s has no autoloads" file))
a273d3e0 476 (setq no-autoloads t)
b59c7256
RM
477 t)
478 (or existing-buffer
479 (kill-buffer (current-buffer))))))))
57cf354d 480 (generate-file-autoloads file))))
f7ed02ac 481 (and save-after
2336b6a9 482 (buffer-modified-p)
a273d3e0
GM
483 (save-buffer))
484
485 (if no-autoloads file))))
486
a273d3e0
GM
487(defun autoload-remove-section (begin)
488 (goto-char begin)
489 (search-forward generate-autoload-section-trailer)
490 (delete-region begin (point)))
0231f2dc
JB
491
492;;;###autoload
56eebc29 493(defun update-directory-autoloads (&rest dirs)
d08589bf 494 "\
3fbca58a 495Update loaddefs.el with all the current autoloads from DIRS, and no old ones.
ac644d50 496This uses `update-file-autoloads' (which see) to do its work.
56eebc29
RS
497In an interactive call, you must give one argument, the name
498of a single directory. In a call from Lisp, you can supply multiple
499directories as separate arguments, but this usage is discouraged.
500
501The function does NOT recursively descend into subdirectories of the
502directory or directories specified."
b59c7256 503 (interactive "DUpdate autoloads from directory: ")
a85e4d58
SM
504 (let* ((files-re (let ((tmp nil))
505 (dolist (suf load-suffixes
506 (concat "^[^=.].*" (regexp-opt tmp t) "\\'"))
507 (unless (string-match "\\.elc" suf) (push suf tmp)))))
508 (files (apply 'nconc
a273d3e0
GM
509 (mapcar (lambda (dir)
510 (directory-files (expand-file-name dir)
a85e4d58 511 t files-re))
a273d3e0
GM
512 dirs)))
513 (this-time (current-time))
514 (no-autoloads nil) ;files with no autoload cookies.
515 (autoloads-file
0e193890 516 (expand-file-name generated-autoload-file
a273d3e0
GM
517 (expand-file-name "lisp" source-directory)))
518 (top-dir (file-name-directory autoloads-file)))
519
520 (with-current-buffer
521 (find-file-noselect (autoload-ensure-default-file autoloads-file))
e2b6138f 522 (save-excursion
a273d3e0
GM
523
524 ;; Canonicalize file names and remove the autoload file itself.
525 (setq files (delete (autoload-trim-file-name buffer-file-name)
526 (mapcar 'autoload-trim-file-name files)))
527
b59c7256
RM
528 (goto-char (point-min))
529 (while (search-forward generate-autoload-section-header nil t)
2336b6a9 530 (let* ((form (autoload-read-section-header))
b59c7256 531 (file (nth 3 form)))
a273d3e0
GM
532 (cond ((and (consp file) (stringp (car file)))
533 ;; This is a list of files that have no autoload cookies.
534 ;; There shouldn't be more than one such entry.
535 ;; Remove the obsolete section.
536 (autoload-remove-section (match-beginning 0))
537 (let ((last-time (nth 4 form)))
538 (dolist (file file)
539 (let ((file-time (nth 5 (file-attributes file))))
540 (when (and file-time
66dc9a0f 541 (not (time-less-p last-time file-time)))
a273d3e0
GM
542 ;; file unchanged
543 (push file no-autoloads)
544 (setq files (delete file files)))))))
545 ((not (stringp file)))
3fbca58a 546 ((not (file-exists-p (expand-file-name file top-dir)))
b59c7256 547 ;; Remove the obsolete section.
a273d3e0
GM
548 (autoload-remove-section (match-beginning 0)))
549 ((equal (nth 4 form) (nth 5 (file-attributes file)))
550 ;; File hasn't changed.
551 nil)
b59c7256
RM
552 (t
553 (update-file-autoloads file)))
554 (setq files (delete file files)))))
a273d3e0
GM
555 ;; Elements remaining in FILES have no existing autoload sections yet.
556 (setq no-autoloads
557 (append no-autoloads
558 (delq nil (mapcar 'update-file-autoloads files))))
559 (when no-autoloads
000d9923
MR
560 ;; Sort them for better readability.
561 (setq no-autoloads (sort no-autoloads 'string<))
a273d3e0
GM
562 ;; Add the `no-autoloads' section.
563 (goto-char (point-max))
564 (search-backward "\f" nil t)
565 (autoload-insert-section-header
566 (current-buffer) nil nil no-autoloads this-time)
567 (insert generate-autoload-section-trailer))
568
b59c7256 569 (save-buffer))))
0231f2dc 570
1e0888f5
LH
571(define-obsolete-function-alias 'update-autoloads-from-directories
572 'update-directory-autoloads "22.1")
573
0231f2dc
JB
574;;;###autoload
575(defun batch-update-autoloads ()
b59c7256 576 "Update loaddefs.el autoloads in batch mode.
375d5635
JPW
577Calls `update-directory-autoloads' on the command line arguments."
578 (apply 'update-directory-autoloads command-line-args-left)
b59c7256 579 (setq command-line-args-left nil))
0231f2dc
JB
580
581(provide 'autoload)
ffd56f97 582
b7a45ee1 583;; arch-tag: 00244766-98f4-4767-bf42-8a22103441c6
c0274f38 584;;; autoload.el ends here