Package: emacs;
Reported by: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Tue, 8 Apr 2025 15:18:01 UTC
Severity: normal
Tags: patch
To reply to this bug, email your comments to 77649 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
juri <at> linkov.net, mail <at> daniel-mendler.de, bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Tue, 08 Apr 2025 15:18:02 GMT) Full text and rfc822 format available.Spencer Baugh <sbaugh <at> janestreet.com>
:juri <at> linkov.net, mail <at> daniel-mendler.de, bug-gnu-emacs <at> gnu.org
.
(Tue, 08 Apr 2025 15:18:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Spencer Baugh <sbaugh <at> janestreet.com> To: bug-gnu-emacs <at> gnu.org Subject: [PATCH] Add support for updating *Completions* as you type Date: Tue, 08 Apr 2025 11:17:17 -0400
[Message part 1 (text/plain, inline)]
Tags: patch Add support for updating the *Completions* buffer as you type, controlled by a new completion metadata symbol 'eager-update and new defcustom completion-eager-update. You can configure a completion category to update *Completions* as you type by setting completion-category-overrides appropriately; or set completion-eager-update to t to always update *Completions* as you type. This is similar to the recently added completion-eager-display. In GNU Emacs 30.1.50 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2025-04-03 built on igm-qws-u22796a Repository revision: e0d429965010d82a05225e53ba6fbb97bea23ae9 Repository branch: emacs-30 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.10 (Green Obsidian) Configured using: 'configure --config-cache --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'
[0001-Add-support-for-updating-Completions-as-you-type.patch (text/patch, attachment)]
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Tue, 08 Apr 2025 18:36:01 GMT) Full text and rfc822 format available.Message #8 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Juri Linkov <juri <at> linkov.net> To: Spencer Baugh <sbaugh <at> janestreet.com> Cc: Daniel Mendler <mail <at> daniel-mendler.de>, 77649 <at> debbugs.gnu.org Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Tue, 08 Apr 2025 21:33:31 +0300
> Add support for updating the *Completions* buffer as you type, > controlled by a new completion metadata symbol 'eager-update and > new defcustom completion-eager-update. > > You can configure a completion category to update *Completions* > as you type by setting completion-category-overrides > appropriately; or set completion-eager-update to t to always > update *Completions* as you type. > > This is similar to the recently added completion-eager-display. Thanks, now finally we'll have this long-needed feature. The first question: should it depend on the value of 'minibuffer-visible-completions'? OTOH, even when it's nil, *Completions* can be displayed by non-nil completion-eager-display. So the only problem is that when the *Completions* window is removed (e.g. when no candidates remains), it never comes back to the display (e.g. after deleting previous characters). Or maybe this is not a problem, I have to test it more.
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Tue, 08 Apr 2025 19:09:01 GMT) Full text and rfc822 format available.Message #11 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Spencer Baugh <sbaugh <at> janestreet.com> To: Juri Linkov <juri <at> linkov.net> Cc: Daniel Mendler <mail <at> daniel-mendler.de>, 77649 <at> debbugs.gnu.org Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Tue, 08 Apr 2025 15:00:35 -0400
Juri Linkov <juri <at> linkov.net> writes: >> Add support for updating the *Completions* buffer as you type, >> controlled by a new completion metadata symbol 'eager-update and >> new defcustom completion-eager-update. >> >> You can configure a completion category to update *Completions* >> as you type by setting completion-category-overrides >> appropriately; or set completion-eager-update to t to always >> update *Completions* as you type. >> >> This is similar to the recently added completion-eager-display. > > Thanks, now finally we'll have this long-needed feature. Indeed. BTW, I should have mentioned in my first email that this depends, for performance, on the new lazy-inserting-into-*Completions* functionality I added; that makes performance good even when there are many completions. > The first question: should it depend on the value of > 'minibuffer-visible-completions'? OTOH, even when it's nil, > *Completions* can be displayed by non-nil completion-eager-display. Right, or of course the user could just explicitly hit ? to display *Completions*. So I don't currently see a reason why we'd depend on minibuffer-visible-completions. > So the only problem is that when the *Completions* window is removed > (e.g. when no candidates remains), it never comes back to the display > (e.g. after deleting previous characters). > > Or maybe this is not a problem, I have to test it more. The specific scenario of *Completions* disappearing when no candidates remain has not been a problem for me. But it is possible that we want to make other changes in this area (maybe separate from this patch?) *Completions* can be hidden for many reasons, but maybe when eager-display behavior is enabled, *Completions* should not be hidden as readily? Maybe eager-display should cause the behavior to be more like completion-auto-help=visible?
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Thu, 17 Jul 2025 20:34:01 GMT) Full text and rfc822 format available.Message #14 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: sbaugh <at> catern.com To: Spencer Baugh <sbaugh <at> janestreet.com> Cc: Daniel Mendler <mail <at> daniel-mendler.de>, 77649 <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net> Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Thu, 17 Jul 2025 20:33:28 +0000 (UTC)
Spencer Baugh <sbaugh <at> janestreet.com> writes: > Juri Linkov <juri <at> linkov.net> writes: > >>> Add support for updating the *Completions* buffer as you type, >>> controlled by a new completion metadata symbol 'eager-update and >>> new defcustom completion-eager-update. >>> >>> You can configure a completion category to update *Completions* >>> as you type by setting completion-category-overrides >>> appropriately; or set completion-eager-update to t to always >>> update *Completions* as you type. >>> >>> This is similar to the recently added completion-eager-display. >> >> Thanks, now finally we'll have this long-needed feature. Hi, have you gotten a chance to try this out? I have been running this for several completion categories at my site and have had no complaints.
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Fri, 18 Jul 2025 06:52:02 GMT) Full text and rfc822 format available.Message #17 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Juri Linkov <juri <at> linkov.net> To: sbaugh <at> catern.com Cc: Spencer Baugh <sbaugh <at> janestreet.com>, 77649 <at> debbugs.gnu.org, Daniel Mendler <mail <at> daniel-mendler.de> Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Fri, 18 Jul 2025 09:40:36 +0300
>>>> Add support for updating the *Completions* buffer as you type, >>>> controlled by a new completion metadata symbol 'eager-update and >>>> new defcustom completion-eager-update. >>>> >>>> You can configure a completion category to update *Completions* >>>> as you type by setting completion-category-overrides >>>> appropriately; or set completion-eager-update to t to always >>>> update *Completions* as you type. >>>> >>>> This is similar to the recently added completion-eager-display. >>> >>> Thanks, now finally we'll have this long-needed feature. > > Hi, have you gotten a chance to try this out? Yes, I tried it out, and everything worked nicely. > I have been running this for several completion categories at my site > and have had no complaints. Could you send a complete patch with a NEWS entry?
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Mon, 21 Jul 2025 16:45:02 GMT) Full text and rfc822 format available.Message #20 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Spencer Baugh <sbaugh <at> janestreet.com> To: Juri Linkov <juri <at> linkov.net> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, Daniel Mendler <mail <at> daniel-mendler.de> Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Mon, 21 Jul 2025 12:43:56 -0400
[Message part 1 (text/plain, inline)]
Juri Linkov <juri <at> linkov.net> writes: >>>>> Add support for updating the *Completions* buffer as you type, >>>>> controlled by a new completion metadata symbol 'eager-update and >>>>> new defcustom completion-eager-update. >>>>> >>>>> You can configure a completion category to update *Completions* >>>>> as you type by setting completion-category-overrides >>>>> appropriately; or set completion-eager-update to t to always >>>>> update *Completions* as you type. >>>>> >>>>> This is similar to the recently added completion-eager-display. >>>> >>>> Thanks, now finally we'll have this long-needed feature. >> >> Hi, have you gotten a chance to try this out? > > Yes, I tried it out, and everything worked nicely. > >> I have been running this for several completion categories at my site >> and have had no complaints. > > Could you send a complete patch with a NEWS entry? Yes, attached.
[0001-Add-support-for-updating-Completions-as-you-type.patch (text/x-patch, inline)]
From 5c8290de611710c1859c65c37daf961507b20e62 Mon Sep 17 00:00:00 2001 From: Spencer Baugh <sbaugh <at> janestreet.com> Date: Thu, 3 Apr 2025 15:38:22 -0400 Subject: [PATCH] Add support for updating *Completions* as you type Add support for updating the *Completions* buffer as you type, controlled by a new completion metadata symbol 'eager-update and new defcustom completion-eager-update. You can configure a completion category to update *Completions* as you type by setting completion-category-overrides appropriately; or set completion-eager-update to t to always update *Completions* as you type. This is similar to the recently added completion-eager-display. * lisp/minibuffer.el (completion-eager-update): Add new defcustom defaulting to 'auto. (bug#77649) (completion--eager-update-p, completions--background-update) (completions--post-command-update): Add. (completions--after-change): Call completions--post-command-update via post-command-hook. (minibuffer-completion-help): Check completion-eager-update and install completions--after-change. (completion-help-at-point): Call completion--eager-update-p if ONLY-IF-EAGER is non-nil. * etc/NEWS: Announce completion-eager-update. Slightly reword the announcement of completion-eager-display for consistency. --- etc/NEWS | 13 +++++++++- lisp/minibuffer.el | 59 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index b469b22aacf..0c0f333319a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -167,11 +167,22 @@ This option configures whether completion commands should display the "*Completions*" buffer immediately. When the option is set to t, all completion commands show "*Completions*" immediately, respectively nil disables the eager display for all commands. The default setting auto -enables eager completion only if requested by the command. +enables eager display only if requested by the command. For more fine-grained control you can also toggle this feature by category using the symbol 'eager-display' in the user option 'completion-category-overrides'. ++++ +*** New user option 'completion-eager-update. +This option configures whether typing should update the contents of the +"*Completions*" buffer, if it is shown. When the option is set to t, +typing will always update the "*Completions*" buffer. Note that for +large or inefficient completion tables, this can slow down typing. The +default setting enables eager updating only if requested by the command. +For more fine-grained control you can also toggle this feature by +category using the symbol 'eager-update in the user option +'completion-category-overrides'. + +++ *** New user option 'completion-pcm-leading-wildcard'. This option configures how the partial-completion style does completion. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 571c4174537..12f66f57747 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1072,6 +1072,21 @@ completion-eager-display (const :tag "If requested by the completion command" auto)) :version "31.1") +(defcustom completion-eager-update 'auto + "Whether typing should update the *Completions* buffer eagerly. + +If `t', always update as you type. + +If `auto', only update if the completion table has requested it or +`eager-update' is set in in `completion-category-defaults'. + +This only affects the *Completions* buffer if it is already +displayed." + :type '(choice (const :tag "Do nothing when you type" nil) + (const :tag "Auto-update based on the category" auto) + (const :tag "Always update as you type" t)) + :version "31.1") + (defcustom completion-auto-help t "Non-nil means automatically provide help for invalid completion input. If the value is t, the *Completions* buffer is displayed whenever completion @@ -2648,12 +2663,43 @@ completions--deselect (goto-char (or (next-single-property-change (point) 'completion--string) (point-max))))) +(defun completion--eager-update-p (start) + "Return non-nil if *Completions* should be automatically updated. + +If `completion-eager-update' is the symbol `auto', checks completion +metadata for the string from START to point." + (if (eq completion-eager-update 'auto) + (completion-metadata-get (completion--field-metadata start) 'eager-update) + completion-eager-update)) + +(defun completions--background-update () + "Try to update *Completions* without blocking input. + +This function uses `while-no-input' and sets `non-essential' to t +so that the update is less likely to interfere with user typing." + (while-no-input + (let ((non-essential t)) + (redisplay) + (cond + (completion-in-region-mode (completion-help-at-point t)) + ((completion--eager-update-p (minibuffer-prompt-end)) + (minibuffer-completion-help)))))) + +(defun completions--post-command-update () + "Update displayed *Completions* buffer after command, once." + (remove-hook 'post-command-hook #'completions--post-command-update) + (when (and completion-eager-update (get-buffer-window "*Completions*" 0)) + (completions--background-update))) + (defun completions--after-change (_start _end _old-len) "Update displayed *Completions* buffer after change in buffer contents." - (when completion-auto-deselect + (when (or completion-auto-deselect completion-eager-update) (when-let* ((window (get-buffer-window "*Completions*" 0))) - (with-selected-window window - (completions--deselect))))) + (when completion-auto-deselect + (with-selected-window window + (completions--deselect))) + (when completion-eager-update + (add-hook 'post-command-hook #'completions--post-command-update))))) (defun minibuffer-completion-help (&optional start end) "Display a list of possible completions of the current minibuffer contents." @@ -2744,7 +2790,7 @@ minibuffer-completion-help (body-function . ,#'(lambda (window) (with-current-buffer mainbuf - (when completion-auto-deselect + (when (or completion-auto-deselect completion-eager-update) (add-hook 'after-change-functions #'completions--after-change nil t)) ;; Remove the base-size tail because `sort' requires a properly ;; nil-terminated list. @@ -3133,7 +3179,7 @@ completion-at-point (car res))) (cdr res))))) -(defun completion-help-at-point () +(defun completion-help-at-point (&optional only-if-eager) "Display the completions on the text around point. The completion method is determined by `completion-at-point-functions'." (interactive) @@ -3160,7 +3206,8 @@ completion-help-at-point `(,start ,(copy-marker end t) ,collection ,(plist-get plist :predicate))) (completion-in-region-mode 1) - (minibuffer-completion-help start end))) + (when (or (not only-if-eager) (completion--eager-update-p start)) + (minibuffer-completion-help start end)))) (`(,hookfun . ,_) ;; The hook function already performed completion :-( ;; Not much we can do at this point. -- 2.39.3
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Tue, 22 Jul 2025 12:23:02 GMT) Full text and rfc822 format available.Message #23 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Spencer Baugh <sbaugh <at> janestreet.com> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, mail <at> daniel-mendler.de, juri <at> linkov.net Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Tue, 22 Jul 2025 15:22:34 +0300
> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, > Daniel Mendler <mail <at> daniel-mendler.de> > Date: Mon, 21 Jul 2025 12:43:56 -0400 > From: Spencer Baugh via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org> > > +*** New user option 'completion-eager-update. ^ Closing quote missing there. > +This option configures whether typing should update the contents of the ^^^^^^^^^^ We normally use "controls". > +"*Completions*" buffer, if it is shown. When the option is set to t, > +typing will always update the "*Completions*" buffer. Note that for > +large or inefficient completion tables, this can slow down typing. The > +default setting enables eager updating only if requested by the command. > +For more fine-grained control you can also toggle this feature by > +category using the symbol 'eager-update in the user option > +'completion-category-overrides'. IMO, the last two sentences are too vague/mysterious to be useful (this is a user option, remember?) > +If `auto', only update if the completion table has requested it or > +`eager-update' is set in in `completion-category-defaults'. This should at least hint how would a completion table request the update, or mention some function or variable whose doc string explains that. The doc string should also describe what happens when the value is nil. > + :type '(choice (const :tag "Do nothing when you type" nil) "Do nothing" is incorrect. I think you mean "Do not update completions" or somesuch. Thanks.
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Tue, 22 Jul 2025 16:33:01 GMT) Full text and rfc822 format available.Message #26 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Spencer Baugh <sbaugh <at> janestreet.com> To: Eli Zaretskii <eliz <at> gnu.org> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, juri <at> linkov.net, mail <at> daniel-mendler.de Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Tue, 22 Jul 2025 12:32:18 -0400
Eli Zaretskii <eliz <at> gnu.org> writes: >> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, >> Daniel Mendler <mail <at> daniel-mendler.de> >> Date: Mon, 21 Jul 2025 12:43:56 -0400 >> From: Spencer Baugh via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org> >> >> +*** New user option 'completion-eager-update. > ^ > Closing quote missing there. > >> +This option configures whether typing should update the contents of the > ^^^^^^^^^^ > We normally use "controls". > >> +"*Completions*" buffer, if it is shown. When the option is set to t, >> +typing will always update the "*Completions*" buffer. Note that for >> +large or inefficient completion tables, this can slow down typing. The >> +default setting enables eager updating only if requested by the command. >> +For more fine-grained control you can also toggle this feature by >> +category using the symbol 'eager-update in the user option >> +'completion-category-overrides'. > > IMO, the last two sentences are too vague/mysterious to be useful > (this is a user option, remember?) These two sentences are just copied (with a minor change) from the announcement for the very similar option completion-eager-display, just above. Should I reword that one as well in this commit? >> +If `auto', only update if the completion table has requested it or >> +`eager-update' is set in in `completion-category-defaults'. > > This should at least hint how would a completion table request the > update, or mention some function or variable whose doc string explains > that. > > The doc string should also describe what happens when the value is nil. > >> + :type '(choice (const :tag "Do nothing when you type" nil) > > "Do nothing" is incorrect. I think you mean "Do not update > completions" or somesuch. > > Thanks.
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Tue, 22 Jul 2025 17:06:02 GMT) Full text and rfc822 format available.Message #29 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Spencer Baugh <sbaugh <at> janestreet.com> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, juri <at> linkov.net, mail <at> daniel-mendler.de Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Tue, 22 Jul 2025 20:05:04 +0300
> From: Spencer Baugh <sbaugh <at> janestreet.com> > Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, mail <at> daniel-mendler.de, > juri <at> linkov.net > Date: Tue, 22 Jul 2025 12:32:18 -0400 > > Eli Zaretskii <eliz <at> gnu.org> writes: > > >> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, > >> Daniel Mendler <mail <at> daniel-mendler.de> > >> Date: Mon, 21 Jul 2025 12:43:56 -0400 > >> From: Spencer Baugh via "Bug reports for GNU Emacs, > >> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org> > >> > >> +*** New user option 'completion-eager-update. > > ^ > > Closing quote missing there. > > > >> +This option configures whether typing should update the contents of the > > ^^^^^^^^^^ > > We normally use "controls". > > > >> +"*Completions*" buffer, if it is shown. When the option is set to t, > >> +typing will always update the "*Completions*" buffer. Note that for > >> +large or inefficient completion tables, this can slow down typing. The > >> +default setting enables eager updating only if requested by the command. > >> +For more fine-grained control you can also toggle this feature by > >> +category using the symbol 'eager-update in the user option > >> +'completion-category-overrides'. > > > > IMO, the last two sentences are too vague/mysterious to be useful > > (this is a user option, remember?) > > These two sentences are just copied (with a minor change) from the > announcement for the very similar option completion-eager-display, just > above. Should I reword that one as well in this commit? If you wish, yes.
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Tue, 22 Jul 2025 19:29:02 GMT) Full text and rfc822 format available.Message #32 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Spencer Baugh <sbaugh <at> janestreet.com> To: Eli Zaretskii <eliz <at> gnu.org> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, mail <at> daniel-mendler.de, juri <at> linkov.net Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Tue, 22 Jul 2025 15:27:53 -0400
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes: >> From: Spencer Baugh <sbaugh <at> janestreet.com> >> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, mail <at> daniel-mendler.de, >> juri <at> linkov.net >> Date: Tue, 22 Jul 2025 12:32:18 -0400 >> >> Eli Zaretskii <eliz <at> gnu.org> writes: >> >> >> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, >> >> Daniel Mendler <mail <at> daniel-mendler.de> >> >> Date: Mon, 21 Jul 2025 12:43:56 -0400 >> >> From: Spencer Baugh via "Bug reports for GNU Emacs, >> >> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org> >> >> >> >> +*** New user option 'completion-eager-update. >> > ^ >> > Closing quote missing there. >> > >> >> +This option configures whether typing should update the contents of the >> > ^^^^^^^^^^ >> > We normally use "controls". >> > >> >> +"*Completions*" buffer, if it is shown. When the option is set to t, >> >> +typing will always update the "*Completions*" buffer. Note that for >> >> +large or inefficient completion tables, this can slow down typing. The >> >> +default setting enables eager updating only if requested by the command. >> >> +For more fine-grained control you can also toggle this feature by >> >> +category using the symbol 'eager-update in the user option >> >> +'completion-category-overrides'. >> > >> > IMO, the last two sentences are too vague/mysterious to be useful >> > (this is a user option, remember?) >> >> These two sentences are just copied (with a minor change) from the >> announcement for the very similar option completion-eager-display, just >> above. Should I reword that one as well in this commit? > > If you wish, yes. Updated and fixed your feedback.
[0001-Add-support-for-updating-Completions-as-you-type.patch (text/x-patch, inline)]
From 6e6d38974ad142882fd9919f452ae311b418a712 Mon Sep 17 00:00:00 2001 From: Spencer Baugh <sbaugh <at> janestreet.com> Date: Thu, 3 Apr 2025 15:38:22 -0400 Subject: [PATCH] Add support for updating *Completions* as you type Add support for updating the *Completions* buffer as you type, controlled by a new completion metadata symbol 'eager-update and new defcustom completion-eager-update. You can configure a completion category to update *Completions* as you type by setting completion-category-overrides appropriately; or set completion-eager-update to t to always update *Completions* as you type. This is similar to the recently added completion-eager-display. * lisp/minibuffer.el (completion-eager-update): Add new defcustom defaulting to 'auto. (bug#77649) (completion--eager-update-p, completions--background-update) (completions--post-command-update): Add. (completions--after-change): Call completions--post-command-update via post-command-hook. (minibuffer-completion-help): Check completion-eager-update and install completions--after-change. (completion-help-at-point): Call completion--eager-update-p if ONLY-IF-EAGER is non-nil. * etc/NEWS: Announce completion-eager-update. Reword the announcement of completion-eager-display for consistency. --- etc/NEWS | 29 +++++++++++++++------- lisp/minibuffer.el | 62 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 2d904614153..f2a08ee3009 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -173,15 +173,26 @@ this behavior is now off by default. You can re-enable it by setting ** Minibuffer and Completions +++ -*** New user option 'completion-eager-display'. -This option configures whether completion commands should display the -"*Completions*" buffer immediately. When the option is set to t, all -completion commands show "*Completions*" immediately, respectively nil -disables the eager display for all commands. The default setting auto -enables eager completion only if requested by the command. -For more fine-grained control you can also toggle this feature by -category using the symbol 'eager-display' in the user option -'completion-category-overrides'. +*** Support for immediate display of the "*Completions*" buffer +Whenever a minibuffer with completion is opened, the "*Completions*" +buffer will now be displayed immediately if the completion property +'eager-display', set by the completion table, is non-nil. This property +can be overridden for different completion categories by customizing +'completion-category-overrides'. Alternatively, the new user option +'completion-eager-display' can be set to t to force eager display of +"*Completions*" for all minibuffers, or nil to suppress this for all +minibuffers. + ++++ +*** Support for updating "*Completions*" as you type +If the "*Completions*" buffer is displayed, it will now be updated as +you type if the completion property 'eager-update', set by the +completion table, is non-nil. This property can be overridden for +different completion categories by customizing +'completion-category-overrides'. Alternatively, the new user option +'completion-eager-update can be set to t to make "*Completions*" always +be updated as you type, or nil to suppress this always. Note that for +large or inefficient completion tables this can slow down typing. +++ *** New user option 'completion-pcm-leading-wildcard'. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 571c4174537..ea2546f7d2c 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1072,6 +1072,24 @@ completion-eager-display (const :tag "If requested by the completion command" auto)) :version "31.1") +(defcustom completion-eager-update 'auto + "Whether the *Completions* buffer should update as you type. + +If `t', always update as you type. + +If `auto', only update if the completion property 'eager-update' is +non-nil, whether set by the completion table or by +`completion-category-overrides' or by `completion-category-defaults'. + +If nil, never update as you type. + +This only affects the *Completions* buffer if it is already +displayed." + :type '(choice (const :tag "Don't update as you type" nil) + (const :tag "Auto-update based on the category" auto) + (const :tag "Always update as you type" t)) + :version "31.1") + (defcustom completion-auto-help t "Non-nil means automatically provide help for invalid completion input. If the value is t, the *Completions* buffer is displayed whenever completion @@ -2648,12 +2666,43 @@ completions--deselect (goto-char (or (next-single-property-change (point) 'completion--string) (point-max))))) +(defun completion--eager-update-p (start) + "Return non-nil if *Completions* should be automatically updated. + +If `completion-eager-update' is the symbol `auto', checks completion +metadata for the string from START to point." + (if (eq completion-eager-update 'auto) + (completion-metadata-get (completion--field-metadata start) 'eager-update) + completion-eager-update)) + +(defun completions--background-update () + "Try to update *Completions* without blocking input. + +This function uses `while-no-input' and sets `non-essential' to t +so that the update is less likely to interfere with user typing." + (while-no-input + (let ((non-essential t)) + (redisplay) + (cond + (completion-in-region-mode (completion-help-at-point t)) + ((completion--eager-update-p (minibuffer-prompt-end)) + (minibuffer-completion-help)))))) + +(defun completions--post-command-update () + "Update displayed *Completions* buffer after command, once." + (remove-hook 'post-command-hook #'completions--post-command-update) + (when (and completion-eager-update (get-buffer-window "*Completions*" 0)) + (completions--background-update))) + (defun completions--after-change (_start _end _old-len) "Update displayed *Completions* buffer after change in buffer contents." - (when completion-auto-deselect + (when (or completion-auto-deselect completion-eager-update) (when-let* ((window (get-buffer-window "*Completions*" 0))) - (with-selected-window window - (completions--deselect))))) + (when completion-auto-deselect + (with-selected-window window + (completions--deselect))) + (when completion-eager-update + (add-hook 'post-command-hook #'completions--post-command-update))))) (defun minibuffer-completion-help (&optional start end) "Display a list of possible completions of the current minibuffer contents." @@ -2744,7 +2793,7 @@ minibuffer-completion-help (body-function . ,#'(lambda (window) (with-current-buffer mainbuf - (when completion-auto-deselect + (when (or completion-auto-deselect completion-eager-update) (add-hook 'after-change-functions #'completions--after-change nil t)) ;; Remove the base-size tail because `sort' requires a properly ;; nil-terminated list. @@ -3133,7 +3182,7 @@ completion-at-point (car res))) (cdr res))))) -(defun completion-help-at-point () +(defun completion-help-at-point (&optional only-if-eager) "Display the completions on the text around point. The completion method is determined by `completion-at-point-functions'." (interactive) @@ -3160,7 +3209,8 @@ completion-help-at-point `(,start ,(copy-marker end t) ,collection ,(plist-get plist :predicate))) (completion-in-region-mode 1) - (minibuffer-completion-help start end))) + (when (or (not only-if-eager) (completion--eager-update-p start)) + (minibuffer-completion-help start end)))) (`(,hookfun . ,_) ;; The hook function already performed completion :-( ;; Not much we can do at this point. -- 2.39.3
bug-gnu-emacs <at> gnu.org
:bug#77649
; Package emacs
.
(Sat, 26 Jul 2025 09:43:01 GMT) Full text and rfc822 format available.Message #35 received at 77649 <at> debbugs.gnu.org (full text, mbox):
From: Eli Zaretskii <eliz <at> gnu.org> To: Spencer Baugh <sbaugh <at> janestreet.com> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, mail <at> daniel-mendler.de, juri <at> linkov.net Subject: Re: bug#77649: [PATCH] Add support for updating *Completions* as you type Date: Sat, 26 Jul 2025 12:42:02 +0300
> From: Spencer Baugh <sbaugh <at> janestreet.com> > Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, juri <at> linkov.net, > mail <at> daniel-mendler.de > Date: Tue, 22 Jul 2025 15:27:53 -0400 > > Eli Zaretskii <eliz <at> gnu.org> writes: > >> From: Spencer Baugh <sbaugh <at> janestreet.com> > >> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, mail <at> daniel-mendler.de, > >> juri <at> linkov.net > >> Date: Tue, 22 Jul 2025 12:32:18 -0400 > >> > >> Eli Zaretskii <eliz <at> gnu.org> writes: > >> > >> >> Cc: sbaugh <at> catern.com, 77649 <at> debbugs.gnu.org, > >> >> Daniel Mendler <mail <at> daniel-mendler.de> > >> >> Date: Mon, 21 Jul 2025 12:43:56 -0400 > >> >> From: Spencer Baugh via "Bug reports for GNU Emacs, > >> >> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org> > >> >> > >> >> +*** New user option 'completion-eager-update. > >> > ^ > >> > Closing quote missing there. > >> > > >> >> +This option configures whether typing should update the contents of the > >> > ^^^^^^^^^^ > >> > We normally use "controls". > >> > > >> >> +"*Completions*" buffer, if it is shown. When the option is set to t, > >> >> +typing will always update the "*Completions*" buffer. Note that for > >> >> +large or inefficient completion tables, this can slow down typing. The > >> >> +default setting enables eager updating only if requested by the command. > >> >> +For more fine-grained control you can also toggle this feature by > >> >> +category using the symbol 'eager-update in the user option > >> >> +'completion-category-overrides'. > >> > > >> > IMO, the last two sentences are too vague/mysterious to be useful > >> > (this is a user option, remember?) > >> > >> These two sentences are just copied (with a minor change) from the > >> announcement for the very similar option completion-eager-display, just > >> above. Should I reword that one as well in this commit? > > > > If you wish, yes. > > Updated and fixed your feedback. Thanks. > +*** Support for immediate display of the "*Completions*" buffer > +Whenever a minibuffer with completion is opened, the "*Completions*" > +buffer will now be displayed immediately if the completion property > +'eager-display', set by the completion table, is non-nil. This property > +can be overridden for different completion categories by customizing > +'completion-category-overrides'. Alternatively, the new user option > +'completion-eager-display' can be set to t to force eager display of > +"*Completions*" for all minibuffers, or nil to suppress this for all > +minibuffers. > + > ++++ > +*** Support for updating "*Completions*" as you type > +If the "*Completions*" buffer is displayed, it will now be updated as > +you type if the completion property 'eager-update', set by the > +completion table, is non-nil. This property can be overridden for > +different completion categories by customizing > +'completion-category-overrides'. Alternatively, the new user option > +'completion-eager-update can be set to t to make "*Completions*" always > +be updated as you type, or nil to suppress this always. Note that for > +large or inefficient completion tables this can slow down typing. The two heading lines still don't end in a period. No further comments, once those nits are fixed.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.