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 14:26:47 +0200 Message-ID: <87h79zlxmg.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="2422"; mail-complaints-to="usenet@ciao.gmane.io" To: 53362@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 19 13:46:20 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 1nAALz-0000Qt-SP for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 13:46:19 +0100 Original-Received: from localhost ([::1]:41852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAALw-0002dM-Rn for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 07:46:17 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAA4I-0003Xg-Db for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 07:28:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAA4I-000884-2P for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 07:28:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nAA4H-0003Y2-TJ for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 07:28: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 12:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 53362 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.164259523613579 (code B ref -1); Wed, 19 Jan 2022 12:28:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Jan 2022 12:27:16 +0000 Original-Received: from localhost ([127.0.0.1]:52561 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAA3Y-0003Wx-Hj for submit@debbugs.gnu.org; Wed, 19 Jan 2022 07:27:16 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:33214) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAA3U-0003Wn-2s for submit@debbugs.gnu.org; Wed, 19 Jan 2022 07:27:15 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAA3R-0003CR-Jj for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 07:27:11 -0500 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:49553) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAA3P-0007yg-Cm for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 07:27:09 -0500 Original-Received: (Authenticated sender: public@protesilaos.com) by mail.gandi.net (Postfix) with ESMTPSA id C9A0F100003 for ; Wed, 19 Jan 2022 12:26:48 +0000 (UTC) Received-SPF: none client-ip=217.70.178.231; envelope-from=info@protesilaos.com; helo=relay11.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:224560 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-Completions-sorting-a-user-option.patch >From e53bd2b2383f3dfa367f2af8d4ed43c6c42dd002 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 | 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 --=-=-=--