few problems, approaches and solutions

twiddling with weblogger.el (emacs + wordpress)

Although wordpress.com provides a feature rich editor, I prefer writing my posts in emacs. Edit (in emacs), copy, paste (to wordpress) is possible, but more interesting would be to post from withing emacs. Thats were weblogger.el comes in. Here is some help on how to set it up. But still, I was a little uncomfortable with the default configuration. For example, I am little more adapt to using \C-x\C-s in emacs. And each time I did this, the post would be published and the buffer closed. I would have to again fetch the blog entries (\M-x RET weblogger-fetch-entries).

This post is about the hacks made into weblogger.el to suit my needs. If it helps you, feel free1 to download the file from here. Rename it with extension .el.

Essentially what I wanted was for the modes to save the post (either published or as a draft), without closing the buffer. The change for this seemed to be simple, just remove the (burry-buffer), from the respective functions. The exception was that if we started with a new post, then saving the buffer would sent it to the server, but the buffer itself wouldn’t be updated with the information for the new post created at the server. Thus I changed the code to look for this exception while saving. If the post is new, then simply do (weblogger-fetch-entries).

Few more changes to customizing my editing experience. I like editing/programming in auto-fill mode. But available width for posts in wordpress themes usually wouldn’t match with that of auto-fill mode. The alternative was longlines mode. It allowed editing with word wrapping (soft newlines), and also didn’t introduce any (hard) new lines. Unfortunately, in this mode also, saving a post caused the post to show up all the soft newlines as newlines. What I needed was some way to turn off the longlines-mode before saving, and then again turn it on, if the buffer is not to be buried. I have introduced two new hooks, one to be run before saving the draft, and the other to be run afterwords, if the buffer is not to be closed.

Here are the weblogger related initializations from my .emacs

(add-hook 'weblogger-start-edit-entry-hook
	  (lambda()
	    (flyspell-mode 1)
	    (flyspell-buffer)	; spell check the fetched post
	    (longlines-mode)))
(add-hook 'weblogger-publish-entry-hook
	  (lambda()
	    (when longlines-mode
	      (longlines-mode-off))))
(add-hook 'weblogger-publish-entry-end-hook
	  (lambda()
	    (longlines-mode)))

(weblogger-select-configuration "my configuration name" )

Two tools of trade that helped me the most were eval-buffer and \C-h f.

  • \M-x eval-buffer evaluates a buffer, so that you don’t have to restart emacs after each change, to see its effects.
  • Emacs lisp is a self documenting system, where you provide the description of the function in the function itself. \C-h f <name of function> shows the description of the function.

Thats how I tried to understand the code structure, and various library functions. To know the key bindings and command options, try \C-h a weblogger. Its fairly easy to change the key binding by editing the weblogger.el file.

I am fairly novice at emacs and emacs lisp. So please do consider the chances of disk formatting bugs lurking in my code.

About these ads

5 responses to “twiddling with weblogger.el (emacs + wordpress)

  1. Pingback: Blogging from Emacs « Chopmo’s Weblog

  2. Pingback: Updated wordpress.com blogs from emacs using weblogger.el « Alexander's particulars

  3. ncalexan June 10, 2009 at 2:48 am

    So far, so good for me. You might want to add a (require ‘longlines) — without I get symbol not found errors on longlines-mode-off.

  4. Pingback: Wordpress Blogging from Emacs @ SystemICs Blog

  5. Pingback: Wordpress Blogging from Emacs | The CoVerification Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: