0
|
1 ;;; autoload.el --- maintain autoloads in loaddefs.el.
|
|
2 ;;; Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 ;;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
4 ;;; Copyright (C) 1996 Ben Wing.
|
|
5
|
|
6 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>
|
|
7 ;; Keywords: maint
|
|
8
|
12
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; 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.
|
0
|
15
|
12
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
|
25
|
|
26 ;;; Synched up with: Not synched with FSF.
|
0
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This code helps GNU Emacs maintainers keep the loaddefs.el file up to
|
|
31 ;; date. It interprets magic cookies of the form ";;;###autoload" in
|
|
32 ;; lisp source files in various useful ways. To learn more, read the
|
|
33 ;; source; if you're going to use this, you'd better be able to.
|
|
34
|
|
35 ;;; Code:
|
|
36
|
|
37 (defun make-autoload (form file)
|
|
38 "Turn FORM, a defun or defmacro, into an autoload for source file FILE.
|
|
39 Returns nil if FORM is not a defun, define-skeleton or defmacro."
|
|
40 (let ((car (car-safe form)))
|
|
41 (if (memq car '(defun define-skeleton defmacro))
|
|
42 (let ((macrop (eq car 'defmacro))
|
|
43 name doc)
|
|
44 (setq form (cdr form)
|
|
45 name (car form)
|
|
46 ;; Ignore the arguments.
|
|
47 form (cdr (if (eq car 'define-skeleton)
|
|
48 form
|
|
49 (cdr form)))
|
|
50 doc (car form))
|
|
51 (if (stringp doc)
|
|
52 (setq form (cdr form))
|
|
53 (setq doc nil))
|
|
54 (list 'autoload (list 'quote name) file doc
|
|
55 (or (eq car 'define-skeleton)
|
|
56 (eq (car-safe (car form)) 'interactive))
|
|
57 (if macrop (list 'quote 'macro) nil)))
|
|
58 nil)))
|
|
59
|
|
60 (put 'define-skeleton 'doc-string-elt 3)
|
|
61
|
12
|
62 (defvar generate-autoload-cookie ";;;###autoload"
|
0
|
63 "Magic comment indicating the following form should be autoloaded.
|
12
|
64 Used by `update-file-autoloads'. This string should be
|
0
|
65 meaningless to Lisp (e.g., a comment).
|
|
66
|
|
67 This string is used:
|
|
68
|
|
69 ;;;###autoload
|
|
70 \(defun function-to-be-autoloaded () ...)
|
|
71
|
12
|
72 If this string appears alone on a line, the following form will be
|
|
73 read and an autoload made for it. If it is followed by the string
|
|
74 \"immediate\", then the form on the following line will be copied
|
|
75 verbatim. If there is further text on the line, that text will be
|
|
76 copied verbatim to `generated-autoload-file'.")
|
0
|
77
|
12
|
78 (defvar generate-autoload-section-header "\f\n;;;### "
|
0
|
79 "String inserted before the form identifying
|
|
80 the section of autoloads for a file.")
|
|
81
|
12
|
82 (defvar generate-autoload-section-trailer "\n;;;***\n"
|
0
|
83 "String which indicates the end of the section of autoloads for a file.")
|
|
84
|
|
85 ;;; Forms which have doc-strings which should be printed specially.
|
|
86 ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is
|
|
87 ;;; the doc-string in FORM.
|
|
88 ;;;
|
|
89 ;;; There used to be the following note here:
|
|
90 ;;; ;;; Note: defconst and defvar should NOT be marked in this way.
|
|
91 ;;; ;;; We don't want to produce defconsts and defvars that
|
|
92 ;;; ;;; make-docfile can grok, because then it would grok them twice,
|
|
93 ;;; ;;; once in foo.el (where they are given with ;;;###autoload) and
|
|
94 ;;; ;;; once in loaddefs.el.
|
|
95 ;;;
|
|
96 ;;; Counter-note: Yes, they should be marked in this way.
|
|
97 ;;; make-docfile only processes those files that are loaded into the
|
|
98 ;;; dumped Emacs, and those files should never have anything
|
|
99 ;;; autoloaded here. The above-feared problem only occurs with files
|
|
100 ;;; which have autoloaded entries *and* are processed by make-docfile;
|
|
101 ;;; there should be no such files.
|
|
102
|
|
103 (put 'autoload 'doc-string-elt 3)
|
|
104 (put 'defun 'doc-string-elt 3)
|
|
105 (put 'defvar 'doc-string-elt 3)
|
|
106 (put 'defconst 'doc-string-elt 3)
|
|
107 (put 'defmacro 'doc-string-elt 3)
|
|
108
|
|
109 (defun autoload-trim-file-name (file)
|
12
|
110 "Returns a relative pathname of FILE including the last directory."
|
0
|
111 (setq file (expand-file-name file))
|
12
|
112 (file-relative-name file (file-name-directory
|
|
113 (directory-file-name
|
|
114 (file-name-directory file)))))
|
0
|
115
|
|
116 ;;;###autoload
|
|
117 (defun generate-file-autoloads (file &optional funlist)
|
|
118 "Insert at point a loaddefs autoload section for FILE.
|
|
119 autoloads are generated for defuns and defmacros in FILE
|
|
120 marked by `generate-autoload-cookie' (which see).
|
|
121 If FILE is being visited in a buffer, the contents of the buffer
|
|
122 are used."
|
|
123 (interactive "fGenerate autoloads for file: ")
|
12
|
124 (generate-file-autoloads-1 file funlist))
|
|
125
|
|
126 (defun* generate-file-autoloads-1 (file funlist)
|
|
127 "Insert at point a loaddefs autoload section for FILE.
|
|
128 autoloads are generated for defuns and defmacros in FILE
|
|
129 marked by `generate-autoload-cookie' (which see).
|
|
130 If FILE is being visited in a buffer, the contents of the buffer
|
|
131 are used."
|
0
|
132 (let ((outbuf (current-buffer))
|
|
133 (autoloads-done '())
|
12
|
134 (load-name (replace-in-string (file-name-nondirectory file)
|
|
135 "\\.elc?$"
|
|
136 ""))
|
|
137 (trim-name (autoload-trim-file-name file))
|
0
|
138 (dofiles (not (null funlist)))
|
|
139 (print-length nil)
|
|
140 (print-readably t) ; XEmacs
|
|
141 (float-output-format nil)
|
12
|
142 ;; (done-any nil)
|
0
|
143 (visited (get-file-buffer file))
|
|
144 output-end)
|
|
145
|
|
146 ;; If the autoload section we create here uses an absolute
|
|
147 ;; pathname for FILE in its header, and then Emacs is installed
|
|
148 ;; under a different path on another system,
|
|
149 ;; `update-autoloads-here' won't be able to find the files to be
|
|
150 ;; autoloaded. So, if FILE is in the same directory or a
|
|
151 ;; subdirectory of the current buffer's directory, we'll make it
|
|
152 ;; relative to the current buffer's directory.
|
|
153 (setq file (expand-file-name file))
|
|
154
|
|
155 (save-excursion
|
|
156 (unwind-protect
|
|
157 (progn
|
12
|
158 (set-buffer (or visited (find-file-noselect file)))
|
0
|
159 (save-excursion
|
|
160 (save-restriction
|
|
161 (widen)
|
|
162 (goto-char (point-min))
|
12
|
163 (unless (search-forward generate-autoload-cookie nil t)
|
|
164 (message "No autoloads found in %s" trim-name)
|
|
165 (return-from generate-file-autoloads-1))
|
|
166
|
|
167 (message "Generating autoloads for %s..." trim-name)
|
|
168 (goto-char (point-min))
|
0
|
169 (while (if dofiles funlist (not (eobp)))
|
|
170 (if (not dofiles)
|
|
171 (skip-chars-forward " \t\n\f")
|
|
172 (goto-char (point-min))
|
|
173 (re-search-forward
|
|
174 (concat "(def\\(un\\|var\\|const\\|macro\\) "
|
|
175 (regexp-quote (symbol-name (car funlist)))
|
|
176 "\\s "))
|
|
177 (goto-char (match-beginning 0)))
|
|
178 (cond
|
|
179 ((or dofiles
|
|
180 (looking-at (regexp-quote generate-autoload-cookie)))
|
|
181 (if dofiles
|
|
182 nil
|
|
183 (search-forward generate-autoload-cookie)
|
|
184 (skip-chars-forward " \t"))
|
12
|
185 ;; (setq done-any t)
|
0
|
186 (if (or dofiles (eolp))
|
|
187 ;; Read the next form and make an autoload.
|
|
188 (let* ((form (prog1 (read (current-buffer))
|
|
189 (or (bolp) (forward-line 1))))
|
|
190 (autoload (make-autoload form load-name))
|
|
191 (doc-string-elt (get (car-safe form)
|
|
192 'doc-string-elt)))
|
|
193 (if autoload
|
|
194 (setq autoloads-done (cons (nth 1 form)
|
|
195 autoloads-done))
|
|
196 (setq autoload form))
|
|
197 (if (and doc-string-elt
|
|
198 (stringp (nth doc-string-elt autoload)))
|
|
199 ;; We need to hack the printing because the
|
|
200 ;; doc-string must be printed specially for
|
|
201 ;; make-docfile (sigh).
|
|
202 (let* ((p (nthcdr (1- doc-string-elt)
|
|
203 autoload))
|
|
204 (elt (cdr p)))
|
|
205 (setcdr p nil)
|
|
206 (princ "\n(" outbuf)
|
|
207 ;; XEmacs change: don't let ^^L's get into
|
|
208 ;; the file or sorting is hard.
|
|
209 (let ((print-escape-newlines t)
|
|
210 (p (save-excursion
|
|
211 (set-buffer outbuf)
|
|
212 (point)))
|
|
213 p2)
|
|
214 (mapcar (function (lambda (elt)
|
|
215 (prin1 elt outbuf)
|
|
216 (princ " " outbuf)))
|
|
217 autoload)
|
|
218 (save-excursion
|
|
219 (set-buffer outbuf)
|
|
220 (setq p2 (point-marker))
|
|
221 (goto-char p)
|
|
222 (save-match-data
|
|
223 (while (search-forward "\^L" p2 t)
|
|
224 (delete-char -1)
|
|
225 (insert "\\^L")))
|
|
226 (goto-char p2)
|
|
227 ))
|
|
228 (princ "\"\\\n" outbuf)
|
|
229 (let ((begin (save-excursion
|
|
230 (set-buffer outbuf)
|
|
231 (point))))
|
|
232 (princ (substring
|
|
233 (prin1-to-string (car elt)) 1)
|
|
234 outbuf)
|
|
235 ;; Insert a backslash before each ( that
|
|
236 ;; appears at the beginning of a line in
|
|
237 ;; the doc string.
|
|
238 (save-excursion
|
|
239 (set-buffer outbuf)
|
|
240 (save-excursion
|
|
241 (while (search-backward "\n(" begin t)
|
|
242 (forward-char 1)
|
|
243 (insert "\\"))))
|
|
244 (if (null (cdr elt))
|
|
245 (princ ")" outbuf)
|
|
246 (princ " " outbuf)
|
|
247 (princ (substring
|
|
248 (prin1-to-string (cdr elt))
|
|
249 1)
|
|
250 outbuf))
|
|
251 (terpri outbuf)))
|
|
252 ;; XEmacs change: another fucking ^L hack
|
|
253 (let ((p (save-excursion
|
|
254 (set-buffer outbuf)
|
|
255 (point)))
|
|
256 (print-escape-newlines t)
|
|
257 p2)
|
|
258 (print autoload outbuf)
|
|
259 (save-excursion
|
|
260 (set-buffer outbuf)
|
|
261 (setq p2 (point-marker))
|
|
262 (goto-char p)
|
|
263 (save-match-data
|
|
264 (while (search-forward "\^L" p2 t)
|
|
265 (delete-char -1)
|
|
266 (insert "\\^L")))
|
|
267 (goto-char p2)
|
|
268 ))
|
|
269 ))
|
|
270 ;; Copy the rest of the line to the output.
|
|
271 (let ((begin (point)))
|
|
272 (terpri outbuf)
|
|
273 (cond ((looking-at "immediate\\s *$") ; XEmacs
|
|
274 ;; This is here so that you can automatically
|
|
275 ;; have small hook functions copied to
|
|
276 ;; loaddefs.el so that it's not necessary to
|
|
277 ;; load a whole file just to get a two-line
|
|
278 ;; do-nothing find-file-hook... --Stig
|
|
279 (forward-line 1)
|
|
280 (setq begin (point))
|
|
281 (forward-sexp)
|
|
282 (forward-line 1))
|
|
283 (t
|
|
284 (forward-line 1)))
|
|
285 (princ (buffer-substring begin (point)) outbuf))))
|
|
286 ((looking-at ";")
|
|
287 ;; Don't read the comment.
|
|
288 (forward-line 1))
|
|
289 (t
|
|
290 (forward-sexp 1)
|
|
291 (forward-line 1)))
|
|
292 (if dofiles
|
|
293 (setq funlist (cdr funlist)))))))
|
12
|
294 (unless visited
|
0
|
295 ;; We created this buffer, so we should kill it.
|
|
296 (kill-buffer (current-buffer)))
|
|
297 (set-buffer outbuf)
|
|
298 (setq output-end (point-marker))))
|
|
299 (if t ;; done-any
|
|
300 ;; XEmacs -- always do this so that we cache the information
|
|
301 ;; that we've processed the file already.
|
|
302 (progn
|
|
303 (insert generate-autoload-section-header)
|
12
|
304 (prin1 (list 'autoloads autoloads-done load-name trim-name)
|
0
|
305 outbuf)
|
|
306 (terpri outbuf)
|
12
|
307 ;;;; (insert ";;; Generated autoloads from "
|
|
308 ;;;; (autoload-trim-file-name file) "\n")
|
0
|
309 ;; Warn if we put a line in loaddefs.el
|
|
310 ;; that is long enough to cause trouble.
|
12
|
311 (when (< output-end (point))
|
|
312 (setq output-end (point-marker)))
|
0
|
313 (while (< (point) output-end)
|
|
314 (let ((beg (point)))
|
|
315 (end-of-line)
|
|
316 (if (> (- (point) beg) 900)
|
|
317 (progn
|
|
318 (message "A line is too long--over 900 characters")
|
|
319 (sleep-for 2)
|
|
320 (goto-char output-end))))
|
|
321 (forward-line 1))
|
|
322 (goto-char output-end)
|
|
323 (insert generate-autoload-section-trailer)))
|
|
324 (or noninteractive ; XEmacs: only need one line in -batch mode.
|
|
325 (message "Generating autoloads for %s...done" file))))
|
12
|
326
|
0
|
327
|
12
|
328 (defvar generated-autoload-file
|
|
329 (expand-file-name "../lisp/prim/auto-autoloads.el" data-directory)
|
|
330 "*File `update-file-autoloads' puts autoloads into.
|
0
|
331 A .el file can set this in its local variables section to make its
|
|
332 autoloads go somewhere else.")
|
|
333
|
|
334 ;;;###autoload
|
|
335 (defun update-file-autoloads (file)
|
|
336 "Update the autoloads for FILE in `generated-autoload-file'
|
|
337 \(which FILE might bind in its local variables)."
|
|
338 (interactive "fUpdate autoloads for file: ")
|
12
|
339 (setq file (expand-file-name file))
|
|
340 (let ((load-name (replace-in-string (file-name-nondirectory file)
|
|
341 "\\.elc?$"
|
|
342 ""))
|
0
|
343 (trim-name (autoload-trim-file-name file))
|
12
|
344 section-begin form)
|
0
|
345 (save-excursion
|
|
346 (set-buffer (or (get-file-buffer generated-autoload-file)
|
|
347 (find-file-noselect generated-autoload-file)))
|
12
|
348 ;; First delete all sections for this file.
|
|
349 (goto-char (point-min))
|
|
350 (while (search-forward generate-autoload-section-header nil t)
|
|
351 (setq section-begin (match-beginning 0))
|
|
352 (setq form (read (current-buffer)))
|
|
353 (when (string= (nth 2 form) load-name)
|
|
354 (search-forward generate-autoload-section-trailer)
|
|
355 (delete-region section-begin (point))))
|
|
356
|
|
357 ;; Now find insertion point for new section
|
|
358 (block find-insertion-point
|
|
359 (goto-char (point-min))
|
|
360 (while (search-forward generate-autoload-section-header nil t)
|
|
361 (setq form (read (current-buffer)))
|
|
362 (when (string< trim-name (nth 3 form))
|
|
363 ;; Found alphabetically correct insertion point
|
|
364 (goto-char (match-beginning 0))
|
|
365 (return-from find-insertion-point))
|
|
366 (search-forward generate-autoload-section-trailer))
|
|
367 (when (eq (point) (point-min)) ; No existing entries?
|
|
368 (goto-char (point-max)))) ; Append.
|
|
369
|
|
370 ;; Add in new sections for file
|
|
371 (generate-file-autoloads file))
|
|
372
|
|
373 (when (interactive-p) (save-buffer))))
|
0
|
374
|
|
375 ;;;###autoload
|
|
376 (defun update-autoloads-here ()
|
12
|
377 "Update sections of the current buffer generated by `update-file-autoloads'."
|
0
|
378 (interactive)
|
|
379 (let ((generated-autoload-file (buffer-file-name)))
|
|
380 (save-excursion
|
|
381 (goto-char (point-min))
|
|
382 (while (search-forward generate-autoload-section-header nil t)
|
|
383 (let* ((form (condition-case ()
|
|
384 (read (current-buffer))
|
|
385 (end-of-file nil)))
|
|
386 (file (nth 3 form)))
|
|
387 ;; XEmacs change: if we can't find the file as specified, look
|
|
388 ;; around a bit more.
|
|
389 (cond ((and (stringp file)
|
|
390 (or (get-file-buffer file)
|
|
391 (file-exists-p file))))
|
|
392 ((and (stringp file)
|
|
393 (save-match-data
|
|
394 (let ((loc (locate-file (file-name-nondirectory file)
|
|
395 load-path)))
|
|
396 (if (null loc)
|
|
397 nil
|
|
398 (setq loc (expand-file-name
|
|
399 (autoload-trim-file-name loc)
|
|
400 ".."))
|
|
401 (if (or (get-file-buffer loc)
|
|
402 (file-exists-p loc))
|
|
403 (setq file loc)
|
|
404 nil))))))
|
|
405 (t
|
12
|
406 (setq file
|
|
407 (if (y-or-n-p
|
|
408 (format
|
|
409 "Can't find library `%s'; remove its autoloads? "
|
|
410 (nth 2 form) file))
|
|
411 t
|
|
412 (condition-case ()
|
|
413 (read-file-name
|
|
414 (format "Find `%s' load file: "
|
|
415 (nth 2 form))
|
|
416 nil nil t)
|
|
417 (quit nil))))))
|
0
|
418 (if file
|
|
419 (let ((begin (match-beginning 0)))
|
|
420 (search-forward generate-autoload-section-trailer)
|
|
421 (delete-region begin (point))))
|
|
422 (if (stringp file)
|
|
423 (generate-file-autoloads file)))))))
|
|
424
|
|
425 ;;;###autoload
|
12
|
426 (defun update-autoloads-from-directory (dir)
|
|
427 "Update `generated-autoload-file' with all the current autoloads from DIR.
|
|
428 This runs `update-file-autoloads' on each .el file in DIR.
|
|
429 Obsolete autoload entries for files that no longer exist are deleted."
|
0
|
430 (interactive "DUpdate autoloads for directory: ")
|
12
|
431 (setq dir (expand-file-name dir))
|
|
432 (let ((simple-dir (file-name-as-directory
|
|
433 (file-name-nondirectory
|
|
434 (directory-file-name dir))))
|
|
435 (enable-local-eval nil))
|
|
436 (save-excursion
|
|
437 (set-buffer (find-file-noselect generated-autoload-file))
|
|
438 (goto-char (point-min))
|
|
439 (while (search-forward generate-autoload-section-header nil t)
|
|
440 (let* ((begin (match-beginning 0))
|
|
441 (form (condition-case ()
|
|
442 (read (current-buffer))
|
|
443 (end-of-file nil)))
|
|
444 (file (nth 3 form)))
|
|
445 (when (and (stringp file)
|
|
446 (string= (file-name-directory file) simple-dir)
|
|
447 (not (file-exists-p
|
|
448 (expand-file-name
|
|
449 (file-name-nondirectory file) dir))))
|
|
450 ;; Remove the obsolete section.
|
|
451 (search-forward generate-autoload-section-trailer)
|
|
452 (delete-region begin (point)))))
|
|
453 ;; Update or create autoload sections for existing files.
|
|
454 (mapcar 'update-file-autoloads (directory-files dir t "^[^=].*\\.el$"))
|
|
455 (unless noninteractive
|
|
456 (save-buffer)))))
|
0
|
457
|
|
458 ;;;###autoload
|
|
459 (defun batch-update-autoloads ()
|
|
460 "Update the autoloads for the files or directories on the command line.
|
12
|
461 Runs `update-file-autoloads' on files and `update-directory-autoloads'
|
0
|
462 on directories. Must be used only with -batch, and kills Emacs on completion.
|
|
463 Each file will be processed even if an error occurred previously.
|
12
|
464 For example, invoke `xemacs -batch -f batch-update-autoloads *.el'."
|
|
465 (unless noninteractive
|
|
466 (error "batch-update-autoloads is to be used only with -batch"))
|
|
467 (let ((defdir default-directory)
|
|
468 (enable-local-eval nil)) ; Don't query in batch mode.
|
0
|
469 (message "Updating autoloads in %s..." generated-autoload-file)
|
12
|
470 (dolist (arg command-line-args-left)
|
|
471 (setq arg (expand-file-name arg defdir))
|
|
472 (cond
|
|
473 ((file-directory-p arg)
|
|
474 (message "Updating autoloads for directory %s..." arg)
|
|
475 (update-autoloads-from-directory arg))
|
|
476 ((file-exists-p arg)
|
|
477 (update-file-autoloads arg))
|
|
478 (t (error "No such file or directory: %s" arg))))
|
0
|
479 (save-some-buffers t)
|
|
480 (message "Done")
|
12
|
481 (kill-emacs 0)))
|
0
|
482
|
|
483 (provide 'autoload)
|
|
484
|
|
485 ;;; autoload.el ends here
|