all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 59486@debbugs.gnu.org
Subject: bug#59486: completion-auto-wrap disobeyed by vertical navigation
Date: Wed, 01 Nov 2023 19:45:50 +0200	[thread overview]
Message-ID: <86a5rxwf9v.fsf@mail.linkov.net> (raw)
In-Reply-To: <86r0lbuvrv.fsf@mail.linkov.net> (Juri Linkov's message of "Tue,  31 Oct 2023 09:44:28 +0200")

[-- Attachment #1: Type: text/plain, Size: 608 bytes --]

>> In a multi-column layout, the keys <left> and <right>
>> wrap to the beginning/end of the completions buffer,
>> but <up> and <down> don't.  Here is a patch that supports
>> completion-auto-wrap for wrapping to the top/bottom:
>
> Ok, here is a better patch:

Pushed to master.

Now here is a patch that implements the long-discussed feature of
using arrow keys for navigating completions from the minibuffer
only when the *Completions* buffer is visible.

It's disabled by default and can be enabled by the option
'minibuffer-completion-visible'.  It works nicely for
the in-buffer completions as well:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: minibuffer-completion-visible.patch --]
[-- Type: text/x-diff, Size: 4743 bytes --]

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 2120e31775e..2601e705aa0 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2707,8 +2716,14 @@ completion-in-region-mode
 	  completion-in-region-mode-predicate)
     (setq-local minibuffer-completion-auto-choose nil)
     (add-hook 'post-command-hook #'completion-in-region--postch)
-    (push `(completion-in-region-mode . ,completion-in-region-mode-map)
-          minor-mode-overriding-map-alist)))
+    (let* ((keymap completion-in-region-mode-map)
+           (keymap (if minibuffer-completion-visible
+                       (make-composed-keymap
+                        (list minibuffer-local-visible-completion-map
+                              keymap))
+                     keymap)))
+      (push `(completion-in-region-mode . ,keymap)
+            minor-mode-overriding-map-alist))))
 
 ;; Define-minor-mode added our keymap to minor-mode-map-alist, but we want it
 ;; on minor-mode-overriding-map-alist instead.
@@ -2953,7 +2972,32 @@ minibuffer-mode
   :interactive nil
   ;; Enable text conversion, but always make sure `RET' does
   ;; something.
-  (setq text-conversion-style 'action))
+  (setq text-conversion-style 'action)
+  (when minibuffer-completion-visible
+    (setq-local minibuffer-completion-auto-choose nil)))
+
+(defcustom minibuffer-completion-visible t
+  "Non-nil means to navigate completions with arrows from the minibuffer.
+This has effect only when the window with the *Completions* buffer
+is visible on the screen."
+  :type 'boolean
+  :version "30.1")
+
+(defun minibuffer-bind-visible (binding)
+  `(menu-item
+    "" ,binding
+    :filter ,(lambda (cmd)
+               (when (get-buffer-window "*Completions*" 0)
+                 cmd))))
+
+(defvar-keymap minibuffer-local-visible-completion-map
+  :doc "Local keymap for minibuffer input with visible completions."
+  "<left>"  (minibuffer-bind-visible #'minibuffer-previous-completion)
+  "<right>" (minibuffer-bind-visible #'minibuffer-next-completion)
+  "<up>"    (minibuffer-bind-visible #'minibuffer-previous-line-completion)
+  "<down>"  (minibuffer-bind-visible #'minibuffer-next-line-completion)
+  "RET"     (minibuffer-bind-visible #'minibuffer-choose-completion)
+  "C-g"     (minibuffer-bind-visible #'minibuffer-hide-completions))
 
 ;;; Completion tables.
 
@@ -4370,6 +4414,11 @@ completing-read-default
                     ;; in minibuffer-local-filename-completion-map can
                     ;; override bindings in base-keymap.
                     base-keymap)))
+         (keymap (if minibuffer-completion-visible
+                     (make-composed-keymap
+                      (list minibuffer-local-visible-completion-map
+                            keymap))
+                   keymap))
          (buffer (current-buffer))
          (c-i-c completion-ignore-case)
          (result
@@ -4489,8 +4538,9 @@ minibuffer-completion-auto-choose
   :type 'boolean
   :version "29.1")
 
-(defun minibuffer-next-completion (&optional n)
+(defun minibuffer-next-completion (&optional n vertical)
   "Move to the next item in its completions window from the minibuffer.
+When the optional argument VERTICAL is non-nil, move vertically.
 When `minibuffer-completion-auto-choose' is non-nil, then also
 insert the selected completion to the minibuffer."
   (interactive "p")
@@ -4498,7 +4548,9 @@ minibuffer-next-completion
     (with-minibuffer-completions-window
       (when completions-highlight-face
         (setq-local cursor-face-highlight-nonselected-window t))
-      (next-completion (or n 1))
+      (if vertical
+          (next-line-completion (or n 1))
+        (next-completion (or n 1)))
       (when auto-choose
         (let ((completion-use-base-affixes t))
           (choose-completion nil t t))))))
@@ -4510,6 +4562,20 @@ minibuffer-previous-completion
   (interactive "p")
   (minibuffer-next-completion (- (or n 1))))
 
+(defun minibuffer-next-line-completion (&optional n)
+  "Move to the next completion line from the minibuffer.
+When `minibuffer-completion-auto-choose' is non-nil, then also
+insert the selected completion to the minibuffer."
+  (interactive "p")
+  (minibuffer-next-completion (or n 1) t))
+
+(defun minibuffer-previous-line-completion (&optional n)
+  "Move to the previous completion line from the minibuffer.
+When `minibuffer-completion-auto-choose' is non-nil, then also
+insert the selected completion to the minibuffer."
+  (interactive "p")
+  (minibuffer-next-completion (- (or n 1)) t))
+
 (defun minibuffer-choose-completion (&optional no-exit no-quit)
   "Run `choose-completion' from the minibuffer in its completions window.
 With prefix argument NO-EXIT, insert the completion at point to the

  reply	other threads:[~2023-11-01 17:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 17:38 bug#59486: completion-auto-wrap disobeyed by vertical navigation Juri Linkov
2022-11-23 18:49 ` Juri Linkov
2022-11-24  7:59   ` Juri Linkov
2022-11-24  8:13     ` Eli Zaretskii
2022-11-24 18:30       ` Juri Linkov
2022-11-24 18:43         ` Eli Zaretskii
2022-11-25  7:47           ` Juri Linkov
2022-11-25  8:38             ` Eli Zaretskii
2022-11-28  7:56               ` Juri Linkov
2023-10-31  7:44   ` Juri Linkov
2023-11-01 17:45     ` Juri Linkov [this message]
2023-11-02  8:11       ` Eli Zaretskii
2023-11-02 17:14         ` Juri Linkov
2023-11-05 17:53           ` Juri Linkov
2023-11-15 17:45             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86a5rxwf9v.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=59486@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.