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