【发布时间】:2013-09-06 03:18:07
【问题描述】:
我有一个关于 Emacs Lisp 的问题,我想实现这个功能:'高亮光标下的一个单词,然后当我按下 C-s C-s 时,我可以跳转到下一个高亮的单词。
所以在我高亮一个词之后,我希望isearch-string可以设置成和我高亮的那个词一样,即default ** search string for command **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)))
但总是提示:[No previous search string]
你能帮助我吗?谢谢!
【问题讨论】:
-
你试过
C-s C-w吗?这应该会自动突出显示当前单词(或多个单词以获得更多C-w)并在您使用C-s(C-r) 向前(或向后)移动时突出显示相同的搜索字符串... -
我同意 abiessu,但是如果您使用
(thing-at-pt 'word)获取单词(如果您仍需要手动删除属性,则可以使用bounds-of-thing-at-point)获取单词。 -
那就是
search-ring -
@juanleon,你知道有没有“highlight-regexp-ring”之类的东西来存储突出显示的单词历史?
-
我不这么认为(有
regexp-search-ring,但这与突出显示无关)