From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.devel Subject: Re: Updating *Completions* as you type Date: Thu, 19 Oct 2023 02:29:20 +0000 (UTC) Message-ID: <87y1fztke8.fsf@catern.com> References: <87bkd3z9bi.fsf@catern.com> <86cyxjyr1y.fsf@mail.linkov.net> <86r0lxm7um.fsf@mail.linkov.net> <87sf6dx954.fsf@catern.com> <87ttqpwea9.fsf@catern.com> <86wmvlw178.fsf@mail.linkov.net> <87bkcwx3ft.fsf@catern.com> <86y1g076vh.fsf@mail.linkov.net> <87sf68unh1.fsf@catern.com> <86zg0fu99i.fsf@mail.linkov.net> <875y33v73h.fsf@catern.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="22635"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 19 04:30:21 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qtIni-0005ct-Bt for ged-emacs-devel@m.gmane-mx.org; Thu, 19 Oct 2023 04:30:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtImr-0002qd-Ja; Wed, 18 Oct 2023 22:29:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtImp-0002qR-J5 for emacs-devel@gnu.org; Wed, 18 Oct 2023 22:29:23 -0400 Original-Received: from s.wrqvwxzv.outbound-mail.sendgrid.net ([149.72.154.232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtImn-0006Q4-RZ for emacs-devel@gnu.org; Wed, 18 Oct 2023 22:29:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: cc:content-type:from:subject:to; s=s1; bh=/WKXKUvM1N81ktQCJE3LE636VCIH93IbiptOz9Iqcdo=; b=JceUKTfyyNBAn7Na/NpuWvkWM2XyMNQDKRiOPa+T7Nw3/w00hBRY3+HT/RjH71+7MLbM JXTSltqLrXiTTMF7Sm0jmX6Rt+9BBQOAPY3XoT43W24gPqHkSKOV+FPC1I0fewBEunv42h FrDnhyt4vliZiPNlTW5RUXbpoU0wFQrm97CkvYSYuH2pwVfnF7xlGy0JsMj3Z52rVlPlkN uF1frxXhYiNi8EssnApOc/nd+D7DberfbX2C6qgF2eJKOkxlqTyB8JuKapNz+300KguP1l +S2kHXgJ2j90H3+Jj9l8oMZA6dT6v8/hUX5l8LS/ulSTKDLUJ/Y3CNNUY1M6ZtrQ== Original-Received: by filterdrecv-canary-7c48c4df88-8m24j with SMTP id filterdrecv-canary-7c48c4df88-8m24j-1-65309480-C 2023-10-19 02:29:20.453782115 +0000 UTC m=+114510.169514428 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-24 (SG) with ESMTP id 1wgMtNfFTTCEVFq5f57qXw Thu, 19 Oct 2023 02:29:20.340 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver=linkov.net Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id C29B166EE9; Wed, 18 Oct 2023 22:29:19 -0400 (EDT) In-Reply-To: <875y33v73h.fsf@catern.com> X-SG-EID: =?us-ascii?Q?GW3oCMoYnalRiojMOuLzE6x2H5kORXvlCdz1UwQVRMVT4fbh9ODEfCogOe74cO?= =?us-ascii?Q?rI4e0V+MFZgakz9Re5a6=2FCgtgtVoqBzyIobu=2Fkn?= =?us-ascii?Q?vBrmdRmknfhtQpZIixEuobupOfVdg=2Fm9yZYa=2FwZ?= =?us-ascii?Q?swJE9xsq4VmHIGZzOVdk9ab1MvYq0W+fXaRwWIa?= =?us-ascii?Q?rutZTr=2F7TiZos5iAHOxIiPo8qHwApM5F0vnvDpB?= =?us-ascii?Q?=2FqGSUx+IBHdSx=2FoI6eT6Se90LfzpsKgrHkuX7R?= X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== Received-SPF: pass client-ip=149.72.154.232; envelope-from=bounces+21787432-489d-emacs-devel=gnu.org@em8926.catern.com; helo=s.wrqvwxzv.outbound-mail.sendgrid.net X-Spam_score_int: 6 X-Spam_score: 0.6 X-Spam_bar: / X-Spam_report: (0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_BL_SPAMCOP_NET=1.347, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_RPBL=1.31, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:311569 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Spencer Baugh writes: > Juri Linkov writes: > >>>> Actually there is already a nil value in completions-sort with the tag >>>> "No sorting". This works nicely for 'C-x b'. The remaining need is >>>> to be able to set it only for 'C-x b', not for other completion types. >>> >>> I feel quite strongly that we should not extend completions-sort to be >>> able to affect different completion types differently. Instead I think >>> we should leave completions-sort as a blanket configuration for what to >>> do if the completion metadata does not specify display-sort-function, >>> and if we want to allow customizing an individual completion type, that >>> completion type should specify a display-sort-function which can be >>> customized. >>> >>> If we do extend completions-sort to affect different completion types >>> differently, I expect we'll see lots of silly things, like packages with >>> new completion types which automatically install changes to >>> completions-sort instead of just specifying their own >>> display-sort-function. >> >> Probably different completion types should provide separate options >> such as e.g. 'read-char-by-name-sort' defines 'display-sort-function' >> for 'read-char-by-name'. > > Agreed. > >> The same could be added for 'C-x b'. But unfortunately currently >> it's hard-coded in 'internal-complete-buffer': >> >> #+begin_src c >> else if (EQ (flag, Qmetadata)) >> return list3 (Qmetadata, >> Fcons (Qcategory, Qbuffer), >> Fcons (Qcycle_sort_function, Qidentity)); >> #+end_src > > Not hard to fix. I will post a patch to make this customizable soon. How about this? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-read-buffer-sort.patch >From 2c5807193713893b8cecacf6ae9318e3e504fb93 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Wed, 18 Oct 2023 22:28:59 -0400 Subject: [PATCH] Add read-buffer-sort Add the ability to customize how read-buffer (actually internal-complete-buffer) sorts the buffer completion candidates. * lisp/cus-start.el (standard): Add customization information for read-buffer-sort. * src/minibuf.c (Finternal_complete_buffer): Use read-buffer-sort. (syms_of_minibuf): Add read-buffer-sort. --- lisp/cus-start.el | 4 ++++ src/minibuf.c | 26 +++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lisp/cus-start.el b/lisp/cus-start.el index 054683d7cf6..569a0cf54b3 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -439,6 +439,10 @@ minibuffer-prompt-properties--setter (read-buffer-function minibuffer (choice (const nil) function)) + (read-buffer-sort minibuffer + (choice (const :tag "completions-sort controls sorting" nil) + (const :tag "sort matching buffer-list" buffer-list)) + "30.1") ;; msdos.c (dos-unsupported-char-glyph display integer) ;; nsterm.m diff --git a/src/minibuf.c b/src/minibuf.c index 58adde1bf66..715b4c08886 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -2186,9 +2186,13 @@ DEFUN ("internal-complete-buffer", Finternal_complete_buffer, Sinternal_complete else if (EQ (flag, Qlambda)) return Ftest_completion (string, Vbuffer_alist, predicate); else if (EQ (flag, Qmetadata)) - return list3 (Qmetadata, - Fcons (Qcategory, Qbuffer), - Fcons (Qcycle_sort_function, Qidentity)); + { + Lisp_Object res = list2 (Fcons (Qcategory, Qbuffer), + Fcons (Qcycle_sort_function, Qidentity)); + if (EQ (Vread_buffer_sort, Qbuffer_list)) + res = Fcons (Fcons (Qdisplay_sort_function, Qidentity), res); + return Fcons (Qmetadata, res); + } else return Qnil; } @@ -2323,6 +2327,7 @@ syms_of_minibuf (void) DEFSYM (Qcase_fold_search, "case-fold-search"); DEFSYM (Qmetadata, "metadata"); DEFSYM (Qcycle_sort_function, "cycle-sort-function"); + DEFSYM (Qdisplay_sort_function, "display-sort-function"); /* A frame parameter. */ DEFSYM (Qminibuffer_exit, "minibuffer-exit"); @@ -2522,6 +2527,21 @@ syms_of_minibuf (void) the minibuffer. However, if `minibuffer-restore-windows' is present in `minibuffer-exit-hook', exiting the minibuffer will remove the window showing the *Completions* buffer, if any. */); + + DEFVAR_LISP ("read-buffer-sort", Vread_buffer_sort, + doc: /* Non-nil means sort completions in `read-buffer'. + +If this is nil (the default), completions in `read-buffer' are sorted +according to `completions-sort'. + +If this is `buffer-list', completions are sorted to match the order of +`buffer-list'. + +This variable only affects the default `read-buffer', so if +`read-buffer-function' is set to a function which does not use +`internal-complete-buffer', this variable will have no effect.*/); + Vread_buffer_sort = Qnil; + read_minibuffer_restore_windows = true; defsubr (&Sactive_minibuffer_window); -- 2.41.0 --=-=-=--