annotate lisp/utils/autoload.el @ 153:25f70ba0133c r20-3b3

Import from CVS: tag r20-3b3
author cvs
date Mon, 13 Aug 2007 09:38:25 +0200
parents 1370575f1259
children 43dd3413c7c7
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 ;;; Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: maint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
9 ;; This file is part of XEmacs.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
10
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
12 ;; under the terms of the GNU General Public License as published by
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
14 ;; any later version.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
19 ;; General Public License for more details.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
20
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
21 ;; You should have received a copy of the GNU General Public License
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
24 ;; 02111-1307, USA.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
25
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
26 ;;; Synched up with: Not synched with FSF.
0
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
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
62 (defvar generate-autoload-cookie ";;;###autoload"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Magic comment indicating the following form should be autoloaded.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
64 Used by `update-file-autoloads'. This string should be
0
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
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
72 If this string appears alone on a line, the following form will be
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
73 read and an autoload made for it. If it is followed by the string
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
74 \"immediate\", then the form on the following line will be copied
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
75 verbatim. If there is further text on the line, that text will be
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
76 copied verbatim to `generated-autoload-file'.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
78 (defvar generate-autoload-section-header "\f\n;;;### "
0
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
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
82 (defvar generate-autoload-section-trailer "\n;;;***\n"
0
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)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
110 "Returns a relative pathname of FILE including the last directory."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (setq file (expand-file-name file))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
112 (file-relative-name file (file-name-directory
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
113 (directory-file-name
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
114 (file-name-directory file)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defun generate-file-autoloads (file &optional funlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "Insert at point a loaddefs autoload section for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 autoloads are generated for defuns and defmacros in FILE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 marked by `generate-autoload-cookie' (which see).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 If FILE is being visited in a buffer, the contents of the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 are used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (interactive "fGenerate autoloads for file: ")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
124 (generate-file-autoloads-1 file funlist))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
125
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
126 (defun* generate-file-autoloads-1 (file funlist)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
127 "Insert at point a loaddefs autoload section for FILE.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
128 autoloads are generated for defuns and defmacros in FILE
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
129 marked by `generate-autoload-cookie' (which see).
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
130 If FILE is being visited in a buffer, the contents of the buffer
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
131 are used."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (let ((outbuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (autoloads-done '())
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
134 (load-name (replace-in-string (file-name-nondirectory file)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
135 "\\.elc?$"
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
136 ""))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
137 (trim-name (autoload-trim-file-name file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (dofiles (not (null funlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (print-length nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (print-readably t) ; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (float-output-format nil)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
142 ;; (done-any nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (visited (get-file-buffer file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 output-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; If the autoload section we create here uses an absolute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; pathname for FILE in its header, and then Emacs is installed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; under a different path on another system,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; `update-autoloads-here' won't be able to find the files to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; autoloaded. So, if FILE is in the same directory or a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; subdirectory of the current buffer's directory, we'll make it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; relative to the current buffer's directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq file (expand-file-name file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (progn
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 112
diff changeset
158 (let ((find-file-hooks nil)
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 112
diff changeset
159 (enable-local-variables nil))
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 112
diff changeset
160 (set-buffer (or visited (find-file-noselect file)))
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 112
diff changeset
161 (set-syntax-table lisp-mode-syntax-table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (goto-char (point-min))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
166 (unless (search-forward generate-autoload-cookie nil t)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
167 (message "No autoloads found in %s" trim-name)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
168 (return-from generate-file-autoloads-1))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
169
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
170 (message "Generating autoloads for %s..." trim-name)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
171 (goto-char (point-min))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (while (if dofiles funlist (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if (not dofiles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (skip-chars-forward " \t\n\f")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (concat "(def\\(un\\|var\\|const\\|macro\\) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (regexp-quote (symbol-name (car funlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "\\s "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (goto-char (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ((or dofiles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (looking-at (regexp-quote generate-autoload-cookie)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if dofiles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (search-forward generate-autoload-cookie)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (skip-chars-forward " \t"))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
188 ;; (setq done-any t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (if (or dofiles (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Read the next form and make an autoload.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (let* ((form (prog1 (read (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (or (bolp) (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (autoload (make-autoload form load-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (doc-string-elt (get (car-safe form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 'doc-string-elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (if autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (setq autoloads-done (cons (nth 1 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 autoloads-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (setq autoload form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (and doc-string-elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (stringp (nth doc-string-elt autoload)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; We need to hack the printing because the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; doc-string must be printed specially for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; make-docfile (sigh).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (let* ((p (nthcdr (1- doc-string-elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 autoload))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (elt (cdr p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setcdr p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (princ "\n(" outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; XEmacs change: don't let ^^L's get into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; the file or sorting is hard.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (let ((print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (p (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 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (mapcar (function (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (prin1 elt outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (princ " " outbuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 autoload)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (set-buffer outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (setq p2 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (while (search-forward "\^L" p2 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (insert "\\^L")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (goto-char p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (princ "\"\\\n" outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (let ((begin (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (set-buffer outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (princ (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (prin1-to-string (car elt)) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; Insert a backslash before each ( that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; appears at the beginning of a line in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; the doc string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (set-buffer outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (while (search-backward "\n(" begin t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (insert "\\"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if (null (cdr elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (princ ")" outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (princ " " outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (princ (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (prin1-to-string (cdr elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 outbuf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (terpri outbuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;; XEmacs change: another fucking ^L hack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (let ((p (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (set-buffer outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (print autoload outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (set-buffer outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (setq p2 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (while (search-forward "\^L" p2 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (insert "\\^L")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (goto-char p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; Copy the rest of the line to the output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (let ((begin (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (terpri outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (cond ((looking-at "immediate\\s *$") ; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;; This is here so that you can automatically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; have small hook functions copied to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; loaddefs.el so that it's not necessary to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; load a whole file just to get a two-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; do-nothing find-file-hook... --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (setq begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (princ (buffer-substring begin (point)) outbuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ((looking-at ";")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;; Don't read the comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if dofiles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (setq funlist (cdr funlist)))))))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
297 ;;(unless visited
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;; We created this buffer, so we should kill it.
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
299 ;; Customize needs it later, we don't want to read the file
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
300 ;; in twice.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
301 ;;(kill-buffer (current-buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (set-buffer outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (setq output-end (point-marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (if t ;; done-any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;; XEmacs -- always do this so that we cache the information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; that we've processed the file already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (insert generate-autoload-section-header)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
309 (prin1 (list 'autoloads autoloads-done load-name trim-name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (terpri outbuf)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
312 ;;;; (insert ";;; Generated autoloads from "
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
313 ;;;; (autoload-trim-file-name file) "\n")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; Warn if we put a line in loaddefs.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;; that is long enough to cause trouble.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
316 (when (< output-end (point))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
317 (setq output-end (point-marker)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (while (< (point) output-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (if (> (- (point) beg) 900)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (message "A line is too long--over 900 characters")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (sleep-for 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (goto-char output-end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (goto-char output-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (insert generate-autoload-section-trailer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (or noninteractive ; XEmacs: only need one line in -batch mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (message "Generating autoloads for %s...done" file))))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
331
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
333 (defvar generated-autoload-file
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
334 (expand-file-name "../lisp/prim/auto-autoloads.el" data-directory)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
335 "*File `update-file-autoloads' puts autoloads into.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 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
337 autoloads go somewhere else.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
339 (defvar generated-custom-file
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 126
diff changeset
340 (expand-file-name "../lisp/prim/cus-load.el" data-directory)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
341 "*File `update-file-autoloads' puts customization into.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
342
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
343 ;; Written by Per Abrahamsen
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
344 (defun autoload-snarf-defcustom (file)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
345 "Snarf all customizations in the current buffer."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
346 (let ((visited (get-file-buffer file)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
347 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
348 (set-buffer (or visited (find-file-noselect file)))
112
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
349 (when (and file
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
350 (string-match "\\`\\(.*\\)\\.el\\'" file)
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
351 (not (buffer-modified-p)))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
352 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
353 (condition-case nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
354 (let ((name (file-name-nondirectory (match-string 1 file))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
355 (while t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
356 (let ((expr (read (current-buffer))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
357 (when (and (listp expr)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
358 (memq (car expr) '(defcustom defface defgroup)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
359 (eval expr)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
360 (put (nth 1 expr) 'custom-where name)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
361 (error nil)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
362 (unless (buffer-modified-p)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
363 (kill-buffer (current-buffer))))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
364
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (defun update-file-autoloads (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 "Update the autoloads for FILE in `generated-autoload-file'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 \(which FILE might bind in its local variables)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (interactive "fUpdate autoloads for file: ")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
370 (setq file (expand-file-name file))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
371 (let ((load-name (replace-in-string (file-name-nondirectory file)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
372 "\\.elc?$"
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
373 ""))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (trim-name (autoload-trim-file-name file))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
375 section-begin form)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (save-excursion
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 78
diff changeset
377 (let ((find-file-hooks nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 78
diff changeset
378 (set-buffer (or (get-file-buffer generated-autoload-file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 78
diff changeset
379 (find-file-noselect generated-autoload-file))))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
380 ;; First delete all sections for this file.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
381 (goto-char (point-min))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
382 (while (search-forward generate-autoload-section-header nil t)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
383 (setq section-begin (match-beginning 0))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
384 (setq form (read (current-buffer)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
385 (when (string= (nth 2 form) load-name)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
386 (search-forward generate-autoload-section-trailer)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
387 (delete-region section-begin (point))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
388
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
389 ;; Now find insertion point for new section
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
390 (block find-insertion-point
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
391 (goto-char (point-min))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
392 (while (search-forward generate-autoload-section-header nil t)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
393 (setq form (read (current-buffer)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
394 (when (string< trim-name (nth 3 form))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
395 ;; Found alphabetically correct insertion point
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
396 (goto-char (match-beginning 0))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
397 (return-from find-insertion-point))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
398 (search-forward generate-autoload-section-trailer))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
399 (when (eq (point) (point-min)) ; No existing entries?
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
400 (goto-char (point-max)))) ; Append.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
401
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
402 ;; Add in new sections for file
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
403 (generate-file-autoloads file)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
404 (autoload-snarf-defcustom file))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
405
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
406 (when (interactive-p) (save-buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defun update-autoloads-here ()
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
410 "Update sections of the current buffer generated by `update-file-autoloads'."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (let ((generated-autoload-file (buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (while (search-forward generate-autoload-section-header nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (let* ((form (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (read (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (end-of-file nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (file (nth 3 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ;; XEmacs change: if we can't find the file as specified, look
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;; around a bit more.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (cond ((and (stringp file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (or (get-file-buffer file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (file-exists-p file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ((and (stringp file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (let ((loc (locate-file (file-name-nondirectory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 load-path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (if (null loc)
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 (setq loc (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (autoload-trim-file-name loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ".."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (if (or (get-file-buffer loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (file-exists-p loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (setq file loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (t
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
439 (setq file
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
440 (if (y-or-n-p
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
441 (format
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
442 "Can't find library `%s'; remove its autoloads? "
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
443 (nth 2 form) file))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
444 t
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
445 (condition-case ()
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
446 (read-file-name
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
447 (format "Find `%s' load file: "
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
448 (nth 2 form))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
449 nil nil t)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
450 (quit nil))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (let ((begin (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (search-forward generate-autoload-section-trailer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (delete-region begin (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (if (stringp file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (generate-file-autoloads file)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;;;###autoload
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
459 (defun update-autoloads-from-directory (dir)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
460 "Update `generated-autoload-file' with all the current autoloads from DIR.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
461 This runs `update-file-autoloads' on each .el file in DIR.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
462 Obsolete autoload entries for files that no longer exist are deleted."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (interactive "DUpdate autoloads for directory: ")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
464 (setq dir (expand-file-name dir))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
465 (let ((simple-dir (file-name-as-directory
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
466 (file-name-nondirectory
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
467 (directory-file-name dir))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
468 (enable-local-eval nil))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
469 (save-excursion
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 78
diff changeset
470 (let ((find-file-hooks nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 78
diff changeset
471 (set-buffer (find-file-noselect generated-autoload-file)))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
472 (goto-char (point-min))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
473 (while (search-forward generate-autoload-section-header nil t)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
474 (let* ((begin (match-beginning 0))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
475 (form (condition-case ()
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
476 (read (current-buffer))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
477 (end-of-file nil)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
478 (file (nth 3 form)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
479 (when (and (stringp file)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
480 (string= (file-name-directory file) simple-dir)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
481 (not (file-exists-p
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
482 (expand-file-name
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
483 (file-name-nondirectory file) dir))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
484 ;; Remove the obsolete section.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
485 (search-forward generate-autoload-section-trailer)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
486 (delete-region begin (point)))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
487 ;; Update or create autoload sections for existing files.
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
488 (mapcar 'update-file-autoloads (directory-files dir t "^[^=].*\\.el$"))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
489 (unless noninteractive
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
490 (save-buffer)))))
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 24
diff changeset
491
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
492 ;; Based on code from Per Abrahamsen
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
493 (defun autoload-save-customization ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
494 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
495 (set-buffer (find-file-noselect generated-custom-file))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
496 (erase-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
497 (insert
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
498 (with-output-to-string
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
499 (mapatoms (lambda (symbol)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
500 (let ((members (get symbol 'custom-group))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
501 item where found)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
502 (when members
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
503 (princ "(put '")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
504 (princ symbol)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
505 (princ " 'custom-loads '(")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
506 (while members
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
507 (setq item (car (car members))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
508 members (cdr members)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
509 where (get item 'custom-where))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
510 (unless (or (null where)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
511 (member where found))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
512 (when found
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
513 (princ " "))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
514 (prin1 where)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
515 (push where found)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
516 (princ "))\n")))))))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
517
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (defun batch-update-autoloads ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 "Update the autoloads for the files or directories on the command line.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
521 Runs `update-file-autoloads' on files and `update-directory-autoloads'
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 on directories. Must be used only with -batch, and kills Emacs on completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 Each file will be processed even if an error occurred previously.
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
524 For example, invoke `xemacs -batch -f batch-update-autoloads *.el'."
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
525 (unless noninteractive
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
526 (error "batch-update-autoloads is to be used only with -batch"))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
527 (let ((defdir default-directory)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
528 (enable-local-eval nil)) ; Don't query in batch mode.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (message "Updating autoloads in %s..." generated-autoload-file)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
530 (dolist (arg command-line-args-left)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
531 (setq arg (expand-file-name arg defdir))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
532 (cond
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
533 ((file-directory-p arg)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
534 (message "Updating autoloads for directory %s..." arg)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
535 (update-autoloads-from-directory arg))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
536 ((file-exists-p arg)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
537 (update-file-autoloads arg))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
538 (t (error "No such file or directory: %s" arg))))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 100
diff changeset
539 (autoload-save-customization)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (save-some-buffers t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (message "Done")
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
542 (kill-emacs 0)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (provide 'autoload)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;;; autoload.el ends here