Thanks to visit codestin.com
Credit goes to code.neomutt.org

NeoMutt  2025-12-11-189-gceedb6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
init.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <string.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "init.h"
36#include "commands.h"
37#include "get.h"
38#include "keymap.h"
39#include "menu.h"
40
42struct MenuDefinitionArray MenuDefs;
43
45struct SubMenuArray SubMenus;
46
48
52const struct Command KeyCommands[] = {
53 // clang-format off
55 N_("Bind a key to a function"),
56 N_("bind <map>[,<map> ... ] <key> <function>"),
57 "configuration.html#bind" },
59 N_("Execute a function"),
60 N_("exec <function> [ <function> ... ]"),
61 "configuration.html#exec" },
63 N_("Define a keyboard macro"),
64 N_("macro <map>[,<map> ... ] <key> <sequence> [ <description> ]"),
65 "configuration.html#macro" },
67 N_("Push a string into NeoMutt's input queue (simulate typing)"),
68 N_("push <string>"),
69 "configuration.html#push" },
71 N_("Remove a key binding"),
72 N_("unbind { * | <map>[,<map> ... ] } [ <key> ]"),
73 "configuration.html#unbind" },
75 N_("Remove a keyboard `macro`"),
76 N_("unmacro { * | <map>[,<map> ... ] } [ <key> ]"),
77 "configuration.html#unmacro" },
78
79 { NULL, CMD_NONE, NULL, CMD_NO_DATA, NULL, NULL, NULL, CF_NO_FLAGS },
80 // clang-format on
81};
82
92{
93 struct SubMenu sm = { 0 };
96
97 ARRAY_ADD(&SubMenus, sm);
98 return ARRAY_LAST(&SubMenus);
99}
100
107struct MenuDefinition *km_register_menu(int menu, const char *name)
108{
109 struct MenuDefinition md = { 0 };
110 md.id = menu;
111 md.name = mutt_str_dup(name);
112 ARRAY_INIT(&md.submenus);
113
114 ARRAY_ADD(&MenuDefs, md);
115 return ARRAY_LAST(&MenuDefs);
116}
117
123void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
124{
125 if (!sm->parent)
126 sm->parent = md;
127
128 ARRAY_ADD(&md->submenus, sm);
129}
130
136void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
137{
138 for (int i = 0; bindings[i].op != OP_NULL; i++)
139 {
140 if (bindings[i].seq)
141 {
142 km_bind(md, bindings[i].seq, bindings[i].op, NULL, NULL, NULL);
143 }
144 }
145}
146
151{
152 if (nc->event_type != NT_CONFIG)
153 return 0;
154 if (!nc->event_data)
155 return -1;
156
157 struct EventConfig *ev_c = nc->event_data;
158
159 if (!mutt_str_equal(ev_c->name, "abort_key"))
160 return 0;
161
163 mutt_debug(LL_DEBUG5, "config done\n");
164 return 0;
165}
166
177
181void km_cleanup(void)
182{
183 if (NeoMutt && NeoMutt->sub)
185
186 struct MenuDefinition *md = NULL;
188 {
189 FREE(&md->name);
190 ARRAY_FREE(&md->submenus);
191 }
193
194 struct SubMenu *sm = NULL;
196 {
198 }
200
203}
204
211{
212 keycode_t buf[4] = { 0 };
213 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
214
215 size_t len = parse_keys(c_abort_key, buf, countof(buf));
216 if (len == 0)
217 {
218 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
219 AbortKey = ctrl('G');
220 return;
221 }
222
223 if (len > 1)
224 {
225 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
226 c_abort_key);
227 }
228 AbortKey = buf[0];
229}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition array.h:145
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
#define CMD_NO_DATA
Convenience symbol.
Definition command.h:148
#define CF_NO_FLAGS
No flags are set.
Definition command.h:46
@ CMD_EXEC
:exec
Definition command.h:72
@ CMD_UNMACRO
:unmacro
Definition command.h:133
@ CMD_MACRO
:macro
Definition command.h:88
@ CMD_PUSH
:push
Definition command.h:99
@ CMD_NONE
No Command.
Definition command.h:57
@ CMD_BIND
:bind
Definition command.h:65
@ CMD_UNBIND
:unbind
Definition command.h:126
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition get.c:56
struct KeyEventArray UngetKeyEvents
These are used in all other "normal" situations, and are not ignored when passing GETCH_IGNORE_MACRO.
Definition get.c:60
Get a key from the user.
enum CommandResult parse_push(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'push' command - Implements Command::parse() -.
Definition commands.c:204
enum CommandResult parse_macro(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'macro' command - Implements Command::parse() -.
Definition commands.c:665
enum CommandResult parse_exec(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'exec' command - Implements Command::parse() -.
Definition commands.c:768
enum CommandResult parse_bind(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'bind' command - Implements Command::parse() -.
Definition commands.c:239
enum CommandResult parse_unbind(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'unbind' and 'unmacro' commands - Implements Command::parse() -.
Definition commands.c:641
#define mutt_warning(...)
Definition logging2.h:92
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
int km_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition init.c:150
Convenience wrapper for the gui headers.
struct MenuDefinitionArray MenuDefs
All the registered Menus.
Definition init.c:42
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition init.c:47
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:123
struct SubMenuArray SubMenus
All the registered SubMenus.
Definition init.c:45
void km_cleanup(void)
Free the key maps.
Definition init.c:181
void km_init(void)
Initialise all the menu keybindings.
Definition init.c:170
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:91
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:107
void km_set_abort_key(void)
Parse the abort_key config string.
Definition init.c:210
const struct Command KeyCommands[]
Key Binding Commands.
Definition init.c:52
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:136
Set up the key bindings.
Parse key binding commands.
enum CommandResult km_bind(struct MenuDefinition *md, const char *key_str, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition menu.c:51
void keymaplist_free(struct KeymapList *kml)
Free a List of Keymaps.
Definition keymap.c:144
size_t parse_keys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition keymap.c:318
Keymap handling.
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition keymap.h:31
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
#define countof(x)
Definition memory.h:45
#define FREE(x)
Definition memory.h:63
Maniplate Menus and SubMenus.
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition notify.c:191
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
#define ctrl(ch)
Definition mutt_curses.h:52
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
A config-change event.
Definition subset.h:70
const char * name
Name of config item that changed.
Definition subset.h:72
Functions for a Dialog or Window.
Definition menu.h:81
const char * name
Menu name, e.g. "alias".
Definition menu.h:83
int id
Menu ID, e.g. MENU_ALIAS.
Definition menu.h:82
struct SubMenuPArray submenus
Parts making up the Menu.
Definition menu.h:84
Mapping between a function and an operation.
Definition menu.h:39
Mapping between an operation and a key sequence.
Definition menu.h:49
int op
Operation, e.g. OP_DELETE.
Definition menu.h:50
Container for Accounts, Notifications.
Definition neomutt.h:128
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:134
Data passed to a notification function.
Definition observer.h:34
void * event_data
Data from notify_send()
Definition observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition observer.h:36
Collection of related functions.
Definition menu.h:69
const struct MenuFuncOp * functions
All available functions.
Definition menu.h:71
struct KeymapList keymaps
All keybindings.
Definition menu.h:72
struct MenuDefinition * parent
Primary parent.
Definition menu.h:70