Try this. Bind it to a key. You can use M-s h u
to unhighlight the last-highlighted word. You're prompted for the word, with the word at point as default.
The regexp to match is whatever word you enter, expanded by word chars on either side. So if you want to match houses
, entering house
will pick that up too.
There's no easy answer to what you might be expecting, which is to have Emacs know about actual English (or whatever language) words, e.g., to know that houses
is a word but thouses
is not. But it's not too likely that you'll end up with such non-words in your buffer.
If you want to allow only for suffixes (e.g. s
) and not also prefixes, then replace the "\\b\\w*"
with just "\\b"
.
(defun foo (word)
(interactive (list (read-string "Word: " (word-at-point))))
(highlight-phrase (concat "\\b\\w*" word "\\w*\\b")))
But if your question was really about searching, then use C-M-s C-w
to pick up the word at point, then M-e
to edit that search pattern, then type \w*\b
for a pattern that adds suffixes, then C-s
to continue searching.
If you want Isearch to highlight across the whole buffer then set variable lazy-highlight-buffer
to t
.
If you want Isearch highlighting to persist till the next search, set variable lazy-highlight-cleanup
to nil
.