From: Protesilaos Stavrou <info@protesilaos.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 53362@debbugs.gnu.org
Subject: bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option
Date: Wed, 19 Jan 2022 16:09:05 +0200 [thread overview]
Message-ID: <878rvblsvy.fsf@protesilaos.com> (raw)
In-Reply-To: <83k0evsvn9.fsf@gnu.org>
[-- 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
next prev parent reply other threads:[~2022-01-19 14:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=878rvblsvy.fsf@protesilaos.com \
--to=info@protesilaos.com \
--cc=53362@debbugs.gnu.org \
--cc=eliz@gnu.org \
/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).