|
From: | Dmitry Gutov |
Subject: | Re: [Patch] Add project.el command to replace symbol at point throughout project |
Date: | Thu, 13 Jan 2022 00:12:11 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 |
On 12.01.2022 21:56, Juri Linkov wrote:
If we're trying to improve project-query-replace-regexp, why not make it use the symbol at point by default?I thought about the option of using symbol at point by default, but I noticed that the command currently uses the history variable. I wondered if some people were relying on its current behavior in a way that I didn’t anticipate (especially since I’m pretty new to all this). If so, it would be an annoying change to have to worry about whether the cursor is on a symbol when using a command you previously relied on. I wanted to try to put forth something possibly useful without breaking stuff.You would use the same command, but would be able to press RET to have the default regexp (symbol at point) used as FROM. I don't have a patch yet, but it might be something that all callers of query-replace-read-args might benefit from.Since I think I can understand what you’re suggesting, I would be happy to make an attempt at a patch to modify the callers of query-replace-read-args to default to a regexp quoted symbol-at-point. But no worries if you would rather have experienced eyes on it.I'm actually not sure about the best way to implement this: whether we definitely want query-replace-read-args to use symbol-at-point as the default FROM. But it does sounds handy to me. Let's ask the developer who touched it last.query-replace-read-args can't be changed because in query-replace RET should use the previous from->to pair from the history.
That probably makes sense. But the user could use 'M-p' for that and otherwise enjoy a different default (FROM defaulting to symbol-at-point).
But it would be a breaking change, admittedly.
So if you want, you could change project-query-replace-regexp: let-bind read-regexp-defaults-function around the call of query-replace-read-args, and use a symbol at point as the default.
...or that. After all, when doing project-wise replacements, you probably wouldn't repeat the same search twice. Or at least, not do it often.
And you can actually do this right now: - Enter command 'project-query-replace-regexp' - Press M-n, having the symbol at point picked up as FROM, hit return - Enter the replacement string and hit returnThis is awesome! Did not know about that behavior, thank you for sharing!That capability actually comes with the "forward history" thing. Not very obvious, but when you learn about it, it's pretty nice.Maybe the prompt should show some indication that the default can be fetched by M-n?
Could be an improvement, but I'm not sure how that'd look, or what text to show ("future history" is not a very obvious name).
[Prev in Thread] | Current Thread | [Next in Thread] |