[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating *Completions* as you type

From: Spencer Baugh
Subject: Re: Updating *Completions* as you type
Date: Thu, 19 Oct 2023 02:29:20 +0000 (UTC)

Spencer Baugh <sbaugh@catern.com> writes:

> Juri Linkov <juri@linkov.net> 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?

>From 2c5807193713893b8cecacf6ae9318e3e504fb93 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@catern.com>
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
* 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)
+             (read-buffer-sort minibuffer
+                               (choice (const :tag "completions-sort controls 
sorting" nil)
+                                       (const :tag "sort matching 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);
+    }
     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
+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);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]