I have a question about Emacs Lisp, I want to achieve this functionality: ‘highlight a word under cursor, then when I push C-s C-s, I can jump to the next highlighted word’.
So after I highlight a word, I hope the isearch-string can be set as the same as the word I have high lightened, i.e. the default ** search string for command **isearch-forward or isearch-backward can be my highlighted word.
My code is like:
(defun highlight-current-word()
"highlight the word under cursor"
(interactive)
(let (head-point tail-point word)
(skip-chars-forward "-_A-Za-z0-9")
(setq tail-point (point))
(skip-chars-backward "-_A-Za-z0-9")
(setq head-point (point))
(setq word (buffer-substring-no-properties head-point tail-point))
(setq isearch-string word) ; no use
(isearch-search-and-update) ; no use
(highlight-regexp word 'hi-yellow)))
But it always prompts: [No previous search string]
Can you help me? Thank you!
C-s C-w? This should auto-highlight the current word (or multiple words for moreC-w) and highlight the same search string as you move forward (or backward) withC-s(C-r)...(thing-at-pt 'word)(orbounds-of-thing-at-pointif you still need to remove properties manually).search-ringregexp-search-ring, but that has nothing to do with highlighting)