0

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

flumpb
  • 495
  • 1
  • 5
  • 16

3 Answers3

1

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.

akira
  • 61,009
  • 17
  • 135
  • 165
  • I'm actually thinking about doing this right now but I would love to become more proficient with vim. – flumpb 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 – flumpb Oct 17 '11 at 16:36
1

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

You can create a simple function to do this.

Tamara Wijsman
  • 57,083
  • 27
  • 185
  • 256
uzsolt
  • 1,245
  • 7
  • 13
0

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+>);
}
Luc Hermitte
  • 1,855
  • 11
  • 11