2

I'm using some snippet I found from the internet.

And I encounter lots of error when using them.

for example,

printf ("${1:%s}\\n"${1:$(if (string-match "%" text) "," "\);")
}$2${1:$(if (string-match "%" text) "\);" "")}

This is a printf snippet for c mode. But it always gave me [yas] elisp error! Symbol's value as variable is void: text

So is there any bug in this piece of code or bug at somewhere else? If so, how can I debug it?

LoveProgramming
  • 2,121
  • 3
  • 18
  • 25
  • Is the percentage a special character that needs to be escaped? – lawlist Jan 30 '14 at 02:48
  • yas is clearly evaluating part of the snippet as an elisp expression -- it looks as if the syntax is `$(expr)` -- and there is no variable `text` when `(string-match "%" text)` is evaluated. Why did you use that variable name, and what do you believe it should be set to? A pointer to some documentation would probably be good. – phils Jan 30 '14 at 03:52

1 Answers1

2

It seems that the snippet you are using was written for older versions of yasnippet because the variable text was renamed to yas-text in newer versions, try replacing text with yas-text in the snippet.

I case you are not aware you can use yas/tryout-snippet to quickly try out snippets while editing them.