-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One commit is all we'll need here, right?
A single take, just like Calculon.
- Loading branch information
0 parents
commit c2c3111
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
SuperPython | ||
=========== | ||
|
||
Adds tab-completion to Python's somewhat verbose `super()` construct. Just hit `tab` after a `super` keyword and a snippet will be inserted contained the likely current class and method name, with the existing arguments already filled. | ||
|
||
Example: | ||
```python | ||
class AHappyClass(JustSwellBase): | ||
def __init__(self, required_arg, and_another, *anything_else, **enough_already): | ||
super#<tab> | ||
|
||
# Becomes: | ||
|
||
class AHappyClass(JustSwellBase): | ||
def __init__(self, required_arg, and_another, *anything_else, **enough_already): | ||
super(AHappyClass, self).__init__(required_arg, and_another, *anything_else, **enough_already) | ||
|
||
``` | ||
|
||
SubleText's own parsing is used to guess the "current" class name, method name and arguments, which should be fine almost all the time, but may in rare cases pick up the wrong thing, say, if there's an innter class or method definition between the call to `super` and the real method signature. | ||
|
||
Installation | ||
------------ | ||
|
||
You know the drill. To install this plugin, you have two options: | ||
|
||
1. **Package Control** (recommended). If you have [Sublime Package | ||
Control](https://sublime.wbond.net/) installed, simply search for | ||
`SuperPython` to install. | ||
|
||
2. **Manual**. Clone source code to Sublime Text `Packages` folder: | ||
```bash | ||
$ git clone https://github.com/rubyruy/SuperPython | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import bisect | ||
import sublime, sublime_plugin | ||
|
||
def _find_closest_scope(view, scope, target): | ||
matches = view.find_by_selector(scope) | ||
closest_insrt = bisect.bisect_left(matches, target) | ||
return view.substr(matches[closest_insrt - 1]) | ||
|
||
class SuperComplete(sublime_plugin.EventListener): | ||
def on_query_completions(self, view, prefix, locations): | ||
if prefix == 'super' or prefix == 'supe' \ | ||
and 'source.python' in view.scope_name(locations[0]): | ||
|
||
target = sublime.Region(locations[0], locations[0]) | ||
fn_name = _find_closest_scope( | ||
view, 'entity.name.function.python', target) | ||
cls_name = _find_closest_scope( | ||
view, 'entity.name.type.class.python', target) | ||
|
||
args = _find_closest_scope( | ||
view, 'meta.function.parameters.python', target) | ||
|
||
self_name, other_args = args.split(',', 1) | ||
|
||
return [('auto-super()', 'super(%s, %s).%s(${1:%s})' % ( | ||
cls_name, self_name, fn_name, other_args.strip()))] | ||
|
||
|
||
|
||
|