Search code examples
emacscode-snippetsyasnippet

How can I expand a snippet within a snippet using YASnippet?


At the YASnippet site I noticed the following description of yas/triggers-in-field :

If non-nil, yas/next-field-key can trigger stacked expansions, that is a snippet expansion inside another snippet expansion. Otherwise, yas/next-field-key just tries to move on to the next field.

I'm not clear how to make this happen.

I assumed that after I set: #expand-env: ((yas/triggers-in-field #t)), whenever I typed an abbrev in a field and pressed Tab it would expand, however that's not the case.


Solution

  • yas/triggers-in-field is a variable. Per default it is set to nil.

    Its docstring says:

    If non-nil, `yas/next-field-key' can trigger stacked expansions.

    Otherwise, `yas/next-field-key' just tries to move on to the next field

    Thus, to enable stacked expansions you have to set the variable to a non-nil value such as t. If you want this setting permanent put the following in your .emacs:

    (setq yas/triggers-in-field t); Enable nested triggering of snippets
    

    You can read about other customizable YASnippet variables