I want to have sort of indiacator at left side of the line wherever I have in the source code
#TODO: some comment
//TODO: some comments
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)))))))
You can customize the bitmap as desired.
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.
Note: The code was updated 27/02/2010 to use overlays instead of directly adding text properties to the current text.
Gopalakrishnan Subramani : This work great. unfortunately I have enabled the line number to be displayed. So line numbers are overriding the TODO: mark. Any way to make both to appearGopalakrishnan Subramani : @Trey Jackson. It works great now. I added next to line number indicator. Thanks a lotCheeso : Cool! but.....:) ...What would be more useful is to display red bars on the fringe, scaled to the length of the document. In other words, if the TODO appears at the 75% point of the document, then the indicator would also appear at 75% on the fringe bar, regardless of scroll state and whether the TODO was visible in the window at the time. Some diff tools do this. With that sort of indicator, you can see the presence of TODO items indicated in the fringe, regardless whether they are visible currently on the screen.Trey Jackson : @Cheeso kind of like the scroll bar. I'm not sure if this is possible in the fringe, but it is intriguing.jrockway : This seems like the sort of thing to implement via font-lock. An overlay seems heavy and inflexible.Trey Jackson : @jrockway That'd be nice, but I didn't see any way to associate fonts with displaying stuff in the margins. But I'm always up for learning a new way...Cheeso : what's the `(format "A")` for? Can't that just be `"A"` ?Trey Jackson : @Cheeso I cut/paste that part (the `format "A"`) assuming that the `propertize` function needed a non-constant string, but now that I've read the documentation for `propertize`, I see that is not the case. I've updated the code appropriately. -
I like the approach described in this post on emacs-fu, which adds TODO/FIXME/... to the font-lock settings of the modes where you need it. In contrast to Trey's approach this should highlight the words as you type, whereas his approach should only highlight them when you open a file (or do I get this wrong).
Anyway its up to you. A good google search gives you probably even more ideas: http://www.google.com/search?q=emacs+highlight+todo
Update: Your question has already been answered: Emacs, highlight all occurences of a word
0 comments:
Post a Comment