]> git.eshelyaron.com Git - emacs.git/commitdiff
Unify 'cycle-' and 'display-sort-function' to just 'sort-function'
authorEshel Yaron <me@eshelyaron.com>
Wed, 28 Feb 2024 16:56:50 +0000 (17:56 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 28 Feb 2024 17:00:13 +0000 (18:00 +0100)
12 files changed:
lisp/completion-preview.el
lisp/dabbrev.el
lisp/ecomplete.el
lisp/external-completion.el
lisp/faces.el
lisp/international/mule-cmds.el
lisp/minibuffer.el
lisp/net/rcirc.el
lisp/pcomplete.el
lisp/progmodes/eglot.el
lisp/recentf.el
lisp/tmm.el

index e827da43a08d87fc9770baff841f800bbb3d2932..75386f9642987952e4eee0061e224aff784f8860 100644 (file)
@@ -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
index 853c0f4b29073775ff2165fb523b5f1d1cae31de..63eba4b999123975c3ede68860e6fbc390b821f6 100644 (file)
@@ -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
index ee79dd5fa473cc802a95fb58dd73077efc6b26f5..56cc6376492e4628114577f9f9408cf2ad5e747d 100644 (file)
@@ -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
index b171e27014ce572f1a522362af496fc44d76d072..7a25653700f3403256d41b869b95a51658218394 100644 (file)
@@ -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
index 2cbf1e56583f0aa34fd8e82c53b312ec8690755b..e9f2cb42a567df713b8772bb49fcc570f13da8bb 100644 (file)
@@ -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
index 99ad70dc5d93b8c6df6ad5ec62ce9eb0bee57e1e..75c9f9383446eabd86952c25bd3dc1db8aeea411 100644 (file)
@@ -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)
index 4b70e2ec6d4eaebb244c293fa488aa2c07614668..8df8bb62815d71fe832009466482b39ed5b3ff66 100644 (file)
@@ -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)
index 0835d25460c16603e90ad9939146c876df1cc2b7..f6efb728d9c1fd7a2850135eb1ba4345a03bb4ef 100644 (file)
@@ -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)
index 46ec67d5de6c31994cd63cbf3c2d103aeae0e1aa..8b435f64ba485948d3e16cbe91741ed72e172732 100644 (file)
@@ -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)))
index 6d79d1e67c597207e88c1745790277075d4bfd0e..8201ef53a7de04f564b1fc0e95ff18fcb43d239d 100644 (file)
@@ -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))
index b236eea2be948b7ab092dd1fdb92ecd80c977e4c..5db412ca0c59e2691f40897f58888a554fd885fd 100644 (file)
@@ -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)
 
index 8c0f192322a4f1cc2870cc7cfa02eeb7b1a1e48f..b04afc4881a115b96276ffec2229b4f774d977e4 100644 (file)
@@ -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)