Sublime Forum

Fast way to select current function in python?

#1

Anyone knows a fast way to select current function in Python?

“command”: “expand_selection”, “args”: {“to”: “scope”} should have worked, but it doesn’t, leading to select everything.

0 Likes

#2

“command”: “expand_selection”, “args”: {“to”: “indentation”} nearly works, but it won’t select the function header. I hope the behavior of expand_selection to scope can be improved.

0 Likes

#3

You can press ctrl+shift+j to select the contents of the function/class, but you still have to use the lmb to reverse where the mouse pointer is, so you can select the function/class header as well :frowning:

has anyone found a better way? this is a bit frustrating :cry:

0 Likes

#4

AFAIK, you can know when a function starts but not when the function ends.

0 Likes

#5

Well, I’m getting ready to release something that should fit your requirements.

http://youtu.be/u3vXVrLVG5M

If everything goes according to plan, it should be available as an early beta sometime next week.

0 Likes

#6

That looks excellent!! I can’t wait !

0 Likes

#7

Had a plugin like that for ST1. You can hook in the scope/block awareness into test runner too.

http://ndudfield.com/zencoding/old/PyNodesNose/PyNodesNose.gif

http://ndudfield.com/zencoding/old/PyNodesNoseContext/PyNodesNoseContext.gif

0 Likes

#8

[quote=“wuub”]Well, I’m getting ready to release something that should fit your requirements.

http://youtu.be/u3vXVrLVG5M

If everything goes according to plan, it should be available as an early beta sometime next week.[/quote]

That looks sweet!!! Can’t wait! Where is the repo if you don’t mind me asking?

0 Likes

#9

It’s not ready for general consumption yet. But if you’re still interested.

You need this:

git clone https://github.com/wuub/eyeball.git cd eyeball pip install --user .

and this:
github.com/wuub/dotfiles/blob/m … _plugin.py

and this:
github.com/wuub/dotfiles/blob/m … ime-keymap

Ctrl+Shit+C will change selection.
Tested in Stublime Text 3dev & linux only!!!

0 Likes

#10

I only get a python window for a split-second and then nothing. Nothing in the console, as well. :cry:
(btw, on windows 7)

0 Likes

#11

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 :wink:

0 Likes

#12

all right, all right, I’ll try being an adult about it and…be…patient!

0 Likes

#13

Are you using st2 or st3?

0 Likes

#14

http://ndudfield.com/zencoding/old/search-in-area.gif

Blocks are good for rudimentary scoped var renaming too

0 Likes

#15

[quote=“castles_made_of_sand”]
Blocks are good for rudimentary scoped var renaming too

How did you find boundaries of current blocks? Also with ast or some other method?[/quote]

0 Likes

#16

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.

0 Likes

#17

Will see if I can dig it up and port it

0 Likes

#18

@wuub ST3

0 Likes

#19

Great!

Installation instructions:

  1. Clone this repo into your Preferences -> Browse Packages directory.
    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.
    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 :wink:
  • 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
0 Likes

#20

I just saw this !! :blush: great! :laughing: :laughing: :laughing:
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)

0 Likes