(query-replace "foo" "bar")
shows you all occurrences of foo
and offers to replace them by bar
.
I would love to have a version of query-replace
that only picks the occurrences of foo
that are "in some context" (to be defined). At the moment, I'm thinking of LaTeX files with the context being "any part that is in math style". Or any part not in math style. These parts are already highlighted by Emacs' latex-mode
so it can recognize them.
query-replace
can already perform a bit of context checking since its DELIMITED
argument allows restricting to occurrences surrounded by word boundaries, but this is a simple special case that can be implemented with regular expressions, e.g., looking for \<foo\>
.
My question: do you know of an extension of query-replace
in some package somewhere that can do the replace-only-in-math-style trick I need? Or of something similar enough that would be a good start for tweaking and hacking around?
texmathp.el
(it's bundled into AUCTeX but doesn't require it to work), which provides you the functiontexmathp
to check whether point is inside math mode. – giordano Nov 8 '15 at 14:16query-replace
and insert a(if (texmathp) ..)
at the right place. I'll try that and report on the outcome. – phs Nov 8 '15 at 14:51isearch-filter-predicate
variable I have set it to something that callstexmathp
. It is annoying that they do not have the same interface:isearch-filer-predicate
wants a(beg end)
region argument,texmathp
looks at point in buffer. I'd suggest just allowing an optionalpos
argument totexmathp
. – phs Nov 8 '15 at 20:43isearch-filter-predicate
to something that callstexmathp
"? I am also interested in this approach. – Gabriele Nicolardi Mar 4 '19 at 22:08http://www.lsv.fr/~phs/query-replace-in-tex-math-only.el
– phs Mar 5 '19 at 18:03