branch: master
commit cc56ec08419a4ddffe4424b301c47edd204f3adf
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
swiper.el (swiper-isearch-format-function): Add
Re #2034
---
swiper.el | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/swiper.el b/swiper.el
index 92e7836..358e2c6 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1301,6 +1301,39 @@ When not running `swiper-isearch' already, start it."
map)
"Keymap for `swiper-isearch'.")
+(defun swiper-isearch-format-function (_cands)
+ (let* ((half-height (/ ivy-height 2))
+ (current (ivy-state-current ivy-last))
+ (i (1- ivy--index))
+ (len 0)
+ res s)
+ (while (and (>= i 0)
+ (string= (nth i ivy--old-cands)
+ current))
+ (cl-decf i))
+ (while (and (>= i 0)
+ (< len half-height))
+ (setq s (nth i ivy--old-cands))
+ (unless (equal s (car res))
+ (push (ivy--format-minibuffer-line s) res)
+ (cl-incf len))
+ (cl-decf i))
+ (setq res (nreverse res))
+ (push (ivy--add-face (ivy--format-minibuffer-line current)
'ivy-current-match) res)
+ (cl-incf len)
+ (setq i (1+ ivy--index))
+ (while (and (< i ivy--length)
+ (string= (nth i ivy--old-cands) current))
+ (cl-incf i))
+ (while (and (< i ivy--length)
+ (< len ivy-height))
+ (setq s (nth i ivy--old-cands))
+ (unless (equal s (car res))
+ (push (ivy--format-minibuffer-line s) res)
+ (cl-incf len))
+ (cl-incf i))
+ (mapconcat #'identity (nreverse res) "\n")))
+
;;;###autoload
(defun swiper-isearch (&optional initial-input)
"A `swiper' that's not line-based."
@@ -1312,6 +1345,7 @@ When not running `swiper-isearch' already, start it."
(let ((ivy-fixed-height-minibuffer t)
(cursor-in-non-selected-windows nil)
(swiper-min-highlight 1)
+ (ivy-format-function #'swiper-isearch-format-function)
res)
(unwind-protect
(and