bug#81411: 31.0.90; Selecting completion for completing-read-multiple does not respect completion boundaries

Eli Zaretskii <[email protected]> Sat, 01 Aug 2026 11:34:25 +0300
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> Cc: [email protected]
> Date: Tue, 14 Jul 2026 14:54:07 -0400
> From: Aaron Zeng via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email protected]>
> 
> When in a completing-read-multiple, selecting a completion to insert
> into the minibuffer does not respect the completion boundaries, leading
> to unexpected results.  A common example of a completion table with
> nontrivial boundaries is completion-file-name-table, although the use
> case I have in mind is with a custom, site-specific completion table.
> 
> Here is a quick example to reproduce from 'emacs -Q':
> 
> ```
> (defun crm-file-boundary-repro (reader)
>   (let* ((root (make-temp-file "crm-boundary-" 'directory))
>          (default-directory root))
>     (unwind-protect
>         (progn
>           (make-directory "dir")
>           (with-temp-file "dir/alpha" (insert ""))
>           (funcall reader
>                    "Pick: "
>                    #'completion-file-name-table
>                    nil t "dir/a"))
>       (delete-directory root t))))
> 
> (defun crm-file-boundary-repro-single ()
>   (interactive)
>   (message "Result: %S"
>            (crm-file-boundary-repro #'completing-read)))
> 
> (defun crm-file-boundary-repro-multiple ()
>   (interactive)
>   (message "Result: %S"
>            (crm-file-boundary-repro #'completing-read-multiple)))
> ```
> 
> Reproduction steps:
> 
> 1. Eval the above snippet
> 2. M-x crm-file-boundary-repro-single; initial input is "dir/a"
> 3. Press ? to show completions, then M-<down> to select the string "alpha"
> 4. Press M-RET: completing-read returns "dir/alpha" as expected
> 
> In contrast:
> 
> 5. M-x crm-file-boundary-repro-multiple; initial input is "dir/a"
> 6. Press ? to show completions, then M-<down> to select the string "alpha"
> 7. Press M-RET: the minibuffer contents are replaced by "alpha" ("dir/"
>    was erased unexpectedly).  completing-read-multiple does not return
>    because REQUIRE-MATCH was non-nil and the input does not match.
> 
>    Instead, inserting the completion should only affect the region after
>    "dir/".

Spencer and Stefan, any comments or suggestions?

> In GNU Emacs 31.0.90 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
>  version 1.15.12, Xaw scroll bars) of 2026-07-14 built on
>  igm-qws-u12685a
> Repository revision: 48a481ac8d8d0c2436ee343b582755d51c608374
> Repository branch: HEAD
> Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
> System Description: Rocky Linux 8.10 (Green Obsidian)
> 
> Configured using:
>  'configure --with-x-toolkit=lucid --without-gpm --without-gconf
>  --without-selinux --without-imagemagick --with-modules --with-gif=no
>  --with-cairo --with-rsvg --without-compress-install --with-tree-sitter
>  --with-native-compilation=aot
>  PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/'
> 
> Configured features:
> CAIRO DBUS FREETYPE GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBSYSTEMD
> LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP
> SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER X11 XDBE XIM
> XINERAMA XINPUT2 XPM XRANDR LUCID ZLIB
> 
> Important settings:
>   value of $LANG: en_US.utf8
>   locale-coding-system: utf-8-unix
> 
> Major mode: Lisp Interaction
> 
> Minor modes in effect:
>   tooltip-mode: t
>   global-eldoc-mode: t
>   eldoc-mode: t
>   show-paren-mode: t
>   electric-indent-mode: t
>   mouse-wheel-mode: t
>   tool-bar-mode: t
>   menu-bar-mode: t
>   file-name-shadow-mode: t
>   global-font-lock-mode: t
>   font-lock-mode: t
>   blink-cursor-mode: t
>   minibuffer-nonselected-mode: t
>   minibuffer-regexp-mode: t
>   line-number-mode: t
>   indent-tabs-mode: t
>   transient-mark-mode: t
>   auto-composition-mode: t
>   auto-encryption-mode: t
>   auto-compression-mode: t
> 
> Load-path shadows:
> None found.
> 
> Features:
> (shadow sort mail-extr emacsbug lisp-mnt message mailcap yank-media puny
> dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg
> rfc6068 epg-config gnus-util text-property-search time-date subr-x
> mule-util mm-decode mm-bodies mm-encode mailabbrev gmm-utils mailheader
> sendmail mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mm-util
> mail-prsvr mail-utils format-spec crm thingatpt comp-run bytecomp
> byte-compile comp-common rx warnings icons cl-loaddefs cl-lib rmc
> iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
> vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
> term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
> fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
> register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
> scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
> frame minibuffer nadvice seq simple cl-generic indonesian philippine
> cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
> korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
> european ethiopic indian cyrillic chinese composite emoji-zwj charscript
> charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
> cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
> files window text-properties overlay sha1 md5 base64 format env
> code-pages mule custom widget keymap hashtable-print-readable backquote
> threads dbusbind inotify dynamic-setting system-font-setting
> font-render-setting cairo x-toolkit xinput2 x multi-tty move-toolbar
> make-network-process tty-child-frames native-compile emacs)
> 
> Memory information:
> ((conses 16 58648 18691) (symbols 48 6366 0) (strings 32 16506 1939)
>  (string-bytes 1 565419) (vectors 16 9924)
>  (vector-slots 8 142174 9474) (floats 8 26 18) (intervals 56 331 0)
>  (buffers 1064 11))
> 
> 
> 
>