Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: TODO indicator on left fringe has a strange side-effect - deleting characters

Tags:

emacs

I just read Emacs :TODO indicator at left side, and tried it out. It seems intriguing. The little indicator triangles appear, but I'm getting a weird side effect: the text itself is being altered. Characters are being deleted.

Before:

alt text

After:

alt text

The mode-line does indicate that the buffer has been altered after running annotate-todo. What explains this?

(I'm using emacs 22.2.1 on Windows)

like image 261
Cheeso Avatar asked Feb 27 '10 19:02

Cheeso


1 Answers

Ahhh... I see the error of my ways earlier. Here's a new version.

(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 (format "A")
                                                        'display '(left-fringe right-triangle)))))))

The first solution used a the 'display text property, which changes how the specified text is displayed, in this case it was replaced by the triangle in the left fringe. What I needed to do was to use a 'before-string overlay instead. Which doesn't change the string being displayed.

Another advantage, the cut/paste of the code annotated by this does not carry the markup.

I've updated the code in the original question to reflect this change as well.

like image 66
Trey Jackson Avatar answered Oct 22 '22 18:10

Trey Jackson