##// END OF EJS Templates
Merge upstream
Fernando Perez -
r1193:7a255fdd merge
parent child Browse files
Show More
@@ -0,0 +1,75 b''
1 """ Greedy completer extension for IPython
2
3 Normal tab completer refuses to evaluate nonsafe stuff. This will evaluate
4 everything, so you need to consider the consequences of pressing tab
5 yourself!
6
7 Note that this extension simplifies readline interaction by setting
8 only whitespace as completer delimiter. If this works well, we will
9 do the same in default completer.
10
11 """
12 from IPython import generics,ipapi
13 from IPython.genutils import dir2
14
15 def attr_matches(self, text):
16 """Compute matches when text contains a dot.
17
18 MONKEYPATCHED VERSION (ipy_greedycompleter.py)
19
20 Assuming the text is of the form NAME.NAME....[NAME], and is
21 evaluatable in self.namespace or self.global_namespace, it will be
22 evaluated and its attributes (as revealed by dir()) are used as
23 possible completions. (For class instances, class members are are
24 also considered.)
25
26 WARNING: this can still invoke arbitrary C code, if an object
27 with a __getattr__ hook is evaluated.
28
29 """
30 import re
31
32 force_complete = 1
33 # Another option, seems to work great. Catches things like ''.<tab>
34 m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
35
36 if m:
37 expr, attr = m.group(1, 3)
38 else:
39 # force match - eval anything that ends with colon
40 if not force_complete:
41 return []
42
43 m2 = re.match(r"(.+)\.(\w*)$", self.lbuf)
44 if not m2:
45 return []
46 expr, attr = m2.group(1,2)
47
48
49 try:
50 obj = eval(expr, self.namespace)
51 except:
52 try:
53 obj = eval(expr, self.global_namespace)
54 except:
55 return []
56
57 words = dir2(obj)
58
59 try:
60 words = generics.complete_object(obj, words)
61 except ipapi.TryNext:
62 pass
63 # Build match list to return
64 n = len(attr)
65 res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ]
66 return res
67
68 def main():
69 import readline
70 readline.set_completer_delims(" \n\t")
71 # monkeypatch - the code will be folded to normal completer later on
72 import IPython.completer
73 IPython.completer.Completer.attr_matches = attr_matches
74
75 main() No newline at end of file
@@ -94,8 +94,16 b' def matchorfail(text, pos):'
94 94 match = tokenprog.match(text, pos)
95 95 if match is None:
96 96 raise ItplError(text, pos)
97
97 98 return match, match.end()
98 99
100 try:
101 itpl_encoding = sys.stdin.encoding or 'ascii'
102 except AttributeError:
103 itpl_encoding = 'ascii'
104
105
106
99 107 class Itpl:
100 108 """Class representing a string with interpolation abilities.
101 109
@@ -104,7 +112,7 b' class Itpl:'
104 112 evaluation and substitution happens in the namespace of the
105 113 caller when str(instance) is called."""
106 114
107 def __init__(self, format,codec=sys.stdin.encoding,encoding_errors='backslashreplace'):
115 def __init__(self, format,codec=itpl_encoding,encoding_errors='backslashreplace'):
108 116 """The single mandatory argument to this constructor is a format
109 117 string.
110 118
@@ -87,6 +87,11 b' def main():'
87 87 # For bzr completer, requires bzrlib (the python installation of bzr)
88 88 #ip.load('ipy_bzr')
89 89
90 # Tab completer that is not quite so picky (i.e.
91 # "foo".<TAB> and str(2).<TAB> will work). Complete
92 # at your own risk!
93 #import ipy_greedycompleter
94
90 95
91 96
92 97 # some config helper functions you can use
@@ -1,3 +1,10 b''
1 2008-05-14 Ville Vainio <vivainio@gmail.com>
2
3 * Extensions/ipy_greedycompleter.py:
4 New extension that enables a bit more "relaxed" tab
5 completer that evaluates code without safety checks
6 (i.e. there can be side effects like function calls)
7
1 8 2008-04-20 Ville Vainio <vivainio@gmail.com>
2 9
3 10 * Extensions/ipy_lookfor.py: add %lookfor magic command
@@ -13,9 +13,43 b" if sys.platform != 'win32':"
13 13 # Produce pdf.
14 14 os.chdir('build/latex')
15 15
16 # Change chapter style to section style: allows chapters to start on the current page. Works much better for the short chapters we have.
16 # Change chapter style to section style: allows chapters to start on
17 # the current page. Works much better for the short chapters we have.
18 # This must go in the class file rather than the preamble, so we modify
19 # manual.cls at runtime.
20 chapter_cmds=r'''
21 % Local changes.
22 \renewcommand\chapter{
23 \thispagestyle{plain}
24 \global\@topnum\z@
25 \@afterindentfalse
26 \secdef\@chapter\@schapter
27 }
28 \def\@makechapterhead#1{
29 \vspace*{10\p@}
30 {\raggedright \reset@font \Huge \bfseries \thechapter \quad #1}
31 \par\nobreak
32 \hrulefill
33 \par\nobreak
34 \vspace*{10\p@}
35 }
36 \def\@makeschapterhead#1{
37 \vspace*{10\p@}
38 {\raggedright \reset@font \Huge \bfseries #1}
39 \par\nobreak
40 \hrulefill
41 \par\nobreak
42 \vspace*{10\p@}
43 }
44 '''
45
46 unmodified=True
17 47 for line in fileinput.FileInput('manual.cls',inplace=1):
18 line=line.replace('py@OldChapter=\chapter','py@OldChapter=\section')
48 if 'Support for module synopsis' in line and unmodified:
49 line=chapter_cmds+line
50 elif 'makechapterhead' in line:
51 # Already have altered manual.cls: don't need to again.
52 unmodified=False
19 53 print line,
20 54
21 55 # Copying the makefile produced by sphinx...
@@ -123,7 +123,7 b" latex_font_size = '10pt'"
123 123 latex_documents = [('ipython','ipython.tex','IPython Documentation','IPython developers','manual')]
124 124
125 125 # Additional stuff for the LaTeX preamble.
126 latex_preamble = '\\def\\thesection{\\arabic{section}}'
126 #latex_preamble = ''
127 127
128 128 # Documents to append as an appendix to all manuals.
129 129 #latex_appendices = []
General Comments 0
You need to be logged in to leave comments. Login now