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 19:16:57 +0200 Message-ID: <87zgnrk5me.fsf@protesilaos.com> References: <87h79zlxmg.fsf@protesilaos.com> <83wnivsx2f.fsf@gnu.org> <87bl07lvae.fsf@protesilaos.com> <83k0evsvn9.fsf@gnu.org> <878rvblsvy.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="13542"; 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 18:33:38 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 1nAEq2-0003Iv-2s for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 18:33:38 +0100 Original-Received: from localhost ([::1]:42566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAEq0-0006Sv-IU for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 12:33:36 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAEbJ-000294-4z for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 12:18:26 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAEaw-000055-88 for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 12:18:21 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nAEav-0002y1-UB for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 12:18:01 -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 17:18:01 +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.164261263111329 (code B ref 53362); Wed, 19 Jan 2022 17:18:01 +0000 Original-Received: (at 53362) by debbugs.gnu.org; 19 Jan 2022 17:17:11 +0000 Original-Received: from localhost ([127.0.0.1]:55404 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAEa6-0002wf-RM for submit@debbugs.gnu.org; Wed, 19 Jan 2022 12:17:11 -0500 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:58465) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAEa1-0002w2-RH for 53362@debbugs.gnu.org; Wed, 19 Jan 2022 12:17:09 -0500 Original-Received: (Authenticated sender: public@protesilaos.com) by mail.gandi.net (Postfix) with ESMTPSA id 1120520010; Wed, 19 Jan 2022 17:16:58 +0000 (UTC) In-Reply-To: <878rvblsvy.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:224623 Archived-At: --=-=-= Content-Type: text/plain 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. -- Protesilaos Stavrou https://protesilaos.com --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-Completions-sorting-a-user-option.patch >From 401b48c9b14f71dfa0f44e426fbbfe8fa48fd0f8 Mon Sep 17 00:00:00 2001 Message-Id: <401b48c9b14f71dfa0f44e426fbbfe8fa48fd0f8.1642612531.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 | 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 --=-=-=--