2

I have a yasnippet that is conflicting with multiple-cursors because it is not exiting immediately. When multiple-cursors is not active, I would like the snippet to pause and permit me to enter the data. Can I have an example, please, of a yasnippet that uses some elisp conditions:

For example,

(if mc-mode
  \hspace*{$0}
  \hspace*{$1})
2

You can use the #condition directive to provide an elisp predicate. The snippet will only be expanded when the condition code you provide evaluates to non-nil. So, you could simply add this to your snippet:

#condition: (mc-mode)
  • I interpreted, perhaps incorrectly (?), the term expand to mean that yasnippet does what it is supposed to do. And, that the #condition is designed to prevent yasnippet from functioning if the condition is satisfied. Does the #condition affect the whole kitten-kaboodle (i.e., nothing at all should happen), or just whether to pause at position $1 to wait for user input? – lawlist Dec 18 '14 at 5:55
  • If the condition returns nil, the snippet will not be eligible for expansion. So, when #condition is nil, yas-expand behaves as if the snippet didn't exist. What it does instead of snippet expansion(assuming no other snippet is a match either) depends on the fallback behaviour. – Pradhan Dec 18 '14 at 6:02
1

Yasnippet will accept elisp (including, but limited to conditions) provided that it is surrounded by backticks. In the following example, $0 will cause the snippet to automatically exit when mc-mode is t; whereas, $1 will cause a pause at that location for user input when mc-mode is nil.

`(if mc-mode
    "\\\\hspace*{$0}"
    "\\\\hspace*{$1}")`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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