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