[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d060eea 313/399: swiper.el (swiper-query-replace): Add que
From: |
Oleh Krehel |
Subject: |
[elpa] master d060eea 313/399: swiper.el (swiper-query-replace): Add query-replace-compile-replacement |
Date: |
Sat, 20 Jul 2019 14:57:47 -0400 (EDT) |
branch: master
commit d060eea466de6478291b4adf4f23db1da10e0473
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper-query-replace): Add query-replace-compile-replacement
Fixes #2096
---
swiper.el | 47 ++++++++++++++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 13 deletions(-)
diff --git a/swiper.el b/swiper.el
index 9990664..620416c 100644
--- a/swiper.el
+++ b/swiper.el
@@ -137,8 +137,19 @@
(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))))
+ (let ((lisp (ignore-errors (nth 2 (query-replace-compile-replacement
ivy-text t)))))
+ (dolist (ov swiper--query-replace-overlays)
+ (when lisp
+ (dolist (x (overlay-get ov 'matches))
+ (setq lisp (cl-subst (cadr x) (car x) lisp :test #'equal)))
+ (setq lisp (ignore-errors (eval lisp))))
+ (overlay-put
+ ov 'after-string
+ (propertize
+ (if (stringp lisp)
+ lisp
+ ivy-text)
+ 'face 'error)))))
(defun swiper--query-replace-cleanup ()
(while swiper--query-replace-overlays
@@ -151,8 +162,15 @@
(save-excursion
(goto-char (window-start))
(while (re-search-forward re end t)
- (push (make-overlay (1- (match-end 0)) (match-end 0))
- swiper--query-replace-overlays))))))
+ (let ((ov (make-overlay (1- (match-end 0)) (match-end 0)))
+ (md (match-data)))
+ (overlay-put
+ ov 'matches
+ (mapcar
+ (lambda (x)
+ (list `(match-string ,x) (match-string x)))
+ (number-sequence 0 (1- (/ (length md) 2)))))
+ (push ov swiper--query-replace-overlays)))))))
(defun swiper-query-replace ()
"Start `query-replace' with string to replace from last search string."
@@ -166,15 +184,18 @@
(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))))
+ (to
+ (query-replace-compile-replacement
+ (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))
+ t)))
(swiper--cleanup)
(ivy-exit-with-action
(lambda (_)
- [elpa] master 034f3af 306/399: swiper.el (swiper-isearch): Allow char-fold-to-regexp, (continued)
- [elpa] master 034f3af 306/399: swiper.el (swiper-isearch): Allow char-fold-to-regexp, Oleh Krehel, 2019/07/20
- [elpa] master 5cc1e5c 298/399: swiper.el (swiper-isearch-thing-at-point): Improve, Oleh Krehel, 2019/07/20
- [elpa] master 3b6c898 303/399: counsel.el (counsel-mark-ring): Add preview by candidate, Oleh Krehel, 2019/07/20
- [elpa] master 93616f7 296/399: ivy.el (ivy--regex): Match initial dot in the input as a literal dot, Oleh Krehel, 2019/07/20
- [elpa] master ac1e07c 305/399: ivy.el (ivy--reset-state): Modify prompt for multi-isearch-buffers, Oleh Krehel, 2019/07/20
- [elpa] master 4078eb9 308/399: counsel.el (counsel-yank-pop-height): Remove, Oleh Krehel, 2019/07/20
- [elpa] master 895906e 309/399: counsel.el (counsel-descbinds-function): Add, Oleh Krehel, 2019/07/20
- [elpa] master 4a37e1e 314/399: swiper.el (swiper-query-replace): Make eval-style replacement more accessible, Oleh Krehel, 2019/07/20
- [elpa] master dd2d495 312/399: swiper.el (swiper-all-thing-at-point): Add, Oleh Krehel, 2019/07/20
- [elpa] master 0576b61 315/399: .github/FUNDING.yml: Add, Oleh Krehel, 2019/07/20
- [elpa] master d060eea 313/399: swiper.el (swiper-query-replace): Add query-replace-compile-replacement,
Oleh Krehel <=
- [elpa] master 09b9508 321/399: ivy.el (ivy--find-file-action): Fix for virtual buffers, Oleh Krehel, 2019/07/20
- [elpa] master 7d46450 311/399: Add more information about the collection argument in `ivy-read`., Oleh Krehel, 2019/07/20
- [elpa] master 676a8ee 318/399: swiper.el (swiper-isearch-current-match): Remove unused face, Oleh Krehel, 2019/07/20
- [elpa] master ba626e7 317/399: ivy.el (ivy-next-history-element): Use minibuffer-default for dired-dwim-target, Oleh Krehel, 2019/07/20
- [elpa] master 51e765e 316/399: ivy.el (ivy-partial): Return nil when comletion was not updated, Oleh Krehel, 2019/07/20
- [elpa] master 16d2268 320/399: Fix ivy-push/switch-view windows layout, Oleh Krehel, 2019/07/20
- [elpa] master d260c48 322/399: swiper.el: Obey search-invisible, Oleh Krehel, 2019/07/20
- [elpa] master de8842e 323/399: Add ivy-switch-buffer-map to counsel-switch-buffer, Oleh Krehel, 2019/07/20
- [elpa] master 0d87297 326/399: counsel.el (counsel-open-buffer-file-externally): Cleanup, Oleh Krehel, 2019/07/20
- [elpa] master 7defba2 327/399: ivy.el (ivy-avy): Fix when there's a scroll, Oleh Krehel, 2019/07/20