From: Juri Linkov <juri@linkov.net>
To: 59486@debbugs.gnu.org
Subject: bug#59486: completion-auto-wrap disobeyed by vertical navigation
Date: Tue, 31 Oct 2023 09:44:28 +0200 [thread overview]
Message-ID: <86r0lbuvrv.fsf@mail.linkov.net> (raw)
In-Reply-To: <86zgchbj61.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 23 Nov 2022 20:49:27 +0200")
[-- Attachment #1: Type: text/plain, Size: 256 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:
[-- Attachment #2: next-line-completion.patch --]
[-- Type: text/x-diff, Size: 5691 bytes --]
diff --git a/etc/NEWS b/etc/NEWS
index 9c0f28e3fa9..cabdfe50a19 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -999,8 +999,15 @@ A major mode based on the tree-sitter library for editing Elixir files.
*** New major mode 'lua-ts-mode'.
A major mode based on the tree-sitter library for editing Lua files.
+** Minibuffer and Completions
+
+*** New commands 'previous-line-completion' and 'next-line-completion'.
+Bound to [up] and [down] respectively, they navigate the *Completions*
+buffer vertically, wrapping at the top/bottom when 'completion-auto-wrap'
+is non-nil.
+
+++
-** New global minor mode 'minibuffer-regexp-mode'.
+*** New global minor mode 'minibuffer-regexp-mode'.
This is a minor mode for editing regular expressions in the minibuffer.
It highlights parens via ‘show-paren-mode’ and ‘blink-matching-paren’ in
a user-friendly way, avoids reporting alleged paren mismatches and makes
diff --git a/lisp/simple.el b/lisp/simple.el
index ec14bec9e07..b0782d1f8ae 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9820,6 +9827,8 @@ completion-list-mode-map
(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 [up] 'previous-line-completion)
+ (define-key map [down] 'next-line-completion)
(define-key map [left] 'previous-completion)
(define-key map [right] 'next-completion)
(define-key map [?\t] 'next-completion)
@@ -9882,7 +9891,8 @@ delete-completion-window
(defcustom completion-auto-wrap t
"Non-nil means to wrap around when selecting completion options.
-This affects the commands `next-completion' and `previous-completion'.
+This affects the commands `next-completion', `previous-completion',
+`next-line-completion' and `previous-line-completion'.
When `completion-auto-select' is t, it wraps through the minibuffer
for the commands bound to the TAB key."
:type 'boolean
@@ -10000,6 +10010,87 @@ next-completion
(when (/= 0 n)
(switch-to-minibuffer))))
+(defun previous-line-completion (&optional n)
+ "Move to the item on the previous line in the completion list.
+With prefix argument N, move back N items line-wise (negative N
+means move forward).
+
+Also see the `completion-auto-wrap' variable."
+ (interactive "p")
+ (next-line-completion (- n)))
+
+(defun next-line-completion (&optional n)
+ "Move to the item on the next line in the completion list.
+With prefix argument N, move N items line-wise (negative N
+means move backward).
+
+Also see the `completion-auto-wrap' variable."
+ (interactive "p")
+ (let (line column pos)
+ (when (and (bobp)
+ (> n 0)
+ (get-text-property (point) 'mouse-face)
+ (not (get-text-property (point) 'first-completion)))
+ (let ((inhibit-read-only t))
+ (add-text-properties (point) (1+ (point)) '(first-completion t)))
+ (setq n (1- n)))
+
+ (if (get-text-property (point) 'mouse-face)
+ ;; If in a completion, move to the start of it.
+ (when (and (not (bobp))
+ (get-text-property (1- (point)) 'mouse-face))
+ (goto-char (previous-single-property-change (point) 'mouse-face)))
+ ;; Try to move to the previous completion.
+ (setq pos (previous-single-property-change (point) 'mouse-face))
+ (if pos
+ ;; Move to the start of the previous completion.
+ (progn
+ (goto-char pos)
+ (unless (get-text-property (point) 'mouse-face)
+ (goto-char (previous-single-property-change
+ (point) 'mouse-face nil (point-min)))))
+ (cond ((> n 0) (setq n (1- n)) (first-completion))
+ ((< n 0) (first-completion)))))
+
+ (while (> n 0)
+ (setq pos nil column (current-column) line (line-number-at-pos))
+ (when (and (or (not (eq (forward-line 1) 0))
+ (eobp)
+ (not (eq (move-to-column column) column))
+ (not (get-text-property (point) 'mouse-face)))
+ completion-auto-wrap)
+ (save-excursion
+ (goto-char (point-min))
+ (when (and (eq (move-to-column column) column)
+ (get-text-property (point) 'mouse-face))
+ (setq pos (point)))
+ (while (and (not pos) (> line (line-number-at-pos)))
+ (forward-line 1)
+ (when (and (eq (move-to-column column) column)
+ (get-text-property (point) 'mouse-face))
+ (setq pos (point)))))
+ (if pos (goto-char pos)))
+ (setq n (1- n)))
+
+ (while (< n 0)
+ (setq pos nil column (current-column) line (line-number-at-pos))
+ (when (and (or (not (eq (forward-line -1) 0))
+ (not (eq (move-to-column column) column))
+ (not (get-text-property (point) 'mouse-face)))
+ completion-auto-wrap)
+ (save-excursion
+ (goto-char (point-max))
+ (when (and (eq (move-to-column column) column)
+ (get-text-property (point) 'mouse-face))
+ (setq pos (point)))
+ (while (and (not pos) (< line (line-number-at-pos)))
+ (forward-line -1)
+ (when (and (eq (move-to-column column) column)
+ (get-text-property (point) 'mouse-face))
+ (setq pos (point)))))
+ (if pos (goto-char pos)))
+ (setq n (1+ n)))))
+
(defun choose-completion (&optional event no-exit no-quit)
"Choose the completion at point.
If EVENT, use EVENT's position to determine the starting position.
next prev parent reply other threads:[~2023-10-31 7:44 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 [this message]
2023-11-01 17:45 ` Juri Linkov
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86r0lbuvrv.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).