branch: externals/ivy-hydra
commit 95d557babbb4996b50ee8ea59609463ccc1f4553
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
swiper.el (swiper-query-replace): Add a more straightforward default
Example buffer contents with symlinks:
.Xmodmap -> git/home/.Xmodmap
.gitignore -> git/home/.gitignore
.gitconfig -> git/home/.gitconfig
We search for "[^\n ]+\( -> \).*". This regex has 3 groups: the link,
->, and where it points to.
Note that we're using a relatively new `ivy--regex' feature, where an
explicit group "\( -> \)" acts as a splitter between the other two
implicit groups.
(ivy--regex "[^\n ]+\\( -> \\).*")
;; => "\\([^\n ]+\\)\\( -> \\).*?\\(.*\\)"
Since there are 3 groups, a reasonable default for replacement is "\1
\2 \3". In the end, we likely want to use "\3 \1"; the default serves
to remind us of the sytax.
The second default is: \,(concat \1 " " \2 " " \3).
It's a little more cumbersome, but it's Lisp! So we could use something
like:
\,(concat \1 " " \2 " " (expand-file-name \3))
Which I think may be powerful in some situations.
---
swiper.el | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/swiper.el b/swiper.el
index 1635585..426dce9 100644
--- a/swiper.el
+++ b/swiper.el
@@ -197,13 +197,17 @@ Treated as non-nil when searching backwards."
(unwind-protect
(let* ((enable-recursive-minibuffers t)
(from ivy--old-re)
+ (groups (number-sequence 1 ivy--subexps))
(default
- (format "\\,(concat %s)"
- (if (<= ivy--subexps 1)
- "\\&"
- (mapconcat (lambda (i) (format "\\%d" i))
- (number-sequence 1 ivy--subexps)
- " \" \" "))))
+ (list
+ (mapconcat (lambda (i) (format "\\%d" i)) groups " ")
+ (format "\\,(concat %s)"
+ (if (<= ivy--subexps 1)
+ "\\&"
+ (mapconcat
+ (lambda (i) (format "\\%d" i))
+ groups
+ " \" \" ")))))
(to
(query-replace-compile-replacement
(ivy-read