Description

Mark a method as an interactive command.

Mark a public method with the Command attribute.

The method HelloX requires a string and returns a string. The [Command] attribute marks it as an interactive command to Minibuffer by the name 'hello-x', which can be executed by typing M-x hello-x. Minibuffer will then prompt the user String name: . Suppose the user responds Mary. The method will return a string "Hello, Mary", and Minibuffer will show this as a message Hello, Mary.

public string HelloX(string name) {
return "Hello, " + name;
}
command-case.png
Command case setting
Note
The naming convention for commands may be set to PascalCase, camelCase, and kebab-case, or as-is. So the HelloX command name would be "HelloX", "helloX", or "hello-x" respectively. See CanonizeCommand for more details.

Registering with Minibuffer

Classes do have to register with Minibuffer.

void Start() {
Minibuffer.Register(this);
}

Specify the command name

Type M-x hi to run the following command.

[Command("hi")]
public string HelloY(string name) {
return "Hello, " + name;
}

Provide a description

Explain what a command does in its description that is used in various help commands like M-x describe-command and M-x describe-bindings.

[Command("hi-there", description = "Say hello to X.") ]
public string HelloW(string name) {
return "Hello, " + name;
}

See its description by typing M-x describe-command hi-there.

hi-there is not bound to any keys.
Description: "Say hello to X."
It is defined in class ExampleCommands.
String HelloW(String str)

Set a key binding

Bind a key to the command. Run the command M-x hello-z or by typing C-h w.

[Command(keyBinding = "C-h w")]
public string HelloZ(string name) {
return "Hello, " + name;
}

See listing of all builtin Commands, or type C-h c all.

Prompts

The default prompt for each command argument is "<type> <argument-name>: ". This can be changed by adding a Prompt attribute.

public string HelloA([Prompt("First name: ", history = "first-name")] string name) {
return "Hello, " + name;
}

See the Prompt class for more details.

Special Return Types

Minibuffer commands that return a String or IEnumerator are handled differently for convenience.

String Return Type

A command that returns a String is output as a message.

public string HelloX(string name) {
return "Hello, " + name;
}

It is equivalent to the following code.

public void HelloX2(string name) {
Minibuffer.instance.Message("Hello, " + name);
}

IEnumerator Return Type

A command that returns an IEnumerator is run as a coroutine.

public IEnumerator HelloWaitForIt(string name) {
Minibuffer.instance.Message("Hello, ");
yield new WaitForSeconds(1f);
Minibuffer.instance.Message("Wait for it...");
yield new WaitForSeconds(1f);
Minibuffer.instance.Message(name);
}

It is equivalent to the following code.

public void HelloWaitForIt2(string name) {
StartCoroutine(HelloWaitForIt2Helper(name));
}
private IEnumerator HelloWaitForIt2Helper(string name) {
Minibuffer.instance.Message("Hello, ");
yield new WaitForSeconds(1f);
Minibuffer.instance.Message("Wait for it...");
yield new WaitForSeconds(1f);
Minibuffer.instance.Message(name);
}

Public Member Functions

 Command ()
 The command name will be derived from the method's name. More...
 
 Command (string name)
 Command with given name.
 

Public Attributes

string name
 Name of the command. More...
 
string description
 Command description or null. More...
 
string briefDescription
 The brief description will be generated from the first sentence of the description if available; otherwise it's null. More...
 
string keyBinding
 Bind a key sequence to this command. More...
 
string[] keyBindings
 Bind multiple key sequences to this command. More...
 
string keymap
 The keymap to place any key bindings in. More...
 
string group
 Place command in given group. More...
 

Constructor & Destructor Documentation

Command ( )

The command name will be derived from the method's name.

Member Data Documentation

string name

Name of the command.

If not given, will use the method's name.

string description

Command description or null.

string briefDescription

The brief description will be generated from the first sentence of the description if available; otherwise it's null.

string keyBinding

Bind a key sequence to this command.

string [] keyBindings

Bind multiple key sequences to this command.

string keymap

The keymap to place any key bindings in.

string group

Place command in given group.

By default it will go into the group of its class.