Reputation: 47061
For example, I have the codes below:
(defun toggle-light ()
"Toggle setting tab widths between 4 and 8"
(setq a
(if (boundp 'a) a nil))
(interactive)
(if a
(progn
(load-theme 'solarized-dark t)
(setq a nil))
(progn
(load-theme 'solarized-light t)
(setq a t) )))
And now I want to refactor this blocks by replacing the variable name a
with is-lighted
, but without changing other character a
in other words (for example, in interactive
or tab
).
Is there a built-in function in emacs that can finsih that job?
Upvotes: 2
Views: 115
Reputation: 18055
While phils's answer is correct and idiomatic, you should also learn about \b
word boundary regular expression. Thus, equivalent regexp replace would be M-%\ba\b
. See Backslash in Regular Expressions @ Emacs Manual and Regular Expression @ EmacsWiki.
Upvotes: 1
Reputation: 73256
C-uM-% a
RET is-lighted
RET
The prefix argument ("delimited") to the standard query-replace functions wraps the pattern with word-boundary markers.
Upvotes: 5