I have installed Racket in my home folder. The path to the drracket 
executable is added to the PATH environment variable, but the tab 
completions in the prompt widget doesn't work for drracket executable.

However the CommandCompleter class and its complete seems to be working 
fine.
Here's a little test I did.

> import os
> import glob
> class CommandCompleter:
>     DEFAULTPATH = "/bin:/usr/bin:/usr/local/bin"
>
>     def __init__(self, qtile, _testing=False):
>         """
>         _testing: disables reloading of the lookup table
>                   to make testing possible.
>         """
>         self.lookup, self.offset = None, None
>         self.thisfinal = None
>         self._testing = _testing
>
>     def actual(self):
>         """
>             Returns the current actual value.
>         """
>         return self.thisfinal
>
>     def executable(self, fpath):
>         return os.access(fpath, os.X_OK)
>
>     def reset(self):
>         self.lookup = None
>         self.offset = -1
>
>     def complete(self, txt):
>         """
>         Returns the next completion for txt, or None if there is no 
> completion.
>         """
>         if not self.lookup:
>             if not self._testing:
>                 # Lookup is a set of (display value, actual value) tuples.
>                 self.lookup = []
>                 if txt and txt[0] in "~/":
>                     path = os.path.expanduser(txt)
>                     if os.path.isdir(path):
>                         files = glob.glob(os.path.join(path, "*"))
>                         prefix = txt
>                     else:
>                         files = glob.glob(path + "*")
>                         prefix = os.path.dirname(txt)
>                     prefix = prefix.rstrip("/") or "/"
>                     for f in files:
>                         if self.executable(f):
>                             display = os.path.join(prefix, 
> os.path.basename(f))
>                             if os.path.isdir(f):
>                                 display += "/"
>                             self.lookup.append((display, f))
>                 else:
>                     dirs = os.environ.get("PATH", 
> self.DEFAULTPATH).split(":")
>                     for didx, d in enumerate(dirs):
>                         try:
>                             for cmd in glob.glob(os.path.join(d, "%s*" % 
> txt)):
>                                 if self.executable(cmd):
>                                     self.lookup.append(
>                                         (
>                                             os.path.basename(cmd),
>                                             cmd
>                                         ),
>                                     )
>                         except OSError:
>                             pass
>             self.lookup.sort()
>             self.offset = -1
>             self.lookup.append((txt, txt))
>         self.offset += 1
>         if self.offset >= len(self.lookup):
>             self.offset = 0
>         ret = self.lookup[self.offset]
>         self.thisfinal = ret[1]
>         return ret[0]
>
> if __name__ == "__main__":
>     cc = CommandCompleter("qtile")
>     print cc.complete("dr") # gives "drracket"
>     print cc.complete("dr") # and the 'lookup' list contains the tuple 
> with "drracket" and its path.
>     
>
>
>
Though I am not able to check further since one class depends on the other 
and so on. I don't know how to debug this kind of code, so I need help. 
Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"qtile-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to