Skip to content

Commit

Permalink
chore: format with stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jul 13, 2024
1 parent 5bef42a commit 909776f
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 71 deletions.
112 changes: 67 additions & 45 deletions docgen/docgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,20 @@ docgen.generators = {
"",
"### Further Reading",
"",
docgen.lookup_modules(mods, "To find out how to rebind the available keys consult the [`core.keybinds`](@core.keybinds) wiki entry."),
docgen.lookup_modules(
mods,
"To find out how to rebind the available keys consult the [`core.keybinds`](@core.keybinds) wiki entry."
),
"",
}

local main_preset = "neorg"

for preset_name, preset_data in vim.spairs(keybind_data) do
table.insert(layout, string.format("## Preset `%s`%s", preset_name, preset_name == main_preset and " (default)" or ""))
table.insert(
layout,
string.format("## Preset `%s`%s", preset_name, preset_name == main_preset and " (default)" or "")
)
table.insert(layout, "")

for neorg_mode_name, neorg_mode_data in vim.spairs(preset_data) do
Expand All @@ -583,9 +589,11 @@ docgen.generators = {

for key, data in vim.spairs(mode_data) do
if not vim.tbl_isempty(data.comments) then
local comments = vim.iter(data.comments):map(function(comment)
return (comment:gsub("^%s*%-%-%s*", ""))
end):totable()
local comments = vim.iter(data.comments)
:map(function(comment)
return (comment:gsub("^%s*%-%-%s*", ""))
end)
:totable()

local mnemonic = docgen.extract_mnemonic(comments)

Expand All @@ -599,7 +607,10 @@ docgen.generators = {
table.insert(layout, string.format("- `%s` - %s", key, description))
table.insert(layout, string.format(" - Default map: `%s`", data.rhs))
if mnemonic then
table.insert(layout, string.format(" - Mnemonic: %s", docgen.format_mnemonic(mnemonic)))
table.insert(
layout,
string.format(" - Mnemonic: %s", docgen.format_mnemonic(mnemonic))
)
end

table.insert(layout, "")
Expand All @@ -610,7 +621,7 @@ docgen.generators = {
end

return layout
end
end,
}

--- Check the integrity of the description comments found in configuration blocks
Expand Down Expand Up @@ -788,55 +799,66 @@ end
---@param buffer number The buffer ID to extract information from.
---@return table<string, table>
docgen.parse_keybind_data = function(buffer)
local query = utils.ts_parse_query("lua", [[
local query = utils.ts_parse_query(
"lua",
[[
(field
name: (identifier) @_ident
(#eq? @_ident "presets")) @presets
]])

local root = assert(vim.treesitter.get_parser(buffer, "lua"):parse()[1]:root(), "unable to parse keybinds!")

local _, presets = query:iter_captures(root, buffer)()
assert(presets, "could not find presets")

local available_keys = neorg.modules.loaded_modules["core.keybinds"].private.presets

local output = vim.defaulttable()

for preset in presets:named_child(1):iter_children() do
if preset:type() == "field" then
local preset_name, preset_data = vim.treesitter.get_node_text(assert(preset:named_child(0)), buffer), preset:named_child(1)

for neorg_mode in assert(preset_data):iter_children() do
if neorg_mode:type() == "field" then
local neorg_mode_name, neorg_mode_data = vim.treesitter.get_node_text(assert(neorg_mode:named_child(0)), buffer), neorg_mode:named_child(1)

for neovim_mode in assert(neorg_mode_data):iter_children() do
if neovim_mode:type() == "field" then
local mode_name, mode_data = vim.treesitter.get_node_text(assert(neovim_mode:named_child(0)), buffer), neovim_mode:named_child(1)

local comments = {}
local i, keybind_data
]]
)

for comment_or_data in assert(mode_data):iter_children() do
if comment_or_data:type() == "comment" then
table.insert(comments, vim.trim(vim.treesitter.get_node_text(comment_or_data, buffer)))
elseif comment_or_data:type() == "field" then
i, keybind_data = next(available_keys[preset_name][neorg_mode_name][mode_name], i)
output[preset_name][neorg_mode_name][mode_name][keybind_data[1]] = {
comments = comments,
rhs = keybind_data[2],
}
comments = {}
end
local root = assert(vim.treesitter.get_parser(buffer, "lua"):parse()[1]:root(), "unable to parse keybinds!")

local _, presets = query:iter_captures(root, buffer)()
assert(presets, "could not find presets")

local available_keys = neorg.modules.loaded_modules["core.keybinds"].private.presets

local output = vim.defaulttable()

for preset in presets:named_child(1):iter_children() do
if preset:type() == "field" then
local preset_name, preset_data =
vim.treesitter.get_node_text(assert(preset:named_child(0)), buffer), preset:named_child(1)

for neorg_mode in assert(preset_data):iter_children() do
if neorg_mode:type() == "field" then
local neorg_mode_name, neorg_mode_data =
vim.treesitter.get_node_text(assert(neorg_mode:named_child(0)), buffer),
neorg_mode:named_child(1)

for neovim_mode in assert(neorg_mode_data):iter_children() do
if neovim_mode:type() == "field" then
local mode_name, mode_data =
vim.treesitter.get_node_text(assert(neovim_mode:named_child(0)), buffer),
neovim_mode:named_child(1)

local comments = {}
local i, keybind_data

for comment_or_data in assert(mode_data):iter_children() do
if comment_or_data:type() == "comment" then
table.insert(
comments,
vim.trim(vim.treesitter.get_node_text(comment_or_data, buffer))
)
elseif comment_or_data:type() == "field" then
i, keybind_data = next(available_keys[preset_name][neorg_mode_name][mode_name], i)
output[preset_name][neorg_mode_name][mode_name][keybind_data[1]] = {
comments = comments,
rhs = keybind_data[2],
}
comments = {}
end
end
end
end
end
end
end
return output
end
return output
end

docgen.format_mnemonic = function(str)
Expand Down
8 changes: 7 additions & 1 deletion docgen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ end

-- Non-module pages have their own dedicated generators
fileio.write_to_wiki("Home", docgen.generators.homepage(doc_modules))
fileio.write_to_wiki("Default-Keybinds", docgen.generators.keybinds(doc_modules, docgen.open_file(vim.fn.fnamemodify("../lua/neorg/modules/core/keybinds/module.lua", ":p"))))
fileio.write_to_wiki(
"Default-Keybinds",
docgen.generators.keybinds(
doc_modules,
docgen.open_file(vim.fn.fnamemodify("../lua/neorg/modules/core/keybinds/module.lua", ":p"))
)
)
fileio.write_to_wiki("_Sidebar", docgen.generators.sidebar(doc_modules))

-- Loop through all modules and generate their respective wiki files
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/dirman/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ module.public = {
end
end)
end
end
end,
}

module.on_event = function(event)
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ module.public = {
local parsed_link = module.public.parse_link(link_node_at_cursor)

module.public.follow_link(link_node_at_cursor, split_mode, parsed_link)
end
end,
}

module.private = {
Expand Down
26 changes: 21 additions & 5 deletions lua/neorg/modules/core/keybinds/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ module.private = {
},

-- Promote an object non-recursively.
{ ">.", "<Plug>(neorg.promo.promote)", opts = { desc = "[neorg] Promote Object (Non-Recursively)" } },
{
">.",
"<Plug>(neorg.promo.promote)",
opts = { desc = "[neorg] Promote Object (Non-Recursively)" },
},
-- Demote an object non-recursively.
{ "<,", "<Plug>(neorg.promo.demote)", opts = { desc = "[neorg] Demote Object (Non-Recursively)" } },

Expand All @@ -246,7 +250,11 @@ module.private = {
opts = { desc = "[neorg] Promote Object (Recursively)" },
},
-- Demote an object recursively.
{ "<<", "<Plug>(neorg.promo.demote.nested)", opts = { desc = "[neorg] Demote Object (Recursively)" } },
{
"<<",
"<Plug>(neorg.promo.demote.nested)",
opts = { desc = "[neorg] Demote Object (Recursively)" },
},

-- Toggle a list from ordered <-> unordered
-- ^List Toggle
Expand All @@ -273,14 +281,22 @@ module.private = {

i = {
-- Promote an object recursively.
{ "<C-t>", "<Plug>(neorg.promo.promote)", opts = { desc = "[neorg] Promote Object (Recursively)" } },
{
"<C-t>",
"<Plug>(neorg.promo.promote)",
opts = { desc = "[neorg] Promote Object (Recursively)" },
},
-- Demote an object recursively.
{ "<C-d>", "<Plug>(neorg.promo.demote)", opts = { desc = "[neorg] Demote Object (Recursively)" } },
-- Create an iteration of e.g. a list item.
{ "<M-CR>", "<Plug>(neorg.itero.next-iteration)", opts = { desc = "[neorg] Continue Object" } },
-- Insert a link to a date at the current cursor position.
-- ^Date
{ "<M-d>", "<Plug>(neorg.tempus.insert-date-insert-mode)", opts = { desc = "[neorg] Insert Date" } },
{
"<M-d>",
"<Plug>(neorg.tempus.insert-date-insert-mode)",
opts = { desc = "[neorg] Insert Date" },
},
},

v = {
Expand All @@ -289,7 +305,7 @@ module.private = {
-- Demote objects in range.
{ "<", "<Plug>(neorg.promo.demote.range)", opts = { desc = "[neorg] Demote Objects in Range" } },
},
}
},
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions lua/neorg/modules/core/looking-glass/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ module.public = {
})
end,

magnify_code_block = function ()
magnify_code_block = function()
local buffer = vim.api.nvim_get_current_buf()
local window = vim.api.nvim_get_current_win()

Expand Down Expand Up @@ -263,7 +263,7 @@ module.public = {
vsplit,
vim.api.nvim_get_current_win()
)
end
end,
}

return module
5 changes: 1 addition & 4 deletions lua/neorg/modules/core/pivot/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ module.public = {
local buffer = vim.api.nvim_get_current_buf()
local cursor = vim.api.nvim_win_get_cursor(0)

local node = module.required["core.integrations.treesitter"].get_first_node_on_line(
buffer,
cursor[1] - 1
)
local node = module.required["core.integrations.treesitter"].get_first_node_on_line(buffer, cursor[1] - 1)

if not node then
log.error("No node found under the cursor! Make sure your cursor is in a list.")
Expand Down
14 changes: 7 additions & 7 deletions lua/neorg/modules/core/tempus/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ module.public = {
prompt = "Date: ",
}, callback)
end
end
end,
}

module.private = {
Expand All @@ -450,12 +450,12 @@ module.private = {
end

return vim.trim(
d(date_table.weekday and date_table.weekday.name)
.. d(date_table.day)
.. d(date_table.month and date_table.month.name)
.. d(date_table.year and string.format("%04d", date_table.year))
.. d(date_table.time and tostring(date_table.time))
.. d(date_table.timezone)
d(date_table.weekday and date_table.weekday.name)
.. d(date_table.day)
.. d(date_table.month and date_table.month.name)
.. d(date_table.year and string.format("%04d", date_table.year))
.. d(date_table.time and tostring(date_table.time))
.. d(date_table.timezone)
)
end,
})
Expand Down
30 changes: 25 additions & 5 deletions lua/neorg/modules/core/text-objects/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,31 @@ module.load = function()
ts = module.required["core.integrations.treesitter"]
vim.keymap.set("", "<Plug>(neorg.text-objects.item-up)", module.public.move_up)
vim.keymap.set("", "<Plug>(neorg.text-objects.item-down)", module.public.move_down)
vim.keymap.set("", "<Plug>(neorg.text-objects.textobject.heading.outer)", lib.wrap(module.public.highlight_node, "heading.outer"))
vim.keymap.set("", "<Plug>(neorg.text-objects.textobject.heading.inner)", lib.wrap(module.public.highlight_node, "heading.inner"))
vim.keymap.set("", "<Plug>(neorg.text-objects.textobject.tag.inner)", lib.wrap(module.public.highlight_node, "tag.inner"))
vim.keymap.set("", "<Plug>(neorg.text-objects.textobject.tag.outer)", lib.wrap(module.public.highlight_node, "tag.outer"))
vim.keymap.set("", "<Plug>(neorg.text-objects.textobject.list.outer)", lib.wrap(module.public.highlight_node, "lits.outer"))
vim.keymap.set(
"",
"<Plug>(neorg.text-objects.textobject.heading.outer)",
lib.wrap(module.public.highlight_node, "heading.outer")
)
vim.keymap.set(
"",
"<Plug>(neorg.text-objects.textobject.heading.inner)",
lib.wrap(module.public.highlight_node, "heading.inner")
)
vim.keymap.set(
"",
"<Plug>(neorg.text-objects.textobject.tag.inner)",
lib.wrap(module.public.highlight_node, "tag.inner")
)
vim.keymap.set(
"",
"<Plug>(neorg.text-objects.textobject.tag.outer)",
lib.wrap(module.public.highlight_node, "tag.outer")
)
vim.keymap.set(
"",
"<Plug>(neorg.text-objects.textobject.list.outer)",
lib.wrap(module.public.highlight_node, "lits.outer")
)
end

module.config.public = {
Expand Down

0 comments on commit 909776f

Please sign in to comment.