added a method 'api_classes.Completion.name_with_signs', because this is important for #280

This commit is contained in:
David Halter
2013-08-15 13:56:43 +04:30
parent 5c0dec6106
commit d6e9732064
2 changed files with 33 additions and 13 deletions

View File

@@ -321,16 +321,7 @@ class Completion(BaseDefinition):
self._followed_definitions = None
@property
def complete(self):
"""
Return the rest of the word, e.g. completing ``isinstance``::
isinstan# <-- Cursor is here
would return the string 'ce'. It also adds additional stuff, depending
on your `settings.py`.
"""
def _complete(self, like_name):
dot = '.' if self._needs_dot else ''
append = ''
if settings.add_bracket_after_function \
@@ -342,7 +333,23 @@ class Completion(BaseDefinition):
append += '.'
if isinstance(self._base, pr.Param):
append += '='
return dot + self._name.names[-1][self._like_name_length:] + append
name = self._name.names[-1]
if like_name:
name = name[self._like_name_length:]
return dot + name + append
@property
def complete(self):
"""
Return the rest of the word, e.g. completing ``isinstance``::
isinstan# <-- Cursor is here
would return the string 'ce'. It also adds additional stuff, depending
on your `settings.py`.
"""
return self._complete(True)
@property
def name(self):
@@ -352,10 +359,22 @@ class Completion(BaseDefinition):
isinstan
would return 'isinstance'.
would return `isinstance`.
"""
return unicode(self._name.names[-1])
@property
def name_with_signs(self):
"""
Similar to :meth:`Completion.name`, but like :meth:`Completion.name`
returns also the signs, for example::
list()
would return ``.append`` and others.
"""
return self._complete(False)
@property
def word(self):
"""

View File

@@ -93,7 +93,8 @@ def setup_readline(namespace=__main__.__dict__):
self.matches.append(path + dot + name)
else:
completions = interpreter.completions()
self.matches = [text + c.complete for c in completions]
self.matches = [path + dot + c.name_with_signs
for c in completions]
try:
return self.matches[state]
except IndexError: