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