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:
org-export
.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:
dw-username
– your Dreamwidth username.dw-pin
– the PIN you set for DW “mobile posting”.dw-defaultlocation
– if you want to change the house emoji to something else, go ahead.dw-iconfile
– the path to the file in which your list of icons is stored; more about this below.lastfm-login
– this is set to true or false (in Lisp, t
or nil
, which I maintain is ridiculous). If true, it’ll grab your scrobbles from last.fm (and you’ll need to install the lastfm.el package); if false, it’ll prompt manually for music as it does for the title, tags, etc.lastfm-user
– your last.fm username; this line can be deleted if you’ve gone for the manual music prompting option.
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!