unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Eshel Yaron <me@eshelyaron.com>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
	 Eli Zaretskii <eliz@gnu.org>,
	 emacs-devel@gnu.org
Subject: Re: Completions group metadata [
Date: Fri, 09 Aug 2024 19:16:14 +0300	[thread overview]
Message-ID: <86plqhr7sh.fsf@mail.linkov.net> (raw)
In-Reply-To: <86frrgizy5.fsf_-_@mail.linkov.net> (Juri Linkov's message of "Wed, 07 Aug 2024 09:56:02 +0300")

[-- Attachment #1: Type: text/plain, Size: 2464 bytes --]

>>>> - 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'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: completions-group-p.patch --]
[-- Type: text/x-diff, Size: 4671 bytes --]

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))

  reply	other threads:[~2024-08-09 16:16 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <171558357066.26019.9766615061719600757@vcs2.savannah.gnu.org>
     [not found] ` <20240513065931.0D83AC12C31@vcs2.savannah.gnu.org>
2024-05-13  9:22   ` master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846) Eshel Yaron
2024-05-13 16:30     ` Juri Linkov
2024-05-14  6:08       ` Juri Linkov
2024-05-14  6:38         ` Eli Zaretskii
2024-05-14 13:10           ` Stefan Monnier
2024-05-14 16:46             ` Juri Linkov
2024-05-14 20:58             ` Daniel Mendler via Emacs development discussions.
2024-05-14 23:26               ` FW: [External] : " Drew Adams
2024-05-15 16:51           ` Juri Linkov
2024-05-15 18:03             ` Eli Zaretskii
2024-05-15 18:30             ` Eshel Yaron
2024-05-16  6:08               ` Juri Linkov
2024-05-16  9:51                 ` Eli Zaretskii
2024-05-17  6:48                   ` Juri Linkov
2024-05-17 15:36                     ` Stefan Monnier
2024-05-17 16:43                       ` Juri Linkov
2024-05-18 15:12                         ` Stefan Monnier
2024-05-20  6:46                           ` Juri Linkov
2024-05-27 18:18                             ` Juri Linkov
2024-07-14  6:28                               ` Eshel Yaron
2024-07-14  6:53                                 ` Juri Linkov
2024-07-14 10:55                                   ` Eshel Yaron
2024-07-14 17:00                                     ` Juri Linkov
2024-07-16  6:57                                       ` Eshel Yaron
2024-08-07  6:51                                         ` Juri Linkov
2024-08-07  8:33                                           ` Eshel Yaron
2024-08-07 16:46                                             ` Juri Linkov
2024-08-09  6:59                                               ` Juri Linkov
2024-08-09  7:11                                                 ` Eli Zaretskii
2024-08-09 16:10                                                   ` Juri Linkov
2024-08-09 17:43                                                     ` Eli Zaretskii
2024-08-07  6:56                                         ` Completions group metadata [was: master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846)] Juri Linkov
2024-08-09 16:16                                           ` Juri Linkov [this message]
2024-08-14  1:41                                       ` master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846) Stefan Monnier
2024-08-20 17:51                                         ` Juri Linkov
2024-05-14 15:26         ` [External] : " Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86plqhr7sh.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=me@eshelyaron.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).