问题描述
我想在源代码中的任何位置都有一些indiacator在行的左侧。
I want to have sort of indiacator at left side of the line wherever I have in the source code
#TODO :一些评论
// TODO:一些评论
//TODO: some comments
该指标可能是一个标记,我已经启用了行号显示在emacs。
The indicator could be a just mark and I already enabled line numbers displayed at emacs.
推荐答案
这个命令将会像你想要的那样做。
This command will do something like you want.
(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)))))))
您可以
为了使其适用于所有文件,您可以将它添加到'find-file-hooks
To get this to apply to all files, you could add it to the 'find-file-hooks
(add-hook 'find-file-hooks 'annotate-todo)
或者,如果你只想要一定模式,您可以将其添加到这些模式挂钩。
Or, if you want it just for certain modes, you could add it to those mode hooks.
请参阅,,,最重要的是属性。
See Fringes, The 'display' Property, Overlays, and most importantly the before-string property.
注意:代码已更新27/02/2010至使用重叠式广告代替直接向当前文本添加文本属性。
Note: The code was updated 27/02/2010 to use overlays instead of directly adding text properties to the current text.
这篇关于Emacs:TODO指示灯在左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!