Skip to content

Commit 560d5a0

Browse files
committed
refactor(neorgcmd)!: slowly move away from the deprecated commands directory
1 parent e7f524c commit 560d5a0

File tree

4 files changed

+76
-131
lines changed

4 files changed

+76
-131
lines changed

lua/neorg/core/modules.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,10 @@ function modules.load_module(module_name, cfg)
445445
local fallback_exists, fallback_module = pcall(require, "neorg.modules." .. module_name)
446446

447447
if not fallback_exists then
448-
log.error("Unable to load module", module_name, "-", module)
448+
log.error(
449+
"Unable to load module '" .. module_name .. "'. The module probably does not exist! Stacktrace: ",
450+
module
451+
)
449452
return false
450453
end
451454

lua/neorg/modules/core/neorgcmd/commands/module/list/module.lua

-78
This file was deleted.

lua/neorg/modules/core/neorgcmd/commands/module/load/module.lua

-48
This file was deleted.

lua/neorg/modules/core/neorgcmd/module.lua

+72-4
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,28 @@ module.config.public = {
121121
--
122122
-- This feature will soon be deprecated, so it is not recommended to touch it.
123123
default = {
124-
"module.list",
125-
"module.load",
126124
"return",
127125
},
128126
}
129127

130128
---@class core.neorgcmd
131129
module.public = {
132130
-- The table containing all the functions. This can get a tad complex so I recommend you read the wiki entry
133-
neorg_commands = {},
131+
neorg_commands = {
132+
module = {
133+
subcommands = {
134+
load = {
135+
args = 1,
136+
name = "module.load",
137+
},
138+
139+
list = {
140+
args = 0,
141+
name = "module.list",
142+
},
143+
},
144+
},
145+
},
134146

135147
--- Recursively merges the contents of the module's config.public.funtions table with core.neorgcmd's module.config.public.neorg_commands table.
136148
---@param module_name string #An absolute path to a loaded module with a module.config.public.neorg_commands table following a valid structure
@@ -233,7 +245,7 @@ module.private = {
233245
return
234246
elseif not check_condition(ref.condition) then
235247
log.error(
236-
("Error when executing `:Neorg %s` - the command is currently disabled. Some commands will only become available under certain conditions!"):format(
248+
("Error when executing `:Neorg %s` - the command is currently disabled. Some commands will only become available under certain conditions, e.g. being within a `.norg` file!"):format(
237249
table.concat(vim.list_slice(args, 1, i), " ")
238250
)
239251
)
@@ -421,4 +433,60 @@ module.private = {
421433

422434
module.neorg_post_load = module.public.sync
423435

436+
module.on_event = function(event)
437+
if event.type == "core.neorgcmd.events.module.load" then
438+
modules.load_module(event.content[1])
439+
end
440+
441+
if event.type == "core.neorgcmd.events.module.list" then
442+
if not neorg.modules.is_module_loaded("core.ui") then
443+
log.error(":Neorg module list requires the `core.ui` module to be loaded!")
444+
return
445+
end
446+
447+
local lines = {
448+
-- modules.get_module_config("core.concealer").icons.heading.level_1.icon
449+
"*"
450+
.. " "
451+
.. "Loaded Neorg Modules",
452+
}
453+
454+
for _, mod in pairs(modules.loaded_modules) do
455+
table.insert(lines, " - `" .. mod.name .. "`")
456+
end
457+
458+
-- FIXME(vhyrro): This creates a listed buffer which makes things very ugly.
459+
-- Also make sure to disable folds in this view.
460+
local buf = neorg.modules.get_module("core.ui").create_norg_buffer("module_list", "nosplit")
461+
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
462+
vim.keymap.set("n", "q", vim.cmd.quit, { buffer = buf, silent = true, nowait = true })
463+
464+
local width = vim.api.nvim_win_get_width(0)
465+
local height = vim.api.nvim_win_get_height(0)
466+
467+
vim.api.nvim_open_win(buf, true, {
468+
relative = "win",
469+
win = 0,
470+
width = math.floor(width * 0.7),
471+
height = math.floor(height * 0.9),
472+
col = math.floor(width * 0.15),
473+
row = math.floor(height * 0.05),
474+
border = "single",
475+
style = "minimal",
476+
})
477+
478+
vim.bo[buf].modifiable = false
479+
vim.bo[buf].filetype = "norg"
480+
481+
vim.api.nvim_buf_set_name(buf, "loaded_modules.norg")
482+
end
483+
end
484+
485+
module.events.subscribed = {
486+
["core.neorgcmd"] = {
487+
["module.load"] = true,
488+
["module.list"] = true,
489+
},
490+
}
491+
424492
return module

0 commit comments

Comments
 (0)