|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' |
|
3 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> |
|
4 <html><head> |
|
5 <title>eric5.DebugClients.Python.FlexCompleter</title> |
|
6 <style> |
|
7 b'body {\n background:white;\n margin: 0em 1em 10em 1em;\n color: black;\n}\n\nh1 { color: white; background: #4FA4FF; }\nh2 { color: white; background: #4FA4FF; }\nh3 { color: white; background: #00557F; }\nh4 { color: white; background: #00557F; }\n \na { color: #AA5500; }\n' |
|
8 </style> |
|
9 </head> |
|
10 <body><a NAME="top" ID="top"></a> |
|
11 <h1>eric5.DebugClients.Python.FlexCompleter</h1> |
|
12 <p> |
|
13 Word completion for the eric5 shell |
|
14 </p><p> |
|
15 <h4>NOTE for eric5 variant</h4> |
|
16 </p><p> |
|
17 This version is a re-implementation of FlexCompleter |
|
18 as found in the PyQwt package. It is modified to work with the eric5 debug |
|
19 clients. |
|
20 </p><p> |
|
21 |
|
22 </p><p> |
|
23 <h4>NOTE for the PyQwt variant</h4> |
|
24 </p><p> |
|
25 This version is a re-implementation of FlexCompleter |
|
26 with readline support for PyQt&sip-3.6 and earlier. |
|
27 </p><p> |
|
28 Full readline support is present in PyQt&sip-snapshot-20030531 and later. |
|
29 </p><p> |
|
30 |
|
31 </p><p> |
|
32 <h4>NOTE for FlexCompleter</h4> |
|
33 </p><p> |
|
34 This version is a re-implementation of rlcompleter with |
|
35 selectable namespace. |
|
36 </p><p> |
|
37 The problem with rlcompleter is that it's hardwired to work with |
|
38 __main__.__dict__, and in some cases one may have 'sandboxed' namespaces. So |
|
39 this class is a ripoff of rlcompleter, with the namespace to work in as an |
|
40 optional parameter. |
|
41 </p><p> |
|
42 This class can be used just like rlcompleter, but the Completer class now has |
|
43 a constructor with the optional 'namespace' parameter. |
|
44 </p><p> |
|
45 A patch has been submitted to Python@sourceforge for these changes to go in |
|
46 the standard Python distribution. |
|
47 </p><p> |
|
48 |
|
49 </p><p> |
|
50 <h4>Original rlcompleter documentation</h4> |
|
51 </p><p> |
|
52 This requires the latest extension to the readline module (the |
|
53 completes keywords, built-ins and globals in __main__; when completing |
|
54 NAME.NAME..., it evaluates (!) the expression up to the last dot and |
|
55 completes its attributes. |
|
56 </p><p> |
|
57 It's very cool to do "import string" type "string.", hit the |
|
58 completion key (twice), and see the list of names defined by the |
|
59 string module! |
|
60 </p><p> |
|
61 Tip: to use the tab key as the completion key, call |
|
62 </p><p> |
|
63 'readline.parse_and_bind("tab: complete")' |
|
64 </p><p> |
|
65 <b>Notes</b>: |
|
66 <ul> |
|
67 <li> |
|
68 Exceptions raised by the completer function are *ignored* (and |
|
69 generally cause the completion to fail). This is a feature -- since |
|
70 readline sets the tty device in raw (or cbreak) mode, printing a |
|
71 traceback wouldn't work well without some complicated hoopla to save, |
|
72 reset and restore the tty state. |
|
73 </li> |
|
74 <li> |
|
75 The evaluation of the NAME.NAME... form may cause arbitrary |
|
76 application defined code to be executed if an object with a |
|
77 __getattr__ hook is found. Since it is the responsibility of the |
|
78 application (or the user) to enable this feature, I consider this an |
|
79 acceptable risk. More complicated expressions (e.g. function calls or |
|
80 indexing operations) are *not* evaluated. |
|
81 </li> |
|
82 <li> |
|
83 GNU readline is also used by the built-in functions input() and |
|
84 raw_input(), and thus these also benefit/suffer from the completer |
|
85 features. Clearly an interactive application can benefit by |
|
86 specifying its own completer function and using raw_input() for all |
|
87 its input. |
|
88 </li> |
|
89 <li> |
|
90 When the original stdin is not a tty device, GNU readline is never |
|
91 used, and this module (and the readline module) are silently inactive. |
|
92 </li> |
|
93 </ul> |
|
94 </p> |
|
95 <h3>Global Attributes</h3> |
|
96 <table> |
|
97 <tr><td>__all__</td></tr> |
|
98 </table> |
|
99 <h3>Classes</h3> |
|
100 <table> |
|
101 <tr> |
|
102 <td><a href="#Completer">Completer</a></td> |
|
103 <td>Class implementing the command line completer object.</td> |
|
104 </tr> |
|
105 </table> |
|
106 <h3>Functions</h3> |
|
107 <table> |
|
108 <tr> |
|
109 <td><a href="#get_class_members">get_class_members</a></td> |
|
110 <td>Module function to retrieve the class members.</td> |
|
111 </tr> |
|
112 </table> |
|
113 <hr /><hr /> |
|
114 <a NAME="Completer" ID="Completer"></a> |
|
115 <h2>Completer</h2> |
|
116 <p> |
|
117 Class implementing the command line completer object. |
|
118 </p> |
|
119 <h3>Derived from</h3> |
|
120 object |
|
121 <h3>Class Attributes</h3> |
|
122 <table> |
|
123 <tr><td>None</td></tr> |
|
124 </table> |
|
125 <h3>Methods</h3> |
|
126 <table> |
|
127 <tr> |
|
128 <td><a href="#Completer.__init__">Completer</a></td> |
|
129 <td>Create a new completer for the command line.</td> |
|
130 </tr><tr> |
|
131 <td><a href="#Completer.attr_matches">attr_matches</a></td> |
|
132 <td>Compute matches when text contains a dot.</td> |
|
133 </tr><tr> |
|
134 <td><a href="#Completer.complete">complete</a></td> |
|
135 <td>Return the next possible completion for 'text'.</td> |
|
136 </tr><tr> |
|
137 <td><a href="#Completer.global_matches">global_matches</a></td> |
|
138 <td>Compute matches when text is a simple name.</td> |
|
139 </tr> |
|
140 </table> |
|
141 <a NAME="Completer.__init__" ID="Completer.__init__"></a> |
|
142 <h4>Completer (Constructor)</h4> |
|
143 <b>Completer</b>(<i>namespace = None</i>) |
|
144 <p> |
|
145 Create a new completer for the command line. |
|
146 </p><p> |
|
147 Completer([namespace]) -> completer instance. |
|
148 </p><p> |
|
149 If unspecified, the default namespace where completions are performed |
|
150 is __main__ (technically, __main__.__dict__). Namespaces should be |
|
151 given as dictionaries. |
|
152 </p><p> |
|
153 Completer instances should be used as the completion mechanism of |
|
154 readline via the set_completer() call: |
|
155 </p><p> |
|
156 readline.set_completer(Completer(my_namespace).complete) |
|
157 </p><dl> |
|
158 <dt><i>namespace</i></dt> |
|
159 <dd> |
|
160 The namespace for the completer. |
|
161 </dd> |
|
162 </dl><a NAME="Completer.attr_matches" ID="Completer.attr_matches"></a> |
|
163 <h4>Completer.attr_matches</h4> |
|
164 <b>attr_matches</b>(<i>text</i>) |
|
165 <p> |
|
166 Compute matches when text contains a dot. |
|
167 </p><p> |
|
168 Assuming the text is of the form NAME.NAME....[NAME], and is |
|
169 evaluatable in self.namespace, it will be evaluated and its attributes |
|
170 (as revealed by dir()) are used as possible completions. (For class |
|
171 instances, class members are are also considered.) |
|
172 </p><p> |
|
173 <b>WARNING</b>: this can still invoke arbitrary C code, if an object |
|
174 with a __getattr__ hook is evaluated. |
|
175 </p><dl> |
|
176 <dt><i>text</i></dt> |
|
177 <dd> |
|
178 The text to be completed. (string) |
|
179 </dd> |
|
180 </dl><dl> |
|
181 <dt>Returns:</dt> |
|
182 <dd> |
|
183 A list of all matches. |
|
184 </dd> |
|
185 </dl><a NAME="Completer.complete" ID="Completer.complete"></a> |
|
186 <h4>Completer.complete</h4> |
|
187 <b>complete</b>(<i>text, state</i>) |
|
188 <p> |
|
189 Return the next possible completion for 'text'. |
|
190 </p><p> |
|
191 This is called successively with state == 0, 1, 2, ... until it |
|
192 returns None. The completion should begin with 'text'. |
|
193 </p><dl> |
|
194 <dt><i>text</i></dt> |
|
195 <dd> |
|
196 The text to be completed. (string) |
|
197 </dd><dt><i>state</i></dt> |
|
198 <dd> |
|
199 The state of the completion. (integer) |
|
200 </dd> |
|
201 </dl><dl> |
|
202 <dt>Returns:</dt> |
|
203 <dd> |
|
204 The possible completions as a list of strings. |
|
205 </dd> |
|
206 </dl><a NAME="Completer.global_matches" ID="Completer.global_matches"></a> |
|
207 <h4>Completer.global_matches</h4> |
|
208 <b>global_matches</b>(<i>text</i>) |
|
209 <p> |
|
210 Compute matches when text is a simple name. |
|
211 </p><dl> |
|
212 <dt><i>text</i></dt> |
|
213 <dd> |
|
214 The text to be completed. (string) |
|
215 </dd> |
|
216 </dl><dl> |
|
217 <dt>Returns:</dt> |
|
218 <dd> |
|
219 A list of all keywords, built-in functions and names currently |
|
220 defined in self.namespace that match. |
|
221 </dd> |
|
222 </dl> |
|
223 <div align="right"><a href="#top">Up</a></div> |
|
224 <hr /><hr /> |
|
225 <a NAME="get_class_members" ID="get_class_members"></a> |
|
226 <h2>get_class_members</h2> |
|
227 <b>get_class_members</b>(<i>klass</i>) |
|
228 <p> |
|
229 Module function to retrieve the class members. |
|
230 </p><dl> |
|
231 <dt><i>klass</i></dt> |
|
232 <dd> |
|
233 The class object to be analysed. |
|
234 </dd> |
|
235 </dl><dl> |
|
236 <dt>Returns:</dt> |
|
237 <dd> |
|
238 A list of all names defined in the class. |
|
239 </dd> |
|
240 </dl> |
|
241 <div align="right"><a href="#top">Up</a></div> |
|
242 <hr /> |
|
243 </body></html> |