Skip to content

Commit

Permalink
Various sequence fixes in Swiper
Browse files Browse the repository at this point in the history
* swiper.el (swiper--avy-candidates, swiper-all-function): Prefer
cl-delete over cl-remove on fresh sequences.
(swiper--re-builder, swiper--update-input-ivy): Use substring rather
than regexp operations.
(swiper--positive-regexps): Remove; replace all uses with
ivy--positive-regexps.
  • Loading branch information
basil-conto committed May 20, 2024
1 parent 6a98b00 commit c8808d8
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions swiper.el
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ If the input is empty, select the previous history element instead."
(cl-sort visible-overlays #'< :key #'overlay-start)))
(min-overlay-start 0)
(overlays-for-avy
(cl-remove-if-not
(cl-delete-if-not
(lambda (ov)
(when (and (>= (overlay-start ov)
min-overlay-start)
Expand Down Expand Up @@ -781,7 +781,7 @@ Add a space after a leading `^' for `swiper', and apply
This is the regex used in the minibuffer where candidates have
line numbers. For the buffer, use `ivy--regex' instead."
(let* ((re-builder (ivy-alist-setting ivy-re-builders-alist))
(str (replace-regexp-in-string "\\\\n" "\n" str))
(str (ivy--string-replace "\\n" "\n" str))
(re (funcall re-builder str)))
(if (consp re)
(mapcar
Expand Down Expand Up @@ -948,24 +948,17 @@ the face, window and priority of the overlay."
(or (display-graphic-p)
(not recenter-redisplay)))

(defun swiper--positive-regexps ()
(if (listp ivy-regex)
(mapcar #'car (cl-remove-if-not #'cdr ivy-regex))
(list ivy-regex)))

(defun swiper--update-input-ivy ()
"Called when `ivy' input is updated."
(with-ivy-window
(swiper--cleanup)
(when (> (length (ivy-state-current ivy-last)) 0)
(let ((regexps (swiper--positive-regexps))
(let ((regexps (ivy--positive-regexps))
(re-idx -1)
(case-fold-search (ivy--case-fold-p ivy-text)))
(dolist (re regexps)
(setq re-idx (1+ re-idx))
(let* ((re (replace-regexp-in-string
" " "\t"
re))
(let* ((re (ivy--string-replace " " "\t" re))
(num (swiper--line-number (ivy-state-current ivy-last))))
(unless (memq this-command '(ivy-yank-word
ivy-yank-symbol
Expand Down Expand Up @@ -1272,7 +1265,7 @@ otherwise continue prompting for buffers."
"Search in all open buffers for STR."
(or
(ivy-more-chars)
(let* ((buffers (cl-remove-if-not #'swiper-all-buffer-p (buffer-list)))
(let* ((buffers (cl-delete-if-not #'swiper-all-buffer-p (buffer-list)))
(re-full ivy-regex)
re re-tail
cands match
Expand Down Expand Up @@ -1494,7 +1487,7 @@ that we search only for one character."
(lambda ()
(with-ivy-window
(swiper--add-overlays (ivy--regex ivy-text))))))
(dolist (re (swiper--positive-regexps))
(dolist (re (ivy--positive-regexps))
(swiper--add-overlays re))))

(defun swiper--isearch-candidate-pos (cand)
Expand Down

0 comments on commit c8808d8

Please sign in to comment.