0

With point over a word, pressing C-u C-s highlights this word and any identical words. How can I make this work for substring search as well, i.e. if highlighting the word house, occurrences of houses are also highlighted?

Also, I would like to have this functionality extend through the entire buffer, so that if I scoll with C-v and M-v words are already highlighted.

0

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.

2
  • thank you for your detailed anwer. I think it doesnt have to be so complicated. All I want is for entries to appear if they contain the word house in any form. – CD86 Jun 11 at 7:46
  • The question is unclear. Are you asking about search or just highlighting? What's an "entry" - is it a word or any text (what limits?) that contains the initial word (base) you've typed? Etc. Think about what you've written - the problem isn't well specified. – Drew Jun 11 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.