From c9ac633fa9ad9e43f84e7f67c02e1d87ced2d2e3 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 28 Feb 2024 17:56:50 +0100 Subject: [PATCH] Unify 'cycle-' and 'display-sort-function' to just 'sort-function' --- lisp/completion-preview.el | 3 +- lisp/dabbrev.el | 2 +- lisp/ecomplete.el | 3 +- lisp/external-completion.el | 8 ++-- lisp/faces.el | 3 +- lisp/international/mule-cmds.el | 2 +- lisp/minibuffer.el | 81 ++++++++++++++++----------------- lisp/net/rcirc.el | 2 +- lisp/pcomplete.el | 2 +- lisp/progmodes/eglot.el | 4 +- lisp/recentf.el | 5 +- lisp/tmm.el | 2 +- 12 files changed, 55 insertions(+), 62 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index e827da43a08..75386f96429 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -233,8 +233,7 @@ non-nil, return nil instead." (exit-fn (plist-get props :exit-function)) (string (buffer-substring beg end)) (md (completion-metadata string table pred)) - (sort-fn (or (completion-metadata-get md 'cycle-sort-function) - (completion-metadata-get md 'display-sort-function) + (sort-fn (or (completion-metadata-get md 'sort-function) completion-preview-sort-function)) (all (let ((completion-lazy-hilit t)) (completion-all-completions string table pred diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 853c0f4b290..63eba4b9991 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el @@ -408,7 +408,7 @@ then it searches *all* buffers." (table (lambda (s p a) (if (eq a 'metadata) - `(metadata (cycle-sort-function . ,#'identity) + `(metadata (sort-function . ,#'identity) (category . dabbrev)) (when (eq list 'uninitialized) (save-excursion diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el index ee79dd5fa47..56cc6376492 100644 --- a/lisp/ecomplete.el +++ b/lisp/ecomplete.el @@ -273,8 +273,7 @@ non-nil and there is only a single completion option available." (pcase action (`(boundaries . ,_) nil) ('metadata `(metadata (category . ecomplete) - (display-sort-function . ,#'identity) - (cycle-sort-function . ,#'identity))) + (sort-function . ,#'identity))) (_ (let* ((elems (cdr (assq type ecomplete-database))) (candidates diff --git a/lisp/external-completion.el b/lisp/external-completion.el index b171e27014c..7a25653700f 100644 --- a/lisp/external-completion.el +++ b/lisp/external-completion.el @@ -92,10 +92,10 @@ should detect pending user input using `while-no-input' or cancel the request (if possible) and immediately return any non-list. -METADATA is an alist of additional properties such as -`cycle-sort-function' to associate with CATEGORY. This means -that the caller may still retain control the sorting of the -candidates while the tool controls the matching. +METADATA is an alist of additional properties such as `sort-function' to +associate with CATEGORY. This means that the caller may still retain +control the sorting of the candidates while the tool controls the +matching. Optional TRY-COMPLETION-FUNCTION helps some frontends partially or fully expand PATTERN before finishing the completion diff --git a/lisp/faces.el b/lisp/faces.el index 2cbf1e56583..e9f2cb42a56 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -1198,8 +1198,7 @@ STRING, PRED and ACTION." (if (eq action 'metadata) `(metadata (category . face) - (display-sort-function . read-face-name-sort-aliases-last) - (cycle-sort-function . read-face-name-sort-aliases-last) + (sort-function . read-face-name-sort-aliases-last) ,@(when read-face-name-sample-text '((affixation-function . completion-face-name-affixation)))) (complete-with-action action obarray string diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 99ad70dc5d9..75c9f938344 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3312,7 +3312,7 @@ single characters to be treated as standing for themselves." (completing-read prompt (completion-table-with-metadata (ucs-names) - `((display-sort-function . ,sort-fun) + `((sort-function . ,sort-fun) (affixation-function . ,#'mule--ucs-names-affixation) (narrow-completions-function . ,#'mule--ucs-names-narrow) (group-function . ,group-fun) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 4b70e2ec6d4..8df8bb62815 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -133,11 +133,9 @@ This metadata is an alist. Currently understood keys are: belongs. The returned title may be nil. Otherwise the function returns the transformed candidate. The transformation can remove a redundant prefix, which is displayed in the group title. -- `display-sort-function': function to sort entries in *Completions*. +- `sort-function': function to sort completion candidates. Takes one argument (COMPLETIONS) and should return a new list of completions. Can operate destructively. -- `cycle-sort-function': function to sort entries when cycling. - Works like `display-sort-function'. - `narrow-completions-function': function for narrowing (restricting) the completions list. This function overrides `minibuffer-narrow-completions-function', which see. @@ -176,11 +174,18 @@ specify the property, the `completion-extra-properties' plist is consulted. Note that the keys of the `completion-extra-properties' plist are keyword symbols, not plain symbols." - (if-let (((not (eq prop 'category))) - (cat (completion--metadata-get-1 metadata 'category)) - (over (completion--category-override cat prop))) - (cdr over) - (completion--metadata-get-1 metadata prop))) + (let ((cat (completion--metadata-get-1 metadata 'category))) + (cond + ((eq prop 'category) cat) + ((eq prop 'sort-function) + (or (cdr (completion--category-override cat 'sort-function)) + (completion--metadata-get-1 metadata 'sort-function) + (cdr (completion--category-override cat 'cycle-sort-function)) + (completion--metadata-get-1 metadata 'cycle-sort-function) + (cdr (completion--category-override cat 'display-sort-function)) + (completion--metadata-get-1 metadata 'display-sort-function))) + (t (or (cdr (completion--category-override cat prop)) + (completion--metadata-get-1 metadata prop)))))) (defun complete-with-action (action collection string predicate) "Perform completion according to ACTION. @@ -1189,15 +1194,14 @@ styles for specific categories, such as files, buffers, etc." (xref-location (styles . (substring))) (info-menu (styles . (basic substring))) (symbol-help (styles . (basic shorthand substring))) - (calendar-month (display-sort-function . identity))) + (calendar-month (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. -- `cycle-sort-function': function to sort entries when cycling. -- `display-sort-function': function to sort entries in *Completions*. +- `sort-function': function to sort entries when cycling. - `group-function': function for grouping the completion candidates. - `annotation-function': function to add annotations in *Completions*. - `affixation-function': function to prepend/append a prefix/suffix. @@ -1215,8 +1219,7 @@ 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. -- `cycle-sort-function': function to sort entries when cycling. -- `display-sort-function': nil means to use either the sorting +- `sort-function': function to sort entries when cycling. function from metadata, or if that is nil, fall back to `completions-sort'; `identity' disables sorting and keeps the original order; and other possible values are the same as in `completions-sort'. @@ -1245,10 +1248,8 @@ overrides the default specified in `completion-category-defaults'." (cons :tag "Cycling threshold" (const cycle) ,completion--cycling-threshold-type) - (cons :tag "Cycle order" - (const cycle-sort-function) function) - (cons :tag "Sorting for display" - (const display-sort-function) + (cons :tag "Sort order" + (const sort-function) (choice (const :tag "Default sorting" nil) (const :tag "No sorting" identity) @@ -1439,9 +1440,8 @@ The sorting function takes a list of completion candidate strings, which it may modify; it should return a sorted list, which may be the same. -If the completion-specific metadata provides a -`display-sort-function', that function overrides the value of -this variable." +If the completion-specific metadata provides a `sort-function', that +function overrides the value of this variable." :type '(choice (const :tag "No sorting" nil) (const :tag "Alphabetical sorting" alphabetical) (const :tag "Historical sorting" historical) @@ -1874,7 +1874,7 @@ Remove completion BASE prefix string from history elements." COMPLETIONS are sorted alphabetically by `string-lessp'. This is a suitable function to use for `completions-sort' or to -include as `display-sort-function' in completion metadata." +include as `sort-function' in completion metadata." (sort completions #'string-lessp)) (defvar minibuffer-completion-base nil @@ -1896,7 +1896,7 @@ this call of `completing-read', COMPLETIONS are sorted only by `minibuffer-sort-alphbetically'. This is a suitable function to use for `completions-sort' or to -include as `display-sort-function' in completion metadata." +include as `sort-function' in completion metadata." (let ((alphabetized (sort completions #'string-lessp))) ;; Only use history when it's specific to these completions. (if (eq minibuffer-history-variable @@ -1943,7 +1943,12 @@ include as `display-sort-function' in completion metadata." minibuffer-completion-predicate)) (sort-fun (or minibuffer-completions-sort-function - (completion-metadata-get all-md 'cycle-sort-function))) + (completion-metadata-get all-md 'sort-function) + (pcase completions-sort + ('nil #'identity) + ('alphabetical #'minibuffer-sort-alphabetically) + ('historical #'minibuffer-sort-by-history) + (_ completions-sort)))) (group-fun (completion-metadata-get all-md 'group-function)) (full-base (substring string 0 base-size)) (minibuffer-completion-base @@ -2602,7 +2607,7 @@ and with BASE-SIZE appended as the last element." When the value of this variable is a function, `minibuffer-completion-help' uses that function to sort the -completions list instead of using the `display-sort-function' +completions list instead of using the `sort-function' from the completion table or the value of `completions-sort'. `minibuffer-sort-completions' sets the value of this variable to @@ -2673,9 +2678,7 @@ These include: `:group-function': Function for grouping the completion candidates. -`:display-sort-function': Function to sort entries in *Completions*. - -`:cycle-sort-function': Function to sort entries when cycling. +`:sort-function': Function to sort completion candidates. `:narrow-completions-function': function for narrowing the completions list. @@ -2757,7 +2760,7 @@ current order instead." (or (completion-metadata-get (completion--field-metadata (minibuffer-prompt-end)) - 'display-sort-function) + 'sort-function) (pcase completions-sort ('nil #'identity) ('alphabetical #'minibuffer-sort-alphabetically) @@ -2922,7 +2925,7 @@ completions list." minibuffer-completion-predicate)) (ann-fun (completion-metadata-get all-md 'annotation-function)) (aff-fun (completion-metadata-get all-md 'affixation-function)) - (sort-fun (completion-metadata-get all-md 'display-sort-function)) + (sort-fun (completion-metadata-get all-md 'sort-function)) (group-fun (completion-metadata-get all-md 'group-function)) (category (completion-metadata-get all-md 'category)) (minibuffer-completion-base @@ -2960,7 +2963,7 @@ completions list." comp)) completions))) - ;; Sort first using the `display-sort-function'. + ;; Sort first using the `sort-function'. ;; FIXME: This function is for the output of ;; all-completions, not ;; completion-all-completions. Often it's the @@ -4152,8 +4155,7 @@ possible completions." (if (eq action 'metadata) `(metadata (category . buffer) - (cycle-sort-function . identity) - (display-sort-function . identity) + (sort-function . identity) (narrow-completions-function . minibuffer-narrow-buffer-completions) ,@(when completions-detailed '((affixation-function . completion-buffer-name-affixation)))) @@ -5047,10 +5049,7 @@ that is non-nil." (defun completion--flex-adjust-metadata (metadata) "If `flex' is actually doing filtering, adjust sorting." (let ((flex-is-filtering-p completion-pcm--regexp) - (existing-dsf - (completion-metadata-get metadata 'display-sort-function)) - (existing-csf - (completion-metadata-get metadata 'cycle-sort-function))) + (existing-sf (completion-metadata-get metadata 'sort-function))) (cl-flet ((compose-flex-sort-fn (existing-sort-fn) (lambda (completions) @@ -5076,9 +5075,7 @@ that is non-nil." sorted)))) `(metadata ,@(and flex-is-filtering-p - `((display-sort-function . ,(compose-flex-sort-fn existing-dsf)))) - ,@(and flex-is-filtering-p - `((cycle-sort-function . ,(compose-flex-sort-fn existing-csf)))) + `((sort-function . ,(compose-flex-sort-fn existing-sf)))) ,@(cdr metadata))))) (defun completion-flex--make-flex-pattern (pattern) @@ -5421,8 +5418,7 @@ instead of the default completion table." (completion-in-region (minibuffer--completion-prompt-end) (point-max) (completion-table-with-metadata - completions '((display-sort-function . identity) - (cycle-sort-function . identity))))))) + completions '((sort-function . identity))))))) (defun minibuffer-complete-defaults () "Complete minibuffer defaults as far as possible. @@ -5439,8 +5435,7 @@ instead of the completion table." (completion-in-region (minibuffer--completion-prompt-end) (point-max) (completion-table-with-metadata - completions '((display-sort-function . identity) - (cycle-sort-function . identity)))))) + completions '((sort-function . identity)))))) (define-key minibuffer-local-map [?\C-x up] 'minibuffer-complete-history) (define-key minibuffer-local-map [?\C-x down] 'minibuffer-complete-defaults) diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index 0835d25460c..f6efb728d9c 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -1325,7 +1325,7 @@ The list is updated automatically by `defun-rcirc-command'.") (list beg (point) (lambda (str pred action) (if (eq action 'metadata) - '(metadata (cycle-sort-function . identity)) + '(metadata (sort-function . identity)) (complete-with-action action table str pred))))))) (defun rcirc-set-decode-coding-system (coding-system) diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 46ec67d5de6..8b435f64ba4 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -913,7 +913,7 @@ this is `comint-dynamic-complete-functions'." (or (null predicate) (funcall predicate f)))))))) (lambda (s p a) (if (and (eq a 'metadata) pcomplete-compare-entry-function) - `(metadata (cycle-sort-function + `(metadata (sort-function . ,(lambda (comps) (sort comps pcomplete-compare-entry-function))) ,@(cdr (completion-file-name-table s p a))) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 6d79d1e67c5..8201ef53a7d 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -2893,7 +2893,7 @@ If BUFFER, switch to it before." (external-completion-table 'eglot-indirection-joy #'lookup - `((cycle-sort-function + `((sort-function . ,(lambda (completions) (cl-sort completions #'> :key #'score)))))))) @@ -3086,7 +3086,7 @@ for which LSP on-type-formatting should be requested." (get-text-property 0 'eglot--lsp-item c) :sortText))))) (metadata `(metadata (category . eglot-capf) - (display-sort-function . ,sort-completions))) + (sort-function . ,sort-completions))) (local-cache :none) (orig-pos (point)) (resolved (make-hash-table)) diff --git a/lisp/recentf.el b/lisp/recentf.el index b236eea2be9..5db412ca0c5 100644 --- a/lisp/recentf.el +++ b/lisp/recentf.el @@ -501,13 +501,14 @@ is not already on." ;; category, so users can configure the two separately. (category . recent-file) ;; Sort candidates by their position in `recentf-list'. - (cycle-sort-function . identity) - (display-sort-function . identity) + (sort-function . identity) ,@(when completions-detailed '((affixation-function . completion-file-name-affixation))))) nil 'confirm)))) (funcall recentf-menu-action file)) +(put 'recentf-open 'minibuffer-action 'find-file) + ;;;###autoload (defalias 'recentf 'recentf-open) diff --git a/lisp/tmm.el b/lisp/tmm.el index 8c0f192322a..b04afc4881a 100644 --- a/lisp/tmm.el +++ b/lisp/tmm.el @@ -115,7 +115,7 @@ specify nil for this variable." "Face used for inactive menu items.") (defun tmm--completion-table (items) - (completion-table-with-metadata items '((display-sort-function . identity)))) + (completion-table-with-metadata items '((sort-function . identity)))) (defvar tmm--history nil) -- 2.39.5