annotate lisp/emacs-lisp/autoload.el @ 3777:d6f56b9586f7

(make-autoload): Use memq once instead eq twice. (generate-file-autoloads): For non-autoloads, copy the defn textually rather than printing it after reading.
author Roland McGrath <roland@gnu.org>
date Wed, 16 Jun 1993 23:06:58 +0000
parents 3b0cb275ca29
children 21c6c1e1a38b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;;; This program is free software; you can redistribute it and/or modify
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;;; any later version.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;;;
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;;; This program is distributed in the hope that it will be useful,
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;;; GNU General Public License for more details.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;;;
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;;; A copy of the GNU General Public License can be obtained from this
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;;; 02139, USA.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;;;
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 (defun make-autoload (form file)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 "Turn FORM, a defun or defmacro, into an autoload for source file FILE.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 Returns nil if FORM is not a defun or defmacro."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 (setq form (cdr form))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (setq name (car form))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;; Ignore the arguments.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (setq form (cdr (cdr form)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 (setq doc (car form))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 (if (stringp doc)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 (setq form (cdr form))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (setq doc nil))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 nil)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 meaningless to Lisp (e.g., a comment).
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 This string is used:
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 ;;;###autoload
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 \(defun function-to-be-autoloaded () ...)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 If this string appears alone on a line, the following form will be
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 read and an autoload made for it. If there is further text on the line,
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 that text will be copied verbatim to `generated-autoload-file'.")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 (defconst generate-autoload-section-header "\f\n;;;### "
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 "String inserted before the form identifying
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 the section of autoloads for a file.")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 (defconst generate-autoload-section-trailer "\n;;;***\n"
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 "String which indicates the end of the section of autoloads for a file.")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
74 ;;; Forms which have doc-strings which should be printed specially.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
75 ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
76 ;;; the doc-string in FORM.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
77 ;;;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
78 ;;; There used to be the following note here:
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
79 ;;; ;;; Note: defconst and defvar should NOT be marked in this way.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
80 ;;; ;;; We don't want to produce defconsts and defvars that
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
81 ;;; ;;; make-docfile can grok, because then it would grok them twice,
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
82 ;;; ;;; once in foo.el (where they are given with ;;;###autoload) and
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
83 ;;; ;;; once in loaddefs.el.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
84 ;;;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
85 ;;; Counter-note: Yes, they should be marked in this way.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
86 ;;; make-docfile only processes those files that are loaded into the
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
87 ;;; dumped Emacs, and those files should never have anything
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
88 ;;; autoloaded here. The above-feared problem only occurs with files
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
89 ;;; which have autoloaded entries *and* are processed by make-docfile;
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
90 ;;; there should be no such files.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
91
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 (put 'autoload 'doc-string-elt 3)
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
93 (put 'defun 'doc-string-elt 3)
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
94 (put 'defvar 'doc-string-elt 3)
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
95 (put 'defconst 'doc-string-elt 3)
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
96 (put 'defmacro 'doc-string-elt 3)
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (defun generate-file-autoloads (file)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 "Insert at point a loaddefs autoload section for FILE.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 If FILE is being visited in a buffer, the contents of the buffer
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 are used."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (interactive "fGenerate autoloads for file: ")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 (let ((outbuf (current-buffer))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 (autoloads-done '())
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 (load-name (let ((name (file-name-nondirectory file)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (if (string-match "\\.elc?$" name)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (substring name 0 (match-beginning 0))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 name)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (print-length nil)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (floating-output-format "%20e")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 output-end)
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
116
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
117 ;; If the autoload section we create here uses an absolute
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
118 ;; pathname for FILE in its header, and then Emacs is installed
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
119 ;; under a different path on another system,
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
120 ;; `update-autoloads-here' won't be able to find the files to be
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
121 ;; autoloaded. So, if FILE is in the same directory or a
732
a8d94735277e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 727
diff changeset
122 ;; subdirectory of the current buffer's directory, we'll make it
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
123 ;; relative to the current buffer's directory.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
124 (setq file (expand-file-name file))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
125 (if (and (< (length default-directory) (length file))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
126 (string= default-directory
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
127 (substring file 0 (length default-directory))))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
128 (progn
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
129 (setq file (substring file (length default-directory)))))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
130
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (message "Generating autoloads for %s..." file)
1975
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
132 (save-excursion
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
133 (unwind-protect
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
134 (progn
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
135 (set-buffer (find-file-noselect file))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
136 (save-excursion
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
137 (save-restriction
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
138 (widen)
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
139 (goto-char (point-min))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
140 (while (not (eobp))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
141 (skip-chars-forward " \t\n\f")
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
142 (cond
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
143 ((looking-at (regexp-quote generate-autoload-cookie))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
144 (search-forward generate-autoload-cookie)
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
145 (skip-chars-forward " \t")
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
146 (setq done-any t)
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
147 (if (eolp)
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
148 ;; Read the next form and make an autoload.
3777
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
149 (let* ((before (point))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
150 (form (prog1 (read (current-buffer))
1975
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
151 (forward-line 1)))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
152 (autoload (make-autoload form load-name))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
153 (doc-string-elt (get (car-safe form)
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
154 'doc-string-elt)))
3777
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
155 (if (null autoload)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
156 ;; We are copying a defvar or defconst form.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
157 ;; Copy the text instead of printing the form,
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
158 ;; so as to preserve the original formatting.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
159 (let ((inbuf (current-buffer))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
160 (after (point)))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
161 (save-excursion
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
162 (set-buffer outbuf)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
163 ;; Insert the form.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
164 (insert-buffer-substring inbuf before after)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
165 (and doc-string-elt
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
166 (stringp (nth doc-string-elt form))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
167 ;; The form has a docstring.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
168 ;; Hack it for make-docfile.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
169 (save-excursion
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
170 ;; Move point back to FORM's start.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
171 (backward-char (- after before))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
172 (skip-chars-forward " \t\n")
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
173 (or (looking-at "(")
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
174 (error "expected ("))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
175 (forward-char 1) ; Skip the paren.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
176 ;; Skip sexps before the docstring.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
177 (forward-sexp doc-string-elt)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
178 (skip-chars-forward " \t")
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
179 (if (eolp) (delete-char 1))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
180 (skip-chars-forward " \t")
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
181 (or (looking-at "\"")
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
182 (error "expected \""))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
183 (forward-char 1) ; Skip the ".
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
184 (insert "\\\n"))) ;make-docfile happy.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
185 (goto-char after)))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
186 ;; Write the autoload for this defun or defmacro.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
187 (setq autoloads-done (cons (nth 1 form)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
188 autoloads-done))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
189 (if (and doc-string-elt
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
190 (stringp (nth doc-string-elt autoload)))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
191 ;; We need to hack the printing because the
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
192 ;; doc-string must be printed specially for
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
193 ;; make-docfile (sigh).
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
194 (let* ((p (nthcdr (1- doc-string-elt)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
195 autoload))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
196 (elt (cdr p)))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
197 (setcdr p nil)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
198 (princ "\n(" outbuf)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
199 (mapcar (function (lambda (elt)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
200 (prin1 elt outbuf)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
201 (princ " " outbuf)))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
202 autoload)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
203 (princ "\"\\\n" outbuf)
1975
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
204 (princ (substring
3777
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
205 (prin1-to-string (car elt)) 1)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
206 outbuf)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
207 (if (null (cdr elt))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
208 (princ ")" outbuf)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
209 (princ " " outbuf)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
210 (princ (substring
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
211 (prin1-to-string (cdr elt))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
212 1)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
213 outbuf))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
214 (terpri outbuf))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
215 (print autoload outbuf))))
1975
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
216 ;; 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
217 (let ((begin (point)))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
218 (forward-line 1)
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
219 (princ (buffer-substring begin (point)) outbuf))))
3777
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
220 ((looking-at ";")
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
221 ;; Don't read the comment.
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
222 (forward-line 1))
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
223 (t
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
224 (forward-sexp 1)
d6f56b9586f7 (make-autoload): Use memq once instead eq twice.
Roland McGrath <roland@gnu.org>
parents: 3774
diff changeset
225 (forward-line 1)))))))
1975
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
226 (or visited
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
227 ;; 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
228 (kill-buffer (current-buffer)))
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
229 (set-buffer outbuf)
3334e2489824 * autoload.el (generate-file-autoloads): Add another
Jim Blandy <jimb@redhat.com>
parents: 1884
diff changeset
230 (setq output-end (point-marker))))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (if done-any
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (progn
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (insert generate-autoload-section-header)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 (prin1 (list 'autoloads autoloads-done load-name file
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (nth 5 (file-attributes file)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 outbuf)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (terpri outbuf)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (insert ";;; Generated autoloads from " file "\n")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (goto-char output-end)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 (insert generate-autoload-section-trailer)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (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
242
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (defconst generated-autoload-file "loaddefs.el"
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 "*File \\[update-file-autoloads] puts autoloads into.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 A .el file can set this in its local variables section to make its
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 autoloads go somewhere else.")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 ;;;###autoload
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (defun update-file-autoloads (file)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 "Update the autoloads for FILE in `generated-autoload-file'
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 \(which FILE might bind in its local variables)."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (interactive "fUpdate autoloads for file: ")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (let ((load-name (let ((name (file-name-nondirectory file)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (if (string-match "\\.elc?$" name)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (substring name 0 (match-beginning 0))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 name)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (done nil)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (existing-buffer (get-file-buffer file)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (save-excursion
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 ;; We want to get a value for generated-autoload-file from
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 ;; the local variables section if it's there.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (set-buffer (find-file-noselect file))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (set-buffer (find-file-noselect generated-autoload-file))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (save-excursion
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (save-restriction
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (widen)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (goto-char (point-min))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (while (search-forward generate-autoload-section-header nil t)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (let ((form (condition-case ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (read (current-buffer))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (end-of-file nil))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (if (string= (nth 2 form) load-name)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 (let ((begin (match-beginning 0))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (last-time (nth 4 form))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 (file-time (nth 5 (file-attributes file))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (if (and (or (null existing-buffer)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (not (buffer-modified-p existing-buffer)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (listp last-time) (= (length last-time) 2)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (or (> (car last-time) (car file-time))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (and (= (car last-time) (car file-time))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 (>= (nth 1 last-time)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 (nth 1 file-time)))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 (message "Autoload section for %s is up to date."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 file)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (search-forward generate-autoload-section-trailer)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (delete-region begin (point))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 (generate-file-autoloads file))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 (setq done t))))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 (if done
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 ;; Have the user tell us where to put the section.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 (save-window-excursion
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 (switch-to-buffer (current-buffer))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (with-output-to-temp-buffer "*Help*"
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (princ (substitute-command-keys
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 (format "\
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 Move point to where the autoload section
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 for %s should be inserted.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 Then do \\[exit-recursive-edit]."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 file))))
1108
6a0c694bd3a5 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
301 (recursive-edit)
6a0c694bd3a5 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
302 (beginning-of-line))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (generate-file-autoloads file)))
2535
86d5500624d5 (update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents: 2494
diff changeset
304 (if (interactive-p) (save-buffer))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (if (and (null existing-buffer)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 (setq existing-buffer (get-file-buffer file)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 (kill-buffer existing-buffer)))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 ;;;###autoload
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 (defun update-autoloads-here ()
3774
3b0cb275ca29 (generate-autoload-cookie, update-autoloads-here): Doc fixes.
Roland McGrath <roland@gnu.org>
parents: 2535
diff changeset
311 "\
3b0cb275ca29 (generate-autoload-cookie, update-autoloads-here): Doc fixes.
Roland McGrath <roland@gnu.org>
parents: 2535
diff changeset
312 Update sections of the current buffer generated by \\[update-file-autoloads]."
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 (interactive)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 (let ((generated-autoload-file (buffer-file-name)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 (save-excursion
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 (goto-char (point-min))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 (while (search-forward generate-autoload-section-header nil t)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 (let* ((form (condition-case ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 (read (current-buffer))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 (end-of-file nil)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (file (nth 3 form)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 (if (and (stringp file)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 (or (get-file-buffer file)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (file-exists-p file)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (setq file (if (y-or-n-p (format "Library \"%s\" (load \
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 file \"%s\") doesn't exist. Remove its autoload section? "
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 (nth 2 form) file))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 t
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 (condition-case ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 (read-file-name (format "Find \"%s\" load file: "
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 (nth 2 form))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 nil nil t)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 (quit nil)))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 (if file
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 (let ((begin (match-beginning 0)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (search-forward generate-autoload-section-trailer)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (delete-region begin (point))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 (if (stringp file)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (generate-file-autoloads file)))))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 ;;;###autoload
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (defun update-directory-autoloads (dir)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 "Run \\[update-file-autoloads] on each .el file in DIR."
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (interactive "DUpdate autoloads for directory: ")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (mapcar 'update-file-autoloads
2535
86d5500624d5 (update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents: 2494
diff changeset
347 (directory-files dir nil "\\.el$"))
86d5500624d5 (update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents: 2494
diff changeset
348 (if (interactive-p)
86d5500624d5 (update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents: 2494
diff changeset
349 (save-excursion
86d5500624d5 (update-file-autoloads, update-directory-autoloads): If called
Roland McGrath <roland@gnu.org>
parents: 2494
diff changeset
350 (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
351 (save-buffer))))
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 ;;;###autoload
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 (defun batch-update-autoloads ()
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 "Update the autoloads for the files or directories on the command line.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 Runs \\[update-file-autoloads] on files and \\[update-directory-autoloads]
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 on directories. Must be used only with -batch, and kills Emacs on completion.
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 Each file will be processed even if an error occurred previously.
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 473
diff changeset
359 For example, invoke \"emacs -batch -f batch-update-autoloads *.el\""
473
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (if (not noninteractive)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (error "batch-update-file-autoloads is to be used only with -batch"))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (let ((lost nil)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (args command-line-args-left))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (while args
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (catch 'file
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (condition-case lossage
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (if (file-directory-p (expand-file-name (car args)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (update-directory-autoloads (car args))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (update-file-autoloads (car args)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 (error (progn (message ">>Error processing %s: %s"
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (car args) lossage)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 (setq lost t)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 (throw 'file nil)))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 (setq args (cdr args)))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 (save-some-buffers t)
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 (message "Done")
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (kill-emacs (if lost 1 0))))
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
999d0b38694e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (provide 'autoload)
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 473
diff changeset
380
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 648
diff changeset
381 ;;; autoload.el ends here