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