0

I've been looking at making more snippets for Sublimetext2. I've been looking at http://sublimetext.info/docs/en/extensibility/snippets.html and other questions here and I was able to write this snippet to get the name of the file as a function name:

<content><![CDATA[function ${1:${TM_FILENAME/(.+)\..+|.*/$1/:name}$SELECTION()
{

}]]></content>

But now I am trying to write one that takes TM_FILEPATH does a replace and slices of the filename and the beginning of the path. For example I want to turn this:

"/Library/WebServer/Documents/projects/CGI/source/com/test/play/Bla.js"

into this:

"com.test.play"

I am stumped by the regex syntax and what I should do with "${var_name/regex/format_string/options}". Can anyone explain to me how to write such a regex, and how to use these four items to rewrite the TM_FILEPATH variable?

Soesah
  • 155
  • 2
  • 10
  • You will need 2 steps, one to capture the `com/test/play`, and the other to change the `/` to `.`. Just in case the namespace has more levels or less than 3. Not sure if they allow you to pass in another level of replacement in the replace string. – nhahtdh Aug 18 '12 at 06:59
  • Is it possible to do two steps in a single regex? I tried looking for other ways to hook into the snippet being inserted, but it seems there isn't any. – Soesah Aug 18 '12 at 09:31
  • It is possible if you limit the number of levels. Another thing I didn't mention is that, you need to know where the start of the namespace is - is "source" always the folder before the start of namespace? – nhahtdh Aug 18 '12 at 11:37
  • Yes, source is always going to be the start. – Soesah Aug 18 '12 at 11:55
  • When I tried to do this, I realized that I still need 2 steps regardless. The thing is, I need to know the number of levels to insert the `.` correctly. – nhahtdh Aug 18 '12 at 12:59

0 Answers0