]> code.delx.au - gnu-emacs/blob - lisp/emacs-lisp/autoload.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / emacs-lisp / autoload.el
1 ;; autoload.el --- maintain autoloads in loaddefs.el
2
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Author: Roland McGrath <roland@gnu.org>
7 ;; Keywords: maint
8
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 3, 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
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This code helps GNU Emacs maintainers keep the loaddefs.el file up to
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
33 ;;; Code:
34
35 (require 'lisp-mode) ;for `doc-string-elt' properties.
36 (require 'help-fns) ;for help-add-fundoc-usage.
37 (eval-when-compile (require 'cl))
38
39 (defvar generated-autoload-file "loaddefs.el"
40 "*File \\[update-file-autoloads] puts autoloads into.
41 A `.el' file can set this in its local variables section to make its
42 autoloads go somewhere else. The autoload file is assumed to contain a
43 trailer starting with a FormFeed character.")
44 ;;;###autoload
45 (put 'generated-autoload-file 'safe-local-variable 'stringp)
46
47 ;; This feels like it should be a defconst, but MH-E sets it to
48 ;; ";;;###mh-autoload" for the autoloads that are to go into mh-loaddefs.el.
49 (defvar generate-autoload-cookie ";;;###autoload"
50 "Magic comment indicating the following form should be autoloaded.
51 Used by \\[update-file-autoloads]. This string should be
52 meaningless to Lisp (e.g., a comment).
53
54 This string is used:
55
56 \;;;###autoload
57 \(defun function-to-be-autoloaded () ...)
58
59 If this string appears alone on a line, the following form will be
60 read and an autoload made for it. If there is further text on the line,
61 that text will be copied verbatim to `generated-autoload-file'.")
62
63 (defconst generate-autoload-section-header "\f\n;;;### "
64 "String that marks the form at the start of a new file's autoload section.")
65
66 (defconst generate-autoload-section-trailer "\n;;;***\n"
67 "String which indicates the end of the section of autoloads for a file.")
68
69 (defconst generate-autoload-section-continuation ";;;;;; "
70 "String to add on each continuation of the section header form.")
71
72 (defvar autoload-modified-buffers) ;Dynamically scoped var.
73
74 (defun make-autoload (form file)
75 "Turn FORM into an autoload or defvar for source file FILE.
76 Returns nil if FORM is not a special autoload form (i.e. a function definition
77 or macro definition or a defcustom)."
78 (let ((car (car-safe form)) expand)
79 (cond
80 ;; For complex cases, try again on the macro-expansion.
81 ((and (memq car '(easy-mmode-define-global-mode define-global-minor-mode
82 define-globalized-minor-mode
83 easy-mmode-define-minor-mode define-minor-mode))
84 (setq expand (let ((load-file-name file)) (macroexpand form)))
85 (eq (car expand) 'progn)
86 (memq :autoload-end expand))
87 (let ((end (memq :autoload-end expand)))
88 ;; Cut-off anything after the :autoload-end marker.
89 (setcdr end nil)
90 (cons 'progn
91 (mapcar (lambda (form) (make-autoload form file))
92 (cdr expand)))))
93
94 ;; For special function-like operators, use the `autoload' function.
95 ((memq car '(defun define-skeleton defmacro define-derived-mode
96 define-compilation-mode define-generic-mode
97 easy-mmode-define-global-mode define-global-minor-mode
98 define-globalized-minor-mode
99 easy-mmode-define-minor-mode define-minor-mode
100 defun* defmacro*))
101 (let* ((macrop (memq car '(defmacro defmacro*)))
102 (name (nth 1 form))
103 (args (case car
104 ((defun defmacro defun* defmacro*) (nth 2 form))
105 ((define-skeleton) '(&optional str arg))
106 ((define-generic-mode define-derived-mode
107 define-compilation-mode) nil)
108 (t)))
109 (body (nthcdr (get car 'doc-string-elt) form))
110 (doc (if (stringp (car body)) (pop body))))
111 (when (listp args)
112 ;; Add the usage form at the end where describe-function-1
113 ;; can recover it.
114 (setq doc (help-add-fundoc-usage doc args)))
115 ;; `define-generic-mode' quotes the name, so take care of that
116 (list 'autoload (if (listp name) name (list 'quote name)) file doc
117 (or (and (memq car '(define-skeleton define-derived-mode
118 define-generic-mode
119 easy-mmode-define-global-mode
120 define-global-minor-mode
121 define-globalized-minor-mode
122 easy-mmode-define-minor-mode
123 define-minor-mode)) t)
124 (eq (car-safe (car body)) 'interactive))
125 (if macrop (list 'quote 'macro) nil))))
126
127 ;; Convert defcustom to less space-consuming data.
128 ((eq car 'defcustom)
129 (let ((varname (car-safe (cdr-safe form)))
130 (init (car-safe (cdr-safe (cdr-safe form))))
131 (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form)))))
132 ;; (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form)))))
133 )
134 `(progn
135 (defvar ,varname ,init ,doc)
136 (custom-autoload ',varname ,file
137 ,(condition-case nil
138 (null (cadr (memq :set form)))
139 (error nil))))))
140
141 ((eq car 'defgroup)
142 ;; In Emacs this is normally handled separately by cus-dep.el, but for
143 ;; third party packages, it can be convenient to explicitly autoload
144 ;; a group.
145 (let ((groupname (nth 1 form)))
146 `(let ((loads (get ',groupname 'custom-loads)))
147 (if (member ',file loads) nil
148 (put ',groupname 'custom-loads (cons ',file loads))))))
149
150 ;; nil here indicates that this is not a special autoload form.
151 (t nil))))
152
153 ;; Forms which have doc-strings which should be printed specially.
154 ;; A doc-string-elt property of ELT says that (nth ELT FORM) is
155 ;; the doc-string in FORM.
156 ;; Those properties are now set in lisp-mode.el.
157
158 (defun autoload-generated-file ()
159 (expand-file-name generated-autoload-file
160 ;; File-local settings of generated-autoload-file should
161 ;; be interpreted relative to the file's location,
162 ;; of course.
163 (if (not (local-variable-p 'generated-autoload-file))
164 (expand-file-name "lisp" source-directory))))
165
166
167 (defun autoload-read-section-header ()
168 "Read a section header form.
169 Since continuation lines have been marked as comments,
170 we must copy the text of the form and remove those comment
171 markers before we call `read'."
172 (save-match-data
173 (let ((beginning (point))
174 string)
175 (forward-line 1)
176 (while (looking-at generate-autoload-section-continuation)
177 (forward-line 1))
178 (setq string (buffer-substring beginning (point)))
179 (with-current-buffer (get-buffer-create " *autoload*")
180 (erase-buffer)
181 (insert string)
182 (goto-char (point-min))
183 (while (search-forward generate-autoload-section-continuation nil t)
184 (replace-match " "))
185 (goto-char (point-min))
186 (read (current-buffer))))))
187
188 (defvar autoload-print-form-outbuf nil
189 "Buffer which gets the output of `autoload-print-form'.")
190
191 (defun autoload-print-form (form)
192 "Print FORM such that `make-docfile' will find the docstrings.
193 The variable `autoload-print-form-outbuf' specifies the buffer to
194 put the output in."
195 (cond
196 ;; If the form is a sequence, recurse.
197 ((eq (car form) 'progn) (mapcar 'autoload-print-form (cdr form)))
198 ;; Symbols at the toplevel are meaningless.
199 ((symbolp form) nil)
200 (t
201 (let ((doc-string-elt (get (car-safe form) 'doc-string-elt))
202 (outbuf autoload-print-form-outbuf))
203 (if (and doc-string-elt (stringp (nth doc-string-elt form)))
204 ;; We need to hack the printing because the
205 ;; doc-string must be printed specially for
206 ;; make-docfile (sigh).
207 (let* ((p (nthcdr (1- doc-string-elt) form))
208 (elt (cdr p)))
209 (setcdr p nil)
210 (princ "\n(" outbuf)
211 (let ((print-escape-newlines t)
212 (print-quoted t)
213 (print-escape-nonascii t))
214 (dolist (elt form)
215 (prin1 elt outbuf)
216 (princ " " outbuf)))
217 (princ "\"\\\n" outbuf)
218 (let ((begin (with-current-buffer outbuf (point))))
219 (princ (substring (prin1-to-string (car elt)) 1)
220 outbuf)
221 ;; Insert a backslash before each ( that
222 ;; appears at the beginning of a line in
223 ;; the doc string.
224 (with-current-buffer outbuf
225 (save-excursion
226 (while (re-search-backward "\n[[(]" begin t)
227 (forward-char 1)
228 (insert "\\"))))
229 (if (null (cdr elt))
230 (princ ")" outbuf)
231 (princ " " outbuf)
232 (princ (substring (prin1-to-string (cdr elt)) 1)
233 outbuf))
234 (terpri outbuf)))
235 (let ((print-escape-newlines t)
236 (print-quoted t)
237 (print-escape-nonascii t))
238 (print form outbuf)))))))
239
240 (defun autoload-ensure-default-file (file)
241 "Make sure that the autoload file FILE exists and if not create it."
242 (unless (file-exists-p file)
243 (let ((basename (file-name-nondirectory file)))
244 (write-region
245 (concat ";;; " basename
246 " --- automatically extracted autoloads\n"
247 ";;\n"
248 ";;; Code:\n\n"
249 "\f\n"
250 "(provide '" (file-name-sans-extension basename) ")\n"
251 ";; Local Variables:\n"
252 ";; version-control: never\n"
253 ";; no-byte-compile: t\n"
254 ";; no-update-autoloads: t\n"
255 ";; End:\n"
256 ";;; " basename
257 " ends here\n")
258 nil file)))
259 file)
260
261 (defun autoload-insert-section-header (outbuf autoloads load-name file time)
262 "Insert the section-header line,
263 which lists the file name and which functions are in it, etc."
264 (insert generate-autoload-section-header)
265 (prin1 (list 'autoloads autoloads load-name file time)
266 outbuf)
267 (terpri outbuf)
268 ;; Break that line at spaces, to avoid very long lines.
269 ;; Make each sub-line into a comment.
270 (with-current-buffer outbuf
271 (save-excursion
272 (forward-line -1)
273 (while (not (eolp))
274 (move-to-column 64)
275 (skip-chars-forward "^ \n")
276 (or (eolp)
277 (insert "\n" generate-autoload-section-continuation))))))
278
279 (defun autoload-find-file (file)
280 "Fetch file and put it in a temp buffer. Return the buffer."
281 ;; It is faster to avoid visiting the file.
282 (setq file (expand-file-name file))
283 (with-current-buffer (get-buffer-create " *autoload-file*")
284 (kill-all-local-variables)
285 (erase-buffer)
286 (setq buffer-undo-list t
287 buffer-read-only nil)
288 (emacs-lisp-mode)
289 (setq default-directory (file-name-directory file))
290 (insert-file-contents file nil)
291 (let ((enable-local-variables :safe))
292 (hack-local-variables))
293 (current-buffer)))
294
295 (defvar no-update-autoloads nil
296 "File local variable to prevent scanning this file for autoload cookies.")
297
298 (defun autoload-file-load-name (file)
299 (let ((name (file-name-nondirectory file)))
300 (if (string-match "\\.elc?\\(\\.\\|\\'\\)" name)
301 (substring name 0 (match-beginning 0))
302 name)))
303
304 (defun generate-file-autoloads (file)
305 "Insert at point a loaddefs autoload section for FILE.
306 Autoloads are generated for defuns and defmacros in FILE
307 marked by `generate-autoload-cookie' (which see).
308 If FILE is being visited in a buffer, the contents of the buffer
309 are used.
310 Return non-nil in the case where no autoloads were added at point."
311 (interactive "fGenerate autoloads for file: ")
312 (autoload-generate-file-autoloads file (current-buffer)))
313
314 ;; When called from `generate-file-autoloads' we should ignore
315 ;; `generated-autoload-file' altogether. When called from
316 ;; `update-file-autoloads' we don't know `outbuf'. And when called from
317 ;; `update-directory-autoloads' it's in between: we know the default
318 ;; `outbuf' but we should obey any file-local setting of
319 ;; `generated-autoload-file'.
320 (defun autoload-generate-file-autoloads (file &optional outbuf outfile)
321 "Insert an autoload section for FILE in the appropriate buffer.
322 Autoloads are generated for defuns and defmacros in FILE
323 marked by `generate-autoload-cookie' (which see).
324 If FILE is being visited in a buffer, the contents of the buffer are used.
325 OUTBUF is the buffer in which the autoload statements should be inserted.
326 If OUTBUF is nil, it will be determined by `autoload-generated-file'.
327
328 If provided, OUTFILE is expected to be the file name of OUTBUF.
329 If OUTFILE is non-nil and FILE specifies a `generated-autoload-file'
330 different from OUTFILE, then OUTBUF is ignored.
331
332 Return non-nil iff FILE adds no autoloads to OUTFILE
333 \(or OUTBUF if OUTFILE is nil)."
334 (catch 'done
335 (let ((autoloads-done '())
336 (load-name (autoload-file-load-name file))
337 (print-length nil)
338 (print-level nil)
339 (print-readably t) ; This does something in Lucid Emacs.
340 (float-output-format nil)
341 (visited (get-file-buffer file))
342 (otherbuf nil)
343 (absfile (expand-file-name file))
344 relfile
345 ;; nil until we found a cookie.
346 output-start)
347
348 (with-current-buffer (or visited
349 ;; It is faster to avoid visiting the file.
350 (autoload-find-file file))
351 ;; Obey the no-update-autoloads file local variable.
352 (unless no-update-autoloads
353 (message "Generating autoloads for %s..." file)
354 (save-excursion
355 (save-restriction
356 (widen)
357 (goto-char (point-min))
358 (while (not (eobp))
359 (skip-chars-forward " \t\n\f")
360 (cond
361 ((looking-at (regexp-quote generate-autoload-cookie))
362 ;; If not done yet, figure out where to insert this text.
363 (unless output-start
364 (when (and outfile
365 (not (equal outfile (autoload-generated-file))))
366 ;; A file-local setting of autoload-generated-file says
367 ;; we should ignore OUTBUF.
368 (setq outbuf nil)
369 (setq otherbuf t))
370 (unless outbuf
371 (setq outbuf (autoload-find-destination absfile))
372 (unless outbuf
373 ;; The file has autoload cookies, but they're
374 ;; already up-to-date. If OUTFILE is nil, the
375 ;; entries are in the expected OUTBUF, otherwise
376 ;; they're elsewhere.
377 (throw 'done outfile)))
378 (with-current-buffer outbuf
379 (setq relfile (file-relative-name absfile))
380 (setq output-start (point)))
381 ;; (message "file=%S, relfile=%S, dest=%S"
382 ;; file relfile (autoload-generated-file))
383 )
384 (search-forward generate-autoload-cookie)
385 (skip-chars-forward " \t")
386 (if (eolp)
387 (condition-case err
388 ;; Read the next form and make an autoload.
389 (let* ((form (prog1 (read (current-buffer))
390 (or (bolp) (forward-line 1))))
391 (autoload (make-autoload form load-name)))
392 (if autoload
393 (push (nth 1 form) autoloads-done)
394 (setq autoload form))
395 (let ((autoload-print-form-outbuf outbuf))
396 (autoload-print-form autoload)))
397 (error
398 (message "Error in %s: %S" file err)))
399
400 ;; Copy the rest of the line to the output.
401 (princ (buffer-substring
402 (progn
403 ;; Back up over whitespace, to preserve it.
404 (skip-chars-backward " \f\t")
405 (if (= (char-after (1+ (point))) ? )
406 ;; Eat one space.
407 (forward-char 1))
408 (point))
409 (progn (forward-line 1) (point)))
410 outbuf)))
411 ((looking-at ";")
412 ;; Don't read the comment.
413 (forward-line 1))
414 (t
415 (forward-sexp 1)
416 (forward-line 1))))))
417
418 (when output-start
419 (let ((secondary-autoloads-file-buf
420 (if (local-variable-p 'generated-autoload-file)
421 (current-buffer))))
422 (with-current-buffer outbuf
423 (save-excursion
424 ;; Insert the section-header line which lists the file name
425 ;; and which functions are in it, etc.
426 (goto-char output-start)
427 (autoload-insert-section-header
428 outbuf autoloads-done load-name relfile
429 (if secondary-autoloads-file-buf
430 ;; MD5 checksums are much better because they do not
431 ;; change unless the file changes (so they'll be
432 ;; equal on two different systems and will change
433 ;; less often than time-stamps, thus leading to fewer
434 ;; unneeded changes causing spurious conflicts), but
435 ;; using time-stamps is a very useful optimization,
436 ;; so we use time-stamps for the main autoloads file
437 ;; (loaddefs.el) where we have special ways to
438 ;; circumvent the "random change problem", and MD5
439 ;; checksum in secondary autoload files where we do
440 ;; not need the time-stamp optimization because it is
441 ;; already provided by the primary autoloads file.
442 (md5 secondary-autoloads-file-buf
443 ;; We'd really want to just use
444 ;; `emacs-internal' instead.
445 nil nil 'emacs-mule-unix)
446 (nth 5 (file-attributes relfile))))
447 (insert ";;; Generated autoloads from " relfile "\n"))
448 (insert generate-autoload-section-trailer))))
449 (message "Generating autoloads for %s...done" file))
450 (or visited
451 ;; We created this buffer, so we should kill it.
452 (kill-buffer (current-buffer))))
453 ;; If the entries were added to some other buffer, then the file
454 ;; doesn't add entries to OUTFILE.
455 (or (not output-start) otherbuf))))
456 \f
457 (defun autoload-save-buffers ()
458 (while autoload-modified-buffers
459 (with-current-buffer (pop autoload-modified-buffers)
460 (save-buffer))))
461
462 ;;;###autoload
463 (defun update-file-autoloads (file &optional save-after)
464 "Update the autoloads for FILE in `generated-autoload-file'
465 \(which FILE might bind in its local variables).
466 If SAVE-AFTER is non-nil (which is always, when called interactively),
467 save the buffer too.
468
469 Return FILE if there was no autoload cookie in it, else nil."
470 (interactive "fUpdate autoloads for file: \np")
471 (let* ((autoload-modified-buffers nil)
472 (no-autoloads (autoload-generate-file-autoloads file)))
473 (if autoload-modified-buffers
474 (if save-after (autoload-save-buffers))
475 (if (interactive-p)
476 (message "Autoload section for %s is up to date." file)))
477 (if no-autoloads file)))
478
479 (defun autoload-find-destination (file)
480 "Find the destination point of the current buffer's autoloads.
481 FILE is the file name of the current buffer.
482 Returns a buffer whose point is placed at the requested location.
483 Returns nil if the file's autoloads are uptodate, otherwise
484 removes any prior now out-of-date autoload entries."
485 (catch 'up-to-date
486 (let* ((load-name (autoload-file-load-name file))
487 (buf (current-buffer))
488 (existing-buffer (if buffer-file-name buf))
489 (found nil))
490 (with-current-buffer
491 ;; We used to use `raw-text' to read this file, but this causes
492 ;; problems when the file contains non-ASCII characters.
493 (find-file-noselect
494 (autoload-ensure-default-file (autoload-generated-file)))
495 ;; This is to make generated-autoload-file have Unix EOLs, so
496 ;; that it is portable to all platforms.
497 (unless (zerop (coding-system-eol-type buffer-file-coding-system))
498 (set-buffer-file-coding-system 'unix))
499 (or (> (buffer-size) 0)
500 (error "Autoloads file %s does not exist" buffer-file-name))
501 (or (file-writable-p buffer-file-name)
502 (error "Autoloads file %s is not writable" buffer-file-name))
503 (widen)
504 (goto-char (point-min))
505 ;; Look for the section for LOAD-NAME.
506 (while (and (not found)
507 (search-forward generate-autoload-section-header nil t))
508 (let ((form (autoload-read-section-header)))
509 (cond ((string= (nth 2 form) load-name)
510 ;; We found the section for this file.
511 ;; Check if it is up to date.
512 (let ((begin (match-beginning 0))
513 (last-time (nth 4 form))
514 (file-time (nth 5 (file-attributes file))))
515 (if (and (or (null existing-buffer)
516 (not (buffer-modified-p existing-buffer)))
517 (or
518 ;; last-time is the time-stamp (specifying
519 ;; the last time we looked at the file) and
520 ;; the file hasn't been changed since.
521 (and (listp last-time) (= (length last-time) 2)
522 (not (time-less-p last-time file-time)))
523 ;; last-time is an MD5 checksum instead.
524 (and (stringp last-time)
525 (equal last-time
526 (md5 buf nil nil 'emacs-mule)))))
527 (throw 'up-to-date nil)
528 (autoload-remove-section begin)
529 (setq found t))))
530 ((string< load-name (nth 2 form))
531 ;; We've come to a section alphabetically later than
532 ;; LOAD-NAME. We assume the file is in order and so
533 ;; there must be no section for LOAD-NAME. We will
534 ;; insert one before the section here.
535 (goto-char (match-beginning 0))
536 (setq found t)))))
537 (or found
538 (progn
539 ;; No later sections in the file. Put before the last page.
540 (goto-char (point-max))
541 (search-backward "\f" nil t)))
542 (unless (memq (current-buffer) autoload-modified-buffers)
543 (push (current-buffer) autoload-modified-buffers))
544 (current-buffer)))))
545
546 (defun autoload-remove-section (begin)
547 (goto-char begin)
548 (search-forward generate-autoload-section-trailer)
549 (delete-region begin (point)))
550
551 ;;;###autoload
552 (defun update-directory-autoloads (&rest dirs)
553 "\
554 Update loaddefs.el with all the current autoloads from DIRS, and no old ones.
555 This uses `update-file-autoloads' (which see) to do its work.
556 In an interactive call, you must give one argument, the name
557 of a single directory. In a call from Lisp, you can supply multiple
558 directories as separate arguments, but this usage is discouraged.
559
560 The function does NOT recursively descend into subdirectories of the
561 directory or directories specified."
562 (interactive "DUpdate autoloads from directory: ")
563 (let* ((files-re (let ((tmp nil))
564 (dolist (suf (get-load-suffixes)
565 (concat "^[^=.].*" (regexp-opt tmp t) "\\'"))
566 (unless (string-match "\\.elc" suf) (push suf tmp)))))
567 (files (apply 'nconc
568 (mapcar (lambda (dir)
569 (directory-files (expand-file-name dir)
570 t files-re))
571 dirs)))
572 (done ())
573 (this-time (current-time))
574 ;; Files with no autoload cookies or whose autoloads go to other
575 ;; files because of file-local autoload-generated-file settings.
576 (no-autoloads nil)
577 (autoload-modified-buffers nil))
578
579 (with-current-buffer
580 (find-file-noselect
581 (autoload-ensure-default-file (autoload-generated-file)))
582 (save-excursion
583
584 ;; Canonicalize file names and remove the autoload file itself.
585 (setq files (delete (file-relative-name buffer-file-name)
586 (mapcar 'file-relative-name files)))
587
588 (goto-char (point-min))
589 (while (search-forward generate-autoload-section-header nil t)
590 (let* ((form (autoload-read-section-header))
591 (file (nth 3 form)))
592 (cond ((and (consp file) (stringp (car file)))
593 ;; This is a list of files that have no autoload cookies.
594 ;; There shouldn't be more than one such entry.
595 ;; Remove the obsolete section.
596 (autoload-remove-section (match-beginning 0))
597 (let ((last-time (nth 4 form)))
598 (dolist (file file)
599 (let ((file-time (nth 5 (file-attributes file))))
600 (when (and file-time
601 (not (time-less-p last-time file-time)))
602 ;; file unchanged
603 (push file no-autoloads)
604 (setq files (delete file files)))))))
605 ((not (stringp file)))
606 ((or (not (file-exists-p file))
607 ;; Remove duplicates as well, just in case.
608 (member file done))
609 ;; Remove the obsolete section.
610 (autoload-remove-section (match-beginning 0)))
611 ((not (time-less-p (nth 4 form)
612 (nth 5 (file-attributes file))))
613 ;; File hasn't changed.
614 nil)
615 (t
616 (autoload-remove-section (match-beginning 0))
617 (if (autoload-generate-file-autoloads
618 file (current-buffer) buffer-file-name)
619 (push file no-autoloads))))
620 (push file done)
621 (setq files (delete file files)))))
622 ;; Elements remaining in FILES have no existing autoload sections yet.
623 (dolist (file files)
624 (if (autoload-generate-file-autoloads file nil buffer-file-name)
625 (push file no-autoloads)))
626
627 (when no-autoloads
628 ;; Sort them for better readability.
629 (setq no-autoloads (sort no-autoloads 'string<))
630 ;; Add the `no-autoloads' section.
631 (goto-char (point-max))
632 (search-backward "\f" nil t)
633 (autoload-insert-section-header
634 (current-buffer) nil nil no-autoloads this-time)
635 (insert generate-autoload-section-trailer))
636
637 (save-buffer)
638 ;; In case autoload entries were added to other files because of
639 ;; file-local autoload-generated-file settings.
640 (autoload-save-buffers))))
641
642 (define-obsolete-function-alias 'update-autoloads-from-directories
643 'update-directory-autoloads "22.1")
644
645 ;;;###autoload
646 (defun batch-update-autoloads ()
647 "Update loaddefs.el autoloads in batch mode.
648 Calls `update-directory-autoloads' on the command line arguments."
649 (let ((args command-line-args-left))
650 (setq command-line-args-left nil)
651 (apply 'update-directory-autoloads args)))
652
653 (provide 'autoload)
654
655 ;; arch-tag: 00244766-98f4-4767-bf42-8a22103441c6
656 ;;; autoload.el ends here