0
|
1 ;;; autoload.el --- maintain autoloads in loaddefs.el.
|
155
|
2
|
|
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
5 ;; Copyright (C) 1996 Ben Wing.
|
0
|
6
|
|
7 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>
|
|
8 ;; Keywords: maint
|
|
9
|
78
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
0
|
16
|
78
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
25 ;; 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: Not synched with FSF.
|
0
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This code helps GNU Emacs maintainers keep the loaddefs.el file up to
|
|
32 ;; date. It interprets magic cookies of the form ";;;###autoload" in
|
|
33 ;; lisp source files in various useful ways. To learn more, read the
|
|
34 ;; source; if you're going to use this, you'd better be able to.
|
|
35
|
|
36 ;;; Code:
|
|
37
|
|
38 (defun make-autoload (form file)
|
|
39 "Turn FORM, a defun or defmacro, into an autoload for source file FILE.
|
|
40 Returns nil if FORM is not a defun, define-skeleton or defmacro."
|
|
41 (let ((car (car-safe form)))
|
|
42 (if (memq car '(defun define-skeleton defmacro))
|
|
43 (let ((macrop (eq car 'defmacro))
|
|
44 name doc)
|
|
45 (setq form (cdr form)
|
|
46 name (car form)
|
|
47 ;; Ignore the arguments.
|
|
48 form (cdr (if (eq car 'define-skeleton)
|
|
49 form
|
|
50 (cdr form)))
|
|
51 doc (car form))
|
|
52 (if (stringp doc)
|
|
53 (setq form (cdr form))
|
|
54 (setq doc nil))
|
|
55 (list 'autoload (list 'quote name) file doc
|
|
56 (or (eq car 'define-skeleton)
|
|
57 (eq (car-safe (car form)) 'interactive))
|
|
58 (if macrop (list 'quote 'macro) nil)))
|
|
59 nil)))
|
|
60
|
|
61 (put 'define-skeleton 'doc-string-elt 3)
|
|
62
|
78
|
63 (defvar generate-autoload-cookie ";;;###autoload"
|
0
|
64 "Magic comment indicating the following form should be autoloaded.
|
78
|
65 Used by `update-file-autoloads'. This string should be
|
0
|
66 meaningless to Lisp (e.g., a comment).
|
|
67
|
|
68 This string is used:
|
|
69
|
|
70 ;;;###autoload
|
|
71 \(defun function-to-be-autoloaded () ...)
|
|
72
|
78
|
73 If this string appears alone on a line, the following form will be
|
|
74 read and an autoload made for it. If it is followed by the string
|
|
75 \"immediate\", then the form on the following line will be copied
|
|
76 verbatim. If there is further text on the line, that text will be
|
|
77 copied verbatim to `generated-autoload-file'.")
|
0
|
78
|
78
|
79 (defvar generate-autoload-section-header "\f\n;;;### "
|
0
|
80 "String inserted before the form identifying
|
|
81 the section of autoloads for a file.")
|
|
82
|
78
|
83 (defvar generate-autoload-section-trailer "\n;;;***\n"
|
0
|
84 "String which indicates the end of the section of autoloads for a file.")
|
|
85
|
|
86 ;;; Forms which have doc-strings which should be printed specially.
|
|
87 ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is
|
|
88 ;;; the doc-string in FORM.
|
|
89 ;;;
|
|
90 ;;; There used to be the following note here:
|
|
91 ;;; ;;; Note: defconst and defvar should NOT be marked in this way.
|
|
92 ;;; ;;; We don't want to produce defconsts and defvars that
|
|
93 ;;; ;;; make-docfile can grok, because then it would grok them twice,
|
|
94 ;;; ;;; once in foo.el (where they are given with ;;;###autoload) and
|
|
95 ;;; ;;; once in loaddefs.el.
|
|
96 ;;;
|
|
97 ;;; Counter-note: Yes, they should be marked in this way.
|
|
98 ;;; make-docfile only processes those files that are loaded into the
|
|
99 ;;; dumped Emacs, and those files should never have anything
|
|
100 ;;; autoloaded here. The above-feared problem only occurs with files
|
|
101 ;;; which have autoloaded entries *and* are processed by make-docfile;
|
|
102 ;;; there should be no such files.
|
|
103
|
|
104 (put 'autoload 'doc-string-elt 3)
|
|
105 (put 'defun 'doc-string-elt 3)
|
|
106 (put 'defvar 'doc-string-elt 3)
|
|
107 (put 'defconst 'doc-string-elt 3)
|
|
108 (put 'defmacro 'doc-string-elt 3)
|
|
109
|
|
110 (defun autoload-trim-file-name (file)
|
78
|
111 "Returns a relative pathname of FILE including the last directory."
|
0
|
112 (setq file (expand-file-name file))
|
78
|
113 (file-relative-name file (file-name-directory
|
|
114 (directory-file-name
|
|
115 (file-name-directory file)))))
|
0
|
116
|
|
117 ;;;###autoload
|
|
118 (defun generate-file-autoloads (file &optional funlist)
|
|
119 "Insert at point a loaddefs autoload section for FILE.
|
|
120 autoloads are generated for defuns and defmacros in FILE
|
|
121 marked by `generate-autoload-cookie' (which see).
|
|
122 If FILE is being visited in a buffer, the contents of the buffer
|
|
123 are used."
|
|
124 (interactive "fGenerate autoloads for file: ")
|
78
|
125 (generate-file-autoloads-1 file funlist))
|
|
126
|
|
127 (defun* generate-file-autoloads-1 (file funlist)
|
|
128 "Insert at point a loaddefs autoload section for FILE.
|
|
129 autoloads are generated for defuns and defmacros in FILE
|
|
130 marked by `generate-autoload-cookie' (which see).
|
|
131 If FILE is being visited in a buffer, the contents of the buffer
|
|
132 are used."
|
0
|
133 (let ((outbuf (current-buffer))
|
|
134 (autoloads-done '())
|
78
|
135 (load-name (replace-in-string (file-name-nondirectory file)
|
|
136 "\\.elc?$"
|
|
137 ""))
|
|
138 (trim-name (autoload-trim-file-name file))
|
0
|
139 (dofiles (not (null funlist)))
|
|
140 (print-length nil)
|
|
141 (print-readably t) ; XEmacs
|
|
142 (float-output-format nil)
|
78
|
143 ;; (done-any nil)
|
0
|
144 (visited (get-file-buffer file))
|
|
145 output-end)
|
|
146
|
|
147 ;; If the autoload section we create here uses an absolute
|
|
148 ;; pathname for FILE in its header, and then Emacs is installed
|
|
149 ;; under a different path on another system,
|
|
150 ;; `update-autoloads-here' won't be able to find the files to be
|
|
151 ;; autoloaded. So, if FILE is in the same directory or a
|
|
152 ;; subdirectory of the current buffer's directory, we'll make it
|
|
153 ;; relative to the current buffer's directory.
|
|
154 (setq file (expand-file-name file))
|
|
155
|
|
156 (save-excursion
|
|
157 (unwind-protect
|
|
158 (progn
|
126
|
159 (let ((find-file-hooks nil)
|
|
160 (enable-local-variables nil))
|
|
161 (set-buffer (or visited (find-file-noselect file)))
|
|
162 (set-syntax-table lisp-mode-syntax-table))
|
0
|
163 (save-excursion
|
|
164 (save-restriction
|
|
165 (widen)
|
|
166 (goto-char (point-min))
|
78
|
167 (unless (search-forward generate-autoload-cookie nil t)
|
|
168 (message "No autoloads found in %s" trim-name)
|
|
169 (return-from generate-file-autoloads-1))
|
|
170
|
|
171 (message "Generating autoloads for %s..." trim-name)
|
|
172 (goto-char (point-min))
|
0
|
173 (while (if dofiles funlist (not (eobp)))
|
|
174 (if (not dofiles)
|
|
175 (skip-chars-forward " \t\n\f")
|
|
176 (goto-char (point-min))
|
|
177 (re-search-forward
|
|
178 (concat "(def\\(un\\|var\\|const\\|macro\\) "
|
|
179 (regexp-quote (symbol-name (car funlist)))
|
|
180 "\\s "))
|
|
181 (goto-char (match-beginning 0)))
|
|
182 (cond
|
|
183 ((or dofiles
|
|
184 (looking-at (regexp-quote generate-autoload-cookie)))
|
|
185 (if dofiles
|
|
186 nil
|
|
187 (search-forward generate-autoload-cookie)
|
|
188 (skip-chars-forward " \t"))
|
78
|
189 ;; (setq done-any t)
|
0
|
190 (if (or dofiles (eolp))
|
|
191 ;; Read the next form and make an autoload.
|
|
192 (let* ((form (prog1 (read (current-buffer))
|
|
193 (or (bolp) (forward-line 1))))
|
|
194 (autoload (make-autoload form load-name))
|
|
195 (doc-string-elt (get (car-safe form)
|
|
196 'doc-string-elt)))
|
|
197 (if autoload
|
|
198 (setq autoloads-done (cons (nth 1 form)
|
|
199 autoloads-done))
|
|
200 (setq autoload form))
|
|
201 (if (and doc-string-elt
|
|
202 (stringp (nth doc-string-elt autoload)))
|
|
203 ;; We need to hack the printing because the
|
|
204 ;; doc-string must be printed specially for
|
|
205 ;; make-docfile (sigh).
|
|
206 (let* ((p (nthcdr (1- doc-string-elt)
|
|
207 autoload))
|
|
208 (elt (cdr p)))
|
|
209 (setcdr p nil)
|
|
210 (princ "\n(" outbuf)
|
|
211 ;; XEmacs change: don't let ^^L's get into
|
|
212 ;; the file or sorting is hard.
|
|
213 (let ((print-escape-newlines t)
|
|
214 (p (save-excursion
|
|
215 (set-buffer outbuf)
|
|
216 (point)))
|
|
217 p2)
|
|
218 (mapcar (function (lambda (elt)
|
|
219 (prin1 elt outbuf)
|
|
220 (princ " " outbuf)))
|
|
221 autoload)
|
|
222 (save-excursion
|
|
223 (set-buffer outbuf)
|
|
224 (setq p2 (point-marker))
|
|
225 (goto-char p)
|
|
226 (save-match-data
|
|
227 (while (search-forward "\^L" p2 t)
|
|
228 (delete-char -1)
|
|
229 (insert "\\^L")))
|
|
230 (goto-char p2)
|
|
231 ))
|
|
232 (princ "\"\\\n" outbuf)
|
|
233 (let ((begin (save-excursion
|
|
234 (set-buffer outbuf)
|
|
235 (point))))
|
|
236 (princ (substring
|
|
237 (prin1-to-string (car elt)) 1)
|
|
238 outbuf)
|
|
239 ;; Insert a backslash before each ( that
|
|
240 ;; appears at the beginning of a line in
|
|
241 ;; the doc string.
|
|
242 (save-excursion
|
|
243 (set-buffer outbuf)
|
|
244 (save-excursion
|
|
245 (while (search-backward "\n(" begin t)
|
|
246 (forward-char 1)
|
|
247 (insert "\\"))))
|
|
248 (if (null (cdr elt))
|
|
249 (princ ")" outbuf)
|
|
250 (princ " " outbuf)
|
|
251 (princ (substring
|
|
252 (prin1-to-string (cdr elt))
|
|
253 1)
|
|
254 outbuf))
|
|
255 (terpri outbuf)))
|
|
256 ;; XEmacs change: another fucking ^L hack
|
|
257 (let ((p (save-excursion
|
|
258 (set-buffer outbuf)
|
|
259 (point)))
|
|
260 (print-escape-newlines t)
|
|
261 p2)
|
|
262 (print autoload outbuf)
|
|
263 (save-excursion
|
|
264 (set-buffer outbuf)
|
|
265 (setq p2 (point-marker))
|
|
266 (goto-char p)
|
|
267 (save-match-data
|
|
268 (while (search-forward "\^L" p2 t)
|
|
269 (delete-char -1)
|
|
270 (insert "\\^L")))
|
|
271 (goto-char p2)
|
|
272 ))
|
|
273 ))
|
|
274 ;; Copy the rest of the line to the output.
|
|
275 (let ((begin (point)))
|
|
276 (terpri outbuf)
|
|
277 (cond ((looking-at "immediate\\s *$") ; XEmacs
|
|
278 ;; This is here so that you can automatically
|
|
279 ;; have small hook functions copied to
|
|
280 ;; loaddefs.el so that it's not necessary to
|
|
281 ;; load a whole file just to get a two-line
|
|
282 ;; do-nothing find-file-hook... --Stig
|
|
283 (forward-line 1)
|
|
284 (setq begin (point))
|
|
285 (forward-sexp)
|
|
286 (forward-line 1))
|
|
287 (t
|
|
288 (forward-line 1)))
|
|
289 (princ (buffer-substring begin (point)) outbuf))))
|
|
290 ((looking-at ";")
|
|
291 ;; Don't read the comment.
|
|
292 (forward-line 1))
|
|
293 (t
|
|
294 (forward-sexp 1)
|
|
295 (forward-line 1)))
|
|
296 (if dofiles
|
|
297 (setq funlist (cdr funlist)))))))
|
110
|
298 ;;(unless visited
|
0
|
299 ;; We created this buffer, so we should kill it.
|
110
|
300 ;; Customize needs it later, we don't want to read the file
|
|
301 ;; in twice.
|
|
302 ;;(kill-buffer (current-buffer)))
|
0
|
303 (set-buffer outbuf)
|
|
304 (setq output-end (point-marker))))
|
|
305 (if t ;; done-any
|
|
306 ;; XEmacs -- always do this so that we cache the information
|
|
307 ;; that we've processed the file already.
|
|
308 (progn
|
|
309 (insert generate-autoload-section-header)
|
78
|
310 (prin1 (list 'autoloads autoloads-done load-name trim-name)
|
0
|
311 outbuf)
|
|
312 (terpri outbuf)
|
78
|
313 ;;;; (insert ";;; Generated autoloads from "
|
|
314 ;;;; (autoload-trim-file-name file) "\n")
|
0
|
315 ;; Warn if we put a line in loaddefs.el
|
|
316 ;; that is long enough to cause trouble.
|
78
|
317 (when (< output-end (point))
|
|
318 (setq output-end (point-marker)))
|
0
|
319 (while (< (point) output-end)
|
169
|
320 ;; (let ((beg (point)))
|
0
|
321 (end-of-line)
|
165
|
322 ;; Emacs -- I still haven't figured this one out.
|
|
323 ;; (if (> (- (point) beg) 900)
|
|
324 ;; (progn
|
|
325 ;; (message "A line is too long--over 900 characters")
|
|
326 ;; (sleep-for 2)
|
|
327 ;; (goto-char output-end)))
|
169
|
328 ;; )
|
0
|
329 (forward-line 1))
|
|
330 (goto-char output-end)
|
|
331 (insert generate-autoload-section-trailer)))
|
|
332 (or noninteractive ; XEmacs: only need one line in -batch mode.
|
|
333 (message "Generating autoloads for %s...done" file))))
|
78
|
334
|
0
|
335
|
163
|
336 (defconst autoload-file-name "auto-autoloads.el"
|
|
337 "Generic filename to put autoloads into.
|
|
338 Unless you are an XEmacs maintainer, it is probably unwise to change this.")
|
|
339
|
|
340 (defvar autoload-target-directory "../lisp/prim/"
|
|
341 "Directory to put autoload declaration file into.
|
|
342 Unless you know what you're doing, don't mess with this.")
|
|
343
|
78
|
344 (defvar generated-autoload-file
|
163
|
345 (expand-file-name (concat autoload-target-directory
|
|
346 autoload-file-name)
|
|
347 data-directory)
|
78
|
348 "*File `update-file-autoloads' puts autoloads into.
|
0
|
349 A .el file can set this in its local variables section to make its
|
|
350 autoloads go somewhere else.")
|
|
351
|
163
|
352 (defconst cusload-file-name "custom-load.el"
|
|
353 "Generic filename ot put custom loads into.
|
|
354 Unless you are an XEmacs maintainr, it is probably unwise to change this.")
|
|
355
|
110
|
356 (defvar generated-custom-file
|
163
|
357 (expand-file-name (concat autoload-target-directory
|
|
358 cusload-file-name)
|
|
359 data-directory)
|
110
|
360 "*File `update-file-autoloads' puts customization into.")
|
|
361
|
169
|
362 (defvar customized-symbols nil)
|
|
363
|
110
|
364 ;; Written by Per Abrahamsen
|
|
365 (defun autoload-snarf-defcustom (file)
|
|
366 "Snarf all customizations in the current buffer."
|
|
367 (let ((visited (get-file-buffer file)))
|
|
368 (save-excursion
|
|
369 (set-buffer (or visited (find-file-noselect file)))
|
112
|
370 (when (and file
|
|
371 (string-match "\\`\\(.*\\)\\.el\\'" file)
|
|
372 (not (buffer-modified-p)))
|
110
|
373 (goto-char (point-min))
|
|
374 (condition-case nil
|
|
375 (let ((name (file-name-nondirectory (match-string 1 file))))
|
|
376 (while t
|
|
377 (let ((expr (read (current-buffer))))
|
|
378 (when (and (listp expr)
|
|
379 (memq (car expr) '(defcustom defface defgroup)))
|
|
380 (eval expr)
|
169
|
381 (put (nth 1 expr) 'custom-where name)
|
|
382 (pushnew (nth 1 expr) customized-symbols)))))
|
110
|
383 (error nil)))
|
|
384 (unless (buffer-modified-p)
|
|
385 (kill-buffer (current-buffer))))))
|
|
386
|
169
|
387 (defvar autoload-do-custom-save nil)
|
|
388
|
0
|
389 ;;;###autoload
|
|
390 (defun update-file-autoloads (file)
|
|
391 "Update the autoloads for FILE in `generated-autoload-file'
|
169
|
392 \(which FILE might bind in its local variables).
|
|
393 This functions refuses to update autolaods files and custom loads."
|
0
|
394 (interactive "fUpdate autoloads for file: ")
|
78
|
395 (setq file (expand-file-name file))
|
169
|
396 (when (and (file-newer-than-file-p file generated-autoload-file)
|
|
397 (not (member (file-name-nondirectory file)
|
|
398 (list autoload-file-name cusload-file-name))))
|
78
|
399
|
169
|
400 (setq autoload-do-custom-save t)
|
|
401 (let ((load-name (replace-in-string (file-name-nondirectory file)
|
|
402 "\\.elc?$"
|
|
403 ""))
|
|
404 (trim-name (autoload-trim-file-name file))
|
|
405 section-begin form)
|
|
406 (save-excursion
|
|
407 (let ((find-file-hooks nil))
|
|
408 (set-buffer (or (get-file-buffer generated-autoload-file)
|
|
409 (find-file-noselect generated-autoload-file))))
|
|
410 ;; First delete all sections for this file.
|
78
|
411 (goto-char (point-min))
|
|
412 (while (search-forward generate-autoload-section-header nil t)
|
169
|
413 (setq section-begin (match-beginning 0))
|
78
|
414 (setq form (read (current-buffer)))
|
169
|
415 (when (string= (nth 2 form) load-name)
|
|
416 (search-forward generate-autoload-section-trailer)
|
|
417 (delete-region section-begin (point))))
|
78
|
418
|
169
|
419 ;; Now find insertion point for new section
|
|
420 (block find-insertion-point
|
|
421 (goto-char (point-min))
|
|
422 (while (search-forward generate-autoload-section-header nil t)
|
|
423 (setq form (read (current-buffer)))
|
|
424 (when (string< trim-name (nth 3 form))
|
|
425 ;; Found alphabetically correct insertion point
|
|
426 (goto-char (match-beginning 0))
|
|
427 (return-from find-insertion-point))
|
|
428 (search-forward generate-autoload-section-trailer))
|
|
429 (when (eq (point) (point-min)) ; No existing entries?
|
|
430 (goto-char (point-max)))) ; Append.
|
78
|
431
|
169
|
432 ;; Add in new sections for file
|
|
433 (generate-file-autoloads file)
|
|
434 (autoload-snarf-defcustom file))
|
|
435
|
|
436 (when (interactive-p) (save-buffer)))))
|
0
|
437
|
|
438 ;;;###autoload
|
|
439 (defun update-autoloads-here ()
|
78
|
440 "Update sections of the current buffer generated by `update-file-autoloads'."
|
0
|
441 (interactive)
|
|
442 (let ((generated-autoload-file (buffer-file-name)))
|
|
443 (save-excursion
|
|
444 (goto-char (point-min))
|
|
445 (while (search-forward generate-autoload-section-header nil t)
|
|
446 (let* ((form (condition-case ()
|
|
447 (read (current-buffer))
|
|
448 (end-of-file nil)))
|
|
449 (file (nth 3 form)))
|
|
450 ;; XEmacs change: if we can't find the file as specified, look
|
|
451 ;; around a bit more.
|
|
452 (cond ((and (stringp file)
|
|
453 (or (get-file-buffer file)
|
|
454 (file-exists-p file))))
|
|
455 ((and (stringp file)
|
|
456 (save-match-data
|
|
457 (let ((loc (locate-file (file-name-nondirectory file)
|
|
458 load-path)))
|
|
459 (if (null loc)
|
|
460 nil
|
|
461 (setq loc (expand-file-name
|
|
462 (autoload-trim-file-name loc)
|
|
463 ".."))
|
|
464 (if (or (get-file-buffer loc)
|
|
465 (file-exists-p loc))
|
|
466 (setq file loc)
|
|
467 nil))))))
|
|
468 (t
|
78
|
469 (setq file
|
|
470 (if (y-or-n-p
|
|
471 (format
|
|
472 "Can't find library `%s'; remove its autoloads? "
|
|
473 (nth 2 form) file))
|
|
474 t
|
|
475 (condition-case ()
|
|
476 (read-file-name
|
|
477 (format "Find `%s' load file: "
|
|
478 (nth 2 form))
|
|
479 nil nil t)
|
|
480 (quit nil))))))
|
0
|
481 (if file
|
|
482 (let ((begin (match-beginning 0)))
|
|
483 (search-forward generate-autoload-section-trailer)
|
|
484 (delete-region begin (point))))
|
|
485 (if (stringp file)
|
|
486 (generate-file-autoloads file)))))))
|
|
487
|
|
488 ;;;###autoload
|
78
|
489 (defun update-autoloads-from-directory (dir)
|
|
490 "Update `generated-autoload-file' with all the current autoloads from DIR.
|
|
491 This runs `update-file-autoloads' on each .el file in DIR.
|
|
492 Obsolete autoload entries for files that no longer exist are deleted."
|
0
|
493 (interactive "DUpdate autoloads for directory: ")
|
169
|
494 (setq autoload-do-custom-save nil)
|
78
|
495 (setq dir (expand-file-name dir))
|
|
496 (let ((simple-dir (file-name-as-directory
|
|
497 (file-name-nondirectory
|
|
498 (directory-file-name dir))))
|
|
499 (enable-local-eval nil))
|
|
500 (save-excursion
|
100
|
501 (let ((find-file-hooks nil))
|
|
502 (set-buffer (find-file-noselect generated-autoload-file)))
|
78
|
503 (goto-char (point-min))
|
|
504 (while (search-forward generate-autoload-section-header nil t)
|
|
505 (let* ((begin (match-beginning 0))
|
|
506 (form (condition-case ()
|
|
507 (read (current-buffer))
|
|
508 (end-of-file nil)))
|
|
509 (file (nth 3 form)))
|
|
510 (when (and (stringp file)
|
|
511 (string= (file-name-directory file) simple-dir)
|
|
512 (not (file-exists-p
|
|
513 (expand-file-name
|
|
514 (file-name-nondirectory file) dir))))
|
|
515 ;; Remove the obsolete section.
|
|
516 (search-forward generate-autoload-section-trailer)
|
|
517 (delete-region begin (point)))))
|
|
518 ;; Update or create autoload sections for existing files.
|
|
519 (mapcar 'update-file-autoloads (directory-files dir t "^[^=].*\\.el$"))
|
|
520 (unless noninteractive
|
|
521 (save-buffer)))))
|
32
|
522
|
110
|
523 ;; Based on code from Per Abrahamsen
|
|
524 (defun autoload-save-customization ()
|
|
525 (save-excursion
|
|
526 (set-buffer (find-file-noselect generated-custom-file))
|
|
527 (erase-buffer)
|
|
528 (insert
|
|
529 (with-output-to-string
|
169
|
530 (mapcar (lambda (symbol)
|
|
531 (let ((members (condition-case nil
|
|
532 (get symbol 'custom-group)
|
|
533 (t (progn
|
|
534 (message "Bad plist in %s"
|
|
535 (symbol-name symbol)))
|
|
536 nil)))
|
|
537 item where
|
|
538 (found (condition-case nil
|
|
539 (get symbol 'custom-loads)
|
|
540 (t nil)))
|
|
541 )
|
|
542 (when (or members found)
|
|
543 (princ "(custom-put '")
|
|
544 (princ symbol)
|
|
545 (princ " 'custom-loads '(")
|
|
546 (when found
|
|
547 ;; (message "found = `%s'" found)
|
|
548 (insert (mapconcat 'prin1-to-string found " ")))
|
|
549 (while members
|
|
550 (setq item (car (car members))
|
|
551 members (cdr members)
|
|
552 where (get item 'custom-where))
|
|
553 (unless (or (null where)
|
|
554 (member where found))
|
|
555 ;; (message "where = `%s', found = `%s'" where found)
|
|
556 (when found
|
|
557 (princ " "))
|
|
558 (prin1 where)
|
|
559 (push where found)))
|
|
560 (princ "))\n"))))
|
|
561 customized-symbols)))
|
|
562 (when (= (point-min) (point-max))
|
|
563 (set-buffer-modified-p nil))))
|
110
|
564
|
0
|
565 ;;;###autoload
|
|
566 (defun batch-update-autoloads ()
|
|
567 "Update the autoloads for the files or directories on the command line.
|
78
|
568 Runs `update-file-autoloads' on files and `update-directory-autoloads'
|
0
|
569 on directories. Must be used only with -batch, and kills Emacs on completion.
|
|
570 Each file will be processed even if an error occurred previously.
|
169
|
571 For example, invoke `xemacs -batch -f batch-update-autoloads *.el'.
|
|
572 The directory to which the auto-autoloads.el and custom-load.el files must
|
|
573 be the first parameter on the command line."
|
78
|
574 (unless noninteractive
|
|
575 (error "batch-update-autoloads is to be used only with -batch"))
|
|
576 (let ((defdir default-directory)
|
|
577 (enable-local-eval nil)) ; Don't query in batch mode.
|
169
|
578 (when (file-exists-p generated-custom-file)
|
|
579 (flet ((custom-put (symbol property value)
|
|
580 (progn
|
|
581 (put symbol property value)
|
|
582 (pushnew symbol customized-symbols))))
|
|
583 (load generated-custom-file nil t)))
|
|
584 ;; (message "Updating autoloads in %s..." generated-autoload-file)
|
78
|
585 (dolist (arg command-line-args-left)
|
|
586 (setq arg (expand-file-name arg defdir))
|
|
587 (cond
|
|
588 ((file-directory-p arg)
|
|
589 (message "Updating autoloads for directory %s..." arg)
|
|
590 (update-autoloads-from-directory arg))
|
|
591 ((file-exists-p arg)
|
|
592 (update-file-autoloads arg))
|
|
593 (t (error "No such file or directory: %s" arg))))
|
169
|
594 (when autoload-do-custom-save
|
|
595 (autoload-save-customization))
|
|
596 (fixup-autoload-buffer (concat (file-name-nondirectory defdir)
|
|
597 "-autoloads"))
|
0
|
598 (save-some-buffers t)
|
169
|
599 ;; (message "Done")
|
78
|
600 (kill-emacs 0)))
|
0
|
601
|
163
|
602 (defun fixup-autoload-buffer (sym)
|
|
603 (save-excursion
|
|
604 (set-buffer (find-file-noselect generated-autoload-file))
|
|
605 (goto-char (point-min))
|
|
606 (if (and (not (= (point-min) (point-max)))
|
|
607 (not (looking-at ";;; DO NOT MODIFY THIS FILE")))
|
|
608 (progn
|
|
609 (insert ";;; DO NOT MODIFY THIS FILE\n")
|
185
|
610 (insert "(if (featurep '" sym "-autoloads)")
|
|
611 (insert " (error \"Already loaded\"))")
|
163
|
612 (goto-char (point-max))
|
183
|
613 (insert "\n(provide '" sym ")\n")))))
|
|
614
|
|
615 (defvar autoload-package-name nil)
|
163
|
616
|
|
617 ;;;###autoload
|
|
618 (defun batch-update-directory ()
|
|
619 "Update the autoloads for the directory on the command line.
|
|
620 Runs `update-file-autoloads' on each file in the given directory, and must
|
|
621 be used only with -batch, and kills XEmacs on completion."
|
|
622 (unless noninteractive
|
169
|
623 (error "batch-update-directory is to be used only with -batch"))
|
163
|
624 (let ((defdir default-directory)
|
|
625 (enable-local-eval nil)) ; Don't query in batch mode.
|
|
626 (dolist (arg command-line-args-left)
|
|
627 (setq arg (expand-file-name arg defdir))
|
|
628 (let ((generated-autoload-file (concat arg "/" autoload-file-name))
|
|
629 (generated-custom-file (concat arg "/" cusload-file-name)))
|
169
|
630 (when (file-exists-p generated-custom-file)
|
|
631 (flet ((custom-put (symbol property value)
|
|
632 (progn
|
|
633 (put symbol property value)
|
|
634 ;; (message "Loading %s = %s"
|
|
635 ;; (symbol-name symbol)
|
|
636 ;; (prin1-to-string value))
|
|
637 (pushnew symbol customized-symbols))))
|
|
638 (load generated-custom-file nil t)))
|
163
|
639 (cond
|
|
640 ((file-directory-p arg)
|
|
641 (message "Updating autoloads in directory %s..." arg)
|
|
642 (update-autoloads-from-directory arg))
|
|
643 (t (error "No such file or directory: %s" arg)))
|
169
|
644 (when autoload-do-custom-save
|
|
645 (autoload-save-customization)
|
|
646 (setq customized-symbols nil))
|
183
|
647 (fixup-autoload-buffer (concat (if autoload-package-name
|
|
648 autoload-package-name
|
|
649 (file-name-nondirectory arg))
|
169
|
650 "-autoloads"))
|
163
|
651 (save-some-buffers t))
|
169
|
652 ;; (message "Done")
|
163
|
653 ;; (kill-emacs 0)
|
167
|
654 )
|
|
655 (setq command-line-args-left nil)))
|
163
|
656
|
0
|
657 (provide 'autoload)
|
|
658
|
|
659 ;;; autoload.el ends here
|