dotfiles

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

Commit: 6f0af48a1e0d9d2b6a0f85d040e909dd2b6d2bd5
Parent: 7aff5afd0660b71fba04547c0fc4d756b39c7d7f
Author: Randy Palamar
Date:   Sat, 14 Oct 2023 10:00:16 -0600

vis: move some helper fns to util

Diffstat:
M.config/vis/macros.lua | 18+++---------------
M.config/vis/util.lua | 21+++++++++++++++++++++
M.config/vis/visrc.lua | 14+++++++-------
3 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/.config/vis/macros.lua b/.config/vis/macros.lua @@ -1,10 +1,4 @@ --- function chain -local function fc(argv) - return function () - for _, f in ipairs(argv) do f() end - return true - end -end +local util = require('util') -- insert local function ins(str) @@ -30,14 +24,6 @@ local function sur(p, s) end end --- feedkeys -local function fk(fkeys) - return function () - vis:feedkeys(fkeys) - return true - end -end - -- inserts a latex environment local lenv = function(env, inner) local out = "\\begin{%s}\n%s\\end{%s}" @@ -47,6 +33,8 @@ end local function macros(win) local m = vis.modes + local fc, fk = util.function_chain, util.feedkeys + local lang = {} lang["latex"] = { { m.NORMAL, "\\al", fc({ lenv("align*"), fk("O") }) }, diff --git a/.config/vis/util.lua b/.config/vis/util.lua @@ -12,4 +12,25 @@ function util.message_clear(vis) vis.win.file:delete(0, vis.win.file.size) end +-- returns a function that when called runs all functions in argv +function util.function_chain(argv) + return function () + for _, f in ipairs(argv) do f() end + end +end + +-- returns a function that when called runs vis:feedkeys(keys) +function util.feedkeys(keys) + return function () + vis:feedkeys(keys) + end +end + +-- returns a function that when called runs vis:command(cmd) +function util.command(cmd) + return function() + vis:command(cmd) + end +end + return util diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua @@ -26,15 +26,15 @@ vis.events.subscribe(vis.events.INIT, function() vis.options = { autoindent = true } - vis:command("map normal gq vip=<Escape>") - vis:command("map normal ,f v$:|furigana<Enter><Escape>") - vis:command("map visual ,s :|sort<Enter>") + local m, fk, cmd = vis.modes, util.feedkeys, util.command + vis:map(m.NORMAL, " f", fk("v$:|furigana<Enter><Escape>")) + vis:map(m.NORMAL, "gq", fk("vip=<Escape>")) + vis:map(m.VISUAL, " s", cmd("|sort")) - vis:map(vis.modes.NORMAL, "vo", function() - vis:command("x/[ \t\r]+$/ d") - end, "remove spaces, tabs, and \r from end of all lines") + vis:map(m.NORMAL, "vo", cmd("x/[ \t\r]+$/ d"), + "remove whitespace from end of all lines") - vis:map(vis.modes.NORMAL, " l", function() + vis:map(m.NORMAL, " l", function() local ui = vis.ui if ui.layout == ui.layouts.HORIZONTAL then ui.layout = ui.layouts.VERTICAL