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