1

I am trying to create a way in UltiSnip to take a list of variable names and transform them into a line delimited list of strings (like you would see in AngularJS). So you type each arg, jump to next placeholder, and above the function is filled in with what you want.

Start with this:

function(FirstArg, SecondArg, ThirdArg)

Hit the CTRL-J (next placeholder)

And Final Result:

[
  'FirstArg',
  'SecondArg',
  'ThridArg',
  function(FirstArg, SecondArg, ThirdArg) {
    // ... cursor here after hitting CTRL-J
    // this would be $0
  }
]

Any hints would be great!

beeryardtech
  • 605
  • 1
  • 4
  • 15
  • Just an idea: take the whole string between () as $1 and then use python interpolation to split it at the commas and generate the lines above. Should work in principle but I don't know how messy it would become if you dive into the details. – wataya Mar 10 '15 at 21:46

1 Answers1

2

Simpler then I thought. This is the function

global !p
def varDeps(args):
    result = ""
    argList = args.split(",")

    for arg in argList:
        dep = "    " + "'" + arg.strip() + "',\n"
        result = result + dep

    return result.rstrip()
 endglobal

Then use something like this (where this is the third placeholder)

    `!p snip.rv = varDeps(t[3])`
        function($scope, ${3:deps}) {
            //....
        }
beeryardtech
  • 605
  • 1
  • 4
  • 15