* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
@ 2022-01-19 12:26 Protesilaos Stavrou
2022-01-19 12:56 ` Eli Zaretskii
2022-01-19 16:10 ` bug#53362: [External] : " Drew Adams
0 siblings, 2 replies; 9+ messages in thread
From: Protesilaos Stavrou @ 2022-01-19 12:26 UTC (permalink / raw)
To: 53362
[-- Attachment #1: Type: text/plain, Size: 353 bytes --]
Dear maintainers,
I was wondering whether we could make the sorting of candidates in the
Completions' buffer subject to a user option.
See the attached patch for a possible implementation. I have kept it
backward-compatible by making string-lessp the default sort function.
All the best,
Protesilaos
--
Protesilaos Stavrou
https://protesilaos.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-Completions-sorting-a-user-option.patch --]
[-- Type: text/x-patch, Size: 3078 bytes --]
From e53bd2b2383f3dfa367f2af8d4ed43c6c42dd002 Mon Sep 17 00:00:00 2001
Message-Id: <e53bd2b2383f3dfa367f2af8d4ed43c6c42dd002.1642595067.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Wed, 19 Jan 2022 14:20:19 +0200
Subject: [PATCH] Make Completions sorting a user option
* etc/NEWS: Document the new user option.
* lisp/minibuffer.el (completions-sort): Add new user option.
(minibuffer-completion-help): Implement it for the Completions buffer.
---
etc/NEWS | 6 ++++++
lisp/minibuffer.el | 19 ++++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 47dbfba9c0..c2d442833c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -418,6 +418,12 @@ When non-nil, the commands 'next-completion' and 'previous-completion'
automatically wrap around on reaching the beginning or the end of
the *Completions* buffer.
+*** New user option 'completions-sort'.
+Controls the sorting of the completion candidates in the *Completions*
+buffer. Available styles are no sorting, alphabetical, lexicographic
+(the default), or a custom sort function. The function takes and
+returns a list of completion candidate strings.
+
** Isearch and Replace
+++
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index ab760a42d1..d64b0cbd24 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1169,6 +1169,20 @@ (defcustom completion-cycle-threshold nil
:version "24.1"
:type completion--cycling-threshold-type)
+(defcustom completions-sort 'lexicographic
+ "Sort candidates in the *Completions* buffer.
+
+The value can be nil to disable sorting altogether,
+`alphabetical' for alphabetical sorting, `lexicographic' for
+lexicographic sorting, or a custom sorting function. The sorting
+function takes and returns a list of completion candidate
+strings."
+ :type '(choice (const :tag "No sorting" nil)
+ (const :tag "Alphabetical sorting" alphabetical)
+ (const :tag "Lexicographic sorting" lexicographic)
+ function :tag "Custom function")
+ :version "29.1")
+
(defcustom completions-group nil
"Enable grouping of completion candidates in the *Completions* buffer.
See also `completions-group-format' and `completions-group-sort'."
@@ -2264,7 +2278,10 @@ (defun minibuffer-completion-help (&optional start end)
;; same, but not always.
(setq completions (if sort-fun
(funcall sort-fun completions)
- (sort completions 'string-lessp)))
+ (pcase completions-sort
+ ('alphabetical (sort completions #'string-version-lessp))
+ ('lexicographic (sort completions #'string-lessp))
+ (_ completions))))
;; After sorting, group the candidates using the
;; `group-function'.
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-19 12:26 bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option Protesilaos Stavrou
@ 2022-01-19 12:56 ` Eli Zaretskii
2022-01-19 13:17 ` Protesilaos Stavrou
2022-01-19 16:10 ` bug#53362: [External] : " Drew Adams
1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2022-01-19 12:56 UTC (permalink / raw)
To: Protesilaos Stavrou; +Cc: 53362
> From: Protesilaos Stavrou <info@protesilaos.com>
> Date: Wed, 19 Jan 2022 14:26:47 +0200
>
> +(defcustom completions-sort 'lexicographic
> + "Sort candidates in the *Completions* buffer.
> +
> +The value can be nil to disable sorting altogether,
> +`alphabetical' for alphabetical sorting, `lexicographic' for
> +lexicographic sorting
Here you expect everyone to understand the subtle difference between
these two sorting orders. I don't think this expectation is
reasonable.
> + ('alphabetical (sort completions #'string-version-lessp))
Doesn't string-version-lessp do stuff that is only appropriate with
version numbers like 1.2.3beta?
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-19 12:56 ` Eli Zaretskii
@ 2022-01-19 13:17 ` Protesilaos Stavrou
2022-01-19 13:27 ` Eli Zaretskii
0 siblings, 1 reply; 9+ messages in thread
From: Protesilaos Stavrou @ 2022-01-19 13:17 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 53362
On 2022-01-19, 14:56 +0200, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Protesilaos Stavrou <info@protesilaos.com>
>> Date: Wed, 19 Jan 2022 14:26:47 +0200
>>
>> +(defcustom completions-sort 'lexicographic
>> + "Sort candidates in the *Completions* buffer.
>> +
>> +The value can be nil to disable sorting altogether,
>> +`alphabetical' for alphabetical sorting, `lexicographic' for
>> +lexicographic sorting
>
> Here you expect everyone to understand the subtle difference between
> these two sorting orders. I don't think this expectation is
> reasonable.
Perhaps it is better to reference string-lessp and string-version-lessp
directly?
>> + ('alphabetical (sort completions #'string-version-lessp))
>
> Doesn't string-version-lessp do stuff that is only appropriate with
> version numbers like 1.2.3beta?
It also helps when the string starts with a number:
(sort '("1 test" "21 test" "11 test" "2 test") #'string-lessp)
;; => ("1 test" "11 test" "2 test" "21 test")
(sort '("1 test" "21 test" "11 test" "2 test") #'string-version-lessp)
;; => ("1 test" "2 test" "11 test" "21 test")
--
Protesilaos Stavrou
https://protesilaos.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-19 13:17 ` Protesilaos Stavrou
@ 2022-01-19 13:27 ` Eli Zaretskii
2022-01-19 14:09 ` Protesilaos Stavrou
0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2022-01-19 13:27 UTC (permalink / raw)
To: Protesilaos Stavrou; +Cc: 53362
> From: Protesilaos Stavrou <info@protesilaos.com>
> Cc: 53362@debbugs.gnu.org
> Date: Wed, 19 Jan 2022 15:17:13 +0200
>
> >> +(defcustom completions-sort 'lexicographic
> >> + "Sort candidates in the *Completions* buffer.
> >> +
> >> +The value can be nil to disable sorting altogether,
> >> +`alphabetical' for alphabetical sorting, `lexicographic' for
> >> +lexicographic sorting
> >
> > Here you expect everyone to understand the subtle difference between
> > these two sorting orders. I don't think this expectation is
> > reasonable.
>
> Perhaps it is better to reference string-lessp and string-version-lessp
> directly?
That'd be a step backward, IMO.
> > Doesn't string-version-lessp do stuff that is only appropriate with
> > version numbers like 1.2.3beta?
>
> It also helps when the string starts with a number:
>
> (sort '("1 test" "21 test" "11 test" "2 test") #'string-lessp)
> ;; => ("1 test" "11 test" "2 test" "21 test")
Yes, and how does that match the "alphabetical order" description?
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-19 13:27 ` Eli Zaretskii
@ 2022-01-19 14:09 ` Protesilaos Stavrou
2022-01-19 17:16 ` Protesilaos Stavrou
0 siblings, 1 reply; 9+ messages in thread
From: Protesilaos Stavrou @ 2022-01-19 14:09 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 53362
[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]
On 2022-01-19, 15:27 +0200, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Protesilaos Stavrou <info@protesilaos.com>
>> Cc: 53362@debbugs.gnu.org
>> Date: Wed, 19 Jan 2022 15:17:13 +0200
>>
>> >> +(defcustom completions-sort 'lexicographic
>> >> + "Sort candidates in the *Completions* buffer.
>> >> +
>> >> +The value can be nil to disable sorting altogether,
>> >> +`alphabetical' for alphabetical sorting, `lexicographic' for
>> >> +lexicographic sorting
>> >
>> > Here you expect everyone to understand the subtle difference between
>> > these two sorting orders. I don't think this expectation is
>> > reasonable.
>>
>> Perhaps it is better to reference string-lessp and string-version-lessp
>> directly?
>
> That'd be a step backward, IMO.
>
>> > Doesn't string-version-lessp do stuff that is only appropriate with
>> > version numbers like 1.2.3beta?
>>
>> It also helps when the string starts with a number:
>>
>> (sort '("1 test" "21 test" "11 test" "2 test") #'string-lessp)
>> ;; => ("1 test" "11 test" "2 test" "21 test")
>
> Yes, and how does that match the "alphabetical order" description?
In the revised patch (see attached), I follow the example of
completions-group-sort.
--
Protesilaos Stavrou
https://protesilaos.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-Completions-sorting-a-user-option.patch --]
[-- Type: text/x-patch, Size: 2859 bytes --]
From 3e9e0c2310afdcc921cda2a6d431d7fcbe1eb01a Mon Sep 17 00:00:00 2001
Message-Id: <3e9e0c2310afdcc921cda2a6d431d7fcbe1eb01a.1642601249.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Wed, 19 Jan 2022 14:20:19 +0200
Subject: [PATCH] Make Completions sorting a user option
* etc/NEWS: Document the new user option.
* lisp/minibuffer.el (completions-sort): Add new user option.
(minibuffer-completion-help): Implement it for the Completions buffer.
---
etc/NEWS | 6 ++++++
lisp/minibuffer.el | 16 +++++++++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 47dbfba9c0..8f68336d30 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -418,6 +418,12 @@ When non-nil, the commands 'next-completion' and 'previous-completion'
automatically wrap around on reaching the beginning or the end of
the *Completions* buffer.
+*** New user option 'completions-sort'.
+Controls the sorting of the completion candidates in the *Completions*
+buffer. Available styles are no sorting, alphabetical (the default),
+or a custom sort function (e.g. 'string-version-lessp'). The function
+takes and returns a list of completion candidate strings.
+
** Isearch and Replace
+++
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index ab760a42d1..7b7e734b72 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1169,6 +1169,18 @@ (defcustom completion-cycle-threshold nil
:version "24.1"
:type completion--cycling-threshold-type)
+(defcustom completions-sort 'alphabetical
+ "Sort candidates in the *Completions* buffer.
+
+The value can be nil to disable sorting, `alphabetical' for
+alphabetical sorting or a custom sorting function. The sorting
+function takes and returns a list of completion candidate
+strings."
+ :type '(choice (const :tag "No sorting" nil)
+ (const :tag "Alphabetical sorting" alphabetical)
+ function :tag "Custom function")
+ :version "29.1")
+
(defcustom completions-group nil
"Enable grouping of completion candidates in the *Completions* buffer.
See also `completions-group-format' and `completions-group-sort'."
@@ -2264,7 +2276,9 @@ (defun minibuffer-completion-help (&optional start end)
;; same, but not always.
(setq completions (if sort-fun
(funcall sort-fun completions)
- (sort completions 'string-lessp)))
+ (pcase completions-sort
+ ('alphabetical (sort completions #'string-lessp))
+ (_ completions))))
;; After sorting, group the candidates using the
;; `group-function'.
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#53362: [External] : bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-19 12:26 bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option Protesilaos Stavrou
2022-01-19 12:56 ` Eli Zaretskii
@ 2022-01-19 16:10 ` Drew Adams
1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2022-01-19 16:10 UTC (permalink / raw)
To: Protesilaos Stavrou, 53362@debbugs.gnu.org
See library sortie.el.
* Description: https://www.emacswiki.org/emacs/Sortie
* Code: https://www.emacswiki.org/emacs/download/sortie.el
You can define sort orders and choose among them on the fly.
Different sort orders are appropriate for different operations, different sets of completion candidates, and different use cases/contexts and users.
A user option to choose a preferred sort order is at best appropriate for an overall _default_ sort order.
It could also be a place to hold a set of sort orders, including orders defined by a user. But on its own, it can't deal with the need to be able to change sort orders anytime.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-19 14:09 ` Protesilaos Stavrou
@ 2022-01-19 17:16 ` Protesilaos Stavrou
2022-01-20 5:33 ` Protesilaos Stavrou
0 siblings, 1 reply; 9+ messages in thread
From: Protesilaos Stavrou @ 2022-01-19 17:16 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 53362
[-- Attachment #1: Type: text/plain, Size: 300 bytes --]
On 2022-01-19, 16:09 +0200, Protesilaos Stavrou <info@protesilaos.com> wrote:
> In the revised patch (see attached), I follow the example of
> completions-group-sort.
I sent a faulty patch. Sorry! Attached is the one that should work as intended.
--
Protesilaos Stavrou
https://protesilaos.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-Completions-sorting-a-user-option.patch --]
[-- Type: text/x-patch, Size: 2949 bytes --]
From 401b48c9b14f71dfa0f44e426fbbfe8fa48fd0f8 Mon Sep 17 00:00:00 2001
Message-Id: <401b48c9b14f71dfa0f44e426fbbfe8fa48fd0f8.1642612531.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Wed, 19 Jan 2022 14:20:19 +0200
Subject: [PATCH] Make Completions sorting a user option
* etc/NEWS: Document the new user option.
* lisp/minibuffer.el (completions-sort): Add new user option.
(minibuffer-completion-help): Implement it for the Completions buffer.
---
etc/NEWS | 6 ++++++
lisp/minibuffer.el | 17 ++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 47dbfba9c0..8f68336d30 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -418,6 +418,12 @@ When non-nil, the commands 'next-completion' and 'previous-completion'
automatically wrap around on reaching the beginning or the end of
the *Completions* buffer.
+*** New user option 'completions-sort'.
+Controls the sorting of the completion candidates in the *Completions*
+buffer. Available styles are no sorting, alphabetical (the default),
+or a custom sort function (e.g. 'string-version-lessp'). The function
+takes and returns a list of completion candidate strings.
+
** Isearch and Replace
+++
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index ab760a42d1..f332ef3793 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1169,6 +1169,18 @@ (defcustom completion-cycle-threshold nil
:version "24.1"
:type completion--cycling-threshold-type)
+(defcustom completions-sort 'alphabetical
+ "Sort candidates in the *Completions* buffer.
+
+The value can be nil to disable sorting, `alphabetical' for
+alphabetical sorting or a custom sorting function. The sorting
+function takes and returns a list of completion candidate
+strings."
+ :type '(choice (const :tag "No sorting" nil)
+ (const :tag "Alphabetical sorting" alphabetical)
+ function :tag "Custom function")
+ :version "29.1")
+
(defcustom completions-group nil
"Enable grouping of completion candidates in the *Completions* buffer.
See also `completions-group-format' and `completions-group-sort'."
@@ -2264,7 +2276,10 @@ (defun minibuffer-completion-help (&optional start end)
;; same, but not always.
(setq completions (if sort-fun
(funcall sort-fun completions)
- (sort completions 'string-lessp)))
+ (pcase completions-sort
+ ('nil completions)
+ ('alphabetical (sort completions #'string-lessp))
+ (_ (sort completions completions-sort)))))
;; After sorting, group the candidates using the
;; `group-function'.
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-19 17:16 ` Protesilaos Stavrou
@ 2022-01-20 5:33 ` Protesilaos Stavrou
2022-01-24 13:37 ` Eli Zaretskii
0 siblings, 1 reply; 9+ messages in thread
From: Protesilaos Stavrou @ 2022-01-20 5:33 UTC (permalink / raw)
To: 53362
[-- Attachment #1: Type: text/plain, Size: 497 bytes --]
On 2022-01-19, 19:16 +0200, Protesilaos Stavrou <info@protesilaos.com> wrote:
> On 2022-01-19, 16:09 +0200, Protesilaos Stavrou <info@protesilaos.com> wrote:
>
>> In the revised patch (see attached), I follow the example of
>> completions-group-sort.
>
> I sent a faulty patch. Sorry! Attached is the one that should work as intended.
This is awkward: I sent the wrong file twice.
If you are still reading this, I attach the definitive patch.
--
Protesilaos Stavrou
https://protesilaos.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-Completions-sorting-a-user-option.patch --]
[-- Type: text/x-patch, Size: 2922 bytes --]
From c5538d31855ba7184ffbd51230d17b81e5a083fe Mon Sep 17 00:00:00 2001
Message-Id: <c5538d31855ba7184ffbd51230d17b81e5a083fe.1642656616.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Wed, 19 Jan 2022 14:20:19 +0200
Subject: [PATCH] Make Completions sorting a user option
* etc/NEWS: Document the new user option.
* lisp/minibuffer.el (completions-sort): Add new user option.
(minibuffer-completion-help): Implement it for the Completions buffer.
---
etc/NEWS | 6 ++++++
lisp/minibuffer.el | 17 ++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 47dbfba9c0..23b23e922c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -418,6 +418,12 @@ When non-nil, the commands 'next-completion' and 'previous-completion'
automatically wrap around on reaching the beginning or the end of
the *Completions* buffer.
+*** New user option 'completions-sort'.
+Controls the sorting of the completion candidates in the *Completions*
+buffer. Available styles are no sorting, alphabetical (the default),
+or a custom sort function. The function takes and returns a list of
+completion candidate strings.
+
** Isearch and Replace
+++
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index ab760a42d1..643e0f309e 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1169,6 +1169,18 @@ (defcustom completion-cycle-threshold nil
:version "24.1"
:type completion--cycling-threshold-type)
+(defcustom completions-sort 'alphabetical
+ "Sort candidates in the *Completions* buffer.
+
+The value can be nil to disable sorting, `alphabetical' for
+alphabetical sorting or a custom sorting function. The sorting
+function takes and returns a list of completion candidate
+strings."
+ :type '(choice (const :tag "No sorting" nil)
+ (const :tag "Alphabetical sorting" alphabetical)
+ function :tag "Custom function")
+ :version "29.1")
+
(defcustom completions-group nil
"Enable grouping of completion candidates in the *Completions* buffer.
See also `completions-group-format' and `completions-group-sort'."
@@ -2264,7 +2276,10 @@ (defun minibuffer-completion-help (&optional start end)
;; same, but not always.
(setq completions (if sort-fun
(funcall sort-fun completions)
- (sort completions 'string-lessp)))
+ (pcase completions-sort
+ ('nil completions)
+ ('alphabetical (sort completions #'string-lessp))
+ (_ (funcall completions-sort completions)))))
;; After sorting, group the candidates using the
;; `group-function'.
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
2022-01-20 5:33 ` Protesilaos Stavrou
@ 2022-01-24 13:37 ` Eli Zaretskii
0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2022-01-24 13:37 UTC (permalink / raw)
To: Protesilaos Stavrou; +Cc: 53362-done
> From: Protesilaos Stavrou <info@protesilaos.com>
> Date: Thu, 20 Jan 2022 07:33:38 +0200
>
> If you are still reading this, I attach the definitive patch.
Thanks, now installed on master.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-01-24 13:37 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-19 12:26 bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option Protesilaos Stavrou
2022-01-19 12:56 ` Eli Zaretskii
2022-01-19 13:17 ` Protesilaos Stavrou
2022-01-19 13:27 ` Eli Zaretskii
2022-01-19 14:09 ` Protesilaos Stavrou
2022-01-19 17:16 ` Protesilaos Stavrou
2022-01-20 5:33 ` Protesilaos Stavrou
2022-01-24 13:37 ` Eli Zaretskii
2022-01-19 16:10 ` bug#53362: [External] : " Drew Adams
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.