annotate lisp/utils/autoload.el @ 0:376386a54a3c r19-14

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