(codepage-setup): Fix typo in obsolescence declaration.
[emacs.git] / lisp / emacs-lisp / autoload.el
blobe6bca3b15dde0cb3d046c0dbd7328bd535c7254a
1 ;; autoload.el --- maintain autoloads in loaddefs.el
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Roland McGrath <roland@gnu.org>
7 ;; Keywords: maint
9 ;; This file is part of GNU Emacs.
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.
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.
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.
26 ;;; Commentary:
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.
33 ;;; Code:
35 (require 'lisp-mode) ;for `doc-string-elt' properties.
36 (require 'help-fns) ;for help-add-fundoc-usage.
37 (eval-when-compile (require 'cl))
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)
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).
54 This string is used:
56 \;;;###autoload
57 \(defun function-to-be-autoloaded () ...)
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'.")
63 (defconst generate-autoload-section-header "\f\n;;;### "
64 "String that marks the form at the start of a new file's autoload section.")
66 (defconst generate-autoload-section-trailer "\n;;;***\n"
67 "String which indicates the end of the section of autoloads for a file.")
69 (defconst generate-autoload-section-continuation ";;;;;; "
70 "String to add on each continuation of the section header form.")
72 (defvar autoload-modified-buffers) ;Dynamically scoped var.
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)))))
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))))
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)))))
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))))))
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))))))
150 ;; nil here indicates that this is not a special autoload form.
151 (t nil))))
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.
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))))
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))))))
188 (defvar autoload-print-form-outbuf nil
189 "Buffer which gets the output of `autoload-print-form'.")
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)
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)))))))
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)
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))))))
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)))
295 (defvar no-update-autoloads nil
296 "File local variable to prevent scanning this file for autoload cookies.")
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)))
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)))
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'.
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.
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-readably t) ; This does something in Lucid Emacs.
339 (float-output-format nil)
340 (visited (get-file-buffer file))
341 (otherbuf nil)
342 (absfile (expand-file-name file))
343 relfile
344 ;; nil until we found a cookie.
345 output-start)
347 (with-current-buffer (or visited
348 ;; It is faster to avoid visiting the file.
349 (autoload-find-file file))
350 ;; Obey the no-update-autoloads file local variable.
351 (unless no-update-autoloads
352 (message "Generating autoloads for %s..." file)
353 (save-excursion
354 (save-restriction
355 (widen)
356 (goto-char (point-min))
357 (while (not (eobp))
358 (skip-chars-forward " \t\n\f")
359 (cond
360 ((looking-at (regexp-quote generate-autoload-cookie))
361 ;; If not done yet, figure out where to insert this text.
362 (unless output-start
363 (when (and outfile
364 (not (equal outfile (autoload-generated-file))))
365 ;; A file-local setting of autoload-generated-file says
366 ;; we should ignore OUTBUF.
367 (setq outbuf nil)
368 (setq otherbuf t))
369 (unless outbuf
370 (setq outbuf (autoload-find-destination absfile))
371 (unless outbuf
372 ;; The file has autoload cookies, but they're
373 ;; already up-to-date. If OUTFILE is nil, the
374 ;; entries are in the expected OUTBUF, otherwise
375 ;; they're elsewhere.
376 (throw 'done outfile)))
377 (with-current-buffer outbuf
378 (setq relfile (file-relative-name absfile))
379 (setq output-start (point)))
380 ;; (message "file=%S, relfile=%S, dest=%S"
381 ;; file relfile (autoload-generated-file))
383 (search-forward generate-autoload-cookie)
384 (skip-chars-forward " \t")
385 (if (eolp)
386 (condition-case err
387 ;; Read the next form and make an autoload.
388 (let* ((form (prog1 (read (current-buffer))
389 (or (bolp) (forward-line 1))))
390 (autoload (make-autoload form load-name)))
391 (if autoload
392 (push (nth 1 form) autoloads-done)
393 (setq autoload form))
394 (let ((autoload-print-form-outbuf outbuf))
395 (autoload-print-form autoload)))
396 (error
397 (message "Error in %s: %S" file err)))
399 ;; Copy the rest of the line to the output.
400 (princ (buffer-substring
401 (progn
402 ;; Back up over whitespace, to preserve it.
403 (skip-chars-backward " \f\t")
404 (if (= (char-after (1+ (point))) ? )
405 ;; Eat one space.
406 (forward-char 1))
407 (point))
408 (progn (forward-line 1) (point)))
409 outbuf)))
410 ((looking-at ";")
411 ;; Don't read the comment.
412 (forward-line 1))
414 (forward-sexp 1)
415 (forward-line 1))))))
417 (when output-start
418 (let ((secondary-autoloads-file-buf
419 (if (local-variable-p 'generated-autoload-file)
420 (current-buffer))))
421 (with-current-buffer outbuf
422 (save-excursion
423 ;; Insert the section-header line which lists the file name
424 ;; and which functions are in it, etc.
425 (goto-char output-start)
426 (autoload-insert-section-header
427 outbuf autoloads-done load-name relfile
428 (if secondary-autoloads-file-buf
429 ;; MD5 checksums are much better because they do not
430 ;; change unless the file changes (so they'll be
431 ;; equal on two different systems and will change
432 ;; less often than time-stamps, thus leading to fewer
433 ;; unneeded changes causing spurious conflicts), but
434 ;; using time-stamps is a very useful optimization,
435 ;; so we use time-stamps for the main autoloads file
436 ;; (loaddefs.el) where we have special ways to
437 ;; circumvent the "random change problem", and MD5
438 ;; checksum in secondary autoload files where we do
439 ;; not need the time-stamp optimization because it is
440 ;; already provided by the primary autoloads file.
441 (md5 secondary-autoloads-file-buf
442 ;; We'd really want to just use
443 ;; `emacs-internal' instead.
444 nil nil 'emacs-mule-unix)
445 (nth 5 (file-attributes relfile))))
446 (insert ";;; Generated autoloads from " relfile "\n"))
447 (insert generate-autoload-section-trailer))))
448 (message "Generating autoloads for %s...done" file))
449 (or visited
450 ;; We created this buffer, so we should kill it.
451 (kill-buffer (current-buffer))))
452 ;; If the entries were added to some other buffer, then the file
453 ;; doesn't add entries to OUTFILE.
454 (or (not output-start) otherbuf))))
456 (defun autoload-save-buffers ()
457 (while autoload-modified-buffers
458 (with-current-buffer (pop autoload-modified-buffers)
459 (save-buffer))))
461 ;;;###autoload
462 (defun update-file-autoloads (file &optional save-after)
463 "Update the autoloads for FILE in `generated-autoload-file'
464 \(which FILE might bind in its local variables).
465 If SAVE-AFTER is non-nil (which is always, when called interactively),
466 save the buffer too.
468 Return FILE if there was no autoload cookie in it, else nil."
469 (interactive "fUpdate autoloads for file: \np")
470 (let* ((autoload-modified-buffers nil)
471 (no-autoloads (autoload-generate-file-autoloads file)))
472 (if autoload-modified-buffers
473 (if save-after (autoload-save-buffers))
474 (if (interactive-p)
475 (message "Autoload section for %s is up to date." file)))
476 (if no-autoloads file)))
478 (defun autoload-find-destination (file)
479 "Find the destination point of the current buffer's autoloads.
480 FILE is the file name of the current buffer.
481 Returns a buffer whose point is placed at the requested location.
482 Returns nil if the file's autoloads are uptodate, otherwise
483 removes any prior now out-of-date autoload entries."
484 (catch 'up-to-date
485 (let* ((load-name (autoload-file-load-name file))
486 (buf (current-buffer))
487 (existing-buffer (if buffer-file-name buf))
488 (found nil))
489 (with-current-buffer
490 ;; We used to use `raw-text' to read this file, but this causes
491 ;; problems when the file contains non-ASCII characters.
492 (find-file-noselect
493 (autoload-ensure-default-file (autoload-generated-file)))
494 ;; This is to make generated-autoload-file have Unix EOLs, so
495 ;; that it is portable to all platforms.
496 (unless (zerop (coding-system-eol-type buffer-file-coding-system))
497 (set-buffer-file-coding-system 'unix))
498 (or (> (buffer-size) 0)
499 (error "Autoloads file %s does not exist" buffer-file-name))
500 (or (file-writable-p buffer-file-name)
501 (error "Autoloads file %s is not writable" buffer-file-name))
502 (widen)
503 (goto-char (point-min))
504 ;; Look for the section for LOAD-NAME.
505 (while (and (not found)
506 (search-forward generate-autoload-section-header nil t))
507 (let ((form (autoload-read-section-header)))
508 (cond ((string= (nth 2 form) load-name)
509 ;; We found the section for this file.
510 ;; Check if it is up to date.
511 (let ((begin (match-beginning 0))
512 (last-time (nth 4 form))
513 (file-time (nth 5 (file-attributes file))))
514 (if (and (or (null existing-buffer)
515 (not (buffer-modified-p existing-buffer)))
517 ;; last-time is the time-stamp (specifying
518 ;; the last time we looked at the file) and
519 ;; the file hasn't been changed since.
520 (and (listp last-time) (= (length last-time) 2)
521 (not (time-less-p last-time file-time)))
522 ;; last-time is an MD5 checksum instead.
523 (and (stringp last-time)
524 (equal last-time
525 (md5 buf nil nil 'emacs-mule)))))
526 (throw 'up-to-date nil)
527 (autoload-remove-section begin)
528 (setq found t))))
529 ((string< load-name (nth 2 form))
530 ;; We've come to a section alphabetically later than
531 ;; LOAD-NAME. We assume the file is in order and so
532 ;; there must be no section for LOAD-NAME. We will
533 ;; insert one before the section here.
534 (goto-char (match-beginning 0))
535 (setq found t)))))
536 (or found
537 (progn
538 ;; No later sections in the file. Put before the last page.
539 (goto-char (point-max))
540 (search-backward "\f" nil t)))
541 (unless (memq (current-buffer) autoload-modified-buffers)
542 (push (current-buffer) autoload-modified-buffers))
543 (current-buffer)))))
545 (defun autoload-remove-section (begin)
546 (goto-char begin)
547 (search-forward generate-autoload-section-trailer)
548 (delete-region begin (point)))
550 ;;;###autoload
551 (defun update-directory-autoloads (&rest dirs)
553 Update loaddefs.el with all the current autoloads from DIRS, and no old ones.
554 This uses `update-file-autoloads' (which see) to do its work.
555 In an interactive call, you must give one argument, the name
556 of a single directory. In a call from Lisp, you can supply multiple
557 directories as separate arguments, but this usage is discouraged.
559 The function does NOT recursively descend into subdirectories of the
560 directory or directories specified."
561 (interactive "DUpdate autoloads from directory: ")
562 (let* ((files-re (let ((tmp nil))
563 (dolist (suf (get-load-suffixes)
564 (concat "^[^=.].*" (regexp-opt tmp t) "\\'"))
565 (unless (string-match "\\.elc" suf) (push suf tmp)))))
566 (files (apply 'nconc
567 (mapcar (lambda (dir)
568 (directory-files (expand-file-name dir)
569 t files-re))
570 dirs)))
571 (done ())
572 (this-time (current-time))
573 ;; Files with no autoload cookies or whose autoloads go to other
574 ;; files because of file-local autoload-generated-file settings.
575 (no-autoloads nil)
576 (autoload-modified-buffers nil))
578 (with-current-buffer
579 (find-file-noselect
580 (autoload-ensure-default-file (autoload-generated-file)))
581 (save-excursion
583 ;; Canonicalize file names and remove the autoload file itself.
584 (setq files (delete (file-relative-name buffer-file-name)
585 (mapcar 'file-relative-name files)))
587 (goto-char (point-min))
588 (while (search-forward generate-autoload-section-header nil t)
589 (let* ((form (autoload-read-section-header))
590 (file (nth 3 form)))
591 (cond ((and (consp file) (stringp (car file)))
592 ;; This is a list of files that have no autoload cookies.
593 ;; There shouldn't be more than one such entry.
594 ;; Remove the obsolete section.
595 (autoload-remove-section (match-beginning 0))
596 (let ((last-time (nth 4 form)))
597 (dolist (file file)
598 (let ((file-time (nth 5 (file-attributes file))))
599 (when (and file-time
600 (not (time-less-p last-time file-time)))
601 ;; file unchanged
602 (push file no-autoloads)
603 (setq files (delete file files)))))))
604 ((not (stringp file)))
605 ((or (not (file-exists-p file))
606 ;; Remove duplicates as well, just in case.
607 (member file done))
608 ;; Remove the obsolete section.
609 (autoload-remove-section (match-beginning 0)))
610 ((not (time-less-p (nth 4 form)
611 (nth 5 (file-attributes file))))
612 ;; File hasn't changed.
613 nil)
615 (autoload-remove-section (match-beginning 0))
616 (if (autoload-generate-file-autoloads
617 file (current-buffer) buffer-file-name)
618 (push file no-autoloads))))
619 (push file done)
620 (setq files (delete file files)))))
621 ;; Elements remaining in FILES have no existing autoload sections yet.
622 (dolist (file files)
623 (if (autoload-generate-file-autoloads file nil buffer-file-name)
624 (push file no-autoloads)))
626 (when no-autoloads
627 ;; Sort them for better readability.
628 (setq no-autoloads (sort no-autoloads 'string<))
629 ;; Add the `no-autoloads' section.
630 (goto-char (point-max))
631 (search-backward "\f" nil t)
632 (autoload-insert-section-header
633 (current-buffer) nil nil no-autoloads this-time)
634 (insert generate-autoload-section-trailer))
636 (save-buffer)
637 ;; In case autoload entries were added to other files because of
638 ;; file-local autoload-generated-file settings.
639 (autoload-save-buffers))))
641 (define-obsolete-function-alias 'update-autoloads-from-directories
642 'update-directory-autoloads "22.1")
644 ;;;###autoload
645 (defun batch-update-autoloads ()
646 "Update loaddefs.el autoloads in batch mode.
647 Calls `update-directory-autoloads' on the command line arguments."
648 (let ((args command-line-args-left))
649 (setq command-line-args-left nil)
650 (apply 'update-directory-autoloads args)))
652 (provide 'autoload)
654 ;; arch-tag: 00244766-98f4-4767-bf42-8a22103441c6
655 ;;; autoload.el ends here