Mercurial > emacs
comparison lisp/simple.el @ 45612:e1b3f85895a5
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.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Sat, 01 Jun 2002 21:56:01 +0000 |
parents | 98941f178aa2 |
children | 58054a96d922 |
comparison
equal
deleted
inserted
replaced
45611:b234841ccaef | 45612:e1b3f85895a5 |
---|---|
3776 (setq len (1- len)) | 3776 (setq len (1- len)) |
3777 (forward-char 1)) | 3777 (forward-char 1)) |
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 |
3789 ;; to keep. If it is nil, use choose-completion-delete-max-match instead. | 3793 ;; to keep. If it is nil, use choose-completion-delete-max-match instead. |
3790 | 3794 |
3791 ;; If BUFFER is the minibuffer, exit the minibuffer | 3795 ;; If BUFFER is the minibuffer, exit the minibuffer |
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 |
3803 ;; active minibuffer. | 3802 ;; active minibuffer. |
3804 (if (and mini-p | 3803 (if (and mini-p |
3805 (or (not (active-minibuffer-window)) | 3804 (or (not (active-minibuffer-window)) |
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. |
3839 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\ | 3840 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\ |
3840 to select the completion near point. | 3841 to select the completion near point. |