Emacs:左侧的TODO指示器

19 lisp emacs elisp highlighting todo

无论我在源代码中的哪个位置,我都希望在线的左侧有一些indiacator

#TODO:一些评论

// TODO:一些评论

该指标可能只是一个标记,我已经启用了emacs上显示的行号.

Tre*_*son 20

此命令将执行您想要的操作.

(defun annotate-todo ()
  "put fringe marker on TODO: lines in the curent buffer"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "TODO:" nil t)
      (let ((overlay (make-overlay (- (point) 5) (point))))
        (overlay-put overlay 'before-string (propertize "A"
                                                        'display '(left-fringe right-triangle)))))))
Run Code Online (Sandbox Code Playgroud)

您可以根据需要自定义位图.

要将此应用于所有文件,您可以将其添加到 'find-file-hooks

(add-hook 'find-file-hooks 'annotate-todo)
Run Code Online (Sandbox Code Playgroud)

或者,如果您只想要某些模式,可以将它添加到这些模式挂钩.

请参阅Fringes,'display'属性,Overlays,以及最重要的before-string属性.

注意:代码已更新27/02/2010以使用叠加而不是直接向当前文本添加文本属性.


dan*_*poe 6

我喜欢本文中关于emacs-fu的描述方法,它将TODO/FIXME/...添加到您需要的模式的字体锁定设置中.与Trey的方法相反,这应该在您键入时强调单词,而他的方法应该只在您打开文件时突出显示它们(或者我错了).

无论如何,它取决于你.一个好的谷歌搜索可能会给你更多的想法:http://www.google.com/search? q = emacs + hiighlight +todo

更新:您的问题已经得到解答:Emacs,突出显示一个单词的所有出现