NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
init.h File Reference

Set up the key bindings. More...

#include "menu.h"
+ Include dependency graph for init.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void km_cleanup (struct KeyModuleData *mod_data)
 Free the key maps.
 
int km_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
void km_init (struct KeyModuleData *mod_data)
 Initialise all the menu keybindings.
 
void km_menu_add_bindings (struct MenuDefinition *md, const struct MenuOpSeq bindings[])
 Add Keybindings to a Menu.
 
void km_menu_add_submenu (struct MenuDefinition *md, struct SubMenu *sm)
 Add a SubMenu to a Menu Definition.
 
struct MenuDefinitionkm_register_menu (int menu, const char *name)
 Register a menu.
 
struct SubMenukm_register_submenu (const struct MenuFuncOp functions[])
 Register a submenu.
 
void km_set_abort_key (keycode_t *abort_key)
 Parse the abort_key config string.
 
void km_sort (void)
 Sort all the menu keybindings.
 

Detailed Description

Set up the key bindings.

Authors
  • Richard Russon

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 http://www.gnu.org/licenses/.

Definition in file init.h.

Function Documentation

◆ km_cleanup()

void km_cleanup ( struct KeyModuleData * mod_data)

Free the key maps.

Parameters
mod_dataKey module data

Definition at line 203 of file init.c.

204{
205 if (NeoMutt && NeoMutt->sub)
207
208 struct MenuDefinition **mdp = NULL;
209 ARRAY_FOREACH(mdp, &mod_data->menu_defs)
210 {
211 struct MenuDefinition *md = *mdp;
212
213 FREE(&md->name);
214 ARRAY_FREE(&md->submenus);
215 FREE(&md);
216 }
217 ARRAY_FREE(&mod_data->menu_defs);
218
219 struct SubMenu *sm = NULL;
220 ARRAY_FOREACH(sm, &mod_data->sub_menus)
221 {
223 }
224 ARRAY_FREE(&mod_data->sub_menus);
225
226 ARRAY_FREE(&mod_data->macro_events);
227 ARRAY_FREE(&mod_data->unget_key_events);
228}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
int km_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition init.c:148
void keymaplist_free(struct KeymapList *kml)
Free a List of Keymaps.
Definition keymap.c:163
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
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
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
struct KeyEventArray macro_events
Macro event buffer.
Definition module_data.h:36
struct MenuDefinitionArray menu_defs
All registered Menus.
Definition module_data.h:39
struct SubMenuArray sub_menus
All registered SubMenus.
Definition module_data.h:40
struct KeyEventArray unget_key_events
Unget key event buffer.
Definition module_data.h:37
Functions for a Dialog or Window.
Definition menu.h:77
const char * name
Menu name, e.g. "alias".
Definition menu.h:79
struct SubMenuPArray submenus
Parts making up the Menu.
Definition menu.h:80
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Collection of related functions.
Definition menu.h:65
struct KeymapList keymaps
All keybindings.
Definition menu.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( struct KeyModuleData * mod_data)

Initialise all the menu keybindings.

Parameters
mod_dataKey module data

Definition at line 170 of file init.c.

171{
172 ARRAY_INIT(&mod_data->menu_defs);
173 ARRAY_INIT(&mod_data->sub_menus);
174 mod_data->key_names = keymap_get_key_names();
175
177}
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
struct Mapping * keymap_get_key_names(void)
Get the KeyNames lookup table.
Definition keymap.c:120
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
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
struct Mapping * key_names
Key name lookup table.
Definition module_data.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_menu_add_bindings()

void km_menu_add_bindings ( struct MenuDefinition * md,
const struct MenuOpSeq bindings[] )

Add Keybindings to a Menu.

Parameters
mdMenu Definition
bindingsKeybindings to add

Definition at line 134 of file init.c.

135{
136 for (int i = 0; bindings[i].op != OP_NULL; i++)
137 {
138 if (bindings[i].seq)
139 {
140 km_bind(md, bindings[i].seq, bindings[i].op, NULL, NULL, NULL);
141 }
142 }
143}
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:52
int op
Operation, e.g. OP_DELETE.
Definition menu.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_menu_add_submenu()

void km_menu_add_submenu ( struct MenuDefinition * md,
struct SubMenu * sm )

Add a SubMenu to a Menu Definition.

Parameters
mdMenu Definition
smSubMenu to add

Definition at line 121 of file init.c.

122{
123 if (!sm->parent)
124 sm->parent = md;
125
126 ARRAY_ADD(&md->submenus, sm);
127}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
struct MenuDefinition * parent
Primary parent.
Definition menu.h:66
+ Here is the caller graph for this function:

◆ km_register_menu()

struct MenuDefinition * km_register_menu ( int menu,
const char * name )

Register a menu.

Parameters
menuMenu Type, e.g. MENU_INDEX
nameMenu name, e.g. "index"
Return values
ptrMenu Definition

Definition at line 104 of file init.c.

105{
107 struct MenuDefinition *md = MUTT_MEM_CALLOC(1, struct MenuDefinition);
108 md->id = menu;
109 md->name = mutt_str_dup(name);
110 ARRAY_INIT(&md->submenus);
111
112 ARRAY_ADD(&mod_data->menu_defs, md);
113 return *ARRAY_LAST(&mod_data->menu_defs);
114}
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition array.h:145
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MODULE_ID_KEY
ModuleKey, Key mappings
Definition module_api.h:73
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
Key private Module data.
Definition module_data.h:34
int id
Menu ID, e.g. MENU_ALIAS.
Definition menu.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_register_submenu()

struct SubMenu * km_register_submenu ( const struct MenuFuncOp functions[])

Register a submenu.

Parameters
functionsFunction definitions
Return values
ptrSubMenu

Register a set of functions. The result can be used in multiple Menus.

Definition at line 87 of file init.c.

88{
90 struct SubMenu sm = { 0 };
93
94 ARRAY_ADD(&mod_data->sub_menus, sm);
95 return ARRAY_LAST(&mod_data->sub_menus);
96}
const struct MenuFuncOp * functions
All available functions.
Definition menu.h:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_set_abort_key()

void km_set_abort_key ( keycode_t * abort_key)

Parse the abort_key config string.

Parameters
abort_keyPointer to the abort key variable to set

Parse the string into $abort_key and put the keycode into AbortKey.

Definition at line 236 of file init.c.

237{
238 keycode_t buf[4] = { 0 };
239 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
240
241 size_t len = parse_keys(c_abort_key, buf, countof(buf));
242 if (len == 0)
243 {
244 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
245 *abort_key = ctrl('G');
246 return;
247 }
248
249 if (len > 1)
250 {
251 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
252 c_abort_key);
253 }
254 *abort_key = buf[0];
255}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
#define mutt_warning(...)
Definition logging2.h:92
#define mutt_error(...)
Definition logging2.h:94
size_t parse_keys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition keymap.c:337
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition keymap.h:31
#define countof(x)
Definition memory.h:49
#define _(a)
Definition message.h:28
#define ctrl(ch)
Convert a letter to a control character (e.g., 'A' -> Ctrl-A)
Definition mutt_curses.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_sort()

void km_sort ( void )

Sort all the menu keybindings.

Definition at line 193 of file init.c.

194{
196 ARRAY_SORT(&mod_data->menu_defs, menu_defs_sort, NULL);
197}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition array.h:373
static int menu_defs_sort(const void *a, const void *b, void *sdata)
Compare two MenuDefinitions by their names - Implements sort_t -.
Definition init.c:182
+ Here is the call graph for this function:
+ Here is the caller graph for this function: