Internal Irreal Links with Emacs

I try to keep a couple of posts in reserve for those days when nothing strikes me as worth writing about. Other times, I may write a series of posts on a related topic and not post them until the entire series is done. Whenever possible, I like to provide internal links to previous posts to provide readers with context. For example, in a series the subsequent posts might have links to the previous posts in the series.

The problem is that those earlier posts haven't been published yet so there's nothing to link to. Fortunately, org2blog inserts the page ID of the post into the org file when it get's pushed to WordPress so I can push the posts to WordPress as drafts and then publish them later. That means that the org file has the page ID of the post so that I can link to it even though it hasn't been published yet. Of course, the post containing the link has to be published after the linked post.

As I've mentioned before, org links have the form

[[url][label]]

so knowing the url, which for Irreal posts is http://irreal.org/blog/?p=ID where ID is the page ID, makes it possible to add links to not yet published posts.

Naturally, I'm much to lazy too do that by hand so I whipped up a bit of Elisp to do it for me:

(defun irreal-post (label id)
  "Make a link to an Irreal post given its ID number and a label."
  (interactive "sLabel: \nsID: ")
  (insert (concat "[[http://irreal.org/blog/?p=" id "][" label "]]")))

Now I just call irreal-post, fill in the label and post ID and the link is inserted. As with most of these little helper functions, it's not a big thing but it does make my life a little easier.

This entry was posted in Programming and tagged , . Bookmark the permalink.

One Response to Internal Irreal Links with Emacs

  1. Jonathan says:

    Couldn't you also just create a link abbreviation for the blog? (See: http://orgmode.org/manual/Link-abbreviations.html )

    #+LINK: irreal http://irreal.org/blog/?p=%s

    At the top of your Org file and then you would just have to use:

    [[irreal:1155][This Entry]]

    It should also work using org-insert-link.

    With a quick look at org2blog it looks like it inserts the ID using #+POSTID as opposed to setting it as a property for the headline, otherwise you could probably use completion to retrieve the ID by finding the headline.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>