YASnippet and Babel

Org-mode allows you to use Babel. As it says in the manual: Babel is Org-mode's ability to execute source code within Org-mode documents

Here's a bit of Java, wrapped up in Babel

#+BEGIN_SRC java :classname example
    public class example 
    { 
            public static void main (String args []) 
            { 
                System.out.println("Go Babel!");
            } 
    } 

#+END_SRC

Put the point in the block and

C-c '           to edit the code 
C-c C-c         to run the code

In the past, I never used Babel as often as I should, mainly because I could never quite remember the syntax.

Then I had the idea of adding Babel to YASnippet.

I added the following to my org-mode snippets:

# -*- mode: snippet -*-
# name: jbabel
# key: jbabel
# --
#+BEGIN_SRC java :classname $1
    public class $1 
    { 
            public static void main (String args []) 
            { 
                System.out.println("$0");
            } 
    } 

#+END_SRC

… and now I just have to type jbabel and hit tab to have my Babel block ready to go.

It works with ditaa too. As I could never quite remember all the codes when I needed them, I just put a few of ones I used most frequently in a YASnippet example:

# -*- mode: snippet -*-
# name: ditaa babel 
# key: dbabel
# --
#+begin_src ditaa :file $1.png

/-----------------\
| Things to do    |        +-----+   
| cGRE            |        |{s}  |
| o Cut the grass *-+----->|     |
| o Buy jam       |        |     |
| o Fix car       |        +-----+
| o Make website  |
\-----------------/


#+end_src

Take a look at the header image to see what it looks like when converted.