{-- Thu, 12 Jul 2012 20:50:28 +0200: Matthias <mtr...@web.de> wrote: --}

  Matthias> Hi Keith, I've played with filename completion for your
  Matthias> remarkable shell. First the good news: it works (for
  Matthias> me). The bad news is that the code is by far not as readable
  Matthias> as yours. But I tried my best.

Nice.  Maintaining completion while supporting search directories
invalidates my original solution for completion and implementing it is
definitely a jump in complexity.

<description of _filedirs map based implementation omitted>

  Matthias> The drawback of the current code is that you cannot give
  Matthias> directory names any more. Only the filenames itself are
  Matthias> allowed. This is fine for me, but may bother the users.

I think another limitation is that the use of the #cd directive to
change directories won't work in files any longer.  Preserving this is
slightly tricky because of the way the code tracks nested directory
changes in files included with the #include directory, but to do so I
would replace the call to:

 os.path.normpath(os.path.join(os.path.join(wd, filename))

near the top of the upload_files() method with a call to a function
like:

def find_upload_file(self, filename, working_directory):
    if os.path.isabs(filename):
        return filename   # Don't search if given absolute path
    for p in self._search_path:
        fn = os.path.normpath(os.path.join(p, filename))
        if not os.path.isabs(fn):
           fn = os.path.normpath(os.path.join(working_directory, fn))
        if os.path.exists(fn):
             return fn
    return filename        # The attempt to open later will fail...

I think this should handle everything required to get the search
behavior working if at startup you split the AMFORTH_LIB environment
variable contents into the "self._search_path" instance variable.  Note
I haven't actually tried to implement just typed it in.  It would be an
alternative to the way you have it implemented right now.

The completion support is trickier.  Roughly, I would replace the code
in the _rl_completer function for #include and #edit directives with
something like:

if os.path.isabs(text):
   self._rl_matches = glob.glob(text + "*")
else:
   self._rl_matches = itertools.chain(map(lambda p: \
        glob.glob(os.path.join(p, text) + "*"), self._search_path))

This will essentially return the union of the glob matches for the
supplied completion text in all possible search directories if the
completion text is not already an absolute filename.  It might get slow
if you have a lot of large directories on your search path, but I
suspect it will be fine.  I also expect I didn't get it really right but
I think it should be close enough that you could get it working if you
started with this.

It's really nice to see these additional features being added!

       --- Keith

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to