diff options
| author | Richard M. Stallman | 2001-06-20 11:03:58 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2001-06-20 11:03:58 +0000 |
| commit | 513e7954c847611f69aedbc134e8be542e83d90e (patch) | |
| tree | b8435c92d07d5513313a0c765be9e6cc7a6199d4 | |
| parent | 4de68712e34b609d7793461b468e1de14d23de6c (diff) | |
| download | emacs-513e7954c847611f69aedbc134e8be542e83d90e.tar.gz emacs-513e7954c847611f69aedbc134e8be542e83d90e.zip | |
(dabbrev--make-friend-buffer-list): New function,
broken out from dabbrev--find-expansion. Handle minibuffer
specially here.
(dabbrev--find-expansion): Simplify code in various ways.
Don't treat minibuffers specially.
Call dabbrev--make-friend-buffer-list.
(dabbrev--select-buffers): Don't treat minibuffers specially.
Simplify.
(dabbrev--scanning-message): Do nothing when minibuffer is current.
| -rw-r--r-- | lisp/dabbrev.el | 216 |
1 files changed, 114 insertions, 102 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 38c3a19b5ac..aa92a4cc6aa 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el | |||
| @@ -294,7 +294,7 @@ this list.") | |||
| 294 | ;; The list of remaining buffers with the same mode as current buffer. | 294 | ;; The list of remaining buffers with the same mode as current buffer. |
| 295 | (defvar dabbrev--friend-buffer-list nil) | 295 | (defvar dabbrev--friend-buffer-list nil) |
| 296 | 296 | ||
| 297 | ;; The buffer we looked in last. | 297 | ;; The buffer we looked in last, not counting the current buffer. |
| 298 | (defvar dabbrev--last-buffer nil) | 298 | (defvar dabbrev--last-buffer nil) |
| 299 | 299 | ||
| 300 | ;; The buffer we found the expansion last time. | 300 | ;; The buffer we found the expansion last time. |
| @@ -655,21 +655,21 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 655 | dabbrev--check-other-buffers dabbrev-check-other-buffers)) | 655 | dabbrev--check-other-buffers dabbrev-check-other-buffers)) |
| 656 | 656 | ||
| 657 | (defun dabbrev--select-buffers () | 657 | (defun dabbrev--select-buffers () |
| 658 | "Return a list of all buffers that should be searched for a possible abbrev. | 658 | "Return a list of other buffers to search for a possible abbrev. |
| 659 | 659 | The current buffer is not included in the list. | |
| 660 | This function makes a list of all the buffers returned by `buffer-list', and | 660 | |
| 661 | then filters out every buffer for which `dabbrev-friend-buffer-function', | 661 | This function makes a list of all the buffers returned by `buffer-list', |
| 662 | if it is bound, returns nil. The resulting partial list is returned." | 662 | then discards buffers whose names match `dabbrev-ignored-buffer-names' |
| 663 | (save-excursion | 663 | or `dabbrev-ignored-buffer-regexps'. It also discards buffers for which |
| 664 | (and (window-minibuffer-p (selected-window)) | 664 | `dabbrev-friend-buffer-function', if it is bound, returns nil when called |
| 665 | (set-buffer (dabbrev--minibuffer-origin))) | 665 | with the buffer as argument. |
| 666 | (let ((orig-buffer (current-buffer))) | 666 | It returns the list of the buffers that are not discarded." |
| 667 | (dabbrev-filter-elements | 667 | (dabbrev-filter-elements |
| 668 | buffer (buffer-list) | 668 | buffer (buffer-list) |
| 669 | (and (not (eq orig-buffer buffer)) | 669 | (and (not (eq (current-buffer) buffer)) |
| 670 | (not (dabbrev--ignore-buffer-p buffer)) | 670 | (not (dabbrev--ignore-buffer-p buffer)) |
| 671 | (boundp 'dabbrev-friend-buffer-function) | 671 | (boundp 'dabbrev-friend-buffer-function) |
| 672 | (funcall dabbrev-friend-buffer-function buffer)))))) | 672 | (funcall dabbrev-friend-buffer-function buffer))))) |
| 673 | 673 | ||
| 674 | (defun dabbrev--try-find (abbrev reverse n ignore-case) | 674 | (defun dabbrev--try-find (abbrev reverse n ignore-case) |
| 675 | "Search for ABBREV, backwards if REVERSE, N times. | 675 | "Search for ABBREV, backwards if REVERSE, N times. |
| @@ -705,7 +705,8 @@ If IGNORE-CASE is non-nil, accept matches which differ in case." | |||
| 705 | all-expansions)) | 705 | all-expansions)) |
| 706 | 706 | ||
| 707 | (defun dabbrev--scanning-message () | 707 | (defun dabbrev--scanning-message () |
| 708 | (message "Scanning `%s'" (buffer-name (current-buffer)))) | 708 | (unless (window-minibuffer-p (selected-window)) |
| 709 | (message "Scanning `%s'" (buffer-name (current-buffer))))) | ||
| 709 | 710 | ||
| 710 | (defun dabbrev--ignore-buffer-p (buffer) | 711 | (defun dabbrev--ignore-buffer-p (buffer) |
| 711 | "Return non-nil if BUFFER should be ignored by dabbrev." | 712 | "Return non-nil if BUFFER should be ignored by dabbrev." |
| @@ -728,93 +729,104 @@ This sets `dabbrev--last-direction' to 1 or -1 according | |||
| 728 | to the direction in which the occurrence was actually found. | 729 | to the direction in which the occurrence was actually found. |
| 729 | It sets `dabbrev--last-expansion-location' to the location | 730 | It sets `dabbrev--last-expansion-location' to the location |
| 730 | of the start of the occurrence." | 731 | of the start of the occurrence." |
| 731 | (let (expansion) | 732 | (save-excursion |
| 732 | (save-excursion | 733 | ;; If we were scanning something other than the current buffer, |
| 733 | (cond | 734 | ;; continue scanning there. |
| 734 | (dabbrev--last-buffer | 735 | (when dabbrev--last-buffer |
| 735 | (set-buffer dabbrev--last-buffer) | 736 | (set-buffer dabbrev--last-buffer) |
| 736 | (dabbrev--scanning-message)) | 737 | (dabbrev--scanning-message)) |
| 737 | ((and (not dabbrev-search-these-buffers-only) | 738 | (or |
| 738 | (window-minibuffer-p (selected-window))) | 739 | ;; ------------------------------------------ |
| 739 | (set-buffer (dabbrev--minibuffer-origin)) | 740 | ;; Look backward in current buffer. |
| 740 | ;; In the minibuffer-origin buffer we will only search from | 741 | ;; ------------------------------------------ |
| 741 | ;; the top and down. | 742 | (and (not dabbrev-search-these-buffers-only) |
| 742 | (goto-char (point-min)) | 743 | (>= direction 0) |
| 743 | (setq direction -1) | 744 | (setq dabbrev--last-direction (min 1 direction)) |
| 744 | (dabbrev--scanning-message))) | 745 | (dabbrev--try-find abbrev t |
| 745 | (cond | 746 | (max 1 direction) |
| 746 | ;; ------------------------------------------ | 747 | ignore-case)) |
| 747 | ;; Look backwards | 748 | ;; ------------------------------------------ |
| 748 | ;; ------------------------------------------ | 749 | ;; Look forward in current buffer |
| 749 | ((and (not dabbrev-search-these-buffers-only) | 750 | ;; or whatever buffer we were last scanning. |
| 750 | (>= direction 0) | 751 | ;; ------------------------------------------ |
| 751 | (setq dabbrev--last-direction (min 1 direction)) | 752 | (and (or (not dabbrev-search-these-buffers-only) |
| 752 | (setq expansion (dabbrev--try-find abbrev t | 753 | dabbrev--last-buffer) |
| 753 | (max 1 direction) | 754 | (<= direction 0) |
| 754 | ignore-case))) | 755 | (setq dabbrev--last-direction -1) |
| 755 | expansion) | 756 | (dabbrev--try-find abbrev nil |
| 756 | ;; ------------------------------------------ | 757 | (max 1 (- direction)) |
| 757 | ;; Look forward | 758 | ignore-case)) |
| 758 | ;; ------------------------------------------ | 759 | ;; ------------------------------------------ |
| 759 | ((and (or (not dabbrev-search-these-buffers-only) | 760 | ;; Look in other buffers. |
| 760 | dabbrev--last-buffer) | 761 | ;; Always start at (point-min) and look forward. |
| 761 | (<= direction 0) | 762 | ;; ------------------------------------------ |
| 762 | (setq dabbrev--last-direction -1) | 763 | (progn |
| 763 | (setq expansion (dabbrev--try-find abbrev nil | 764 | (setq dabbrev--last-direction -1) |
| 764 | (max 1 (- direction)) | 765 | (unless dabbrev--last-buffer |
| 765 | ignore-case))) | 766 | ;; If we have just now begun to search other buffers, |
| 766 | expansion) | 767 | ;; determine which other buffers we should check. |
| 767 | ;; ------------------------------------------ | 768 | ;; Put that list in dabbrev--friend-buffer-list. |
| 768 | ;; Look in other buffers. | 769 | (or dabbrev--friend-buffer-list |
| 769 | ;; Start at (point-min) and look forward. | 770 | (setq dabbrev--friend-buffer-list |
| 770 | ;; ------------------------------------------ | 771 | (dabbrev--make-friend-buffer-list)))) |
| 771 | (t | 772 | ;; Walk through the buffers till we find a match. |
| 772 | (setq dabbrev--last-direction -1) | 773 | (let (expansion) |
| 773 | ;; Make sure that we should check other buffers | 774 | (while (and (not expansion) dabbrev--friend-buffer-list) |
| 774 | (or dabbrev--friend-buffer-list | 775 | (setq dabbrev--last-buffer |
| 775 | dabbrev--last-buffer | 776 | (car dabbrev--friend-buffer-list)) |
| 776 | (setq dabbrev--friend-buffer-list | 777 | (setq dabbrev--friend-buffer-list |
| 777 | (mapcar (function get-buffer) | 778 | (cdr dabbrev--friend-buffer-list)) |
| 778 | dabbrev-search-these-buffers-only)) | 779 | (set-buffer dabbrev--last-buffer) |
| 779 | (not dabbrev--check-other-buffers) | 780 | (dabbrev--scanning-message) |
| 780 | (not (or (eq dabbrev--check-other-buffers t) | 781 | (setq dabbrev--last-expansion-location (point-min)) |
| 781 | (progn | 782 | (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case))) |
| 782 | (setq dabbrev--check-other-buffers | 783 | expansion))))) |
| 783 | (y-or-n-p "Scan other buffers also? "))))) | 784 | |
| 784 | (let* (friend-buffer-list non-friend-buffer-list) | 785 | ;; Compute the list of buffers to scan. |
| 785 | (setq dabbrev--friend-buffer-list | 786 | ;; If dabbrev-search-these-buffers-only, then the current buffer |
| 786 | (funcall dabbrev-select-buffers-function)) | 787 | ;; is included in this list if it should be searched. |
| 787 | (if dabbrev-check-all-buffers | 788 | ;; Otherwise, the current buffer is searched first specially., |
| 788 | (setq non-friend-buffer-list | 789 | ;; and it is not included in this list. |
| 790 | (defun dabbrev--make-friend-buffer-list () | ||
| 791 | (let ((list (mapcar (function get-buffer) | ||
| 792 | dabbrev-search-these-buffers-only))) | ||
| 793 | (when (and (null dabbrev-search-these-buffers-only) | ||
| 794 | dabbrev--check-other-buffers | ||
| 795 | (or (eq dabbrev--check-other-buffers t) | ||
| 796 | (setq dabbrev--check-other-buffers | ||
| 797 | (y-or-n-p "Scan other buffers also? ")))) | ||
| 798 | (setq list (funcall dabbrev-select-buffers-function)) | ||
| 799 | ;; If dabbrev-check-all-buffers, tack on all the other | ||
| 800 | ;; buffers at the end of the list, except those which are | ||
| 801 | ;; specifically to be ignored. | ||
| 802 | (if dabbrev-check-all-buffers | ||
| 803 | (setq list | ||
| 804 | (append list | ||
| 789 | (dabbrev-filter-elements | 805 | (dabbrev-filter-elements |
| 790 | buffer (buffer-list) | 806 | buffer (buffer-list) |
| 791 | (and (not (memq buffer dabbrev--friend-buffer-list)) | 807 | (and (not (memq buffer list)) |
| 792 | (not (dabbrev--ignore-buffer-p buffer)))) | 808 | (not (dabbrev--ignore-buffer-p buffer))))))) |
| 793 | dabbrev--friend-buffer-list | 809 | ;; Remove the current buffer. |
| 794 | (append dabbrev--friend-buffer-list | 810 | (setq list (delq (current-buffer) list))) |
| 795 | non-friend-buffer-list))))) | 811 | ;; Move buffers in the list that are visible on the screen |
| 796 | ;; Move buffers that are visible on the screen | 812 | ;; to the front of the list, but don't add anything to the list. |
| 797 | ;; to the front of the list. Remove the current buffer. | 813 | (if list |
| 798 | (when dabbrev--friend-buffer-list | 814 | (walk-windows (lambda (w) |
| 799 | (walk-windows (lambda (w) | 815 | (unless (eq w (selected-window)) |
| 800 | (unless (eq w (selected-window)) | 816 | (if (memq (window-buffer w) list) |
| 801 | (setq dabbrev--friend-buffer-list | 817 | (setq list |
| 802 | (cons (window-buffer w) | 818 | (cons (window-buffer w) |
| 803 | (delq (window-buffer w) | 819 | (delq (window-buffer w) |
| 804 | dabbrev--friend-buffer-list)))))) | 820 | list)))))))) |
| 805 | (setq dabbrev--friend-buffer-list | 821 | ;; In a minibuffer, search the buffer it was activated from, |
| 806 | (delq (current-buffer) dabbrev--friend-buffer-list))) | 822 | ;; first after the minibuffer itself. Unless we aren't supposed |
| 807 | ;; Walk through the buffers | 823 | ;; to search the current buffer either. |
| 808 | (while (and (not expansion) dabbrev--friend-buffer-list) | 824 | (if (and (window-minibuffer-p (selected-window)) |
| 809 | (setq dabbrev--last-buffer | 825 | (not dabbrev-search-these-buffers-only)) |
| 810 | (car dabbrev--friend-buffer-list)) | 826 | (setq list |
| 811 | (setq dabbrev--friend-buffer-list | 827 | (cons (dabbrev--minibuffer-origin) |
| 812 | (cdr dabbrev--friend-buffer-list)) | 828 | (delq (dabbrev--minibuffer-origin) list)))) |
| 813 | (set-buffer dabbrev--last-buffer) | 829 | list)) |
| 814 | (dabbrev--scanning-message) | ||
| 815 | (setq dabbrev--last-expansion-location (point-min)) | ||
| 816 | (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case))) | ||
| 817 | expansion))))) | ||
| 818 | 830 | ||
| 819 | (defun dabbrev--safe-replace-match (string &optional fixedcase literal) | 831 | (defun dabbrev--safe-replace-match (string &optional fixedcase literal) |
| 820 | (if (eq major-mode 'picture-mode) | 832 | (if (eq major-mode 'picture-mode) |