2

In yasnippet's manual expansion of snippet inside a snippet is mentioned but I wasn't able to achieve this. Can someone tell me what I'm doing wrong ?

I have two snippets :

# -*- mode: snippet -*-
# name: newhist
# key: newhist
# expand-env: ((yas-triggers-in-field 't))
# --
${1:-- }----------------------------------------------------------------------------
${2:_head}$2
$1Objet        : ${4:Objet}$0

and

# -*- mode: snippet -*-
# name: _head
# key: _head
# --
${1:-- }Auteur       : `(and (boundp 'user-ngram) user-ngram)`
$1Date         : `(capitalize (format-time-string "%d/%m/%Y"))`
$1Version      : `(and (boundp 'global-release) global-release)`.00.${2:0001}$0

And I expect something like that after expansion :

-- ----------------------------------------------------------------------------
-- Auteur       : me
-- Date         : 29/09/2016
-- Version      : 513.00.0001
-- Objet        : Objet

But all I get is :

-- ----------------------------------------------------------------------------
_head_head
-- Objet        : Objet
1

2 Answers 2

4

you need to add this to your yasnippet config in .emacs to enable nested triggering of snippets

(setq yas-triggers-in-field t)

2
  • I try to do that but it doesn't work. Sep 30, 2016 at 10:17
  • 1
    @Pierre You have to move point to the end of _head and then press TAB.
    – npostavs
    Sep 30, 2016 at 14:11
1

An alternative to yas-triggers-in-field is to bind yas-expand to a key (I use C-<tab>), and then use this key to expand when you're already in a snippet.

It has the benefit that you'd only get expansion when you want to, TAB would by default not perform expansion when you're already in a snippet (unlike using yas-triggers-in-field).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.