[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Suggestions for improvements to the *Completions* buffer
From: |
Philip Kaludercic |
Subject: |
Re: Suggestions for improvements to the *Completions* buffer |
Date: |
Sun, 19 Dec 2021 14:55:43 +0000 |
Juri Linkov <juri@linkov.net> writes:
>> The mechanism used to make backtab in the minibuffer switch to the last
>> completion option is not that nice as it uses this-command and
>> this-command-keys.
>
> When completion-auto-select is not enabled, TAB scrolls the completions buffer
> forward. So S-TAB (backtab) could scroll backward.
>
> When completion-auto-select will be enabled, backtab could switch to
> the completions as well, indeed.
How is this?
>From 6315289b47083c32ca28d2c582eb80b5c80345e0 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Thu, 9 Dec 2021 17:34:54 +0100
Subject: [PATCH 1/3] Allow for the completion buffer to be automatically
selected
* lisp/simple.el (completion-auto-select): Add new option.
(completion-setup-function): Respect completion-auto-select.
---
lisp/simple.el | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 26c3ff575e..d0e58575e1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9226,6 +9226,12 @@ completion-show-help
:version "22.1"
:group 'completion)
+(defcustom completion-auto-select t
+ "Non-nil means to automatically select the completions buffer."
+ :type 'boolean
+ :version "29.1"
+ :group 'completion)
+
;; This function goes in completion-setup-hook, so that it is called
;; after the text of the completion list buffer is written.
(defun completion-setup-function ()
@@ -9262,7 +9268,9 @@ completion-setup-function
(insert "Click on a completion to select it.\n"))
(insert (substitute-command-keys
"In this buffer, type \\[choose-completion] to \
-select the completion near point.\n\n"))))))
+select the completion near point.\n\n")))))
+ (when completion-auto-select
+ (switch-to-completions)))
(add-hook 'completion-setup-hook #'completion-setup-function)
--
2.30.2
>From 300b30423f1515d5d1b2fcc477185b79ac4bb832 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Thu, 9 Dec 2021 17:26:14 +0100
Subject: [PATCH 2/3] Allow for next-completion to wrap around the completion
buffer
* lisp/simple.el (completion-wrap-movement): Add new option.
(previous-completion): Update docstring.
(next-completion): Respect completion-wrap-movement.
(switch-to-completions): Handle backwards completion by jumping to the
end of the buffer.
* lisp/minibuffer.el: (minibuffer-local-completion-map): Bind
minibuffer-complete to backtab
(completion--in-region-1): Handle backtab to scroll backwards
---
lisp/minibuffer.el | 5 ++-
lisp/simple.el | 81 ++++++++++++++++++++++++++++++----------------
2 files changed, 57 insertions(+), 29 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 28bd1df59a..559e36e370 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1386,7 +1386,9 @@ completion--in-region-1
(set-window-start window (point-min) nil)
;; Else scroll down one screen.
(with-selected-window window
- (scroll-up)))
+ (if (equal (this-command-keys) [backtab])
+ (scroll-down)
+ (scroll-up))))
nil)))
;; If we're cycling, keep on cycling.
((and completion-cycling completion-all-sorted-completions)
@@ -2651,6 +2653,7 @@ minibuffer-local-completion-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map minibuffer-local-map)
(define-key map "\t" 'minibuffer-complete)
+ (define-key map [backtab] 'minibuffer-complete)
;; M-TAB is already abused for many other purposes, so we should find
;; another binding for it.
;; (define-key map "\e\t" 'minibuffer-force-complete)
diff --git a/lisp/simple.el b/lisp/simple.el
index d0e58575e1..626c24e10d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9027,38 +9027,57 @@ delete-completion-window
(if (get-buffer-window buf)
(select-window (get-buffer-window buf))))))
+(defcustom completion-wrap-movement t
+ "Non-nil means to wrap around when selecting completion options.
+This affects the commands `next-completion' and
+`previous-completion'."
+ :type 'boolean
+ :version "29.1"
+ :group 'completion)
+
(defun previous-completion (n)
- "Move to the previous item in the completion list."
+ "Move to the previous item in the completion list.
+With prefix argument N, move back N items (negative N means move
+forward)."
(interactive "p")
(next-completion (- n)))
(defun next-completion (n)
"Move to the next item in the completion list.
-With prefix argument N, move N items (negative N means move backward)."
+With prefix argument N, move N items (negative N means move
+backward)."
(interactive "p")
(let ((beg (point-min)) (end (point-max)))
- (while (and (> n 0) (not (eobp)))
- ;; If in a completion, move to the end of it.
- (when (get-text-property (point) 'mouse-face)
- (goto-char (next-single-property-change (point) 'mouse-face nil end)))
- ;; Move to start of next one.
- (unless (get-text-property (point) 'mouse-face)
- (goto-char (next-single-property-change (point) 'mouse-face nil end)))
- (setq n (1- n)))
- (while (and (< n 0) (not (bobp)))
- (let ((prop (get-text-property (1- (point)) 'mouse-face)))
- ;; If in a completion, move to the start of it.
- (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
- (goto-char (previous-single-property-change
- (point) 'mouse-face nil beg)))
- ;; Move to end of the previous completion.
- (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
- (goto-char (previous-single-property-change
- (point) 'mouse-face nil beg)))
- ;; Move to the start of that one.
- (goto-char (previous-single-property-change
- (point) 'mouse-face nil beg))
- (setq n (1+ n))))))
+ (catch 'bound
+ (while (> n 0)
+ ;; If in a completion, move to the end of it.
+ (when (get-text-property (point) 'mouse-face)
+ (goto-char (next-single-property-change (point) 'mouse-face nil
end)))
+ (when (and completion-wrap-movement (eobp))
+ (throw 'bound nil))
+ ;; Move to start of next one.
+ (unless (get-text-property (point) 'mouse-face)
+ (goto-char (next-single-property-change (point) 'mouse-face nil
end)))
+ (setq n (1- n)))
+ (while (< n 0)
+ (let ((prop (get-text-property (1- (point)) 'mouse-face)))
+ ;; If in a completion, move to the start of it.
+ (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
+ (goto-char (previous-single-property-change
+ (point) 'mouse-face nil beg)))
+ ;; Move to end of the previous completion.
+ (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
+ (goto-char (previous-single-property-change
+ (point) 'mouse-face nil beg)))
+ (when (and completion-wrap-movement (bobp))
+ (goto-char (next-single-property-change (point) 'mouse-face nil
end))
+ (throw 'bound nil))
+ ;; Move to the start of that one.
+ (goto-char (previous-single-property-change
+ (point) 'mouse-face nil beg))
+ (setq n (1+ n)))))
+ (when (/= 0 n)
+ (switch-to-minibuffer))))
(defun choose-completion (&optional event)
"Choose the completion at point.
@@ -9283,10 +9302,16 @@ switch-to-completions
(get-buffer-window "*Completions*" 0)))))
(when window
(select-window window)
- ;; In the new buffer, go to the first completion.
- ;; FIXME: Perhaps this should be done in `minibuffer-completion-help'.
- (when (bobp)
- (next-completion 1)))))
+ (cond
+ ((and (memq this-command '(completion-at-point minibuffer-complete))
+ (equal (this-command-keys) [backtab])
+ (bobp))
+ (goto-char (point-max))
+ (previous-completion 1))
+ ;; In the new buffer, go to the first completion.
+ ;; FIXME: Perhaps this should be done in `minibuffer-completion-help'.
+ ((bobp)
+ (next-completion 1))))))
(defun read-expression-switch-to-completions ()
"Select the completion list window while reading an expression."
--
2.30.2
>From 37af745b2f97ea7f9a719b4ba4c488bb8df0d79a Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Thu, 9 Dec 2021 17:36:14 +0100
Subject: [PATCH 3/3] Delete completion window on quitting
* lisp/simple.el (completion-list-mode-map): Rebind
delete-completion-window over keyboard-quit.
---
lisp/simple.el | 1 +
1 file changed, 1 insertion(+)
diff --git a/lisp/simple.el b/lisp/simple.el
index 626c24e10d..d30b52e286 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8980,6 +8980,7 @@ completion-list-mode-map
(define-key map [down-mouse-2] nil)
(define-key map "\C-m" 'choose-completion)
(define-key map "\e\e\e" 'delete-completion-window)
+ (define-key map [remap keyboard-quit] #'delete-completion-window)
(define-key map [left] 'previous-completion)
(define-key map [right] 'next-completion)
(define-key map [?\t] 'next-completion)
--
2.30.2
--
Philip Kaludercic
- Re: Suggestions for improvements to the *Completions* buffer, (continued)
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/13
- Re: Suggestions for improvements to the *Completions* buffer, Juri Linkov, 2021/12/14
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/17
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/17
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/18
- Re: Suggestions for improvements to the *Completions* buffer, Po Lu, 2021/12/18
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/18
- Re: Suggestions for improvements to the *Completions* buffer, Po Lu, 2021/12/19
- Re: Suggestions for improvements to the *Completions* buffer, Juri Linkov, 2021/12/18
- Re: Suggestions for improvements to the *Completions* buffer,
Philip Kaludercic <=
- Re: Suggestions for improvements to the *Completions* buffer, Juri Linkov, 2021/12/19
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/19
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/20
- Re: Suggestions for improvements to the *Completions* buffer, Juri Linkov, 2021/12/21
- Re: Suggestions for improvements to the *Completions* buffer, Philip Kaludercic, 2021/12/21
- Re: Suggestions for improvements to the *Completions* buffer, Daniel Semyonov, 2021/12/22
- Re: Suggestions for improvements to the *Completions* buffer, Juri Linkov, 2021/12/22
- Re: Suggestions for improvements to the *Completions* buffer, Daniel Semyonov, 2021/12/22
- Re: Suggestions for improvements to the *Completions* buffer, Juri Linkov, 2021/12/22
- Re: Suggestions for improvements to the *Completions* buffer, Eli Zaretskii, 2021/12/22