Mercurial > emacs
annotate lisp/emacs-lisp/autoload.el @ 5432:c3677267e74d
(file_name_completion_stat): If have symlinks, use lstat.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 04 Jan 1994 06:37:51 +0000 |
parents | 434ef4c2fda7 |
children | b1e5e6efed1d |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
648
diff
changeset
|
1 ;;; autoload.el --- maintain autoloads in loaddefs.el. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
648
diff
changeset
|
2 |
1884
4a8bc12e7017
(generate-file-autoloads): If no buffer was visiting FILE when we started,
Roland McGrath <roland@gnu.org>
parents:
1552
diff
changeset
|
3 ;;; Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. |
473 | 4 ;;; |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1975
diff
changeset
|
6 ;; Keywords: maint |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
7 |
473 | 8 ;;; This program is free software; you can redistribute it and/or modify |
9 ;;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
10 ;;; the Free Software Foundation; either version 2, or (at your option) |
473 | 11 ;;; any later version. |
12 ;;; | |
13 ;;; This program is distributed in the hope that it will be useful, | |
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;;; GNU General Public License for more details. | |
17 ;;; | |
18 ;;; A copy of the GNU General Public License can be obtained from this | |
19 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from | |
20 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | |
21 ;;; 02139, USA. | |
22 ;;; | |
23 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
24 ;;; Commentary;: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
25 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
26 ;; This code helps GNU Emacs maintainers keep the autoload.el file up to |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 ;; date. It interprets magic cookies of the form ";;;###autoload" in |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
28 ;; lisp source files in various useful ways. To learn more, read the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
29 ;; source; if you're going to use this, you'd better be able to. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
30 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
31 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
32 |
473 | 33 (defun make-autoload (form file) |
34 "Turn FORM, a defun or defmacro, into an autoload for source file FILE. | |
35 Returns nil if FORM is not a defun or defmacro." | |
36 (let ((car (car-safe form))) | |
3777
d6f56b9586f7
(make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents:
3774
diff
changeset
|
37 (if (memq car '(defun defmacro)) |
d6f56b9586f7
(make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents:
3774
diff
changeset
|
38 (let ((macrop (eq car 'defmacro)) |
d6f56b9586f7
(make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents:
3774
diff
changeset
|
39 name doc) |
473 | 40 (setq form (cdr form)) |
41 (setq name (car form)) | |
42 ;; Ignore the arguments. | |
43 (setq form (cdr (cdr form))) | |
44 (setq doc (car form)) | |
45 (if (stringp doc) | |
46 (setq form (cdr form)) | |
47 (setq doc nil)) | |
48 (list 'autoload (list 'quote name) file doc | |
1552
f2901040a07b
* autoload.el (make-autoload): When creating an autoload
Jim Blandy <jimb@redhat.com>
parents:
1108
diff
changeset
|
49 (eq (car-safe (car form)) 'interactive) |
f2901040a07b
* autoload.el (make-autoload): When creating an autoload
Jim Blandy <jimb@redhat.com>
parents:
1108
diff
changeset
|
50 (if macrop (list 'quote 'macro) nil))) |
473 | 51 nil))) |
52 | |
53 (defconst generate-autoload-cookie ";;;###autoload" | |
3774
3b0cb275ca29
(generate-autoload-cookie, update-autoloads-here): Doc fixes.
Roland McGrath <roland@gnu.org>
parents:
2535
diff
changeset
|
54 "Magic comment indicating the following form should be autoloaded. |
3b0cb275ca29
(generate-autoload-cookie, update-autoloads-here): Doc fixes.
Roland McGrath <roland@gnu.org>
parents:
2535
diff
changeset
|
55 Used by \\[update-file-autoloads]. This string should be |
473 | 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 inserted before the form identifying | |
69 the section of autoloads for a file.") | |
70 | |
71 (defconst generate-autoload-section-trailer "\n;;;***\n" | |
72 "String which indicates the end of the section of autoloads for a file.") | |
73 | |
727 | 74 ;;; Forms which have doc-strings which should be printed specially. |
75 ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is | |
76 ;;; the doc-string in FORM. | |
77 ;;; | |
78 ;;; There used to be the following note here: | |
79 ;;; ;;; Note: defconst and defvar should NOT be marked in this way. | |
80 ;;; ;;; We don't want to produce defconsts and defvars that | |
81 ;;; ;;; make-docfile can grok, because then it would grok them twice, | |
82 ;;; ;;; once in foo.el (where they are given with ;;;###autoload) and | |
83 ;;; ;;; once in loaddefs.el. | |
84 ;;; | |
85 ;;; Counter-note: Yes, they should be marked in this way. | |
86 ;;; make-docfile only processes those files that are loaded into the | |
87 ;;; dumped Emacs, and those files should never have anything | |
88 ;;; autoloaded here. The above-feared problem only occurs with files | |
89 ;;; which have autoloaded entries *and* are processed by make-docfile; | |
90 ;;; there should be no such files. | |
91 | |
473 | 92 (put 'autoload 'doc-string-elt 3) |
727 | 93 (put 'defun 'doc-string-elt 3) |
94 (put 'defvar 'doc-string-elt 3) | |
95 (put 'defconst 'doc-string-elt 3) | |
96 (put 'defmacro 'doc-string-elt 3) | |
473 | 97 |
98 (defun generate-file-autoloads (file) | |
99 "Insert at point a loaddefs autoload section for FILE. | |
100 autoloads are generated for defuns and defmacros in FILE | |
2494
c0fbbfadcb04
(generate-file-autoloads): Doc fix.
Roland McGrath <roland@gnu.org>
parents:
2307
diff
changeset
|
101 marked by `generate-autoload-cookie' (which see). |
473 | 102 If FILE is being visited in a buffer, the contents of the buffer |
103 are used." | |
104 (interactive "fGenerate autoloads for file: ") | |
105 (let ((outbuf (current-buffer)) | |
106 (autoloads-done '()) | |
107 (load-name (let ((name (file-name-nondirectory file))) | |
108 (if (string-match "\\.elc?$" name) | |
109 (substring name 0 (match-beginning 0)) | |
110 name))) | |
111 (print-length nil) | |
4555
434ef4c2fda7
(generate-file-autoloads): Set float-output-format to
Richard M. Stallman <rms@gnu.org>
parents:
4215
diff
changeset
|
112 (float-output-format nil) |
473 | 113 (done-any nil) |
1884
4a8bc12e7017
(generate-file-autoloads): If no buffer was visiting FILE when we started,
Roland McGrath <roland@gnu.org>
parents:
1552
diff
changeset
|
114 (visited (get-file-buffer file)) |
473 | 115 output-end) |
727 | 116 |
117 ;; If the autoload section we create here uses an absolute | |
118 ;; pathname for FILE in its header, and then Emacs is installed | |
119 ;; under a different path on another system, | |
120 ;; `update-autoloads-here' won't be able to find the files to be | |
121 ;; autoloaded. So, if FILE is in the same directory or a | |
732 | 122 ;; subdirectory of the current buffer's directory, we'll make it |
727 | 123 ;; relative to the current buffer's directory. |
124 (setq file (expand-file-name file)) | |
4089
410395998370
(generate-file-autoloads): Fix FILE truename hacking to substring
Roland McGrath <roland@gnu.org>
parents:
4068
diff
changeset
|
125 (let* ((source-truename (file-truename file)) |
410395998370
(generate-file-autoloads): Fix FILE truename hacking to substring
Roland McGrath <roland@gnu.org>
parents:
4068
diff
changeset
|
126 (dir-truename (file-name-as-directory |
410395998370
(generate-file-autoloads): Fix FILE truename hacking to substring
Roland McGrath <roland@gnu.org>
parents:
4068
diff
changeset
|
127 (file-truename default-directory))) |
410395998370
(generate-file-autoloads): Fix FILE truename hacking to substring
Roland McGrath <roland@gnu.org>
parents:
4068
diff
changeset
|
128 (len (length dir-truename))) |
410395998370
(generate-file-autoloads): Fix FILE truename hacking to substring
Roland McGrath <roland@gnu.org>
parents:
4068
diff
changeset
|
129 (if (and (< len (length source-truename)) |
410395998370
(generate-file-autoloads): Fix FILE truename hacking to substring
Roland McGrath <roland@gnu.org>
parents:
4068
diff
changeset
|
130 (string= dir-truename (substring source-truename 0 len))) |
410395998370
(generate-file-autoloads): Fix FILE truename hacking to substring
Roland McGrath <roland@gnu.org>
parents:
4068
diff
changeset
|
131 (setq file (substring source-truename len)))) |
727 | 132 |
473 | 133 (message "Generating autoloads for %s..." file) |
1975
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
134 (save-excursion |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
135 (unwind-protect |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
136 (progn |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
137 (set-buffer (find-file-noselect file)) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
138 (save-excursion |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
139 (save-restriction |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
140 (widen) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
141 (goto-char (point-min)) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
142 (while (not (eobp)) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
143 (skip-chars-forward " \t\n\f") |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
144 (cond |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
145 ((looking-at (regexp-quote generate-autoload-cookie)) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
146 (search-forward generate-autoload-cookie) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
147 (skip-chars-forward " \t") |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
148 (setq done-any t) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
149 (if (eolp) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
150 ;; Read the next form and make an autoload. |
3805
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
151 (let* ((form (prog1 (read (current-buffer)) |
1975
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
152 (forward-line 1))) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
153 (autoload (make-autoload form load-name)) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
154 (doc-string-elt (get (car-safe form) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
155 'doc-string-elt))) |
3805
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
156 (if autoload |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
157 (setq autoloads-done (cons (nth 1 form) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
158 autoloads-done)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
159 (setq autoload form)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
160 (if (and doc-string-elt |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
161 (stringp (nth doc-string-elt autoload))) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
162 ;; We need to hack the printing because the |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
163 ;; doc-string must be printed specially for |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
164 ;; make-docfile (sigh). |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
165 (let* ((p (nthcdr (1- doc-string-elt) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
166 autoload)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
167 (elt (cdr p))) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
168 (setcdr p nil) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
169 (princ "\n(" outbuf) |
4215
ccb1fb62bba6
(generate-file-autoloads): Bind float-output-format.
Richard M. Stallman <rms@gnu.org>
parents:
4152
diff
changeset
|
170 (let ((print-escape-newlines t)) |
ccb1fb62bba6
(generate-file-autoloads): Bind float-output-format.
Richard M. Stallman <rms@gnu.org>
parents:
4152
diff
changeset
|
171 (mapcar (function (lambda (elt) |
ccb1fb62bba6
(generate-file-autoloads): Bind float-output-format.
Richard M. Stallman <rms@gnu.org>
parents:
4152
diff
changeset
|
172 (prin1 elt outbuf) |
ccb1fb62bba6
(generate-file-autoloads): Bind float-output-format.
Richard M. Stallman <rms@gnu.org>
parents:
4152
diff
changeset
|
173 (princ " " outbuf))) |
ccb1fb62bba6
(generate-file-autoloads): Bind float-output-format.
Richard M. Stallman <rms@gnu.org>
parents:
4152
diff
changeset
|
174 autoload)) |
3805
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
175 (princ "\"\\\n" outbuf) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
176 (princ (substring |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
177 (prin1-to-string (car elt)) 1) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
178 outbuf) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
179 (if (null (cdr elt)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
180 (princ ")" outbuf) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
181 (princ " " outbuf) |
1975
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
182 (princ (substring |
3805
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
183 (prin1-to-string (cdr elt)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
184 1) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
185 outbuf)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
186 (terpri outbuf)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
187 (print autoload outbuf))) |
1975
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
188 ;; Copy the rest of the line to the output. |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
189 (let ((begin (point))) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
190 (forward-line 1) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
191 (princ (buffer-substring begin (point)) outbuf)))) |
3805
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
192 ((looking-at ";") |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
193 ;; Don't read the comment. |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
194 (forward-line 1)) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
195 (t |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
196 (forward-sexp 1) |
21c6c1e1a38b
(generate-file-autoloads): Undo previous change
Richard M. Stallman <rms@gnu.org>
parents:
3777
diff
changeset
|
197 (forward-line 1))))))) |
1975
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
198 (or visited |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
199 ;; We created this buffer, so we should kill it. |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
200 (kill-buffer (current-buffer))) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
201 (set-buffer outbuf) |
3334e2489824
* autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents:
1884
diff
changeset
|
202 (setq output-end (point-marker)))) |
473 | 203 (if done-any |
204 (progn | |
205 (insert generate-autoload-section-header) | |
206 (prin1 (list 'autoloads autoloads-done load-name file | |
207 (nth 5 (file-attributes file))) | |
208 outbuf) | |
209 (terpri outbuf) | |
210 (insert ";;; Generated autoloads from " file "\n") | |
211 (goto-char output-end) | |
212 (insert generate-autoload-section-trailer))) | |
213 (message "Generating autoloads for %s...done" file))) | |
2535
86d5500624d5
(update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents:
2494
diff
changeset
|
214 |
473 | 215 (defconst generated-autoload-file "loaddefs.el" |
216 "*File \\[update-file-autoloads] puts autoloads into. | |
217 A .el file can set this in its local variables section to make its | |
218 autoloads go somewhere else.") | |
219 | |
220 ;;;###autoload | |
221 (defun update-file-autoloads (file) | |
222 "Update the autoloads for FILE in `generated-autoload-file' | |
223 \(which FILE might bind in its local variables)." | |
224 (interactive "fUpdate autoloads for file: ") | |
225 (let ((load-name (let ((name (file-name-nondirectory file))) | |
226 (if (string-match "\\.elc?$" name) | |
227 (substring name 0 (match-beginning 0)) | |
228 name))) | |
229 (done nil) | |
230 (existing-buffer (get-file-buffer file))) | |
231 (save-excursion | |
232 ;; We want to get a value for generated-autoload-file from | |
233 ;; the local variables section if it's there. | |
234 (set-buffer (find-file-noselect file)) | |
235 (set-buffer (find-file-noselect generated-autoload-file)) | |
236 (save-excursion | |
237 (save-restriction | |
238 (widen) | |
239 (goto-char (point-min)) | |
240 (while (search-forward generate-autoload-section-header nil t) | |
241 (let ((form (condition-case () | |
242 (read (current-buffer)) | |
243 (end-of-file nil)))) | |
244 (if (string= (nth 2 form) load-name) | |
245 (let ((begin (match-beginning 0)) | |
246 (last-time (nth 4 form)) | |
247 (file-time (nth 5 (file-attributes file)))) | |
248 (if (and (or (null existing-buffer) | |
249 (not (buffer-modified-p existing-buffer))) | |
250 (listp last-time) (= (length last-time) 2) | |
251 (or (> (car last-time) (car file-time)) | |
252 (and (= (car last-time) (car file-time)) | |
253 (>= (nth 1 last-time) | |
254 (nth 1 file-time))))) | |
255 (message "Autoload section for %s is up to date." | |
256 file) | |
257 (search-forward generate-autoload-section-trailer) | |
258 (delete-region begin (point)) | |
259 (generate-file-autoloads file)) | |
260 (setq done t)))))) | |
261 (if done | |
4026
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
262 ;; There was an existing section and we have updated it. |
473 | 263 () |
4026
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
264 (if (save-excursion |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
265 (set-buffer (find-file-noselect file)) |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
266 (save-excursion |
4152
1e1a395e4718
(update-file-autoloads): Go to the beginning of FILE before searching it
Roland McGrath <roland@gnu.org>
parents:
4089
diff
changeset
|
267 (save-restriction |
1e1a395e4718
(update-file-autoloads): Go to the beginning of FILE before searching it
Roland McGrath <roland@gnu.org>
parents:
4089
diff
changeset
|
268 (widen) |
1e1a395e4718
(update-file-autoloads): Go to the beginning of FILE before searching it
Roland McGrath <roland@gnu.org>
parents:
4089
diff
changeset
|
269 (goto-char (point-min)) |
1e1a395e4718
(update-file-autoloads): Go to the beginning of FILE before searching it
Roland McGrath <roland@gnu.org>
parents:
4089
diff
changeset
|
270 (search-forward generate-autoload-cookie nil t)))) |
4026
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
271 ;; There are autoload cookies in FILE. |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
272 ;; Have the user tell us where to put the new section. |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
273 (progn |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
274 (save-window-excursion |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
275 (switch-to-buffer (current-buffer)) |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
276 (with-output-to-temp-buffer "*Help*" |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
277 (princ (substitute-command-keys |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
278 (format "\ |
473 | 279 Move point to where the autoload section |
280 for %s should be inserted. | |
281 Then do \\[exit-recursive-edit]." | |
4026
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
282 file)))) |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
283 (recursive-edit) |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
284 (beginning-of-line)) |
7b72e141f1ad
(update-file-autoloads): Correctly do nothing when there are no cookies.
Roland McGrath <roland@gnu.org>
parents:
4012
diff
changeset
|
285 (generate-file-autoloads file))))) |
2535
86d5500624d5
(update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents:
2494
diff
changeset
|
286 (if (interactive-p) (save-buffer)) |
473 | 287 (if (and (null existing-buffer) |
288 (setq existing-buffer (get-file-buffer file))) | |
289 (kill-buffer existing-buffer))))) | |
290 | |
291 ;;;###autoload | |
292 (defun update-autoloads-here () | |
3774
3b0cb275ca29
(generate-autoload-cookie, update-autoloads-here): Doc fixes.
Roland McGrath <roland@gnu.org>
parents:
2535
diff
changeset
|
293 "\ |
3b0cb275ca29
(generate-autoload-cookie, update-autoloads-here): Doc fixes.
Roland McGrath <roland@gnu.org>
parents:
2535
diff
changeset
|
294 Update sections of the current buffer generated by \\[update-file-autoloads]." |
473 | 295 (interactive) |
296 (let ((generated-autoload-file (buffer-file-name))) | |
297 (save-excursion | |
298 (goto-char (point-min)) | |
299 (while (search-forward generate-autoload-section-header nil t) | |
300 (let* ((form (condition-case () | |
301 (read (current-buffer)) | |
302 (end-of-file nil))) | |
303 (file (nth 3 form))) | |
304 (if (and (stringp file) | |
305 (or (get-file-buffer file) | |
306 (file-exists-p file))) | |
307 () | |
308 (setq file (if (y-or-n-p (format "Library \"%s\" (load \ | |
309 file \"%s\") doesn't exist. Remove its autoload section? " | |
310 (nth 2 form) file)) | |
311 t | |
312 (condition-case () | |
313 (read-file-name (format "Find \"%s\" load file: " | |
314 (nth 2 form)) | |
315 nil nil t) | |
316 (quit nil))))) | |
317 (if file | |
318 (let ((begin (match-beginning 0))) | |
319 (search-forward generate-autoload-section-trailer) | |
320 (delete-region begin (point)))) | |
321 (if (stringp file) | |
322 (generate-file-autoloads file))))))) | |
323 | |
324 ;;;###autoload | |
325 (defun update-directory-autoloads (dir) | |
326 "Run \\[update-file-autoloads] on each .el file in DIR." | |
327 (interactive "DUpdate autoloads for directory: ") | |
328 (mapcar 'update-file-autoloads | |
2535
86d5500624d5
(update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents:
2494
diff
changeset
|
329 (directory-files dir nil "\\.el$")) |
86d5500624d5
(update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents:
2494
diff
changeset
|
330 (if (interactive-p) |
86d5500624d5
(update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents:
2494
diff
changeset
|
331 (save-excursion |
86d5500624d5
(update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents:
2494
diff
changeset
|
332 (set-buffer (find-file-noselect generated-autoload-file)) |
86d5500624d5
(update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents:
2494
diff
changeset
|
333 (save-buffer)))) |
473 | 334 |
335 ;;;###autoload | |
336 (defun batch-update-autoloads () | |
337 "Update the autoloads for the files or directories on the command line. | |
338 Runs \\[update-file-autoloads] on files and \\[update-directory-autoloads] | |
339 on directories. Must be used only with -batch, and kills Emacs on completion. | |
340 Each file will be processed even if an error occurred previously. | |
648 | 341 For example, invoke \"emacs -batch -f batch-update-autoloads *.el\"" |
473 | 342 (if (not noninteractive) |
4012 | 343 (error "batch-update-autoloads is to be used only with -batch")) |
473 | 344 (let ((lost nil) |
345 (args command-line-args-left)) | |
346 (while args | |
347 (catch 'file | |
348 (condition-case lossage | |
349 (if (file-directory-p (expand-file-name (car args))) | |
350 (update-directory-autoloads (car args)) | |
351 (update-file-autoloads (car args))) | |
352 (error (progn (message ">>Error processing %s: %s" | |
353 (car args) lossage) | |
354 (setq lost t) | |
355 (throw 'file nil))))) | |
356 (setq args (cdr args))) | |
357 (save-some-buffers t) | |
358 (message "Done") | |
359 (kill-emacs (if lost 1 0)))) | |
360 | |
361 (provide 'autoload) | |
648 | 362 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
648
diff
changeset
|
363 ;;; autoload.el ends here |