Skip to content

Commit

Permalink
fix: don't autoload core.neorgcmd nor core.keybinds as dependenci…
Browse files Browse the repository at this point in the history
…es of other modules (#1051)
  • Loading branch information
vhyrro committed Sep 23, 2023
1 parent 114d125 commit 62ba931
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 133 deletions.
36 changes: 21 additions & 15 deletions lua/neorg/modules/core/dirman/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local module = modules.create("core.dirman")
module.setup = function()
return {
success = true,
requires = { "core.autocommands", "core.neorgcmd", "core.keybinds", "core.ui", "core.storage" },
requires = { "core.autocommands", "core.ui", "core.storage" },
}
end

Expand All @@ -54,17 +54,21 @@ module.load = function()
module.config.public.workspaces[name] = vim.fn.expand(workspace_location)
end

module.required["core.keybinds"].register_keybind(module.name, "new.note")
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybind(module.name, "new.note")
end)

-- Used to detect when we've entered a buffer with a potentially different cwd
module.required["core.autocommands"].enable_autocommand("BufEnter", true)

module.required["core.neorgcmd"].add_commands_from_table({
index = {
args = 0,
name = "dirman.index",
},
})
modules.await("core.neorgcmd", function(neorgcmd)
neorgcmd.add_commands_from_table({
index = {
args = 0,
name = "dirman.index",
},
})
end)

-- Synchronize core.neorgcmd autocompletions
module.public.sync()
Expand Down Expand Up @@ -251,13 +255,15 @@ module.public = {
local workspace_names = module.public.get_workspace_names()

-- Add the command to core.neorgcmd so it can be used by the user!
module.required["core.neorgcmd"].add_commands_from_table({
workspace = {
max_args = 1,
name = "dirman.workspace",
complete = { workspace_names },
},
})
modules.await("core.neorgcmd", function(neorgcmd)
neorgcmd.add_commands_from_table({
workspace = {
max_args = 1,
name = "dirman.workspace",
complete = { workspace_names },
},
})
end)
end,
--- Takes in a path (can include directories) and creates a .norg file from that path
---@param path string a path to place the .norg file in
Expand Down
5 changes: 3 additions & 2 deletions lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.setup = function()
return {
success = true,
requires = {
"core.keybinds",
"core.integrations.treesitter",
"core.ui",
"core.dirman.utils",
Expand All @@ -29,7 +28,9 @@ module.setup = function()
end

module.load = function()
module.required["core.keybinds"].register_keybind(module.name, "hop-link")
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybind(module.name, "hop-link")
end)
end

module.config.public = {
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/esupports/metagen/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ local function fill_template_defaults()
end

module.setup = function()
return { requires = { "core.autocommands", "core.keybinds", "core.integrations.treesitter" } }
return { requires = { "core.autocommands", "core.integrations.treesitter" } }
end

module.config.public = {
Expand Down
23 changes: 12 additions & 11 deletions lua/neorg/modules/core/integrations/treesitter/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.private = {
}

module.setup = function()
return { success = true, requires = { "core.highlights", "core.mode", "core.keybinds", "core.neorgcmd" } }
return { success = true, requires = { "core.highlights", "core.mode" } }
end

module.load = function()
Expand All @@ -65,12 +65,14 @@ module.load = function()
install_info = module.config.public.parser_configs.norg_meta,
}

module.required["core.neorgcmd"].add_commands_from_table({
["sync-parsers"] = {
args = 0,
name = "sync-parsers",
},
})
modules.await("core.neorgcmd", function(neorgcmd)
neorgcmd.add_commands_from_table({
["sync-parsers"] = {
args = 0,
name = "sync-parsers",
},
})
end)

-- luacheck: pop

Expand Down Expand Up @@ -100,10 +102,9 @@ module.load = function()
module.private.ts_utils = ts_utils

module.required["core.mode"].add_mode("traverse-heading")
module.required["core.keybinds"].register_keybinds(
module.name,
{ "next.heading", "previous.heading", "next.link", "previous.link" }
)
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybinds(module.name, { "next.heading", "previous.heading", "next.link", "previous.link" })
end)
end

module.config.public = {
Expand Down
5 changes: 3 additions & 2 deletions lua/neorg/modules/core/itero/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ local module = modules.create("core.itero")
module.setup = function()
return {
requires = {
"core.keybinds",
"core.integrations.treesitter",
},
}
Expand Down Expand Up @@ -76,7 +75,9 @@ module.config.private = {
}

module.load = function()
module.required["core.keybinds"].register_keybinds(module.name, { "next-iteration", "stop-iteration" })
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybinds(module.name, { "next-iteration", "stop-iteration" })
end)
end

module.on_event = function(event)
Expand Down
40 changes: 20 additions & 20 deletions lua/neorg/modules/core/journal/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ module.setup = function()
success = true,
requires = {
"core.dirman",
"core.keybinds",
"core.neorgcmd",
"core.integrations.treesitter",
},
}
Expand Down Expand Up @@ -423,27 +421,29 @@ module.load = function()
module.config.public.strategy = module.config.private.strategies[module.config.public.strategy]
end

module.required["core.neorgcmd"].add_commands_from_table({
journal = {
min_args = 1,
max_args = 2,
subcommands = {
tomorrow = { args = 0, name = "journal.tomorrow" },
yesterday = { args = 0, name = "journal.yesterday" },
today = { args = 0, name = "journal.today" },
custom = { max_args = 1, name = "journal.custom" }, -- format :yyyy-mm-dd
template = { args = 0, name = "journal.template" },
toc = {
args = 1,
name = "journal.toc",
subcommands = {
open = { args = 0, name = "journal.toc.open" },
update = { args = 0, name = "journal.toc.update" },
modules.await("core.neorgcmd", function(neorgcmd)
neorgcmd.add_commands_from_table({
journal = {
min_args = 1,
max_args = 2,
subcommands = {
tomorrow = { args = 0, name = "journal.tomorrow" },
yesterday = { args = 0, name = "journal.yesterday" },
today = { args = 0, name = "journal.today" },
custom = { max_args = 1, name = "journal.custom" }, -- format :yyyy-mm-dd
template = { args = 0, name = "journal.template" },
toc = {
args = 1,
name = "journal.toc",
subcommands = {
open = { args = 0, name = "journal.toc.open" },
update = { args = 0, name = "journal.toc.update" },
},
},
},
},
},
})
})
end)
end

module.on_event = function(event)
Expand Down
5 changes: 3 additions & 2 deletions lua/neorg/modules/core/looking-glass/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ module.setup = function()
return {
success = true,
requires = {
"core.keybinds",
"core.integrations.treesitter",
"core.ui",
},
}
end

module.load = function()
module.required["core.keybinds"].register_keybind(module.name, "magnify-code-block")
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybind(module.name, "magnify-code-block")
end)
end

module.public = {
Expand Down
32 changes: 15 additions & 17 deletions lua/neorg/modules/core/presenter/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ module.setup = function()
"core.integrations.treesitter",
"core.ui",
"core.mode",
"core.keybinds",
"core.neorgcmd",
},
}
end

module.load = function()
local error_loading = false

---@type core.keybinds
---@diagnostic disable-next-line: unused-local
local keybinds = module.required["core.keybinds"]

if module.config.public.zen_mode == "truezen" then
modules.load_module("core.integrations.truezen")
elseif module.config.public.zen_mode == "zen-mode" then
Expand All @@ -55,18 +49,22 @@ module.load = function()
return
end

keybinds.register_keybinds(module.name, { "next_page", "previous_page", "close" })
-- Add neorgcmd capabilities
module.required["core.neorgcmd"].add_commands_from_table({
presenter = {
args = 1,
condition = "norg",
subcommands = {
start = { args = 0, name = "presenter.start" },
close = { args = 0, name = "presenter.close" },
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybinds(module.name, { "next_page", "previous_page", "close" })
end)

modules.await("core.neorgcmd", function(neorgcmd)
neorgcmd.add_commands_from_table({
presenter = {
args = 1,
condition = "norg",
subcommands = {
start = { args = 0, name = "presenter.start" },
close = { args = 0, name = "presenter.close" },
},
},
},
})
})
end)
end

module.config.public = {
Expand Down
25 changes: 13 additions & 12 deletions lua/neorg/modules/core/promo/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,25 @@ module.setup = function()
success = true,
requires = {
"core.integrations.treesitter",
"core.keybinds",
},
}
end

module.load = function()
module.required["core.keybinds"].register_keybinds(
module.name,
(function()
local keys = vim.tbl_keys(module.events.subscribed["core.keybinds"])

for i, key in ipairs(keys) do
keys[i] = key:sub(module.name:len() + 2)
end
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybinds(
module.name,
(function()
local keys = vim.tbl_keys(module.events.subscribed["core.keybinds"])

for i, key in ipairs(keys) do
keys[i] = key:sub(module.name:len() + 2)
end

return keys
end)()
)
return keys
end)()
)
end)
end

module.private = {
Expand Down
26 changes: 14 additions & 12 deletions lua/neorg/modules/core/qol/todo_items/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ local log, modules = neorg.log, neorg.modules
local module = modules.create("core.qol.todo_items")

module.setup = function()
return { success = true, requires = { "core.keybinds", "core.integrations.treesitter" } }
return { success = true, requires = { "core.integrations.treesitter" } }
end

module.load = function()
module.required["core.keybinds"].register_keybinds(
module.name,
(function()
local keys = vim.tbl_keys(module.events.subscribed["core.keybinds"])

for i, key in ipairs(keys) do
keys[i] = key:sub(module.name:len() + 2)
end
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybinds(
module.name,
(function()
local keys = vim.tbl_keys(module.events.subscribed["core.keybinds"])

for i, key in ipairs(keys) do
keys[i] = key:sub(module.name:len() + 2)
end

return keys
end)()
)
return keys
end)()
)
end)
end

module.config.public = {
Expand Down
19 changes: 10 additions & 9 deletions lua/neorg/modules/core/summary/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ local module = modules.create("core.summary")
module.setup = function()
return {
sucess = true,
requires = { "core.neorgcmd", "core.integrations.treesitter" },
requires = { "core.integrations.treesitter" },
}
end

module.load = function()
module.required["core.neorgcmd"].add_commands_from_table({
["generate-workspace-summary"] = {
args = 0,
condition = "norg",
name = "summary.summarize",
},
})

modules.await("core.neorgcmd", function(neorgcmd)
neorgcmd.add_commands_from_table({
["generate-workspace-summary"] = {
args = 0,
condition = "norg",
name = "summary.summarize",
},
})
end)
local ts = module.required["core.integrations.treesitter"]

module.config.public.strategy = lib.match(module.config.public.strategy)({
Expand Down
Loading

0 comments on commit 62ba931

Please sign in to comment.