aboutsummaryrefslogtreecommitdiff
path: root/evil-commands.el
diff options
context:
space:
mode:
authorJustin Burkett <justin@burkett.cc>2017-12-28 23:26:01 -0500
committerJustin Burkett <justin@burkett.cc>2018-01-03 22:18:42 -0500
commit9bebd449912f009923bb7128a58680e55e6ec52d (patch)
tree4be6a8a7fd6fd38c125d93234b6e0cbf28efea0e /evil-commands.el
parent0100e61d74d7d6249ace901f6ecca90cb0fcfd51 (diff)
Reveal hidden search terms in evil-ex-substitute
Do this by simulating the effect of turning on reveal-mode when the substitution requires confirmation. Fixes #983
Diffstat (limited to 'evil-commands.el')
-rw-r--r--evil-commands.el35
1 files changed, 34 insertions, 1 deletions
diff --git a/evil-commands.el b/evil-commands.el
index ea353eb..d676cb2 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -3346,6 +3346,29 @@ resp. after executing the command."
evil-symbol-word-search))
(evil-ex-start-word-search t 'backward count symbol))
+(defun evil-revert-reveal (open-spots)
+ "Unconditionally close overlays in OPEN-SPOTS in current window.
+Modified version of `reveal-close-old-overlays' from
+reveal.el. OPEN-SPOTS is a local version of `reveal-open-spots'."
+ (dolist (spot open-spots)
+ (let ((window (car spot))
+ (ol (cdr spot)))
+ (unless (eq window (selected-window))
+ (error "evil-revert-reveal: slot with wrong window"))
+ (let* ((inv (overlay-get ol 'reveal-invisible))
+ (open (or (overlay-get ol 'reveal-toggle-invisible)
+ (get inv 'reveal-toggle-invisible)
+ (overlay-get ol 'isearch-open-invisible-temporary))))
+ (if (and (overlay-start ol) ;Check it's still live.
+ open)
+ (condition-case err
+ (funcall open ol t)
+ (error (message "!!Reveal-hide (funcall %s %s t): %s !!"
+ open ol err)))
+ (overlay-put ol 'invisible inv))
+ ;; Remove the overlay from the list of open spots.
+ (overlay-put ol 'reveal-invisible nil)))))
+
(evil-define-operator evil-ex-substitute
(beg end pattern replacement flags)
"The Ex substitute command.
@@ -3373,6 +3396,8 @@ resp. after executing the command."
(evil-ex-substitute-hl (evil-ex-make-hl 'evil-ex-substitute))
(orig-point-marker (move-marker (make-marker) (point)))
(end-marker (move-marker (make-marker) end))
+ (use-reveal (and confirm (require 'reveal nil t)))
+ reveal-open-spots
zero-length-match
match-contains-newline
transient-mark-mode)
@@ -3415,8 +3440,13 @@ resp. after executing the command."
(evil-match-substitute-replacement
evil-ex-substitute-replacement
(not case-replace))))
+ (search-invisible t)
response)
(move-overlay evil-ex-substitute-overlay match-beg match-end)
+ ;; Simulate `reveal-mode'. `reveal-mode' uses
+ ;; `post-command-hook' but that won't work here.
+ (when use-reveal
+ (reveal-post-command))
(catch 'exit-read-char
(while (setq response (read-char prompt))
(when (member response '(?y ?a ?l))
@@ -3481,7 +3511,10 @@ resp. after executing the command."
(goto-char evil-ex-substitute-last-point))
(move-marker orig-point-marker nil)
- (move-marker end-marker nil))
+ (move-marker end-marker nil)
+
+ (when use-reveal
+ (evil-revert-reveal reveal-open-spots)))
(message "%s %d occurrence%s"
(if count-only "Found" "Replaced")