Adding Yasnippets Snippets

yasnippet is an Emacs package which turns things like

tf<TAB>

into

import unittest
from test_file import *



if __name__ == '__main__':
    unittest.main()

From there, further <TAB> strokes scroll through elements of the snippet which should be renamed/specified. It’s a nice way to reduce mechanical repetitive work.

I want to create yasnippets for org mode because new projects should include the following (which I normally ignore):

  • purpose
  • motivation
  • success definition
  • and the first next action

Here’s a good reference for snippet writing and organization.

snippets are in \~/.emacs.d/elpa/yasnippet-20150212.240/snippets, e.g.

ls ~/.emacs.d/elpa/yasnippet-20150212.240/snippets/org-mode | head -n 5

They are defined with the following syntax

cat ~/.emacs.d/elpa/yasnippet-20150212.240/snippets/org-mode/code
# -*- mode: snippet -*-
# name: code
# key: code
# --
#+begin_${1:lang} ${2:options}
$0
#+end_$1

But user snippets should be stored elsewhere.

snipdir="/home/joth/.emacs.d/snippets/org-mode"
if [ ! -d "$snipdir" ]; then
  echo "Making dir $snipdir"
  mkdir -p "$snipdir"
else
  ls -al "$snipdir"
fi

~/.emacs.d/snippets

And create .emacs.d/snippets/ in my dotfiles repo

mkdir -p ~/dotfiles/emacs/.emacs.d/snippets/org-mode

There, create a file, project, and add this to the file

# -*- mode: snippet -*-
# name: project
# key: proj
# --
** ${0:lang} ${1:options}
*** Overview
Motivation
  ${2:motivation}

Objective
  ${3:objectives}

Success Vision
  ${4:objectives}

*** NEXT ${5:nextaction}
    ${6:nextdescr}

And stow (symlink the file to the snippets dir) it.

cd /home/joth/dotfiles
stow -v emacs

Now proj<TAB> kicks off a new project as shown below.

** TODO projectname [/]
*** Overview
    *Motivation*
    why bother

    *Objective*
    SMART GOALS

    *Success Vision*
    how to know when I'm done

*** NEXT what's next
    nextdescr

Go Top
comments powered by Disqus