From 8dc02d5b725f78d1f80904807b46f5406f129674 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Thu, 29 Aug 2024 19:17:32 +0200 Subject: [PATCH] Fix Emacs 30 'sort' and 'value<' feature detection * 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. --- ivy.el | 13 ++++++++++--- swiper.el | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ivy.el b/ivy.el index 5056d4e4..15bf9bbe 100644 --- a/ivy.el +++ b/ivy.el @@ -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)))) @@ -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))) @@ -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))) diff --git a/swiper.el b/swiper.el index ca2975ba..b4507890 100644 --- a/swiper.el +++ b/swiper.el @@ -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)