Commit: 2a40f3aa255d3a2de9398a4a9c86f93732b45b82
Parent: aac4c7617402b4f3b49194577a696a9c68b86703
Author: Randy Palamar
Date: Sun, 23 Mar 2025 11:02:03 -0600
vis: add gf binding to goto selected file:line:col tuple
Diffstat:
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/.config/vis/goto-ref.lua b/.config/vis/goto-ref.lua
@@ -1,7 +1,7 @@
local M = {}
-local focus_file = function(name)
- local realpath = io.popen("realpath " .. name):read("*a"):sub(1, -2)
+local focus_or_open = function(file)
+ local realpath = io.popen("realpath " .. file):read("*a"):sub(1, -2)
for win in vis:windows() do
if win.file and win.file.path == realpath then
vis.win = win
@@ -11,14 +11,19 @@ local focus_file = function(name)
vis:command(":o " .. realpath)
end
+M.focus_file_at = function(file, line, col)
+ if file then
+ focus_or_open(file)
+ vis.mode = vis.modes.NORMAL
+ vis.win.selection:to(line and line or 1, col and col or 1)
+ end
+end
+
M.generate_iterators = function(file_index_table)
local current_index = 1;
local iterate = function(inc)
- local file, line, col = table.unpack(file_index_table[current_index])
- focus_file(file)
- if type(col) == 'string' then col = tonumber(col) end
- vis.win.selection:to(line, col and col or 1)
+ M.focus_file_at(table.unpack(file_index_table[current_index]))
current_index = current_index + inc
if current_index > #file_index_table then
current_index = 1
diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua
@@ -64,6 +64,14 @@ vis.events.subscribe(vis.events.INIT, function()
vis:message("syntax = " .. tostring(vis.win.syntax))
vis:message("file.name = " .. fn)
end, "dump info to message window")
+
+ vis:map(m.VISUAL, "gf", function()
+ local sel = vis.win.selection
+ local data = vis.win.file:content(sel.range)
+ local pairs = gf.generate_line_indices(data)
+ vis.mode = vis.modes.NORMAL
+ if pairs then gf.focus_file_at(table.unpack(pairs[1])) end
+ end, 'Goto selected "file:line:[col:]"')
end)
vis:command_register("ag", function(argv)