2

I'm looking for a way to write a snippet that would let me include another snippet. Here is an example of a snippet for a python function:

def test(args):
    ${1:code here}
    $(insert-snippet "not_implemented_exception")

In the example, I would like to first write some contents to the python function in field #1, then hit TAB. Hitting TAB should take me to the lisp bit, where I may choose to expand the snippet with the name "not_implemented_exception".

I tried reading the source code but am very new to lisp, so I found nothing of use.

sp3ctum
  • 429
  • 6
  • 9
  • possible duplicate of [How can I expand a snippet within a snippet using YASnippet?](http://stackoverflow.com/questions/9556922/how-can-i-expand-a-snippet-within-a-snippet-using-yasnippet) – Tyler Nov 17 '12 at 03:09

1 Answers1

1

I think you could just make the text "not_implemented_exception" the last tabstop, so you can press TAB one more time to expand it.

def test(args):
    ${1:code here}
    not_implemented_exception$0

In case you don't want to put the snippet at the end, you can enable nested snippet by

(setq yas-triggers-in-field t)
tungd
  • 14,467
  • 5
  • 41
  • 45
  • Seems to work, with a limitation that it only works for the last field. I tried changing the last line to ${2:not_implemented_exception$3} but yas-next-field does not expand my exception snippet. I wonder what could be wrong. – sp3ctum Nov 18 '12 at 10:28
  • There's some change in yasnippet recently, you should try `yas-next-field-or-maybe-expand` (with `yas-triggers-in-field` on) instead – tungd Nov 19 '12 at 03:26
  • Sorry I didn't read your comment through. If you want to make `not_implemented_exception` a place holder it needs to be `${2:not_implemented_exception$0}`. Tab stop `$0` will exit the first snippet so it can expand the next one. If you want to use stacked snippet expand then see my previous comment. Personally I find it confusing so I don't use it. – tungd Nov 19 '12 at 03:31
  • `yas-triggers-in-field` is set to `t`, but `yas-next-field-or-maybe-expand` still jumps to the next snippet when applied with `${2:not_implemented_exception$3}`. This happens at field #3. Could this be a misconfiguration? Here is all my [config](http://hpaste.org/77952) on yasnippet. – sp3ctum Nov 20 '12 at 06:30
  • 1
    It could be a bug or something, you can try contact the author on Github. Honestly I used this feature only a few times before. – tungd Nov 21 '12 at 15:54
  • Thanks, I'll try asking the author on Github. – sp3ctum Nov 22 '12 at 07:34