NonGNU ELPA - annotate

annotate Atom Feed

annotate files without changing them
annotate-2.2.2.tar (.sig), 2024-May-09, 970 KiB
Bastian Bechtold <>, cage <>
Browse ELPA's repository
CGit or Gitweb

To install this package from Emacs, use package-install or list-packages.

Full description




1. introduction

This package provides a minor mode annotate-mode, which can add annotations to arbitrary files without changing the files themselves. This is very useful for code reviews. When annotate-mode is active, C-c C-a will create, edit, or delete annotations. example.png

2. Usage

2.1. Quick start

With an active region, C-c C-a creates a new annotation for that region. With no active region, C-c C-a will create an annotation for the word under point. If point is on an annotated region, C-c C-a will edit that annotation instead of creating a new one. Typing C-c C-d or clearing the annotation deletes them.

Use C-c ] to jump to the next annotation and C-c [ to jump to the previous annotation.

2.2. Metadata

The current database for annotations is contained in the file indicated by the variable annotate-file (~/.emacs.d/annotations by default) but each user can change this value in a dynamic way using the command annotate-switch-db. This command will take care to refresh/redraw all annotations in the buffers that uses annotate-mode.

The database holds the hash of each annotated file so it can print a warning if the file has been modified outside Emacs (for example).

Warning can be suppressed setting the variable annotate-warn-if-hash-mismatch to nil.

Please note that switching database, in this context, means rebinding the aforementioned variable (annotate-file). This means than no more than a single database can be active for each Emacs session.

If an empty annotation database (in memory) is saved the database file is deleted instead, if annotate-database-confirm-deletion is non nil (the default) a confirmation action is asked to the user before actually remove the file from the file system.

  1. related customizable variable
    • annotate-file
    • annotate-warn-if-hash-mismatch
    • annotate-database-confirm-deletion
2.2.1. Non centralized database

To use multiple database in the same Emacs session annotate-file should be made buffer-local,


this thread and, in particular this message.

Finally, if the customizable variable annotate-file-buffer-local is non-nil (default nil), for each annotated file an annotation database is saved under the same directory that contains the annotated file.

The name of the annotation database is built concatenating the name of the annotated file without the optional extension and the string value bound to the customizable variable annotate-buffer-local-database-extension (default: notes), example follows:

annotated file annotations file
/home/user/foo.c /home/user/foo.notes

Important note: if /home/user/foo.notes exists, will be overwritten.

  1. related customizable variable
    • annotate-file-buffer-local
    • annotate-buffer-local-database-extension
2.2.2. Uninstalling

Users of no-littering can take advantage of its packages generated files management.

2.3. keybindings

2.3.1. C-c C-a (function annotate-annotate)

Creates a new annotation for that region.

With no active region, C-c C-a will create an annotation for the word under point. If point is on an annotated region, C-c C-a will edit that annotation instead of creating a new one. Clearing the annotation deletes them.

If annotate-annotation-confirm-deletion is non nil (the default is nil) a confirmation action is asked, using y-or-n-p, to the user before actually remove the annotation.

If point is the newline character and the customizable variable annotate-endline-annotate-whole-line is not nil (default is non nil) the whole line is annotated (or the next if the line is empty).

If the line contains a single annotation that cover all the line, annotating the newline will ask to edit the annotation. If annotate-endline-annotate-whole-line is nil annotating a newline will signal an error.

With a numeric prefix the annotations will be displayed with the faces indicated in annotate-highlight-faces and annotate-annotation-text-faces, respectively. The numeric prefix is used as index in the lists bound to the aforementioned variables.

The first theme can be addressed by the prefix 1, the second by the prefix 2 and so on.

  1. related customizable variable
    • annotate-annotation-column;
    • annotate-annotation-confirm-deletion;
    • annotate-annotation-max-size-not-place-new-line;
    • annotate-annotation-position-policy;
    • annotate-endline-annotate-whole-line;
    • annotate-highlight-faces;
    • annotate-annotation-text-faces.
2.3.2. C-c C-d

Delete an annotation under point, if such annotation exists.

If annotate-annotation-confirm-deletion is non nil (the default is nil) a confirmation action is asked, using y-or-n-p, to the user before actually remove the annotation.

  1. related customizable variable
    • annotate-annotation-confirm-deletion.
2.3.3. C-c ] (function annotate-goto-next-annotation)

Jump to the next annotation.

2.3.4. C-c [ (function annotate-goto-previous-annotation)

Jump to the previous annotation.

2.3.5. C-c C-s (function annotate-show-annotation-summary)

Show summary window.

A window with a list of annotated files together with their annotations is shown. If annotate-summary-ask-query is non nil (default is t) then a prompt is shown where the user can insert a query to filter the annotation database, see "Query Language" below.

The summary window allow editing and removing of annotation using the provided buttons.

The annotation text can be pressed to and will open the annotated file, placing the cursor at the point where the corresponding annotated text appears.

  1. related customizable variable
    • annotate-summary-ask-query.
2.3.6. C-c C-c (function annotate-change-annotation-colors)

Change the color of the annotation below point (both higlight and annotation text colors are changed).

These changes are kept after the buffer is killed.

2.3.7. C-c C-p (function annotate-change-annotation-text-position)

Change the policy positioning the annotation below point, a message with the new policy is printed.

These changes are kept after the buffer is killed.

3. Exporting

Annotations can be exported annotate-export-annotations as commented unified diffs, like this:


Alternatively, they can be integrated annotate-integrate-annotations as comments into the current buffer, like this:


  1. related customizable variable
    • annotate-integrate-marker
    • annotate-diff-export-options
    • annotate-integrate-highlight
    • annotate-fallback-comment

4. Importing

An annotation database file can be imported using the command annotate-import-annotations.

When importing, overlapping annotations will be merged in a single annotation with the new annotated text that maximizes the portion of text annotated, e.g.

The quick brown fox ← text
 ^^^^^^^^           ← first annotation
      ********      ← second annotation
 +++++++++++++      ← merged annotation

The text of the merged annotation is the concatenated text of the two annotations.

Note that importing a database will modify permanently the file bound to the variable annotate-file. If unsure of the results, backup that file before importing.

  1. related customizable variable
    • annotate-database-confirm-import.

5. Alternative visualization of annotations

For typographically difficult scenarios (or just because you prefer it), such as variable-width fonts or overlay-heavy modes, the default visualization system that renders the annotation into the buffer could not properly works.

In this case the users can switch to a "pop-up" style annotation setting to a non-nil value the variable annotate-use-echo-area.

When such variable's value is not null, moving the mouse pointer over the annotated text will temporary show the annotation.

The actual visuals of this "pop-up" can be different depending of your system's setup (see this pull request for a couple of examples.

Moreover if annotate-use-echo-area and annotate-print-annotation-under-cursor value both non null, placing the cursor over an annotated text region will print the annotation's text in the minibuffer prefixed by the value of customizable variable annotate-print-annotation-under-cursor-prefix, after a delay (in seconds) defined by the variable annotate-print-annotation-under-cursor-delay.

Another alternative way to show annotations is provided by the command: annotate-summary-of-file-from-current-pos.

Calling this command will show a summary window that prints all the annotations related to annotated text that appears (in the active buffer) beyond the current cursor position.

  1. related customizable variable
    • annotate-use-echo-area
    • annotate-print-annotation-under-cursor
    • annotate-print-annotation-under-cursor-prefix
    • annotate-print-annotation-under-cursor-delay
    • annotate-summary-of-file-from-current-pos.

6. Other commands

6.1. annotate-switch-db

This command will ask the user for a new annotation database files, load it and refresh all the annotations contained in each buffer where annotate minor mode is active.

See the docstring for more information and this thread for a possible workflow where this command could be useful.

6.2. annotate-toggle-annotation-text

Shows or hides annotation's text under cursor.

6.3. annotate-toggle-all-annotations-text

Shows or hides the annotation's text in the whole buffer.

7. More documentation

Please check M-x customize-group RET annotate as there is extensive documentation for each customizable variable.


8.1. Known bugs

  • Annotations in org-mode source blocks will be underlined, but the annotations don't show up. This is likely a fundamental incompatibility with the way source blocks are highlighted and the way annotations are displayed.
  • Because of a limitation in the Emacs display routines scroll-down-line could get stuck on a annotated line. So no fix can be provided by the authors of annotate.el, a possible

workaround is to call the command with a numeric prefix equals to one plus the number of annotation text lines below the annotated text.

For example:

foo bar baz

needs a prefix of 2: C-u 2 M-x scroll-down-line

But note that:

foo bar baz   annotation

Needs no prefix.

  • Deleting the first character of an annotated text will remove the annotation (this turned out to be useful, though).

8.2. Report bugs

To report bugs please, point your browser to the issue tracker.

9. Query Language

The summary window can shows results filtered by criteria specified with a very simple query language, the basis syntax for that language is shown below:

[file-mask] [(and | or) [not] regex-note [(and | or) [not] regexp-note ...]]


is a regular expression that should match the path of file the annotation refers to;
and, or, not
you guess? Classics logical operators;
the text of annotation must match this regular expression.

9.1. Examples

lisp$ and TODO

matches the text TODO in all lisp files

Parenthesis can be used for the expression related to the text of annotation, like this:

lisp$ and (TODO or important)

the same as above but checks also for string `important'


matches all the annotation that refers to file in the directory /home/foo

/home/foo/ and not minor

matches all the annotation that refers to file in the directory /home/foo and that not contains the text minor.

.* and "not"

the quotation mark (") can be used to escape strings.

As a shortcut, an empty query will match everything (just press return at prompt).

10. FAQ

Sometimes the package does not respect the customizable variable's value of annotate-annotation-position-policy, is this a bug?

No it is not, when a line which is using a non default font is annotated the software force the :new-line policy, that is the annotation will be displayed on a new line regardless of the value of the variable mentioned in the question.

This is necessary to prevent the annotation to be pushed beyond the window limits if an huge font is used by the annotated text.


This package is released under the MIT license, see file LICENSE

Old versions

annotate-2.2.1.tar.lz2024-Mar-31 652 KiB
annotate-2.2.0.tar.lz2024-Mar-20 651 KiB
annotate-2.1.0.tar.lz2023-Nov-02 650 KiB
annotate-2.0.3.tar.lz2023-Sep-30 650 KiB
annotate-2.0.2.tar.lz2023-Aug-30 650 KiB
annotate-2.0.1.tar.lz2023-Jul-09 650 KiB
annotate-2.0.0.tar.lz2023-Apr-01 650 KiB
annotate-1.9.0.tar.lz2023-Mar-10 650 KiB
annotate-1.8.5.tar.lz2023-Feb-03 649 KiB
annotate-1.8.4.tar.lz2022-Dec-19 649 KiB
annotate-1.8.3.tar.lz2022-Dec-10 649 KiB
annotate-1.8.0.tar.lz2022-Sep-30 648 KiB
annotate-1.7.2.tar.lz2022-Sep-16 646 KiB
annotate-1.7.1.tar.lz2022-Aug-09 646 KiB
annotate-1.7.0.tar.lz2022-Jul-07 646 KiB
annotate-1.6.0.tar.lz2022-Jun-03 644 KiB
annotate-1.5.4.tar.lz2022-Apr-28 644 KiB
annotate-1.5.3.tar.lz2022-Apr-08 644 KiB
annotate-1.5.2.tar.lz2022-Apr-07 643 KiB
annotate-1.5.0.tar.lz2022-Feb-04 643 KiB


2024-03-23 v2.2.1 cage
This version added missing information from documentation about annotations database file format.
2023-10-10 v2.2.0 cage

This version adds two new commands:

  • annotate-change-annotation-text-position;
  • annotate-change-annotation-colors.

To force positioning or color, respectively, for a single annotation.

2023-10-10 v2.1.0 cage
This version ensures that the color theme for each annotation (both underline color of the annotated text and colors of the annotation), is saved when a an annotated file (or Emacs) is closed. The same color theme will be restored together with the annotations when, for example, the annotated file will be visited again.
2023-09-27 v2.0.3 cage
This version fixed a bug that could render with the same color two adjacent annotations.
2023-08-09 v2.0.2 cage
This version replaced a procedure with a call to an equivalent library function.
2023-07-06 v2.0.1 cage

This version ensures that querying the database will search in all the annotated buffers on the current Emacs session.

A phrase regarding the annotation of the newline character has been corrected in

2023-03-22 v2.0.0 cage
This version modify the command annotate-annotate to allow setting specific colors for each annotation.
2023-02-22 v1.9.0 cage
This version added two new commands to hide/show the annotation's text:
shows or hides annotation's text under cursor;
shows or hides the annotation's text in the whole buffer.
2022-12-15 v1.8.5 cage
This version fixed a regression that prevented to delete annotations when disabling annotation-mode.
2022-12-15 v1.8.4 cage

This versions prevented printing of a warning

`annotate-save-annotations' printed a warning if the buffer was not based on a file's contents. But the warning was printed even if the buffer contained no annotations at all.

This version prints the warning about missing file only if the buffer is annotated (i.e. contains at least an annotation).

2022-11-30 v1.8.3 cage

This versions fixed a bug that prevented annotations of info files.

Also opening of annotated remote files should be faster.

2022-10-20 v1.8.2 cage

This version fixed a crash that occurred when visiting an annotated buffer using TRAMP.

Thanks to gsingh93 for discovering the bug and providing an immensely useful help.

2022-10-20 v1.8.1 cage
This version fix the command annotate-integrate-annotations that was corrupting the buffer containing the annotations, when used.
2022-09-21 v1.8.0 cage

This version allows printing of the annotation in the minibuffer when the cursor is placed over an annotated text region.

To activate this feature set to non nil the values of these two customizable variables:

  • annotate-use-echo-area
  • annotate-print-annotation-under-cursor
2022-08-02 v1.7.2 cage

This version removed an error signalled when closing an annotated indirect buffer. Instead, when an annotated indirect buffer is killed annotate-mode will clone it into a new regular buffer so that the user can decide to save it in a file or discard it completely.

Thanks JuanManuelM!

2022-08-02 v1.7.1 cage
This version fix a bug that prevented saving some annotations when Emacs was closed.
2022-05-26 v1.7.0 cage
This version no more sets the buffer as modified when the only changes made by the user to such buffer are related to annotations (for example, creating a new annotation or deleting an existing one).
2022-05-26 v1.6.0 cage
This version allows users to instruct the program to generate an annotation database for each annotated file, instead of using a central database that contains all the annotations.
2022-04-23 v1.5.4 cage
This version restored redrawing of annotation when the window is

… …