I'm implementing hundreds of similar functions at the moment which take on the form

String name(String arg1, String arg2, String arg3, String arg4) {
  trampoline("name={name}&arg1={arg1}&arg2={arg2}&arg3={arg3}&arg4={arg4}",
              name, arg1, arg2, arg3, arg4);
}

The tricky part is the function can take between 2 and 10 arguments.

If I could have a way to make vim ask me for "Name of function: ", "Number of args: ", "arg1: " I could easily build these functions.

If you need further information to help you help me, I would be more than willing to supply.

Thanks

link|improve this question

feedback

3 Answers

up vote 1 down vote accepted

not really an answer: if you are already at a point when you recognize that you should automate this (for hundreds of functions), you should go one step further and automate it completely: write a code generator in insert_your_favourite_language_here.

link|improve this answer
I'm actually thinking about doing this right now but I would love to become more proficient with vim. – kisplit Oct 17 '11 at 14:36
good intention but for this task maybe the wrong time :) – akira Oct 17 '11 at 14:37
Good point, I went ahead and wrote the generator (in..... c++!) and finished all the methods :). I'll have to go learn vim scripting in some free time at another date – kisplit Oct 17 '11 at 16:36
feedback

First idea: in vim has for (Try :help for).

You can create a simple function to do this.

link|improve this answer
feedback

Here is an answer based on mu-template (it should be easy to port it to plain viml using :put).

VimL: " {rtp}/template/{your_filetype}/{yourgenerator}.template
VimL: let s:nb_args = INPUT("Number of args: ")
VimL: let s:args=map(copy(range(1,s:nb_args)), '"arg".v:val')
VimL: let s:formal = join(map(copy(s:args), "'String '.v:val"), ', ')
VimL: let s:real = join(s:args, ', ')
VimL: let s:format = join(map(copy(s:args), "v:val.'={'.v:val.'}'"), '&')
String name(<+s:formal+>) {
    trampoline("name={name}&<+s:format+>",
        name, <+s:real+>);
}
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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