All Together Now: Markdown Mode

Everything in one place. I love being able to manage my website through the command line and Emacs, but what if I want to write posts from my laptop? What if I just want to write a post without having to upload it to the server under published: false to deploy when I’m ready? I decided to look into if anyone had attempted writing their posts in Emacs away from a computer that has an established Ruby/Octopress-environment. Most bloggers were Mac owners. They wrote their posts in iA Writer, then deposited their posts to Dropbox for deployment to Github. So what was left for us lowly non-mac users? Turns out, there’s Markdown-Mode for Emacs. Hooray!

Download Markdown Mode

First, download the Mode from Jason Blevin’s website. Next, unpack the tarball with tar -xzvf Move it to your .emacs.d folder with the mv command, as in mv /Downloads/markdown-mode-2.0 ~/.emacs.d Now check if its really there by going into your .emacs.d file and entering ls Sometimes mv is sneaky and just renames the file instead of moving it around if you’re a new user. Next you have to use mv for its other pupose, and rename the markdown folder to markdown-mode for simplicity’s sake.

Add to your .emacs file

Here’s your code!

;add markdown mode to the path
(add-to-list 'load-path "~/.emacs.d/markdown-mode")
(autoload 'markdown-mode "markdown-mode"
  "Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))

Did it work? Do a test run with M-x load-file .emacs, or open a new file with C-x C-f test.markdown. You will see a new file in the mode (Markdown)!

Getting Markdown to parse in Emacs

Of course, you’re not out of the woods yet. Emacs has no idea what to do with the Markdown file. If you try to compile your new document with C-c C-c m then you get a lovely error message that says /bin/bash: markdown: command not found. Well, first you have to install rdiscount with gem gem install rdiscount (You can learn how to set up a ruby environment from Lennu.net). Now that you’ve installed Rdiscount, go back into Emacs and enter in the buffer M-x customize-mode hit Return, then markdown-mode From there a GUI appears. Search for Markdown Command: and enter in rdiscount. Save your changes, and test out your markdown-mode compilation again.

Creating Your Posts in Emacs + Dropbox

If you want to type your posts directly into dropbox, type within emacs C-x C-w This is the Save As feature, and will allow you to save your file anywhere on your computer. Save it in /Dropbox if you’d like, and create a new file following the standard year-month-day-title extension as a .markdown file.

Happy writing!