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