[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master df8901f 132/399: swiper.el (swiper-query-replace): Add pre
From: |
Oleh Krehel |
Subject: |
[elpa] master df8901f 132/399: swiper.el (swiper-query-replace): Add preview overlays |
Date: |
Sat, 20 Jul 2019 14:57:09 -0400 (EDT) |
branch: master
commit df8901f0b2dd2076f92a8baa6629edbd35b6c5d6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper-query-replace): Add preview overlays
Fixes #1948
---
swiper.el | 58 +++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 41 insertions(+), 17 deletions(-)
diff --git a/swiper.el b/swiper.el
index 20fcf54..37193b5 100644
--- a/swiper.el
+++ b/swiper.el
@@ -93,28 +93,52 @@
map)
"Keymap for swiper.")
+(defvar swiper--query-replace-overlays nil)
+
+(defun swiper--query-replace-updatefn ()
+ (dolist (ov swiper--query-replace-overlays)
+ (overlay-put ov 'after-string (propertize ivy-text 'face 'error))))
+
+(defun swiper--query-replace-cleanup ()
+ (while swiper--query-replace-overlays
+ (delete-overlay (pop swiper--query-replace-overlays))))
+
+(defun swiper--query-replace-setup ()
+ (with-ivy-window
+ (let ((end (window-end (selected-window) t)))
+ (save-excursion
+ (goto-char (window-start))
+ (while (re-search-forward ivy--old-re end t)
+ (push (make-overlay (1- (match-end 0)) (match-end 0))
+ swiper--query-replace-overlays))))))
+
(defun swiper-query-replace ()
"Start `query-replace' with string to replace from last search string."
(interactive)
(if (null (window-minibuffer-p))
(user-error "Should only be called in the minibuffer through
`swiper-map'")
- (let* ((enable-recursive-minibuffers t)
- (from (ivy--regex ivy-text))
- (to (minibuffer-with-setup-hook
- (lambda ()
- (setq minibuffer-default
- (if (string-match "\\`\\\\_<\\(.*\\)\\\\_>\\'"
ivy-text)
- (match-string 1 ivy-text)
- ivy-text)))
- (read-from-minibuffer (format "Query replace %s with: "
from)))))
- (swiper--cleanup)
- (ivy-exit-with-action
- (lambda (_)
- (with-ivy-window
- (move-beginning-of-line 1)
- (let ((inhibit-read-only t))
- (perform-replace from to
- t t nil))))))))
+ (swiper--query-replace-setup)
+ (unwind-protect
+ (let* ((enable-recursive-minibuffers t)
+ (from (ivy--regex ivy-text))
+ (to (minibuffer-with-setup-hook
+ (lambda ()
+ (setq minibuffer-default
+ (if (string-match "\\`\\\\_<\\(.*\\)\\\\_>\\'"
ivy-text)
+ (match-string 1 ivy-text)
+ ivy-text)))
+ (ivy-read
+ (format "Query replace %s with: " from) nil
+ :update-fn #'swiper--query-replace-updatefn))))
+ (swiper--cleanup)
+ (ivy-exit-with-action
+ (lambda (_)
+ (with-ivy-window
+ (move-beginning-of-line 1)
+ (let ((inhibit-read-only t))
+ (perform-replace from to
+ t t nil))))))
+ (swiper--query-replace-cleanup))))
(defvar inhibit-message)
- [elpa] master 5e54abd 123/399: Fix counsel-org-tag-agenda, (continued)
- [elpa] master 5e54abd 123/399: Fix counsel-org-tag-agenda, Oleh Krehel, 2019/07/20
- [elpa] master 1998783 125/399: counsel.el (counsel-find-file-ignore-regexp): Add nested hidden dotfiles, Oleh Krehel, 2019/07/20
- [elpa] master bb5d0d4 119/399: ivy-overlay.el (ivy-display-function-overlay): Refactor, Oleh Krehel, 2019/07/20
- [elpa] master f9b64c3 126/399: swiper.el (swiper-isearch): Add, Oleh Krehel, 2019/07/20
- [elpa] master 1606918 129/399: ivy.el (ivy-read): Allow :update-fn to be 'auto, Oleh Krehel, 2019/07/20
- [elpa] master f4431d4 133/399: doc/ivy.org (automatically integrated packages): Add, Oleh Krehel, 2019/07/20
- [elpa] master 0465711 124/399: counsel.el (counsel-org-tag-agenda): Check org-version, Oleh Krehel, 2019/07/20
- [elpa] master 3416142 128/399: counsel.el (counsel--async-sentinel): Fix index jumping randomly, Oleh Krehel, 2019/07/20
- [elpa] master 31a554d 130/399: swiper.el (swiper-isearch): Anchor to line-beginning-position, Oleh Krehel, 2019/07/20
- [elpa] master adad2e4 127/399: counsel.el: Strip space from initial input of counsel-package, Oleh Krehel, 2019/07/20
- [elpa] master df8901f 132/399: swiper.el (swiper-query-replace): Add preview overlays,
Oleh Krehel <=
- [elpa] master dc3f469 131/399: swiper.el (swiper-isearch): Extend, Oleh Krehel, 2019/07/20
- [elpa] master bc479ed 134/399: swiper.el (swiper-isearch): Fix minibuffer height, Oleh Krehel, 2019/07/20
- [elpa] master fa2e02d 137/399: ivy-overlay.el (ivy-cursor): Customize for dark background, Oleh Krehel, 2019/07/20
- [elpa] master 8edde1c 135/399: swiper.el (swiper-isearch): Change prompt, Oleh Krehel, 2019/07/20
- [elpa] master 66961f8 138/399: swiper.el (swiper-isearch-action): Add a cursor overlay, Oleh Krehel, 2019/07/20
- [elpa] master ce31009 144/399: swiper.el (swiper-isearch-function): Use text with faces, Oleh Krehel, 2019/07/20
- [elpa] master 8229304 141/399: ivy.el: Add display transformer for counsel-dired, Oleh Krehel, 2019/07/20
- [elpa] master fef96f4 139/399: counsel.el (counsel--find-file-1): Extract, Oleh Krehel, 2019/07/20
- [elpa] master 3b40e99 142/399: swiper.el (swiper-isearch-action): Fix fake cursor at eol, Oleh Krehel, 2019/07/20
- [elpa] master eaba38a 145/399: counsel.el (counsel-dired-jump-args): Fix for OSX, Oleh Krehel, 2019/07/20