improved help content

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-04-02 14:17:22 +00:00
parent 7c3b05dcc8
commit c958253e34
2 changed files with 43 additions and 25 deletions

View File

@ -17,6 +17,10 @@ class ShowMode(Method):
lines = ['%s mode' % m.name, ''] lines = ['%s mode' % m.name, '']
if hasattr(m, 'description'):
lines.append('Description:')
lines.extend(m.description.split('\n'))
seen = set() seen = set()
triples = [] triples = []
l1, l2 = 0, 0 l1, l2 = 0, 0
@ -36,7 +40,7 @@ class ShowMode(Method):
triples.append([name, '', a.methods[name].help]) triples.append([name, '', a.methods[name].help])
last = None last = None
lines.append('Key Bindings:') lines.extend(('Key Bindings:', ''))
for triple in sorted(triples): for triple in sorted(triples):
name, keys, _help = triple name, keys, _help = triple
if name == last: if name == last:

View File

@ -7,12 +7,6 @@ from parse import Any, And, Or, Optional, Name, Match, Matchs
from method import Method, arg from method import Method, arg
from method.shell import Exec from method.shell import Exec
try:
import bike
has_bike = True
except ImportError:
has_bike = False
class StringGrammar1(Grammar): class StringGrammar1(Grammar):
rules = [ rules = [
PatternRule(r'octal', r'\\[0-7]{3}'), 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')] args = [arg('name', t="string", p="Name: ", h='name to get help on')]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
name = vargs['name'] name = vargs['name']
stmt = '"try:\n import %s\nexcept:\n pass\nhelp(%s)"' % (name, name) stmt = 'try:\n import %s\nexcept:\n pass\nhelp(%s)' % (name, name)
self._doit(w, None, 'python -c %s' % stmt) self._doit(w, None, 'python -c "%s"' % stmt)
class PythonInsertTripleSquotes(method.Method): class PythonInsertTripleSquotes(method.Method):
'''Insert a triple-quoted string using single-quotes''' '''Insert a triple-quoted string using single-quotes'''
@ -392,27 +386,38 @@ class PythonBrmFindReferences(method.Method):
if w.mode.brm is None: if w.mode.brm is None:
w.set_error('bicycle repairman not installed') w.set_error('bicycle repairman not installed')
return return
base = os.getcwd()
path = w.buffer.path path = w.buffer.path
cursor = w.logical_cursor() cursor = w.logical_cursor()
y, x = cursor.yx() line, col = cursor.y + 1, cursor.x + 1
refs = w.mode.brm.findReferencesByCoordinates(path, y, x) refs = w.mode.brm.findReferencesByCoordinates(path, line, col)
lines = []
n = 0 l, count, tokens = 0, 0, []
if not base.endswith('/'): base += '/'
for r in refs: for r in refs:
f, n, c = r.filename, r.lineno, r.confidence f, n, c = r.filename, r.lineno, r.confidence
s = '%s:%d: %3d%% confidence' % (f, n, c) f = f.replace(base, '')
lines.append(s) label = '%s:%d:' % (f, n)
n += 1 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: if n == 0:
w.set_error('no references found') w.set_error('no references found')
return return
data = '\n'.join(lines) data = '\n'.join(lines)
w.application.data_buffer("*References*", data, switch_to=True) w.application.data_buffer("*References*", data, switch_to=True)
if n == 1: if count == 1:
w.set_error('1 reference found') w.set_error('1 reference found')
else: else:
w.set_error('%d references found' % n) w.set_error('%d references found' % count)
class PythonNameCompleter(completer.Completer): class PythonNameCompleter(completer.Completer):
def _get_dict(self, w): def _get_dict(self, w):
@ -488,13 +493,9 @@ class PythonContext(context.Context):
tokens = highlights.tokens[i] tokens = highlights.tokens[i]
g = highlights.tokens[i] g = highlights.tokens[i]
if self.empty_match.match(tokens): 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: if last is None:
last = i last = i
i += 1 i += 1
#if i == y2 and y2 < blen:
# y2 += 1
continue continue
if g[0].name == 'spaces': if g[0].name == 'spaces':
@ -541,6 +542,14 @@ class PythonContext(context.Context):
self.namelines[k] = (curr, None) self.namelines[k] = (curr, None)
class Python(mode.Fundamental): 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' name = 'Python'
extensions = ['.py'] extensions = ['.py']
detection = ['python'] detection = ['python']
@ -643,9 +652,14 @@ class Python(mode.Fundamental):
self.context = PythonContext(self) self.context = PythonContext(self)
# bicycle repairman! # bicycle repairman!
if has_bike: try:
import bike
self.brm = bike.init() 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 self.brm = None
install = Python.install install = Python.install