From e0ad7a7b26f574911f532e3f1a6d7563ad44bace Mon Sep 17 00:00:00 2001 From: Chris Pecunies Date: Sat, 16 Nov 2024 00:01:17 -0800 Subject: [PATCH] scaffolding other mods --- .../mod/{style/conceal/module.lua => .lua} | 0 lua/dorm/mod/base/module.lua | 7 + lua/dorm/mod/capture/module.lua | 61 ++ lua/dorm/mod/cmd/module.lua | 1 + lua/dorm/mod/{style => completion}/module.lua | 0 lua/dorm/mod/data/module.lua | 0 lua/dorm/mod/encrypt/module.lua | 61 ++ .../mod/{conceal => icon}/base/module.lua | 0 .../mod/{conceal => icon}/diamond/module.lua | 0 lua/dorm/mod/{conceal => icon}/module.lua | 0 lua/dorm/mod/init.lua | 3 +- lua/dorm/mod/lsp/module.lua | 0 lua/dorm/mod/metadata/module.lua | 61 ++ lua/dorm/mod/notes/module.lua | 10 +- lua/dorm/mod/preview/module.lua | 0 lua/dorm/mod/publish/module.lua | 0 lua/dorm/mod/run/module.lua | 61 ++ lua/dorm/mod/search/module.lua | 61 ++ lua/dorm/mod/style/hl/module.lua | 634 ------------------ lua/dorm/mod/template/module.lua | 61 ++ lua/dorm/mod/treesitter/module.lua | 4 +- lua/dorm/mod/workspace/module.lua | 1 + 22 files changed, 383 insertions(+), 643 deletions(-) rename lua/dorm/mod/{style/conceal/module.lua => .lua} (100%) create mode 100644 lua/dorm/mod/capture/module.lua rename lua/dorm/mod/{style => completion}/module.lua (100%) create mode 100644 lua/dorm/mod/data/module.lua create mode 100644 lua/dorm/mod/encrypt/module.lua rename lua/dorm/mod/{conceal => icon}/base/module.lua (100%) rename lua/dorm/mod/{conceal => icon}/diamond/module.lua (100%) rename lua/dorm/mod/{conceal => icon}/module.lua (100%) create mode 100644 lua/dorm/mod/lsp/module.lua create mode 100644 lua/dorm/mod/metadata/module.lua create mode 100644 lua/dorm/mod/preview/module.lua create mode 100644 lua/dorm/mod/publish/module.lua create mode 100644 lua/dorm/mod/run/module.lua create mode 100644 lua/dorm/mod/search/module.lua delete mode 100644 lua/dorm/mod/style/hl/module.lua create mode 100644 lua/dorm/mod/template/module.lua diff --git a/lua/dorm/mod/style/conceal/module.lua b/lua/dorm/mod/.lua similarity index 100% rename from lua/dorm/mod/style/conceal/module.lua rename to lua/dorm/mod/.lua diff --git a/lua/dorm/mod/base/module.lua b/lua/dorm/mod/base/module.lua index 5a0ab8d..5091dc9 100644 --- a/lua/dorm/mod/base/module.lua +++ b/lua/dorm/mod/base/module.lua @@ -27,13 +27,20 @@ local mod = dorm.mod return mod.create_meta( -- "treesitter", + "base", + "encrypt", "autocmd", "notes", "maps", "cmd", "store", "code", + "metadata", + "capture", + "template", + "run", + "search", "todo", "ui", "calendar", diff --git a/lua/dorm/mod/capture/module.lua b/lua/dorm/mod/capture/module.lua new file mode 100644 index 0000000..f1075a4 --- /dev/null +++ b/lua/dorm/mod/capture/module.lua @@ -0,0 +1,61 @@ +local d = require("dorm") +local lib, mod = d.lib, d.mod + +local module = mod.create("capture") + +module.load = function() + mod.await("cmd", function(cmd) + cmd.add_commands_from_table({ + ["capture"] = { + subcommands = { + update = { + args = 0, + name = "capture.update" + }, + insert = { + name = "capture.insert", + args = 0, + }, + }, + name = "capture" + } + }) + end) +end + + + +module.setup = function() + return { + success = true, + requires = { + "workspace" + } + + } +end + +module.public = { + +} + +module.config.private = { + +} +module.config.public = { + +} +module.private = { + +} +module.events = {} + + +module.events.subscribed = { + cmd = { + ["capture.insert"] = true, + ["capture.update"] = true, + }, +} + +return module diff --git a/lua/dorm/mod/cmd/module.lua b/lua/dorm/mod/cmd/module.lua index f2bf839..319b59c 100644 --- a/lua/dorm/mod/cmd/module.lua +++ b/lua/dorm/mod/cmd/module.lua @@ -96,6 +96,7 @@ module.load = function() -- If the user passes no arguments or too few, we'll query them for the remainder using select_next_cmd_arg. vim.api.nvim_create_user_command("Dorm", module.private.command_callback, { desc = "The dorm command", + force = true, -- bang = true, nargs = "*", complete = module.private.generate_completions, diff --git a/lua/dorm/mod/style/module.lua b/lua/dorm/mod/completion/module.lua similarity index 100% rename from lua/dorm/mod/style/module.lua rename to lua/dorm/mod/completion/module.lua diff --git a/lua/dorm/mod/data/module.lua b/lua/dorm/mod/data/module.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/dorm/mod/encrypt/module.lua b/lua/dorm/mod/encrypt/module.lua new file mode 100644 index 0000000..8ce921b --- /dev/null +++ b/lua/dorm/mod/encrypt/module.lua @@ -0,0 +1,61 @@ +local d = require("dorm") +local lib, mod = d.lib, d.mod + +local module = mod.create("encrypt") + +module.load = function() + mod.await("cmd", function(cmd) + cmd.add_commands_from_table({ + ["encrypt"] = { + subcommands = { + update = { + args = 0, + name = "encrypt.update" + }, + insert = { + name = "encrypt.insert", + args = 0, + }, + }, + name = "encrypt" + } + }) + end) +end + + + +module.setup = function() + return { + success = true, + requires = { + "workspace" + } + + } +end + +module.public = { + +} + +module.config.private = { + +} +module.config.public = { + +} +module.private = { + +} +module.events = {} + + +module.events.subscribed = { + cmd = { + ["encrypt.insert"] = true, + ["encrypt.update"] = true, + }, +} + +return module diff --git a/lua/dorm/mod/conceal/base/module.lua b/lua/dorm/mod/icon/base/module.lua similarity index 100% rename from lua/dorm/mod/conceal/base/module.lua rename to lua/dorm/mod/icon/base/module.lua diff --git a/lua/dorm/mod/conceal/diamond/module.lua b/lua/dorm/mod/icon/diamond/module.lua similarity index 100% rename from lua/dorm/mod/conceal/diamond/module.lua rename to lua/dorm/mod/icon/diamond/module.lua diff --git a/lua/dorm/mod/conceal/module.lua b/lua/dorm/mod/icon/module.lua similarity index 100% rename from lua/dorm/mod/conceal/module.lua rename to lua/dorm/mod/icon/module.lua diff --git a/lua/dorm/mod/init.lua b/lua/dorm/mod/init.lua index 3dfb1ca..2b9b599 100644 --- a/lua/dorm/mod/init.lua +++ b/lua/dorm/mod/init.lua @@ -31,8 +31,7 @@ local utils = require("dorm.util") --- @field ["ui.text_popup"] Mi.text_popup --- Defines both a public and private configuration for a dorm module. ---- Public configurations may be tweaked by the user from the `dorm.setup()` function, ---- whereas private configurations are for internal use only. +--- Public configurations may be tweaked by the user from the `dorm.setup()` function, whereas private configurations are for internal use only. --- @class (exact) dorm.module.configuration --- @field custom? table Internal table that tracks the differences (changes) between the base `public` table and the new (altered) `public` table. It contains only the tables that the user has altered in their own configuration. --- @field public private? table Internal configuration variables that may be tweaked by the developer. diff --git a/lua/dorm/mod/lsp/module.lua b/lua/dorm/mod/lsp/module.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/dorm/mod/metadata/module.lua b/lua/dorm/mod/metadata/module.lua new file mode 100644 index 0000000..6101cec --- /dev/null +++ b/lua/dorm/mod/metadata/module.lua @@ -0,0 +1,61 @@ +local d = require("dorm") +local lib, mod = d.lib, d.mod + +local module = mod.create("metadata") + +module.load = function() + mod.await("cmd", function(cmd) + cmd.add_commands_from_table({ + ["metadata"] = { + subcommands = { + update = { + args = 0, + name = "metadata.update" + }, + insert = { + name = "metadata.insert", + args = 0, + }, + }, + name = "metadata" + } + }) + end) +end + + + +module.setup = function() + return { + success = true, + requires = { + "workspace" + } + + } +end + +module.public = { + +} + +module.config.private = { + +} +module.config.public = { + +} +module.private = { + +} +module.events = {} + + +module.events.subscribed = { + cmd = { + ["metadata.insert"] = true, + ["metadata.update"] = true, + }, +} + +return module diff --git a/lua/dorm/mod/notes/module.lua b/lua/dorm/mod/notes/module.lua index 02dac1e..5dc8b8e 100644 --- a/lua/dorm/mod/notes/module.lua +++ b/lua/dorm/mod/notes/module.lua @@ -252,7 +252,7 @@ module.private = { end -- If it's a .dorm file, also ensure it is a day entry - if dtype == "file" and string.match(dname, "%d%d%.dorm") then + if dtype == "file" and string.match(dname, "%d%d%.md") then -- Split the file name local file = vim.split(dname, ".", { plain = true }) @@ -291,7 +291,7 @@ module.private = { -- If it is a .dorm file, but it's not any user generated file. -- The match is here to avoid handling files made by the user, like a template file, or -- the toc file - if type == "file" and string.match(name, "%d+-%d+-%d+%.dorm") then + if type == "file" and string.match(name, "%d+-%d+-%d+%.md") then -- Split yyyy-mm-dd to a table local file = vim.split(name, ".", { plain = true }) local parts = vim.split(file[1], "-") @@ -395,7 +395,7 @@ module.config.public = { strategy = "nested", -- The name of the template file to use when running `:Dorm notes template`. - template_name = "template.dorm", + template_name = "template.md", -- Whether to apply the template file to new notes entries. use_template = true, @@ -409,8 +409,8 @@ module.config.public = { module.config.private = { strategies = { - flat = "%Y-%m-%d.dorm", - nested = "%Y" .. config.pathsep .. "%m" .. config.pathsep .. "%d.dorm", + flat = "%Y-%m-%d.md", + nested = "%Y" .. config.pathsep .. "%m" .. config.pathsep .. "%d.md", }, } diff --git a/lua/dorm/mod/preview/module.lua b/lua/dorm/mod/preview/module.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/dorm/mod/publish/module.lua b/lua/dorm/mod/publish/module.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/dorm/mod/run/module.lua b/lua/dorm/mod/run/module.lua new file mode 100644 index 0000000..2daddb1 --- /dev/null +++ b/lua/dorm/mod/run/module.lua @@ -0,0 +1,61 @@ +local d = require("dorm") +local lib, mod = d.lib, d.mod + +local module = mod.create("run") + +module.load = function() + mod.await("cmd", function(cmd) + cmd.add_commands_from_table({ + ["run"] = { + subcommands = { + update = { + args = 0, + name = "run.update" + }, + insert = { + name = "run.insert", + args = 0, + }, + }, + name = "run" + } + }) + end) +end + + + +module.setup = function() + return { + success = true, + requires = { + "workspace" + } + + } +end + +module.public = { + +} + +module.config.private = { + +} +module.config.public = { + +} +module.private = { + +} +module.events = {} + + +module.events.subscribed = { + cmd = { + ["run.insert"] = true, + ["run.update"] = true, + }, +} + +return module diff --git a/lua/dorm/mod/search/module.lua b/lua/dorm/mod/search/module.lua new file mode 100644 index 0000000..37d5d76 --- /dev/null +++ b/lua/dorm/mod/search/module.lua @@ -0,0 +1,61 @@ +local d = require("dorm") +local lib, mod = d.lib, d.mod + +local module = mod.create("search") + +module.load = function() + mod.await("cmd", function(cmd) + cmd.add_commands_from_table({ + ["search"] = { + subcommands = { + update = { + args = 0, + name = "search.update" + }, + insert = { + name = "search.insert", + args = 0, + }, + }, + name = "search" + } + }) + end) +end + + + +module.setup = function() + return { + success = true, + requires = { + "workspace" + } + + } +end + +module.public = { + +} + +module.config.private = { + +} +module.config.public = { + +} +module.private = { + +} +module.events = {} + + +module.events.subscribed = { + cmd = { + ["search.insert"] = true, + ["search.update"] = true, + }, +} + +return module diff --git a/lua/dorm/mod/style/hl/module.lua b/lua/dorm/mod/style/hl/module.lua deleted file mode 100644 index 8692ec7..0000000 --- a/lua/dorm/mod/style/hl/module.lua +++ /dev/null @@ -1,634 +0,0 @@ ---[[ - file: base-hl - title: No Colour Means no Productivity - summary: Manages your highlight groups with this module. - internal: true - --- -`base.hl` maps all possible highlight groups available throughout -dorm under a single tree of hl: `@dorm.*`. ---]] - -local dorm = require("dorm") -local lib, log, mod = dorm.lib, dorm.log, dorm.mod - -local module = mod.create("hl") - ---[[ ---]] -module.config.public = { - -- The TS hl for each dorm type. - -- - -- The `hl` table is a large collection of nested trees. At the leaves of each of these - -- trees is the final highlight to apply to that tree. For example: `"+@comment"` tells dorm to - -- link to an existing highlight group `@comment` (denoted by the `+` prefix). When no prefix is - -- found, the string is treated as arguments passed to `:highlight`, for example: `gui=bold - -- fg=#000000`. - -- - -- Nested trees concatenate, thus: - -- ```lua - -- tags = { - -- ranged_verbatim = { - -- begin = "+@comment", - -- }, - -- } - -- ``` - -- matches the highlight group: - -- ```lua - -- @dorm.tags.ranged_verbatim.begin - -- ``` - -- and converts into the following command: - -- ```vim - -- highlight! link @dorm.tags.ranged_verbatim.begin @comment - -- ``` - hl = { - -- hl displayed in dorm selection window popups. - selection_window = { - heading = "+@annotation", - arrow = "+@none", - key = "+@module", - keyname = "+@constant", - nestedkeyname = "+@string", - }, - - -- hl displayed in all sorts of tag types. - -- - -- These include: `@`, `.`, `|`, `#`, `+` and `=`. - tags = { - -- hl for the `@` verbatim tags. - ranged_verbatim = { - begin = "+@keyword", - - ["end"] = "+@keyword", - - name = { - [""] = "+@none", - delimiter = "+@none", - word = "+@keyword", - }, - - parameters = "+@type", - - document_meta = { - key = "+@variable.member", - value = "+@string", - number = "+@number", - trailing = "+@keyword.repeat", - title = "+@markup.heading", - description = "+@label", - authors = "+@annotation", - categories = "+@keyword", - created = "+@number.float", - updated = "+@number.float", - version = "+@number.float", - - object = { - bracket = "+@punctuation.bracket", - }, - - array = { - bracket = "+@punctuation.bracket", - value = "+@none", - }, - }, - }, - - -- hl for the carryover (`#`, `+`) tags. - carryover = { - begin = "+@label", - - name = { - [""] = "+@none", - word = "+@label", - delimiter = "+@none", - }, - - parameters = "+@string", - }, - - -- hl for the content of any tag named `comment`. - -- - -- Most prominent use case is for the `#comment` carryover tag. - comment = { - content = "+@comment", - }, - }, - - -- hl for each individual heading level. - headings = { - ["1"] = { - title = "+@attribute", - prefix = "+@attribute", - }, - ["2"] = { - title = "+@label", - prefix = "+@label", - }, - ["3"] = { - title = "+@constant", - prefix = "+@constant", - }, - ["4"] = { - title = "+@string", - prefix = "+@string", - }, - ["5"] = { - title = "+@label", - prefix = "+@label", - }, - ["6"] = { - title = "+@constructor", - prefix = "+@constructor", - }, - }, - - -- In case of errors in the syntax tree, use the following highlight. - error = "+Error", - - -- hl for definitions (`$ Definition`). - definitions = { - prefix = "+@punctuation.delimiter", - suffix = "+@punctuation.delimiter", - title = "+@markup.strong", - content = "+@markup.italic", - }, - - -- hl for footnotes (`^ My Footnote`). - footnotes = { - prefix = "+@punctuation.delimiter", - suffix = "+@punctuation.delimiter", - title = "+@markup.strong", - content = "+@markup.italic", - }, - - -- hl for TODO items. - -- - -- This strictly covers the `( )` component of any detached modifier. In other words, these - -- hl only bother with highlighting the brackets and the content within, but not the - -- object containing the TODO item itself. - todo_items = { - undone = "+@punctuation.delimiter", - pending = "+@module", - done = "+@string", - on_hold = "+@comment.note", - cancelled = "+NonText", - urgent = "+@comment.error", - uncertain = "+@boolean", - recurring = "+@keyword.repeat", - }, - - -- hl for all the possible levels of ordered and unordered lists. - lists = { - unordered = { prefix = "+@markup.list" }, - - ordered = { prefix = "+@keyword.repeat" }, - }, - - -- hl for all the possible levels of quotes. - quotes = { - ["1"] = { - prefix = "+@punctuation.delimiter", - content = "+@punctuation.delimiter", - }, - ["2"] = { - prefix = "+Blue", - content = "+Blue", - }, - ["3"] = { - prefix = "+Yellow", - content = "+Yellow", - }, - ["4"] = { - prefix = "+Red", - content = "+Red", - }, - ["5"] = { - prefix = "+Green", - content = "+Green", - }, - ["6"] = { - prefix = "+Brown", - content = "+Brown", - }, - }, - - -- hl for the anchor syntax: `[name]{location}`. - anchors = { - declaration = { - [""] = "+@markup.link.label", - delimiter = "+NonText", - }, - definition = { - delimiter = "+NonText", - }, - }, - - link = { - description = { - [""] = "+@markup.link.url", - delimiter = "+NonText", - }, - - file = { - [""] = "+@comment", - delimiter = "+NonText", - }, - - location = { - delimiter = "+NonText", - - url = "+@markup.link.url", - - generic = { - [""] = "+@type", - prefix = "+@type", - }, - - external_file = { - [""] = "+@label", - prefix = "+@label", - }, - - marker = { - [""] = "+@dorm.markers.title", - prefix = "+@dorm.markers.prefix", - }, - - definition = { - [""] = "+@dorm.definitions.title", - prefix = "+@dorm.definitions.prefix", - }, - - footnote = { - [""] = "+@dorm.footnotes.title", - prefix = "+@dorm.footnotes.prefix", - }, - - heading = { - ["1"] = { - [""] = "+@dorm.headings.1.title", - prefix = "+@dorm.headings.1.prefix", - }, - - ["2"] = { - [""] = "+@dorm.headings.2.title", - prefix = "+@dorm.headings.2.prefix", - }, - - ["3"] = { - [""] = "+@dorm.headings.3.title", - prefix = "+@dorm.headings.3.prefix", - }, - - ["4"] = { - [""] = "+@dorm.headings.4.title", - prefix = "+@dorm.headings.4.prefix", - }, - - ["5"] = { - [""] = "+@dorm.headings.5.title", - prefix = "+@dorm.headings.5.prefix", - }, - - ["6"] = { - [""] = "+@dorm.headings.6.title", - prefix = "+@dorm.headings.6.prefix", - }, - }, - }, - }, - - -- hl for inline markup. - -- - -- This is all the hl like `bold`, `italic` and so on. - markup = { - bold = { - [""] = "+@markup.strong", - delimiter = "+NonText", - }, - italic = { - [""] = "+@markup.italic", - delimiter = "+NonText", - }, - underline = { - [""] = "+@markup.underline", - delimiter = "+NonText", - }, - strikethrough = { - [""] = "+@markup.strikethrough", - delimiter = "+NonText", - }, - spoiler = { - [""] = "+@comment.error", - delimiter = "+NonText", - }, - subscript = { - [""] = "+@label", - delimiter = "+NonText", - }, - superscript = { - [""] = "+@number", - delimiter = "+NonText", - }, - variable = { - [""] = "+@function.macro", - delimiter = "+NonText", - }, - verbatim = { - delimiter = "+NonText", - }, - inline_comment = { - delimiter = "+NonText", - }, - inline_math = { - [""] = "+@markup.math", - delimiter = "+NonText", - }, - - free_form_delimiter = "+NonText", - }, - - -- hl for all the delimiter types. These include: - -- - `---` - the weak delimiter - -- - `===` - the strong delimiter - -- - `___` - the horizontal rule - delimiters = { - strong = "+@punctuation.delimiter", - weak = "+@punctuation.delimiter", - horizontal_line = "+@punctuation.delimiter", - }, - - -- Inline modifiers. - -- - -- This includes: - -- - `~` - the trailing modifier - -- - All link characters (`{`, `}`, `[`, `]`, `<`, `>`) - -- - The escape character (`\`) - modifiers = { - link = "+NonText", - escape = "+@type", - }, - - -- Rendered Latex, this will dictate the foreground color of latex images rendered via - -- base.latex.renderer - rendered = { - latex = "+Normal", - }, - }, - - -- Handles the dimming of certain highlight groups. - -- - -- It sometimes is favourable to use an existing highlight group, - -- but to dim or brighten it a little bit. - -- - -- To do so, you may use this table, which, similarly to the `hl` table, - -- will concatenate nested trees to form a highlight group name. - -- - -- The difference is, however, that the leaves of the tree are a table, not a single string. - -- This table has three possible fields: - -- - `reference` - which highlight to use as reference for the dimming. - -- - `percentage` - by how much to darken the reference highlight. This value may be between - -- `-100` and `100`, where negative percentages brighten the reference highlight, whereas - -- positive values dim the highlight by the given percentage. - dim = { - tags = { - ranged_verbatim = { - code_block = { - reference = "Normal", - percentage = 15, - affect = "background", - }, - }, - }, - - markup = { - verbatim = { - reference = "Normal", - percentage = 20, - }, - - inline_comment = { - reference = "Normal", - percentage = 40, - }, - }, - }, -} - -module.setup = function() - return { success = true, requires = { "autocmd" } } -end - -module.load = function() - module.required["autocmd"].enable_autocommand("BufEnter") - module.required["autocmd"].enable_autocommand("FileType") - module.required["autocmd"].enable_autocommand("ColorScheme", true) - - module.public.trigger_hl() - - vim.api.nvim_create_autocmd({ "FileType", "ColorScheme" }, { - callback = module.public.trigger_hl, - }) -end - ----@class base.hl -module.public = { - - --- Reads the hl configuration table and applies all defined hl - trigger_hl = function() - -- NOTE(vhyrro): This code was added here to work around oddities related to nvim-treesitter. - -- This code, with modern nvim-treesitter versions, will probably not break as harshly. - -- This code should be removed as soon as possible. - -- - -- do - -- local query = require("nvim-treesitter.query") - - -- if not query.has_hl("dorm") then - -- query.invalidate_query_cache() - - -- if not query.has_hl("dorm") then - -- log.error( - -- "nvim-treesitter has no available hl for dorm! Ensure treesitter is properly loaded in your config." - -- ) - -- end - -- end - - -- if vim.bo.filetype == "dorm" then - -- require("nvim-treesitter.highlight").attach(vim.api.nvim_get_current_buf(), "dorm") - -- end - -- end - - --- Recursively descends down the highlight configuration and applies every highlight accordingly - ---@param hl table #The table of hl to descend down - ---@param callback fun(hl_name: string, highlight: table, prefix: string): boolean? #A callback function to be invoked for every highlight. If it returns true then we should recurse down the table tree further ---@diagnostic disable-line -- TODO: type error workaround - ---@param prefix string #Should be only used by the function itself, acts as a "savestate" so the function can keep track of what path it has descended down - local function descend(hl, callback, prefix) - -- Loop through every highlight defined in the provided table - for hl_name, highlight in pairs(hl) do - -- If the callback returns true then descend further down the table tree - if callback(hl_name, highlight, prefix) then - descend(highlight, callback, prefix .. "." .. hl_name) - end - end - end - - -- Begin the descent down the public hl configuration table - descend(module.config.public.hl, function(hl_name, highlight, prefix) - -- If the type of highlight we have encountered is a table - -- then recursively descend down it as well - if type(highlight) == "table" then - return true - end - - -- Trim any potential leading and trailing whitespace - highlight = vim.trim(highlight) - - -- Check whether we are trying to link to an existing hl group - -- by checking for the existence of the + sign at the front - local is_link = highlight:sub(1, 1) == "+" - - local full_highlight_name = "@dorm" .. prefix .. (hl_name:len() > 0 and ("." .. hl_name) or "") - local does_hl_exist = lib.inline_pcall(vim.api.nvim_exec, "highlight " .. full_highlight_name, true) ---@diagnostic disable-line -- TODO: type error workaround - - -- If we are dealing with a link then link the hl together (excluding the + symbol) - if is_link then - -- If the highlight already exists then assume the user doesn't want it to be - -- overwritten - if does_hl_exist and does_hl_exist:len() > 0 and not does_hl_exist:match("xxx%s+cleared") then - return - end - - vim.api.nvim_set_hl(0, full_highlight_name, { - link = highlight:sub(2), - }) - else -- Otherwise simply apply the highlight options the user provided - -- If the highlight already exists then assume the user doesn't want it to be - -- overwritten - if does_hl_exist and does_hl_exist:len() > 0 then - return - end - - -- We have to use vim.cmd here - vim.cmd({ - cmd = "highlight", - args = { full_highlight_name, highlight }, - bang = true, - }) - end - end, "") - - -- Begin the descent down the dimming configuration table - descend(module.config.public.dim, function(hl_name, highlight, prefix) - -- If we don't have a percentage value then keep traversing down the table tree - if not highlight.percentage then - return true - end - - local full_highlight_name = "@dorm" .. prefix .. (hl_name:len() > 0 and ("." .. hl_name) or "") - local does_hl_exist = lib.inline_pcall(vim.api.nvim_exec, "highlight " .. full_highlight_name, true) ---@diagnostic disable-line -- TODO: type error workaround - - -- If the highlight already exists then assume the user doesn't want it to be - -- overwritten - if does_hl_exist and does_hl_exist:len() > 0 and not does_hl_exist:match("xxx%s+cleared") then - return - end - - -- Apply the dimmed highlight - vim.api.nvim_set_hl(0, full_highlight_name, { - [highlight.affect == "background" and "bg" or "fg"] = module.public.dim_color( - module.public.get_attribute( - highlight.reference or full_highlight_name, - highlight.affect or "foreground" - ), - highlight.percentage - ), - }) - end, "") - end, - - --- Takes in a table of hl and applies them to the current buffer - ---@param hl table #A table of hl - add_hl = function(hl) - module.config.public.hl = - vim.tbl_deep_extend("force", module.config.public.hl, hl or {}) - module.public.trigger_hl() - end, - - --- Takes in a table of items to dim and applies the dimming to them - ---@param dim table #A table of items to dim - add_dim = function(dim) - module.config.public.dim = vim.tbl_deep_extend("force", module.config.public.dim, dim or {}) - module.public.trigger_hl() - end, - - --- Assigns all dorm* hl to `clear` - clear_hl = function() - --- Recursively descends down the highlight configuration and clears every highlight accordingly - ---@param hl table #The table of hl to descend down - ---@param prefix string #Should be only used by the function itself, acts as a "savestate" so the function can keep track of what path it has descended down - local function descend(hl, prefix) - -- Loop through every defined highlight - for hl_name, highlight in pairs(hl) do - -- If it is a table then recursively traverse down it! - if type(highlight) == "table" then - descend(highlight, hl_name) - else -- Otherwise we're dealing with a string - -- Hence we should clear the highlight - vim.cmd("highlight! clear dorm" .. prefix .. hl_name) - end - end - end - - -- Begin the descent - descend(module.config.public.hl, "") - end, - - -- NOTE: Shamelessly taken and tweaked a little from akinsho's nvim-bufferline: - -- https://github.com/akinsho/nvim-bufferline.lua/blob/fec44821eededceadb9cc25bc610e5114510a364/lua/bufferline/colors.lua - -- <3 - get_attribute = function(name, attribute) - -- Attempt to get the highlight - local success, hl = pcall(vim.api.nvim_get_hl_by_name, name, true) ---@diagnostic disable-line -- TODO: type error workaround - - -- If we were successful and if the attribute exists then return it - if success and hl[attribute] then - return bit.tohex(hl[attribute], 6) - else -- Else log the message in a regular info() call, it's not an insanely important error - log.info("Unable to grab highlight for attribute", attribute, " - full error:", hl) - end - - return "NONE" - end, - - hex_to_rgb = function(hex_colour) - return tonumber(hex_colour:sub(1, 2), 16), tonumber(hex_colour:sub(3, 4), 16), tonumber(hex_colour:sub(5), 16) - end, - - dim_color = function(colour, percent) - if colour == "NONE" then - return colour - end - - local function alter(attr) - return math.floor(attr * (100 - percent) / 100) - end - - local r, g, b = module.public.hex_to_rgb(colour) - - if not r or not g or not b then - return "NONE" - end - - return string.format("#%02x%02x%02x", math.min(alter(r), 255), math.min(alter(g), 255), math.min(alter(b), 255)) - end, - - -- END of shamelessly ripped off akinsho code -} - -module.events.subscribed = { - ["autocmd"] = { - colorscheme = true, - bufenter = true, - }, -} - -return module diff --git a/lua/dorm/mod/template/module.lua b/lua/dorm/mod/template/module.lua new file mode 100644 index 0000000..bb44b74 --- /dev/null +++ b/lua/dorm/mod/template/module.lua @@ -0,0 +1,61 @@ +local d = require("dorm") +local lib, mod = d.lib, d.mod + +local module = mod.create("template") + +module.load = function() + mod.await("cmd", function(cmd) + cmd.add_commands_from_table({ + ["template"] = { + subcommands = { + update = { + args = 0, + name = "template.update" + }, + insert = { + name = "template.insert", + args = 0, + }, + }, + name = "template" + } + }) + end) +end + + + +module.setup = function() + return { + success = true, + requires = { + "workspace" + } + + } +end + +module.public = { + +} + +module.config.private = { + +} +module.config.public = { + +} +module.private = { + +} +module.events = {} + + +module.events.subscribed = { + cmd = { + ["template.insert"] = true, + ["template.update"] = true, + }, +} + +return module diff --git a/lua/dorm/mod/treesitter/module.lua b/lua/dorm/mod/treesitter/module.lua index 561cd32..2c6c899 100644 --- a/lua/dorm/mod/treesitter/module.lua +++ b/lua/dorm/mod/treesitter/module.lua @@ -87,7 +87,7 @@ module.load = function() -- luacheck: pop vim.api.nvim_create_autocmd("BufEnter", { - pattern = "*.dorm", + pattern = "*.md", once = true, callback = function() module.public.parser_path = vim.api.nvim_get_runtime_file("parser/dorm.so", false)[1] @@ -97,7 +97,7 @@ module.load = function() end if module.config.public.install_parsers then - require("nvim-treesitter.install").commands.TSInstallSync["run!"]("markdown", "dorm_meta") + require("nvim-treesitter.install").commands.TSInstallSync["run!"]("markdown", "markdown_inilne") module.public.parser_path = vim.api.nvim_get_runtime_file("parser/dorm.so", false)[1] else assert( diff --git a/lua/dorm/mod/workspace/module.lua b/lua/dorm/mod/workspace/module.lua index c08b945..1cde6af 100644 --- a/lua/dorm/mod/workspace/module.lua +++ b/lua/dorm/mod/workspace/module.lua @@ -125,6 +125,7 @@ module.config.public = { ---@type table workspaces = { default = require("pathlib").cwd(), + base = require("pathlib").cwd(), }, -- The name for the index file. --