我有一个关于Emacs Lisp的问题,我想实现这个功能:高亮鼠标下的单词,然后当我按下C-s C-s时,我可以跳到下一个高亮的单词。
所以在我高亮一个单词之后,我希望isearch-string被设置为与我高亮的单词相同,即isearch-forward或isearch-backward命令的默认**搜索字符串可以是我的高亮单词。
所以在我高亮一个单词之后,我希望isearch-string被设置为与我高亮的单词相同,即isearch-forward或isearch-backward命令的默认**搜索字符串可以是我的高亮单词。
我的代码如下:
(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)))
但它总是提示:[没有先前的搜索字符串]
你能帮我吗?谢谢!
C-s C-w
吗?这个快捷键可以自动高亮当前单词(或者多个单词,使用更多的C-w
),并且在你使用C-s
(向前搜索)或者C-r
(向后搜索)时,会高亮相同的搜索字符串。 - abiessu(thing-at-pt 'word)
(或者如果你仍然需要手动删除属性,则使用bounds-of-thing-at-point
)获取单词,你也可以简化自己的代码。 - philssearch-ring
。 - juanleon