Commit | Line | Data |
---|---|---|
56eebc29 | 1 | ;; autoload.el --- maintain autoloads in loaddefs.el |
c0274f38 | 2 | |
b7a45ee1 | 3 | ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003, |
f0fa15c5 | 4 | ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
b578f267 | 5 | |
5762abec | 6 | ;; Author: Roland McGrath <roland@gnu.org> |
e9571d2a | 7 | ;; Keywords: maint |
e5167999 | 8 | |
b578f267 EN |
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 2, or (at your option) | |
14 | ;; 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; see the file COPYING. If not, write to the | |
3a35cf56 LK |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | ;; Boston, MA 02110-1301, USA. | |
0231f2dc | 25 | |
07b3798c | 26 | ;;; Commentary: |
e41b2db1 | 27 | |
00ee57f3 | 28 | ;; This code helps GNU Emacs maintainers keep the loaddefs.el file up to |
e41b2db1 ER |
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. | |
32 | ||
e5167999 ER |
33 | ;;; Code: |
34 | ||
b0daab9a | 35 | (require 'lisp-mode) ;for `doc-string-elt' properties. |
890df022 | 36 | (require 'help-fns) ;for help-add-fundoc-usage. |
6826a134 | 37 | (eval-when-compile (require 'cl)) |
b0daab9a | 38 | |
0ceb5fe0 RS |
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 | |
c8aca7d1 KH |
42 | autoloads go somewhere else. The autoload file is assumed to contain a |
43 | trailer starting with a FormFeed character.") | |
0ceb5fe0 RS |
44 | |
45 | (defconst generate-autoload-cookie ";;;###autoload" | |
46 | "Magic comment indicating the following form should be autoloaded. | |
47 | Used by \\[update-file-autoloads]. This string should be | |
48 | meaningless to Lisp (e.g., a comment). | |
49 | ||
50 | This string is used: | |
51 | ||
52 | ;;;###autoload | |
53 | \(defun function-to-be-autoloaded () ...) | |
54 | ||
55 | If this string appears alone on a line, the following form will be | |
56 | read and an autoload made for it. If there is further text on the line, | |
57 | that text will be copied verbatim to `generated-autoload-file'.") | |
58 | ||
59 | (defconst generate-autoload-section-header "\f\n;;;### " | |
2336b6a9 | 60 | "String that marks the form at the start of a new file's autoload section.") |
0ceb5fe0 RS |
61 | |
62 | (defconst generate-autoload-section-trailer "\n;;;***\n" | |
63 | "String which indicates the end of the section of autoloads for a file.") | |
64 | ||
2336b6a9 KH |
65 | (defconst generate-autoload-section-continuation ";;;;;; " |
66 | "String to add on each continuation of the section header form.") | |
67 | ||
0231f2dc | 68 | (defun make-autoload (form file) |
ceaa3695 | 69 | "Turn FORM into an autoload or defvar for source file FILE. |
e8139c11 SM |
70 | Returns nil if FORM is not a special autoload form (i.e. a function definition |
71 | or macro definition or a defcustom)." | |
72 | (let ((car (car-safe form)) expand) | |
73 | (cond | |
74 | ;; For complex cases, try again on the macro-expansion. | |
1b39b493 | 75 | ((and (memq car '(easy-mmode-define-global-mode define-global-minor-mode |
32324290 | 76 | define-globalized-minor-mode |
e8139c11 SM |
77 | easy-mmode-define-minor-mode define-minor-mode)) |
78 | (setq expand (let ((load-file-name file)) (macroexpand form))) | |
79 | (eq (car expand) 'progn) | |
80 | (memq :autoload-end expand)) | |
81 | (let ((end (memq :autoload-end expand))) | |
82 | ;; Cut-off anything after the :autoload-end marker. | |
83 | (setcdr end nil) | |
84 | (cons 'progn | |
85 | (mapcar (lambda (form) (make-autoload form file)) | |
86 | (cdr expand))))) | |
87 | ||
88 | ;; For special function-like operators, use the `autoload' function. | |
89 | ((memq car '(defun define-skeleton defmacro define-derived-mode | |
c6a3142d JL |
90 | define-compilation-mode define-generic-mode |
91 | easy-mmode-define-global-mode define-global-minor-mode | |
32324290 | 92 | define-globalized-minor-mode |
c6a3142d JL |
93 | easy-mmode-define-minor-mode define-minor-mode |
94 | defun* defmacro*)) | |
74312ddc | 95 | (let* ((macrop (memq car '(defmacro defmacro*))) |
e8139c11 | 96 | (name (nth 1 form)) |
6826a134 SM |
97 | (args (case car |
98 | ((defun defmacro defun* defmacro*) (nth 2 form)) | |
99 | ((define-skeleton) '(&optional str arg)) | |
bec34fb0 TTN |
100 | ((define-generic-mode define-derived-mode |
101 | define-compilation-mode) nil) | |
6826a134 | 102 | (t))) |
e8139c11 SM |
103 | (body (nthcdr (get car 'doc-string-elt) form)) |
104 | (doc (if (stringp (car body)) (pop body)))) | |
890df022 SM |
105 | (when (listp args) |
106 | ;; Add the usage form at the end where describe-function-1 | |
107 | ;; can recover it. | |
108 | (setq doc (help-add-fundoc-usage doc args))) | |
e8139c11 SM |
109 | ;; `define-generic-mode' quotes the name, so take care of that |
110 | (list 'autoload (if (listp name) name (list 'quote name)) file doc | |
111 | (or (and (memq car '(define-skeleton define-derived-mode | |
112 | define-generic-mode | |
113 | easy-mmode-define-global-mode | |
c6a3142d | 114 | define-global-minor-mode |
32324290 | 115 | define-globalized-minor-mode |
e8139c11 SM |
116 | easy-mmode-define-minor-mode |
117 | define-minor-mode)) t) | |
118 | (eq (car-safe (car body)) 'interactive)) | |
119 | (if macrop (list 'quote 'macro) nil)))) | |
120 | ||
d49298d9 | 121 | ;; Convert defcustom to less space-consuming data. |
e8139c11 SM |
122 | ((eq car 'defcustom) |
123 | (let ((varname (car-safe (cdr-safe form))) | |
124 | (init (car-safe (cdr-safe (cdr-safe form)))) | |
125 | (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form))))) | |
d49298d9 MR |
126 | ;; (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form))))) |
127 | ) | |
128 | `(progn | |
129 | (defvar ,varname ,init ,doc) | |
fb2dd970 SM |
130 | (custom-autoload ',varname ,file |
131 | ,(condition-case nil | |
132 | (null (cadr (memq :set form))) | |
133 | (error nil)))))) | |
e8139c11 | 134 | |
1bddeeed SM |
135 | ((eq car 'defgroup) |
136 | ;; In Emacs this is normally handled separately by cus-dep.el, but for | |
137 | ;; third party packages, it can be convenient to explicitly autoload | |
138 | ;; a group. | |
139 | (let ((groupname (nth 1 form))) | |
140 | `(let ((loads (get ',groupname 'custom-loads))) | |
141 | (if (member ',file loads) nil | |
142 | (put ',groupname 'custom-loads (cons ',file loads)))))) | |
143 | ||
e8139c11 SM |
144 | ;; nil here indicates that this is not a special autoload form. |
145 | (t nil)))) | |
0231f2dc | 146 | |
890df022 SM |
147 | ;; Forms which have doc-strings which should be printed specially. |
148 | ;; A doc-string-elt property of ELT says that (nth ELT FORM) is | |
149 | ;; the doc-string in FORM. | |
150 | ;; Those properties are now set in lisp-mode.el. | |
fc89daee | 151 | |
0231f2dc | 152 | |
72c19d97 | 153 | (defun autoload-trim-file-name (file) |
8d3e5475 | 154 | ;; Returns a relative file path for FILE |
1eb0a345 RS |
155 | ;; starting from the directory that loaddefs.el is in. |
156 | ;; That is normally a directory in load-path, | |
157 | ;; which means Emacs will be able to find FILE when it looks. | |
158 | ;; Any extra directory names here would prevent finding the file. | |
72c19d97 RM |
159 | (setq file (expand-file-name file)) |
160 | (file-relative-name file | |
1eb0a345 | 161 | (file-name-directory generated-autoload-file))) |
72c19d97 | 162 | |
2336b6a9 KH |
163 | (defun autoload-read-section-header () |
164 | "Read a section header form. | |
165 | Since continuation lines have been marked as comments, | |
166 | we must copy the text of the form and remove those comment | |
167 | markers before we call `read'." | |
168 | (save-match-data | |
169 | (let ((beginning (point)) | |
170 | string) | |
171 | (forward-line 1) | |
172 | (while (looking-at generate-autoload-section-continuation) | |
173 | (forward-line 1)) | |
174 | (setq string (buffer-substring beginning (point))) | |
175 | (with-current-buffer (get-buffer-create " *autoload*") | |
176 | (erase-buffer) | |
177 | (insert string) | |
178 | (goto-char (point-min)) | |
179 | (while (search-forward generate-autoload-section-continuation nil t) | |
180 | (replace-match " ")) | |
181 | (goto-char (point-min)) | |
182 | (read (current-buffer)))))) | |
183 | ||
ac644d50 JB |
184 | (defvar autoload-print-form-outbuf nil |
185 | "Buffer which gets the output of `autoload-print-form'.") | |
4a3c5b3a | 186 | |
a8add29d | 187 | (defun autoload-print-form (form) |
4a3c5b3a RS |
188 | "Print FORM such that `make-docfile' will find the docstrings. |
189 | The variable `autoload-print-form-outbuf' specifies the buffer to | |
190 | put the output in." | |
a8add29d SM |
191 | (cond |
192 | ;; If the form is a sequence, recurse. | |
193 | ((eq (car form) 'progn) (mapcar 'autoload-print-form (cdr form))) | |
194 | ;; Symbols at the toplevel are meaningless. | |
195 | ((symbolp form) nil) | |
196 | (t | |
4a3c5b3a RS |
197 | (let ((doc-string-elt (get (car-safe form) 'doc-string-elt)) |
198 | (outbuf autoload-print-form-outbuf)) | |
a8add29d SM |
199 | (if (and doc-string-elt (stringp (nth doc-string-elt form))) |
200 | ;; We need to hack the printing because the | |
201 | ;; doc-string must be printed specially for | |
202 | ;; make-docfile (sigh). | |
203 | (let* ((p (nthcdr (1- doc-string-elt) form)) | |
204 | (elt (cdr p))) | |
205 | (setcdr p nil) | |
206 | (princ "\n(" outbuf) | |
207 | (let ((print-escape-newlines t) | |
208 | (print-escape-nonascii t)) | |
7dab57b6 RS |
209 | (dolist (elt form) |
210 | (prin1 elt outbuf) | |
211 | (princ " " outbuf))) | |
a8add29d SM |
212 | (princ "\"\\\n" outbuf) |
213 | (let ((begin (with-current-buffer outbuf (point)))) | |
214 | (princ (substring (prin1-to-string (car elt)) 1) | |
215 | outbuf) | |
216 | ;; Insert a backslash before each ( that | |
217 | ;; appears at the beginning of a line in | |
218 | ;; the doc string. | |
219 | (with-current-buffer outbuf | |
220 | (save-excursion | |
890df022 | 221 | (while (re-search-backward "\n[[(]" begin t) |
a8add29d SM |
222 | (forward-char 1) |
223 | (insert "\\")))) | |
224 | (if (null (cdr elt)) | |
225 | (princ ")" outbuf) | |
226 | (princ " " outbuf) | |
227 | (princ (substring (prin1-to-string (cdr elt)) 1) | |
228 | outbuf)) | |
229 | (terpri outbuf))) | |
230 | (let ((print-escape-newlines t) | |
231 | (print-escape-nonascii t)) | |
232 | (print form outbuf))))))) | |
233 | ||
a273d3e0 GM |
234 | (defun autoload-ensure-default-file (file) |
235 | "Make sure that the autoload file FILE exists and if not create it." | |
236 | (unless (file-exists-p file) | |
237 | (write-region | |
238 | (concat ";;; " (file-name-nondirectory file) | |
239 | " --- automatically extracted autoloads\n" | |
240 | ";;\n" | |
241 | ";;; Code:\n\n" | |
242 | "\f\n;; Local Variables:\n" | |
243 | ";; version-control: never\n" | |
244 | ";; no-byte-compile: t\n" | |
245 | ";; no-update-autoloads: t\n" | |
246 | ";; End:\n" | |
247 | ";;; " (file-name-nondirectory file) | |
4994a50d | 248 | " ends here\n") |
a273d3e0 GM |
249 | nil file)) |
250 | file) | |
251 | ||
252 | (defun autoload-insert-section-header (outbuf autoloads load-name file time) | |
253 | "Insert the section-header line, | |
254 | which lists the file name and which functions are in it, etc." | |
255 | (insert generate-autoload-section-header) | |
256 | (prin1 (list 'autoloads autoloads load-name | |
257 | (if (stringp file) (autoload-trim-file-name file) file) | |
258 | time) | |
259 | outbuf) | |
260 | (terpri outbuf) | |
261 | ;; Break that line at spaces, to avoid very long lines. | |
262 | ;; Make each sub-line into a comment. | |
263 | (with-current-buffer outbuf | |
264 | (save-excursion | |
265 | (forward-line -1) | |
266 | (while (not (eolp)) | |
267 | (move-to-column 64) | |
268 | (skip-chars-forward "^ \n") | |
269 | (or (eolp) | |
270 | (insert "\n" generate-autoload-section-continuation)))))) | |
271 | ||
69135525 SM |
272 | (defun autoload-find-file (file) |
273 | "Fetch file and put it in a temp buffer. Return the buffer." | |
274 | ;; It is faster to avoid visiting the file. | |
275 | (with-current-buffer (get-buffer-create " *autoload-file*") | |
276 | (kill-all-local-variables) | |
277 | (erase-buffer) | |
278 | (setq buffer-undo-list t | |
279 | buffer-read-only nil) | |
280 | (emacs-lisp-mode) | |
281 | (insert-file-contents file nil) | |
282 | (let ((enable-local-variables :safe)) | |
283 | (hack-local-variables)) | |
284 | (current-buffer))) | |
285 | ||
b17b8839 SM |
286 | (defvar no-update-autoloads nil |
287 | "File local variable to prevent scanning this file for autoload cookies.") | |
288 | ||
0231f2dc JB |
289 | (defun generate-file-autoloads (file) |
290 | "Insert at point a loaddefs autoload section for FILE. | |
b17b8839 | 291 | Autoloads are generated for defuns and defmacros in FILE |
da8826b4 | 292 | marked by `generate-autoload-cookie' (which see). |
0231f2dc | 293 | If FILE is being visited in a buffer, the contents of the buffer |
b17b8839 SM |
294 | are used. |
295 | Return non-nil in the case where no autoloads were added at point." | |
0231f2dc JB |
296 | (interactive "fGenerate autoloads for file: ") |
297 | (let ((outbuf (current-buffer)) | |
0231f2dc JB |
298 | (autoloads-done '()) |
299 | (load-name (let ((name (file-name-nondirectory file))) | |
a85e4d58 | 300 | (if (string-match "\\.elc?\\(\\.\\|$\\)" name) |
0231f2dc JB |
301 | (substring name 0 (match-beginning 0)) |
302 | name))) | |
303 | (print-length nil) | |
72c19d97 | 304 | (print-readably t) ; This does something in Lucid Emacs. |
aa7ea8bd | 305 | (float-output-format nil) |
0231f2dc | 306 | (done-any nil) |
7e4263eb | 307 | (visited (get-file-buffer file)) |
b17b8839 | 308 | output-start) |
daa37602 JB |
309 | |
310 | ;; If the autoload section we create here uses an absolute | |
8d3e5475 | 311 | ;; file name for FILE in its header, and then Emacs is installed |
daa37602 JB |
312 | ;; under a different path on another system, |
313 | ;; `update-autoloads-here' won't be able to find the files to be | |
314 | ;; autoloaded. So, if FILE is in the same directory or a | |
e5d77022 | 315 | ;; subdirectory of the current buffer's directory, we'll make it |
daa37602 JB |
316 | ;; relative to the current buffer's directory. |
317 | (setq file (expand-file-name file)) | |
1265394f RM |
318 | (let* ((source-truename (file-truename file)) |
319 | (dir-truename (file-name-as-directory | |
320 | (file-truename default-directory))) | |
321 | (len (length dir-truename))) | |
322 | (if (and (< len (length source-truename)) | |
323 | (string= dir-truename (substring source-truename 0 len))) | |
324 | (setq file (substring source-truename len)))) | |
daa37602 | 325 | |
b17b8839 SM |
326 | (with-current-buffer (or visited |
327 | ;; It is faster to avoid visiting the file. | |
328 | (autoload-find-file file)) | |
329 | ;; Obey the no-update-autoloads file local variable. | |
330 | (unless no-update-autoloads | |
331 | (message "Generating autoloads for %s..." file) | |
332 | (setq output-start (with-current-buffer outbuf (point))) | |
333 | (save-excursion | |
334 | (save-restriction | |
335 | (widen) | |
336 | (goto-char (point-min)) | |
337 | (while (not (eobp)) | |
338 | (skip-chars-forward " \t\n\f") | |
339 | (cond | |
340 | ((looking-at (regexp-quote generate-autoload-cookie)) | |
341 | (search-forward generate-autoload-cookie) | |
342 | (skip-chars-forward " \t") | |
343 | (setq done-any t) | |
344 | (if (eolp) | |
345 | ;; Read the next form and make an autoload. | |
346 | (let* ((form (prog1 (read (current-buffer)) | |
347 | (or (bolp) (forward-line 1)))) | |
348 | (autoload (make-autoload form load-name))) | |
349 | (if autoload | |
350 | (push (nth 1 form) autoloads-done) | |
351 | (setq autoload form)) | |
352 | (let ((autoload-print-form-outbuf outbuf)) | |
353 | (autoload-print-form autoload))) | |
354 | ||
355 | ;; Copy the rest of the line to the output. | |
356 | (princ (buffer-substring | |
357 | (progn | |
358 | ;; Back up over whitespace, to preserve it. | |
359 | (skip-chars-backward " \f\t") | |
360 | (if (= (char-after (1+ (point))) ? ) | |
361 | ;; Eat one space. | |
362 | (forward-char 1)) | |
363 | (point)) | |
364 | (progn (forward-line 1) (point))) | |
365 | outbuf))) | |
366 | ((looking-at ";") | |
367 | ;; Don't read the comment. | |
368 | (forward-line 1)) | |
369 | (t | |
370 | (forward-sexp 1) | |
371 | (forward-line 1)))))) | |
372 | ||
373 | (when done-any | |
374 | (with-current-buffer outbuf | |
375 | (save-excursion | |
376 | ;; Insert the section-header line which lists the file name | |
377 | ;; and which functions are in it, etc. | |
378 | (goto-char output-start) | |
379 | (autoload-insert-section-header | |
380 | outbuf autoloads-done load-name file | |
381 | (nth 5 (file-attributes file))) | |
382 | (insert ";;; Generated autoloads from " | |
383 | (autoload-trim-file-name file) "\n")) | |
384 | (insert generate-autoload-section-trailer))) | |
385 | (message "Generating autoloads for %s...done" file)) | |
386 | (or visited | |
387 | ;; We created this buffer, so we should kill it. | |
388 | (kill-buffer (current-buffer)))) | |
389 | (not done-any))) | |
e2b6138f | 390 | \f |
0231f2dc | 391 | ;;;###autoload |
f7ed02ac | 392 | (defun update-file-autoloads (file &optional save-after) |
0231f2dc | 393 | "Update the autoloads for FILE in `generated-autoload-file' |
a273d3e0 | 394 | \(which FILE might bind in its local variables). |
f7ed02ac RS |
395 | If SAVE-AFTER is non-nil (which is always, when called interactively), |
396 | save the buffer too. | |
397 | ||
398 | Return FILE if there was no autoload cookie in it, else nil." | |
399 | (interactive "fUpdate autoloads for file: \np") | |
0231f2dc | 400 | (let ((load-name (let ((name (file-name-nondirectory file))) |
a85e4d58 | 401 | (if (string-match "\\.elc?\\(\\.\\|$\\)" name) |
0231f2dc JB |
402 | (substring name 0 (match-beginning 0)) |
403 | name))) | |
d55e3ff0 | 404 | (found nil) |
a273d3e0 GM |
405 | (existing-buffer (get-file-buffer file)) |
406 | (no-autoloads nil)) | |
0231f2dc JB |
407 | (save-excursion |
408 | ;; We want to get a value for generated-autoload-file from | |
409 | ;; the local variables section if it's there. | |
b59c7256 RM |
410 | (if existing-buffer |
411 | (set-buffer existing-buffer)) | |
9e3366e4 EZ |
412 | ;; We must read/write the file without any code conversion, |
413 | ;; but still decode EOLs. | |
414 | (let ((coding-system-for-read 'raw-text)) | |
68521d61 | 415 | (set-buffer (find-file-noselect |
a273d3e0 GM |
416 | (autoload-ensure-default-file |
417 | (expand-file-name generated-autoload-file | |
418 | (expand-file-name "lisp" | |
419 | source-directory))))) | |
9e3366e4 EZ |
420 | ;; This is to make generated-autoload-file have Unix EOLs, so |
421 | ;; that it is portable to all platforms. | |
422 | (setq buffer-file-coding-system 'raw-text-unix)) | |
0b33ec46 RS |
423 | (or (> (buffer-size) 0) |
424 | (error "Autoloads file %s does not exist" buffer-file-name)) | |
425 | (or (file-writable-p buffer-file-name) | |
426 | (error "Autoloads file %s is not writable" buffer-file-name)) | |
0231f2dc JB |
427 | (save-excursion |
428 | (save-restriction | |
429 | (widen) | |
430 | (goto-char (point-min)) | |
d55e3ff0 RM |
431 | ;; Look for the section for LOAD-NAME. |
432 | (while (and (not found) | |
433 | (search-forward generate-autoload-section-header nil t)) | |
2336b6a9 | 434 | (let ((form (autoload-read-section-header))) |
d55e3ff0 RM |
435 | (cond ((string= (nth 2 form) load-name) |
436 | ;; We found the section for this file. | |
437 | ;; Check if it is up to date. | |
438 | (let ((begin (match-beginning 0)) | |
439 | (last-time (nth 4 form)) | |
440 | (file-time (nth 5 (file-attributes file)))) | |
441 | (if (and (or (null existing-buffer) | |
442 | (not (buffer-modified-p existing-buffer))) | |
443 | (listp last-time) (= (length last-time) 2) | |
66dc9a0f | 444 | (not (time-less-p last-time file-time))) |
d55e3ff0 | 445 | (progn |
d5aa62ec RM |
446 | (if (interactive-p) |
447 | (message "\ | |
448 | Autoload section for %s is up to date." | |
449 | file)) | |
d55e3ff0 RM |
450 | (setq found 'up-to-date)) |
451 | (search-forward generate-autoload-section-trailer) | |
452 | (delete-region begin (point)) | |
453 | (setq found t)))) | |
454 | ((string< load-name (nth 2 form)) | |
455 | ;; We've come to a section alphabetically later than | |
456 | ;; LOAD-NAME. We assume the file is in order and so | |
457 | ;; there must be no section for LOAD-NAME. We will | |
458 | ;; insert one before the section here. | |
459 | (goto-char (match-beginning 0)) | |
72c19d97 | 460 | (setq found 'new))))) |
0f09bac6 RM |
461 | (or found |
462 | (progn | |
463 | (setq found 'new) | |
464 | ;; No later sections in the file. Put before the last page. | |
465 | (goto-char (point-max)) | |
5a161ab5 | 466 | (search-backward "\f" nil t))) |
72c19d97 | 467 | (or (eq found 'up-to-date) |
b17b8839 | 468 | (setq no-autoloads (generate-file-autoloads file))))) |
f7ed02ac | 469 | (and save-after |
2336b6a9 | 470 | (buffer-modified-p) |
a273d3e0 GM |
471 | (save-buffer)) |
472 | ||
473 | (if no-autoloads file)))) | |
474 | ||
a273d3e0 GM |
475 | (defun autoload-remove-section (begin) |
476 | (goto-char begin) | |
477 | (search-forward generate-autoload-section-trailer) | |
478 | (delete-region begin (point))) | |
0231f2dc JB |
479 | |
480 | ;;;###autoload | |
56eebc29 | 481 | (defun update-directory-autoloads (&rest dirs) |
d08589bf | 482 | "\ |
3fbca58a | 483 | Update loaddefs.el with all the current autoloads from DIRS, and no old ones. |
ac644d50 | 484 | This uses `update-file-autoloads' (which see) to do its work. |
56eebc29 RS |
485 | In an interactive call, you must give one argument, the name |
486 | of a single directory. In a call from Lisp, you can supply multiple | |
487 | directories as separate arguments, but this usage is discouraged. | |
488 | ||
489 | The function does NOT recursively descend into subdirectories of the | |
490 | directory or directories specified." | |
b59c7256 | 491 | (interactive "DUpdate autoloads from directory: ") |
a85e4d58 | 492 | (let* ((files-re (let ((tmp nil)) |
de10856c | 493 | (dolist (suf (get-load-suffixes) |
a85e4d58 SM |
494 | (concat "^[^=.].*" (regexp-opt tmp t) "\\'")) |
495 | (unless (string-match "\\.elc" suf) (push suf tmp))))) | |
496 | (files (apply 'nconc | |
a273d3e0 GM |
497 | (mapcar (lambda (dir) |
498 | (directory-files (expand-file-name dir) | |
a85e4d58 | 499 | t files-re)) |
a273d3e0 GM |
500 | dirs))) |
501 | (this-time (current-time)) | |
502 | (no-autoloads nil) ;files with no autoload cookies. | |
503 | (autoloads-file | |
0e193890 | 504 | (expand-file-name generated-autoload-file |
a273d3e0 GM |
505 | (expand-file-name "lisp" source-directory))) |
506 | (top-dir (file-name-directory autoloads-file))) | |
507 | ||
508 | (with-current-buffer | |
509 | (find-file-noselect (autoload-ensure-default-file autoloads-file)) | |
e2b6138f | 510 | (save-excursion |
a273d3e0 GM |
511 | |
512 | ;; Canonicalize file names and remove the autoload file itself. | |
513 | (setq files (delete (autoload-trim-file-name buffer-file-name) | |
514 | (mapcar 'autoload-trim-file-name files))) | |
515 | ||
b59c7256 RM |
516 | (goto-char (point-min)) |
517 | (while (search-forward generate-autoload-section-header nil t) | |
2336b6a9 | 518 | (let* ((form (autoload-read-section-header)) |
b59c7256 | 519 | (file (nth 3 form))) |
a273d3e0 GM |
520 | (cond ((and (consp file) (stringp (car file))) |
521 | ;; This is a list of files that have no autoload cookies. | |
522 | ;; There shouldn't be more than one such entry. | |
523 | ;; Remove the obsolete section. | |
524 | (autoload-remove-section (match-beginning 0)) | |
525 | (let ((last-time (nth 4 form))) | |
526 | (dolist (file file) | |
527 | (let ((file-time (nth 5 (file-attributes file)))) | |
528 | (when (and file-time | |
66dc9a0f | 529 | (not (time-less-p last-time file-time))) |
a273d3e0 GM |
530 | ;; file unchanged |
531 | (push file no-autoloads) | |
532 | (setq files (delete file files))))))) | |
533 | ((not (stringp file))) | |
3fbca58a | 534 | ((not (file-exists-p (expand-file-name file top-dir))) |
b59c7256 | 535 | ;; Remove the obsolete section. |
a273d3e0 GM |
536 | (autoload-remove-section (match-beginning 0))) |
537 | ((equal (nth 4 form) (nth 5 (file-attributes file))) | |
538 | ;; File hasn't changed. | |
539 | nil) | |
b59c7256 RM |
540 | (t |
541 | (update-file-autoloads file))) | |
542 | (setq files (delete file files))))) | |
a273d3e0 GM |
543 | ;; Elements remaining in FILES have no existing autoload sections yet. |
544 | (setq no-autoloads | |
545 | (append no-autoloads | |
546 | (delq nil (mapcar 'update-file-autoloads files)))) | |
547 | (when no-autoloads | |
000d9923 MR |
548 | ;; Sort them for better readability. |
549 | (setq no-autoloads (sort no-autoloads 'string<)) | |
a273d3e0 GM |
550 | ;; Add the `no-autoloads' section. |
551 | (goto-char (point-max)) | |
552 | (search-backward "\f" nil t) | |
553 | (autoload-insert-section-header | |
554 | (current-buffer) nil nil no-autoloads this-time) | |
555 | (insert generate-autoload-section-trailer)) | |
556 | ||
b59c7256 | 557 | (save-buffer)))) |
0231f2dc | 558 | |
1e0888f5 LH |
559 | (define-obsolete-function-alias 'update-autoloads-from-directories |
560 | 'update-directory-autoloads "22.1") | |
561 | ||
0231f2dc JB |
562 | ;;;###autoload |
563 | (defun batch-update-autoloads () | |
b59c7256 | 564 | "Update loaddefs.el autoloads in batch mode. |
375d5635 JPW |
565 | Calls `update-directory-autoloads' on the command line arguments." |
566 | (apply 'update-directory-autoloads command-line-args-left) | |
b59c7256 | 567 | (setq command-line-args-left nil)) |
0231f2dc JB |
568 | |
569 | (provide 'autoload) | |
ffd56f97 | 570 | |
b7a45ee1 | 571 | ;; arch-tag: 00244766-98f4-4767-bf42-8a22103441c6 |
c0274f38 | 572 | ;;; autoload.el ends here |