Skip to content

Commit

Permalink
Fix Emacs 30 'sort' and 'value<' feature detection
Browse files Browse the repository at this point in the history
* ivy.el (ivy--new-sort-p): New constant.
(ivy--shorter-matches-first, ivy--flx-sort):
* swiper.el (swiper--avy-candidates): Check ivy--new-sort-p instead
of value<, which could be polyfilled by the compat package.

Fixes #3052.
  • Loading branch information
basil-conto committed Aug 29, 2024
1 parent 8cb1e9b commit 8dc02d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -3699,11 +3699,18 @@ CANDIDATES are assumed to be static."
(delete-dups res)
res))))

(eval-and-compile
(defconst ivy--new-sort-p
(condition-case nil
(with-no-warnings (sort []))
(wrong-number-of-arguments))
"Whether Emacs 30 `sort' calling convention is available."))

(defun ivy--shorter-matches-first (_name cands)
"Sort CANDS according to their length."
(if (nthcdr ivy-sort-max-size cands)
cands
(static-if (fboundp 'value<)
(static-if (bound-and-true-p ivy--new-sort-p)
(sort cands :key #'length)
(cl-sort (copy-sequence cands) #'< :key #'length))))

Expand Down Expand Up @@ -4001,7 +4008,7 @@ N wraps around, but skips the first element of the list."
(push cand cands-left)))

;; pre-sort the candidates by length before partitioning
(setq cands-left (static-if (fboundp 'value<)
(setq cands-left (static-if (bound-and-true-p ivy--new-sort-p)
(sort cands-left :key #'length :in-place t)
(cl-sort cands-left #'< :key #'length)))

Expand All @@ -4010,7 +4017,7 @@ N wraps around, but skips the first element of the list."
(push (pop cands-left) cands-to-sort))

(nconc
(static-if (fboundp 'value<)
(static-if (bound-and-true-p ivy--new-sort-p)
(sort cands-to-sort :in-place t
:key (lambda (cand)
(let ((s (flx-score cand flx-name ivy--flx-cache)))
Expand Down
2 changes: 1 addition & 1 deletion swiper.el
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ If the input is empty, select the previous history element instead."
;; throw out non-Swiper overlays or overlapping Swiper
;; overlays.
(visible-overlays
(static-if (fboundp 'value<)
(static-if (bound-and-true-p ivy--new-sort-p)
(sort visible-overlays :key #'overlay-start :in-place t)
(cl-sort visible-overlays #'< :key #'overlay-start)))
(min-overlay-start 0)
Expand Down

0 comments on commit 8dc02d5

Please sign in to comment.