##// END OF EJS Templates
Merge pull request #1944 from Carreau/completer-cell-magic...
Bussonnier Matthias -
r7606:2484ba10 merge
parent child Browse files
Show More
@@ -96,6 +96,10 b" ESC_QUOTE = ',' # Split args on whitespace, quote each as string and call"
96 ESC_QUOTE2 = ';' # Quote all args as a single string, call
96 ESC_QUOTE2 = ';' # Quote all args as a single string, call
97 ESC_PAREN = '/' # Call first argument with rest of line as arguments
97 ESC_PAREN = '/' # Call first argument with rest of line as arguments
98
98
99 ESC_SEQUENCES = [ESC_SHELL, ESC_SH_CAP, ESC_HELP ,\
100 ESC_HELP2, ESC_MAGIC, ESC_MAGIC2,\
101 ESC_QUOTE, ESC_QUOTE2, ESC_PAREN ]
102
99 #-----------------------------------------------------------------------------
103 #-----------------------------------------------------------------------------
100 # Utilities
104 # Utilities
101 #-----------------------------------------------------------------------------
105 #-----------------------------------------------------------------------------
@@ -5,7 +5,7 b''
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6
6
7 # Standard library imports
7 # Standard library imports
8 from os.path import commonprefix
8 import os.path
9 import re
9 import re
10 import sys
10 import sys
11 from textwrap import dedent
11 from textwrap import dedent
@@ -16,6 +16,7 b' from IPython.external.qt import QtCore, QtGui'
16
16
17 # Local imports
17 # Local imports
18 from IPython.config.configurable import LoggingConfigurable
18 from IPython.config.configurable import LoggingConfigurable
19 from IPython.core.inputsplitter import ESC_SEQUENCES
19 from IPython.frontend.qt.rich_text import HtmlExporter
20 from IPython.frontend.qt.rich_text import HtmlExporter
20 from IPython.frontend.qt.util import MetaQObjectHasTraits, get_font
21 from IPython.frontend.qt.util import MetaQObjectHasTraits, get_font
21 from IPython.utils.text import columnize
22 from IPython.utils.text import columnize
@@ -26,10 +27,36 b' from completion_html import CompletionHtml'
26 from completion_plain import CompletionPlain
27 from completion_plain import CompletionPlain
27 from kill_ring import QtKillRing
28 from kill_ring import QtKillRing
28
29
30
29 #-----------------------------------------------------------------------------
31 #-----------------------------------------------------------------------------
30 # Functions
32 # Functions
31 #-----------------------------------------------------------------------------
33 #-----------------------------------------------------------------------------
32
34
35 ESCAPE_CHARS = ''.join(ESC_SEQUENCES)
36 ESCAPE_RE = re.compile("^["+ESCAPE_CHARS+"]+")
37
38 def commonprefix(items):
39 """Get common prefix for completions
40
41 Return the longest common prefix of a list of strings, but with special
42 treatment of escape characters that might precede commands in IPython,
43 such as %magic functions. Used in tab completion.
44
45 For a more general function, see os.path.commonprefix
46 """
47 # the last item will always have the least leading % symbol
48 # min / max are first/last in alphabetical order
49 first_match = ESCAPE_RE.match(min(items))
50 last_match = ESCAPE_RE.match(max(items))
51 # common suffix is (common prefix of reversed items) reversed
52 if first_match and last_match:
53 prefix = os.path.commonprefix((first_match.group(0)[::-1], last_match.group(0)[::-1]))[::-1]
54 else:
55 prefix = ''
56
57 items = [s.lstrip(ESCAPE_CHARS) for s in items]
58 return prefix+os.path.commonprefix(items)
59
33 def is_letter_or_number(char):
60 def is_letter_or_number(char):
34 """ Returns whether the specified unicode character is a letter or a number.
61 """ Returns whether the specified unicode character is a letter or a number.
35 """
62 """
General Comments 0
You need to be logged in to leave comments. Login now