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: Thu, 20 Jan 2022 07:33:38 +0200 Message-ID: <87czkn55u5.fsf@protesilaos.com> References: <87h79zlxmg.fsf@protesilaos.com> <83wnivsx2f.fsf@gnu.org> <87bl07lvae.fsf@protesilaos.com> <83k0evsvn9.fsf@gnu.org> <878rvblsvy.fsf@protesilaos.com> <87zgnrk5me.fsf@protesilaos.com> 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="34985"; 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) To: 53362@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 20 06:34:29 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 1nAQ5b-0008o1-C1 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 20 Jan 2022 06:34:27 +0100 Original-Received: from localhost ([::1]:37162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAQ5Z-0007rM-HD for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 20 Jan 2022 00:34:25 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAQ5E-0007r0-Iy for bug-gnu-emacs@gnu.org; Thu, 20 Jan 2022 00:34:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34924) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAQ5C-0006P7-V4 for bug-gnu-emacs@gnu.org; Thu, 20 Jan 2022 00:34:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nAQ5C-0001Uc-Dv for bug-gnu-emacs@gnu.org; Thu, 20 Jan 2022 00:34: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: Thu, 20 Jan 2022 05:34: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.16426568285715 (code B ref 53362); Thu, 20 Jan 2022 05:34:02 +0000 Original-Received: (at 53362) by debbugs.gnu.org; 20 Jan 2022 05:33:48 +0000 Original-Received: from localhost ([127.0.0.1]:56060 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAQ4y-0001U6-3T for submit@debbugs.gnu.org; Thu, 20 Jan 2022 00:33:48 -0500 Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]:57075) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAQ4w-0001Tp-JQ for 53362@debbugs.gnu.org; Thu, 20 Jan 2022 00:33:47 -0500 Original-Received: (Authenticated sender: public@protesilaos.com) by mail.gandi.net (Postfix) with ESMTPSA id B9C2D60002 for <53362@debbugs.gnu.org>; Thu, 20 Jan 2022 05:33:39 +0000 (UTC) In-Reply-To: <87zgnrk5me.fsf@protesilaos.com> 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:224648 Archived-At: --=-=-= Content-Type: text/plain On 2022-01-19, 19:16 +0200, Protesilaos Stavrou wrote: > On 2022-01-19, 16:09 +0200, Protesilaos Stavrou 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-Completions-sorting-a-user-option.patch >From c5538d31855ba7184ffbd51230d17b81e5a083fe Mon Sep 17 00:00:00 2001 Message-Id: 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 | 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 --=-=-=--