NeoMutt  2025-12-11-58-g09398d
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 N_("Bind a key to a function"),
74 N_("bind <map>[,<map> ... ] <key> <function>"),
75 "configuration.html#bind" },
76 { "exec", parse_exec, 0,
77 N_("Execute a function"),
78 N_("exec <function> [ <function> ... ]"),
79 "configuration.html#exec" },
80 { "macro", parse_macro, 1,
81 N_("Define a keyboard macro"),
82 N_("macro <menu>[,<menu> ... ] <key> <sequence> [ <description> ]"),
83 "configuration.html#macro" },
84 { "push", parse_push, 0,
85 N_("Push a string into NeoMutt's input queue (simulate typing)"),
86 N_("push <string>"),
87 "configuration.html#push" },
88 { "unbind", parse_unbind, MUTT_UNBIND,
89 N_("Remove a key binding"),
90 N_("unbind { * | <menu>[,<menu> ... ] } [ <key> ]"),
91 "configuration.html#unbind" },
92 { "unmacro", parse_unbind, MUTT_UNMACRO,
93 N_("Remove a keyboard `macro`"),
94 N_("unmacro { * | <menu>[,<menu> ... ] } [ <key> ]"),
95 "configuration.html#unmacro" },
96
97 { NULL, NULL, 0, NULL, NULL, NULL, CF_NO_FLAGS },
98 // clang-format on
99};
100
127
132static void mutt_keymaplist_free(struct KeymapList *km_list)
133{
134 struct Keymap *np = NULL, *tmp = NULL;
135 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
136 {
137 STAILQ_REMOVE(km_list, np, Keymap, entries);
138 mutt_keymap_free(&np);
139 }
140}
141
146{
147 if (nc->event_type != NT_CONFIG)
148 return 0;
149 if (!nc->event_data)
150 return -1;
151
152 struct EventConfig *ev_c = nc->event_data;
153
154 if (!mutt_str_equal(ev_c->name, "abort_key"))
155 return 0;
156
158 mutt_debug(LL_DEBUG5, "config done\n");
159 return 0;
160}
161
166{
167 for (enum MenuType i = 1; i < MENU_MAX; i++)
168 {
170 }
171
172 if (NeoMutt && NeoMutt->sub)
174}
175
182{
183 keycode_t buf[2];
184 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
185 size_t len = parsekeys(c_abort_key, buf, countof(buf));
186 if (len == 0)
187 {
188 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
189 AbortKey = ctrl('G');
190 return;
191 }
192 if (len > 1)
193 {
194 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
195 c_abort_key);
196 }
197 AbortKey = buf[0];
198
200}
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
#define CF_NO_FLAGS
No flags are set.
Definition command.h:46
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(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'push' command - Implements Command::parse() -.
Definition commands.c:310
enum CommandResult parse_macro(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'macro' command - Implements Command::parse() -.
Definition commands.c:572
enum CommandResult parse_exec(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'exec' command - Implements Command::parse() -.
Definition commands.c:673
enum CommandResult parse_bind(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'bind' command - Implements Command::parse() -.
Definition commands.c:345
enum CommandResult parse_unbind(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'unbind' command - Implements Command::parse() -.
Definition commands.c:472
#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:145
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:104
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:132
void mutt_keys_cleanup(void)
Free the key maps.
Definition init.c:165
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:181
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:56
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 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
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:127
int op
Operation, e.g. OP_DELETE.
Definition lib.h:128
const char * seq
Default key binding.
Definition lib.h:129
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