Home Download Buy Blog Forum Support

Get text inside current braces

Get text inside current braces

Postby vostok4 on Tue Mar 01, 2011 4:10 am

I was wondering if its possible to get all text within a given brace block (so while (true) { sleep 1; }, get the sleep 1;) and support nested blocks (so once I detect a {, I can find the code inside).

ST2 highlights the brace pair of the block you are currently in, so I was wondering if this information (what region is in the block I guess) is exposed through the API anywhere?
vostok4
 
Posts: 25
Joined: Fri Oct 22, 2010 6:09 pm

Re: Get text inside current braces

Postby adzenith on Tue Mar 01, 2011 4:44 am

Have you tried command+shift+space? (ctrl+shift+space on Windows)
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Get text inside current braces

Postby vostok4 on Tue Mar 01, 2011 9:13 am

Yes that's what I want, but sorry (wasn't clear) how would I do this in a plugin?
vostok4
 
Posts: 25
Joined: Fri Oct 22, 2010 6:09 pm

Re: Get text inside current braces

Postby jps on Tue Mar 01, 2011 9:41 am

You can run the command from within the plugin, via:

Code: Select all
view.run_command("expand_selection", { "to": "brackets" })


That will modify the selection, of course, which may or may not be ok for what you're trying to do.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Get text inside current braces

Postby vostok4 on Wed Mar 02, 2011 12:15 am

Hm, not really looking to expand the selection, I just want to parse the text in the braces. I'm trying to write a code insight plugin for PHP, and still planning it out in my head.
vostok4
 
Posts: 25
Joined: Fri Oct 22, 2010 6:09 pm

Re: Get text inside current braces

Postby adzenith on Wed Mar 02, 2011 12:42 am

You could save the current selection, expand the selection, copy the text, then set the selection back to what it used to be...
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Get text inside current braces

Postby vostok4 on Wed Mar 02, 2011 2:09 am

I just realized I'll need a different solution since I'll be working with all files in the current project, not just ones that are open.

Thanks anyways for the help!
vostok4
 
Posts: 25
Joined: Fri Oct 22, 2010 6:09 pm


Return to Plugin Development

Who is online

Users browsing this forum: Exabot [Bot] and 0 guests