M-x all-things-emacs

YASnippet Updated – Supports Nested Placeholders and More

July 27th, 2009 by Rob Christie · 4 Comments

YASnippet Dropdown Menu Support

YASnippet, or Yet Another Snippet package just released a new beta with many new features. YaSnippet is a template system for emacs. It allows you to type an abbrevation and then trigger that abbreviation into an expansion in your buffer. Some of the new features are:

  • Nested Placeholders: Nested placeholders allow you to support optional attributes or portions of your snippet. If you don’t need these optional attributes then type C-d and exit out of the snippet. This feature is heavily used in TextMate snippets, and now makes borrowing snippets from TextMate even easier. For example, the snippet below gives you a div tag and optionally allows you to specify your id.
     <div${1: id="${2:someid}"}> $0
  • Menu Grouping: The YASnippets menu now supports logical grouping of snippets under the mode. For example, ruby-mode snippets are now grouped into logical areas such as collections and control structures. I don’t normally like using menus in emacs, but I find the logical grouping in lieu of the long list helpful until I have the snippets memorized.
  • Multiple Prompting Mechanisms: If you have multiple snippets attached to the same tag trigger, then you will get prompted for the snippet you desire. You can specify the desired order for how you want to be prompted by setting the function list in the variable yas/prompt-functions. Some people like menus so you might want to use yas/dropdown-prompt (see the screenshot above), but my current preference is yas/ido-prompt.
  • Easier Snippet Development: When working on a new snippet, you can use the command M-x yas/tryout-snippet or C-c C-t which opens a test buffer and expands your new snippet.
  • Snippets within Snippets: You can now call one snippet while within the expansion of another snippet.

For more info, take a look at the YASnippet documentation.

Tags: misc · snippet

4 responses so far ↓

  • 1 Shoulda Snippets for Emacs — neutron flux // Jul 28, 2009 at 5:09 am

    [...] I have just updated my Shoulda snippets for the Emacs YASnippets templating package. Shoulda is a ruby-based testing framework that consists of test macros, assertions, and helpers added on to the Test::Unit ruby framework. The snippets are based, and in many cases copied from the TextMate Shoulda snippet bundle, and modified where needed to work with the YASnippets package. New features in the recently released 0.6beta of YASnippet allow support for more of the TextMate-based snippets. The new YASnippet functionality is discussed in more detail in a post I did on Emacs Blog. [...]

  • 2 y.chaouche // Sep 15, 2009 at 2:25 am

    M-/ would do for me.

  • 3 Sporter // May 9, 2010 at 6:23 pm

    [...] I have just updated my Shoulda snippets for the Emacs YASnippets templating package. Shoulda is a ruby-based testing framework that consists of test macros, assertions, and helpers added on to the Test::Unit ruby framework. The snippets are based, and in many cases copied from the TextMate Shoulda snippet bundle, and modified where needed to work with the YASnippets package. New features in the recently released 0.6beta of YASnippet allow support for more of the TextMate-based snippets. The new YASnippet functionality is discussed in more detail in a post I did on Emacs Blog. [...]
    +1

  • 4 My Tech Guru » sdgf // Sep 12, 2010 at 12:51 pm

    [...] July 27th, 2009 by Rob Christie ยท 3 Comments [...]