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