benma / visual-regexp.el

A regexp/replace command for Emacs with interactive visual feedback
392 stars 28 forks source link

[Feature] Be able to pass in a regexp but still be able to use visualized replacement prompting #64

Closed Inc0n closed 2 years ago

Inc0n commented 2 years ago

For example, I could invoke vr/query-replace, it could for example take in the symbol at the point to be the regex string to be replaced, but it would continue to prompt for replacement. This way I could get the visual fancies from this package.

benma commented 2 years ago

I am not sure I understand. Can you rephrase it please?

Inc0n commented 2 years ago

In other words I would like to have something like (vr/replace "evil" nil nil nil) possible, where a regexp is passed in, but a replacement would still need to be prompted. So, the first prompt of the regex string to be replaced can be skipped and passed in as an argument, but the function could still proceed to ask for replacement string.

benma commented 2 years ago

I will not add this feature to the main package, but you can achieve your goal by doing something like this locally:

(flet ((vr--set-regexp-string () (setq vr--regexp-string "MY-REGEXP"))) (call-interactively 'vr/query-replace))
Inc0n commented 2 years ago

That's great, thank you very much!

Inc0n commented 2 years ago

Hi benma,

Thanks again for the solution provided, however, in recent times this solution hasn't worked. As I have start using Emacs 28. I made some minor modification to make it work:

(cl-letf (((symbol-function 'vr--set-regexp-string)
             (lambda () (setq vr--regexp-string regexp-string))))
    (call-interactively 'vr/query-replace))

And of course, regexp-string will be the regexp to query to be replaced.