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