dotfiles

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

Commit: 67c2680e09da67522e0baeee331f674f272343ff
Parent: 76319eb8a7b9860b873dbec58c542f3f4fe721f9
Author: Randy Palamar
Date:   Fri, 16 Dec 2022 21:54:02 -0700

vis: deduplicate some code in build and macros

Diffstat:
M.config/vis/build.lua | 16+++++++---------
M.config/vis/macros.lua | 13+++++--------
2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/.config/vis/build.lua b/.config/vis/build.lua @@ -1,4 +1,6 @@ -function build_files(win) +require('util') + +local function build_files(win) function error() vis:info('This filetype is not supported') end @@ -24,21 +26,17 @@ function build_files(win) -- write file vis:command('w') - local f = win.file.name + local f, e = splitext(win.file.name) if f == nil then error() return end - local i = string.find(f, '%.') - if i == nil then error() return end - - local method = lang[string.sub(f, i)] + local method = lang[e] if method == nil then error() return end - vis:info(string.format('building \'%s\'', f)) - method(string.sub(f, 0, i - 1)) + vis:info(string.format('building: %s', f .. e)) + method(f) end vis:map(vis.modes.NORMAL, ',c', build) vis:command_register('build', build) end - vis.events.subscribe(vis.events.WIN_OPEN, build_files) diff --git a/.config/vis/macros.lua b/.config/vis/macros.lua @@ -1,4 +1,6 @@ -function macros(win) +require('util') + +local function macros(win) local lang = {} lang['.tex'] = { { 'normal', '\\bf', 'i\\\\textbf{}<Escape>hi' }, @@ -14,18 +16,13 @@ function macros(win) { 'normal', 'gq', 'vip:|hindent<Enter><Escape>'}, } - local f = win.file.name - if f == nil then return end - - local i = string.find(f, '%.') - if i == nil then return end + local _, e = splitext(win.file.name) - local binds = lang[string.sub(f, i)] + local binds = lang[e] if binds == nil then return end for _, map in pairs(binds) do vis:command(string.format('map! %s %s %s', map[1], map[2], map[3])) end end - vis.events.subscribe(vis.events.WIN_OPEN, macros)