Add -docstring option to the 'def' command

used defined commands can have their own documentation strings
This commit is contained in:
Maxime Coste 2014-02-19 03:40:52 +00:00
parent 4b9d49d7ab
commit aab390ab92
2 changed files with 7 additions and 1 deletions

View File

@ -789,6 +789,7 @@ def can also takes some flags:
* +-allow-override+: allow the new command to replace an exisiting one
with the same name.
* +-hidden+: do not show the command in command name completions
* +-docstring+: define the documentation string for the command
Using shell expansion permits to define complex commands or to access
Kakoune state:

View File

@ -588,6 +588,10 @@ void define_command(const ParametersParser& parser, Context& context)
if (parser.has_option("hidden"))
flags = CommandFlags::Hidden;
String docstring;
if (parser.has_option("docstring"))
docstring = parser.option_value("docstring");
String commands = parser[1];
Command cmd;
ParameterDesc desc;
@ -645,7 +649,7 @@ void define_command(const ParametersParser& parser, Context& context)
return Completions{ 0_byte, params[token_to_complete].length(), split(output, '\n') };
};
}
CommandManager::instance().register_command(cmd_name, cmd, "", desc, flags, completer);
CommandManager::instance().register_command(cmd_name, cmd, std::move(docstring), desc, flags, completer);
}
const CommandDesc define_command_cmd = {
@ -658,6 +662,7 @@ const CommandDesc define_command_cmd = {
{ "allow-override", { false, "allow overriding existing command" } },
{ "file-completion", { false, "complete parameters using filename completion" } },
{ "hidden", { false, "do not display the command as completion candidate" } },
{ "docstring", { true, "set docstring for command" } },
{ "shell-completion", { true, "complete the parameters using the given shell-script" } } },
ParameterDesc::Flags::None,
2, 2