enchanter
enchanter

Reputation: 924

How to write a snippet which content is depended on some expanded field?

I try to write a snippet to achieve this:

Expandable field:

<something I don't know how to write>(my_class#($1))

Expected result:

If $1 is empty:

`my_factory_utils(my_class)

If $1 is not empty:

`my_factory_param_utils(my_class#(<$1 content>))

Could anyone give me a clue about how could I do that?

Thanks

Upvotes: 1

Views: 79

Answers (1)

event_jr
event_jr

Reputation: 17707

You want to use transformations on mirrors

# -*- mode: snippet -*-
# name: testsnip
# key: testsnip
# --
${1:$(if (zerop (length yas-text)) "my_factory_utils" "my_factory_param_utils")}(my_class${1:$(if (zerop (length yas-text)) "" "#")}$1)

See docs.

Upvotes: 1

Related Questions