cmd, readline, and rlcompleter problems

Michael Hudson mwh21 at cam.ac.uk
Fri Jun 16 09:03:49 EDT 2000


BTW: your followups-to header is broken, I think.

pete-python-5-17 at kazmier.com (Peter Kazmier) writes:

> I need help debugging a very strange problem.  I'm not a python expert
> so it could be something very simple, on the other hand, I did use the
> debugger already, but the problem disappears miraculously when I use
> the debugger.  It makes no sense to me.
> 
> So, I'm basically trying to write my own cmd and rlcompleter.  I've
> attached both the module and a small example of its use.  Its almost
> identical to the standard cmd however I am trying to offer command
> line completion.  
[snip]
> Everything works fine IF I comment out the get_line_buffer() line.
> Unfortunately, that would only do completion on the current word.
> When I uncomment the get_line_buffer() line, everything seems to work,
> but during the 'for word in self.__class__.__dict__.keys()' loop, half
> of the keys mysteriously disappear!  The DEBUG output, shows only some
> of the keys, not all of them.  Comment out the get_line_buffer() line
> and all of the keys() are back!  When I stepped through this in the
> debugger, all of the keys() were also there!!  It appears that the
> get_line_buffer() call is somehow munging my environment in a weird
> way.  Oddly enough, whwen debugging, his munging does not appear.

If I understand the situation properly, you have several problems.

The first is to understand that when your completer function is
called, the terminal is in some unusual mode (cbreak mode? something
like that).

This means you really don't want to mess with it, eg. by printing to
it.  You'll only confuse yourself; I'd try writing debugging output to
some random file and then 'tail -f'-ing it from another xterm.

It also means that trying to run it under pdb is just hopeless, I'm
afraid.

If I comment out the prints, it sort of works for me, but you still
have other problems.  The simplest is that when you type

# show vers

and bang TAB, the completer returns "show version", so readline
completes "vers" as "show version" and the buffer becomes

# show show version

Also, wouldn't you like

# show     vers

to work?  It won't currently.

Your best be may be to change the "completer_delims" to not include
space, but I think you're going to have to work a bit harder than it
would seem you hope to in your completer function.

HTH,
Michael

-- 
  Or here's an even simpler indicator of how much C++ sucks: Print
  out the C++ Public Review Document.  Have someone  hold it about
  three feet  above your head and then drop it.  Thus  you will be
  enlightened.                                        -- Thant Tessman



More information about the Python-list mailing list