Using yasnippet to Reduce Blogging Friction

Every Irreal blog post begins with some header information that tells org2blog the title, category, and tags for the post. These get communicated to WordPress when org2blog exports the post. Those lines look like this:

#+TITLE: Using =yasnippet= to Reduce Blogging Friction
#+CATEGORY: Blogging
#+TAGS: Emacs

There are 862 posts on Irreal at the moment and everyone of them begins with those 3 header lines. That’s a lot of typing, especially with all the capitalization. (Yes, yes, I know all about upcase-word and in fact I type them in lower case and then use 【Meta+b Meta+u】 to capitalize them—it’s still a lot of typing.)

I finally reached the end of the rope and decided that it was past time to install yasnippet so that I could automate that. After some floundering around, I figured out how to get snippets to load with Org Mode and added this snippet:

# -*- mode: snippet -*-
# name: header
# key: bh
# --
#+TITLE: $1
#+CATEGORY: ${2:General}
#+TAGS: $3

Now when I start a post, I begin with bhTab】 and the header skeleton is automatically inserted. I know I’m late to the party on this. Everyone else is already using yasnippet and wondering what took me so long.

All this probably isn’t going to save me huge amounts of time but it does reduce blogging friction a bit so it’s a win. Now that I have yasnippet installed I’ll be looking for other ways to leverage its power.

This entry was posted in Blogging and tagged . Bookmark the permalink.

6 Responses to Using yasnippet to Reduce Blogging Friction

  1. mbork says:

    Just curious: why do you use M-b M-u instead of M– M-u? It is equivalent in case of going back one word, but negative argument for M-u is more efficient in the general case of more words.

    • jcs jcs says:

      I guess because I didn’t think of it. For the header lines there was only one word so it didn’t matter. Happily it doesn’t matter anymore because yasnippet takes care of it for me.

  2. Xavier Garrido says:

    I was not using anymore yasnippet for several reasons but as I am writing more and more stuff with org, I would like to give it another try. Can you share your configuration (write another post ?) because I can not make it working nicely with orgmode . Information are quite deprecated and does not work with melpa version of yasnippet

    • jcs jcs says:

      I loaded yasnippet with ELPA and I’m pretty sure it came from MELPA. My configuration is merely

      (require 'yasnippet)
      (yas-global-mode 1)

      I had to restart Emacs to get it to see the “built-in” snippets. There are no predefined Org Mode snippets but you can define your own (as I did) by adding the directories ~/.emacs.d/snippets/org-mode and adding your custom Org Mode snippets to the org-mode directory

  3. FredTantini says:


    firstly, thank you for your blog. I discover a lot of great stuff thanks to you.
    I don’t write often, but I am lazy, so I wrote a function to start a new post. It asks for a title and opens a new file in the folder I would like to, with the title in the name, and inserts #TITLE/#DATE header :

    (defvar homeblogdir "/data/Donnees/Sites/fredtantini/")

    (defun newPost (title)
    "open a new file in YEAR/MONTH/"
    (interactive "sTitre: ")
    (let* ((tmptitle (replace-regexp-in-string "[ ']" "_" title))
    (year (format-time-string "%Y"))
    (month (format-time-string "%m"))
    (day (format-time-string "%d"))
    (newtitle (downcase (concat year month day "_" tmptitle ".org")))
    (newdir (concat homeblogdir year "/" month "/"))
    (make-directory newdir t)
    (find-file (concat newdir newtitle))
    (insert (concat "#+DATE: \n"))
    (insert (concat "#+TITLE: " title "\n\n"))


    abbrev and yasnippet are things I still have to discover…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>