From 3dc4f09c77fd5293099de1e8a921725ac3416208 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Wed, 28 Aug 2024 08:57:08 +0200 Subject: WIP: complicated --- init.lua | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 2c98e4f..cb14b69 100644 --- a/init.lua +++ b/init.lua @@ -27,6 +27,37 @@ local M = {} +--- Dump value of a variable in a formatted string +-- +--- @param o table Dumpable object +--- @param tbs string|nil Tabulation string, ' ' by default +--- @param tb number|nil Initial tabulation level, 0 by default +--- @return string +local function dump(o, tbs, tb) + tb = tb or 0 + tbs = tbs or " " + if type(o) == "table" then + local s = "{" + if (next(o)) then + s = s .. "\n" + else + return s .. "}" + end + tb = tb + 1 + for k, v in pairs(o) do + if type(k) ~= "number" then + k = '"' .. k .. '"' + end + s = s .. tbs:rep(tb) .. "[" .. k .. "] = " .. dump(v, tbs, tb) + s = s .. ",\n" + end + tb = tb - 1 + return s .. tbs:rep(tb) .. "}" + else + return tostring(o) + end +end + M.settings = {} function execute(s, arg, arg2) @@ -45,6 +76,14 @@ function execute(s, arg, arg2) end end +-- TODO There is something wrong, gh#jocap/vis-filetype-settings!5 mentions +-- settings = { +-- ['.funkytype'] = { +-- "set expandtab on", +-- } +-- } +-- That dot makes me wonder + -- Register events vis.events.subscribe(vis.events.INPUT, function() @@ -63,6 +102,7 @@ local file_events = { for _, event in pairs(file_events) do vis.events.subscribe(vis.events[event], function(file, path) for win in vis:windows() do + vis:info("FILE win.file " .. win.file.name .. ", syntax " .. win.syntax) if win.file == file then if M.settings[win.syntax] and M.settings[win.syntax][event] then execute(M.settings[win.syntax][event], file, path) @@ -89,7 +129,11 @@ local win_events = { for _, event in pairs(win_events) do vis.events.subscribe(vis.events[event], function(win) - if M.settings[win.syntax] == nil then return end + if win.file and (win.syntax ~= nil) then + -- vis:info("WIN win.file " .. win.file.name .. ", syntax " .. win.syntax .. ", settings " .. dump(M.settings[win.syntax])) + vis:info("WIN syntax " .. win.syntax .. ", partial set " .. dump(M.settings[win.syntax])) + end + if M.settings[win.syntax] == nil then return end if M.settings[win.syntax] then if M.settings[win.syntax][event] then execute(M.settings[win.syntax][event], win) -- cgit