Show More
@@ -96,6 +96,10 ESC_QUOTE = ',' # Split args on whitespace, quote each as string and call | |||
|
96 | 96 | ESC_QUOTE2 = ';' # Quote all args as a single string, call |
|
97 | 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 | 104 | # Utilities |
|
101 | 105 | #----------------------------------------------------------------------------- |
@@ -5,7 +5,7 | |||
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | 6 | |
|
7 | 7 | # Standard library imports |
|
8 | from os.path import commonprefix | |
|
8 | import os.path | |
|
9 | 9 | import re |
|
10 | 10 | import sys |
|
11 | 11 | from textwrap import dedent |
@@ -16,6 +16,7 from IPython.external.qt import QtCore, QtGui | |||
|
16 | 16 | |
|
17 | 17 | # Local imports |
|
18 | 18 | from IPython.config.configurable import LoggingConfigurable |
|
19 | from IPython.core.inputsplitter import ESC_SEQUENCES | |
|
19 | 20 | from IPython.frontend.qt.rich_text import HtmlExporter |
|
20 | 21 | from IPython.frontend.qt.util import MetaQObjectHasTraits, get_font |
|
21 | 22 | from IPython.utils.text import columnize |
@@ -26,10 +27,32 from completion_html import CompletionHtml | |||
|
26 | 27 | from completion_plain import CompletionPlain |
|
27 | 28 | from kill_ring import QtKillRing |
|
28 | 29 | |
|
30 | ||
|
29 | 31 | #----------------------------------------------------------------------------- |
|
30 | 32 | # Functions |
|
31 | 33 | #----------------------------------------------------------------------------- |
|
32 | 34 | |
|
35 | def commonprefix(items): | |
|
36 | """Given a list of pathnames, returns the longest common leading component | |
|
37 | ||
|
38 | Same function as os.path.commonprefix, but don't considere prefix made of | |
|
39 | special caracters like #!$%... see | |
|
40 | ||
|
41 | IPython.core.inputsplitter import ESC_SEQUENCES | |
|
42 | """ | |
|
43 | # the last item will always have the least leading % symbol | |
|
44 | prefixes = ''.join(ESC_SEQUENCES) | |
|
45 | get_prefix = lambda x : x[0:-len(x.lstrip(prefixes))] | |
|
46 | # min / max are first/last in alphabetical order | |
|
47 | first_prefix = get_prefix(min(items)) | |
|
48 | last_prefix = get_prefix(max(items)) | |
|
49 | ||
|
50 | # common suffix is (common prefix of reversed items) reversed | |
|
51 | prefix = os.path.commonprefix((first_prefix[::-1], last_prefix[::-1]))[::-1] | |
|
52 | ||
|
53 | items = [ s.lstrip(prefixes) for s in items ] | |
|
54 | return prefix+os.path.commonprefix(items) | |
|
55 | ||
|
33 | 56 | def is_letter_or_number(char): |
|
34 | 57 | """ Returns whether the specified unicode character is a letter or a number. |
|
35 | 58 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now