Permalink
Browse files

Further tab completion tweaks

  • Loading branch information...
1 parent 260f8b3 commit 407b491db51bc0c20a2f4ba57f7d3e09bf7a921a @inducer committed Feb 1, 2014
Showing with 20 additions and 4 deletions.
  1. +20 −4 pudb/debugger.py
View
@@ -1329,8 +1329,22 @@ def cmdline_tab_complete(w, size, key):
text = self.cmdline_edit.edit_text
pos = self.cmdline_edit.edit_pos
+
chopped_text = text[:pos]
- remainder_text = text[pos:]
+ suffix = text[pos:]
+
+ # stolen from readline in the Python interactive shell
+ delimiters = " \t\n`~!@#$%^&*()-=+[{]}\\|;:\'\",<>/?"
+
+ complete_start_index = max(
+ chopped_text.rfind(delim_i)
+ for delim_i in delimiters)
+
+ if complete_start_index == -1:
+ prefix = ""
+ else:
+ prefix = chopped_text[:complete_start_index+1]
+ chopped_text = chopped_text[complete_start_index+1:]
state = 0
chopped_completions = []
@@ -1364,15 +1378,17 @@ def common_prefix(a, b):
if completed_chopped_text is None:
return
- if len(completed_chopped_text) == pos and len(chopped_completions) > 1:
+ if (
+ len(completed_chopped_text) == len(chopped_text)
+ and len(chopped_completions) > 1):
add_cmdline_content(
" ".join(chopped_completions),
"command line output")
return
self.cmdline_edit.edit_text = \
- completed_chopped_text+remainder_text
- self.cmdline_edit.edit_pos = len(completed_chopped_text)
+ prefix+completed_chopped_text+suffix
+ self.cmdline_edit.edit_pos = len(prefix) + len(completed_chopped_text)
def cmdline_append_newline(w, size, key):
self.cmdline_edit.insert_text("\n")

0 comments on commit 407b491

Please sign in to comment.