NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
mutt_commands.c File Reference
#include "config.h"
#include <stddef.h>
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "mutt_commands.h"
#include "command_parse.h"
#include "hook.h"
#include "keymap.h"
#include "mutt_globals.h"
#include "mutt_lua.h"
#include "score.h"
#include "sidebar/lib.h"
+ Include dependency graph for mutt_commands.c:

Go to the source code of this file.


 ARRAY_HEAD (struct Command)
 Initialize commands array and register default commands. More...
int commands_cmp (const void *a, const void *b)
 Compare two commands by name - Implements sort_t. More...
void commands_register (const struct Command *cmds, const size_t num_cmds)
 Add commands to Commands array. More...
void mutt_commands_free (void)
 Free Commands array. More...
size_t mutt_commands_array (struct Command **first)
 Get Commands array. More...
struct Commandmutt_command_get (const char *s)
 Get a Command by its name. More...
void mutt_commands_apply (void *data, void(*application)(void *, const struct Command *))
 Run a callback function on every Command. More...


static const struct Command mutt_commands []

Detailed Description

Definitions of NeoMutt commands

  • Michael R. Elkins
  • g10 Code GmbH

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Definition in file mutt_commands.c.

Function Documentation


ARRAY_HEAD ( struct Command  )

Initialize commands array and register default commands.

Definition at line 136 of file mutt_commands.c.

142 {
143  ARRAY_RESERVE(&commands, 100);
145 }

◆ commands_cmp()

int commands_cmp ( const void *  a,
const void *  b 

Compare two commands by name - Implements sort_t.

Definition at line 150 of file mutt_commands.c.

151 {
152  struct Command x = *(const struct Command *) a;
153  struct Command y = *(const struct Command *) b;
155  return strcmp(,;
156 }
+ Here is the caller graph for this function:

◆ commands_register()

void commands_register ( const struct Command cmds,
const size_t  num_cmds 

Add commands to Commands array.

cmdsArray of Commands
num_cmdsNumber of Commands in the Array

Definition at line 163 of file mutt_commands.c.

164 {
165  for (int i = 0; i < num_cmds; i++)
166  {
167  ARRAY_ADD(&commands, cmds[i]);
168  }
169  ARRAY_SORT(&commands, commands_cmp);
170 }
+ Here is the call graph for this function:

◆ mutt_commands_free()

void mutt_commands_free ( void  )

Free Commands array.

Definition at line 175 of file mutt_commands.c.

176 {
177  ARRAY_FREE(&commands);
178 }
+ Here is the caller graph for this function:

◆ mutt_commands_array()

size_t mutt_commands_array ( struct Command **  first)

Get Commands array.

firstSet to first element of Commands array
Return values
size_tSize of Commands array

Definition at line 185 of file mutt_commands.c.

186 {
187  *first = ARRAY_FIRST(&commands);
188  return ARRAY_SIZE(&commands);
189 }
+ Here is the caller graph for this function:

◆ mutt_command_get()

struct Command* mutt_command_get ( const char *  s)

Get a Command by its name.

sCommand string to lookup
Return values
ptrSuccess, Command
NULLError, no such command

Definition at line 197 of file mutt_commands.c.

198 {
199  struct Command *cmd = NULL;
200  ARRAY_FOREACH(cmd, &commands)
201  {
202  if (mutt_str_equal(s, cmd->name))
203  return cmd;
204  }
205  return NULL;
206 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_commands_apply()

void mutt_commands_apply ( void *  data,
void(*)(void *, const struct Command *)  application 

Run a callback function on every Command.

dataData to pass to the callback function
applicationCallback function

This is used by Lua to expose all of NeoMutt's Commands.

Definition at line 216 of file mutt_commands.c.

217 {
218  struct Command *cmd = NULL;
219  ARRAY_FOREACH(cmd, &commands)
220  {
221  application(data, cmd);
222  }
223 }
+ Here is the caller graph for this function:

Variable Documentation

◆ mutt_commands

const struct Command mutt_commands[]

Definition at line 49 of file mutt_commands.c.

#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:271
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
A user-callable command.
Definition: mutt_commands.h:45
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
static const struct Command mutt_commands[]
Definition: mutt_commands.c:49
intptr_t data
Data or flags to pass to the command.
Definition: mutt_commands.h:59
int commands_cmp(const void *a, const void *b)
Compare two commands by name - Implements sort_t.
Definition: mutt_commands.c:150
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:185
const char * name
Name of the command.
Definition: mutt_commands.h:47
Definition: mutt_commands.h:77
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:131