diff options
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 25 |
1 files changed, 8 insertions, 17 deletions
@@ -7,20 +7,10 @@ local function file_exists(path) return out end ---- Store the paths we opened to change their line in the second WIN_OPEN event -local paths = {} - vis.events.subscribe(vis.events.WIN_OPEN, function(win) if win.file == nil or win.file.path == nil then return end local ref = win.file.path - -- If this is a file we opened, simply go to the saved line. - if paths[ref] then - vis:feedkeys(tostring(paths[ref]).."G") - paths[ref] = nil - return - end - -- if the file with colon actually exists, don't do anything if file_exists(ref) then return @@ -31,14 +21,15 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) return end - -- Store the file's path to go to line in the next WIN_OPEN event - paths[path] = line - win:close() win.file = path - -- Open the actual file path. This creates a new window and emits a new - -- WIN_OPEN event, which we use to set the correct line. - vis:command("e "..path) - -- Prevent other WIN_OPEN event handlers from running after we closed the window. + -- fire a new WIN_OPEN event because we changed the file + vis.events.emit(vis.events.WIN_OPEN, win) + + -- After the other handlers ran we set the position. + vis:feedkeys(line.."G") + + -- Stop handling the old FILE_OPEN event since we changed the file and emitted + -- a new WIN_OPEN event return true end) |
