diff --git a/dirutil.py b/dirutil.py index 17ba4b9..8ee715d 100644 --- a/dirutil.py +++ b/dirutil.py @@ -1,31 +1,35 @@ import datetime, grp, os, pwd, re, stat from point2 import Point -def resolve_token(w): - c = w.logical_cursor() - p = Point(0, c.y) +def resolve_token(w, y=None): + if y is None: + p = Point(0, w.logical_cursor().y) + else: + p = Point(0, y) return w.get_next_token_by_type(p, 'name') -def resolve_name(w): - t = resolve_token(w) +def resolve_name(w, y=None): + t = resolve_token(w, y) return t.string -def resolve_path(w): +def resolve_path(w, y=None): name = resolve_name(w) path = os.path.join(w.buffer.path, name) return path def find_name(w, s): found = False - w.goto(Point(0, 0)) + y = 0 c = w.logical_cursor() - while not found and c.y < len(w.buffer.lines): - t = resolve_token(w) + while not found and y < len(w.buffer.lines): + t = resolve_token(w, y) if t.string == s: found = True break - w.goto(Point(c.x, c.y + 1)) - c = w.logical_cursor() - if not found: - w.goto(Point(0, 0)) + y += 1 + if found: + w.application.methods['goto-line'].execute(w, lineno=y+1) + p = Point(c.x, y) + if not w.point_is_visible(p): + w.goto(p) def valid_owner(owner): if not owner: @@ -60,7 +64,8 @@ def path_sort(a, b): def path_fields(path, name): # let's escape some troublesome characters name = re.sub(r'([\a\b\n\r\t\v])', r'\\\1', name) - info = os.stat(path) + # don't follow links + info = os.lstat(path) # - regular, b block, c character, d directory, l symlink, p fifo # s socket, ? unknown diff --git a/mode/dir.py b/mode/dir.py index 8e3f446..4878c6e 100644 --- a/mode/dir.py +++ b/mode/dir.py @@ -112,7 +112,7 @@ class DirCmd(Method): (status, output) = commands.getstatusoutput(cmd) if status != 0: w.set_error("%s failed (exit %d)" % (self.name, status)) - w.application.methods['refresh-view'].execute(w, filename=path) + #w.application.methods['refresh-view'].execute(w, filename=path) dirutil.find_name(w, basename) class Chmod(DirCmd):