Home Download Buy Blog Forum Support

Fast way to select current function in python?

Re: Fast way to select current function in python?

Postby wuub on Fri Jun 07, 2013 10:25 pm

sfranky wrote:(btw, on windows 7)


In that case you'll need to wait untill I pack it into a proper plugin and tune things a bit to work on windows. I said it's not ready yet ;)
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Fast way to select current function in python?

Postby sfranky on Fri Jun 07, 2013 10:36 pm

all right, all right, I'll try being an adult about it and..be..patient!
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

Re: Fast way to select current function in python?

Postby wuub on Fri Jun 07, 2013 10:38 pm

Are you using st2 or st3?
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Fast way to select current function in python?

Postby sublimator on Sat Jun 08, 2013 2:13 am

Image

Blocks are good for rudimentary `scoped` var renaming too
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Fast way to select current function in python?

Postby wuub on Sat Jun 08, 2013 7:54 am

castles_made_of_sand wrote:[img]
Blocks are good for rudimentary `scoped` var renaming too


How did you find boundaries of current blocks? Also with ast or some other method?
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Fast way to select current function in python?

Postby sublimator on Sat Jun 08, 2013 8:16 am

Code: Select all
def find_block_starts(view, block_tokens):
    regex = re.compile(block_tokens if block_tokens else BLOCKERS)
    return [r for r in view.find_by_selector('keyword,storage') if
              view.find(r'\S', view.line(r).begin()).begin() == r.begin() and
              regex.match(view.substr(r)) ]


Basically by finding block starting tokens, bisecting the closest to each selection and then using some indentation comparing routines, to find extents of a block. Used a bit of scope awareness etc.

Things like that worked better in ST 1 & 2 when the api was faster and you could do a lot of `pt` by `pt` stuff.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Fast way to select current function in python?

Postby sublimator on Sat Jun 08, 2013 8:22 am

Will see if I can dig it up and port it
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Fast way to select current function in python?

Postby sfranky on Sat Jun 08, 2013 11:53 am

@wuub ST3
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

Re: Fast way to select current function in python?

Postby wuub on Sun Jun 09, 2013 6:15 pm

sfranky wrote:@wuub ST3


Great!


Installation instructions:

1) Clone this repo into your `Preferences -> Browse Packages` directory.
https://github.com/wuub/SublimeEyeball


2) make sure that at least one pythons have eyeball installed (pip install eyeball should work).
Pick the one you code for, or both if you use py2 and py3. Eyeball relies on ast module and it can only parse the same version of python as itself, so py27 might not be able to understand all of python3 and vice versa.
https://github.com/wuub/SublimeEyeball/ ... 20(Windows).sublime-settings

3) Ctrl+Shift+C to select block of code, repeat to cycle up.


Notes:
- STILL WiP! this is a sneak peek, early beta, preview, because sfranky asked nicely ;)
- plugin launches external python each and every time. On most machines it is fast enough (crazy fast on my workstation) and there is no plan to change this behaviour at least for now.
- as said before external python dependency is caused by ast being tied to the specific python version, also I have some other plans for this library/plugin that would be difficult to code using internal sublime python
- eventually I plan to include eyeball library within this plugin, but since PackageControl / github zipballs don't support git submodules, I need to think it through first
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Fast way to select current function in python?

Postby sfranky on Mon Jun 10, 2013 2:01 pm

I just saw this !! :oops: great! :lol: :lol: :lol:
but... it's not working yet!
I get this error in the console:
SublimeEyeball c:\Python32\pythonw.exe No JSON object could be decoded
(I have python 3.2 installed, not python 3.3, so i just changed the line in your file)
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: douglascorrea, Yahoo [Bot] and 33 guests