From 28b180c75aefdb043995297037e0a56dd3a2ae56 Mon Sep 17 00:00:00 2001 From: Chris Pecunies Date: Mon, 23 Dec 2024 00:45:20 -0800 Subject: [PATCH] simplifying config --- README.md | 34 ++---- lua/down.lua | 13 +- lua/down/config.lua | 9 +- lua/down/mod.lua | 56 ++++----- lua/down/mod/data/date/README.md | 0 lua/down/mod/data/date/init.lua | 154 ++++++++++++++++++++++++ lua/down/mod/data/history/README.md | 0 lua/down/mod/data/history/init.lua | 40 ++++++ lua/down/mod/data/store/README.md | 0 lua/down/mod/data/store/init.lua | 47 ++++++++ lua/down/mod/data/task/README.md | 0 lua/down/mod/data/task/agenda/README.md | 0 lua/down/mod/data/task/agenda/init.lua | 48 ++++++++ lua/down/mod/data/task/init.lua | 53 ++++++++ 14 files changed, 387 insertions(+), 67 deletions(-) create mode 100644 lua/down/mod/data/date/README.md create mode 100644 lua/down/mod/data/date/init.lua create mode 100644 lua/down/mod/data/history/README.md create mode 100644 lua/down/mod/data/history/init.lua create mode 100644 lua/down/mod/data/store/README.md create mode 100644 lua/down/mod/data/store/init.lua create mode 100644 lua/down/mod/data/task/README.md create mode 100644 lua/down/mod/data/task/agenda/README.md create mode 100644 lua/down/mod/data/task/agenda/init.lua create mode 100644 lua/down/mod/data/task/init.lua diff --git a/README.md b/README.md index d1e3dd1..ef73fd7 100644 --- a/README.md +++ b/README.md @@ -57,16 +57,12 @@ the _familiar_, organized future for neovim and beyond! branch = "master", config = function() require "down".setup { - mod = { - workspace = { - config = { - default = "notes", - workspaces = { - default = "~/down", - notes = "~/notes", - personal = "~/home" - } - } + workspace = { + default = "notes", + workspaces = { + default = "~/down", + notes = "~/notes", + personal = "~/home" } } } @@ -104,17 +100,13 @@ Plug "pysan3/pathlib.nvim" Plug "clpi/down.lua", { \ "branch" : "master", \ "do" : ':lua require([[down]]).setup({ - \ mod = { \ workspace = { - \ config = { \ workspaces = { \ wiki = [[~/wiki]], \ default = [[~/down]], \ notes = [[~/notes]] \ } - \ } \ } - \ } \ })' \ } ``` @@ -187,17 +179,13 @@ use { branch = 'master', config = function() require("down").setup({ - mod = { - workspace = { - config = { - workspaces = { - default = "~/down", - home = "~/notes", - notes = "~/notes" - } + workspace = { + workspaces = { + default = "~/down", + home = "~/notes", + notes = "~/notes" } } - } }) end, } diff --git a/lua/down.lua b/lua/down.lua index 5eda808..167afcb 100644 --- a/lua/down.lua +++ b/lua/down.lua @@ -37,10 +37,7 @@ local a, f, ext = vim.api, vim.fn, vim.tbl_deep_extend --- Initializes down. Parses the supplied user config, initializes all selected mod and adds filetype checking for `.down`. --- @param conf down.config.UserMod? A table that reflects the structure of `config.user`. function W.setup(conf) - conf = conf or { mod = {} } - if conf.mod == nil then - conf.mod = {} - end + conf = conf or {} con.user = utils.extend(con.user, conf) -- log.new(con.user.logger or log.get_base_config(), true) require('down.config').setup_maps() @@ -60,14 +57,14 @@ function W.setup(conf) end, }) end - require 'down.util.lsp'.setup() - require 'down.util.lsp'.run() + -- require 'down.util.lsp'.setup() + -- require 'down.util.lsp'.run() end ---@param manual table ---@param args table function W.enter(manual, args) - local mods = con.user and con.user.mod or {} + local mods = con and con.user or {} if con.started or not mods or vim.tbl_isempty(mods) then ---@diagnostic disable-line return end @@ -82,7 +79,7 @@ function W.enter(manual, args) end for name, lm in pairs(mods) do - con.mod[name] = utils.extend(con.mod[name] or {}, lm.config or {}) + con[name] = utils.extend(con[name] or {}, lm or {}) end for name, _ in pairs(mods) do if not m.load_mod(name) then diff --git a/lua/down/config.lua b/lua/down/config.lua index a6cd7a2..c2cf41c 100644 --- a/lua/down/config.lua +++ b/lua/down/config.lua @@ -4,12 +4,8 @@ local f = vim.fn --- @type down.Config C.config = { - ---@class down.config.User + ---@class down.mod.Config user = { - ---@class down.config.UserMod - mod = { - config = {}, - }, }, -- data = f.stdpath("data") .. "/down.mpack", @@ -22,9 +18,6 @@ C.config = { down = true, }, - mod = { - config = {}, - }, manual = nil, args = {}, version = "0.1.0", diff --git a/lua/down/mod.lua b/lua/down/mod.lua index aa0478d..c44f1fb 100644 --- a/lua/down/mod.lua +++ b/lua/down/mod.lua @@ -10,26 +10,26 @@ local utils = require('down.util') -- TODO: remove global ---@return ----@class down.Mod +---@class down Mod = setmetatable({}, { __index = Mod, - ---@param self down.Mod - ---@param other down.Mod + ---@param self down + ---@param other down __eq = function(self, other) return self.name == other.name end, - ---@param self down.Mod + ---@param self down __tostring = function(self) return self.name end, }) ----@return down.Mod +---@return down ---@param name string The name of the new mod Mod.default = function(name) return { setup = function() - ---@type down.mod.Setup + ---@type down.Setup return { loaded = true, requires = {}, @@ -52,7 +52,7 @@ Mod.default = function(name) on = function() end, post_load = function() end, name = 'config', - namespace = 'down.' .. name, + namespace = 'down.mod.' .. name, path = 'mod.config', version = require('down').config.version, data = { @@ -71,11 +71,11 @@ Mod.default = function(name) } end ---- @param name string The name of the new init. Modake sure this is unique. The recommended naming convention is `category.modn` or `category.subcategory.modn`. +--- @param name string The name of the new init. Modake sure this is unique. The recommended naming convention is `categoryn` or `category.subcategoryn`. --- @param imports? string[] A list of imports to attach to the init. Import data is requestable via `init.required`. Use paths relative to the current init. ---- @return down.Mod +--- @return down function Mod.create(name, imports) - ---@type down.Mod + ---@type down local new = Mod.default(name) if imports then for _, imp in ipairs(imports) do @@ -107,11 +107,11 @@ end --]] --- Constructs a default array of modules, --- NOTE: Specifically for the introductory `config` module ---- @param name string The name of the new metainit. Modake sure this is unique. The recommended naming convention is `category.modn` or `category.subcategory.modn`. +--- @param name string The name of the new metainit. Modake sure this is unique. The recommended naming convention is `categoryn` or `category.subcategoryn`. --- @param ... string A list of init names to load. ---- @return down.Mod -Mod.modules = function(name, ...) - ---@type down.Mod +--- @return down +local modules = function(name, ...) + ---@type down local m = Mod.create(name) m.config.enable = { ... } m.setup = function() @@ -152,9 +152,9 @@ Mod.modules = function(name, ...) return m end Mod.loaded_mod_count = 0 ---- @type { [string]: down.Mod } +--- @type { [string]: down } Mod.loaded_mod = {} ---- @param m down.Mod The actual init to load. +--- @param m down The actual init to load. --- @return boolean # Whether the init successfully loaded. function Mod.load_mod_from_table(m) log.info('Loading init with name' .. m.name) @@ -166,7 +166,7 @@ function Mod.load_mod_from_table(m) end -- Invoke the setup function. This function returns whether or not the loading of the init was successful and some metadata. - ---@type down.mod.Setup + ---@type down.Setup local mod_load = m.setup and m.setup() or { loaded = true, @@ -208,7 +208,7 @@ function Mod.load_mod_from_table(m) log.trace('Verifying' .. req_mod) if not Mod.is_mod_loaded(req_mod) then - if config.user.mod[req_mod] then + if config.user[req_mod] then log.trace( 'Wanted init' .. req_mod @@ -378,8 +378,8 @@ function Mod.load_mod(modn, cfg) modl.config.custom = cfg modl.config = utils.extend(modl.config, cfg) else - -- print(modl.config.custom, modl.config, config.mod[modn]) - modl.config.custom = config.mod[modn] + -- print(modl.config.custom, modl.config, config[modn]) + modl.config.custom = config[modn] modl.config = -- vim.tbl_extend("force", modl.config, modl.config.custom or {}) utils.extend(modl.config, modl.config.custom or {}) @@ -390,8 +390,8 @@ function Mod.load_mod(modn, cfg) end --- Has the same principle of operation as load_mod_from_table(), except it then sets up the parent init's "required" table, allowing the parent to access the child as if it were a dependency. ---- @param md down.Mod A valid table as returned by mod.create() ---- @param parent_mod string|down.Mod If a string, then the parent is searched for in the loaded mod. If a table, then the init is treated as a valid init as returned by mod.create() +--- @param md down A valid table as returned by mod.create() +--- @param parent_mod string|down If a string, then the parent is searched for in the loaded mod. If a table, then the init is treated as a valid init as returned by mod.create() function Mod.load_mod_as_dependency_from_table(md, parent_mod) if Mod.load_mod_from_table(md) then if type(parent_mod) == 'string' then @@ -408,7 +408,7 @@ end --- @param cfg? table A config that reflects the structure of down.config.user.setup["init.name"].config function Mod.load_mod_as_dependency(modn, parent_mod, cfg) if Mod.load_mod(modn, cfg) and Mod.is_mod_loaded(parent_mod) then - Mod.loaded_mod[parent_mod].required[modn] = Mod.mod_config(modn) + Mod.loaded_mod[parent_mod].required[modn] = Mod_config(modn) end end @@ -428,7 +428,7 @@ end --- Returns the init.config table if the init is loaded --- @param modn string The name of the init to retrieve (init must be loaded) --- @return table? -function Mod.mod_config(modn) +function Mod_config(modn) if not Mod.is_mod_loaded(modn) then log.trace('Attempt to get init config with name' .. modn .. 'failed - init is not loaded.') return @@ -500,7 +500,7 @@ function Mod.split_event_type(type) end --- Returns an event template defined in `init.events`. ---- @param m down.Mod A reference to the init invoking the function +--- @param m down A reference to the init invoking the function --- @param type string A full path to a valid event type (e.g. `init.events.some_event`) --- @return down.Event? function Mod.get_event_template(m, type) @@ -524,7 +524,7 @@ function Mod.get_event_template(m, type) end --- Creates a deep copy of the `mod.base_event` event and returns it with a custom type and referrer. ---- @param m down.Mod A reference to the init invoking the function. +--- @param m down A reference to the init invoking the function. --- @param name string A relative path to a valid event template. --- @return down.Event function Mod.define_event(m, name) @@ -556,7 +556,7 @@ function Mod.define_event(m, name) end --- Returns a copy of the event template provided by a init. ---- @param init down.Mod A reference to the init invoking the function +--- @param init down A reference to the init invoking the function --- @param type string A full path to a valid .vent type (e.g. `init.events.some_event`) --- @param content table|any? The content of the event, can be anything from a string to a table to whatever you please. --- @param ev? table The original event data. @@ -596,7 +596,7 @@ function Mod.create_event(m, type, content, ev) new_event.broadcast = true new_event.buffer = bufid new_event.window = winid - new_event.mode = vim.api.nvim_get_mode().mode + new_evente = vim.api.nvim_get_mode() return new_event end diff --git a/lua/down/mod/data/date/README.md b/lua/down/mod/data/date/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lua/down/mod/data/date/init.lua b/lua/down/mod/data/date/init.lua new file mode 100644 index 0000000..fe03b6c --- /dev/null +++ b/lua/down/mod/data/date/init.lua @@ -0,0 +1,154 @@ +---@class down.Mod +local M = require "down.mod".create("data.date", { +}) + +--- The date data structure. +--- @class down.data.date.Data Data +M.data = { + +} + +local d, t, dt = M.data.datetime.date, M.data.datetime.time, M.data.datetime + +--- The date data structure. +--- @type down.Datetime The datetime data structure. +M.data.datetime = setmetatable({ + --- @type down.Date The datetime data structure. + date = setmetatable({ + year = 0, + month = 0, + day = 0, + week = 0, + ---@param d down.Date The date part of the datetime. + ---@param t? down.Time The date part of the datetime. + ---@return osdateparam params The date part of the datetime. + params = function(d, t) + t = t or { hour = 0, minute = 0, second = 0 } + return { + hour = t.hour or 0, + second = t.second or 0, + minute = t.minute or 0, + year = d.year, + month = d.month, + day = d.day, + week = d.week, + } + end, + date = function(d) + return os.date("%Y-%m-%d", os.time(d)) + end, + fmt = function(d, df) + return string.format(df or "%04d-%02d-%02d", d.year, d.month, d.day) + end + }, { + --- @param dt down.Date + --- @param fmt? string + --- @return string|osdate + __call = function(dt, fmt) + return os.date(fmt or "%02d:%02d:%02d", os.time(M.data.datetime.date.params(dt))) + end, + __tostring = function(d) + return string.format("%04d-%02d-%02d", d.year, d.month, d.day) + end + }), + --- @type down.Time + time = setmetatable({ + hour = 0, + minute = 0, + second = 0, + fmt = function(t, tf) + return string.format(tf or "%02d:%02d:%02d", t.hour, t.minute, t.second) + end, + time = function(t) + return os.time(t) + end, + ---@param d? down.Date The date part of the datetime. + ---@param t down.Time The date part of the datetime. + ---@return down.Datetime + params = function(t, d) + return { + year = d.year or 0, + month = d.month or 0, + day = d.day or 0, + week = d.week or 0, + hour = t.hour or 0, + min = t.minute or 0, + sec = t.second or 0, + } + end, + }, { + --- @param dt down.Time + --- @param fmt? string + --- @return string|osdate + __call = function(dt, fmt) + return os.date(fmt or "%02d:%02d:%02d", os.time(M.data.datetime.time.params(dt))) + end, + __tostring = function(t) + return string.format("%02d:%02d:%02d", t.hour, t.minute, t.second) + end + }), + --- @param dt down.Time + --- @param f? string + --- @return string + fmt = function(dt, f) + return string.format(f or "%s %s", tostring(dt.date), tostring(dt.time)) + end, + --- @param dt down.Datetime + --- @return osdateparam + params = function(dt) + return { + hour = dt.time.hour, + minute = dt.time.minute, + second = dt.time.second, + year = dt.date.year, + month = dt.date.month, + day = dt.date.day, + week = dt.date.week, + } + end, +}, { + __tostring = function(dt) + return tostring(dt.date) .. " " .. tostring(dt.time) + end, + ---@param d down.Datetime + ---@param k string + __index = function(d, k) + if d.date[k] then + return d.date[k] + elseif d.time[k] then + return d.time[k] + end + end, + ---@param dt down.Datetime + ---@param fmt string + ---@return string|osdate + __call = function(dt, fmt) + return os.date("%02d:%02d:%02d", os.time(M.data.datetime.params(dt))) + end, +}) + +---@class table +M.data.stores = { + +} + +---@class down.data.store.Config +M.config = { + + store = "data/stores" + +} + +---@return down.mod.Setup +M.setup = function() + ---@type down.mod.Setup + return { + requires = { + + }, + loaded = true, + } +end + + +return M diff --git a/lua/down/mod/data/history/README.md b/lua/down/mod/data/history/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lua/down/mod/data/history/init.lua b/lua/down/mod/data/history/init.lua new file mode 100644 index 0000000..cf8fc28 --- /dev/null +++ b/lua/down/mod/data/history/init.lua @@ -0,0 +1,40 @@ +---@class down.Mod +local M = require "down.mod".create("data.history", { + +}) + +---@alias down.data.history.Store down.Store Store +---@type down.data.history.Store Store +M.Data.store = { + +} +---@class down.data.history.Data +M.data = { + +} + +---@class table +M.data.stores = { + +} + +---@class down.data.history.Config +M.config = { + + store = "data/stores" + +} + +---@return down.mod.Setup +M.setup = function() + ---@type down.mod.Setup + return { + requires = { + + }, + loaded = true, + } +end + + +return M diff --git a/lua/down/mod/data/store/README.md b/lua/down/mod/data/store/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lua/down/mod/data/store/init.lua b/lua/down/mod/data/store/init.lua new file mode 100644 index 0000000..806b619 --- /dev/null +++ b/lua/down/mod/data/store/init.lua @@ -0,0 +1,47 @@ +---@class down.Mod +local M = require "down.mod".create("data.store", { +}) + +---@class down.data.store.Store +M.Store = { + title = "", + about = "", + status = 0, + due = "", + created = "", + uri = "", + pos = { + line = -1, + char = -1, + } +} +---@class down.data.store.Data +M.data = { + +} + +---@class table +M.data.stores = { + +} + +---@class down.data.store.Config +M.config = { + + store = "data/stores" + +} + +---@return down.mod.Setup +M.setup = function() + ---@type down.mod.Setup + return { + requires = { + + }, + loaded = true, + } +end + + +return M diff --git a/lua/down/mod/data/task/README.md b/lua/down/mod/data/task/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lua/down/mod/data/task/agenda/README.md b/lua/down/mod/data/task/agenda/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lua/down/mod/data/task/agenda/init.lua b/lua/down/mod/data/task/agenda/init.lua new file mode 100644 index 0000000..8f4c7b6 --- /dev/null +++ b/lua/down/mod/data/task/agenda/init.lua @@ -0,0 +1,48 @@ +---@class down.Mod +local M = require "down.mod".create("data.task.agenda", { +}) + +---@class down.data.task.agenda.Agenda +M.Agenda = { + + uri = "", + + store = "", + + tasks = { + + } +} +---@class down.data.task.agenda.Data +M.data = { + +} + +---@class table +M.data.agendas = { + +} + +---@class down.data.task.agenda.Config +M.config = { + + + uri = "", + + store = "data/agendas" + +} + +---@return down.mod.Setup +M.setup = function() + ---@type down.mod.Setup + return { + requires = { + + }, + loaded = true, + } +end + + +return M diff --git a/lua/down/mod/data/task/init.lua b/lua/down/mod/data/task/init.lua new file mode 100644 index 0000000..7dd48b5 --- /dev/null +++ b/lua/down/mod/data/task/init.lua @@ -0,0 +1,53 @@ +---@class down.Mod +local M = require "down.mod".create("data.task", { + "agenda" +}) + +---@class down.data.task.Task +M.Task = { + title = "", + about = "", + status = 0, + due = "", + created = "", + uri = "", + ---@type down.Position + pos = { + line = -1, + char = -1, + } +} +---@class down.data.task.Data +M.data = { + +} + +---@class table +M.data.tasks = { + +} + +---@class down.data.task.Config +M.config = { + store = { + root = "data/task", + agenda = "data/task/agenda", + } +} + +---@return down.mod.Setup +M.setup = function() + ---@type down.mod.Setup + return { + requires = { + "workspace", + "ui.calendar", + "data.store", + "data.task.agenda", + }, + loaded = true, + } +end + + +return M