From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.devel Subject: Re: Updating *Completions* as you type Date: Sun, 15 Oct 2023 11:55:47 -0400 Message-ID: <87h6mryj5o.fsf@catern.com> References: <87bkd3z9bi.fsf@catern.com> <86cyxjyr1y.fsf@mail.linkov.net> <86r0lxm7um.fsf@mail.linkov.net> <87sf6dx954.fsf@catern.com> <8334ycqv0g.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="429"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:2IbFvCTJvWq/ZZNCJPSHvomCFrw= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 16 04:22:47 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qsDFl-000AVj-DT for ged-emacs-devel@m.gmane-mx.org; Mon, 16 Oct 2023 04:22:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsDEn-0002er-6s; Sun, 15 Oct 2023 22:21:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qs3TE-0006GD-DJ for emacs-devel@gnu.org; Sun, 15 Oct 2023 11:56:00 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qs3TC-0000RD-S2 for emacs-devel@gnu.org; Sun, 15 Oct 2023 11:56:00 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1qs3TA-0009Sp-KK for emacs-devel@gnu.org; Sun, 15 Oct 2023 17:55:56 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 15 Oct 2023 22:21:40 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:311504 Archived-At: Eli Zaretskii 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 minibuffer-complete-and-exit minibuffer-force-complete-and-exit 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 next-history-element previous-line-or-history-element next-line-or-history-element minibuffer-choose-completion 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 minibuffer-previous-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 entirely. >> + (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.