summaryrefslogtreecommitdiff
path: root/lisp/minibuffer.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2024-01-04 19:20:30 +0200
committerJuri Linkov <juri@linkov.net>2024-01-04 19:20:30 +0200
commitdc99be8e633fa0d8594b72f41584a53590939fde (patch)
tree54f1df1e061ac30a01c50c83e8041bb46234359c /lisp/minibuffer.el
parentd69fb6dab28e55447516341cf28f1b6d06937ad6 (diff)
downloademacs-dc99be8e633fa0d8594b72f41584a53590939fde.tar.gz
Support display-sort-function in completion-category-overrides (bug#68214)
* doc/lispref/minibuf.texi (Completion Variables): Add 'display-sort-function' to the table of 'completion-category-overrides'. * lisp/calendar/calendar.el (calendar-read-date): Add metadata category 'calendar-month' for completing-read reading a month name. * lisp/minibuffer.el (completion-category-defaults): Add 'display-sort-function' with identity for the category 'calendar-month'. (completion-category-overrides): Add customization for completion sorting with 'display-sort-function' and a choice like in 'completions-sort'. (completion-metadata-override-get): New function. (minibuffer-completion-help): Use 'completion-metadata-override-get' instead of 'completion-metadata-get' to get sort-fun from 'display-sort-function'.
Diffstat (limited to 'lisp/minibuffer.el')
-rw-r--r--lisp/minibuffer.el30
1 files changed, 27 insertions, 3 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index fa2dcb4f698..6ead11d81c8 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1135,12 +1135,14 @@ styles for specific categories, such as files, buffers, etc."
(project-file (styles . (substring)))
(xref-location (styles . (substring)))
(info-menu (styles . (basic substring)))
- (symbol-help (styles . (basic shorthand substring))))
+ (symbol-help (styles . (basic shorthand substring)))
+ (calendar-month (display-sort-function . identity)))
"Default settings for specific completion categories.
Each entry has the shape (CATEGORY . ALIST) where ALIST is
an association list that can specify properties such as:
- `styles': the list of `completion-styles' to use for that category.
- `cycle': the `completion-cycle-threshold' to use for that category.
+- `display-sort-function': the sorting function.
Categories are symbols such as `buffer' and `file', used when
completing buffer and file names, respectively.
@@ -1148,10 +1150,16 @@ Also see `completion-category-overrides'.")
(defcustom completion-category-overrides nil
"List of category-specific user overrides for completion styles.
+
Each override has the shape (CATEGORY . ALIST) where ALIST is
an association list that can specify properties such as:
- `styles': the list of `completion-styles' to use for that category.
- `cycle': the `completion-cycle-threshold' to use for that category.
+- `display-sort-function': where `nil' means to use either the sorting
+function from metadata or if it's nil then fall back to `completions-sort';
+`identity' means to not use any sorting to keep the original order;
+and other values are the same as in `completions-sort'.
+
Categories are symbols such as `buffer' and `file', used when
completing buffer and file names, respectively.
@@ -1171,12 +1179,28 @@ overrides the default specified in `completion-category-defaults'."
,completion--styles-type)
(cons :tag "Completion Cycling"
(const :tag "Select one value from the menu." cycle)
- ,completion--cycling-threshold-type))))
+ ,completion--cycling-threshold-type)
+ (cons :tag "Completion Sorting"
+ (const :tag "Select one value from the menu."
+ display-sort-function)
+ (choice (const :tag "Use default" nil)
+ (const :tag "No sorting" identity)
+ (const :tag "Alphabetical sorting"
+ minibuffer-sort-alphabetically)
+ (const :tag "Historical sorting"
+ minibuffer-sort-by-history)
+ (function :tag "Custom function"))))))
(defun completion--category-override (category tag)
(or (assq tag (cdr (assq category completion-category-overrides)))
(assq tag (cdr (assq category completion-category-defaults)))))
+(defun completion-metadata-override-get (metadata prop)
+ (if-let ((cat (completion-metadata-get metadata 'category))
+ (over (completion--category-override cat prop)))
+ (cdr over)
+ (completion-metadata-get metadata prop)))
+
(defun completion--styles (metadata)
(let* ((cat (completion-metadata-get metadata 'category))
(over (completion--category-override cat 'styles)))
@@ -2522,7 +2546,7 @@ The candidate will still be chosen by `choose-completion' unless
(aff-fun (or (completion-metadata-get all-md 'affixation-function)
(plist-get completion-extra-properties
:affixation-function)))
- (sort-fun (completion-metadata-get all-md 'display-sort-function))
+ (sort-fun (completion-metadata-override-get all-md 'display-sort-function))
(group-fun (completion-metadata-get all-md 'group-function))
(mainbuf (current-buffer))
;; If the *Completions* buffer is shown in a new