bug#81645: 32.0.50; Annotations break *Completions* navigation in vertical format

Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
0. emacs -Q
1. (setopt completions-format 'vertical)
2. Sanity check: Typing `M-x auto- TAB' pops up the *Completions* buffer
   and you can navigate up and down through each column by typing
   `M-<DOWN>' and `M-<UP>' with wrapping from the last to the first
   candidate and vice versa.
3. Now type `M-x abbrev- TAB', then repeatedly type `M-<DOWN>': after
   the last candidate point wraps to the second instead of the first
   candidate.
4. Now type `M-x dabbrev- TAB'.  Now typing `M-<DOWN>' once moves to
   last candidate, but repeating `M-<DOWN>' does not move point (in
   particular, no wrapping).  Now typing `M-<UP>' moves point back to
   the first candidate, but typing `M-<UP>' again move point not to the
   beginning of the last candidate but to the middle of the annotation
   "(M-/)" affixed to the candidate.

The problems in 3 and 4 are due to the annotations in the *Completions*
buffer.  The attached patch fixes these problems, so that navigation in
3 and 4 work as in 2 according to my testing.  I think this patch should
be applied to the release branch because the type of navigation in
vertical format illustrated by 2 was introduced in Emacs 31 by commit
77ca60b48d01, which, however, failed to take annotations into account.


In GNU Emacs 32.0.50 (build 8, x86_64-pc-linux-gnu, GTK+ Version
 3.24.52, cairo version 1.18.4) of 2026-08-14 built on strobelfs
Repository revision: cb22cfe1414bc3aa5a0e0b54f41f5b3453cb1f01
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101024
System Description: Linux From Scratch r13.0-156

Configured using:
 'configure -C --with-native-compilation=no 'CFLAGS=-Og -g3'
 PKG_CONFIG_PATH=/opt/qt6/lib/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP
SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM
XINERAMA XINPUT2 XPM XRANDR GTK3 ZLIB
(unnamed) (text/x-patch, 877 B)
diff --git a/lisp/simple.el b/lisp/simple.el
index 1f7d57f299a..137734d9f03 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10176,8 +10176,11 @@ last-completion
           (last-col (progn
                       (first-completion)
                       (goto-char (pos-eol))
-                      (goto-char (previous-single-property-change
-                                  (point) 'mouse-face))
+                      ;; Go to the beginning of the candidate.  We loop
+                      ;; to move past any completion annotations.
+                      (while (not (get-text-property (point) 'mouse-face))
+                        (goto-char
+                         (previous-single-property-change (point) 'mouse-face)))
                       (current-column))))
       (if (zerop last-col)
           ;; If there is only one column of completions, the last
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.