NeoMutt  2025-09-05-53-g1e05a3
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 "lib.h"
36#include "menu/lib.h"
37
38extern const struct MenuOpSeq AliasDefaultBindings[];
39extern const struct MenuOpSeq AttachmentDefaultBindings[];
40#ifdef USE_AUTOCRYPT
41extern const struct MenuOpSeq AutocryptDefaultBindings[];
42#endif
43extern const struct MenuOpSeq BrowserDefaultBindings[];
44extern const struct MenuOpSeq ComposeDefaultBindings[];
45extern const struct MenuOpSeq EditorDefaultBindings[];
46extern const struct MenuOpSeq IndexDefaultBindings[];
47extern const struct MenuOpSeq PagerDefaultBindings[];
48extern const struct MenuOpSeq PgpDefaultBindings[];
49extern const struct MenuOpSeq PostponedDefaultBindings[];
50extern const struct MenuOpSeq QueryDefaultBindings[];
51extern const struct MenuOpSeq SmimeDefaultBindings[];
52
58static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
59{
60 STAILQ_INIT(&Keymaps[mtype]);
61
62 for (int i = 0; map[i].op != OP_NULL; i++)
63 if (map[i].seq)
64 km_bind(map[i].seq, mtype, map[i].op, NULL, NULL, NULL);
65}
66
70static const struct Command KeyCommands[] = {
71 // clang-format off
72 { "bind", parse_bind, 0 },
73 { "exec", parse_exec, 0 },
74 { "macro", parse_macro, 1 },
75 { "push", parse_push, 0 },
76 { "unbind", parse_unbind, MUTT_UNBIND },
77 { "unmacro", parse_unbind, MUTT_UNMACRO },
78 { NULL, NULL, 0 },
79 // clang-format on
80};
81
108
113static void mutt_keymaplist_free(struct KeymapList *km_list)
114{
115 struct Keymap *np = NULL, *tmp = NULL;
116 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
117 {
118 STAILQ_REMOVE(km_list, np, Keymap, entries);
119 mutt_keymap_free(&np);
120 }
121}
122
127{
128 if (nc->event_type != NT_CONFIG)
129 return 0;
130 if (!nc->event_data)
131 return -1;
132
133 struct EventConfig *ev_c = nc->event_data;
134
135 if (!mutt_str_equal(ev_c->name, "abort_key"))
136 return 0;
137
139 mutt_debug(LL_DEBUG5, "config done\n");
140 return 0;
141}
142
147{
148 for (enum MenuType i = 1; i < MENU_MAX; i++)
149 {
151 }
152
153 if (NeoMutt && NeoMutt->sub)
155}
156
163{
164 keycode_t buf[2];
165 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
166 size_t len = parsekeys(c_abort_key, buf, countof(buf));
167 if (len == 0)
168 {
169 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
170 AbortKey = ctrl('G');
171 return;
172 }
173 if (len > 1)
174 {
175 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
176 c_abort_key);
177 }
178 AbortKey = buf[0];
179
181}
const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition functions.c:109
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition functions.c:92
const struct MenuOpSeq AttachmentDefaultBindings[]
Key bindings for the Attachment Menu.
Definition functions.c:98
const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition functions.c:68
const struct MenuOpSeq BrowserDefaultBindings[]
Key bindings for the file Browser Menu.
Definition functions.c:106
const struct MenuOpSeq ComposeDefaultBindings[]
Key bindings for the Compose Menu.
Definition functions.c:155
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.
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition command.c:51
Convenience wrapper for the core headers.
const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition functions.c:88
enum CommandResult parse_push(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'push' command - Implements Command::parse() -.
Definition commands.c:309
enum CommandResult parse_bind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'bind' command - Implements Command::parse() -.
Definition commands.c:328
enum CommandResult parse_unbind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unbind' command - Implements Command::parse() -.
Definition commands.c:441
enum CommandResult parse_exec(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'exec' command - Implements Command::parse() -.
Definition commands.c:619
enum CommandResult parse_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'macro' command - Implements Command::parse() -.
Definition commands.c:529
#define mutt_warning(...)
Definition logging2.h:91
#define mutt_error(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:90
int key_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition init.c:126
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition functions.c:139
const struct MenuOpSeq DialogDefaultBindings[]
Key bindings for Simple Dialogs.
Definition functions.c:131
Convenience wrapper for the gui headers.
const struct MenuOpSeq IndexDefaultBindings[]
Key bindings for the Index Menu.
Definition functions.c:235
const struct MenuOpSeq PostponedDefaultBindings[]
Key bindings for the Postpone Menu.
Definition functions.c:62
void km_init(void)
Initialise all the menu keybindings.
Definition init.c:85
const struct MenuOpSeq PagerDefaultBindings[]
Key bindings for the Pager Menu.
Definition functions.c:228
static const struct Command KeyCommands[]
Key Binding Commands.
Definition init.c:70
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition init.c:58
const struct MenuOpSeq PgpDefaultBindings[]
Key bindings for the Pgp Menu.
Definition functions.c:64
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition init.c:113
void mutt_keys_cleanup(void)
Free the key maps.
Definition init.c:146
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition functions.c:74
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition init.c:162
enum CommandResult km_bind(const char *s, enum MenuType mtype, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition commands.c:58
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition lib.c:122
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition lib.c:131
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition lib.c:125
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition lib.c:216
Manage keymappings.
#define MUTT_UNBIND
Parse 'unbind' command.
Definition lib.h:49
#define MUTT_UNMACRO
Parse 'unmacro' command.
Definition lib.h:50
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition lib.h:57
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:48
#define countof(x)
Definition memory.h:44
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#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
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:660
#define ctrl(ch)
Definition mutt_curses.h:52
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
#define STAILQ_REMOVE(head, elm, type, field)
Definition queue.h:441
#define STAILQ_INIT(head)
Definition queue.h:410
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition queue.h:400
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
A keyboard mapping.
Definition lib.h:67
Mapping between an operation and a key sequence.
Definition lib.h:125
int op
Operation, e.g. OP_DELETE.
Definition lib.h:126
const char * seq
Default key binding.
Definition lib.h:127
Container for Accounts, Notifications.
Definition neomutt.h:43
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:51
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:47
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
MenuType
Types of GUI selections.
Definition type.h:35
@ MENU_INDEX
Index panel (list of emails)
Definition type.h:46
@ MENU_DIALOG
Simple Dialog.
Definition type.h:43
@ MENU_QUERY
Select from results of external query.
Definition type.h:50
@ MENU_BROWSER
General file/mailbox browser.
Definition type.h:41
@ MENU_AUTOCRYPT
Autocrypt Account menu.
Definition type.h:39
@ MENU_COMPOSE
Compose an email.
Definition type.h:42
@ MENU_ATTACHMENT
Select an attachment.
Definition type.h:37
@ MENU_PGP
PGP encryption menu.
Definition type.h:48
@ MENU_GENERIC
Generic selection list.
Definition type.h:45
@ MENU_PAGER
Pager pager (email viewer)
Definition type.h:47
@ MENU_SMIME
SMIME encryption menu.
Definition type.h:51
@ MENU_MAX
Definition type.h:52
@ MENU_EDITOR
Text entry area.
Definition type.h:44
@ MENU_ALIAS
Select an email address by its alias.
Definition type.h:36
@ MENU_POSTPONED
Select a postponed email.
Definition type.h:49