diff options
| author | Kim F. Storm | 2002-06-01 21:56:40 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2002-06-01 21:56:40 +0000 |
| commit | bbbbb15b5cd93167b2ed901c0862d6ac24baebaf (patch) | |
| tree | 8e72774568620027ce4813d1a1d170c79d999059 /lisp/simple.el | |
| parent | 36236b72327a86ced924d708fd78204b54c625d2 (diff) | |
| download | emacs-bbbbb15b5cd93167b2ed901c0862d6ac24baebaf.tar.gz emacs-bbbbb15b5cd93167b2ed901c0862d6ac24baebaf.zip | |
Reworked 2001-06-01 change.
(choose-completion-string1): Merged back into choose-completion-string.
(choose-completion-string): Run choose-completion-string-functions
after checking for proper minibuffer window. Added mini-p arg to
the hook functions. Insert choice if all hook functions return nil.
(choose-completion-string-functions): Doc update.
Diffstat (limited to 'lisp/simple.el')
| -rw-r--r-- | lisp/simple.el | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 5115fbef72f..9fc3144fb26 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -3778,11 +3778,15 @@ With prefix argument N, move N items (negative N means move backward)." | |||
| 3778 | (delete-char len))) | 3778 | (delete-char len))) |
| 3779 | 3779 | ||
| 3780 | (defvar choose-completion-string-functions nil | 3780 | (defvar choose-completion-string-functions nil |
| 3781 | "List of functions which may override the standard `choose-completion-string'. | 3781 | "Functions that may override the normal insertion of a completion choice. |
| 3782 | Each function in the list is called in turn with arguments CHOICE BUFFER BASE-SIZE | 3782 | These functions are called in order with four arguments: |
| 3783 | like choose-completion-string. If a function in the list returns non-nil, that | 3783 | CHOICE - the string to insert in the buffer, |
| 3784 | function is supposed to have inserted the completion in the minibuffer. | 3784 | BUFFER - the buffer in which the choice should be inserted, |
| 3785 | If all functions in the list return nil, use the default completion selection.") | 3785 | MINI-P - non-nil iff BUFFER is a minibuffer, and |
| 3786 | BASE-SIZE - the part of BUFFER which isn't part of completion. | ||
| 3787 | If a function in the list returns non-nil, that function is supposed | ||
| 3788 | to have inserted the CHOICE in the BUFFER, and possibly exited | ||
| 3789 | the minibuffer; no further functions will be called.") | ||
| 3786 | 3790 | ||
| 3787 | ;; Switch to BUFFER and insert the completion choice CHOICE. | 3791 | ;; Switch to BUFFER and insert the completion choice CHOICE. |
| 3788 | ;; BASE-SIZE, if non-nil, says how many characters of BUFFER's text | 3792 | ;; BASE-SIZE, if non-nil, says how many characters of BUFFER's text |
| @@ -3792,11 +3796,6 @@ If all functions in the list return nil, use the default completion selection.") | |||
| 3792 | ;; unless it is reading a file name and CHOICE is a directory, | 3796 | ;; unless it is reading a file name and CHOICE is a directory, |
| 3793 | ;; or completion-no-auto-exit is non-nil. | 3797 | ;; or completion-no-auto-exit is non-nil. |
| 3794 | (defun choose-completion-string (choice &optional buffer base-size) | 3798 | (defun choose-completion-string (choice &optional buffer base-size) |
| 3795 | (unless (run-hook-with-args-until-success | ||
| 3796 | 'choose-completion-string-functions choice buffer base-size) | ||
| 3797 | (choose-completion-string1 choice buffer base-size))) | ||
| 3798 | |||
| 3799 | (defun choose-completion-string1 (choice &optional buffer base-size) | ||
| 3800 | (let ((buffer (or buffer completion-reference-buffer)) | 3799 | (let ((buffer (or buffer completion-reference-buffer)) |
| 3801 | (mini-p (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer)))) | 3800 | (mini-p (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer)))) |
| 3802 | ;; If BUFFER is a minibuffer, barf unless it's the currently | 3801 | ;; If BUFFER is a minibuffer, barf unless it's the currently |
| @@ -3806,33 +3805,35 @@ If all functions in the list return nil, use the default completion selection.") | |||
| 3806 | (not (equal buffer | 3805 | (not (equal buffer |
| 3807 | (window-buffer (active-minibuffer-window)))))) | 3806 | (window-buffer (active-minibuffer-window)))))) |
| 3808 | (error "Minibuffer is not active for completion") | 3807 | (error "Minibuffer is not active for completion") |
| 3809 | ;; Insert the completion into the buffer where completion was requested. | 3808 | (unless (run-hook-with-args-until-success |
| 3810 | (set-buffer buffer) | 3809 | 'choose-completion-string-functions choice buffer mini-p base-size) |
| 3811 | (if base-size | 3810 | ;; Insert the completion into the buffer where completion was requested. |
| 3812 | (delete-region (+ base-size (if mini-p | 3811 | (set-buffer buffer) |
| 3813 | (minibuffer-prompt-end) | 3812 | (if base-size |
| 3814 | (point-min))) | 3813 | (delete-region (+ base-size (if mini-p |
| 3815 | (point)) | 3814 | (minibuffer-prompt-end) |
| 3816 | (choose-completion-delete-max-match choice)) | 3815 | (point-min))) |
| 3817 | (insert choice) | 3816 | (point)) |
| 3818 | (remove-text-properties (- (point) (length choice)) (point) | 3817 | (choose-completion-delete-max-match choice)) |
| 3819 | '(mouse-face nil)) | 3818 | (insert choice) |
| 3820 | ;; Update point in the window that BUFFER is showing in. | 3819 | (remove-text-properties (- (point) (length choice)) (point) |
| 3821 | (let ((window (get-buffer-window buffer t))) | 3820 | '(mouse-face nil)) |
| 3822 | (set-window-point window (point))) | 3821 | ;; Update point in the window that BUFFER is showing in. |
| 3823 | ;; If completing for the minibuffer, exit it with this choice. | 3822 | (let ((window (get-buffer-window buffer t))) |
| 3824 | (and (not completion-no-auto-exit) | 3823 | (set-window-point window (point))) |
| 3825 | (equal buffer (window-buffer (minibuffer-window))) | 3824 | ;; If completing for the minibuffer, exit it with this choice. |
| 3826 | minibuffer-completion-table | 3825 | (and (not completion-no-auto-exit) |
| 3827 | ;; If this is reading a file name, and the file name chosen | 3826 | (equal buffer (window-buffer (minibuffer-window))) |
| 3828 | ;; is a directory, don't exit the minibuffer. | 3827 | minibuffer-completion-table |
| 3829 | (if (and (eq minibuffer-completion-table 'read-file-name-internal) | 3828 | ;; If this is reading a file name, and the file name chosen |
| 3830 | (file-directory-p (field-string (point-max)))) | 3829 | ;; is a directory, don't exit the minibuffer. |
| 3831 | (let ((mini (active-minibuffer-window))) | 3830 | (if (and (eq minibuffer-completion-table 'read-file-name-internal) |
| 3832 | (select-window mini) | 3831 | (file-directory-p (field-string (point-max)))) |
| 3833 | (when minibuffer-auto-raise | 3832 | (let ((mini (active-minibuffer-window))) |
| 3834 | (raise-frame (window-frame mini)))) | 3833 | (select-window mini) |
| 3835 | (exit-minibuffer)))))) | 3834 | (when minibuffer-auto-raise |
| 3835 | (raise-frame (window-frame mini)))) | ||
| 3836 | (exit-minibuffer))))))) | ||
| 3836 | 3837 | ||
| 3837 | (defun completion-list-mode () | 3838 | (defun completion-list-mode () |
| 3838 | "Major mode for buffers showing lists of possible completions. | 3839 | "Major mode for buffers showing lists of possible completions. |