Skip to content

Commit

Permalink
Cleanup for flake8/pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
adam committed Apr 28, 2016
1 parent 8fd371d commit 5eea9d0
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions qutebrowser/commands/runners.py
Expand Up @@ -171,21 +171,10 @@ def parse(self, text, *, aliases=True, fallback=False, keep=False):
log.commands.debug("Re-parsing with '{}'.".format(new_cmd))
return self.parse(new_cmd, aliases=False, fallback=fallback,
keep=keep)

cmdstr = self._completion_match(cmdstr)

try:

""" If the command given has only one completion match, replace
the given command with the match.
Ex: If they type "bac" and the only completion is "back",
turn the command into "back".
"""

matches = []
for valid_command in cmdutils.cmd_dict.keys():
if valid_command.find(cmdstr) == 0:
matches.append(valid_command)
if len(matches) == 1:
cmdstr = matches[0]

cmd = cmdutils.cmd_dict[cmdstr]
except KeyError:
if fallback:
Expand All @@ -209,6 +198,23 @@ def parse(self, text, *, aliases=True, fallback=False, keep=False):
cmdline = [cmdstr] + args[:]
return ParseResult(cmd=cmd, args=args, cmdline=cmdline, count=count)

def _completion_match(self, cmdstr):
"""Replace cmdstr with a matching completion if there's only one match.
Args:
cmdstr: The string representing the entered command so far
Return:
cmdstr modified to the matching completion or unmodified
"""
matches = []
for valid_command in cmdutils.cmd_dict.keys():
if valid_command.find(cmdstr) == 0:
matches.append(valid_command)
if len(matches) == 1:
cmdstr = matches[0]
return cmdstr

def _split_args(self, cmd, argstr, keep):
"""Split the arguments from an arg string.
Expand Down

0 comments on commit 5eea9d0

Please sign in to comment.