Mercurial > emacs
comparison lisp/emacs-lisp/autoload.el @ 81603:6a5ecb520686
Refactor for upcoming changes.
(autoload-generate-file-autoloads): New function extracted from
generate-file-autoloads. Use file-relative-name. Delay computation of
output-start to the first cookie. Remove done-any, replaced by
output-start.
(generate-file-autoloads): Use it.
(autoload-find-destination): Make use of `begin' var.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 25 Jun 2007 03:48:10 +0000 |
parents | ea507ef94ad6 |
children | feafa882a0cf |
comparison
equal
deleted
inserted
replaced
81602:ea507ef94ad6 | 81603:6a5ecb520686 |
---|---|
307 marked by `generate-autoload-cookie' (which see). | 307 marked by `generate-autoload-cookie' (which see). |
308 If FILE is being visited in a buffer, the contents of the buffer | 308 If FILE is being visited in a buffer, the contents of the buffer |
309 are used. | 309 are used. |
310 Return non-nil in the case where no autoloads were added at point." | 310 Return non-nil in the case where no autoloads were added at point." |
311 (interactive "fGenerate autoloads for file: ") | 311 (interactive "fGenerate autoloads for file: ") |
312 (let ((outbuf (current-buffer)) | 312 (autoload-generate-file-autoloads file (current-buffer))) |
313 (autoloads-done '()) | 313 |
314 (defun autoload-generate-file-autoloads (file outbuf) | |
315 "Insert an autoload section for FILE in the appropriate buffer. | |
316 Autoloads are generated for defuns and defmacros in FILE | |
317 marked by `generate-autoload-cookie' (which see). | |
318 If FILE is being visited in a buffer, the contents of the buffer are used. | |
319 OUTBUF is the buffer in which the autoload statements will be inserted. | |
320 Return non-nil in the case where no autoloads were added in the buffer." | |
321 (let ((autoloads-done '()) | |
314 (load-name (autoload-file-load-name file)) | 322 (load-name (autoload-file-load-name file)) |
315 (print-length nil) | 323 (print-length nil) |
316 (print-readably t) ; This does something in Lucid Emacs. | 324 (print-readably t) ; This does something in Lucid Emacs. |
317 (float-output-format nil) | 325 (float-output-format nil) |
318 (done-any nil) | |
319 (visited (get-file-buffer file)) | 326 (visited (get-file-buffer file)) |
327 (absfile (expand-file-name file)) | |
328 relfile | |
329 ;; nil until we found a cookie. | |
320 output-start) | 330 output-start) |
321 | |
322 ;; If the autoload section we create here uses an absolute | |
323 ;; file name for FILE in its header, and then Emacs is installed | |
324 ;; under a different path on another system, | |
325 ;; `update-autoloads-here' won't be able to find the files to be | |
326 ;; autoloaded. So, if FILE is in the same directory or a | |
327 ;; subdirectory of the current buffer's directory, we'll make it | |
328 ;; relative to the current buffer's directory. | |
329 (setq file (expand-file-name file)) | |
330 (let* ((source-truename (file-truename file)) | |
331 (dir-truename (file-name-as-directory | |
332 (file-truename default-directory))) | |
333 (len (length dir-truename))) | |
334 (if (and (< len (length source-truename)) | |
335 (string= dir-truename (substring source-truename 0 len))) | |
336 (setq file (substring source-truename len)))) | |
337 | 331 |
338 (with-current-buffer (or visited | 332 (with-current-buffer (or visited |
339 ;; It is faster to avoid visiting the file. | 333 ;; It is faster to avoid visiting the file. |
340 (autoload-find-file file)) | 334 (autoload-find-file file)) |
341 ;; Obey the no-update-autoloads file local variable. | 335 ;; Obey the no-update-autoloads file local variable. |
342 (unless no-update-autoloads | 336 (unless no-update-autoloads |
343 (message "Generating autoloads for %s..." file) | 337 (message "Generating autoloads for %s..." file) |
344 (setq output-start (with-current-buffer outbuf (point))) | |
345 (save-excursion | 338 (save-excursion |
346 (save-restriction | 339 (save-restriction |
347 (widen) | 340 (widen) |
348 (goto-char (point-min)) | 341 (goto-char (point-min)) |
349 (while (not (eobp)) | 342 (while (not (eobp)) |
350 (skip-chars-forward " \t\n\f") | 343 (skip-chars-forward " \t\n\f") |
351 (cond | 344 (cond |
352 ((looking-at (regexp-quote generate-autoload-cookie)) | 345 ((looking-at (regexp-quote generate-autoload-cookie)) |
346 ;; If not done yet, figure out where to insert this text. | |
347 (unless output-start | |
348 (with-current-buffer outbuf | |
349 (setq relfile (file-relative-name absfile)) | |
350 (setq output-start (point))) | |
351 ;; (message "file=%S, relfile=%S, dest=%S" | |
352 ;; file relfile (autoload-generated-file)) | |
353 ) | |
353 (search-forward generate-autoload-cookie) | 354 (search-forward generate-autoload-cookie) |
354 (skip-chars-forward " \t") | 355 (skip-chars-forward " \t") |
355 (setq done-any t) | |
356 (if (eolp) | 356 (if (eolp) |
357 (condition-case err | 357 (condition-case err |
358 ;; Read the next form and make an autoload. | 358 ;; Read the next form and make an autoload. |
359 (let* ((form (prog1 (read (current-buffer)) | 359 (let* ((form (prog1 (read (current-buffer)) |
360 (or (bolp) (forward-line 1)))) | 360 (or (bolp) (forward-line 1)))) |
383 (forward-line 1)) | 383 (forward-line 1)) |
384 (t | 384 (t |
385 (forward-sexp 1) | 385 (forward-sexp 1) |
386 (forward-line 1)))))) | 386 (forward-line 1)))))) |
387 | 387 |
388 (when done-any | 388 (when output-start |
389 (with-current-buffer outbuf | 389 (with-current-buffer outbuf |
390 (save-excursion | 390 (save-excursion |
391 ;; Insert the section-header line which lists the file name | 391 ;; Insert the section-header line which lists the file name |
392 ;; and which functions are in it, etc. | 392 ;; and which functions are in it, etc. |
393 (goto-char output-start) | 393 (goto-char output-start) |
394 (autoload-insert-section-header | 394 (autoload-insert-section-header |
395 outbuf autoloads-done load-name file | 395 outbuf autoloads-done load-name relfile |
396 (nth 5 (file-attributes file))) | 396 (nth 5 (file-attributes relfile))) |
397 (insert ";;; Generated autoloads from " | 397 (insert ";;; Generated autoloads from " relfile "\n")) |
398 (autoload-trim-file-name file) "\n")) | |
399 (insert generate-autoload-section-trailer))) | 398 (insert generate-autoload-section-trailer))) |
400 (message "Generating autoloads for %s...done" file)) | 399 (message "Generating autoloads for %s...done" file)) |
401 (or visited | 400 (or visited |
402 ;; We created this buffer, so we should kill it. | 401 ;; We created this buffer, so we should kill it. |
403 (kill-buffer (current-buffer)))) | 402 (kill-buffer (current-buffer)))) |
404 (not done-any))) | 403 (not output-start))) |
405 | 404 |
406 ;;;###autoload | 405 ;;;###autoload |
407 (defun update-file-autoloads (file &optional save-after) | 406 (defun update-file-autoloads (file &optional save-after) |
408 "Update the autoloads for FILE in `generated-autoload-file' | 407 "Update the autoloads for FILE in `generated-autoload-file' |
409 \(which FILE might bind in its local variables). | 408 \(which FILE might bind in its local variables). |
465 (cond ((string= (nth 2 form) load-name) | 464 (cond ((string= (nth 2 form) load-name) |
466 ;; We found the section for this file. | 465 ;; We found the section for this file. |
467 ;; Check if it is up to date. | 466 ;; Check if it is up to date. |
468 (let ((begin (match-beginning 0)) | 467 (let ((begin (match-beginning 0)) |
469 (last-time (nth 4 form)) | 468 (last-time (nth 4 form)) |
470 (file-time (nth 5 (file-attributes file)))) | 469 (file-time (nth 5 (file-attributes file)))) |
471 (if (and (or (null existing-buffer) | 470 (if (and (or (null existing-buffer) |
472 (not (buffer-modified-p existing-buffer))) | 471 (not (buffer-modified-p existing-buffer))) |
473 (listp last-time) (= (length last-time) 2) | 472 (listp last-time) (= (length last-time) 2) |
474 (not (time-less-p last-time file-time))) | 473 (not (time-less-p last-time file-time))) |
475 (throw 'up-to-date nil) | 474 (throw 'up-to-date nil) |
476 (autoload-remove-section (match-beginning 0)) | 475 (autoload-remove-section begin) |
477 (setq found t)))) | 476 (setq found t)))) |
478 ((string< load-name (nth 2 form)) | 477 ((string< load-name (nth 2 form)) |
479 ;; We've come to a section alphabetically later than | 478 ;; We've come to a section alphabetically later than |
480 ;; LOAD-NAME. We assume the file is in order and so | 479 ;; LOAD-NAME. We assume the file is in order and so |
481 ;; there must be no section for LOAD-NAME. We will | 480 ;; there must be no section for LOAD-NAME. We will |