Hi folks,
I’ve written a plugin which parses all selections or the current line for import statements, tries to open them, bookmarks (temporarily, until the file is being closed) and highlights all referenced symbols - thus you can skim thru them like normal bookmarks. This let’s me create and open references extremely easy and without opening and traversing the directory tree. I’m using OSX but it should also work within Linux. I appreciate working patches for Windows.
This involves two files:
- find_python_imports.py: A helper script to parse given content. Returns all imports (e.g. “import a”, “from a import b” or “app.code.some.thing” - see main() in file for many more variants!)
- open_python_file.py: A text command which uses the script above to parse all selections or the current line and does the rest described at the top.
You can easily use this by putting the repo folder mentioned below into your “Packages” folder.
I’m using the following key binding (replace super with ctrl when under Linux/Windows):
{ “keys”: “super+shift+o”], “command”: “open_python_file” }
You might also want to make use of the virtualenv integration I’ve described in a previous forum post (Virtualenv). To combine these two you have to set up the “open_python_file_vrun_executable” variable in your “Global.sublime-settings” file. I’ve set it to the same value as my “exec_arg_list_wrapper” var.
You can now open some Python file from your project folder (or something else), highlight some import statements and let them open up in new tabs.
You can get the code here:
bitbucket.org/theblacklion/sublime_plugins/src
Have fun,
Oktay.