<?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>Drag images and files onto org-mode and insert a link to them</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2015/07/10/Drag-images-and-files-onto-org-mode-and-insert-a-link-to-them</link>
      <pubDate>Fri, 10 Jul 2015 16:11:43 EDT</pubDate>
      <category><![CDATA[video]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">PCVKpOLHIsiYdZGF1Zkux2U37r4=</guid>
      <description>Drag images and files onto org-mode and insert a link to them</description>
      <content:encoded><![CDATA[


&lt;p&gt;
I want to drag and drop an image onto an org mode file and get a link to that file. This would be used for finding images in Finder, and then dragging them to the Emacs buffer. There is &lt;a href="http://orgmode.org/cgit.cgi/org-mode.git/plain/contrib/lisp/org-download.el"&gt;org-download.el&lt;/a&gt; which looks like it should do something like this too, but it did not work out of the box for me, and I want to add a few wrinkles to it. For a simple drag-n-drop, I just want the link to appear. With ctrl-drag-n-drop I want to add an attr_org line to set the image size, add a caption line, insert the image at the beginning of the line where the mouse cursor is, put the cursor on the caption line and then refresh the inline images in org-mode so the image is immediately visible.
&lt;/p&gt;

&lt;p&gt;
While we are at let us also make it possible to drag file links onto org-files, instead of having the files open. Again, for a simple drag-n-drop, I want a link inserted. For ctrl-drag-n-drop we open the file, and for Meta (alt) drag-n-drop, we insert an attachfile link. You can also define s-drag-n-drop (Super/command) and C-s and M-s drag-n-drop if you can think of things to do with that.
&lt;/p&gt;

&lt;p&gt;
Here is the code to make those things happen. Or watch the video: &lt;a href="https://www.youtube.com/watch?v=ahqKXbBVjpQ"&gt;https://www.youtube.com/watch?v=ahqKXbBVjpQ&lt;/a&gt; 
&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;my-dnd-func&lt;/span&gt; (event)
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt; &lt;span style="color: #008000;"&gt;"e"&lt;/span&gt;)
  (goto-char (nth 1 (event-start event)))
  (x-focus-frame nil)
  (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((payload (car (last event)))
         (type (car payload))
         (fname (cadr payload))
         (img-regexp &lt;span style="color: #008000;"&gt;"&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;(&lt;/span&gt;&lt;span style="color: #008000;"&gt;png&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;|&lt;/span&gt;&lt;span style="color: #008000;"&gt;jp[e]?g&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;)&lt;/span&gt;&lt;span style="color: #008000;"&gt;\\&amp;gt;"&lt;/span&gt;))
    (&lt;span style="color: #0000FF;"&gt;cond&lt;/span&gt;
     &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;insert image link&lt;/span&gt;
     ((&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt;  (eq 'drag-n-drop (car event))
            (eq 'file type)
            (string-match img-regexp fname))
      (insert (format &lt;span style="color: #008000;"&gt;"[[%s]]"&lt;/span&gt; fname))
      (org-display-inline-images t t))
     &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;insert image link with caption&lt;/span&gt;
     ((&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt;  (eq 'C-drag-n-drop (car event))
            (eq 'file type)
            (string-match img-regexp fname))
      (insert &lt;span style="color: #008000;"&gt;"#+ATTR_ORG: :width 300\n"&lt;/span&gt;)
      (insert (concat  &lt;span style="color: #008000;"&gt;"#+CAPTION: "&lt;/span&gt; (read-input &lt;span style="color: #008000;"&gt;"Caption: "&lt;/span&gt;) &lt;span style="color: #008000;"&gt;"\n"&lt;/span&gt;))
      (insert (format &lt;span style="color: #008000;"&gt;"[[%s]]"&lt;/span&gt; fname))
      (org-display-inline-images t t))
     &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;C-drag-n-drop to open a file&lt;/span&gt;
     ((&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt;  (eq 'C-drag-n-drop (car event))
            (eq 'file type))
      (find-file fname))
     ((&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; (eq 'M-drag-n-drop (car event))
           (eq 'file type))
      (insert (format &lt;span style="color: #008000;"&gt;"[[attachfile:%s]]"&lt;/span&gt; fname)))
     &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;regular drag and drop on file&lt;/span&gt;
     ((eq 'file type)
      (insert (format &lt;span style="color: #008000;"&gt;"[[%s]]\n"&lt;/span&gt; fname)))
     (t
      (&lt;span style="color: #ff0000; font-weight: bold;"&gt;error&lt;/span&gt; &lt;span style="color: #008000;"&gt;"I am not equipped for dnd on %s"&lt;/span&gt; payload)))))


(define-key org-mode-map (kbd &lt;span style="color: #008000;"&gt;"&amp;lt;drag-n-drop&amp;gt;"&lt;/span&gt;) 'my-dnd-func)
(define-key org-mode-map (kbd &lt;span style="color: #008000;"&gt;"&amp;lt;C-drag-n-drop&amp;gt;"&lt;/span&gt;) 'my-dnd-func)
(define-key org-mode-map (kbd &lt;span style="color: #008000;"&gt;"&amp;lt;M-drag-n-drop&amp;gt;"&lt;/span&gt;) 'my-dnd-func)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
my-dnd-func
&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;

&lt;p&gt;
&lt;a href="/media/2015-07-10-Drag-images-and-files-onto-org-mode-and-insert-a-link-to-them/jkitchin.json"&gt;jkitchin.json&lt;/a&gt; 

&lt;/p&gt;

&lt;p&gt;
&lt;img src="/media/2015-07-10-Drag-images-and-files-onto-org-mode-and-insert-a-link-to-them/Au-icosahedron-3.png"&gt; &lt;/p&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/10/Drag-images-and-files-onto-org-mode-and-insert-a-link-to-them.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>
    <item>
      <title>Acronym minor mode for Emacs</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2015/07/09/Acronym-minor-mode-for-Emacs</link>
      <pubDate>Thu, 09 Jul 2015 08:04:40 EDT</pubDate>
      <category><![CDATA[tooltip]]></category>
      <category><![CDATA[emacs]]></category>
      <category><![CDATA[video]]></category>
      <guid isPermaLink="false">vt7mEa2on8CD1Tjm4o_qa0Q0LKY=</guid>
      <description>Acronym minor mode for Emacs</description>
      <content:encoded><![CDATA[



&lt;p&gt;
Three letter acronyms (TLA) are pretty common, as are other kinds of acronyms, e.g. ferromagnetic (FM), anti-ferromagnetic (AFM), National Security Agency (NSA), even &lt;a href="https://www.gnu.org/fun/jokes/gnuemacs.acro.exp.html"&gt;Escape-Meta-Alt-Control-Shift&lt;/a&gt; (EMACS) etc&amp;#x2026; in technical documents. As you get away from the definition, it can get hard to remember what they are, so here we develop a minor mode that will put a tooltip over acronyms that hopefully shows what they mean.
&lt;/p&gt;

&lt;p&gt;
You can see this in action here: &lt;a href="https://www.youtube.com/watch?v=2G2isMO6E2c"&gt;https://www.youtube.com/watch?v=2G2isMO6E2c&lt;/a&gt; 
&lt;/p&gt;

&lt;p&gt;
When we turn the mode on, it will scan the buffer looking for an acronym pattern, deduce its likely meaning, and put tooltips on every subsequent use of the acronym. The pattern we will look for is a sequence of uppercase letters surrounded by parentheses. We will assume that if we find N uppercase letters, that the previous N words contain the definition of the acronym. This is pretty approximate, but it is not likely to be that wrong. Then, we will use button-lock to put the tooltips on all subsequent instances of acronyms. We don't want flyspell interfering with the tooltips, so we remove the overlays if they are there.
&lt;/p&gt;

&lt;p&gt;
Unlike previous examples where we just use button-lock, here we wrap the feature into a minor mode that you can turn on and off. Note, you cannot add new acronyms and have them have tooltips. You have to refresh the buttons.
&lt;/p&gt;

&lt;p&gt;
Here is the minor mode code. We use the interesting rx package to build the regular expression. It is more verbose, but a little easier to read than a straight regexp like (concat "\\&amp;lt;" (match-string 1) "\\&amp;gt;") in my opinion.
&lt;/p&gt;

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

&lt;pre class="src src-emacs-lisp"&gt;(make-variable-buffer-local
  (&lt;span style="color: #0000FF;"&gt;defvar&lt;/span&gt; &lt;span style="color: #BA36A5;"&gt;*acronym-buttons*&lt;/span&gt; '() &lt;span style="color: #036A07;"&gt;"list of acronym buttons"&lt;/span&gt;))

(&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;rx&lt;/span&gt;)

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-acronyms&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
    (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((case-fold-search nil))
      (goto-char (point-min))
      (&lt;span style="color: #0000FF;"&gt;while&lt;/span&gt; (re-search-forward &lt;span style="color: #008000;"&gt;"(&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;(&lt;/span&gt;&lt;span style="color: #008000;"&gt;[A-Z]+&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;)&lt;/span&gt;&lt;span style="color: #008000;"&gt;)"&lt;/span&gt; nil t)
        (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; flyspell-mode
          (flyspell-delete-region-overlays (match-beginning 1)
                                           (match-end 1)))
        (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((acronym (match-string 1))
               (p (point))
               (definition (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
                             (goto-char (match-beginning 1))
                             (backward-word (length acronym))
                             (buffer-substring (point) p))))
          (add-to-list '*acronym-buttons*
                       (button-lock-set-button
                        (&lt;span style="color: #0000FF;"&gt;rx&lt;/span&gt; word-start (eval (match-string 1)) word-end)
                        nil
                        &lt;span style="color: #006FE0;"&gt;:help-echo&lt;/span&gt; definition)))))))


(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;remove-acronym-buttons&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;dolist&lt;/span&gt; (button *acronym-buttons*)
      (button-lock-unset-button button))
  (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; *acronym-buttons* '()))


(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;refresh-acronyms&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Refresh acronym tooltips in buffer."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (remove-acronym-buttons)
  (highlight-acronyms))


&lt;span style="color: #8D8D84;"&gt;;;;&lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;###&lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold; font-style: italic;"&gt;autoload&lt;/span&gt;
(&lt;span style="color: #0000FF;"&gt;define-minor-mode&lt;/span&gt; &lt;span style="color: #006699;"&gt;acronym-mode&lt;/span&gt;
  &lt;span style="color: #036A07;"&gt;"Put definitions on acronyms."&lt;/span&gt;
  &lt;span style="color: #006FE0;"&gt;:lighter&lt;/span&gt; &lt;span style="color: #008000;"&gt;" AM"&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; acronym-mode
      (highlight-acronyms)
    (remove-acronym-buttons)))


(&lt;span style="color: #0000FF;"&gt;provide&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;acronym-mode&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
acronym-mode
&lt;/pre&gt;

&lt;p&gt;
There it is. Now any time we have an acronym like EMACS we can mouse over it, or type C-h . on the acronym to see how it was previously defined. If you don't like it, you can turn it off!
&lt;/p&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/09/Acronym-minor-mode-for-Emacs.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>
