(generate-file-autoloads): If no buffer was visiting FILE when we started,

kill the buffer we create.
This commit is contained in:
Roland McGrath 1993-02-17 21:30:21 +00:00
parent eceee2c04a
commit 7e4263eb77

View file

@ -1,6 +1,6 @@
;;; autoload.el --- maintain autoloads in loaddefs.el. ;;; autoload.el --- maintain autoloads in loaddefs.el.
;;; Copyright (C) 1991, 1992 Free Software Foundation, Inc. ;;; Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
;;; ;;;
;; Author: Roland McGrath <roland@gnu.ai.mit.edu> ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>
;; Keyword: internal ;; Keyword: internal
@ -96,7 +96,6 @@ If FILE is being visited in a buffer, the contents of the buffer
are used." are used."
(interactive "fGenerate autoloads for file: ") (interactive "fGenerate autoloads for file: ")
(let ((outbuf (current-buffer)) (let ((outbuf (current-buffer))
(inbuf (find-file-noselect file))
(autoloads-done '()) (autoloads-done '())
(load-name (let ((name (file-name-nondirectory file))) (load-name (let ((name (file-name-nondirectory file)))
(if (string-match "\\.elc?$" name) (if (string-match "\\.elc?$" name)
@ -105,6 +104,7 @@ are used."
(print-length nil) (print-length nil)
(floating-output-format "%20e") (floating-output-format "%20e")
(done-any nil) (done-any nil)
(visited (get-file-buffer file))
output-end) output-end)
;; If the autoload section we create here uses an absolute ;; If the autoload section we create here uses an absolute
@ -122,63 +122,70 @@ are used."
(setq file (substring file (length default-directory))))) (setq file (substring file (length default-directory)))))
(message "Generating autoloads for %s..." file) (message "Generating autoloads for %s..." file)
(save-excursion (unwind-protect
(set-buffer inbuf) (progn
(save-excursion (set-buffer (find-file-noselect file))
(save-restriction (save-excursion
(widen) (save-restriction
(goto-char (point-min)) (widen)
(while (not (eobp)) (goto-char (point-min))
(skip-chars-forward " \t\n\f") (while (not (eobp))
(cond ((looking-at (regexp-quote generate-autoload-cookie)) (skip-chars-forward " \t\n\f")
(search-forward generate-autoload-cookie) (cond ((looking-at (regexp-quote generate-autoload-cookie))
(skip-chars-forward " \t") (search-forward generate-autoload-cookie)
(setq done-any t) (skip-chars-forward " \t")
(if (eolp) (setq done-any t)
;; Read the next form and make an autoload. (if (eolp)
(let* ((form (prog1 (read (current-buffer)) ;; Read the next form and make an autoload.
(forward-line 1))) (let* ((form (prog1 (read (current-buffer))
(autoload (make-autoload form load-name)) (forward-line 1)))
(doc-string-elt (get (car-safe form) (autoload (make-autoload form load-name))
'doc-string-elt))) (doc-string-elt (get (car-safe form)
(if autoload 'doc-string-elt)))
(setq autoloads-done (cons (nth 1 form) (if autoload
autoloads-done)) (setq autoloads-done (cons (nth 1 form)
(setq autoload form)) autoloads-done))
(if (and doc-string-elt (setq autoload form))
(stringp (nth doc-string-elt autoload))) (if (and doc-string-elt
;; We need to hack the printing because the (stringp (nth doc-string-elt autoload)))
;; doc-string must be printed specially for ;; We need to hack the printing because the
;; make-docfile (sigh). ;; doc-string must be printed specially for
(let* ((p (nthcdr (1- doc-string-elt) autoload)) ;; make-docfile (sigh).
(elt (cdr p))) (let* ((p (nthcdr (1- doc-string-elt)
(setcdr p nil) autoload))
(princ "\n(" outbuf) (elt (cdr p)))
(mapcar (function (lambda (elt) (setcdr p nil)
(prin1 elt outbuf) (princ "\n(" outbuf)
(princ " " outbuf))) (mapcar (function (lambda (elt)
autoload) (prin1 elt outbuf)
(princ "\"\\\n" outbuf) (princ " " outbuf)))
(princ (substring (prin1-to-string (car elt)) 1) autoload)
outbuf) (princ "\"\\\n" outbuf)
(if (null (cdr elt)) (princ (substring
(princ ")" outbuf) (prin1-to-string (car elt)) 1)
(princ " " outbuf) outbuf)
(princ (substring (prin1-to-string (cdr elt)) (if (null (cdr elt))
1) (princ ")" outbuf)
outbuf)) (princ " " outbuf)
(terpri outbuf)) (princ (substring
(print autoload outbuf))) (prin1-to-string (cdr elt))
;; Copy the rest of the line to the output. 1)
(let ((begin (point))) outbuf))
(forward-line 1) (terpri outbuf))
(princ (buffer-substring begin (point)) outbuf)))) (print autoload outbuf)))
((looking-at ";") ;; Copy the rest of the line to the output.
;; Don't read the comment. (let ((begin (point)))
(forward-line 1)) (forward-line 1)
(t (princ (buffer-substring begin (point)) outbuf))))
(forward-sexp 1) ((looking-at ";")
(forward-line 1)))))) ;; Don't read the comment.
(forward-line 1))
(t
(forward-sexp 1)
(forward-line 1)))))))
(or visited
;; We created this buffer, so we should kill it.
(kill-buffer (current-buffer)))
(set-buffer outbuf) (set-buffer outbuf)
(setq output-end (point-marker))) (setq output-end (point-marker)))
(if done-any (if done-any