NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Manage keymappings. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "menu/lib.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Keymap
 A keyboard mapping. More...
 
struct  KeyEvent
 An event such as a keypress. More...
 
struct  BindingInfo
 Info about one keybinding. More...
 
struct  MenuFuncOp
 Mapping between a function and an operation. More...
 
struct  MenuOpSeq
 Mapping between an operation and a key sequence. More...
 
struct  EventBinding
 A key binding Event. More...
 

Macros

#define MUTT_UNBIND   (1 << 0)
 Parse 'unbind' command.
 
#define MUTT_UNMACRO   (1 << 1)
 Parse 'unmacro' command.
 
#define GETCH_NO_FLAGS   0
 No flags are set.
 
#define GETCH_IGNORE_MACRO   (1 << 0)
 Don't use MacroEvents.
 
#define OP_DEPRECATED   true
 Convenience symbol.
 

Typedefs

typedef uint8_t GetChFlags
 Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.
 
typedef short keycode_t
 Type for key storage, the rest of neomutt works fine with int type.
 

Enumerations

enum  NotifyBinding {
  NT_BINDING_ADD = 1 , NT_BINDING_DELETE , NT_BINDING_DELETE_ALL , NT_MACRO_ADD ,
  NT_MACRO_DELETE , NT_MACRO_DELETE_ALL
}
 Key Binding notification types. More...
 

Functions

 STAILQ_HEAD (KeymapList, Keymap)
 
 ARRAY_HEAD (KeyEventArray, struct KeyEvent)
 
 ARRAY_HEAD (BindingInfoArray, struct BindingInfo)
 
static void init_extended_keys (void)
 
enum CommandResult km_bind (const char *s, enum MenuType mtype, int op, char *macro, char *desc, struct Buffer *err)
 Set up a key binding.
 
enum CommandResult parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() -.
 
enum CommandResult parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::parse() -.
 
enum CommandResult parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() -.
 
enum CommandResult parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() -.
 
enum CommandResult parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() -.
 
void km_init (void)
 Initialise all the menu keybindings.
 
int main_config_observer (struct NotifyCallback *nc)
 
void mutt_init_abort_key (void)
 Parse the abort_key config string.
 
void mutt_keys_cleanup (void)
 Free the key maps.
 
int km_dokey (enum MenuType menu, GetChFlags flags)
 Determine what a keypress should do.
 
struct KeyEvent km_dokey_event (enum MenuType menu, GetChFlags flags)
 Determine what a keypress should do.
 
void km_error_key (enum MenuType menu)
 Handle an unbound key sequence.
 
void mutt_flush_macro_to_endcond (void)
 Drop a macro from the input buffer.
 
bool km_expand_key (struct Keymap *map, struct Buffer *buf)
 Get the key string bound to a Keymap.
 
struct Keymapkm_find_func (enum MenuType menu, int func)
 Find a function's mapping in a Menu.
 
const struct MenuFuncOpkm_get_table (enum MenuType mtype)
 Lookup a Menu's functions.
 
void km_keyname (int c, struct Buffer *buf)
 Get the human name for a key.
 
struct Keymapalloc_keys (size_t len, keycode_t *keys)
 Allocate space for a sequence of keys.
 
enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse 'bind' and 'macro' commands - Implements Command::parse() -.
 
void generic_tokenize_push_string (char *s)
 Parse and queue a 'push' command.
 
int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len)
 Get the function by its name.
 
struct Keymapkm_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos)
 Compare two keymaps' keyscodes and return the bigger one.
 
const char * mutt_get_func (const struct MenuFuncOp *bindings, int op)
 Get the name of a function.
 
void mutt_keymap_free (struct Keymap **ptr)
 Free a Keymap.
 
int parse_fkey (char *s)
 Parse a function key string.
 
size_t parsekeys (const char *str, keycode_t *d, size_t max)
 Parse a key string into key codes.
 
void km_expand_key_string (char *str, struct Buffer *buf)
 Get a human-readable key string.
 
struct KeyEvent mutt_getch (GetChFlags flags)
 Read a character from the input buffer.
 
void mutt_flushinp (void)
 Empty all the keyboard buffers.
 
void mutt_push_macro_event (int ch, int op)
 Add the character/operation to the macro buffer.
 
void mutt_unget_ch (int ch)
 Return a keystroke to the input buffer.
 
void mutt_unget_op (int op)
 Return an operation to the input buffer.
 
void mutt_unget_string (const char *s)
 Return a string to the input buffer.
 
int measure_column (struct BindingInfoArray *bia, int col)
 Measure one column of a table.
 
void gather_menu (enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
 Gather info about one menu.
 
int gather_unbound (const struct MenuFuncOp *funcs, const struct KeymapList *km_menu, const struct KeymapList *km_aux, struct BindingInfoArray *bia_unbound)
 Gather info about unbound functions for one menu.
 
int binding_sort (const void *a, const void *b, void *sdata)
 Compare two BindingInfo by their keybinding - Implements sort_t -.
 

Variables

struct KeyEventArray MacroEvents
 These are used for macros and exec/push commands.
 
struct KeymapList Keymaps []
 Array of Keymap keybindings, one for each Menu.
 
struct Mapping KeyNames []
 Key name lookup table.
 
keycode_t AbortKey
 key to abort edits etc, normally Ctrl-G
 
const struct Mapping Menus []
 

Detailed Description

Manage keymappings.

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 lib.h.

Macro Definition Documentation

◆ MUTT_UNBIND

#define MUTT_UNBIND   (1 << 0)

Parse 'unbind' command.

Definition at line 49 of file lib.h.

◆ MUTT_UNMACRO

#define MUTT_UNMACRO   (1 << 1)

Parse 'unmacro' command.

Definition at line 50 of file lib.h.

◆ GETCH_NO_FLAGS

#define GETCH_NO_FLAGS   0

No flags are set.

Definition at line 53 of file lib.h.

◆ GETCH_IGNORE_MACRO

#define GETCH_IGNORE_MACRO   (1 << 0)

Don't use MacroEvents.

Definition at line 54 of file lib.h.

◆ OP_DEPRECATED

#define OP_DEPRECATED   true

Convenience symbol.

Definition at line 109 of file lib.h.

Typedef Documentation

◆ GetChFlags

typedef uint8_t GetChFlags

Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.

Definition at line 52 of file lib.h.

◆ keycode_t

typedef short keycode_t

Type for key storage, the rest of neomutt works fine with int type.

Definition at line 57 of file lib.h.

Enumeration Type Documentation

◆ NotifyBinding

Key Binding notification types.

Observers of NT_BINDING will be passed an EventBinding.

Note
Notifications are sent after the event.
Enumerator
NT_BINDING_ADD 

Key binding has been added.

NT_BINDING_DELETE 

Key binding has been deleted.

NT_BINDING_DELETE_ALL 

All key bindings have been deleted.

NT_MACRO_ADD 

Key macro has been added.

NT_MACRO_DELETE 

Key macro has been deleted.

NT_MACRO_DELETE_ALL 

All key macros have been deleted.

Definition at line 147 of file lib.h.

148{
149 NT_BINDING_ADD = 1,
152
156};
@ NT_MACRO_ADD
Key macro has been added.
Definition lib.h:153
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition lib.h:154
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition lib.h:155
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition lib.h:150
@ NT_BINDING_ADD
Key binding has been added.
Definition lib.h:149
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition lib.h:151

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( KeymapList ,
Keymap  )

◆ ARRAY_HEAD() [1/2]

ARRAY_HEAD ( KeyEventArray ,
struct KeyEvent  )

◆ ARRAY_HEAD() [2/2]

ARRAY_HEAD ( BindingInfoArray ,
struct BindingInfo  )

◆ init_extended_keys()

static void init_extended_keys ( void )
inlinestatic

Definition at line 162 of file lib.h.

162{}

◆ km_bind()

enum CommandResult km_bind ( const char * s,
enum MenuType mtype,
int op,
char * macro,
char * desc,
struct Buffer * err )

Set up a key binding.

Parameters
sKey string
mtypeMenu type, e.g. MENU_EDITOR
opOperation, e.g. OP_DELETE
macroMacro string
descDescription of macro (OPTIONAL)
errBuffer for error message
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Insert a key sequence into the specified map. The map is sorted by ASCII value (lowest to highest)

Definition at line 58 of file commands.c.

60{
62 struct Keymap *last = NULL, *np = NULL, *compare = NULL;
63 keycode_t buf[MAX_SEQ];
64 size_t pos = 0, lastpos = 0;
65
66 size_t len = parsekeys(s, buf, MAX_SEQ);
67
68 struct Keymap *map = alloc_keys(len, buf);
69 map->op = op;
70 map->macro = mutt_str_dup(macro);
71 map->desc = mutt_str_dup(desc);
72
73 /* find position to place new keymap */
74 STAILQ_FOREACH(np, &Keymaps[mtype], entries)
75 {
76 compare = km_compare_keys(map, np, &pos);
77
78 if (compare == map) /* map's keycode is bigger */
79 {
80 last = np;
81 lastpos = pos;
82 if (pos > np->eq)
83 pos = np->eq;
84 }
85 else if (compare == np) /* np's keycode is bigger, found insert location */
86 {
87 map->eq = pos;
88 break;
89 }
90 else /* equal keycodes */
91 {
92 /* Don't warn on overwriting a 'noop' binding */
93 if ((np->len != len) && (np->op != OP_NULL))
94 {
95 static const char *guide_link = "https://neomutt.org/guide/configuration.html#bind-warnings";
96 /* Overwrite with the different lengths, warn */
97 struct Buffer *old_binding = buf_pool_get();
98 struct Buffer *new_binding = buf_pool_get();
99
100 km_expand_key(map, old_binding);
101 km_expand_key(np, new_binding);
102
103 char *err_msg = _("Binding '%s' will alias '%s' Before, try: 'bind %s %s noop'");
104 if (err)
105 {
106 /* err was passed, put the string there */
107 buf_printf(err, err_msg, buf_string(old_binding), buf_string(new_binding),
108 mutt_map_get_name(mtype, MenuNames), buf_string(new_binding));
109 buf_add_printf(err, " %s", guide_link);
110 }
111 else
112 {
113 struct Buffer *tmp = buf_pool_get();
114 buf_printf(tmp, err_msg, buf_string(old_binding), buf_string(new_binding),
115 mutt_map_get_name(mtype, MenuNames), buf_string(new_binding));
116 buf_add_printf(tmp, " %s", guide_link);
117 mutt_error("%s", buf_string(tmp));
118 buf_pool_release(&tmp);
119 }
120 rc = MUTT_CMD_WARNING;
121
122 buf_pool_release(&old_binding);
123 buf_pool_release(&new_binding);
124 }
125
126 map->eq = np->eq;
127 STAILQ_REMOVE(&Keymaps[mtype], np, Keymap, entries);
128 mutt_keymap_free(&np);
129 break;
130 }
131 }
132
133 if (map->op == OP_NULL)
134 {
135 mutt_keymap_free(&map);
136 }
137 else
138 {
139 if (last) /* if queue has at least one entry */
140 {
141 if (STAILQ_NEXT(last, entries))
142 STAILQ_INSERT_AFTER(&Keymaps[mtype], last, map, entries);
143 else /* last entry in the queue */
144 STAILQ_INSERT_TAIL(&Keymaps[mtype], map, entries);
145 last->eq = lastpos;
146 }
147 else /* queue is empty, so insert from head */
148 {
149 STAILQ_INSERT_HEAD(&Keymaps[mtype], map, entries);
150 }
151 }
152
153 return rc;
154}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
CommandResult
Error codes for command_t parse functions.
Definition command.h:35
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:38
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:37
#define mutt_error(...)
Definition logging2.h:93
#define MAX_SEQ
Maximum length of a key binding sequence used for buffer in km_bind.
Definition commands.c:43
struct Keymap * km_compare_keys(struct Keymap *k1, struct Keymap *k2, size_t *pos)
Compare two keymaps' keyscodes and return the bigger one.
Definition lib.c:275
struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition lib.c:150
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
bool km_expand_key(struct Keymap *map, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition lib.c:434
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition lib.h:57
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition mapping.c:42
#define _(a)
Definition message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:255
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
#define STAILQ_REMOVE(head, elm, type, field)
Definition queue.h:441
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:427
#define STAILQ_INSERT_HEAD(head, elm, field)
Definition queue.h:421
#define STAILQ_NEXT(elm, field)
Definition queue.h:439
#define STAILQ_INSERT_AFTER(head, tqelm, elm, field)
Definition queue.h:415
String manipulation buffer.
Definition buffer.h:36
A keyboard mapping.
Definition lib.h:67
char * macro
Macro expansion (op == OP_MACRO)
Definition lib.h:68
short eq
Number of leading keys equal to next entry.
Definition lib.h:71
char * desc
Description of a macro for the help menu.
Definition lib.h:69
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition lib.h:72
short op
Operation to perform.
Definition lib.h:70
const struct Mapping MenuNames[]
Menu name lookup table.
Definition type.c:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void )

Initialise all the menu keybindings.

Definition at line 85 of file init.c.

86{
87 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
88
91#ifdef USE_AUTOCRYPT
93#endif
105
107}
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
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition command.c:51
const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition functions.c:88
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
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
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
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition functions.c:74
Container for Accounts, Notifications.
Definition neomutt.h:43
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:51
@ 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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main_config_observer()

int main_config_observer ( struct NotifyCallback * nc)
+ Here is the call graph for this function:

◆ mutt_init_abort_key()

void mutt_init_abort_key ( void )

Parse the abort_key config string.

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

Definition at line 162 of file init.c.

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 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:91
int key_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition init.c:126
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition lib.c:122
#define countof(x)
Definition memory.h:44
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
#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
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_keys_cleanup()

void mutt_keys_cleanup ( void )

Free the key maps.

Definition at line 146 of file init.c.

147{
148 for (enum MenuType i = 1; i < MENU_MAX; i++)
149 {
151 }
152
153 if (NeoMutt && NeoMutt->sub)
155}
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition init.c:113
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
MenuType
Types of GUI selections.
Definition type.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey()

int km_dokey ( enum MenuType mtype,
GetChFlags flags )

Determine what a keypress should do.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
flagsFlags, e.g. GETCH_IGNORE_MACRO
Return values
>0Function to execute
OP_NULLNo function bound to key sequence
-1Error occurred while reading input
-2A timeout or sigwinch occurred

Definition at line 537 of file get.c.

538{
539 return km_dokey_event(mtype, flags).op;
540}
struct KeyEvent km_dokey_event(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:419
int op
Function opcode, e.g. OP_HELP.
Definition lib.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey_event()

struct KeyEvent km_dokey_event ( enum MenuType mtype,
GetChFlags flags )

Determine what a keypress should do.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
flagsFlags, e.g. GETCH_IGNORE_MACRO
Return values
ptrEvent

Definition at line 419 of file get.c.

420{
421 struct KeyEvent event = { 0, OP_NULL };
422 struct Keymap *map = STAILQ_FIRST(&Keymaps[mtype]);
423 int pos = 0;
424 int n = 0;
425
426 if (!map && (mtype != MENU_EDITOR))
427 return retry_generic(mtype, NULL, 0, 0, flags);
428
429 while (true)
430 {
431 event = mutt_getch(flags);
432
433 // abort, timeout, repaint
434 if (event.op < OP_NULL)
435 return event;
436
437 /* do we have an op already? */
438 if (event.op != OP_NULL)
439 {
440 const char *func = NULL;
441 const struct MenuFuncOp *funcs = NULL;
442
443 /* is this a valid op for this menu type? */
444 if ((funcs = km_get_table(mtype)) && (func = mutt_get_func(funcs, event.op)))
445 return event;
446
447 if ((mtype != MENU_EDITOR) && (mtype != MENU_PAGER) && (mtype != MENU_GENERIC))
448 {
449 /* check generic menu type */
450 funcs = OpGeneric;
451 func = mutt_get_func(funcs, event.op);
452 if (func)
453 return event;
454 }
455
456 /* Sigh. Valid function but not in this context.
457 * Find the literal string and push it back */
458 for (int i = 0; MenuNames[i].name; i++)
459 {
460 funcs = km_get_table(MenuNames[i].value);
461 if (funcs)
462 {
463 func = mutt_get_func(funcs, event.op);
464 if (func)
465 {
466 mutt_unget_ch('>');
467 mutt_unget_string(func);
468 mutt_unget_ch('<');
469 break;
470 }
471 }
472 }
473 /* continue to chew */
474 if (func)
475 continue;
476 }
477
478 if (!map)
479 return event;
480
481 /* Nope. Business as usual */
482 while (event.ch > map->keys[pos])
483 {
484 if ((pos > map->eq) || !STAILQ_NEXT(map, entries))
485 return retry_generic(mtype, map->keys, pos, event.ch, flags);
486 map = STAILQ_NEXT(map, entries);
487 }
488
489 if (event.ch != map->keys[pos])
490 return retry_generic(mtype, map->keys, pos, event.ch, flags);
491
492 if (++pos == map->len)
493 {
494 if (map->op != OP_MACRO)
495 return (struct KeyEvent) { event.ch, map->op };
496
497 /* #GETCH_IGNORE_MACRO turns off processing the MacroEvents buffer
498 * in mutt_getch(). Generating new macro events during that time would
499 * result in undesired behavior once the option is turned off.
500 *
501 * Originally this returned -1, however that results in an unbuffered
502 * username or password prompt being aborted. Returning OP_NULL allows
503 * mw_get_field() to display the keybinding pressed instead.
504 *
505 * It may be unexpected for a macro's keybinding to be returned,
506 * but less so than aborting the prompt. */
507 if (flags & GETCH_IGNORE_MACRO)
508 {
509 return (struct KeyEvent) { event.ch, OP_NULL };
510 }
511
512 if (n++ == 10)
513 {
515 mutt_error(_("Macro loop detected"));
516 return (struct KeyEvent) { '\0', OP_ABORT };
517 }
518
520 map = STAILQ_FIRST(&Keymaps[mtype]);
521 pos = 0;
522 }
523 }
524
525 /* not reached */
526}
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition get.c:348
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition get.c:58
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition get.c:137
struct KeyEvent mutt_getch(GetChFlags flags)
Read a character from the input buffer.
Definition get.c:210
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition get.c:115
static struct KeyEvent retry_generic(enum MenuType mtype, keycode_t *keys, int keyslen, int lastkey, GetChFlags flags)
Try to find the key in the generic menu bindings.
Definition get.c:321
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition functions.c:69
const char * mutt_get_func(const struct MenuFuncOp *funcs, int op)
Get the name of a function.
Definition lib.c:321
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition lib.c:482
#define GETCH_IGNORE_MACRO
Don't use MacroEvents.
Definition lib.h:54
#define OP_ABORT
$abort_key pressed (Ctrl-G)
Definition opcodes.h:36
#define STAILQ_FIRST(head)
Definition queue.h:388
An event such as a keypress.
Definition lib.h:82
int ch
Raw key pressed.
Definition lib.h:83
keycode_t * keys
Key sequence.
Definition lib.h:73
Mapping between a function and an operation.
Definition lib.h:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_error_key()

void km_error_key ( enum MenuType mtype)

Handle an unbound key sequence.

Parameters
mtypeMenu type, e.g. MENU_PAGER

Definition at line 294 of file get.c.

295{
296 struct Keymap *key = km_find_func(mtype, OP_HELP);
297 if (!key && (mtype != MENU_EDITOR) && (mtype != MENU_PAGER))
298 key = km_find_func(MENU_GENERIC, OP_HELP);
299
300 if (!key)
301 {
302 mutt_error(_("Key is not bound"));
303 return;
304 }
305
306 struct Buffer *buf = buf_pool_get();
307 km_expand_key(key, buf);
308 mutt_error(_("Key is not bound. Press '%s' for help."), buf_string(buf));
309 buf_pool_release(&buf);
310}
struct Keymap * km_find_func(enum MenuType mtype, int func)
Find a function's mapping in a Menu.
Definition lib.c:466
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_flush_macro_to_endcond()

void mutt_flush_macro_to_endcond ( void )

Drop a macro from the input buffer.

All the macro text is deleted until an OP_END_COND command, or the buffer is empty.

Definition at line 166 of file get.c.

167{
169}
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition get.c:49
static void array_to_endcond(struct KeyEventArray *a)
Clear the array until an OP_END_COND.
Definition get.c:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_expand_key()

bool km_expand_key ( struct Keymap * map,
struct Buffer * buf )

Get the key string bound to a Keymap.

Parameters
[in]mapKeybinding map
[out]bufBuffer for the result
Return values
trueSuccess

Definition at line 434 of file lib.c.

435{
436 if (!map || !buf)
437 return false;
438
439 for (int i = 0; i < map->len; i++)
440 {
441 km_keyname(map->keys[i], buf);
442 }
443
444 return true;
445}
void km_keyname(int c, struct Buffer *buf)
Get the human name for a key.
Definition lib.c:390
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_find_func()

struct Keymap * km_find_func ( enum MenuType mtype,
int func )

Find a function's mapping in a Menu.

Parameters
mtypeMenu type, e.g. MENU_PAGER
funcFunction, e.g. OP_DELETE
Return values
ptrKeymap for the function

Definition at line 466 of file lib.c.

467{
468 struct Keymap *np = NULL;
469 STAILQ_FOREACH(np, &Keymaps[mtype], entries)
470 {
471 if (np->op == func)
472 break;
473 }
474 return np;
475}
+ Here is the caller graph for this function:

◆ km_get_table()

const struct MenuFuncOp * km_get_table ( enum MenuType mtype)

Lookup a Menu's functions.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
Return values
ptrArray of functions

Definition at line 482 of file lib.c.

483{
484 switch (mtype)
485 {
486 case MENU_ALIAS:
487 return OpAlias;
488 case MENU_ATTACHMENT:
489 return OpAttachment;
490#ifdef USE_AUTOCRYPT
491 case MENU_AUTOCRYPT:
492 return OpAutocrypt;
493#endif
494 case MENU_BROWSER:
495 return OpBrowser;
496 case MENU_COMPOSE:
497 return OpCompose;
498 case MENU_DIALOG:
499 return OpDialog;
500 case MENU_EDITOR:
501 return OpEditor;
502 case MENU_GENERIC:
503 return OpGeneric;
504 case MENU_INDEX:
505 return OpIndex;
506 case MENU_PAGER:
507 return OpPager;
508 case MENU_PGP:
509 return OpPgp;
510 case MENU_POSTPONED:
511 return OpPostponed;
512 case MENU_QUERY:
513 return OpQuery;
514 case MENU_SMIME:
515 return OpSmime;
516 default:
517 return NULL;
518 }
519}
const struct MenuFuncOp OpQuery[]
Functions for the external Query Menu.
Definition functions.c:75
const struct MenuFuncOp OpAlias[]
Functions for the Alias Menu.
Definition functions.c:59
const struct MenuFuncOp OpAttachment[]
Functions for the Attachment Menu.
Definition functions.c:62
const struct MenuFuncOp OpAutocrypt[]
Functions for the Autocrypt Account.
Definition functions.c:54
const struct MenuFuncOp OpBrowser[]
Functions for the file Browser Menu.
Definition functions.c:72
const struct MenuFuncOp OpCompose[]
Functions for the Compose Menu.
Definition functions.c:87
const struct MenuFuncOp OpEditor[]
Functions for the Editor Menu.
Definition functions.c:53
const struct MenuFuncOp OpDialog[]
Functions for Simple Dialogs.
Definition functions.c:60
const struct MenuFuncOp OpIndex[]
Functions for the Index Menu.
Definition functions.c:90
const struct MenuFuncOp OpPostponed[]
Functions for the Postpone Menu.
Definition functions.c:52
const struct MenuFuncOp OpSmime[]
Functions for the Smime Menu.
Definition functions.c:52
const struct MenuFuncOp OpPager[]
Functions for the Pager Menu.
Definition functions.c:70
const struct MenuFuncOp OpPgp[]
Functions for the Pgp Menu.
Definition functions.c:42
+ Here is the caller graph for this function:

◆ km_keyname()

void km_keyname ( int c,
struct Buffer * buf )

Get the human name for a key.

Parameters
[in]cKey code
[out]bufBuffer for the result

Definition at line 390 of file lib.c.

391{
392 const char *name = mutt_map_get_name(c, KeyNames);
393 if (name)
394 {
395 buf_addstr(buf, name);
396 return;
397 }
398
399 if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
400 {
401 if (c < 0)
402 c += 256;
403
404 if (c < 128)
405 {
406 buf_addch(buf, '^');
407 buf_addch(buf, (c + '@') & 0x7f);
408 }
409 else
410 {
411 buf_add_printf(buf, "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
412 }
413 }
414 else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
415 {
416 buf_add_printf(buf, "<F%d>", c - KEY_F0);
417 }
418 else if ((c < 256) && (c >= -128) && IsPrint(c))
419 {
420 buf_add_printf(buf, "%c", (unsigned char) c);
421 }
422 else
423 {
424 buf_add_printf(buf, "<%ho>", (unsigned short) c);
425 }
426}
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
struct Mapping KeyNames[]
Key name lookup table.
Definition lib.c:58
#define IsPrint(ch)
Definition mbyte.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alloc_keys()

struct Keymap * alloc_keys ( size_t len,
keycode_t * keys )

Allocate space for a sequence of keys.

Parameters
lenNumber of keys
keysArray of keys
Return values
ptrSequence of keys

Definition at line 150 of file lib.c.

151{
152 struct Keymap *p = MUTT_MEM_CALLOC(1, struct Keymap);
153 p->len = len;
155 memcpy(p->keys, keys, len * sizeof(keycode_t));
156 return p;
157}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
+ Here is the caller graph for this function:

◆ generic_tokenize_push_string()

void generic_tokenize_push_string ( char * s)

Parse and queue a 'push' command.

Parameters
sString to push into the key queue

Parses s for <function> syntax and adds the whole sequence the macro buffer.

Definition at line 348 of file get.c.

349{
350 char *pp = NULL;
351 char *p = s + mutt_str_len(s) - 1;
352 size_t l;
353 int i, op = OP_NULL;
354
355 while (p >= s)
356 {
357 /* if we see something like "<PageUp>", look to see if it is a real
358 * function name and return the corresponding value */
359 if (*p == '>')
360 {
361 for (pp = p - 1; pp >= s && *pp != '<'; pp--)
362 ; // do nothing
363
364 if (pp >= s)
365 {
366 i = parse_fkey(pp);
367 if (i > 0)
368 {
369 mutt_push_macro_event(KEY_F(i), 0);
370 p = pp - 1;
371 continue;
372 }
373
374 l = p - pp + 1;
375 for (i = 0; KeyNames[i].name; i++)
376 {
377 if (mutt_istrn_equal(pp, KeyNames[i].name, l))
378 break;
379 }
380 if (KeyNames[i].name)
381 {
382 /* found a match */
383 mutt_push_macro_event(KeyNames[i].value, 0);
384 p = pp - 1;
385 continue;
386 }
387
388 /* See if it is a valid command
389 * skip the '<' and the '>' when comparing */
390 for (enum MenuType j = 0; MenuNames[j].name; j++)
391 {
392 const struct MenuFuncOp *funcs = km_get_table(MenuNames[j].value);
393 if (funcs)
394 {
395 op = get_op(funcs, pp + 1, l - 2);
396 if (op != OP_NULL)
397 break;
398 }
399 }
400
401 if (op != OP_NULL)
402 {
404 p = pp - 1;
405 continue;
406 }
407 }
408 }
409 mutt_push_macro_event((unsigned char) *p--, 0); /* independent 8 bits chars */
410 }
411}
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition get.c:155
int parse_fkey(char *s)
Parse a function key string.
Definition lib.c:166
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition lib.c:299
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:498
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition string.c:455
int op
Operation, e.g. OP_DELETE.
Definition lib.h:117
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_op()

int get_op ( const struct MenuFuncOp * funcs,
const char * start,
size_t len )

Get the function by its name.

Parameters
funcsFunctions table
startName of function to find
lenLength of string to match
Return values
numOperation, e.g. OP_DELETE

Definition at line 299 of file lib.c.

300{
301 for (int i = 0; funcs[i].name; i++)
302 {
303 if (mutt_istrn_equal(start, funcs[i].name, len) && (mutt_str_len(funcs[i].name) == len))
304 {
305 return funcs[i].op;
306 }
307 }
308
309 return OP_NULL;
310}
const char * name
Name of the function.
Definition lib.h:116
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_compare_keys()

struct Keymap * km_compare_keys ( struct Keymap * k1,
struct Keymap * k2,
size_t * pos )

Compare two keymaps' keyscodes and return the bigger one.

Parameters
k1first keymap to compare
k2second keymap to compare
posposition where the two keycodes differ
Return values
ptrKeymap with a bigger ASCII keycode

Definition at line 275 of file lib.c.

276{
277 *pos = 0;
278
279 while (*pos < k1->len && *pos < k2->len)
280 {
281 if (k1->keys[*pos] < k2->keys[*pos])
282 return k2;
283 else if (k1->keys[*pos] > k2->keys[*pos])
284 return k1;
285 else
286 *pos = *pos + 1;
287 }
288
289 return NULL;
290}
+ Here is the caller graph for this function:

◆ mutt_get_func()

const char * mutt_get_func ( const struct MenuFuncOp * funcs,
int op )

Get the name of a function.

Parameters
funcsFunctions table
opOperation, e.g. OP_DELETE
Return values
ptrName of function
NULLOperation not found
Note
This returns a static string.

Definition at line 321 of file lib.c.

322{
323 if (!funcs)
324 return NULL;
325
326 for (int i = 0; funcs[i].name; i++)
327 {
328 if (funcs[i].op == op)
329 return funcs[i].name;
330 }
331
332 return NULL;
333}
+ Here is the caller graph for this function:

◆ mutt_keymap_free()

void mutt_keymap_free ( struct Keymap ** ptr)

Free a Keymap.

Parameters
ptrKeymap to free

Definition at line 131 of file lib.c.

132{
133 if (!ptr || !*ptr)
134 return;
135
136 struct Keymap *km = *ptr;
137 FREE(&km->macro);
138 FREE(&km->desc);
139 FREE(&km->keys);
140
141 FREE(ptr);
142}
#define FREE(x)
Definition memory.h:62
+ Here is the caller graph for this function:

◆ parse_fkey()

int parse_fkey ( char * s)

Parse a function key string.

Parameters
sString to parse
Return values
numNumber of the key

Given "<f8>", it will return 8.

Definition at line 166 of file lib.c.

167{
168 char *t = NULL;
169 int n = 0;
170
171 if ((s[0] != '<') || (mutt_tolower(s[1]) != 'f'))
172 return -1;
173
174 for (t = s + 2; *t && mutt_isdigit(*t); t++)
175 {
176 n *= 10;
177 n += *t - '0';
178 }
179
180 if (*t != '>')
181 return -1;
182 return n;
183}
int mutt_tolower(int arg)
Wrapper for tolower(3)
Definition ctype.c:125
bool mutt_isdigit(int arg)
Wrapper for isdigit(3)
Definition ctype.c:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parsekeys()

size_t parsekeys ( const char * str,
keycode_t * d,
size_t max )

Parse a key string into key codes.

Parameters
strKey string
dArray for key codes
maxMaximum length of key sequence
Return values
numLength of key sequence

Definition at line 216 of file lib.c.

217{
218 int n;
219 size_t len = max;
220 char buf[128] = { 0 };
221 char c;
222 char *t = NULL;
223
224 mutt_str_copy(buf, str, sizeof(buf));
225 char *s = buf;
226
227 while (*s && len)
228 {
229 *d = '\0';
230 if ((*s == '<') && (t = strchr(s, '>')))
231 {
232 t++;
233 c = *t;
234 *t = '\0';
235
237 if (n != -1)
238 {
239 s = t;
240 *d = n;
241 }
242 else if ((n = parse_fkey(s)) > 0)
243 {
244 s = t;
245 *d = KEY_F(n);
246 }
247 else if ((n = parse_keycode(s)) > 0)
248 {
249 s = t;
250 *d = n;
251 }
252
253 *t = c;
254 }
255
256 if (!*d)
257 {
258 *d = (unsigned char) *s;
259 s++;
260 }
261 d++;
262 len--;
263 }
264
265 return max - len;
266}
static int parse_keycode(const char *s)
Parse a numeric keycode.
Definition lib.c:193
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition mapping.c:85
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition string.c:581
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_expand_key_string()

void km_expand_key_string ( char * str,
struct Buffer * buf )

Get a human-readable key string.

Parameters
[in]strRaw key string
[out]bufBuffer for the key string

Definition at line 452 of file lib.c.

453{
454 for (; *str; str++)
455 {
456 km_keyname(*str, buf);
457 }
458}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_getch()

struct KeyEvent mutt_getch ( GetChFlags flags)

Read a character from the input buffer.

Parameters
flagsFlags, e.g. GETCH_IGNORE_MACRO
Return values
objKeyEvent to process

The priority for reading events is:

  1. UngetKeyEvents buffer
  2. MacroEvents buffer
  3. Keyboard

This function can return:

  • Abort { 0, OP_ABORT }
  • Repaint { 0, OP_REPAINT }
  • Timeout { 0, OP_TIMEOUT }

Definition at line 210 of file get.c.

211{
212 static const struct KeyEvent event_abort = { 0, OP_ABORT };
213 static const struct KeyEvent event_repaint = { 0, OP_REPAINT };
214 static const struct KeyEvent event_timeout = { 0, OP_TIMEOUT };
215
216 if (!OptGui)
217 return event_abort;
218
219 struct KeyEvent *event_key = array_pop(&UngetKeyEvents);
220 if (event_key)
221 return *event_key;
222
223 if (!(flags & GETCH_IGNORE_MACRO))
224 {
225 event_key = array_pop(&MacroEvents);
226 if (event_key)
227 return *event_key;
228 }
229
230 int ch;
231 SigInt = false;
233 timeout(1000); // 1 second
234#ifdef USE_INOTIFY
236#else
237 ch = getch();
238#endif
240
241 if (SigInt)
242 {
244 return event_abort;
245 }
246
247 if (ch == KEY_RESIZE)
248 {
249 timeout(0);
250 while ((ch = getch()) == KEY_RESIZE)
251 {
252 // do nothing
253 }
254 }
255
256 if (ch == ERR)
257 {
258 if (!isatty(STDIN_FILENO)) // terminal was lost
259 mutt_exit(1);
260
261 if (SigWinch)
262 {
263 SigWinch = false;
265 return event_repaint;
266 }
267
269 return event_timeout;
270 }
271
272 if (ch == AbortKey)
273 return event_abort;
274
275 if (ch & 0x80)
276 {
277 const bool c_meta_key = cs_subset_bool(NeoMutt->sub, "meta_key");
278 if (c_meta_key)
279 {
280 /* send ALT-x as ESC-x */
281 ch &= ~0x80;
283 return (struct KeyEvent) { '\033', OP_NULL }; // Escape
284 }
285 }
286
287 return (struct KeyEvent) { ch, OP_NULL };
288}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
void mutt_query_exit(void)
Ask the user if they want to leave NeoMutt.
Definition curs_lib.c:138
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition exit.c:41
static struct KeyEventArray UngetKeyEvents
These are used in all other "normal" situations, and are not ignored when passing GETCH_IGNORE_MACRO.
Definition get.c:53
static struct KeyEvent * array_pop(struct KeyEventArray *a)
Remove an event from the array.
Definition get.c:70
static int mutt_monitor_getch(void)
Get a character and poll the filesystem monitor.
Definition get.c:177
bool OptGui
(pseudo) when the gui (and curses) are started
Definition globals.c:59
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
@ NT_TIMEOUT
Timeout has occurred.
Definition notify_type.h:56
@ NT_RESIZE
Window has been resized.
Definition notify_type.h:52
#define OP_TIMEOUT
1 second with no events
Definition opcodes.h:35
#define OP_REPAINT
Repaint is needed.
Definition opcodes.h:34
volatile sig_atomic_t SigWinch
true after SIGWINCH is received
Definition signal.c:69
volatile sig_atomic_t SigInt
true after SIGINT is received
Definition signal.c:68
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
Definition signal.c:315
struct Notify * notify_timeout
Timeout notifications handler.
Definition neomutt.h:46
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_flushinp()

void mutt_flushinp ( void )

Empty all the keyboard buffers.

Definition at line 58 of file get.c.

59{
62 flushinp();
63}
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition array.h:172
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
+ Here is the caller graph for this function:

◆ mutt_push_macro_event()

void mutt_push_macro_event ( int ch,
int op )

Add the character/operation to the macro buffer.

Parameters
chCharacter to add
opOperation to add

Adds the ch/op to the macro buffer. This should be used for macros, push, and exec commands only.

Definition at line 155 of file get.c.

156{
157 array_add(&MacroEvents, ch, op);
158}
static void array_add(struct KeyEventArray *a, int ch, int op)
Add an event to the end of the array.
Definition get.c:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_unget_ch()

void mutt_unget_ch ( int ch)

Return a keystroke to the input buffer.

Parameters
chKey press

This puts events into the UngetKeyEvents buffer

Definition at line 115 of file get.c.

116{
117 array_add(&UngetKeyEvents, ch, OP_NULL);
118}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_unget_op()

void mutt_unget_op ( int op)

Return an operation to the input buffer.

Parameters
opOperation, e.g. OP_DELETE

This puts events into the UngetKeyEvents buffer

Definition at line 126 of file get.c.

127{
128 array_add(&UngetKeyEvents, 0, op);
129}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_unget_string()

void mutt_unget_string ( const char * s)

Return a string to the input buffer.

Parameters
sString to return

This puts events into the UngetKeyEvents buffer

Definition at line 137 of file get.c.

138{
139 const char *p = s + mutt_str_len(s) - 1;
140
141 while (p >= s)
142 {
143 mutt_unget_ch((unsigned char) *p--);
144 }
145}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ measure_column()

int measure_column ( struct BindingInfoArray * bia,
int col )

Measure one column of a table.

Parameters
biaArray of binding info
colColumn to measure
Return values
numWidth of widest column

Definition at line 413 of file dump.c.

414{
415 int max_width = 0;
416
417 struct BindingInfo *bi = NULL;
418 ARRAY_FOREACH(bi, bia)
419 {
420 const int col_width = mutt_strwidth(bi->a[col]);
421 max_width = MAX(max_width, col_width);
422 }
423
424 return max_width;
425}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition curs_lib.c:445
#define MAX(a, b)
Definition memory.h:36
Info about one keybinding.
Definition lib.h:95
const char * a[3]
Array of info.
Definition lib.h:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gather_menu()

void gather_menu ( enum MenuType menu,
struct BindingInfoArray * bia_bind,
struct BindingInfoArray * bia_macro )

Gather info about one menu.

Parameters
menuMenu type
bia_bindArray for bind results (may be NULL)
bia_macroArray for macro results (may be NULL)

Definition at line 357 of file dump.c.

359{
360 struct Buffer *key_binding = buf_pool_get();
361 struct Buffer *macro = buf_pool_get();
362
363 struct Keymap *map = NULL;
364 STAILQ_FOREACH(map, &Keymaps[menu], entries)
365 {
366 struct BindingInfo bi = { 0 };
367
368 buf_reset(key_binding);
369 km_expand_key(map, key_binding);
370
371 if (map->op == OP_MACRO)
372 {
373 if (!bia_macro || (map->op == OP_NULL))
374 continue;
375
376 buf_reset(macro);
377 escape_macro(map->macro, macro);
378 bi.a[0] = buf_strdup(key_binding);
379 bi.a[1] = buf_strdup(macro);
380 bi.a[2] = map->desc;
381 ARRAY_ADD(bia_macro, bi);
382 }
383 else
384 {
385 if (!bia_bind)
386 continue;
387
388 if (map->op == OP_NULL)
389 {
390 bi.a[0] = buf_strdup(key_binding);
391 bi.a[1] = "noop";
392 ARRAY_ADD(bia_bind, bi);
393 continue;
394 }
395
396 bi.a[0] = buf_strdup(key_binding);
397 bi.a[1] = help_lookup_function(map->op, menu);
398 bi.a[2] = _(opcodes_get_description(map->op));
399 ARRAY_ADD(bia_bind, bi);
400 }
401 }
402
403 buf_pool_release(&key_binding);
404 buf_pool_release(&macro);
405}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:156
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * help_lookup_function(int op, enum MenuType menu)
Find a keybinding for an operation.
Definition dump.c:336
void escape_macro(const char *macro, struct Buffer *buf)
Escape any special characters in a macro.
Definition dump.c:282
const char * opcodes_get_description(int op)
Get the description of an opcode.
Definition opcodes.c:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gather_unbound()

int gather_unbound ( const struct MenuFuncOp * funcs,
const struct KeymapList * km_menu,
const struct KeymapList * km_aux,
struct BindingInfoArray * bia_unbound )

Gather info about unbound functions for one menu.

Parameters
funcsList of functions
km_menuKeymaps for the menu
km_auxKeymaps for generic
bia_unboundUnbound functions
Return values
numNumber of unbound functions

Definition at line 363 of file lib.c.

365{
366 if (!funcs)
367 return 0;
368
369 for (int i = 0; funcs[i].name; i++)
370 {
371 if (!funcs[i].deprecated && !is_bound(km_menu, funcs[i].op) &&
372 (!km_aux || !is_bound(km_aux, funcs[i].op)))
373 {
374 struct BindingInfo bi = { 0 };
375 bi.a[0] = NULL;
376 bi.a[1] = funcs[i].name;
377 bi.a[2] = _(opcodes_get_description(funcs[i].op));
378 ARRAY_ADD(bia_unbound, bi);
379 }
380 }
381
382 return ARRAY_SIZE(bia_unbound);
383}
bool is_bound(const struct KeymapList *km_list, int op)
Does a function have a keybinding?
Definition lib.c:341
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MacroEvents

struct KeyEventArray MacroEvents
extern

These are used for macros and exec/push commands.

They can be temporarily ignored by passing GETCH_IGNORE_MACRO

Definition at line 49 of file get.c.

◆ Keymaps

struct KeymapList Keymaps[]
extern

Array of Keymap keybindings, one for each Menu.

Array of Keymap keybindings, one for each Menu.

Definition at line 125 of file lib.c.

◆ KeyNames

struct Mapping KeyNames[]
extern

Key name lookup table.

Definition at line 58 of file lib.c.

58 {
59 // clang-format off
60 { "<PageUp>", KEY_PPAGE },
61 { "<PageDown>", KEY_NPAGE },
62 { "<Up>", KEY_UP },
63 { "<Down>", KEY_DOWN },
64 { "<Right>", KEY_RIGHT },
65 { "<Left>", KEY_LEFT },
66 { "<Delete>", KEY_DC },
67 { "<BackSpace>", KEY_BACKSPACE },
68 { "<Insert>", KEY_IC },
69 { "<Home>", KEY_HOME },
70 { "<End>", KEY_END },
71 { "<Enter>", '\n' },
72 { "<Return>", '\r' },
73#ifdef KEY_ENTER
74 { "<KeypadEnter>", KEY_ENTER },
75#else
76 { "<KeypadEnter>", '\n' },
77#endif
78 { "<Esc>", '\033' }, // Escape
79 { "<Tab>", '\t' },
80 { "<Space>", ' ' },
81#ifdef KEY_BTAB
82 { "<BackTab>", KEY_BTAB },
83#endif
84#ifdef KEY_NEXT
85 { "<Next>", KEY_NEXT },
86#endif
87 /* extensions supported by ncurses. values are filled in during initialization */
88
89 /* CTRL+key */
90 { "<C-Up>", -1 },
91 { "<C-Down>", -1 },
92 { "<C-Left>", -1 },
93 { "<C-Right>", -1 },
94 { "<C-Home>", -1 },
95 { "<C-End>", -1 },
96 { "<C-Next>", -1 },
97 { "<C-Prev>", -1 },
98
99 /* SHIFT+key */
100 { "<S-Up>", -1 },
101 { "<S-Down>", -1 },
102 { "<S-Left>", -1 },
103 { "<S-Right>", -1 },
104 { "<S-Home>", -1 },
105 { "<S-End>", -1 },
106 { "<S-Next>", -1 },
107 { "<S-Prev>", -1 },
108
109 /* ALT+key */
110 { "<A-Up>", -1 },
111 { "<A-Down>", -1 },
112 { "<A-Left>", -1 },
113 { "<A-Right>", -1 },
114 { "<A-Home>", -1 },
115 { "<A-End>", -1 },
116 { "<A-Next>", -1 },
117 { "<A-Prev>", -1 },
118 { NULL, 0 },
119 // clang-format off
120};

◆ AbortKey

keycode_t AbortKey
extern

key to abort edits etc, normally Ctrl-G

key to abort edits etc, normally Ctrl-G

Definition at line 122 of file lib.c.

◆ Menus

const struct Mapping Menus[]
extern