Neorgcmd Module - nvim-neorg/neorg Wiki

Neorgcmd module for Neorg.

Summary

This module deals with handling everything related to the :Neorg command.

Overview

Usage

How to Apply

Configuration

No public configuration

Developer Usage

Public API

This segment will detail all of the functions core.neorgcmd exposes. All of these functions reside in the public table.

Examples

Adding a Neorg command

-- In your module.setup(), make sure to require core.neorgcmd (requires = { "core.neorgcmd" })
-- Afterwards in a function of your choice that gets called *after* core.neorgcmd gets intialized e.g. load():

module.load = function()
    module.required["core.neorgcmd"].add_commands_from_table({
        definitions = { -- Used for completion
            my_command = { -- Define a command called my_command
                my_subcommand = {}, -- Define a subcommand called my_subcommand
            },
        },
        data = { -- Metadata about our commands, should follow the same structure as the definitions table
            my_command = {
                min_args = 1, -- Tells neorgcmd that we want at least one argument for this command
                max_args = 1, -- Tells neorgcmd we want no more than one argument
                args = 1, -- Setting this variable instead would be the equivalent of min_args = 1 and max_args = 1

                subcommands = { -- Defines subcommands

                    -- Repeat the definition cycle again
                    my_subcommand = {
                        args = 0, -- We don't want any arguments
                        name = "my.command", -- The identifying name of this command

                        -- We do not define a subcommands table here because we don't have any more subcommands
                        -- Creating an empty subcommands table will cause errors so don't bother
                    },
                },
            },
        },
    })
end
-- Afterwards, you want to subscribe to the corresponding event:

module.events.subscribed = {
    ["core.neorgcmd"] = {
        ["my.command"] = true, -- Has the same name as our "name" variable had in the "data" table
    },
}

-- There's also another way to define your own custom commands that's a lot more automated. Such automation can be achieved
-- by putting your code in a special directory. That directory is in core.neorgcmd.commands. Creating your modules in this directory
-- will allow users to easily enable you as a "command module" without much hassle.

-- To enable a command in the commands/ directory, do this:

require("neorg").setup({
    load = {
        ["core.neorgcmd"] = {
            config = {
                load = {
                    "some.neorgcmd", -- The name of a valid command
                },
            },
        },
    },
})

-- And that's it! You're good to go.
-- Want to find out more? Read the wiki entry! https://github.com/vhyrro/neorg/wiki/Neorg-Command

Extra Info

Version

This module supports at least version 0.0.9. The current Neorg version is 0.0.9.

Imports

This module does not import any other files.

Requires

This module does not require any other modules to operate.

Required by