all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#59486: completion-auto-wrap disobeyed by vertical navigation
@ 2022-11-22 17:38 Juri Linkov
  2022-11-23 18:49 ` Juri Linkov
  0 siblings, 1 reply; 15+ messages in thread
From: Juri Linkov @ 2022-11-22 17:38 UTC (permalink / raw)
  To: 59486

[-- Attachment #1: Type: text/plain, Size: 219 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:


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

diff --git a/lisp/simple.el b/lisp/simple.el
index 0f44b14948c..459af2fcf55 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9572,6 +9574,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)
@@ -9736,6 +9740,77 @@ 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 ((column (current-column))
+        pos)
+    (catch 'bound
+      (while (> n 0)
+        (setq pos nil)
+        (save-excursion
+          (while (and (not pos) (not (eobp)))
+            (forward-line 1)
+            (when (and (not (eobp))
+                       (eq (move-to-column column) column)
+                       (get-text-property (point) 'mouse-face))
+              (setq pos (point)))))
+        (if pos
+            (goto-char pos)
+          (when completion-auto-wrap
+            (let ((column (current-column)))
+              (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) (not (eobp)))
+                  (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)
+        (save-excursion
+          (while (and (not pos) (not (bobp)))
+            (forward-line -1)
+            (when (and (not (bobp))
+                       (eq (move-to-column column) column)
+                       (get-text-property (point) 'mouse-face))
+              (setq pos (point)))))
+        (if pos
+            (goto-char pos)
+          (when completion-auto-wrap
+            (let ((column (current-column)))
+              (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) (not (bobp)))
+                  (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.

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-11-15 17:45 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.