]> code.delx.au - gnu-emacs-elpa/blob - swiper.el
swiper.el (swiper--re-builder): Replace \t with 4 spaces
[gnu-emacs-elpa] / swiper.el
1 ;;; swiper.el --- Isearch with an overview. Oh, man! -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Author: Oleh Krehel <ohwoeowho@gmail.com>
6 ;; URL: https://github.com/abo-abo/swiper
7 ;; Version: 0.7.0
8 ;; Package-Requires: ((emacs "24.1"))
9 ;; Keywords: matching
10
11 ;; This file is part of GNU Emacs.
12
13 ;; This file is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; any later version.
17
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; For a full copy of the GNU General Public License
24 ;; see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27 ;;
28 ;; This package gives an overview of the current regex search
29 ;; candidates. The search regex can be split into groups with a
30 ;; space. Each group is highlighted with a different face.
31 ;;
32 ;; It can double as a quick `regex-builder', although only single
33 ;; lines will be matched.
34 ;;
35 ;; It also provides `ivy-mode': a global minor mode that uses the
36 ;; matching back end of `swiper' for all matching on your system,
37 ;; including file matching. You can use it in place of `ido-mode'
38 ;; (can't have both on at once).
39
40 ;;; Code:
41 (require 'ivy)
42
43 (defgroup swiper nil
44 "`isearch' with an overview."
45 :group 'matching
46 :prefix "swiper-")
47
48 (defface swiper-match-face-1
49 '((t (:inherit isearch-lazy-highlight-face)))
50 "The background face for `swiper' matches.")
51
52 (defface swiper-match-face-2
53 '((t (:inherit isearch)))
54 "Face for `swiper' matches modulo 1.")
55
56 (defface swiper-match-face-3
57 '((t (:inherit match)))
58 "Face for `swiper' matches modulo 2.")
59
60 (defface swiper-match-face-4
61 '((t (:inherit isearch-fail)))
62 "Face for `swiper' matches modulo 3.")
63
64 (define-obsolete-face-alias 'swiper-minibuffer-match-face-1
65 'ivy-minibuffer-match-face-1 "0.6.0")
66
67 (define-obsolete-face-alias 'swiper-minibuffer-match-face-2
68 'ivy-minibuffer-match-face-2 "0.6.0")
69
70 (define-obsolete-face-alias 'swiper-minibuffer-match-face-3
71 'ivy-minibuffer-match-face-3 "0.6.0")
72
73 (define-obsolete-face-alias 'swiper-minibuffer-match-face-4
74 'ivy-minibuffer-match-face-4 "0.6.0")
75
76 (defface swiper-line-face
77 '((t (:inherit highlight)))
78 "Face for current `swiper' line.")
79
80 (defcustom swiper-faces '(swiper-match-face-1
81 swiper-match-face-2
82 swiper-match-face-3
83 swiper-match-face-4)
84 "List of `swiper' faces for group matches.")
85
86 (defcustom swiper-min-highlight 2
87 "Only highlight matches for regexps at least this long."
88 :type 'integer)
89
90 (defvar swiper-map
91 (let ((map (make-sparse-keymap)))
92 (define-key map (kbd "M-q") 'swiper-query-replace)
93 (define-key map (kbd "C-l") 'swiper-recenter-top-bottom)
94 (define-key map (kbd "C-'") 'swiper-avy)
95 (define-key map (kbd "C-7") 'swiper-mc)
96 (define-key map (kbd "C-c C-f") 'swiper-toggle-face-matching)
97 map)
98 "Keymap for swiper.")
99
100 (defun swiper-query-replace ()
101 "Start `query-replace' with string to replace from last search string."
102 (interactive)
103 (if (null (window-minibuffer-p))
104 (user-error "Should only be called in the minibuffer through `swiper-map'")
105 (let* ((enable-recursive-minibuffers t)
106 (from (ivy--regex ivy-text))
107 (to (query-replace-read-to from "Query replace" t)))
108 (swiper--cleanup)
109 (ivy-exit-with-action
110 (lambda (_)
111 (with-ivy-window
112 (move-beginning-of-line 1)
113 (perform-replace from to
114 t t nil)))))))
115
116 (defvar avy-background)
117 (defvar avy-all-windows)
118 (defvar avy-style)
119 (defvar avy-keys)
120 (declare-function avy--regex-candidates "ext:avy")
121 (declare-function avy--process "ext:avy")
122 (declare-function avy--overlay-post "ext:avy")
123 (declare-function avy-action-goto "ext:avy")
124 (declare-function avy--done "ext:avy")
125 (declare-function avy--make-backgrounds "ext:avy")
126 (declare-function avy-window-list "ext:avy")
127 (declare-function avy-read "ext:avy")
128 (declare-function avy-read-de-bruijn "ext:avy")
129 (declare-function avy-tree "ext:avy")
130 (declare-function avy-push-mark "ext:avy")
131 (declare-function avy--remove-leading-chars "ext:avy")
132
133 ;;;###autoload
134 (defun swiper-avy ()
135 "Jump to one of the current swiper candidates."
136 (interactive)
137 (unless (string= ivy-text "")
138 (let* ((avy-all-windows nil)
139 (candidates (append
140 (with-ivy-window
141 (avy--regex-candidates
142 (ivy--regex ivy-text)))
143 (save-excursion
144 (save-restriction
145 (narrow-to-region (window-start) (window-end))
146 (goto-char (point-min))
147 (forward-line)
148 (let ((cands))
149 (while (< (point) (point-max))
150 (push (cons (1+ (point))
151 (selected-window))
152 cands)
153 (forward-line))
154 cands)))))
155 (candidate (unwind-protect
156 (prog2
157 (avy--make-backgrounds
158 (append (avy-window-list)
159 (list (ivy-state-window ivy-last))))
160 (if (eq avy-style 'de-bruijn)
161 (avy-read-de-bruijn
162 candidates avy-keys)
163 (avy-read (avy-tree candidates avy-keys)
164 #'avy--overlay-post
165 #'avy--remove-leading-chars))
166 (avy-push-mark))
167 (avy--done))))
168 (if (window-minibuffer-p (cdr candidate))
169 (progn
170 (ivy-set-index (- (line-number-at-pos (car candidate)) 2))
171 (ivy--exhibit)
172 (ivy-done)
173 (ivy-call))
174 (ivy-quit-and-run
175 (avy-action-goto (caar candidate)))))))
176
177 (declare-function mc/create-fake-cursor-at-point "ext:multiple-cursors-core")
178 (declare-function multiple-cursors-mode "ext:multiple-cursors-core")
179
180 ;;;###autoload
181 (defun swiper-mc ()
182 (interactive)
183 (unless (require 'multiple-cursors nil t)
184 (error "multiple-cursors isn't installed"))
185 (let ((cands (nreverse ivy--old-cands)))
186 (unless (string= ivy-text "")
187 (ivy-exit-with-action
188 (lambda (_)
189 (let (cand)
190 (while (setq cand (pop cands))
191 (swiper--action cand)
192 (when cands
193 (mc/create-fake-cursor-at-point))))
194 (multiple-cursors-mode 1))))))
195
196 (defun swiper-recenter-top-bottom (&optional arg)
197 "Call (`recenter-top-bottom' ARG)."
198 (interactive "P")
199 (with-ivy-window
200 (recenter-top-bottom arg)))
201
202 (defvar swiper-font-lock-exclude
203 '(package-menu-mode
204 gnus-summary-mode
205 gnus-article-mode
206 gnus-group-mode
207 emms-playlist-mode
208 emms-stream-mode
209 erc-mode
210 org-agenda-mode
211 dired-mode
212 jabber-chat-mode
213 elfeed-search-mode
214 elfeed-show-mode
215 fundamental-mode
216 Man-mode
217 woman-mode
218 mu4e-view-mode
219 mu4e-headers-mode
220 help-mode
221 debbugs-gnu-mode
222 occur-mode
223 occur-edit-mode
224 bongo-mode
225 bongo-library-mode
226 bongo-playlist-mode
227 eww-mode
228 twittering-mode
229 vc-dir-mode
230 rcirc-mode
231 sauron-mode
232 w3m-mode)
233 "List of major-modes that are incompatible with font-lock-ensure.")
234
235 (defun swiper-font-lock-ensure-p ()
236 "Return non-nil if we should font-lock-ensure."
237 (or (derived-mode-p 'magit-mode)
238 (bound-and-true-p magit-blame-mode)
239 (memq major-mode swiper-font-lock-exclude)))
240
241 (defun swiper-font-lock-ensure ()
242 "Ensure the entired buffer is highlighted."
243 (unless (swiper-font-lock-ensure-p)
244 (unless (> (buffer-size) 100000)
245 (if (fboundp 'font-lock-ensure)
246 (font-lock-ensure)
247 (with-no-warnings (font-lock-fontify-buffer))))))
248
249 (defvar swiper--format-spec ""
250 "Store the current candidates format spec.")
251
252 (defvar swiper--width nil
253 "Store the amount of digits needed for the longest line nubmer.")
254
255 (defvar swiper-use-visual-line nil
256 "When non-nil, use `line-move' instead of `forward-line'.")
257
258 (declare-function outline-show-all "outline")
259
260 (defun swiper--candidates (&optional numbers-width)
261 "Return a list of this buffer lines.
262
263 NUMBERS-WIDTH, when specified, is used for line numbers width
264 spec, instead of calculating it as the log of the buffer line
265 count."
266 (if (and visual-line-mode
267 ;; super-slow otherwise
268 (< (buffer-size) 20000))
269 (progn
270 (when (eq major-mode 'org-mode)
271 (require 'outline)
272 (if (fboundp 'outline-show-all)
273 (outline-show-all)
274 (with-no-warnings
275 (show-all))))
276 (setq swiper-use-visual-line t))
277 (setq swiper-use-visual-line nil))
278 (let ((n-lines (count-lines (point-min) (point-max))))
279 (unless (zerop n-lines)
280 (setq swiper--width (or numbers-width
281 (1+ (floor (log n-lines 10)))))
282 (setq swiper--format-spec
283 (format "%%-%dd " swiper--width))
284 (let ((line-number 0)
285 (advancer (if swiper-use-visual-line
286 (lambda (arg) (line-move arg t))
287 #'forward-line))
288 candidates)
289 (save-excursion
290 (goto-char (point-min))
291 (swiper-font-lock-ensure)
292 (while (< (point) (point-max))
293 (let ((str (concat
294 " "
295 (replace-regexp-in-string
296 "\t" " "
297 (if swiper-use-visual-line
298 (buffer-substring
299 (save-excursion
300 (beginning-of-visual-line)
301 (point))
302 (save-excursion
303 (end-of-visual-line)
304 (point)))
305 (buffer-substring
306 (point)
307 (line-end-position)))))))
308 (when (eq major-mode 'twittering-mode)
309 (remove-text-properties 0 (length str) '(field) str))
310 (put-text-property 0 1 'display
311 (format swiper--format-spec
312 (cl-incf line-number))
313 str)
314 (push str candidates))
315 (funcall advancer 1))
316 (nreverse candidates))))))
317
318 (defvar swiper--opoint 1
319 "The point when `swiper' starts.")
320
321 ;;;###autoload
322 (defun swiper (&optional initial-input)
323 "`isearch' with an overview.
324 When non-nil, INITIAL-INPUT is the initial search pattern."
325 (interactive)
326 (swiper--ivy initial-input))
327
328 (defun swiper-occur ()
329 "Generate a custom occur buffer for `swiper'."
330 (ivy-occur-grep-mode)
331 (font-lock-mode -1)
332 (let* ((fname (propertize
333 (with-ivy-window
334 (file-name-nondirectory
335 (buffer-file-name)))
336 'face
337 'compilation-info))
338 (cands (mapcar
339 (lambda (s)
340 (format "%s:%s:%s"
341 fname
342 (propertize
343 (string-trim-right
344 (get-text-property 0 'display s))
345 'face 'compilation-line-number)
346 (substring s 1)))
347 ivy--old-cands)))
348 (insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
349 default-directory))
350 (insert (format "%d candidates:\n" (length cands)))
351 (ivy--occur-insert-lines
352 (mapcar
353 (lambda (cand) (concat "./" cand))
354 cands))))
355
356 (ivy-set-occur 'swiper 'swiper-occur)
357
358 (declare-function evil-jumper--set-jump "ext:evil-jumper")
359
360 (defvar swiper--current-line nil)
361 (defvar swiper--current-match-start nil)
362
363 (defun swiper--init ()
364 "Perform initialization common to both completion methods."
365 (setq swiper--current-line nil)
366 (setq swiper--current-match-start nil)
367 (setq swiper--opoint (point))
368 (when (bound-and-true-p evil-jumper-mode)
369 (evil-jumper--set-jump)))
370
371 (defun swiper--re-builder (str)
372 "Transform STR into a swiper regex.
373 This is the regex used in the minibuffer, since the candidates
374 there have line numbers. In the buffer, `ivy--regex' should be used."
375 (replace-regexp-in-string
376 "\t" " "
377 (cond
378 ((equal str "")
379 "")
380 ((equal str "^")
381 (setq ivy--subexps 0)
382 ".")
383 ((string-match "^\\^" str)
384 (setq ivy--old-re "")
385 (let ((re (ivy--regex-plus (substring str 1))))
386 (if (zerop ivy--subexps)
387 (prog1 (format "^ ?\\(%s\\)" re)
388 (setq ivy--subexps 1))
389 (format "^ %s" re))))
390 (t
391 (ivy--regex-plus str)))))
392
393 (defvar swiper-history nil
394 "History for `swiper'.")
395
396 (defvar swiper-invocation-face nil
397 "The face at the point of invocation of `swiper'.")
398
399 (defun swiper--ivy (&optional initial-input)
400 "`isearch' with an overview using `ivy'.
401 When non-nil, INITIAL-INPUT is the initial search pattern."
402 (interactive)
403 (swiper--init)
404 (setq swiper-invocation-face
405 (plist-get (text-properties-at (point)) 'face))
406 (let ((candidates (swiper--candidates))
407 (preselect
408 (if swiper-use-visual-line
409 (count-screen-lines
410 (point-min)
411 (save-excursion (beginning-of-visual-line) (point)))
412 (1- (line-number-at-pos))))
413 (minibuffer-allow-text-properties t)
414 res)
415 (unwind-protect
416 (and
417 (setq res
418 (ivy-read
419 "Swiper: "
420 candidates
421 :initial-input initial-input
422 :keymap swiper-map
423 :preselect preselect
424 :require-match t
425 :update-fn #'swiper--update-input-ivy
426 :unwind #'swiper--cleanup
427 :action #'swiper--action
428 :re-builder #'swiper--re-builder
429 :history 'swiper-history
430 :caller 'swiper))
431 (point))
432 (unless res
433 (goto-char swiper--opoint)))))
434
435 (defun swiper-toggle-face-matching ()
436 "Toggle matching only the candidates with `swiper-invocation-face'."
437 (interactive)
438 (setf (ivy-state-matcher ivy-last)
439 (if (ivy-state-matcher ivy-last)
440 nil
441 #'swiper--face-matcher))
442 (setq ivy--old-re nil))
443
444 (defun swiper--face-matcher (regexp candidates)
445 "Return REGEXP-matching CANDIDATES.
446 Matched candidates should have `swiper-invocation-face'."
447 (cl-remove-if-not
448 (lambda (x)
449 (and
450 (string-match regexp x)
451 (let ((s (match-string 0 x))
452 (i 0))
453 (while (and (< i (length s))
454 (text-property-any
455 i (1+ i)
456 'face swiper-invocation-face
457 s))
458 (cl-incf i))
459 (eq i (length s)))))
460 candidates))
461
462 (defun swiper--ensure-visible ()
463 "Remove overlays hiding point."
464 (let ((overlays (overlays-at (point)))
465 ov expose)
466 (while (setq ov (pop overlays))
467 (if (and (invisible-p (overlay-get ov 'invisible))
468 (setq expose (overlay-get ov 'isearch-open-invisible)))
469 (funcall expose ov)))))
470
471 (defvar swiper--overlays nil
472 "Store overlays.")
473
474 (defun swiper--cleanup ()
475 "Clean up the overlays."
476 (while swiper--overlays
477 (delete-overlay (pop swiper--overlays)))
478 (save-excursion
479 (goto-char (point-min))
480 (isearch-clean-overlays)))
481
482 (defun swiper--update-input-ivy ()
483 "Called when `ivy' input is updated."
484 (with-ivy-window
485 (swiper--cleanup)
486 (when (> (length ivy--current) 0)
487 (let* ((re (funcall ivy--regex-function ivy-text))
488 (re (if (stringp re) re (caar re)))
489 (str (get-text-property 0 'display ivy--current))
490 (num (if (string-match "^[0-9]+" str)
491 (string-to-number (match-string 0 str))
492 0)))
493 (unless (eq this-command 'ivy-yank-word)
494 (when (cl-plusp num)
495 (unless (if swiper--current-line
496 (eq swiper--current-line num)
497 (eq (line-number-at-pos) num))
498 (goto-char (point-min))
499 (if swiper-use-visual-line
500 (line-move (1- num))
501 (forward-line (1- num))))
502 (if (and (equal ivy-text "")
503 (>= swiper--opoint (line-beginning-position))
504 (<= swiper--opoint (line-end-position)))
505 (goto-char swiper--opoint)
506 (if (eq swiper--current-line num)
507 (when swiper--current-match-start
508 (goto-char swiper--current-match-start))
509 (setq swiper--current-line num))
510 (when (re-search-forward re (line-end-position) t)
511 (setq swiper--current-match-start (match-beginning 0))))
512 (isearch-range-invisible (line-beginning-position)
513 (line-end-position))
514 (unless (and (>= (point) (window-start))
515 (<= (point) (window-end (ivy-state-window ivy-last) t)))
516 (recenter))))
517 (swiper--add-overlays re)))))
518
519 (defun swiper--add-overlays (re &optional beg end wnd)
520 "Add overlays for RE regexp in visible part of the current buffer.
521 BEG and END, when specified, are the point bounds.
522 WND, when specified is the window."
523 (setq wnd (or wnd (ivy-state-window ivy-last)))
524 (let ((ov (if visual-line-mode
525 (make-overlay
526 (save-excursion
527 (beginning-of-visual-line)
528 (point))
529 (save-excursion
530 (end-of-visual-line)
531 (point)))
532 (make-overlay
533 (line-beginning-position)
534 (1+ (line-end-position))))))
535 (overlay-put ov 'face 'swiper-line-face)
536 (overlay-put ov 'window wnd)
537 (push ov swiper--overlays)
538 (let* ((wh (window-height))
539 (beg (or beg (save-excursion
540 (forward-line (- wh))
541 (point))))
542 (end (or end (save-excursion
543 (forward-line wh)
544 (point)))))
545 (when (>= (length re) swiper-min-highlight)
546 (save-excursion
547 (goto-char beg)
548 ;; RE can become an invalid regexp
549 (while (and (ignore-errors (re-search-forward re end t))
550 (> (- (match-end 0) (match-beginning 0)) 0))
551 (let ((i 0))
552 (while (<= i ivy--subexps)
553 (when (match-beginning i)
554 (let ((overlay (make-overlay (match-beginning i)
555 (match-end i)))
556 (face
557 (cond ((zerop ivy--subexps)
558 (cadr swiper-faces))
559 ((zerop i)
560 (car swiper-faces))
561 (t
562 (nth (1+ (mod (+ i 2) (1- (length swiper-faces))))
563 swiper-faces)))))
564 (push overlay swiper--overlays)
565 (overlay-put overlay 'face face)
566 (overlay-put overlay 'window wnd)
567 (overlay-put overlay 'priority i)))
568 (cl-incf i)))))))))
569
570 (defun swiper--action (x)
571 "Goto line X."
572 (let ((ln (1- (read (if (memq this-command '(ivy-occur-press))
573 (when (string-match ":\\([0-9]+\\):.*\\'" x)
574 (match-string-no-properties 1 x))
575 (get-text-property 0 'display x)))))
576 (re (ivy--regex ivy-text)))
577 (if (null x)
578 (user-error "No candidates")
579 (with-ivy-window
580 (unless (equal (current-buffer)
581 (ivy-state-buffer ivy-last))
582 (switch-to-buffer (ivy-state-buffer ivy-last)))
583 (goto-char (point-min))
584 (funcall (if swiper-use-visual-line
585 #'line-move
586 #'forward-line)
587 ln)
588 (re-search-forward re (line-end-position) t)
589 (swiper--ensure-visible)
590 (when (/= (point) swiper--opoint)
591 (unless (and transient-mark-mode mark-active)
592 (when (eq ivy-exit 'done)
593 (push-mark swiper--opoint t)
594 (message "Mark saved where search started"))))
595 (add-to-history
596 'regexp-search-ring
597 re
598 regexp-search-ring-max)))))
599
600 ;; (define-key isearch-mode-map (kbd "C-o") 'swiper-from-isearch)
601 (defun swiper-from-isearch ()
602 "Invoke `swiper' from isearch."
603 (interactive)
604 (let ((query (if isearch-regexp
605 isearch-string
606 (regexp-quote isearch-string))))
607 (isearch-exit)
608 (swiper query)))
609
610 (defvar swiper-multi-buffers nil
611 "Store the current list of buffers.")
612
613 (defvar swiper-multi-candidates nil
614 "Store the list of candidates for `swiper-multi'.")
615
616 (defun swiper-multi-prompt ()
617 (format "Buffers (%s): "
618 (mapconcat #'identity swiper-multi-buffers ", ")))
619
620 (defun swiper-multi ()
621 "Select one or more buffers.
622 Run `swiper' for those buffers."
623 (interactive)
624 (setq swiper-multi-buffers nil)
625 (ivy-read (swiper-multi-prompt)
626 'internal-complete-buffer
627 :action 'swiper-multi-action-1)
628 (ivy-read "Swiper: " swiper-multi-candidates
629 :action 'swiper-multi-action-2
630 :unwind #'swiper--cleanup
631 :caller 'swiper-multi))
632
633 (defun swiper-all ()
634 "Run `swiper' for all opened buffers."
635 (interactive)
636 (ivy-read "Swiper: " (swiper--multi-candidates
637 (cl-remove-if-not
638 #'buffer-file-name
639 (buffer-list)))
640 :action 'swiper-multi-action-2
641 :unwind #'swiper--cleanup
642 :caller 'swiper-multi))
643
644 (defun swiper--multi-candidates (buffers)
645 (let* ((ww (window-width))
646 (res nil)
647 (column-2 (apply #'max
648 (mapcar
649 (lambda (b)
650 (length (buffer-name b)))
651 buffers)))
652 (column-1 (- ww 4 column-2 1)))
653 (dolist (buf buffers)
654 (with-current-buffer buf
655 (setq res
656 (append
657 (mapcar
658 (lambda (s)
659 (setq s (concat (ivy--truncate-string s column-1) " "))
660 (let ((len (length s)))
661 (put-text-property
662 (1- len) len 'display
663 (concat
664 (make-string
665 (- ww (string-width s) (length (buffer-name)) 3)
666 ?\ )
667 (buffer-name))
668 s)
669 s))
670 (swiper--candidates 4))
671 res))
672 nil))
673 res))
674
675 (defun swiper-multi-action-1 (x)
676 (if (member x swiper-multi-buffers)
677 (progn
678 (setq swiper-multi-buffers (delete x swiper-multi-buffers)))
679 (unless (equal x "")
680 (setq swiper-multi-buffers (append swiper-multi-buffers (list x)))))
681 (let ((prompt (swiper-multi-prompt)))
682 (setf (ivy-state-prompt ivy-last) prompt)
683 (setq ivy--prompt (concat "%-4d " prompt)))
684 (cond ((memq this-command '(ivy-done
685 ivy-alt-done
686 ivy-immediate-done))
687 (setq swiper-multi-candidates
688 (swiper--multi-candidates
689 (mapcar #'get-buffer swiper-multi-buffers))))
690 ((eq this-command 'ivy-call)
691 (delete-minibuffer-contents))))
692
693 (defun swiper-multi-action-2 (x)
694 (let ((buf-space (get-text-property (1- (length x)) 'display x)))
695 (with-ivy-window
696 (when (string-match "\\` *\\([^ ]+\\)\\'" buf-space)
697 (switch-to-buffer (match-string 1 buf-space))
698 (goto-char (point-min))
699 (forward-line (1- (read (get-text-property 0 'display x))))
700 (re-search-forward
701 (ivy--regex ivy-text)
702 (line-end-position) t)
703 (unless (eq ivy-exit 'done)
704 (swiper--cleanup)
705 (swiper--add-overlays (ivy--regex ivy-text)))))))
706
707 (provide 'swiper)
708
709 ;;; swiper.el ends here