From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Protesilaos Stavrou Newsgroups: gmane.emacs.bugs Subject: bug#53362: 29.0.50; [PATCH] Make Completions sorting a user option Date: Wed, 19 Jan 2022 16:09:05 +0200 Message-ID: <878rvblsvy.fsf@protesilaos.com> References: <87h79zlxmg.fsf@protesilaos.com> <83wnivsx2f.fsf@gnu.org> <87bl07lvae.fsf@protesilaos.com> <83k0evsvn9.fsf@gnu.org> 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="38988"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Notmuch/0.34.2 (https://notmuchmail.org) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 53362@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 19 15:11:17 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1nABgD-0009zc-9r for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 15:11:17 +0100 Original-Received: from localhost ([::1]:33010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nABgC-0003LL-AU for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 09:11:16 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nABf5-0002Lx-2G for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 09:10:07 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60315) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nABf0-0003JY-Nw for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 09:10:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nABf0-00037u-FN for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 09:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Protesilaos Stavrou Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Jan 2022 14:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53362 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 53362-submit@debbugs.gnu.org id=B53362.164260135611880 (code B ref 53362); Wed, 19 Jan 2022 14:10:02 +0000 Original-Received: (at 53362) by debbugs.gnu.org; 19 Jan 2022 14:09:16 +0000 Original-Received: from localhost ([127.0.0.1]:53205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nABeF-00035X-Oi for submit@debbugs.gnu.org; Wed, 19 Jan 2022 09:09:16 -0500 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:39973) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nABeD-00035I-LD for 53362@debbugs.gnu.org; Wed, 19 Jan 2022 09:09:14 -0500 Original-Received: (Authenticated sender: public@protesilaos.com) by relay12.mail.gandi.net (Postfix) with ESMTPSA id D9FD420000A; Wed, 19 Jan 2022 14:09:06 +0000 (UTC) In-Reply-To: <83k0evsvn9.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:224589 Archived-At: --=-=-= Content-Type: text/plain On 2022-01-19, 15:27 +0200, Eli Zaretskii wrote: >> From: Protesilaos Stavrou >> 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-Completions-sorting-a-user-option.patch >From 3e9e0c2310afdcc921cda2a6d431d7fcbe1eb01a Mon Sep 17 00:00:00 2001 Message-Id: <3e9e0c2310afdcc921cda2a6d431d7fcbe1eb01a.1642601249.git.info@protesilaos.com> From: Protesilaos Stavrou 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 --=-=-=--