]> git.eshelyaron.com Git - emacs.git/commitdiff
Make Completions sorting a user option
authorProtesilaos Stavrou <info@protesilaos.com>
Wed, 19 Jan 2022 12:20:19 +0000 (14:20 +0200)
committerEli Zaretskii <eliz@gnu.org>
Mon, 24 Jan 2022 13:36:11 +0000 (15:36 +0200)
* 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.  (Bug#53362)

etc/NEWS
lisp/minibuffer.el

index 73d12a203e09d27110eceabd31eca11b597be9a5..3f6b2d2a1fc113d8fc42da6d821469f70f58824a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -429,6 +429,11 @@ 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'.
+This option controls the sorting of the completion candidates in
+the *Completions* buffer.  Available styles are no sorting,
+alphabetical (the default), or a custom sort function.
+
 ** Isearch and Replace
 
 +++
index d58c23af8fbf7a363846b922129195ba8bd45c3a..ecede9479d8146d0d9278e6a7475e087cb24dabc 100644 (file)
@@ -1173,6 +1173,18 @@ completion candidates than this number."
   :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'."
@@ -2268,7 +2280,10 @@ variables.")
                       ;; 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'.