From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846) Date: Sun, 14 Jul 2024 20:00:37 +0300 Organization: LINKOV.NET Message-ID: <86msmj9adm.fsf@mail.linkov.net> References: <171558357066.26019.9766615061719600757@vcs2.savannah.gnu.org> <20240513065931.0D83AC12C31@vcs2.savannah.gnu.org> <86v83hwxjs.fsf@mail.linkov.net> <86ikzhq6ja.fsf@mail.linkov.net> <86o798x5hz.fsf@gnu.org> <86bk572e6a.fsf@mail.linkov.net> <861q62pb8y.fsf@mail.linkov.net> <864jayjd8u.fsf@gnu.org> <86le49ymsl.fsf@mail.linkov.net> <86msoo4cf3.fsf@mail.linkov.net> <865xv9ugjx.fsf@mail.linkov.net> <867cffdsp8.fsf@mail.linkov.net> <86ttgs78eu.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26665"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: Stefan Monnier , Eli Zaretskii , emacs-devel@gnu.org To: Eshel Yaron Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jul 14 19:08:05 2024 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 1sT2hg-0006mL-AY for ged-emacs-devel@m.gmane-mx.org; Sun, 14 Jul 2024 19:08:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sT2gx-0004mN-5b; Sun, 14 Jul 2024 13:07:19 -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 1sT2gv-0004kO-7w for emacs-devel@gnu.org; Sun, 14 Jul 2024 13:07:17 -0400 Original-Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sT2gt-00012N-CP; Sun, 14 Jul 2024 13:07:17 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id B6828FF802; Sun, 14 Jul 2024 17:07:07 +0000 (UTC) In-Reply-To: (Eshel Yaron's message of "Sun, 14 Jul 2024 12:55:53 +0200") X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=2001:4b98:dc4:8::229; envelope-from=juri@linkov.net; helo=relay9-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:321646 Archived-At: >>> I'm afraid imenu-flatten=annotation has one more hurdle to overcome. >>> Consider: >>> >>> 1. emacs -Q >>> 2. (setq imenu-flatten 'annotation) >>> 2. C-x C-f .../lisp/imenu.el >>> 3. M-g i >>> 4. M- M- M- M- ... >>> 5. Now the selected candidate in *Completions* is e.g. imenu--cleanup, >>> this is also the minibuffer contents, so far so good. >>> 6. Type M-RET to jump to this candidate. >>> 7. Land on imenu instead of imenu--cleanup. >>> >>> No matter how far down you go with M-, if you go through the entry >>> for imenu, that's where you'll land when you hit M-RET. This is because >>> imenu-flatten=annotation tries to identify candidates by their text >>> properties, but completion--replace retains common parts while replacing >>> minibuffer text, along with the text properties of these common parts. >>> >>> This affects imenu-flatten=group too. >>> >>> It might be possible to resolve this by setting a different >>> completion-list-insert-choice-function that circumvents replaces the >>> whole minibuffer contents, unlike completion--replace, which tries hard >>> to preserve markers etc. >> >> Maybe then imenu--completion-buffer should try to get the text property >> from the end of completion? Provided that completion--replace will keep >> some properties at the end instead of using insert-and-inherit. > > I'm not sure, I think that might work in some cases, but since > completion--replace also keeps the common suffix it may still suffer > from the same issue when going from candidate "foo-baz" to "bar-baz". > > Then there's the problem of what happens when you simply type the > candidate you want to jump to, without completion. For example > M-g i imenu RET goes to the imenu function when imenu-flatten=nil, > but if imenu-flatten=annotation then it goes to the defgroup. > > What I would suggest is to ensure completion candidates are unambiguous > as strings rather than relying on text properties. Namely: Unfortunately, that'd be a step back. Maybe at least we could document limitations that annotations work only by selection. > - Restore imenu-flatten to a boolean option: either flat or nested. > - If imenu-flatten is non-nil, prepend the full prefix to each candidate, > like imenu-flatten=prefix does currently. This takes care of > disambiguating the candidate strings. It can't be boolean, because a more reliable replacement for annotations would be appending the suffix, i.e. by the new value 'suffix'. > - If completions-group is also non-nil, then group candidates according > to their prefix and trim the prefix in the group-function when > transforming candidates for display. The disadvantage of completions-group is its too wide coverage. We should strive for more specific options where possible. Or better: let's enable groups by category. I don't know why we have such a glaring omission that groups still can't be enabled by category. This should be simple to implement: diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index d8df001159f..f26a49a019f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1809,7 +1809,8 @@ completion-all-sorted-completions minibuffer-completion-table minibuffer-completion-predicate)) (sort-fun (completion-metadata-get all-md 'cycle-sort-function)) - (group-fun (completion-metadata-get all-md 'group-function))) + (group-fun (completion-metadata-get all-md 'group-function)) + (group (completion-metadata-get all-md 'group))) (when last (setcdr last nil) @@ -1821,7 +1822,7 @@ completion-all-sorted-completions (cond (sort-fun (setq all (funcall sort-fun all))) - ((and completions-group group-fun) + ((and (or completions-group group) group-fun) ;; TODO: experiment with re-grouping here. Might be slow ;; if the group-fun (given by the table and out of our ;; control) is slow and/or allocates too much.