2

In emacs yas-minor-mode, I want to use place-holders in values listed in yas-choose-value. Is it possible? Following code is what I want to do. However it doesn't work well..

# -*- mode: snippet -*-
# name: my_func
# key: my_func
# --
function_${1:$$(yas-choose-value '("x1(arg1=${2:foo}", "arg2=${3:bar)" "x2(arg1=${2:hoge})" "x3()" ))}
$0

I expects following operation.

(step-1) yas-expand is executed for "my_func"

I should be able to select one from "x1", "x2" and "x3"

(step-2) arguments should be changed acording to the selection in (step-1)

  • if "x1" is selected,

    function_x1(arg1=foo, arg2=bar)
    

    should be complemented. Positions of "foo" and "bar" are place holder and they are default value.

  • if "x2" is selected,

    function_x2(arg1=hoge)
    

    should be complemented. Positions of "hoge" is place holder and it is default value.

  • if "x3" is selected,

     function_x3()
    

    should be complemented. No argument.

elgoog
  • 77
  • 5

1 Answers1

0

I think this has the functionality you are looking for. Give this a shot.

# -*- mode: snippet -*-
# name: my_func
# key: my_func
# --
function_`(yas-choose-value '("x1(arg1=${1:foo}, arg2=${2:bar})" "x2(arg1=${1:hoge})" "x3()"))`
$0
Sandy
  • 799
  • 8
  • 12
  • Thank you for your answer. I tried your snippets. However, (step-2) doesn't work well in my environment. For instance, if "x2" is selected, I want to edit the place holder ${1:hoge}. But it was treated as normal string and I could not edit it. – elgoog Mar 31 '16 at 15:28
  • What is your environment? I have emacs 24.5 and yas snippits 0.8.0. Do you get the dialog box as your first step for choosing a function? – Sandy Apr 04 '16 at 23:13
  • I'm using emacs 24.5.1 and yasnippet 0.91. Yes, I get the dialog box(as helm interface) for choosing following ones when I type "my_func" and execute "yas-expand". x1(arg1=${1:foo}, arg2=${2:bar}) , x2(arg1=${1:hoge}) , x3() However, after one from them is choosen, it is input as a plain text into a buffer. ${1:foo}, ${2:bar} and ${1:hoge} are not treated as place holders. – elgoog Apr 05 '16 at 16:11
  • Hmm, there must be some other yas setting that is making it not work for you as it works perfectly with my set set up :/ Wish I could help more than that. – Sandy Apr 09 '16 at 21:55