Posting to Dreamwidth from emacs org-mode, revised and expanded edition

Back in October I created a function to post to DW straight from Emacs, and I’ve made most of my posts using it since. Several months later I’ve finally refactored the code and made several improvements to integrate it with various DW features, and while I still know nothing about Lisp, I’m quite pleased with how this has ended up.

There are now two functions I can call on the selected text. dwdraft just exports the text as HTML, strips everything that’s not inside the <body> element, and copies it to the clipboard. This is in case I want to preview something before I post it (I can preview using the normal org HTML export, but that doesn’t render cut tags or user mentions properly), or if I want to post to a comm (er, haha remember those) instead of to my own journal.

The second function is my magnum opus, dwpost. This is how I now make my posts. First I select the text of the entry and call dwpost. It prompts me for the following:

There are two things that are not prompted for, but instead ascertained by other means:

The intersection of the Emacs/Dreamwidth Venn diagram is probably quite sparsely populated, but just in case anyone comes across this post and actually wants to run the function, it can be adapted to other users pretty easily. You need to have mu4e set up as this relies on the email posting method. Grab the dwpost.el file from my git repository, put it in your load-path, and customise the variables at the top of the file:

The iconfile is a file containing an Emacs function that selects the icon for the post. Mine currently looks like this:

(defun iconchoose ()
  (cond
   ((string-match-p "\\bauron[^\\/]\\b" (buffer-substring (point-min) (point-max))) (setq icon "auron"))
   ((string-match-p "\\bauron\\/braska\\b" (buffer-substring (point-min) (point-max))) (setq icon "auron/braska"))
   ;; several more lines here but you get the idea
   ((string-match-p "\\bworld of ruin\\b" (buffer-substring (point-min) (point-max))) (setq icon "world of ruin"))))

So for each icon keyword, there should be an instance of the string-match-p function, with the keyword as the first argument (specified as a whole word using regex) and also as the value of the icon variable. Basically this, for each keyword you have:

((string-match-p "\\bKEYWORD\\b" (buffer-substring (point-min) (point-max))) (setq icon "KEYWORD"))

That’s it!

Want to respond to this? Want to see other people’s responses?