Documentation/Source/eric6.DebugClients.Python.FlexCompleter.html

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

eric ide

mercurial