parent
7c3b05dcc8
commit
c958253e34
|
@ -17,6 +17,10 @@ class ShowMode(Method):
|
|||
|
||||
lines = ['%s mode' % m.name, '']
|
||||
|
||||
if hasattr(m, 'description'):
|
||||
lines.append('Description:')
|
||||
lines.extend(m.description.split('\n'))
|
||||
|
||||
seen = set()
|
||||
triples = []
|
||||
l1, l2 = 0, 0
|
||||
|
@ -36,7 +40,7 @@ class ShowMode(Method):
|
|||
triples.append([name, '', a.methods[name].help])
|
||||
|
||||
last = None
|
||||
lines.append('Key Bindings:')
|
||||
lines.extend(('Key Bindings:', ''))
|
||||
for triple in sorted(triples):
|
||||
name, keys, _help = triple
|
||||
if name == last:
|
||||
|
|
|
@ -7,12 +7,6 @@ from parse import Any, And, Or, Optional, Name, Match, Matchs
|
|||
from method import Method, arg
|
||||
from method.shell import Exec
|
||||
|
||||
try:
|
||||
import bike
|
||||
has_bike = True
|
||||
except ImportError:
|
||||
has_bike = False
|
||||
|
||||
class StringGrammar1(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'octal', r'\\[0-7]{3}'),
|
||||
|
@ -309,8 +303,8 @@ class PythonHelp(Exec):
|
|||
args = [arg('name', t="string", p="Name: ", h='name to get help on')]
|
||||
def _execute(self, w, **vargs):
|
||||
name = vargs['name']
|
||||
stmt = '"try:\n import %s\nexcept:\n pass\nhelp(%s)"' % (name, name)
|
||||
self._doit(w, None, 'python -c %s' % stmt)
|
||||
stmt = 'try:\n import %s\nexcept:\n pass\nhelp(%s)' % (name, name)
|
||||
self._doit(w, None, 'python -c "%s"' % stmt)
|
||||
|
||||
class PythonInsertTripleSquotes(method.Method):
|
||||
'''Insert a triple-quoted string using single-quotes'''
|
||||
|
@ -392,27 +386,38 @@ class PythonBrmFindReferences(method.Method):
|
|||
if w.mode.brm is None:
|
||||
w.set_error('bicycle repairman not installed')
|
||||
return
|
||||
|
||||
base = os.getcwd()
|
||||
path = w.buffer.path
|
||||
cursor = w.logical_cursor()
|
||||
y, x = cursor.yx()
|
||||
refs = w.mode.brm.findReferencesByCoordinates(path, y, x)
|
||||
lines = []
|
||||
n = 0
|
||||
line, col = cursor.y + 1, cursor.x + 1
|
||||
refs = w.mode.brm.findReferencesByCoordinates(path, line, col)
|
||||
|
||||
l, count, tokens = 0, 0, []
|
||||
if not base.endswith('/'): base += '/'
|
||||
|
||||
for r in refs:
|
||||
f, n, c = r.filename, r.lineno, r.confidence
|
||||
s = '%s:%d: %3d%% confidence' % (f, n, c)
|
||||
lines.append(s)
|
||||
n += 1
|
||||
f = f.replace(base, '')
|
||||
label = '%s:%d:' % (f, n)
|
||||
l = max(len(label), l)
|
||||
tokens.append((label, c))
|
||||
count += 1
|
||||
|
||||
lines = []
|
||||
for tpl in tokens:
|
||||
lines.append('%-*s %3d%% confidence' % (l, tpl[0], tpl[1]))
|
||||
|
||||
if n == 0:
|
||||
w.set_error('no references found')
|
||||
return
|
||||
|
||||
data = '\n'.join(lines)
|
||||
w.application.data_buffer("*References*", data, switch_to=True)
|
||||
if n == 1:
|
||||
if count == 1:
|
||||
w.set_error('1 reference found')
|
||||
else:
|
||||
w.set_error('%d references found' % n)
|
||||
w.set_error('%d references found' % count)
|
||||
|
||||
class PythonNameCompleter(completer.Completer):
|
||||
def _get_dict(self, w):
|
||||
|
@ -488,13 +493,9 @@ class PythonContext(context.Context):
|
|||
tokens = highlights.tokens[i]
|
||||
g = highlights.tokens[i]
|
||||
if self.empty_match.match(tokens):
|
||||
#if (len(g) == 1 and g[0].name == 'eol' or
|
||||
# len(g) == 2 and g[0].name == 'spaces' and g[1].name == 'eol'):
|
||||
if last is None:
|
||||
last = i
|
||||
i += 1
|
||||
#if i == y2 and y2 < blen:
|
||||
# y2 += 1
|
||||
continue
|
||||
|
||||
if g[0].name == 'spaces':
|
||||
|
@ -541,6 +542,14 @@ class PythonContext(context.Context):
|
|||
self.namelines[k] = (curr, None)
|
||||
|
||||
class Python(mode.Fundamental):
|
||||
description = '''
|
||||
This programming mode is designed to edit Python source files. It
|
||||
features parenthesis matching, syntax highlighting, indentation
|
||||
assistance and syntax checking. It can also find classes and functions
|
||||
by name, provide scope context in the status bar, and has an optional
|
||||
context header. Finally, it can semantically complete tokens and
|
||||
provide help output via the python interpreter.
|
||||
'''
|
||||
name = 'Python'
|
||||
extensions = ['.py']
|
||||
detection = ['python']
|
||||
|
@ -643,9 +652,14 @@ class Python(mode.Fundamental):
|
|||
self.context = PythonContext(self)
|
||||
|
||||
# bicycle repairman!
|
||||
if has_bike:
|
||||
try:
|
||||
import bike
|
||||
self.brm = bike.init()
|
||||
else:
|
||||
# turn off brm's annoying STDERR printing
|
||||
f = open('/dev/null', 'w')
|
||||
self.brm.setProgressLogger(f)
|
||||
self.brm.setWarningLogger(f)
|
||||
except ImportError:
|
||||
self.brm = None
|
||||
|
||||
install = Python.install
|
||||
|
|
Loading…
Reference in New Issue