]> code.delx.au - gnu-emacs/blob - lisp/emacs-lisp/autoload.el
Merge from emacs--devo--0
[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 (write-region
244 (concat ";;; " (file-name-nondirectory file)
245 " --- automatically extracted autoloads\n"
246 ";;\n"
247 ";;; Code:\n\n"
248 "\f\n;; Local Variables:\n"
249 ";; version-control: never\n"
250 ";; no-byte-compile: t\n"
251 ";; no-update-autoloads: t\n"
252 ";; End:\n"
253 ";;; " (file-name-nondirectory file)
254 " ends here\n")
255 nil file))
256 file)
257
258 (defun autoload-insert-section-header (outbuf autoloads load-name file time)
259 "Insert the section-header line,
260 which lists the file name and which functions are in it, etc."
261 (insert generate-autoload-section-header)
262 (prin1 (list 'autoloads autoloads load-name file time)
263 outbuf)
264 (terpri outbuf)
265 ;; Break that line at spaces, to avoid very long lines.
266 ;; Make each sub-line into a comment.
267 (with-current-buffer outbuf
268 (save-excursion
269 (forward-line -1)
270 (while (not (eolp))
271 (move-to-column 64)
272 (skip-chars-forward "^ \n")
273 (or (eolp)
274 (insert "\n" generate-autoload-section-continuation))))))
275
276 (defun autoload-find-file (file)
277 "Fetch file and put it in a temp buffer. Return the buffer."
278 ;; It is faster to avoid visiting the file.
279 (setq file (expand-file-name file))
280 (with-current-buffer (get-buffer-create " *autoload-file*")
281 (kill-all-local-variables)
282 (erase-buffer)
283 (setq buffer-undo-list t
284 buffer-read-only nil)
285 (emacs-lisp-mode)
286 (setq default-directory (file-name-directory file))
287 (insert-file-contents file nil)
288 (let ((enable-local-variables :safe))
289 (hack-local-variables))
290 (current-buffer)))
291
292 (defvar no-update-autoloads nil
293 "File local variable to prevent scanning this file for autoload cookies.")
294
295 (defun autoload-file-load-name (file)
296 (let ((name (file-name-nondirectory file)))
297 (if (string-match "\\.elc?\\(\\.\\|\\'\\)" name)
298 (substring name 0 (match-beginning 0))
299 name)))
300
301 (defun generate-file-autoloads (file)
302 "Insert at point a loaddefs autoload section for FILE.
303 Autoloads are generated for defuns and defmacros in FILE
304 marked by `generate-autoload-cookie' (which see).
305 If FILE is being visited in a buffer, the contents of the buffer
306 are used.
307 Return non-nil in the case where no autoloads were added at point."
308 (interactive "fGenerate autoloads for file: ")
309 (autoload-generate-file-autoloads file (current-buffer)))
310
311 ;; When called from `generate-file-autoloads' we should ignore
312 ;; `generated-autoload-file' altogether. When called from
313 ;; `update-file-autoloads' we don't know `outbuf'. And when called from
314 ;; `update-directory-autoloads' it's in between: we know the default
315 ;; `outbuf' but we should obey any file-local setting of
316 ;; `generated-autoload-file'.
317 (defun autoload-generate-file-autoloads (file &optional outbuf outfile)
318 "Insert an autoload section for FILE in the appropriate buffer.
319 Autoloads are generated for defuns and defmacros in FILE
320 marked by `generate-autoload-cookie' (which see).
321 If FILE is being visited in a buffer, the contents of the buffer are used.
322 OUTBUF is the buffer in which the autoload statements should be inserted.
323 If OUTBUF is nil, it will be determined by `autoload-generated-file'.
324
325 If provided, OUTFILE is expected to be the file name of OUTBUF.
326 If OUTFILE is non-nil and FILE specifies a `generated-autoload-file'
327 different from OUTFILE, then OUTBUF is ignored.
328
329 Return non-nil iff FILE adds no autoloads to OUTFILE
330 \(or OUTBUF if OUTFILE is nil)."
331 (catch 'done
332 (let ((autoloads-done '())
333 (load-name (autoload-file-load-name file))
334 (print-length nil)
335 (print-readably t) ; This does something in Lucid Emacs.
336 (float-output-format nil)
337 (visited (get-file-buffer file))
338 (otherbuf nil)
339 (absfile (expand-file-name file))
340 relfile
341 ;; nil until we found a cookie.
342 output-start)
343
344 (with-current-buffer (or visited
345 ;; It is faster to avoid visiting the file.
346 (autoload-find-file file))
347 ;; Obey the no-update-autoloads file local variable.
348 (unless no-update-autoloads
349 (message "Generating autoloads for %s..." file)
350 (save-excursion
351 (save-restriction
352 (widen)
353 (goto-char (point-min))
354 (while (not (eobp))
355 (skip-chars-forward " \t\n\f")
356 (cond
357 ((looking-at (regexp-quote generate-autoload-cookie))
358 ;; If not done yet, figure out where to insert this text.
359 (unless output-start
360 (when (and outfile
361 (not (equal outfile (autoload-generated-file))))
362 ;; A file-local setting of autoload-generated-file says
363 ;; we should ignore OUTBUF.
364 (setq outbuf nil)
365 (setq otherbuf t))
366 (unless outbuf
367 (setq outbuf (autoload-find-destination absfile))
368 (unless outbuf
369 ;; The file has autoload cookies, but they're
370 ;; already up-to-date. If OUTFILE is nil, the
371 ;; entries are in the expected OUTBUF, otherwise
372 ;; they're elsewhere.
373 (throw 'done outfile)))
374 (with-current-buffer outbuf
375 (setq relfile (file-relative-name absfile))
376 (setq output-start (point)))
377 ;; (message "file=%S, relfile=%S, dest=%S"
378 ;; file relfile (autoload-generated-file))
379 )
380 (search-forward generate-autoload-cookie)
381 (skip-chars-forward " \t")
382 (if (eolp)
383 (condition-case err
384 ;; Read the next form and make an autoload.
385 (let* ((form (prog1 (read (current-buffer))
386 (or (bolp) (forward-line 1))))
387 (autoload (make-autoload form load-name)))
388 (if autoload
389 (push (nth 1 form) autoloads-done)
390 (setq autoload form))
391 (let ((autoload-print-form-outbuf outbuf))
392 (autoload-print-form autoload)))
393 (error
394 (message "Error in %s: %S" file err)))
395
396 ;; Copy the rest of the line to the output.
397 (princ (buffer-substring
398 (progn
399 ;; Back up over whitespace, to preserve it.
400 (skip-chars-backward " \f\t")
401 (if (= (char-after (1+ (point))) ? )
402 ;; Eat one space.
403 (forward-char 1))
404 (point))
405 (progn (forward-line 1) (point)))
406 outbuf)))
407 ((looking-at ";")
408 ;; Don't read the comment.
409 (forward-line 1))
410 (t
411 (forward-sexp 1)
412 (forward-line 1))))))
413
414 (when output-start
415 (let ((secondary-autoloads-file-buf
416 (if (local-variable-p 'generated-autoload-file)
417 (current-buffer))))
418 (with-current-buffer outbuf
419 (save-excursion
420 ;; Insert the section-header line which lists the file name
421 ;; and which functions are in it, etc.
422 (goto-char output-start)
423 (autoload-insert-section-header
424 outbuf autoloads-done load-name relfile
425 (if secondary-autoloads-file-buf
426 ;; MD5 checksums are much better because they do not
427 ;; change unless the file changes (so they'll be
428 ;; equal on two different systems and will change
429 ;; less often than time-stamps, thus leading to fewer
430 ;; unneeded changes causing spurious conflicts), but
431 ;; using time-stamps is a very useful optimization,
432 ;; so we use time-stamps for the main autoloads file
433 ;; (loaddefs.el) where we have special ways to
434 ;; circumvent the "random change problem", and MD5
435 ;; checksum in secondary autoload files where we do
436 ;; not need the time-stamp optimization because it is
437 ;; already provided by the primary autoloads file.
438 (md5 secondary-autoloads-file-buf
439 ;; We'd really want to just use
440 ;; `emacs-internal' instead.
441 nil nil 'emacs-mule-unix)
442 (nth 5 (file-attributes relfile))))
443 (insert ";;; Generated autoloads from " relfile "\n"))
444 (insert generate-autoload-section-trailer))))
445 (message "Generating autoloads for %s...done" file))
446 (or visited
447 ;; We created this buffer, so we should kill it.
448 (kill-buffer (current-buffer))))
449 ;; If the entries were added to some other buffer, then the file
450 ;; doesn't add entries to OUTFILE.
451 (or (not output-start) otherbuf))))
452 \f
453 (defun autoload-save-buffers ()
454 (while autoload-modified-buffers
455 (with-current-buffer (pop autoload-modified-buffers)
456 (save-buffer))))
457
458 ;;;###autoload
459 (defun update-file-autoloads (file &optional save-after)
460 "Update the autoloads for FILE in `generated-autoload-file'
461 \(which FILE might bind in its local variables).
462 If SAVE-AFTER is non-nil (which is always, when called interactively),
463 save the buffer too.
464
465 Return FILE if there was no autoload cookie in it, else nil."
466 (interactive "fUpdate autoloads for file: \np")
467 (let* ((autoload-modified-buffers nil)
468 (no-autoloads (autoload-generate-file-autoloads file)))
469 (if autoload-modified-buffers
470 (if save-after (autoload-save-buffers))
471 (if (interactive-p)
472 (message "Autoload section for %s is up to date." file)))
473 (if no-autoloads file)))
474
475 (defun autoload-find-destination (file)
476 "Find the destination point of the current buffer's autoloads.
477 FILE is the file name of the current buffer.
478 Returns a buffer whose point is placed at the requested location.
479 Returns nil if the file's autoloads are uptodate, otherwise
480 removes any prior now out-of-date autoload entries."
481 (catch 'up-to-date
482 (let* ((load-name (autoload-file-load-name file))
483 (buf (current-buffer))
484 (existing-buffer (if buffer-file-name buf))
485 (found nil))
486 (with-current-buffer
487 ;; We must read/write the file without any code conversion,
488 ;; but still decode EOLs.
489 (let ((coding-system-for-read 'raw-text))
490 (find-file-noselect
491 (autoload-ensure-default-file (autoload-generated-file))))
492 ;; This is to make generated-autoload-file have Unix EOLs, so
493 ;; that it is portable to all platforms.
494 (setq buffer-file-coding-system 'raw-text-unix)
495 (or (> (buffer-size) 0)
496 (error "Autoloads file %s does not exist" buffer-file-name))
497 (or (file-writable-p buffer-file-name)
498 (error "Autoloads file %s is not writable" buffer-file-name))
499 (widen)
500 (goto-char (point-min))
501 ;; Look for the section for LOAD-NAME.
502 (while (and (not found)
503 (search-forward generate-autoload-section-header nil t))
504 (let ((form (autoload-read-section-header)))
505 (cond ((string= (nth 2 form) load-name)
506 ;; We found the section for this file.
507 ;; Check if it is up to date.
508 (let ((begin (match-beginning 0))
509 (last-time (nth 4 form))
510 (file-time (nth 5 (file-attributes file))))
511 (if (and (or (null existing-buffer)
512 (not (buffer-modified-p existing-buffer)))
513 (or
514 ;; last-time is the time-stamp (specifying
515 ;; the last time we looked at the file) and
516 ;; the file hasn't been changed since.
517 (and (listp last-time) (= (length last-time) 2)
518 (not (time-less-p last-time file-time)))
519 ;; last-time is an MD5 checksum instead.
520 (and (stringp last-time)
521 (equal last-time
522 (md5 buf nil nil 'emacs-mule)))))
523 (throw 'up-to-date nil)
524 (autoload-remove-section begin)
525 (setq found t))))
526 ((string< load-name (nth 2 form))
527 ;; We've come to a section alphabetically later than
528 ;; LOAD-NAME. We assume the file is in order and so
529 ;; there must be no section for LOAD-NAME. We will
530 ;; insert one before the section here.
531 (goto-char (match-beginning 0))
532 (setq found t)))))
533 (or found
534 (progn
535 ;; No later sections in the file. Put before the last page.
536 (goto-char (point-max))
537 (search-backward "\f" nil t)))
538 (unless (memq (current-buffer) autoload-modified-buffers)
539 (push (current-buffer) autoload-modified-buffers))
540 (current-buffer)))))
541
542 (defun autoload-remove-section (begin)
543 (goto-char begin)
544 (search-forward generate-autoload-section-trailer)
545 (delete-region begin (point)))
546
547 ;;;###autoload
548 (defun update-directory-autoloads (&rest dirs)
549 "\
550 Update loaddefs.el with all the current autoloads from DIRS, and no old ones.
551 This uses `update-file-autoloads' (which see) to do its work.
552 In an interactive call, you must give one argument, the name
553 of a single directory. In a call from Lisp, you can supply multiple
554 directories as separate arguments, but this usage is discouraged.
555
556 The function does NOT recursively descend into subdirectories of the
557 directory or directories specified."
558 (interactive "DUpdate autoloads from directory: ")
559 (let* ((files-re (let ((tmp nil))
560 (dolist (suf (get-load-suffixes)
561 (concat "^[^=.].*" (regexp-opt tmp t) "\\'"))
562 (unless (string-match "\\.elc" suf) (push suf tmp)))))
563 (files (apply 'nconc
564 (mapcar (lambda (dir)
565 (directory-files (expand-file-name dir)
566 t files-re))
567 dirs)))
568 (done ())
569 (this-time (current-time))
570 ;; Files with no autoload cookies or whose autoloads go to other
571 ;; files because of file-local autoload-generated-file settings.
572 (no-autoloads nil)
573 (autoload-modified-buffers nil))
574
575 (with-current-buffer
576 (find-file-noselect
577 (autoload-ensure-default-file (autoload-generated-file)))
578 (save-excursion
579
580 ;; Canonicalize file names and remove the autoload file itself.
581 (setq files (delete (file-relative-name buffer-file-name)
582 (mapcar 'file-relative-name files)))
583
584 (goto-char (point-min))
585 (while (search-forward generate-autoload-section-header nil t)
586 (let* ((form (autoload-read-section-header))
587 (file (nth 3 form)))
588 (cond ((and (consp file) (stringp (car file)))
589 ;; This is a list of files that have no autoload cookies.
590 ;; There shouldn't be more than one such entry.
591 ;; Remove the obsolete section.
592 (autoload-remove-section (match-beginning 0))
593 (let ((last-time (nth 4 form)))
594 (dolist (file file)
595 (let ((file-time (nth 5 (file-attributes file))))
596 (when (and file-time
597 (not (time-less-p last-time file-time)))
598 ;; file unchanged
599 (push file no-autoloads)
600 (setq files (delete file files)))))))
601 ((not (stringp file)))
602 ((or (not (file-exists-p file))
603 ;; Remove duplicates as well, just in case.
604 (member file done))
605 ;; Remove the obsolete section.
606 (autoload-remove-section (match-beginning 0)))
607 ((not (time-less-p (nth 4 form)
608 (nth 5 (file-attributes file))))
609 ;; File hasn't changed.
610 nil)
611 (t
612 (autoload-remove-section (match-beginning 0))
613 (if (autoload-generate-file-autoloads
614 file (current-buffer) buffer-file-name)
615 (push file no-autoloads))))
616 (push file done)
617 (setq files (delete file files)))))
618 ;; Elements remaining in FILES have no existing autoload sections yet.
619 (dolist (file files)
620 (if (autoload-generate-file-autoloads file nil buffer-file-name)
621 (push file no-autoloads)))
622
623 (when no-autoloads
624 ;; Sort them for better readability.
625 (setq no-autoloads (sort no-autoloads 'string<))
626 ;; Add the `no-autoloads' section.
627 (goto-char (point-max))
628 (search-backward "\f" nil t)
629 (autoload-insert-section-header
630 (current-buffer) nil nil no-autoloads this-time)
631 (insert generate-autoload-section-trailer))
632
633 (save-buffer)
634 ;; In case autoload entries were added to other files because of
635 ;; file-local autoload-generated-file settings.
636 (autoload-save-buffers))))
637
638 (define-obsolete-function-alias 'update-autoloads-from-directories
639 'update-directory-autoloads "22.1")
640
641 ;;;###autoload
642 (defun batch-update-autoloads ()
643 "Update loaddefs.el autoloads in batch mode.
644 Calls `update-directory-autoloads' on the command line arguments."
645 (let ((args command-line-args-left))
646 (setq command-line-args-left nil)
647 (apply 'update-directory-autoloads args)))
648
649 (provide 'autoload)
650
651 ;; arch-tag: 00244766-98f4-4767-bf42-8a22103441c6
652 ;;; autoload.el ends here