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: Completions group metadata [ Date: Fri, 09 Aug 2024 19:16:14 +0300 Organization: LINKOV.NET Message-ID: <86plqhr7sh.fsf@mail.linkov.net> References: <171558357066.26019.9766615061719600757@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> <86msmj9adm.fsf@mail.linkov.net> <86frrgizy5.fsf_-_@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18379"; 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 Fri Aug 09 18:20:41 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 1scSM5-0004gF-Nv for ged-emacs-devel@m.gmane-mx.org; Fri, 09 Aug 2024 18:20:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1scSLR-0004LH-HE; Fri, 09 Aug 2024 12:20:01 -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 1scSLQ-0004FW-0w for emacs-devel@gnu.org; Fri, 09 Aug 2024 12:20:00 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1scSLN-0007pM-O5; Fri, 09 Aug 2024 12:19:59 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id A093740002; Fri, 9 Aug 2024 16:19:52 +0000 (UTC) In-Reply-To: <86frrgizy5.fsf_-_@mail.linkov.net> (Juri Linkov's message of "Wed, 07 Aug 2024 09:56:02 +0300") X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=217.70.183.194; envelope-from=juri@linkov.net; helo=relay2-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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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:322579 Archived-At: --=-=-= Content-Type: text/plain >>>> - 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. >> >> Right. The advantage, on the other hand, is that you can toggle >> completions-group on the fly in the minibuffer, either with >> toggle-option or with a dedicated command. The wide coverage of >> completions-group means there's just one variable to toggle, always. > > Interesting. Then this requires such precedence (from high to low): > > buffer-local value of completions-group -> metadata -> default-value > of completions-group The patch below doesn't yet implement this precedence since I can't find a dedicated command that toggles completions-group on the fly. Such a command doesn't exist even in your branch 'feature/minibuffer-completion-enhancements'. And anyway this should be improved at the same time with introducing a support for toggling the sorting order, layout, etc. >>> 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: >> >> Doesn't the group-function metadata entry give enough control already? > > It's not easy for users to customize group-function metadata > by writing own group function. Whereas with a boolean its easy > to toggle it in the Customization UI for completion-category-overrides. Regarding the value 'group' of imenu-flatten, it can't be removed since it's used in imenu--flatten-index-alist, so the patch hard-codes ':group-p t' for the value 'group'. >> If a category or a specific completion table wants to disable grouping, >> it can simply avoid providing a group-function. If it wants to enable >> grouping, then it does provide a group-function, and now it's up to the >> user's preferences which they express by setting completions-group. >> Maybe your suggestion yields more flexibility in some cases? > > It makes sense to provide a group-function disabled by default > to help users just to enable it in completion-category-overrides > instead of writing it from scratch. Here is the patch that supports (setopt completion-category-overrides '((unicode-name (group-p . t)))) without enabling the global 'completions-group'. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=completions-group-p.patch diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 7d784ef3b1b..e0c282a54e5 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3260,8 +3260,7 @@ read-char-by-name (affixation-function . ,#'mule--ucs-names-affixation) (group-function - . ,(when completions-group - #'mule--ucs-names-group)) + . ,#'mule--ucs-names-group) (category . unicode-name)) (complete-with-action action (ucs-names) string pred))))) (char diff --git a/lisp/imenu.el b/lisp/imenu.el index 8f1b1f22a67..6efa2d55966 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -770,11 +776,12 @@ imenu--completion-buffer ,(lambda (s) (get-text-property 0 'imenu-section s)))) ,@(when (eq imenu-flatten 'group) - `(:group-function - ,(lambda (s transform) - (if transform s - (get-text-property - 0 'imenu-section s))))))) + `( :group-p t + :group-function + ,(lambda (s transform) + (if transform s + (get-text-property + 0 'imenu-section s))))))) (unless imenu-eager-completion-buffer (minibuffer-completion-help))) (setq name (completing-read prompt diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index e8e0f169197..1269bab0d40 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1231,6 +1231,10 @@ completion-category-overrides (const :tag "Historical sorting" minibuffer-sort-by-history) (function :tag "Custom function"))) + (cons :tag "Use Groups" + (const :tag "Enable groups." + group-p) + (boolean)) (cons :tag "Completion Groups" (const :tag "Select one value from the menu." group-function) @@ -1809,7 +1813,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-p (completion-metadata-get all-md 'group-p))) (when last (setcdr last nil) @@ -1821,7 +1826,7 @@ completion-all-sorted-completions (cond (sort-fun (setq all (funcall sort-fun all))) - ((and completions-group group-fun) + ((and (or completions-group group-p) 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. @@ -2610,7 +2615,9 @@ minibuffer-completion-help (ann-fun (completion-metadata-get all-md 'annotation-function)) (aff-fun (completion-metadata-get all-md 'affixation-function)) (sort-fun (completion-metadata-get all-md 'display-sort-function)) - (group-fun (completion-metadata-get all-md 'group-function)) + (group-p (completion-metadata-get all-md 'group-p)) + (group-fun (when (or completions-group group-p) + (completion-metadata-get all-md 'group-function))) (mainbuf (current-buffer)) ;; If the *Completions* buffer is shown in a new ;; window, mark it as softly-dedicated, so bury-buffer in diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 2ea5e36fa88..07b8ec83cf9 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -791,8 +791,7 @@ icomplete--augment by `group-function''s second \"transformation\" protocol." (let* ((aff-fun (completion-metadata-get md 'affixation-function)) (ann-fun (completion-metadata-get md 'annotation-function)) - (grp-fun (and completions-group - (completion-metadata-get md 'group-function))) + (grp-fun (completion-metadata-get md 'group-function)) (annotated (cond (aff-fun (funcall aff-fun prospects)) --=-=-=--