Skip to content

Commit

Permalink
take #!%... prefix into account for completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Jun 13, 2012
1 parent 56a852f commit 5e77f2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions IPython/core/inputsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
ESC_QUOTE2 = ';' # Quote all args as a single string, call
ESC_PAREN = '/' # Call first argument with rest of line as arguments

ESC_SEQUENCES = [ESC_SHELL, ESC_SH_CAP, ESC_HELP ,\
ESC_HELP2, ESC_MAGIC, ESC_MAGIC2,\
ESC_QUOTE, ESC_QUOTE2, ESC_PAREN ]

#-----------------------------------------------------------------------------
# Utilities
#-----------------------------------------------------------------------------
Expand Down
25 changes: 24 additions & 1 deletion IPython/frontend/qt/console/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#-----------------------------------------------------------------------------

# Standard library imports
from os.path import commonprefix
import os.path
import re
import sys
from textwrap import dedent
Expand All @@ -16,6 +16,7 @@

# Local imports
from IPython.config.configurable import LoggingConfigurable
from IPython.core.inputsplitter import ESC_SEQUENCES
from IPython.frontend.qt.rich_text import HtmlExporter
from IPython.frontend.qt.util import MetaQObjectHasTraits, get_font
from IPython.utils.text import columnize
Expand All @@ -26,10 +27,32 @@
from completion_plain import CompletionPlain
from kill_ring import QtKillRing


#-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------

def commonprefix(items):
"""Given a list of pathnames, returns the longest common leading component
Same function as os.path.commonprefix, but don't considere prefix made of
special caracters like #!$%... see
IPython.core.inputsplitter import ESC_SEQUENCES
"""
# the last item will always have the least leading % symbol
prefixes = ''.join(ESC_SEQUENCES)
get_prefix = lambda x : x[0:-len(x.lstrip(prefixes))]
# min / max are first/last in alphabetical order
first_prefix = get_prefix(min(items))
last_prefix = get_prefix(max(items))

# common suffix is (common prefix of reversed items) reversed
prefix = os.path.commonprefix((first_prefix[::-1], last_prefix[::-1]))[::-1]

items = [ s.lstrip(prefixes) for s in items ]
return prefix+os.path.commonprefix(items)

def is_letter_or_number(char):
""" Returns whether the specified unicode character is a letter or a number.
"""
Expand Down

0 comments on commit 5e77f2c

Please sign in to comment.