summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2022-01-30 23:52:26 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2022-01-30 23:52:26 +0100
commit085eb192da194f90ebfa6b9e405fe8f459bd2205 (patch)
treecf47c0b25b2fcd296d701f3657d1607894423c09
parente0ebfdfcdaea50c7bab6e07987ed2053e37ccbc0 (diff)
Use the cycle-sort-function when cycling (Fix #113)
-rw-r--r--corfu.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/corfu.el b/corfu.el
index 871b06f..51f7186 100644
--- a/corfu.el
+++ b/corfu.el
@@ -562,12 +562,14 @@ A scroll bar is displayed from LO to LO+BAR."
"\\)\\'")))
(or (seq-remove (lambda (x) (string-match-p re x)) files) files)))
-(defun corfu--sort-function ()
- "Return the sorting function."
- (or (corfu--metadata-get 'display-sort-function) corfu-sort-function))
-
-(defun corfu--recompute-candidates (str pt table pred)
- "Recompute candidates from STR, PT, TABLE and PRED."
+(defun corfu--sort-function (cycle)
+ "Return the (CYCLE or display) sort function."
+ (or (corfu--metadata-get (if cycle 'cycle-sort-function 'display-sort-function))
+ corfu-sort-function))
+
+(defun corfu--recompute-candidates (str pt table pred cycle)
+ "Recompute candidates from STR, PT, TABLE and PRED.
+Either use the CYCLE or the display sort function."
(pcase-let* ((before (substring str 0 pt))
(after (substring str pt))
(corfu--metadata (completion-metadata before table pred))
@@ -585,8 +587,9 @@ A scroll bar is displayed from LO to LO+BAR."
;; since this breaks the special casing in the `completion-file-name-table' for `file-exists-p'
;; and `file-directory-p'.
(when completing-file (setq all (corfu--filter-files all)))
- (setq all (delete-consecutive-dups (funcall (or (corfu--sort-function) #'identity) all)))
- (setq all (corfu--move-prefix-candidates-to-front field all))
+ (setq all (funcall (or (corfu--sort-function cycle) #'identity) all)
+ all (delete-consecutive-dups all)
+ all (corfu--move-prefix-candidates-to-front field all))
(when (and completing-file (not (string-suffix-p "/" field)))
(setq all (corfu--move-to-front (concat field "/") all)))
(setq all (corfu--move-to-front field all))
@@ -605,7 +608,7 @@ A scroll bar is displayed from LO to LO+BAR."
;; expensive candidate recomputation is performed (Issue #48). See also
;; corresponding vertico#89.
(redisplay)
- (pcase (while-no-input (corfu--recompute-candidates str pt table pred))
+ (pcase (while-no-input (corfu--recompute-candidates str pt table pred nil))
('nil (keyboard-quit))
(`(,base ,candidates ,total ,hl ,metadata ,preselect)
(setq corfu--input (cons str pt)
@@ -1072,7 +1075,7 @@ See `completion-in-region' for the arguments BEG, END, TABLE, PRED."
t)
(`(,newstr . ,newpt)
(pcase-let ((`(,base ,candidates ,total . ,_)
- (corfu--recompute-candidates str pt table pred)))
+ (corfu--recompute-candidates str pt table pred 'cycle)))
(setq beg (copy-marker beg)
end (copy-marker end t)
completion-in-region--data (list beg end table pred))