<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <atom:link href="http://kitchingroup.cheme.cmu.edu/blog/feed/index.xml" rel="self" type="application/rss+xml" />
    <title>The Kitchin Research Group</title>
    <link>https://kitchingroup.cheme.cmu.edu/blog</link>
    <description>Chemical Engineering at Carnegie Mellon University</description>
    <pubDate>Sat, 01 Nov 2025 13:47:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    
    <item>
      <title>A highlight annotation mode for Emacs using font-lock</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2015/07/28/A-highlight-annotation-mode-for-Emacs-using-font-lock</link>
      <pubDate>Tue, 28 Jul 2015 10:57:17 EDT</pubDate>
      <category><![CDATA[annotation]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">728zPTn0N0f1gENydl33NkYFHXo=</guid>
      <description>A highlight annotation mode for Emacs using font-lock</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-1"&gt;1. Known limitations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
One of my students asked about highlighting text in emacs for note-taking. I can see some advantages for doing it while teaching, for example, and for students studying, so here we we work it out.
&lt;/p&gt;

&lt;p&gt;
You will definitely want to see the video on this one, the highlights do not show up in the published html. &lt;a href="https://www.youtube.com/watch?v=Cvz2tiT12-I"&gt;https://www.youtube.com/watch?v=Cvz2tiT12-I&lt;/a&gt; 
&lt;/p&gt;

&lt;p&gt;
For temporary use, highlighting is pretty easy, you just set a property on a region, e.g. the background color. For example, we can do this:
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;&lt;span style="color: #8D8D84;"&gt;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;this seems to be necessary to get the tooltips to work.&lt;/span&gt;
(&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; font-lock-extra-managed-props (delq 'help-echo font-lock-extra-managed-props))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-region&lt;/span&gt; (beg end)
 (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt; &lt;span style="color: #008000;"&gt;"r"&lt;/span&gt;)
 (set-text-properties
  beg end
  '(font-lock-face (&lt;span style="color: #006FE0;"&gt;:background&lt;/span&gt; &lt;span style="color: #008000;"&gt;"Light Salmon"&lt;/span&gt;)
                   highlighted t
                   help-echo &lt;span style="color: #008000;"&gt;"highlighted"&lt;/span&gt;)))

(global-set-key (kbd &lt;span style="color: #008000;"&gt;"s-h"&lt;/span&gt;) 'highlight-region)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
highlight-region
&lt;/pre&gt;

&lt;p&gt;
This sets the background color, and another property "highlighted" that we will use later. The trouble is this is transient. When I close the file, the highlights are lost. We can save them to a file though, and reload them later. As long as we are diligent about that we should be able to provide persistent highlights.
&lt;/p&gt;

&lt;p&gt;
First we need a function to get all the highlights, their start and end, their color, and if there is a help-echo which provides a tooltip. We will see why later. Here we loop through the buffer collecting highlights, and return a list of them.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-get-highlights&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Scan buffer for list of highlighted regions.&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;These are defined only by the highlighted property. That means&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;adjacent highlighted regions will be merged into one region with&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;the color of the first one."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
    (goto-char (point-min))
    (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((highlights '())
          (p)
          (beg)
          (end)
          (note)
          (color))
      &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;corner case of first point being highlighted&lt;/span&gt;
      (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (get-text-property (point) 'highlighted)
        (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; beg (point)
              end (next-single-property-change (point) 'highlighted)
              color (background-color-at-point)
              help-echo (get-text-property (point) 'help-echo))
        (add-to-list 'highlights (list beg end color help-echo) t)
        (goto-char end))

      &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;Now the rest of the buffer&lt;/span&gt;
      (&lt;span style="color: #0000FF;"&gt;while&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; p (next-single-property-change (point) 'highlighted))
        (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; beg (goto-char p))
        (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; color (background-color-at-point))
        (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; note (get-text-property (point) 'help-echo))
        (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; end (next-single-property-change (point) 'highlighted))
        (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; beg end)
          (goto-char end)
          (add-to-list 'highlights (list beg
                                         end
                                         color
                                         note)
                       t)
          (goto-char end)))
      highlights)))

(highlight-get-highlights)
&lt;/pre&gt;
&lt;/div&gt;

&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;


&lt;colgroup&gt;
&lt;col  class="right" /&gt;

&lt;col  class="right" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="right"&gt;438&lt;/td&gt;
&lt;td class="right"&gt;454&lt;/td&gt;
&lt;td class="left"&gt;Light Salmon&lt;/td&gt;
&lt;td class="left"&gt;highlighted&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td class="right"&gt;1014&lt;/td&gt;
&lt;td class="right"&gt;1031&lt;/td&gt;
&lt;td class="left"&gt;Light Salmon&lt;/td&gt;
&lt;td class="left"&gt;highlighted&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;


&lt;p&gt;
Next, we generate a filename, and a function to save the highlights to disk. We make it a hook function that runs every time we save the buffer.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-save-filename&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Return name of file to save overlays in."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (buffer-file-name)
    (concat &lt;span style="color: #008000;"&gt;"."&lt;/span&gt; (file-name-nondirectory (buffer-file-name)) &lt;span style="color: #008000;"&gt;".highlights"&lt;/span&gt;)))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-save&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Loop through buffer and save regions with property highlighted.&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;Save beginning, end of each region, color and help-echo on the&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;first character of the region. Delete highlight file if it is empty."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((fname (highlight-save-filename))
        (highlights (highlight-get-highlights)))
    (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; fname highlights)
          (&lt;span style="color: #0000FF;"&gt;with-temp-file&lt;/span&gt; fname
            (print highlights (current-buffer)))
        &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;get rid of file if there are not highlights&lt;/span&gt;
        (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; fname (file-exists-p fname))
          (delete-file fname)))))

(add-hook 'after-save-hook 'highlight-save)
&lt;/pre&gt;
&lt;/div&gt;

&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;


&lt;colgroup&gt;
&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="left"&gt;highlight-save&lt;/td&gt;
&lt;td class="left"&gt;helm-swoop&amp;#x2013;clear-cache&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-sh"&gt;cat .highlights.org.highlights
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
((438 454 "Light Salmon" "highlighted") (1014 1031 "Light Salmon" "highlighted"))
&lt;/pre&gt;

&lt;p&gt;
Here, we can read the contents and apply the highlights. We set this up on a hook for org-mode, so it will apply them on when we open org-files. You could make this more general if you plan to highlight in code files, for example.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-load&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Load and apply highlights."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; font-lock-extra-managed-props (delq 'help-echo font-lock-extra-managed-props))
  (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((fname (highlight-save-filename)))
    (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; fname (file-exists-p fname))
      (mapcar
       (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (entry)
         (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((beg (nth 0 entry))
               (end (nth 1 entry))
               (color (nth 2 entry))
               (help-echo (nth 3 entry)))
           (set-text-properties
            beg end
            `(font-lock-face (&lt;span style="color: #006FE0;"&gt;:background&lt;/span&gt; ,color)
                             help-echo ,help-echo
                             highlighted t))))
       (&lt;span style="color: #0000FF;"&gt;with-temp-buffer&lt;/span&gt; (insert-file-contents fname)
                         (read (current-buffer)))))))


(add-hook 'org-mode-hook 'highlight-load)
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;
Now, let's outdo ourselves in ridiculosity. We will add a helm-colors selector to give you unprecedented highlighting capability in multicolor magnificence. This function will highlight selected text, or update the color of an existing highlight.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight&lt;/span&gt; (beg end &lt;span style="color: #6434A3;"&gt;&amp;amp;optional&lt;/span&gt; color)
  &lt;span style="color: #036A07;"&gt;"Highlight region from BEG to END with COLOR.&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;COLOR is selected from `&lt;/span&gt;&lt;span style="color: #D0372D;"&gt;helm-colors&lt;/span&gt;&lt;span style="color: #036A07;"&gt;' when run interactively."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt; &lt;span style="color: #008000;"&gt;"r"&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;or&lt;/span&gt; (get-text-property (point) 'highlighted)
              (region-active-p))
    (&lt;span style="color: #ff0000; font-weight: bold;"&gt;error&lt;/span&gt; &lt;span style="color: #008000;"&gt;"No region selected or not on a highlight."&lt;/span&gt;))
  (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; color
    (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; color (s-trim (helm-colors))))
  (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (get-text-property (point) 'highlighted)
      &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;update color&lt;/span&gt;
      (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((beg (previous-single-property-change (point) 'highlighted))
            (end (next-single-property-change (point) 'highlighted)))
        (set-text-properties
         beg end
         `(font-lock-face (&lt;span style="color: #006FE0;"&gt;:background&lt;/span&gt; ,color)
                          highlighted t)))
  (set-text-properties
   beg end
   `(font-lock-face (&lt;span style="color: #006FE0;"&gt;:background&lt;/span&gt; ,color)
                    highlighted t))))

&lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;For convenience&lt;/span&gt;
(global-set-key (kbd &lt;span style="color: #008000;"&gt;"s-h"&lt;/span&gt;) 'highlight)
&lt;/pre&gt;
&lt;/div&gt;
&lt;pre class="example"&gt;
highlight
&lt;/pre&gt;


&lt;p&gt;
Now, we can conveniently highlight text in whatever color we want. How about list your highlights? After we have highlighted a lot, it might be nice to see a list of these we can click on to find our highlights more quickly.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-list&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Make a list of highlighted text in another buffer. "&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((cb (current-buffer))
        (fname (buffer-file-name))
        (hls (mapcar
              (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (entry)
                (list (nth 0 entry)
                      (buffer-substring (nth 0 entry) (nth 1 entry))))
              (highlight-get-highlights))))
    (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; hls
        (&lt;span style="color: #0000FF;"&gt;progn&lt;/span&gt;
          (split-window-right)
          (switch-to-buffer-other-window &lt;span style="color: #008000;"&gt;"*highlights*"&lt;/span&gt;) (org-mode)
          (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; buffer-read-only nil)
          (erase-buffer)
          (insert &lt;span style="color: #008000;"&gt;"Click on text to jump to the position.\n\n"&lt;/span&gt;)

          (&lt;span style="color: #0000FF;"&gt;dolist&lt;/span&gt; (s hls)
            (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((map (make-sparse-keymap)))
              (define-key map [mouse-1]
                `(&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; ()
                   (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
                   (find-file ,fname)
                   (goto-char ,(nth 0 s))))
              (insert (propertize
                       (concat (nth 1 s) &lt;span style="color: #008000;"&gt;"\n"&lt;/span&gt;)
                       'local-map map))))
          (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; buffer-read-only t))
      (message &lt;span style="color: #008000;"&gt;"No highlights found."&lt;/span&gt;))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
highlight-list
&lt;/pre&gt;

&lt;p&gt;
You probably would like to just select some text with your mouse, and have it highlighted. That requires us to advise the mouse-set-region function.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-green&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Highlight region in green."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (highlight (region-beginning) (region-end) &lt;span style="color: #008000;"&gt;"Darkolivegreen1"&lt;/span&gt;))

&lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;create the advice for use later&lt;/span&gt;
(&lt;span style="color: #0000FF;"&gt;defadvice&lt;/span&gt; &lt;span style="color: #006699;"&gt;mouse-set-region&lt;/span&gt; (after my-highlight () disable)
  &lt;span style="color: #036A07;"&gt;"Highlight"&lt;/span&gt;
  (highlight-green))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-mouse-on&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Turn on mouse highlighting"&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (ad-enable-advice 'mouse-set-region 'after 'my-highlight)
  (ad-activate 'mouse-set-region))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-mouse-off&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (ad-disable-advice 'mouse-set-region 'after 'my-highlight)
  (ad-deactivate 'mouse-set-region))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
highlight-mouse-off
&lt;/pre&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-picasso-blues&lt;/span&gt; ()
 (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
 (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
   (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((colors '(&lt;span style="color: #008000;"&gt;"PowderBlue"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Lightskyblue1"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Lightskyblue2"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Lightskyblue3"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Lightskyblue4"&lt;/span&gt;))
         (beg (region-beginning))
         (end (region-end)))
     (goto-char beg)
     (&lt;span style="color: #0000FF;"&gt;while&lt;/span&gt; (&amp;lt; (point) (- end 1))
       (highlight (point) (+ 1 (point))
                  (nth (mod (- (point) (region-beginning)) (length colors)) colors))
       (forward-char)))))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-rainbow&lt;/span&gt; ()
 (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
 (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
   (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((colors '(&lt;span style="color: #008000;"&gt;"Red1"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Orange1"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Yellow1"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Darkolivegreen1"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Skyblue1"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"Blue1"&lt;/span&gt;
                   &lt;span style="color: #008000;"&gt;"DarkViolet"&lt;/span&gt;))
         (beg (region-beginning))
         (end (region-end)))
     (goto-char beg)
     (&lt;span style="color: #0000FF;"&gt;while&lt;/span&gt; (&amp;lt; (point) (- end 1))
       (highlight (point) (+ 1 (point))
                  (nth (mod (- (point) (region-beginning)) (length colors)) colors))
       (forward-char)))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
=These look cool, but they don't get properly saved. The code that finds the highlights finds the region, but only saves the first color. That means that adjacent highlights of different color will also not be saved correctly.
&lt;/p&gt;

&lt;p&gt;
How about a highlight with your own tooltip? In theory we can set the help-echo property to some text. In practice I have found this tricky because font-lock occasionally erases help-echo properties on re-fontifying. We remove help-echo from a list of properties that are affected by this, but another library may add it back, and there might be some unintended consequences of that. Here we design a function to highlight with a user-defined tooltip.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-note&lt;/span&gt; (beg end color &lt;span style="color: #6434A3;"&gt;&amp;amp;optional&lt;/span&gt; note)
  &lt;span style="color: #036A07;"&gt;"Highlight selected text and add NOTE to it as a tooltip."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;
   (list
    (region-beginning)
    (region-end)
    (s-trim (helm-colors))))
  (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; note (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; note (read-input &lt;span style="color: #008000;"&gt;"Note: "&lt;/span&gt;)))
  (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; (region-active-p)
    (&lt;span style="color: #ff0000; font-weight: bold;"&gt;error&lt;/span&gt; &lt;span style="color: #008000;"&gt;"No region selected."&lt;/span&gt;))
  (set-text-properties
   beg end
   `(help-echo ,note font-lock-face (&lt;span style="color: #006FE0;"&gt;:background&lt;/span&gt; ,color)
               highlighted t)))


(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-note-edit&lt;/span&gt; (new-note)
  &lt;span style="color: #036A07;"&gt;"Set tooltip of highlight at point to NEW-NOTE."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt; (list (read-input &lt;span style="color: #008000;"&gt;"Note: "&lt;/span&gt; (get-text-property (point) 'help-echo))))
  (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((region (button-lock-find-extent (point) 'highlighted))
         (beg (car region))
         (end (cdr region)))
    (put-text-property beg end 'help-echo new-note)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
=highlight-note-edit
==highlight-note-edit
==highlight-note-edit
==highlight-note-edit
=C
Want to get rid of the highlights? We may want to delete one or all. We make a function for each.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-clear&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Clear highlight at point."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (get-text-property (point) 'highlighted)
    (set-text-properties
     (next-single-property-change (point) 'highlighted)
     (previous-single-property-change (point) 'highlighted)
     nil)))


(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-clear-all&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Clear all highlights.&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;They are really deleted when you save the buffer."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (mapcar
   (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (entry)
     (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((beg (nth 0 entry))
           (end (nth 1 entry)))
       (set-text-properties
        beg end nil)))
   (highlight-get-highlights))
  (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (get-buffer &lt;span style="color: #008000;"&gt;"*highlights*"&lt;/span&gt;)
    (kill-buffer &lt;span style="color: #008000;"&gt;"*highlights*"&lt;/span&gt;)))
&lt;/pre&gt;
&lt;/div&gt;
&lt;pre class="example"&gt;
highlight-clear-all
&lt;/pre&gt;

&lt;p&gt;
Let's define a few convenience functions for common colors, a hydra to quickly select them and bind it to a key for convenience.  While we are at it, we add a menu to Org too.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-yellow&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Highlight region in yellow."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (highlight (region-beginning) (region-end) &lt;span style="color: #008000;"&gt;"Yellow"&lt;/span&gt;))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-blue&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Highlight region in blue."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (highlight (region-beginning) (region-end) &lt;span style="color: #008000;"&gt;"LightBlue"&lt;/span&gt;))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-pink&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Highlight region in pink."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (highlight (region-beginning) (region-end) &lt;span style="color: #008000;"&gt;"Pink"&lt;/span&gt;))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-green&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Highlight region in green."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (highlight (region-beginning) (region-end) &lt;span style="color: #008000;"&gt;"Darkolivegreen1"&lt;/span&gt;))


(&lt;span style="color: #0000FF;"&gt;defhydra&lt;/span&gt; highlighter (&lt;span style="color: #006FE0;"&gt;:color&lt;/span&gt; blue) &lt;span style="color: #008000;"&gt;"highlighter"&lt;/span&gt;
  (&lt;span style="color: #008000;"&gt;"b"&lt;/span&gt; highlight-blue &lt;span style="color: #008000;"&gt;"blue"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"g"&lt;/span&gt; highlight-green &lt;span style="color: #008000;"&gt;"Green"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"p"&lt;/span&gt; highlight-pink &lt;span style="color: #008000;"&gt;"Pink"&lt;/span&gt;)
  &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;define as many special colors as you like.&lt;/span&gt;
  (&lt;span style="color: #008000;"&gt;"s"&lt;/span&gt; (highlight (region-beginning) (region-end) &lt;span style="color: #008000;"&gt;"Lightsalmon1"&lt;/span&gt;) &lt;span style="color: #008000;"&gt;"Salmon"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"y"&lt;/span&gt; highlight-yellow &lt;span style="color: #008000;"&gt;"yellow"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"c"&lt;/span&gt; highlight &lt;span style="color: #008000;"&gt;"Choose color"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"n"&lt;/span&gt; (highlight-note (region-beginning) (region-end) &lt;span style="color: #008000;"&gt;"Thistle"&lt;/span&gt;) &lt;span style="color: #008000;"&gt;"Note"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"N"&lt;/span&gt; highlight-note &lt;span style="color: #008000;"&gt;"Note (c)"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"m"&lt;/span&gt; highlight-mouse-on &lt;span style="color: #008000;"&gt;"Mouse"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"M"&lt;/span&gt; highlight-mouse-off &lt;span style="color: #008000;"&gt;"Mouse off"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"e"&lt;/span&gt; highlight-note-edit &lt;span style="color: #008000;"&gt;"Edit note"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"l"&lt;/span&gt; highlight-list &lt;span style="color: #008000;"&gt;"List highlights"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"r"&lt;/span&gt; highlight-load &lt;span style="color: #008000;"&gt;"Reload"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"S"&lt;/span&gt; highlight-save &lt;span style="color: #008000;"&gt;"Save"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"d"&lt;/span&gt; highlight-clear &lt;span style="color: #008000;"&gt;"Delete"&lt;/span&gt;)
  (&lt;span style="color: #008000;"&gt;"D"&lt;/span&gt; highlight-clear-all &lt;span style="color: #008000;"&gt;"Delete All"&lt;/span&gt;))

(easy-menu-change
 '(&lt;span style="color: #008000;"&gt;"Org"&lt;/span&gt;) &lt;span style="color: #008000;"&gt;"highlighter"&lt;/span&gt;
 '([&lt;span style="color: #008000;"&gt;"Highlight"&lt;/span&gt; highlight]
   [&lt;span style="color: #008000;"&gt;"Highlight (B)"&lt;/span&gt; highlight-blue]
   [&lt;span style="color: #008000;"&gt;"Highlight (G)"&lt;/span&gt; highlight-green]
   [&lt;span style="color: #008000;"&gt;"Highlight (P)"&lt;/span&gt; highlight-pink]
   [&lt;span style="color: #008000;"&gt;"Highlight (Y)"&lt;/span&gt; highlight-yellow]
   [&lt;span style="color: #008000;"&gt;"Highlight note"&lt;/span&gt; highlight-note]
   [&lt;span style="color: #008000;"&gt;"List highlights"&lt;/span&gt; highlight-list]
   [&lt;span style="color: #008000;"&gt;"Delete highlight"&lt;/span&gt; highlight-clear]
   [&lt;span style="color: #008000;"&gt;"Delete highlights"&lt;/span&gt; highlight-clear-all])
 &lt;span style="color: #008000;"&gt;"Show/Hide"&lt;/span&gt;)


(global-set-key (kbd &lt;span style="color: #008000;"&gt;"s-h"&lt;/span&gt;) 'highlighter/body)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
highlighter/body
&lt;/pre&gt;


&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Known limitations&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
The tooltips seem especially fragile, and if there is code that undoes the removal of help-echo from font-lock-extra-managed-props, it seems possible they would easily get lost. I wouldn't use them a lot without a lot of testing. You &lt;i&gt;have&lt;/i&gt; to rely on the hook functions defined to keep the highlights synchronized between the buffer and the external highlight file. If you were to rename a file externally, e.g. in the OS, or with a shell command, then the highlights will be lost unless you also rename the external file.
&lt;/p&gt;

&lt;p&gt;
Highlights are not robust enough to survive refiling an org-mode section from one file to another.  Personally I don't see these as too big a problem; I don't put a lot of value of highlights, but I can see it being pretty annoying to lose them!
&lt;/p&gt;

&lt;p&gt;
Still, if you want to give this a try, you can use the code here: &lt;a href="/media/2015-07-28-A-highlight-annotation-mode-for-Emacs-using-font-lock/highlights.el"&gt;highlights.el&lt;/a&gt; . You should bind the functions to whatever keys you want. Also, it is setup to only work for org-mode. I am not sure what the best hook to use for any file might be. Maybe find-file-hook.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2015 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2015/07/28/A-highlight-annotation-mode-for-Emacs-using-font-lock.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;]]></content:encoded>
    </item>
  </channel>
</rss>
