diff --git a/buffer/pipe.py b/buffer/pipe.py index 72a7e4a..f8bca59 100644 --- a/buffer/pipe.py +++ b/buffer/pipe.py @@ -84,8 +84,7 @@ class PipeBuffer(Buffer): self._lock.release() if efd: raise Exception, "exception is ready: %s" % repr(efd) - except OSError, e: - # read error means we're done + except (OSError, TypeError): pass os.close(fd) diff --git a/completer.py b/completer.py index a4bc897..dfce5a6 100644 --- a/completer.py +++ b/completer.py @@ -1,4 +1,4 @@ -import glob, os, pwd +import glob, os, pwd, sets import method, util def find_common_string(candidates): @@ -78,7 +78,7 @@ class CommandCompleter(Completer): def get_candidates(self, s, w=None): path = os.getenv('PATH') path_dirs = path.split(':') - candidates = [] + candidates = sets.Set() for d in path_dirs: if (not os.path.isdir(d) or not os.access(d, os.R_OK)): continue @@ -88,8 +88,8 @@ class CommandCompleter(Completer): elif not p.startswith(s): continue else: - candidates.append(p) - return candidates + candidates.add(p) + return sorted(candidates) class ShellCompleter(Completer): def __init__(self, application): diff --git a/mode/shellmini.py b/mode/shellmini.py index e83391b..3a84553 100644 --- a/mode/shellmini.py +++ b/mode/shellmini.py @@ -6,6 +6,13 @@ from point import Point from method import Method from subprocess import Popen, PIPE, STDOUT +class ShellMiniGrammar(Grammar): + rules = [ + PatternRule('word', r'(?:(?:\\.|[^\n\\\'" ])+|"(?:\\.|[^\\\"])*"|\'(?:\\.|[^\\\'])*\')+'), + PatternRule('spaces', r' +'), + PatternRule('eol', r'\n'), + ] + class ShellExec(Method): def _execute(self, w, **vargs): a = w.application @@ -76,27 +83,17 @@ class ShellTab(Method): if curr_t is None: return - if(i == 0) and '/' not in curr_t.string: - # we are completing a command - candidates = [] + s1 = curr_t.string + if(curr_i == 0) and '/' not in s1: + completer = method.DATATYPES['command'] else: - # we are completing a path - cwd = os.getcwd() - if not cwd.endswith('/'): - cwd += '/' - path = cwd + curr_t.string - (d, name) = os.path.split(path) - names = [] - for x in os.listdir(d): - if os.path.isdir(os.path.join(d, x)): - names.append(x + '/') - else: - names.append(x) - candidates = [x for x in names if x.startswith(name)] + completer = method.DATATYPES['path'] - s = completer.find_common_string(candidates)[len(name):] - w.insert_string_at_cursor(s) - mode.mini.use_completion_window(a, name, candidates) + s2, exists, complete = completer.tab_string(s1, w) + w.delete(Point(curr_t.x, curr_t.y), Point(curr_t.end_x(), curr_t.y)) + w.insert_string_at_cursor(s2) + candidates = completer.get_candidates(s1, w) + mode.mini.use_completion_window(a, s2, candidates) class ShellBaseMethod(Method): subcls = Method diff --git a/window.py b/window.py index 91b842d..c72d83a 100644 --- a/window.py +++ b/window.py @@ -523,6 +523,8 @@ class Window(object): self.buffer.delete_char(cursor) else: pass + def delete(self, p1, p2): + self.buffer.delete(p1, p2) # killing def kill_line(self):