[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating *Completions* as you type

From: sbaugh
Subject: Re: Updating *Completions* as you type
Date: Sun, 15 Oct 2023 11:55:47 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

Eli Zaretskii <eliz@gnu.org> writes:

>> From: sbaugh@catern.com
>> Date: Sat, 14 Oct 2023 16:05:11 -0400
>> Yes, agreed.  Taking inspiration from zcomplete, I wrote this patch to
>> provide just this feature, thoughts?
> I tried this.  The update is slow (most probably because it works off
> the post-command-hook), and the UX is therefore extremely unpleasant
> if you type fast enough.

Interesting.  Can you say more about what completion you're doing for
which the update is slow?  I would have expected the while-no-input to
cause the update to not block you if you type fast.

Of course, if there are optimizations that need to be done for
completion-generation, I'm happy to do them.

>> +(defcustom completions-auto-update t
>> +  "If non-nil, update the *Completions* buffer as you type.
> Thus _must_ be nil by default.

Of course, just defaulted to t to make testing the patch easier.

>> +(defconst completions-no-auto-update-commands
>> +  '(previous-history-element
>> +    next-history-element
>> +    previous-line-or-history-element
>> +    next-line-or-history-element
>> +    completion-at-point
>> +    minibuffer-complete-and-exit
>> +    minibuffer-force-complete-and-exit
>> +    minibuffer-next-completion
>> +    minibuffer-previous-completion
>> +    minibuffer-choose-completion)
>> +  "Commands to skip updating *Completions*")
> Why are those excluded?  And why is this a defconst, not a defvar or
> defcustom?

These are basically just commands where it would be annoying or
pointless to do an auto-update.

There are three classes here:

1. completion-at-point

   These commands themselves update *Completions*, so it's not necessary
   to update *Completions* immediately after they run, since it will
   already be up to date for the buffer text.

   This is just a performance thing and isn't strictly necessary.  I'll
   drop them from the next version.

   (The performance optimization could be implemented separately from
   completions-auto-update and apply even if it was nil.  We could have
   a general mechanism to skip regeneration of completions if the
   completion input hasn't changed.  That could be nice, although it's a
   complex topic.)
2. previous-history-element

   These insert some text in the minibuffer which usually (but not
   always) will only have one completion.

   I'll drop these from the next version of my patch, since actually I
   now realize there's no reason to special-case skipping these.

3. minibuffer-next-completion

   These call next-completion, which changes the location of point in
   *Completions*.  And if we auto-update *Completions*, we lose the
   location of point.

   But actually, even without completions-auto-update, it would be
   generally useful to not lose the location of point in *Completions*.
   So I'll just implement that as a separate patch.  And then I can also
   drop these two special cases.

So, in the next version of my patch, this variable will be dropped

>> +    (while-no-input
>> +      (let ((non-essential t))
>                 ^^^^^^^^^^^^^^^
> Why?

This I borrowed from zcomplete.  It seems sensible, since
non-essential's docstring says:

  E.g., it can be used to prevent Tramp from prompting the user for a
  password when we are [...] displaying possible completions before the
  user even asked for it.

>> +        (when (and (get-buffer-window "*Completions*" 0)
>> +                   (not (memq this-command 
>> completions-no-auto-update-commands)))
>> +          (redisplay)
>              ^^^^^^^^^^^
> Why do you need this?

post-command-hook's docstring says:

  It is a bad idea to use this hook for expensive processing.  If
  unavoidable, wrap your code in ‘(while-no-input (redisplay) CODE)’ to
  avoid making Emacs unresponsive while the user types.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]