dotfiles

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

Commit: 19fef60e9ea46b084ac369a03964e92fb344495b
Parent: d2e1c7e42e0d1f184c8e8e07bfb53ed5a8fc6787
Author: Randy Palamar
Date:   Fri, 14 Jun 2024 06:20:05 -0600

vis: simplify goto-ref handling and build logging

Diffstat:
M.config/vis/build.lua | 50++++++++++++++++++--------------------------------
M.config/vis/goto-ref.lua | 10++++++++++
M.config/vis/util.lua | 1+
M.config/vis/visrc.lua | 17+++++------------
4 files changed, 34 insertions(+), 44 deletions(-)

diff --git a/.config/vis/build.lua b/.config/vis/build.lua @@ -15,19 +15,21 @@ vis.events.subscribe(vis.events.FILE_SAVE_PRE, function(file) return M.fix(file) end) +local logger = function(clear, ostr, estr) + if ostr == nil and estr == nil then return end + if clear then util.message_clear(vis) end + if ostr then vis:message(ostr) end + if estr then vis:message(estr) end + vis:message(string.rep("=", vis.win.viewport.width / 2)) +end + local function build_files(win) local build_tex = function (f) local cmd = "xelatex -halt-on-error -shell-escape " -- build in draft mode to update references local err, ostr = vis:pipe(cmd .. "-draftmode " .. f.name) - if err ~= 0 then - if ostr then - util.message_clear(vis) - vis:message(ostr) - end - return false - end + if err ~= 0 then logger(true, ostr) return false end local fp = util.splitext(f.name) -- update refrences @@ -58,41 +60,25 @@ local function build_files(win) local build_python = function (f) local _, ostr, estr = vis:pipe('python ' .. f.name) - if estr then - util.message_clear(vis) - vis:message(estr) - return false - end - if ostr then - util.message_clear(vis) - vis:message(ostr) - end + logger(true, ostr, estr) + if estr then return false end return true end local build_c = function (f) local _, ostr, estr = vis:pipe('./build.sh') - if estr then - 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) - vis:map(vis.modes.NORMAL, "gp", backward) - end - util.message_clear(vis) - vis:message(tostring(estr)) - end + logger(true, ostr, estr) + gf.setup_iterators_from_text(estr, function(str) + local result = str:find("^/usr/include") ~= nil + result = result or str:find("^In file included") + return result + end) return true end local lang = {} lang["ansi_c"] = build_c + lang["cpp"] = build_c lang["latex"] = build_tex lang["python"] = build_python diff --git a/.config/vis/goto-ref.lua b/.config/vis/goto-ref.lua @@ -44,4 +44,14 @@ M.generate_line_indices = function(data, filter) return ret end +M.setup_iterators_from_text = function(text, filter) + if text == nil or #text == 0 then return end + local filepairs = M.generate_line_indices(text, filter) + if #filepairs then + local forward, backward = M.generate_iterators(filepairs) + vis:map(vis.modes.NORMAL, "gn", forward) + vis:map(vis.modes.NORMAL, "gp", backward) + end +end + return M diff --git a/.config/vis/util.lua b/.config/vis/util.lua @@ -10,6 +10,7 @@ end function util.message_clear(vis) vis:message("") -- hack: focus the message window vis.win.file:delete(0, vis.win.file.size) + vis:command("q") end -- returns a function that when called runs all functions in argv diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua @@ -64,23 +64,16 @@ vis.events.subscribe(vis.events.INIT, function() end) vis:command_register("ag", function(argv) - local filepairs = {} util.message_clear(vis) + local outstr = "" for _, arg in ipairs(argv) do - local _, out = vis:pipe("ag -Q " .. arg) + local _, out = vis:pipe("ag -Q --column " .. arg) if out then - vis:message(tostring(out)) - newpairs = gf.generate_line_indices(out) - for i = 1, #newpairs do - table.insert(filepairs, newpairs[i]) - end + vis:message(out) + outstr = outstr .. out end end - if #filepairs then - local forward, backward = gf.generate_iterators(filepairs) - vis:map(vis.modes.NORMAL, "gn", forward) - vis:map(vis.modes.NORMAL, "gp", backward) - end + gf.setup_iterators_from_text(outstr) end, "Search for each literal in argv with the_silver_searcher") local function adjust_layout(wclose)