Search code examples
emacslispelisphighlightingtodo

Emacs :TODO indicator at left side


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.


Solution

  • 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.