Editing blog posts in Emacs

I write everything on this site in emacs of course. I finally got around to organizing the myriad Emacs Lisp hacks I use into a common file: presenting posts.el.

Features:

  • Commands for converting Markdown/Textile into HTML.
  • Key bindings for the same.
  • Rudimentary (and buggy) Markdown syntax highlighting for emacs.
  • Functions for easily typing some unicode characters (via).

It’s not pretty, so I don’t think new emacs users to try this.

Setup/Usage:
Save the file, add to your site-lisp folder or something, and put

(require 'posts)

in your .emacs file. All the customizations will be available whenever you open a .post file. Sorry, I can’t explain it better than this.

I have defined some variables at the beginning: markdown-command-string, textile-command-string etc. Edit those as per your system config. I know I should have used defcustom there, but it seemed like too much work.

Once you’ve done that, you can type M-x markdown or M-x textile to convert the current region/buffer into HTML. You can type M-x markdown-preview to convert your current buffer/region into HTML and then preview it. The previewing function is courtesy Jason.

As using M-x gets tiring soon, so some key bindings to make you happy:

  • C-c m runs Markdown
  • C-c p runs Markdown and previews it
  • C-c s runs ispell
  • ` runs a slightly customized version of ong-insert-special. I use the ` key instead of the recommended apostrophe, it just suits me better.

Markdown syntax highlighting:
I got tired waiting for a true Markdown mode to be available, so I cobbled together a hack that uses html-mode as a base, and some additional rules to highlight Markdown syntax. Using html-mode as a base means that any inline HTML code I use will be properly displayed.

These rules are very basic, and error-prone. I just coded them yesterday, and haven’t really fine-tuned the regular expressions. Anyway, here is a screenshot of what it looks like for now, with the bugs and all, in the color theme I use:

Markdown syntax highlighting in Emacs

It should work (somewhat) with any other theme as well. I haven’t really that though.

This is not a real mode. I don’t know Emacs Lisp at all, and this is the result of my experimentation. I hope someone comes up with a better solution, so I can switch to it.