diff options
| author | Stefan Monnier | 2007-06-25 03:48:10 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-06-25 03:48:10 +0000 |
| commit | ceea9b1803ec19805fd887c58eff545ae102b01c (patch) | |
| tree | 4d3add92bfb908113cf9552b51a58b87d980bc4f | |
| parent | 57536a837158dec3f2fa3635faa59c3fea0cd166 (diff) | |
| download | emacs-ceea9b1803ec19805fd887c58eff545ae102b01c.tar.gz emacs-ceea9b1803ec19805fd887c58eff545ae102b01c.zip | |
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.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/emacs-lisp/autoload.el | 59 |
2 files changed, 34 insertions, 30 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 25f4095c19a..78034f6032b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -4,6 +4,11 @@ | |||
| 4 | (autoload-find-destination): New function extracted from | 4 | (autoload-find-destination): New function extracted from |
| 5 | update-file-autoloads. | 5 | update-file-autoloads. |
| 6 | (update-file-autoloads): Use it. | 6 | (update-file-autoloads): Use it. |
| 7 | (autoload-generate-file-autoloads): New function extracted from | ||
| 8 | generate-file-autoloads. Use file-relative-name. Delay computation of | ||
| 9 | output-start to the first cookie. Remove done-any, replaced by | ||
| 10 | output-start. | ||
| 11 | (generate-file-autoloads): Use it. | ||
| 7 | 12 | ||
| 8 | 2007-06-24 Jay Belanger <jay.p.belanger@gmail.com> | 13 | 2007-06-24 Jay Belanger <jay.p.belanger@gmail.com> |
| 9 | 14 | ||
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el index eb2de503d54..01abb242ea8 100644 --- a/lisp/emacs-lisp/autoload.el +++ b/lisp/emacs-lisp/autoload.el | |||
| @@ -309,39 +309,32 @@ 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 | 331 | ||
| 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 | |||
| 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) |
| @@ -350,9 +343,16 @@ Return non-nil in the case where no autoloads were added at point." | |||
| 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. |
| @@ -385,23 +385,22 @@ Return non-nil in the case where no autoloads were added at point." | |||
| 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) |
| @@ -467,13 +466,13 @@ to call it from a dummy buffer if FILE is not currently visited." | |||
| 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 |