Mercurial > emacs
comparison lisp/emacs-lisp/autoload.el @ 81602:ea507ef94ad6
Refactor for upcoming changes.
(autoload-find-destination): New function extracted from update-file-autoloads.
(update-file-autoloads): Use it.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 25 Jun 2007 03:01:22 +0000 |
parents | ffabac9ec014 |
children | 6a5ecb520686 |
comparison
equal
deleted
inserted
replaced
81601:509be28863a8 | 81602:ea507ef94ad6 |
---|---|
410 If SAVE-AFTER is non-nil (which is always, when called interactively), | 410 If SAVE-AFTER is non-nil (which is always, when called interactively), |
411 save the buffer too. | 411 save the buffer too. |
412 | 412 |
413 Return FILE if there was no autoload cookie in it, else nil." | 413 Return 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. | |
435 FILE is the file name of the current buffer. | |
436 Returns a buffer whose point is placed at the requested location. | |
437 Throws `up-to-date' if the file's autoloads are uptodate, otherwise | |
438 removes any prior now out-of-date autoload entries. | |
439 The current buffer only matters if it is visiting a file or if it has a buffer-local | |
440 value for some variables such as `generated-autoload-file', so it's OK | |
441 to 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)))) |
457 Autoload 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) |
486 (search-forward generate-autoload-section-trailer) | 494 (search-forward generate-autoload-section-trailer) |
487 (delete-region begin (point))) | 495 (delete-region begin (point))) |