Mercurial > emacs
comparison lisp/emacs-lisp/autoload.el @ 5837:fd1e2c6f7bf5
(autoload-trim-file-name): New function.
(generate-file-autoloads): Bind print-readably to t for Lucid.
Use autoload-trim-file-name on FILE when inserting the name.
Scan written text and fix up ^L to \f and ( at bol to \(.
(update-file-autoloads): When we find a later file's section, set FOUND to
'new. If FOUND is 'new after loop, check file for autoload cookies and
don't call generate-file-autoloads if none.
(update-directory-autoloads): Get absolute file names from directory-files.
(batch-update-autoloads): Rewrite from jwz to process later files in a
directory after one file errs.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Mon, 07 Feb 1994 22:19:05 +0000 |
parents | b1e5e6efed1d |
children | d01185037467 |
comparison
equal
deleted
inserted
replaced
5836:6d7ceb4493e3 | 5837:fd1e2c6f7bf5 |
---|---|
93 (put 'defun 'doc-string-elt 3) | 93 (put 'defun 'doc-string-elt 3) |
94 (put 'defvar 'doc-string-elt 3) | 94 (put 'defvar 'doc-string-elt 3) |
95 (put 'defconst 'doc-string-elt 3) | 95 (put 'defconst 'doc-string-elt 3) |
96 (put 'defmacro 'doc-string-elt 3) | 96 (put 'defmacro 'doc-string-elt 3) |
97 | 97 |
98 (defun autoload-trim-file-name (file) | |
99 ;; Returns a relative pathname of FILE including the last directory. | |
100 (setq file (expand-file-name file)) | |
101 (file-relative-name file | |
102 (file-name-directory | |
103 (directory-file-name | |
104 (file-name-directory file))))) | |
105 | |
98 (defun generate-file-autoloads (file) | 106 (defun generate-file-autoloads (file) |
99 "Insert at point a loaddefs autoload section for FILE. | 107 "Insert at point a loaddefs autoload section for FILE. |
100 autoloads are generated for defuns and defmacros in FILE | 108 autoloads are generated for defuns and defmacros in FILE |
101 marked by `generate-autoload-cookie' (which see). | 109 marked by `generate-autoload-cookie' (which see). |
102 If FILE is being visited in a buffer, the contents of the buffer | 110 If FILE is being visited in a buffer, the contents of the buffer |
107 (load-name (let ((name (file-name-nondirectory file))) | 115 (load-name (let ((name (file-name-nondirectory file))) |
108 (if (string-match "\\.elc?$" name) | 116 (if (string-match "\\.elc?$" name) |
109 (substring name 0 (match-beginning 0)) | 117 (substring name 0 (match-beginning 0)) |
110 name))) | 118 name))) |
111 (print-length nil) | 119 (print-length nil) |
120 (print-readably t) ; This does something in Lucid Emacs. | |
112 (float-output-format nil) | 121 (float-output-format nil) |
113 (done-any nil) | 122 (done-any nil) |
114 (visited (get-file-buffer file)) | 123 (visited (get-file-buffer file)) |
115 output-end) | 124 output-end) |
116 | 125 |
144 (cond | 153 (cond |
145 ((looking-at (regexp-quote generate-autoload-cookie)) | 154 ((looking-at (regexp-quote generate-autoload-cookie)) |
146 (search-forward generate-autoload-cookie) | 155 (search-forward generate-autoload-cookie) |
147 (skip-chars-forward " \t") | 156 (skip-chars-forward " \t") |
148 (setq done-any t) | 157 (setq done-any t) |
149 (if (eolp) | 158 (let ((begin (save-excursion (set-buffer outbuf) |
150 ;; Read the next form and make an autoload. | 159 (point)))) |
151 (let* ((form (prog1 (read (current-buffer)) | 160 (if (eolp) |
152 (forward-line 1))) | 161 ;; Read the next form and make an autoload. |
153 (autoload (make-autoload form load-name)) | 162 (let* ((form (prog1 (read (current-buffer)) |
154 (doc-string-elt (get (car-safe form) | 163 (forward-line 1))) |
155 'doc-string-elt))) | 164 (autoload (make-autoload form load-name)) |
156 (if autoload | 165 (doc-string-elt (get (car-safe form) |
157 (setq autoloads-done (cons (nth 1 form) | 166 'doc-string-elt))) |
158 autoloads-done)) | 167 (if autoload |
159 (setq autoload form)) | 168 (setq autoloads-done (cons (nth 1 form) |
160 (if (and doc-string-elt | 169 autoloads-done)) |
161 (stringp (nth doc-string-elt autoload))) | 170 (setq autoload form)) |
162 ;; We need to hack the printing because the | 171 (if (and doc-string-elt |
163 ;; doc-string must be printed specially for | 172 (stringp (nth doc-string-elt autoload))) |
164 ;; make-docfile (sigh). | 173 ;; We need to hack the printing because the |
165 (let* ((p (nthcdr (1- doc-string-elt) | 174 ;; doc-string must be printed specially for |
166 autoload)) | 175 ;; make-docfile (sigh). |
167 (elt (cdr p))) | 176 (let* ((p (nthcdr (1- doc-string-elt) |
168 (setcdr p nil) | 177 autoload)) |
169 (princ "\n(" outbuf) | 178 (elt (cdr p))) |
170 (let ((print-escape-newlines t)) | 179 (setcdr p nil) |
171 (mapcar (function (lambda (elt) | 180 (princ "\n(" outbuf) |
172 (prin1 elt outbuf) | 181 (let ((print-escape-newlines t)) |
173 (princ " " outbuf))) | 182 (mapcar (function (lambda (elt) |
174 autoload)) | 183 (prin1 elt outbuf) |
175 (princ "\"\\\n" outbuf) | 184 (princ " " outbuf))) |
176 (princ (substring | 185 autoload)) |
177 (prin1-to-string (car elt)) 1) | 186 (princ "\"\\\n" outbuf) |
178 outbuf) | 187 (let ((begin (save-excursion |
179 (if (null (cdr elt)) | 188 (set-buffer outbuf) |
180 (princ ")" outbuf) | 189 (point)))) |
181 (princ " " outbuf) | |
182 (princ (substring | 190 (princ (substring |
183 (prin1-to-string (cdr elt)) | 191 (prin1-to-string (car elt)) 1) |
184 1) | 192 outbuf) |
185 outbuf)) | 193 ;; Insert a backslash before each ( that |
186 (terpri outbuf)) | 194 ;; appears at the beginning of a line in |
187 (print autoload outbuf))) | 195 ;; the doc string. |
188 ;; Copy the rest of the line to the output. | 196 (save-excursion |
189 (let ((begin (point))) | 197 (set-buffer outbuf) |
190 (forward-line 1) | 198 (save-excursion |
191 (princ (buffer-substring begin (point)) outbuf)))) | 199 (while (search-backward "\n(" begin t) |
192 ((looking-at ";") | 200 (forward-char 1) |
193 ;; Don't read the comment. | 201 (insert "\\")))) |
194 (forward-line 1)) | 202 (if (null (cdr elt)) |
195 (t | 203 (princ ")" outbuf) |
196 (forward-sexp 1) | 204 (princ " " outbuf) |
197 (forward-line 1))))))) | 205 (princ (substring |
206 (prin1-to-string (cdr elt)) | |
207 1) | |
208 outbuf)) | |
209 (terpri outbuf)) | |
210 (print autoload outbuf))) | |
211 ;; Copy the rest of the line to the output. | |
212 (let ((begin (point))) | |
213 (forward-line 1) | |
214 (princ (buffer-substring begin (point)) outbuf))) | |
215 (save-excursion | |
216 (set-buffer outbuf) | |
217 ;; Replace literal ^Ls with \f in what we just wrote. | |
218 (save-excursion | |
219 (while (search-backward "\f" begin t) | |
220 (delete-char 1) | |
221 (insert "\\f")))))) | |
222 ((looking-at ";") | |
223 ;; Don't read the comment. | |
224 (forward-line 1)) | |
225 (t | |
226 (forward-sexp 1) | |
227 (forward-line 1))))))) | |
198 (or visited | 228 (or visited |
199 ;; We created this buffer, so we should kill it. | 229 ;; We created this buffer, so we should kill it. |
200 (kill-buffer (current-buffer))) | 230 (kill-buffer (current-buffer))) |
201 (set-buffer outbuf) | 231 (set-buffer outbuf) |
202 (setq output-end (point-marker)))) | 232 (setq output-end (point-marker)))) |
203 (if done-any | 233 (if done-any |
204 (progn | 234 (progn |
205 (insert generate-autoload-section-header) | 235 (insert generate-autoload-section-header) |
206 (prin1 (list 'autoloads autoloads-done load-name file | 236 (prin1 (list 'autoloads autoloads-done load-name |
237 (autoload-trim-file-name file) | |
207 (nth 5 (file-attributes file))) | 238 (nth 5 (file-attributes file))) |
208 outbuf) | 239 outbuf) |
209 (terpri outbuf) | 240 (terpri outbuf) |
210 (insert ";;; Generated autoloads from " file "\n") | 241 (insert ";;; Generated autoloads from " |
242 (autoload-trim-file-name file) "\n") | |
211 (goto-char output-end) | 243 (goto-char output-end) |
212 (insert generate-autoload-section-trailer))) | 244 (insert generate-autoload-section-trailer))) |
213 (message "Generating autoloads for %s...done" file))) | 245 (message "Generating autoloads for %s...done" file))) |
214 | 246 |
215 (defconst generated-autoload-file "loaddefs.el" | 247 (defconst generated-autoload-file "loaddefs.el" |
267 ;; We've come to a section alphabetically later than | 299 ;; We've come to a section alphabetically later than |
268 ;; LOAD-NAME. We assume the file is in order and so | 300 ;; LOAD-NAME. We assume the file is in order and so |
269 ;; there must be no section for LOAD-NAME. We will | 301 ;; there must be no section for LOAD-NAME. We will |
270 ;; insert one before the section here. | 302 ;; insert one before the section here. |
271 (goto-char (match-beginning 0)) | 303 (goto-char (match-beginning 0)) |
272 (setq found t))))) | 304 (setq found 'new))))) |
273 (if (eq found t) | 305 (or (eq found 'up-to-date) |
306 (and (eq found 'new) | |
307 ;; Check that FILE has any cookies before generating a | |
308 ;; new section for it. | |
309 (save-excursion | |
310 (set-buffer (find-file-noselect file)) | |
311 (save-excursion | |
312 (widen) | |
313 (goto-char (point-min)) | |
314 (if (search-forward (concat "\n" | |
315 generate-autoload-cookie) | |
316 nil t) | |
317 nil | |
318 (if (interactive-p) | |
319 (message file " has no autoloads")) | |
320 t)))) | |
274 (generate-file-autoloads file)) | 321 (generate-file-autoloads file)) |
275 (setq done t))) | 322 (setq done t))) |
276 (if (interactive-p) (save-buffer)) | 323 (if (interactive-p) (save-buffer)) |
277 (if (and (null existing-buffer) | 324 (if (and (null existing-buffer) |
278 (setq existing-buffer (get-file-buffer file))) | 325 (setq existing-buffer (get-file-buffer file))) |
314 ;;;###autoload | 361 ;;;###autoload |
315 (defun update-directory-autoloads (dir) | 362 (defun update-directory-autoloads (dir) |
316 "Run \\[update-file-autoloads] on each .el file in DIR." | 363 "Run \\[update-file-autoloads] on each .el file in DIR." |
317 (interactive "DUpdate autoloads for directory: ") | 364 (interactive "DUpdate autoloads for directory: ") |
318 (mapcar 'update-file-autoloads | 365 (mapcar 'update-file-autoloads |
319 (directory-files dir nil "\\.el$")) | 366 (directory-files dir t "\\.el$")) |
320 (if (interactive-p) | 367 (if (interactive-p) |
321 (save-excursion | 368 (save-excursion |
322 (set-buffer (find-file-noselect generated-autoload-file)) | 369 (set-buffer (find-file-noselect generated-autoload-file)) |
323 (save-buffer)))) | 370 (save-buffer)))) |
324 | 371 |
330 Each file will be processed even if an error occurred previously. | 377 Each file will be processed even if an error occurred previously. |
331 For example, invoke \"emacs -batch -f batch-update-autoloads *.el\"" | 378 For example, invoke \"emacs -batch -f batch-update-autoloads *.el\"" |
332 (if (not noninteractive) | 379 (if (not noninteractive) |
333 (error "batch-update-autoloads is to be used only with -batch")) | 380 (error "batch-update-autoloads is to be used only with -batch")) |
334 (let ((lost nil) | 381 (let ((lost nil) |
335 (args command-line-args-left)) | 382 (args command-line-args-left) |
336 (while args | 383 (enable-local-eval nil)) ;Don't query in batch mode. |
337 (catch 'file | 384 (message "Updating autoloads in %s..." generated-autoload-file) |
338 (condition-case lossage | 385 (let ((frob (function |
339 (if (file-directory-p (expand-file-name (car args))) | 386 (lambda (file) |
340 (update-directory-autoloads (car args)) | 387 (condition-case lossage |
341 (update-file-autoloads (car args))) | 388 (update-file-autoloads file) |
342 (error (progn (message ">>Error processing %s: %s" | 389 (error |
343 (car args) lossage) | 390 (princ ">>Error processing ") |
344 (setq lost t) | 391 (princ file) |
345 (throw 'file nil))))) | 392 (princ ": ") |
346 (setq args (cdr args))) | 393 (if (fboundp 'display-error) |
394 (display-error lossage nil) | |
395 (prin1 lossage)) | |
396 (princ "\n") | |
397 (setq lost t))))))) | |
398 (while args | |
399 (if (file-directory-p (expand-file-name (car args))) | |
400 (let ((rest (directory-files (car args) t "\\.el$"))) | |
401 (while rest | |
402 (funcall frob (car rest)) | |
403 (setq rest (cdr rest)))) | |
404 (funcall frob (car args))) | |
405 (setq args (cdr args))) | |
347 (save-some-buffers t) | 406 (save-some-buffers t) |
348 (message "Done") | 407 (message "Done") |
349 (kill-emacs (if lost 1 0)))) | 408 (kill-emacs (if lost 1 0)))) |
350 | 409 |
351 (provide 'autoload) | 410 (provide 'autoload) |