Extra Markdown Commands for Emacs

Posted by fiddlemath on February 11, 2012

I spend a lot of my time in emacs. But I’ve only recently really started to fiddle with things in emacs lisp. Here’s some twiddling.

I really like Markdown. I write practically everything in Markdown; it’s a wonderful way to just barely organize what should be mostly plain text. I even like the way that plaintext files look in Markdown. Writing in Markdown is like swinging a well-balanced hammer; it’s easy enough to use that it just seems obvious, rather than designed. (This site is just a thin wrapper around a bunch of Markdown files, for instance…)

Anyway, I also rather like the emacs Markdown Mode, but its title and subsection headings don’t expand to underline the entire line of current text. This bothered me, so I did this:

(defun underline (c)
    (let (w)
      (move-end-of-line 1)  
      (setq w (current-column))
      (insert (apply 'concat (make-list w c)))

(defun markdown-under-title ()
  (underline "=")

(defun markdown-under-section ()
  (underline "-")

(add-hook 'markdown-mode-hook
  (lambda () 
    (local-set-key "\C-c\C-tt" 'markdown-under-title)
    (local-set-key "\C-c\C-ts" 'markdown-under-section)

You could argue that I’m being needlessly fiddly. You’d probably be right.