aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/emacs-lisp/autoload.el124
2 files changed, 76 insertions, 61 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2ca3acd434a..25f4095c19a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12007-06-25 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/autoload.el: Refactor for upcoming changes.
4 (autoload-find-destination): New function extracted from
5 update-file-autoloads.
6 (update-file-autoloads): Use it.
7
12007-06-24 Jay Belanger <jay.p.belanger@gmail.com> 82007-06-24 Jay Belanger <jay.p.belanger@gmail.com>
2 9
3 * calc/calc-comb.el (math-init-random-base,math-prime-test): 10 * calc/calc-comb.el (math-init-random-base,math-prime-test):
@@ -6,7 +13,7 @@
6 13
7 * calc/calc-misc.el (math-div2-bignum): Use math-bignum-digit-size. 14 * calc/calc-misc.el (math-div2-bignum): Use math-bignum-digit-size.
8 15
9 * calc/calc-math.el (math-scale-bignum-digit-size): Renamed from 16 * calc/calc-math.el (math-scale-bignum-digit-size): Rename from
10 math-scale-bignum-3. 17 math-scale-bignum-3.
11 (math-isqrt-bignum): Use math-scale-bignum-digit-size and 18 (math-isqrt-bignum): Use math-scale-bignum-digit-size and
12 math-bignum-digit-size. 19 math-bignum-digit-size.
@@ -24,8 +31,8 @@
24 (bibtex-insert-kill, bibtex-mark-entry): Use push-mark. 31 (bibtex-insert-kill, bibtex-mark-entry): Use push-mark.
25 (bibtex-format-entry, bibtex-reformat): Handle new options of 32 (bibtex-format-entry, bibtex-reformat): Handle new options of
26 bibtex-entry-format. 33 bibtex-entry-format.
27 (bibtex-field-re-init, bibtex-font-lock-cite, bibtex-dist): New 34 (bibtex-field-re-init, bibtex-font-lock-cite, bibtex-dist):
28 functions. 35 New functions.
29 (bibtex-complete-internal): Do not display messages while 36 (bibtex-complete-internal): Do not display messages while
30 minibuffer is used. Do not leave around a completions buffer 37 minibuffer is used. Do not leave around a completions buffer
31 that is out of date. 38 that is out of date.
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el
index 47d167eeecc..eb2de503d54 100644
--- a/lisp/emacs-lisp/autoload.el
+++ b/lisp/emacs-lisp/autoload.el
@@ -412,74 +412,82 @@ save the buffer too.
412 412
413Return FILE if there was no autoload cookie in it, else nil." 413Return FILE if there was no autoload cookie in it, else nil."
414 (interactive "fUpdate autoloads for file: \np") 414 (interactive "fUpdate autoloads for file: \np")
415 (let ((existing-buffer (get-file-buffer file)))
416 (with-temp-buffer
417 ;; Let's presume the file is not visited, so we call
418 ;; autoload-find-destination from a dummy buffer, except if the file
419 ;; is visited, in which case we use that buffer instead.
420 (if existing-buffer (set-buffer existing-buffer))
421
422 (catch 'up-to-date
423 (let ((buf (autoload-find-destination file)))
424 (with-current-buffer buf
425 (let ((no-autoloads (generate-file-autoloads file)))
426
427 (and save-after
428 (buffer-modified-p)
429 (save-buffer))
430
431 (if no-autoloads file))))))))
432
433(defun autoload-find-destination (file)
434 "Find the destination point of the current buffer's autoloads.
435FILE is the file name of the current buffer.
436Returns a buffer whose point is placed at the requested location.
437Throws `up-to-date' if the file's autoloads are uptodate, otherwise
438removes any prior now out-of-date autoload entries.
439The current buffer only matters if it is visiting a file or if it has a buffer-local
440value for some variables such as `generated-autoload-file', so it's OK
441to call it from a dummy buffer if FILE is not currently visited."
442 ;; (message "autoload-find-destination %S" file)
415 (let ((load-name (autoload-file-load-name file)) 443 (let ((load-name (autoload-file-load-name file))
416 (found nil) 444 (existing-buffer (if buffer-file-name (current-buffer)))
417 (existing-buffer (get-file-buffer file)) 445 (found nil))
418 (no-autoloads nil)) 446 (with-current-buffer
419 (save-excursion 447 ;; We must read/write the file without any code conversion,
420 ;; We want to get a value for generated-autoload-file from 448 ;; but still decode EOLs.
421 ;; the local variables section if it's there. 449 (let ((coding-system-for-read 'raw-text))
422 (if existing-buffer 450 (find-file-noselect
423 (set-buffer existing-buffer)) 451 (autoload-ensure-default-file (autoload-generated-file))))
424 ;; We must read/write the file without any code conversion, 452 ;; This is to make generated-autoload-file have Unix EOLs, so
425 ;; but still decode EOLs. 453 ;; that it is portable to all platforms.
426 (let ((coding-system-for-read 'raw-text)) 454 (setq buffer-file-coding-system 'raw-text-unix)
427 (set-buffer (find-file-noselect
428 (autoload-ensure-default-file (autoload-generated-file))))
429 ;; This is to make generated-autoload-file have Unix EOLs, so
430 ;; that it is portable to all platforms.
431 (setq buffer-file-coding-system 'raw-text-unix))
432 (or (> (buffer-size) 0) 455 (or (> (buffer-size) 0)
433 (error "Autoloads file %s does not exist" buffer-file-name)) 456 (error "Autoloads file %s does not exist" buffer-file-name))
434 (or (file-writable-p buffer-file-name) 457 (or (file-writable-p buffer-file-name)
435 (error "Autoloads file %s is not writable" buffer-file-name)) 458 (error "Autoloads file %s is not writable" buffer-file-name))
436 (save-excursion 459 (widen)
437 (save-restriction 460 (goto-char (point-min))
438 (widen) 461 ;; Look for the section for LOAD-NAME.
439 (goto-char (point-min)) 462 (while (and (not found)
440 ;; Look for the section for LOAD-NAME. 463 (search-forward generate-autoload-section-header nil t))
441 (while (and (not found) 464 (let ((form (autoload-read-section-header)))
442 (search-forward generate-autoload-section-header nil t)) 465 (cond ((string= (nth 2 form) load-name)
443 (let ((form (autoload-read-section-header))) 466 ;; We found the section for this file.
444 (cond ((string= (nth 2 form) load-name) 467 ;; Check if it is up to date.
445 ;; We found the section for this file. 468 (let ((begin (match-beginning 0))
446 ;; Check if it is up to date. 469 (last-time (nth 4 form))
447 (let ((begin (match-beginning 0))
448 (last-time (nth 4 form))
449 (file-time (nth 5 (file-attributes file)))) 470 (file-time (nth 5 (file-attributes file))))
450 (if (and (or (null existing-buffer) 471 (if (and (or (null existing-buffer)
451 (not (buffer-modified-p existing-buffer))) 472 (not (buffer-modified-p existing-buffer)))
452 (listp last-time) (= (length last-time) 2) 473 (listp last-time) (= (length last-time) 2)
453 (not (time-less-p last-time file-time))) 474 (not (time-less-p last-time file-time)))
454 (progn 475 (throw 'up-to-date nil)
455 (if (interactive-p) 476 (autoload-remove-section (match-beginning 0))
456 (message "\ 477 (setq found t))))
457Autoload section for %s is up to date." 478 ((string< load-name (nth 2 form))
458 file)) 479 ;; We've come to a section alphabetically later than
459 (setq found 'up-to-date)) 480 ;; LOAD-NAME. We assume the file is in order and so
460 (search-forward generate-autoload-section-trailer) 481 ;; there must be no section for LOAD-NAME. We will
461 (delete-region begin (point)) 482 ;; insert one before the section here.
462 (setq found t)))) 483 (goto-char (match-beginning 0))
463 ((string< load-name (nth 2 form)) 484 (setq found t)))))
464 ;; We've come to a section alphabetically later than 485 (or found
465 ;; LOAD-NAME. We assume the file is in order and so 486 (progn
466 ;; there must be no section for LOAD-NAME. We will 487 ;; No later sections in the file. Put before the last page.
467 ;; insert one before the section here. 488 (goto-char (point-max))
468 (goto-char (match-beginning 0)) 489 (search-backward "\f" nil t)))
469 (setq found 'new))))) 490 (current-buffer))))
470 (or found
471 (progn
472 (setq found 'new)
473 ;; No later sections in the file. Put before the last page.
474 (goto-char (point-max))
475 (search-backward "\f" nil t)))
476 (or (eq found 'up-to-date)
477 (setq no-autoloads (generate-file-autoloads file)))))
478 (and save-after
479 (buffer-modified-p)
480 (save-buffer))
481
482 (if no-autoloads file))))
483 491
484(defun autoload-remove-section (begin) 492(defun autoload-remove-section (begin)
485 (goto-char begin) 493 (goto-char begin)