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