Yankpad 1.3

Keywords and function calls

Edit: Added description of results tag.

Yankpad has some new features since my last post about it. One thing that I missed from YASnippet was the ability to write a keyword into a buffer, press a key, and a specific snippet bound to that keyword would insert itself1. This can now be done with Yankpad by writing a snippet named something like keyword: Snippet name, and then the command yankpad-expand can be used to replace the keyword with the snippet.

The other new feature is the ability to use Yankpad in order to /trigger functions/2. You can either name a snippet into an emacs-lisp function, which will then be triggered when “inserting” the snippet, or you can have an org-mode source block inside the snippet and the source block code will be executed when inserting the snippet. To use this functionality you put the tag func into the snippet title. The func tag does not insert any text into the buffer, it just triggers the function for side effects. If you want to insert the output as text, use the results tag instead.

Here’s an example of how you can use the new features:

* Blog
** header: Insert blog header

   #+TITLE:$1
   #+SUBTITLE:$2
   #+DATE:[`(insert (format-time-string "%Y-%m-%d"))`]

   $0 

** section: Insert a new section

   #+BEGIN_section
   _$1_ $0
   #+END_section

** Copy images      :func:

   #+BEGIN_SRC emacs-lisp
     (copy-directory "~/blog/org/images" "~/blog/published/images")
   #+END_SRC

** Insert number of blogposts    :results:

   #+BEGIN_SRC emacs-lisp
     (length (directory-files "~/blog/org" nil "\\.org"))
   #+END_SRC

Footnotes:

1

In YASnippet this is done by specifying a keyword, by putting # key: keyword in the heading of the snippet file.

2

Say that you have a shell script to copy files between different folders, specific for your current project, for instance.