It’s odd how discovering some small Emacs feature can completely change your workflow. Yesterday, I wrote about counsel-git-grep and how it made searching entire repositories easy. Almost without me being aware of it, it changed my blogging workflow and allowed me to bring one more task into Emacs.
When writing a post, I often want to refer to one or more older posts that are related in some way. My normal way of doing that was to use the search feature of Irreal to locate the posts and then leave them up in my browser so I could review them and then link to them from within Emacs. That meant I had to leave Emacs to interact with the blog itself and, of course, it meant I had to be on-line.
That procedure’s a bit silly because I write my posts in Org mode and have the original source immediately available to me in Emacs. Still, searching the source wasn’t really that convenient and I’d end up with a lot of buffers open I didn’t need. Counsel-git-grep
changed that. I do the search and can see the results in the minibuffer. I can open the one(s) I want easily, review the contents, and then link to them from within my current post.
I use two methods for linking to the old posts. The first makes use of irreal-link
, shown below, to add a link without bothering to open the old post in Irreal. When org2blog
publishes a new blog post, one of the things it does is put the page ID into the source buffer. That makes it easy to link to the post by referring to its ID (see the irreal-link
code). Notice that there’s no browser interaction involved with this process at all.
Sometimes, it’s convenient to have the actual page up in the browser. For those occasions, I use irreal-by-id
, which opens the page in the browser from within Emacs. I send the results to Safari but I could just as easily open it in EWW. Since it is open in Safari, I can add the link in the way I described in the “link to them from with Emacs” link above.
Here’s the code for irreal-link
and irreal-by-id
. As you can see they are trivial but make linking to the old post easy and convenient.
(defun irreal-link (id label) "Make a link to an Irreal post given its ID number and a LABEL." (interactive "sID: \nsLabel: ") (insert (concat "[[http://irreal.org/blog/?p=" id "][" label "]]"))) (defun irreal-by-id (id) "Open an Irreal page by its page ID." (interactive "sID: ") (browse-url (concat "http://irreal.org/blog/?p=" id)))