diff options
| author | Stefan Monnier | 2006-05-29 02:53:14 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2006-05-29 02:53:14 +0000 |
| commit | b17b883963111c8b1d47b397f361d4d0daa50a11 (patch) | |
| tree | f3978a6800ef80a04ef70e91d1fc814deaacb697 | |
| parent | 69135525601292d74ceb4dd80759e71a4a553d3a (diff) | |
| download | emacs-b17b883963111c8b1d47b397f361d4d0daa50a11.tar.gz emacs-b17b883963111c8b1d47b397f361d4d0daa50a11.zip | |
(no-update-autoloads): Declare.
(generate-file-autoloads): Obey it. Return whether autoloads were
added at point or not.
(update-file-autoloads): Use this new return value.
Remove redundant test for the presence of an autoload cookie.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/autoload.el | 159 |
2 files changed, 78 insertions, 87 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f75a7b7ae99..6dd176768be 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2006-05-28 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2006-05-28 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * emacs-lisp/autoload.el (no-update-autoloads): Declare. | ||
| 4 | (generate-file-autoloads): Obey it. Return whether autoloads were | ||
| 5 | added at point or not. | ||
| 6 | (update-file-autoloads): Use this new return value. | ||
| 7 | Remove redundant test for the presence of an autoload cookie. | ||
| 8 | |||
| 3 | * emacs-lisp/autoload.el (autoload-find-file): New fun. | 9 | * emacs-lisp/autoload.el (autoload-find-file): New fun. |
| 4 | This one calls hack-local-variables. | 10 | This one calls hack-local-variables. |
| 5 | (generate-file-autoloads, update-file-autoloads): Use it. | 11 | (generate-file-autoloads, update-file-autoloads): Use it. |
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el index 57e767db873..76699f10df8 100644 --- a/lisp/emacs-lisp/autoload.el +++ b/lisp/emacs-lisp/autoload.el | |||
| @@ -287,12 +287,16 @@ which lists the file name and which functions are in it, etc." | |||
| 287 | (hack-local-variables)) | 287 | (hack-local-variables)) |
| 288 | (current-buffer))) | 288 | (current-buffer))) |
| 289 | 289 | ||
| 290 | (defvar no-update-autoloads nil | ||
| 291 | "File local variable to prevent scanning this file for autoload cookies.") | ||
| 292 | |||
| 290 | (defun generate-file-autoloads (file) | 293 | (defun generate-file-autoloads (file) |
| 291 | "Insert at point a loaddefs autoload section for FILE. | 294 | "Insert at point a loaddefs autoload section for FILE. |
| 292 | autoloads are generated for defuns and defmacros in FILE | 295 | Autoloads are generated for defuns and defmacros in FILE |
| 293 | marked by `generate-autoload-cookie' (which see). | 296 | marked by `generate-autoload-cookie' (which see). |
| 294 | If FILE is being visited in a buffer, the contents of the buffer | 297 | If FILE is being visited in a buffer, the contents of the buffer |
| 295 | are used." | 298 | are used. |
| 299 | Return non-nil in the case where no autoloads were added at point." | ||
| 296 | (interactive "fGenerate autoloads for file: ") | 300 | (interactive "fGenerate autoloads for file: ") |
| 297 | (let ((outbuf (current-buffer)) | 301 | (let ((outbuf (current-buffer)) |
| 298 | (autoloads-done '()) | 302 | (autoloads-done '()) |
| @@ -305,7 +309,7 @@ are used." | |||
| 305 | (float-output-format nil) | 309 | (float-output-format nil) |
| 306 | (done-any nil) | 310 | (done-any nil) |
| 307 | (visited (get-file-buffer file)) | 311 | (visited (get-file-buffer file)) |
| 308 | output-end) | 312 | output-start) |
| 309 | 313 | ||
| 310 | ;; If the autoload section we create here uses an absolute | 314 | ;; If the autoload section we create here uses an absolute |
| 311 | ;; file name for FILE in its header, and then Emacs is installed | 315 | ;; file name for FILE in its header, and then Emacs is installed |
| @@ -323,68 +327,70 @@ are used." | |||
| 323 | (string= dir-truename (substring source-truename 0 len))) | 327 | (string= dir-truename (substring source-truename 0 len))) |
| 324 | (setq file (substring source-truename len)))) | 328 | (setq file (substring source-truename len)))) |
| 325 | 329 | ||
| 326 | (message "Generating autoloads for %s..." file) | 330 | (with-current-buffer (or visited |
| 327 | (save-excursion | 331 | ;; It is faster to avoid visiting the file. |
| 328 | (unwind-protect | 332 | (autoload-find-file file)) |
| 329 | (progn | 333 | ;; Obey the no-update-autoloads file local variable. |
| 330 | (set-buffer (or visited | 334 | (unless no-update-autoloads |
| 331 | ;; It is faster to avoid visiting the file. | 335 | (message "Generating autoloads for %s..." file) |
| 332 | (autoload-find-file file))) | 336 | (setq output-start (with-current-buffer outbuf (point))) |
| 333 | (save-excursion | 337 | (save-excursion |
| 334 | (save-restriction | 338 | (save-restriction |
| 335 | (widen) | 339 | (widen) |
| 336 | (goto-char (point-min)) | 340 | (goto-char (point-min)) |
| 337 | (while (not (eobp)) | 341 | (while (not (eobp)) |
| 338 | (skip-chars-forward " \t\n\f") | 342 | (skip-chars-forward " \t\n\f") |
| 339 | (cond | 343 | (cond |
| 340 | ((looking-at (regexp-quote generate-autoload-cookie)) | 344 | ((looking-at (regexp-quote generate-autoload-cookie)) |
| 341 | (search-forward generate-autoload-cookie) | 345 | (search-forward generate-autoload-cookie) |
| 342 | (skip-chars-forward " \t") | 346 | (skip-chars-forward " \t") |
| 343 | (setq done-any t) | 347 | (setq done-any t) |
| 344 | (if (eolp) | 348 | (if (eolp) |
| 345 | ;; Read the next form and make an autoload. | 349 | ;; Read the next form and make an autoload. |
| 346 | (let* ((form (prog1 (read (current-buffer)) | 350 | (let* ((form (prog1 (read (current-buffer)) |
| 347 | (or (bolp) (forward-line 1)))) | 351 | (or (bolp) (forward-line 1)))) |
| 348 | (autoload (make-autoload form load-name))) | 352 | (autoload (make-autoload form load-name))) |
| 349 | (if autoload | 353 | (if autoload |
| 350 | (push (nth 1 form) autoloads-done) | 354 | (push (nth 1 form) autoloads-done) |
| 351 | (setq autoload form)) | 355 | (setq autoload form)) |
| 352 | (let ((autoload-print-form-outbuf outbuf)) | 356 | (let ((autoload-print-form-outbuf outbuf)) |
| 353 | (autoload-print-form autoload))) | 357 | (autoload-print-form autoload))) |
| 354 | 358 | ||
| 355 | ;; Copy the rest of the line to the output. | 359 | ;; Copy the rest of the line to the output. |
| 356 | (princ (buffer-substring | 360 | (princ (buffer-substring |
| 357 | (progn | 361 | (progn |
| 358 | ;; Back up over whitespace, to preserve it. | 362 | ;; Back up over whitespace, to preserve it. |
| 359 | (skip-chars-backward " \f\t") | 363 | (skip-chars-backward " \f\t") |
| 360 | (if (= (char-after (1+ (point))) ? ) | 364 | (if (= (char-after (1+ (point))) ? ) |
| 361 | ;; Eat one space. | 365 | ;; Eat one space. |
| 362 | (forward-char 1)) | 366 | (forward-char 1)) |
| 363 | (point)) | 367 | (point)) |
| 364 | (progn (forward-line 1) (point))) | 368 | (progn (forward-line 1) (point))) |
| 365 | outbuf))) | 369 | outbuf))) |
| 366 | ((looking-at ";") | 370 | ((looking-at ";") |
| 367 | ;; Don't read the comment. | 371 | ;; Don't read the comment. |
| 368 | (forward-line 1)) | 372 | (forward-line 1)) |
| 369 | (t | 373 | (t |
| 370 | (forward-sexp 1) | 374 | (forward-sexp 1) |
| 371 | (forward-line 1))))))) | 375 | (forward-line 1)))))) |
| 372 | (or visited | 376 | |
| 373 | ;; We created this buffer, so we should kill it. | 377 | (when done-any |
| 374 | (kill-buffer (current-buffer))) | 378 | (with-current-buffer outbuf |
| 375 | (set-buffer outbuf) | 379 | (save-excursion |
| 376 | (setq output-end (point-marker)))) | 380 | ;; Insert the section-header line which lists the file name |
| 377 | (if done-any | 381 | ;; and which functions are in it, etc. |
| 378 | (progn | 382 | (goto-char output-start) |
| 379 | ;; Insert the section-header line | 383 | (autoload-insert-section-header |
| 380 | ;; which lists the file name and which functions are in it, etc. | 384 | outbuf autoloads-done load-name file |
| 381 | (autoload-insert-section-header outbuf autoloads-done load-name file | 385 | (nth 5 (file-attributes file))) |
| 382 | (nth 5 (file-attributes file))) | 386 | (insert ";;; Generated autoloads from " |
| 383 | (insert ";;; Generated autoloads from " | 387 | (autoload-trim-file-name file) "\n")) |
| 384 | (autoload-trim-file-name file) "\n") | 388 | (insert generate-autoload-section-trailer))) |
| 385 | (goto-char output-end) | 389 | (message "Generating autoloads for %s...done" file)) |
| 386 | (insert generate-autoload-section-trailer))) | 390 | (or visited |
| 387 | (message "Generating autoloads for %s...done" file))) | 391 | ;; We created this buffer, so we should kill it. |
| 392 | (kill-buffer (current-buffer)))) | ||
| 393 | (not done-any))) | ||
| 388 | 394 | ||
| 389 | ;;;###autoload | 395 | ;;;###autoload |
| 390 | (defun update-file-autoloads (file &optional save-after) | 396 | (defun update-file-autoloads (file &optional save-after) |
| @@ -463,28 +469,7 @@ Autoload section for %s is up to date." | |||
| 463 | (goto-char (point-max)) | 469 | (goto-char (point-max)) |
| 464 | (search-backward "\f" nil t))) | 470 | (search-backward "\f" nil t))) |
| 465 | (or (eq found 'up-to-date) | 471 | (or (eq found 'up-to-date) |
| 466 | (and (eq found 'new) | 472 | (setq no-autoloads (generate-file-autoloads file))))) |
| 467 | ;; Check that FILE has any cookies before generating a | ||
| 468 | ;; new section for it. | ||
| 469 | (with-current-buffer | ||
| 470 | (or existing-buffer | ||
| 471 | ;; It is faster to avoid visiting the file. | ||
| 472 | (autoload-find-file file)) | ||
| 473 | (save-excursion | ||
| 474 | (save-restriction | ||
| 475 | (widen) | ||
| 476 | (goto-char (point-min)) | ||
| 477 | (prog1 | ||
| 478 | (setq no-autoloads | ||
| 479 | (not (re-search-forward | ||
| 480 | (concat "^" (regexp-quote | ||
| 481 | generate-autoload-cookie)) | ||
| 482 | nil t))) | ||
| 483 | (if (and no-autoloads (interactive-p)) | ||
| 484 | (message "%s has no autoloads" file)) | ||
| 485 | (or existing-buffer | ||
| 486 | (kill-buffer (current-buffer)))))))) | ||
| 487 | (generate-file-autoloads file)))) | ||
| 488 | (and save-after | 473 | (and save-after |
| 489 | (buffer-modified-p) | 474 | (buffer-modified-p) |
| 490 | (save-buffer)) | 475 | (save-buffer)) |