Mercurial > emacs
comparison lisp/emacs-lisp/autoload.el @ 1884:4a8bc12e7017
(generate-file-autoloads): If no buffer was visiting FILE when we started,
kill the buffer we create.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Wed, 17 Feb 1993 21:30:21 +0000 |
parents | f2901040a07b |
children | 3334e2489824 |
comparison
equal
deleted
inserted
replaced
1883:b707809f29bb | 1884:4a8bc12e7017 |
---|---|
1 ;;; autoload.el --- maintain autoloads in loaddefs.el. | 1 ;;; autoload.el --- maintain autoloads in loaddefs.el. |
2 | 2 |
3 ;;; Copyright (C) 1991, 1992 Free Software Foundation, Inc. | 3 ;;; Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. |
4 ;;; | 4 ;;; |
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> | 5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> |
6 ;; Keyword: internal | 6 ;; Keyword: internal |
7 | 7 |
8 ;;; This program is free software; you can redistribute it and/or modify | 8 ;;; This program is free software; you can redistribute it and/or modify |
94 marked by `generate-autoload-regexp' (which see). | 94 marked by `generate-autoload-regexp' (which see). |
95 If FILE is being visited in a buffer, the contents of the buffer | 95 If FILE is being visited in a buffer, the contents of the buffer |
96 are used." | 96 are used." |
97 (interactive "fGenerate autoloads for file: ") | 97 (interactive "fGenerate autoloads for file: ") |
98 (let ((outbuf (current-buffer)) | 98 (let ((outbuf (current-buffer)) |
99 (inbuf (find-file-noselect file)) | |
100 (autoloads-done '()) | 99 (autoloads-done '()) |
101 (load-name (let ((name (file-name-nondirectory file))) | 100 (load-name (let ((name (file-name-nondirectory file))) |
102 (if (string-match "\\.elc?$" name) | 101 (if (string-match "\\.elc?$" name) |
103 (substring name 0 (match-beginning 0)) | 102 (substring name 0 (match-beginning 0)) |
104 name))) | 103 name))) |
105 (print-length nil) | 104 (print-length nil) |
106 (floating-output-format "%20e") | 105 (floating-output-format "%20e") |
107 (done-any nil) | 106 (done-any nil) |
107 (visited (get-file-buffer file)) | |
108 output-end) | 108 output-end) |
109 | 109 |
110 ;; If the autoload section we create here uses an absolute | 110 ;; If the autoload section we create here uses an absolute |
111 ;; pathname for FILE in its header, and then Emacs is installed | 111 ;; pathname for FILE in its header, and then Emacs is installed |
112 ;; under a different path on another system, | 112 ;; under a different path on another system, |
120 (substring file 0 (length default-directory)))) | 120 (substring file 0 (length default-directory)))) |
121 (progn | 121 (progn |
122 (setq file (substring file (length default-directory))))) | 122 (setq file (substring file (length default-directory))))) |
123 | 123 |
124 (message "Generating autoloads for %s..." file) | 124 (message "Generating autoloads for %s..." file) |
125 (save-excursion | 125 (unwind-protect |
126 (set-buffer inbuf) | 126 (progn |
127 (save-excursion | 127 (set-buffer (find-file-noselect file)) |
128 (save-restriction | 128 (save-excursion |
129 (widen) | 129 (save-restriction |
130 (goto-char (point-min)) | 130 (widen) |
131 (while (not (eobp)) | 131 (goto-char (point-min)) |
132 (skip-chars-forward " \t\n\f") | 132 (while (not (eobp)) |
133 (cond ((looking-at (regexp-quote generate-autoload-cookie)) | 133 (skip-chars-forward " \t\n\f") |
134 (search-forward generate-autoload-cookie) | 134 (cond ((looking-at (regexp-quote generate-autoload-cookie)) |
135 (skip-chars-forward " \t") | 135 (search-forward generate-autoload-cookie) |
136 (setq done-any t) | 136 (skip-chars-forward " \t") |
137 (if (eolp) | 137 (setq done-any t) |
138 ;; Read the next form and make an autoload. | 138 (if (eolp) |
139 (let* ((form (prog1 (read (current-buffer)) | 139 ;; Read the next form and make an autoload. |
140 (forward-line 1))) | 140 (let* ((form (prog1 (read (current-buffer)) |
141 (autoload (make-autoload form load-name)) | 141 (forward-line 1))) |
142 (doc-string-elt (get (car-safe form) | 142 (autoload (make-autoload form load-name)) |
143 'doc-string-elt))) | 143 (doc-string-elt (get (car-safe form) |
144 (if autoload | 144 'doc-string-elt))) |
145 (setq autoloads-done (cons (nth 1 form) | 145 (if autoload |
146 autoloads-done)) | 146 (setq autoloads-done (cons (nth 1 form) |
147 (setq autoload form)) | 147 autoloads-done)) |
148 (if (and doc-string-elt | 148 (setq autoload form)) |
149 (stringp (nth doc-string-elt autoload))) | 149 (if (and doc-string-elt |
150 ;; We need to hack the printing because the | 150 (stringp (nth doc-string-elt autoload))) |
151 ;; doc-string must be printed specially for | 151 ;; We need to hack the printing because the |
152 ;; make-docfile (sigh). | 152 ;; doc-string must be printed specially for |
153 (let* ((p (nthcdr (1- doc-string-elt) autoload)) | 153 ;; make-docfile (sigh). |
154 (elt (cdr p))) | 154 (let* ((p (nthcdr (1- doc-string-elt) |
155 (setcdr p nil) | 155 autoload)) |
156 (princ "\n(" outbuf) | 156 (elt (cdr p))) |
157 (mapcar (function (lambda (elt) | 157 (setcdr p nil) |
158 (prin1 elt outbuf) | 158 (princ "\n(" outbuf) |
159 (princ " " outbuf))) | 159 (mapcar (function (lambda (elt) |
160 autoload) | 160 (prin1 elt outbuf) |
161 (princ "\"\\\n" outbuf) | 161 (princ " " outbuf))) |
162 (princ (substring (prin1-to-string (car elt)) 1) | 162 autoload) |
163 outbuf) | 163 (princ "\"\\\n" outbuf) |
164 (if (null (cdr elt)) | 164 (princ (substring |
165 (princ ")" outbuf) | 165 (prin1-to-string (car elt)) 1) |
166 (princ " " outbuf) | 166 outbuf) |
167 (princ (substring (prin1-to-string (cdr elt)) | 167 (if (null (cdr elt)) |
168 1) | 168 (princ ")" outbuf) |
169 outbuf)) | 169 (princ " " outbuf) |
170 (terpri outbuf)) | 170 (princ (substring |
171 (print autoload outbuf))) | 171 (prin1-to-string (cdr elt)) |
172 ;; Copy the rest of the line to the output. | 172 1) |
173 (let ((begin (point))) | 173 outbuf)) |
174 (forward-line 1) | 174 (terpri outbuf)) |
175 (princ (buffer-substring begin (point)) outbuf)))) | 175 (print autoload outbuf))) |
176 ((looking-at ";") | 176 ;; Copy the rest of the line to the output. |
177 ;; Don't read the comment. | 177 (let ((begin (point))) |
178 (forward-line 1)) | 178 (forward-line 1) |
179 (t | 179 (princ (buffer-substring begin (point)) outbuf)))) |
180 (forward-sexp 1) | 180 ((looking-at ";") |
181 (forward-line 1)))))) | 181 ;; Don't read the comment. |
182 (forward-line 1)) | |
183 (t | |
184 (forward-sexp 1) | |
185 (forward-line 1))))))) | |
186 (or visited | |
187 ;; We created this buffer, so we should kill it. | |
188 (kill-buffer (current-buffer))) | |
182 (set-buffer outbuf) | 189 (set-buffer outbuf) |
183 (setq output-end (point-marker))) | 190 (setq output-end (point-marker))) |
184 (if done-any | 191 (if done-any |
185 (progn | 192 (progn |
186 (insert generate-autoload-section-header) | 193 (insert generate-autoload-section-header) |