I want to define a yasnippet for shell-script
mode that would insert a chunk of text whose content depends on the setting of the sh-shell
variable.
Since the possible different text insertions are several lines long, and are quite different from each other, so doing this with conditional fields of the form
${N:`(case sh-shell (zsh "foo")
(bash "bar")
(sh "baz")
(t "frobozz"))`}
...would all but eliminate the convenient formatting one this sort of template for.
EDIT: To clarify: the code above is not useful to me, because I need to insert multi-line formatted text, not little, one-word strings like "foo"
, "bar"
, etc.
If I were to use an unholy mix of Elisp and bash
to represent what I'm looking for, this is how I'd represent it:
`(case sh-shell (zsh <<EOZSH)
zsh version
of
snippet
looks
like
this
EOZSH
(bash <<EOBASH)
bash version of snippet looks like this
EOZSH
(sh <<EOSH)
sh
version
of
snippet
looks
like
this
EOSH
(t <<EODEFAULT)
default version
of snippet
looks
like
this
EOSH
)`
IOW, the snippet would consist of a single embedded Elisp case
expression, where the key of each key-value pair is a possible value of sh-shell
, and the value is a (formatted) snippet/template; I've represented the latter using (totally invalid) heredoc
notation.
Is there a (syntactically sound) way to implement this idea?
case
won't work though, ifsh-shell
takes string values.case
compares viaeql
, which only returns true if the arguments are the same lisp object, not if they are different objects with the same value.