I was writing up a list of comments on someone's code, and got tired of retyping the line number and filename over and over again. Also, I liked to skip around a bit in the files, but wanted to keep my annotations sorted.
So for starters, I wrote a little XEmacs LISP to automatically add my annotations to a buffer called 'Annotations'. It would ask me for the comment in the minibuffer, then write the whole thing, so that I could keep working without even having to switch screens. I bound it to a key so I could do it repeatedly. Pretty basic stuff.
(defun add-note ()
"Adds an annotation to the 'annotations' buffer"
(annotate-comment (read-from-minibuffer "Comment: "))
(annotate-line (number-to-string (line-number)))
(set-buffer (get-buffer-create "annotations"))
(insert-string (concat annotate-buffer ":" annotate-line " " ann
(global-set-key "\C-ca" `add-note)
This would generate a bunch of annotations like this:
comment_tmpl.tt2:1 This would be more readable if I turned on Template
+'s space-stripping options.
comment_reader.pl:31 More informative error message would probably be
comment_reader.pl:71 Need a better explanation of data structure.
annotate.el:1 Should properly be in a mode...
annotate.el:11 Should be configurable variable
annotate.el:13 Formatting should be configurable in variable
annotate.el:11 Should automatically make "annotations" visible if it i
annotate.el:21 Control-c keys are supposed to be for mode-specifics...
Next, I wanted to format my annotations so I could post them here in some kind of HTML format. So I wrote a little text processor to take my annotations, parse them, and format the result in HTML. This was not difficult, since most of the heavy lifting was done by the Template module.
Here's a standard template file... pretty ugly, really, but you can define your own without changing the code...
[% FOREACH file = files %][% FOREACH line = file.lines %]
<dt>[% file.name %]</dt>
<dd><b>line [% line.number %]</b>
<ul>[% FOREACH comment = line.comments %]
<li>[% comment %]</li>
[% END %]</ul>
[% END %][% END %]
Alternatively, I could have had my XEmacs function output XML and used XSLT. Six of one, half a dozen of the other... Plus, one could write a template file to translate annotations into an XML format.
- Should properly be in a mode...
- Should be configurable variable
- Should automatically make "annotations" visible if it isn't already
- Formatting should be configurable in variable
- Control-c keys are supposed to be for mode-specifics...
- More informative error message would probably be good.
- Need a better explanation of data structure.
- This would be more readable if I turned on Template's space-stripping options.