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, 2009, 2010
5 ;; Free Software Foundation, Inc.
7 ;; Author: Roland McGrath <roland@gnu.org>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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.
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.")
45 (put 'generated-autoload-file
'safe-local-variable
'stringp
)
47 (defvar generated-autoload-load-name nil
48 "Load name for `autoload' statements generated from autoload cookies.
49 If nil, this defaults to the file name, sans extension.")
51 (put 'generated-autoload-load-name
'safe-local-variable
'stringp
)
53 ;; This feels like it should be a defconst, but MH-E sets it to
54 ;; ";;;###mh-autoload" for the autoloads that are to go into mh-loaddefs.el.
55 (defvar generate-autoload-cookie
";;;###autoload"
56 "Magic comment indicating the following form should be autoloaded.
57 Used by \\[update-file-autoloads]. This string should be
58 meaningless to Lisp (e.g., a comment).
63 \(defun function-to-be-autoloaded () ...)
65 If this string appears alone on a line, the following form will be
66 read and an autoload made for it. If there is further text on the line,
67 that text will be copied verbatim to `generated-autoload-file'.")
69 (defvar autoload-excludes nil
70 "If non-nil, list of absolute file names not to scan for autoloads.")
72 (defconst generate-autoload-section-header
"\f\n;;;### "
73 "String that marks the form at the start of a new file's autoload section.")
75 (defconst generate-autoload-section-trailer
"\n;;;***\n"
76 "String which indicates the end of the section of autoloads for a file.")
78 (defconst generate-autoload-section-continuation
";;;;;; "
79 "String to add on each continuation of the section header form.")
81 (defvar autoload-modified-buffers
) ;Dynamically scoped var.
83 (defun make-autoload (form file
)
84 "Turn FORM into an autoload or defvar for source file FILE.
85 Returns nil if FORM is not a special autoload form (i.e. a function definition
86 or macro definition or a defcustom)."
87 (let ((car (car-safe form
)) expand
)
89 ;; For complex cases, try again on the macro-expansion.
90 ((and (memq car
'(easy-mmode-define-global-mode define-global-minor-mode
91 define-globalized-minor-mode
92 easy-mmode-define-minor-mode define-minor-mode
))
93 (setq expand
(let ((load-file-name file
)) (macroexpand form
)))
94 (eq (car expand
) 'progn
)
95 (memq :autoload-end expand
))
96 (let ((end (memq :autoload-end expand
)))
97 ;; Cut-off anything after the :autoload-end marker.
100 (mapcar (lambda (form) (make-autoload form file
))
103 ;; For special function-like operators, use the `autoload' function.
104 ((memq car
'(defun define-skeleton defmacro define-derived-mode
105 define-compilation-mode define-generic-mode
106 easy-mmode-define-global-mode define-global-minor-mode
107 define-globalized-minor-mode
108 easy-mmode-define-minor-mode define-minor-mode
109 defun
* defmacro
* define-overloadable-function
))
110 (let* ((macrop (memq car
'(defmacro defmacro
*)))
113 ((defun defmacro defun
* defmacro
*
114 define-overloadable-function
) (nth 2 form
))
115 ((define-skeleton) '(&optional str arg
))
116 ((define-generic-mode define-derived-mode
117 define-compilation-mode
) nil
)
119 (body (nthcdr (get car
'doc-string-elt
) form
))
120 (doc (if (stringp (car body
)) (pop body
))))
122 ;; Add the usage form at the end where describe-function-1
124 (setq doc
(help-add-fundoc-usage doc args
)))
126 ;; `define-generic-mode' quotes the name, so take care of that
127 (list 'autoload
(if (listp name
) name
(list 'quote name
))
129 (or (and (memq car
'(define-skeleton define-derived-mode
131 easy-mmode-define-global-mode
132 define-global-minor-mode
133 define-globalized-minor-mode
134 easy-mmode-define-minor-mode
135 define-minor-mode
)) t
)
136 (eq (car-safe (car body
)) 'interactive
))
137 (if macrop
(list 'quote
'macro
) nil
))))
139 ;; Special case to autoload some of the macro's declarations.
140 (let ((decls (nth (if (stringp (nth 3 form
)) 4 3) form
))
142 (when (eq (car decls
) 'declare
)
143 ;; FIXME: We'd like to reuse macro-declaration-function,
144 ;; but we can't since it doesn't return anything.
146 (case (car-safe decl
)
148 (push `(put ',name
'lisp-indent-function
',(cadr decl
))
151 (push `(put ',name
'doc-string-elt
',(cadr decl
)) exps
))))
153 (setq exp
`(progn ,exp
,@exps
))))))
156 ;; For defclass forms, use `eieio-defclass-autoload'.
158 (let ((name (nth 1 form
))
159 (superclasses (nth 2 form
))
161 (list 'eieio-defclass-autoload
(list 'quote name
)
162 (list 'quote superclasses
) file doc
)))
164 ;; Convert defcustom to less space-consuming data.
166 (let ((varname (car-safe (cdr-safe form
)))
167 (init (car-safe (cdr-safe (cdr-safe form
))))
168 (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form
)))))
169 ;; (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form)))))
172 (defvar ,varname
,init
,doc
)
173 (custom-autoload ',varname
,file
175 (null (cadr (memq :set form
)))
179 ;; In Emacs this is normally handled separately by cus-dep.el, but for
180 ;; third party packages, it can be convenient to explicitly autoload
182 (let ((groupname (nth 1 form
)))
183 `(let ((loads (get ',groupname
'custom-loads
)))
184 (if (member ',file loads
) nil
185 (put ',groupname
'custom-loads
(cons ',file loads
))))))
187 ;; nil here indicates that this is not a special autoload form.
190 ;; Forms which have doc-strings which should be printed specially.
191 ;; A doc-string-elt property of ELT says that (nth ELT FORM) is
192 ;; the doc-string in FORM.
193 ;; Those properties are now set in lisp-mode.el.
195 (defun autoload-generated-file ()
196 (expand-file-name generated-autoload-file
197 ;; File-local settings of generated-autoload-file should
198 ;; be interpreted relative to the file's location,
200 (if (not (local-variable-p 'generated-autoload-file
))
201 (expand-file-name "lisp" source-directory
))))
204 (defun autoload-read-section-header ()
205 "Read a section header form.
206 Since continuation lines have been marked as comments,
207 we must copy the text of the form and remove those comment
208 markers before we call `read'."
210 (let ((beginning (point))
213 (while (looking-at generate-autoload-section-continuation
)
215 (setq string
(buffer-substring beginning
(point)))
216 (with-current-buffer (get-buffer-create " *autoload*")
219 (goto-char (point-min))
220 (while (search-forward generate-autoload-section-continuation nil t
)
222 (goto-char (point-min))
223 (read (current-buffer))))))
225 (defvar autoload-print-form-outbuf nil
226 "Buffer which gets the output of `autoload-print-form'.")
228 (defun autoload-print-form (form)
229 "Print FORM such that `make-docfile' will find the docstrings.
230 The variable `autoload-print-form-outbuf' specifies the buffer to
233 ;; If the form is a sequence, recurse.
234 ((eq (car form
) 'progn
) (mapcar 'autoload-print-form
(cdr form
)))
235 ;; Symbols at the toplevel are meaningless.
238 (let ((doc-string-elt (get (car-safe form
) 'doc-string-elt
))
239 (outbuf autoload-print-form-outbuf
))
240 (if (and doc-string-elt
(stringp (nth doc-string-elt form
)))
241 ;; We need to hack the printing because the
242 ;; doc-string must be printed specially for
243 ;; make-docfile (sigh).
244 (let* ((p (nthcdr (1- doc-string-elt
) form
))
248 (let ((print-escape-newlines t
)
250 (print-escape-nonascii t
))
254 (princ "\"\\\n" outbuf
)
255 (let ((begin (with-current-buffer outbuf
(point))))
256 (princ (substring (prin1-to-string (car elt
)) 1)
258 ;; Insert a backslash before each ( that
259 ;; appears at the beginning of a line in
261 (with-current-buffer outbuf
263 (while (re-search-backward "\n[[(]" begin t
)
269 (princ (substring (prin1-to-string (cdr elt
)) 1)
272 (let ((print-escape-newlines t
)
274 (print-escape-nonascii t
))
275 (print form outbuf
)))))))
277 (defun autoload-rubric (file &optional type feature
)
278 "Return a string giving the appropriate autoload rubric for FILE.
279 TYPE (default \"autoloads\") is a string stating the type of
280 information contained in FILE. If FEATURE is non-nil, FILE
281 will provide a feature. FEATURE may be a string naming the
282 feature, otherwise it will be based on FILE's name.
284 At present, a feature is in fact always provided, but this should
286 (let ((basename (file-name-nondirectory file
)))
287 (concat ";;; " basename
288 " --- automatically extracted " (or type
"autoloads") "\n"
292 ;; This is used outside of autoload.el, eg cus-dep, finder.
294 (if (stringp feature
)
296 (file-name-sans-extension basename
))
298 ";; Local Variables:\n"
299 ";; version-control: never\n"
300 ";; no-byte-compile: t\n"
301 ";; no-update-autoloads: t\n"
307 (defun autoload-ensure-default-file (file)
308 "Make sure that the autoload file FILE exists and if not create it."
309 (unless (file-exists-p file
)
310 (write-region (autoload-rubric file
) nil file
))
313 (defun autoload-insert-section-header (outbuf autoloads load-name file time
)
314 "Insert the section-header line,
315 which lists the file name and which functions are in it, etc."
316 (insert generate-autoload-section-header
)
317 (prin1 (list 'autoloads autoloads load-name file time
)
320 ;; Break that line at spaces, to avoid very long lines.
321 ;; Make each sub-line into a comment.
322 (with-current-buffer outbuf
327 (skip-chars-forward "^ \n")
329 (insert "\n" generate-autoload-section-continuation
))))))
331 (defun autoload-find-file (file)
332 "Fetch file and put it in a temp buffer. Return the buffer."
333 ;; It is faster to avoid visiting the file.
334 (setq file
(expand-file-name file
))
335 (with-current-buffer (get-buffer-create " *autoload-file*")
336 (kill-all-local-variables)
338 (setq buffer-undo-list t
339 buffer-read-only nil
)
341 (setq default-directory
(file-name-directory file
))
342 (insert-file-contents file nil
)
343 (let ((enable-local-variables :safe
))
344 (hack-local-variables))
347 (defvar no-update-autoloads nil
348 "File local variable to prevent scanning this file for autoload cookies.")
350 (defun autoload-file-load-name (file)
351 "Compute the name that will be used to load FILE."
352 ;; OUTFILE should be the name of the global loaddefs.el file, which
353 ;; is expected to be at the root directory of the files we're
354 ;; scanning for autoloads and will be in the `load-path'.
355 (let* ((outfile (default-value 'generated-autoload-file
))
356 (name (file-relative-name file
(file-name-directory outfile
)))
358 (dir (file-name-directory outfile
)))
359 ;; If `name' has directory components, only keep the
360 ;; last few that are really needed.
362 (setq name
(directory-file-name name
))
363 (push (file-name-nondirectory name
) names
)
364 (setq name
(file-name-directory name
)))
367 ((null (cdr names
)) (setq name
(car names
)))
368 ((file-exists-p (expand-file-name "subdirs.el" dir
))
369 ;; FIXME: here we only check the existence of subdirs.el,
370 ;; without checking its content. This makes it generate wrong load
371 ;; names for cases like lisp/term which is not added to load-path.
372 (setq dir
(expand-file-name (pop names
) dir
)))
373 (t (setq name
(mapconcat 'identity names
"/")))))
374 (if (string-match "\\.elc?\\(\\.\\|\\'\\)" name
)
375 (substring name
0 (match-beginning 0))
378 (defun generate-file-autoloads (file)
379 "Insert at point a loaddefs autoload section for FILE.
380 Autoloads are generated for defuns and defmacros in FILE
381 marked by `generate-autoload-cookie' (which see).
382 If FILE is being visited in a buffer, the contents of the buffer
384 Return non-nil in the case where no autoloads were added at point."
385 (interactive "fGenerate autoloads for file: ")
386 (autoload-generate-file-autoloads file
(current-buffer)))
388 (defvar print-readably
)
390 ;; When called from `generate-file-autoloads' we should ignore
391 ;; `generated-autoload-file' altogether. When called from
392 ;; `update-file-autoloads' we don't know `outbuf'. And when called from
393 ;; `update-directory-autoloads' it's in between: we know the default
394 ;; `outbuf' but we should obey any file-local setting of
395 ;; `generated-autoload-file'.
396 (defun autoload-generate-file-autoloads (file &optional outbuf outfile
)
397 "Insert an autoload section for FILE in the appropriate buffer.
398 Autoloads are generated for defuns and defmacros in FILE
399 marked by `generate-autoload-cookie' (which see).
400 If FILE is being visited in a buffer, the contents of the buffer are used.
401 OUTBUF is the buffer in which the autoload statements should be inserted.
402 If OUTBUF is nil, it will be determined by `autoload-generated-file'.
404 If provided, OUTFILE is expected to be the file name of OUTBUF.
405 If OUTFILE is non-nil and FILE specifies a `generated-autoload-file'
406 different from OUTFILE, then OUTBUF is ignored.
408 Return non-nil if and only if FILE adds no autoloads to OUTFILE
409 \(or OUTBUF if OUTFILE is nil)."
411 (let ((autoloads-done '())
415 (print-readably t
) ; This does something in Lucid Emacs.
416 (float-output-format nil
)
417 (visited (get-file-buffer file
))
419 (absfile (expand-file-name file
))
420 ;; nil until we found a cookie.
422 (with-current-buffer (or visited
423 ;; It is faster to avoid visiting the file.
424 (autoload-find-file file
))
425 ;; Obey the no-update-autoloads file local variable.
426 (unless no-update-autoloads
427 (message "Generating autoloads for %s..." file
)
429 (if (stringp generated-autoload-load-name
)
430 generated-autoload-load-name
431 (autoload-file-load-name absfile
)))
433 (not (equal outfile
(autoload-generated-file))))
438 (goto-char (point-min))
440 (skip-chars-forward " \t\n\f")
442 ((looking-at (regexp-quote generate-autoload-cookie
))
443 ;; If not done yet, figure out where to insert this text.
447 ;; A file-local setting of
448 ;; autoload-generated-file says we
449 ;; should ignore OUTBUF.
452 (autoload-find-destination absfile load-name
)
453 ;; The file has autoload cookies, but they're
454 ;; already up-to-date. If OUTFILE is nil, the
455 ;; entries are in the expected OUTBUF,
456 ;; otherwise they're elsewhere.
457 (throw 'done otherbuf
))))
458 (with-current-buffer outbuf
459 (setq output-start
(point-marker)
461 (search-forward generate-autoload-cookie
)
462 (skip-chars-forward " \t")
465 ;; Read the next form and make an autoload.
466 (let* ((form (prog1 (read (current-buffer))
467 (or (bolp) (forward-line 1))))
468 (autoload (make-autoload form load-name
)))
470 (push (nth 1 form
) autoloads-done
)
471 (setq autoload form
))
472 (let ((autoload-print-form-outbuf
473 (marker-buffer output-start
)))
474 (autoload-print-form autoload
)))
476 (message "Error in %s: %S" file err
)))
478 ;; Copy the rest of the line to the output.
479 (princ (buffer-substring
481 ;; Back up over whitespace, to preserve it.
482 (skip-chars-backward " \f\t")
483 (if (= (char-after (1+ (point))) ?
)
487 (progn (forward-line 1) (point)))
488 (marker-buffer output-start
))))
490 ;; Don't read the comment.
494 (forward-line 1))))))
497 (let ((secondary-autoloads-file-buf
498 (if (local-variable-p 'generated-autoload-file
)
500 (with-current-buffer (marker-buffer output-start
)
502 ;; Insert the section-header line which lists the file name
503 ;; and which functions are in it, etc.
504 (assert (= ostart output-start
))
505 (goto-char output-start
)
506 (let ((relfile (file-relative-name absfile
)))
507 (autoload-insert-section-header
508 (marker-buffer output-start
)
509 autoloads-done load-name relfile
510 (if secondary-autoloads-file-buf
511 ;; MD5 checksums are much better because they do not
512 ;; change unless the file changes (so they'll be
513 ;; equal on two different systems and will change
514 ;; less often than time-stamps, thus leading to fewer
515 ;; unneeded changes causing spurious conflicts), but
516 ;; using time-stamps is a very useful optimization,
517 ;; so we use time-stamps for the main autoloads file
518 ;; (loaddefs.el) where we have special ways to
519 ;; circumvent the "random change problem", and MD5
520 ;; checksum in secondary autoload files where we do
521 ;; not need the time-stamp optimization because it is
522 ;; already provided by the primary autoloads file.
523 (md5 secondary-autoloads-file-buf
524 ;; We'd really want to just use
525 ;; `emacs-internal' instead.
526 nil nil
'emacs-mule-unix
)
527 (nth 5 (file-attributes relfile
))))
528 (insert ";;; Generated autoloads from " relfile
"\n")))
529 (insert generate-autoload-section-trailer
))))
530 (message "Generating autoloads for %s...done" file
))
532 ;; We created this buffer, so we should kill it.
533 (kill-buffer (current-buffer))))
534 (or (not output-start
)
535 ;; If the entries were added to some other buffer, then the file
536 ;; doesn't add entries to OUTFILE.
539 (defun autoload-save-buffers ()
540 (while autoload-modified-buffers
541 (with-current-buffer (pop autoload-modified-buffers
)
545 (defun update-file-autoloads (file &optional save-after
)
546 "Update the autoloads for FILE in `generated-autoload-file'
547 \(which FILE might bind in its local variables).
548 If SAVE-AFTER is non-nil (which is always, when called interactively),
551 Return FILE if there was no autoload cookie in it, else nil."
552 (interactive "fUpdate autoloads for file: \np")
553 (let* ((autoload-modified-buffers nil
)
554 (no-autoloads (autoload-generate-file-autoloads file
)))
555 (if autoload-modified-buffers
556 (if save-after
(autoload-save-buffers))
557 (if (called-interactively-p 'interactive
)
558 (message "Autoload section for %s is up to date." file
)))
559 (if no-autoloads file
)))
561 (defun autoload-find-destination (file load-name
)
562 "Find the destination point of the current buffer's autoloads.
563 FILE is the file name of the current buffer.
564 Returns a buffer whose point is placed at the requested location.
565 Returns nil if the file's autoloads are uptodate, otherwise
566 removes any prior now out-of-date autoload entries."
568 (let* ((buf (current-buffer))
569 (existing-buffer (if buffer-file-name buf
))
572 ;; We used to use `raw-text' to read this file, but this causes
573 ;; problems when the file contains non-ASCII characters.
575 (autoload-ensure-default-file (autoload-generated-file)))
576 ;; This is to make generated-autoload-file have Unix EOLs, so
577 ;; that it is portable to all platforms.
578 (unless (zerop (coding-system-eol-type buffer-file-coding-system
))
579 (set-buffer-file-coding-system 'unix
))
580 (or (> (buffer-size) 0)
581 (error "Autoloads file %s lacks boilerplate" buffer-file-name
))
582 (or (file-writable-p buffer-file-name
)
583 (error "Autoloads file %s is not writable" buffer-file-name
))
585 (goto-char (point-min))
586 ;; Look for the section for LOAD-NAME.
587 (while (and (not found
)
588 (search-forward generate-autoload-section-header nil t
))
589 (let ((form (autoload-read-section-header)))
590 (cond ((string= (nth 2 form
) load-name
)
591 ;; We found the section for this file.
592 ;; Check if it is up to date.
593 (let ((begin (match-beginning 0))
594 (last-time (nth 4 form
))
595 (file-time (nth 5 (file-attributes file
))))
596 (if (and (or (null existing-buffer
)
597 (not (buffer-modified-p existing-buffer
)))
599 ;; last-time is the time-stamp (specifying
600 ;; the last time we looked at the file) and
601 ;; the file hasn't been changed since.
602 (and (listp last-time
) (= (length last-time
) 2)
603 (not (time-less-p last-time file-time
)))
604 ;; last-time is an MD5 checksum instead.
605 (and (stringp last-time
)
607 (md5 buf nil nil
'emacs-mule
)))))
608 (throw 'up-to-date nil
)
609 (autoload-remove-section begin
)
611 ((string< load-name
(nth 2 form
))
612 ;; We've come to a section alphabetically later than
613 ;; LOAD-NAME. We assume the file is in order and so
614 ;; there must be no section for LOAD-NAME. We will
615 ;; insert one before the section here.
616 (goto-char (match-beginning 0))
620 ;; No later sections in the file. Put before the last page.
621 (goto-char (point-max))
622 (search-backward "\f" nil t
)))
623 (unless (memq (current-buffer) autoload-modified-buffers
)
624 (push (current-buffer) autoload-modified-buffers
))
627 (defun autoload-remove-section (begin)
629 (search-forward generate-autoload-section-trailer
)
630 (delete-region begin
(point)))
633 (defun update-directory-autoloads (&rest dirs
)
635 Update loaddefs.el with all the current autoloads from DIRS, and no old ones.
636 This uses `update-file-autoloads' (which see) to do its work.
637 In an interactive call, you must give one argument, the name
638 of a single directory. In a call from Lisp, you can supply multiple
639 directories as separate arguments, but this usage is discouraged.
641 The function does NOT recursively descend into subdirectories of the
642 directory or directories specified."
643 (interactive "DUpdate autoloads from directory: ")
644 (let* ((files-re (let ((tmp nil
))
645 (dolist (suf (get-load-suffixes)
646 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
647 (unless (string-match "\\.elc" suf
) (push suf tmp
)))))
649 (mapcar (lambda (dir)
650 (directory-files (expand-file-name dir
)
654 (this-time (current-time))
655 ;; Files with no autoload cookies or whose autoloads go to other
656 ;; files because of file-local autoload-generated-file settings.
658 (autoload-modified-buffers nil
))
662 (autoload-ensure-default-file (autoload-generated-file)))
665 ;; Canonicalize file names and remove the autoload file itself.
666 (setq files
(delete (file-relative-name buffer-file-name
)
667 (mapcar 'file-relative-name files
)))
669 (goto-char (point-min))
670 (while (search-forward generate-autoload-section-header nil t
)
671 (let* ((form (autoload-read-section-header))
673 (cond ((and (consp file
) (stringp (car file
)))
674 ;; This is a list of files that have no autoload cookies.
675 ;; There shouldn't be more than one such entry.
676 ;; Remove the obsolete section.
677 (autoload-remove-section (match-beginning 0))
678 (let ((last-time (nth 4 form
)))
680 (let ((file-time (nth 5 (file-attributes file
))))
682 (not (time-less-p last-time file-time
)))
684 (push file no-autoloads
)
685 (setq files
(delete file files
)))))))
686 ((not (stringp file
)))
687 ((or (not (file-exists-p file
))
688 ;; Remove duplicates as well, just in case.
690 ;; If the file is actually excluded.
691 (member (expand-file-name file
) autoload-excludes
))
692 ;; Remove the obsolete section.
693 (autoload-remove-section (match-beginning 0)))
694 ((not (time-less-p (nth 4 form
)
695 (nth 5 (file-attributes file
))))
696 ;; File hasn't changed.
699 (autoload-remove-section (match-beginning 0))
700 (if (autoload-generate-file-autoloads
701 ;; Passing `current-buffer' makes it insert at point.
702 file
(current-buffer) buffer-file-name
)
703 (push file no-autoloads
))))
705 (setq files
(delete file files
)))))
706 ;; Elements remaining in FILES have no existing autoload sections yet.
709 ((member (expand-file-name file
) autoload-excludes
) nil
)
710 ;; Passing nil as second argument forces
711 ;; autoload-generate-file-autoloads to look for the right
712 ;; spot where to insert each autoloads section.
713 ((autoload-generate-file-autoloads file nil buffer-file-name
)
714 (push file no-autoloads
))))
717 ;; Sort them for better readability.
718 (setq no-autoloads
(sort no-autoloads
'string
<))
719 ;; Add the `no-autoloads' section.
720 (goto-char (point-max))
721 (search-backward "\f" nil t
)
722 (autoload-insert-section-header
723 (current-buffer) nil nil no-autoloads this-time
)
724 (insert generate-autoload-section-trailer
))
727 ;; In case autoload entries were added to other files because of
728 ;; file-local autoload-generated-file settings.
729 (autoload-save-buffers))))
731 (define-obsolete-function-alias 'update-autoloads-from-directories
732 'update-directory-autoloads
"22.1")
734 (defvar autoload-make-program
(or (getenv "MAKE") "make")
735 "Name of the make program in use during the Emacs build process.")
738 (defun batch-update-autoloads ()
739 "Update loaddefs.el autoloads in batch mode.
740 Calls `update-directory-autoloads' on the command line arguments."
741 ;; For use during the Emacs build process only.
742 (unless autoload-excludes
743 (let* ((ldir (file-name-directory generated-autoload-file
))
745 (file-name-as-directory
746 (expand-file-name (if (eq system-type
'windows-nt
)
750 (tmpfile "echolisp.tmp")
752 ;; Windows uses the 'echolisp' approach because:
753 ;; i) It does not have $lisp as a single simple definition, so
754 ;; it would be harder to parse the Makefile.
755 ;; ii) It can, since it already has $lisp broken up into pieces
756 ;; that the command-line can handle.
757 ;; Non-Windows builds do not use the 'echolisp' approach because
758 ;; no-one knows (?) the maximum safe command-line length on all
759 ;; supported systems. $lisp is much longer there since it uses
760 ;; absolute paths, and it would seem a shame to split it just for this.
761 (when (file-readable-p mfile
)
762 (if (eq system-type
'windows-nt
)
764 (if (file-exists-p tmpfile
) (delete-file tmpfile
))
765 ;; FIXME call-process is better, if it works.
766 (shell-command (format "%s echolisp > %s"
767 autoload-make-program tmpfile
))
768 (file-readable-p tmpfile
))
770 (insert-file-contents tmpfile
)
771 ;; FIXME could be a single while loop.
773 (setq lim
(line-end-position))
774 (while (re-search-forward "\\([^ ]+\\.el\\)c?\\>" lim t
)
775 (push (expand-file-name (match-string 1))
779 (insert-file-contents mfile
)
780 (when (re-search-forward "^shortlisp= " nil t
)
781 (setq lim
(line-end-position))
782 (while (re-search-forward "\\.\\./lisp/\\([^ ]+\\.el\\)c?\\>"
784 (push (expand-file-name (match-string 1) ldir
)
785 autoload-excludes
))))))))
786 (let ((args command-line-args-left
))
787 (setq command-line-args-left nil
)
788 (apply 'update-directory-autoloads args
)))
792 ;; arch-tag: 00244766-98f4-4767-bf42-8a22103441c6
793 ;;; autoload.el ends here