bug#81537: 32.0.50; Fixing icomplete-in-buffer requiring users to advice-add
Sean Whitton <[email protected]> Mon, 03 Aug 2026 11:50:58 +0100
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
Version: 32.1
Juri Linkov [02/Aug 6:16pm +03] wrote:
>> We've discussed this before and Eshel and Juri suggested that the thing
>> to do is make icomplete-in-buffer a proper completion-in-region-function
>> value, instead of hanging off the default completion infrastructure as
>> it does now.
>
> Shouldn't the UI of icomplete-in-buffer be the same as the UI
> of icomplete in the minibuffer? That is, only when the user
> types TAB, it should display the *Completions* buffer,
> either in the minibuffer or in the regular buffer.
> But otherwise on typing characters it should display inline
> candidates immediately, without requiring to type TAB,
> i.e. something like 'completion-preview-mode' already does.
I think I've figured out an implementation of this.
Installed and closing, thanks both.
--
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 7ef6f1383ab..24156ded8b3 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1581,6 +1581,9 @@ completion--in-boundaries-p
(end (+ (length string) (cdr boundaries))))
(>= start pos end)))
+(defun completion--icomplete-in-buffer-p ()
+ (eq (bound-and-true-p icomplete--in-region-buffer) (current-buffer)))
+
(defun completion--do-completion (beg end &optional
try-completion-function expect-exact)
"Do the completion and return a summary of what happened.
@@ -1686,6 +1689,7 @@ completion--do-completion
(minibuffer-force-complete beg end))
((or completed only-changed-boundaries)
(cond
+ ((completion--icomplete-in-buffer-p)) ; Bug#81537.
((pcase completion-auto-help
('visible (minibuffer--completions-visible))
('always t))
@@ -1699,14 +1703,16 @@ completion--do-completion
'exact 'unknown))))))
;; Show the completion table, if requested.
((not exact)
- (if (pcase completion-auto-help
- ('lazy (eq this-command last-command))
- (_ completion-auto-help))
+ (if (if (or (eq completion-auto-help 'lazy)
+ (completion--icomplete-in-buffer-p)) ; Bug#81537.
+ (eq this-command last-command)
+ completion-auto-help)
(minibuffer-completion-help beg end)
(completion--message "Next char not unique")))
;; If the last exact completion and this one were the same, it
;; means we've already given a "Complete, but not unique" message
- ;; and the user's hit TAB again, so now we give him help.
+ ;; and the user's hit TAB again, so now we give him help
+ ;; (even if `completion--icomplete-in-buffer-p' is non-nil).
(t
(when (and (eq this-command last-command) completion-auto-help)
(minibuffer-completion-help beg end))
@@ -1774,12 +1780,18 @@ completion--in-region-1
(t (prog1 (pcase (completion--do-completion beg end)
(#b000 nil)
(_ t))
- (if (window-live-p minibuffer-scroll-window)
- (and (eq completion-auto-select t)
- (eq t (frame-visible-p (window-frame minibuffer-scroll-window)))
- ;; When the completion list window was displayed, select it.
- (switch-to-completions))
- (completion-in-region-mode -1))))))
+ ;; FIXME: This part of the fix for bug#81537 reintroduces
+ ;; bug#67001 for `icomplete-in-region' users. It's not as bad
+ ;; for them because Icomplete users probably expect to have to
+ ;; C-g out of completion before using other bindings, but maybe
+ ;; we can still fix it. --spwhitton
+ (unless (completion--icomplete-in-buffer-p)
+ (if (window-live-p minibuffer-scroll-window)
+ (and (eq completion-auto-select t)
+ (eq t (frame-visible-p (window-frame minibuffer-scroll-window)))
+ ;; When the completion list window was displayed, select it.
+ (switch-to-completions))
+ (completion-in-region-mode -1)))))))
(defun completion--cache-all-sorted-completions (beg end comps)
(add-hook 'after-change-functions
--
Sean Whitton