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