dotfiles

personal dotfiles
git clone anongit@rnpnr.xyz:dotfiles.git
Log | Files | Refs | Feed | Submodules

Commit: bddbc35076d3cf323d156fca61dc5fd07f39ce90
Parent: 7207535e4e6a0aadcd02d63e922e3d1d007048d1
Author: Randy Palamar
Date:   Wed, 29 May 2024 20:39:13 -0600

vis: goto-ref: add filter callback and column jumping

Also compare based on absolute path so that ./foo.c and foo.c are
recognized as the same file.

Diffstat:
M.config/vis/build.lua | 8+++++++-
M.config/vis/goto-ref.lua | 18+++++++++++-------
2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/.config/vis/build.lua b/.config/vis/build.lua @@ -73,7 +73,13 @@ local function build_files(win) local build_c = function (f) local _, ostr, estr = vis:pipe('./build.sh') if estr then - local filepairs = gf.generate_line_indices(estr) + local filter = function(str) + local result = str:find("^/usr/include") ~= nil + result = result or str:find("^In file included") + return result + end + + local filepairs = gf.generate_line_indices(estr, filter) if #filepairs then local forward, backward = gf.generate_iterators(filepairs) vis:map(vis.modes.NORMAL, "gn", forward) diff --git a/.config/vis/goto-ref.lua b/.config/vis/goto-ref.lua @@ -1,22 +1,23 @@ local M = {} local focus_file = function(name) + local realpath = io.popen("realpath " .. name):read("*a"):sub(1, -2) for win in vis:windows() do - if win.file and win.file.name == name then + if win.file and win.file.path == realpath then vis.win = win return end end - vis:command(":o " .. name) + vis:command(":o " .. realpath) end M.generate_iterators = function(file_index_table) local current_index = 1; local iterate = function(inc) - local file, line = table.unpack(file_index_table[current_index]) + local file, line, col = table.unpack(file_index_table[current_index]) focus_file(file) - vis.win.selection:to(line, 1) + vis.win.selection:to(line, type(col) == 'number' and col or 1) current_index = current_index + inc if current_index > #file_index_table then current_index = 1 @@ -31,11 +32,14 @@ M.generate_iterators = function(file_index_table) return forward, backward end -M.generate_line_indices = function(data) +M.generate_line_indices = function(data, filter) local ret = {} for s in data:gmatch("[^\n]*") do - found, _, file, line = s:find('^([^:]+):([%d]+):') - if found then table.insert(ret, {file, line}) end + local skip = filter and filter(s) + if not skip then + local found, _, file, line, col = s:find('^([^:]+):([%d]+):([%d]*):?') + if found then table.insert(ret, {file, line, col}) end + end end return ret end