NeoMutt  2025-09-05-43-g177ed6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h
Go to the documentation of this file.
1
22
37
38#ifndef MUTT_KEY_LIB_H
39#define MUTT_KEY_LIB_H
40
41#include "config.h"
42#include <stdbool.h>
43#include <stddef.h>
44#include <stdint.h>
45#include "mutt/lib.h"
46#include "core/lib.h"
47#include "menu/lib.h"
48
49#define MUTT_UNBIND (1 << 0)
50#define MUTT_UNMACRO (1 << 1)
51
52typedef uint8_t GetChFlags;
53#define GETCH_NO_FLAGS 0
54#define GETCH_IGNORE_MACRO (1 << 0)
55
57typedef short keycode_t;
58
66struct Keymap
67{
68 char *macro;
69 char *desc;
70 short op;
71 short eq;
72 short len;
75};
76STAILQ_HEAD(KeymapList, Keymap);
77
82{
83 int ch;
84 int op;
85};
86ARRAY_HEAD(KeyEventArray, struct KeyEvent);
87
95{
96 const char *a[3];
97};
98ARRAY_HEAD(BindingInfoArray, struct BindingInfo);
99
100extern struct KeyEventArray MacroEvents;
101
102extern struct KeymapList Keymaps[];
103extern struct Mapping KeyNames[];
104
105extern keycode_t AbortKey;
106
107extern const struct Mapping Menus[];
108
109#define OP_DEPRECATED true
110
115{
116 const char *name;
117 int op;
119};
120
125{
126 int op;
127 const char *seq;
128};
129
134{
136 const char *key;
137 int op;
138};
139
157
158// key/extended
159#ifdef HAVE_USE_EXTENDED_NAMES
160void init_extended_keys(void);
161#else
162static inline void init_extended_keys(void) {}
163#endif
164
165// key/commands.c
166enum CommandResult km_bind (const char *s, enum MenuType mtype, int op, char *macro, char *desc, struct Buffer *err);
167enum CommandResult parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
168enum CommandResult parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
169enum CommandResult parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
170enum CommandResult parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
171enum CommandResult parse_unbind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
172
173// key/init.c
174void km_init (void);
176void mutt_init_abort_key (void);
177void mutt_keys_cleanup (void);
178
179// key/get.c
180int km_dokey (enum MenuType menu, GetChFlags flags);
181struct KeyEvent km_dokey_event (enum MenuType menu, GetChFlags flags);
182void km_error_key (enum MenuType menu);
184
185// key/lib.c
186bool km_expand_key (struct Keymap *map, struct Buffer *buf);
187struct Keymap * km_find_func (enum MenuType menu, int func);
188const struct MenuFuncOp *km_get_table (enum MenuType mtype);
189void km_keyname (int c, struct Buffer *buf);
190
191// Private to libkey
192struct Keymap * alloc_keys (size_t len, keycode_t *keys);
193enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err);
194void generic_tokenize_push_string(char *s);
195int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len);
196struct Keymap * km_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos);
197const char * mutt_get_func (const struct MenuFuncOp *bindings, int op);
198void mutt_keymap_free (struct Keymap **ptr);
199int parse_fkey (char *s);
200size_t parsekeys (const char *str, keycode_t *d, size_t max);
201void km_expand_key_string (char *str, struct Buffer *buf);
202
203int measure_column(struct BindingInfoArray *bia, int col);
204void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro);
205int gather_unbound(const struct MenuFuncOp *funcs, const struct KeymapList *km_menu, const struct KeymapList *km_aux, struct BindingInfoArray *bia_unbound);
206int binding_sort(const void *a, const void *b, void *sdata);
207
208#endif /* MUTT_KEY_LIB_H */
#define ARRAY_HEAD(name, type)
Define a named struct for arrays of elements of a certain type.
Definition array.h:47
CommandResult
Error codes for command_t parse functions.
Definition command.h:35
Convenience wrapper for the core headers.
struct KeyEvent km_dokey_event(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:419
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition get.c:49
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 dump_bind_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse 'bind' and 'macro' commands - Implements Command::parse() -.
Definition dump.c:172
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
int main_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition init.c:147
int binding_sort(const void *a, const void *b, void *sdata)
Compare two BindingInfo by their keybinding - Implements sort_t -.
Definition lib.c:411
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition lib.c:121
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition lib.c:124
struct Mapping KeyNames[]
Key name lookup table.
Definition lib.c:59
uint8_t GetChFlags
Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.
Definition lib.h:52
const struct Mapping Menus[]
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
NotifyBinding
Key Binding notification types.
Definition lib.h:148
@ 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
int parse_fkey(char *s)
Parse a function key string.
Definition lib.c:165
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition get.c:348
int km_dokey(enum MenuType menu, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:537
int measure_column(struct BindingInfoArray *bia, int col)
Measure one column of a table.
Definition lib.c:430
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:274
struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition lib.c:149
void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
Gather info about one menu.
Definition lib.c:638
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition lib.c:130
void km_init(void)
Initialise all the menu keybindings.
Definition init.c:73
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function's mapping in a Menu.
Definition lib.c:555
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition lib.c:215
const char * mutt_get_func(const struct MenuFuncOp *bindings, int op)
Get the name of a function.
Definition lib.c:320
void km_error_key(enum MenuType menu)
Handle an unbound key sequence.
Definition get.c:294
void km_keyname(int c, struct Buffer *buf)
Get the human name for a key.
Definition lib.c:479
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition lib.h:57
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition get.c:166
static void init_extended_keys(void)
Definition lib.h:162
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition lib.c:571
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition lib.c:298
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.
Definition lib.c:452
void mutt_keys_cleanup(void)
Free the key maps.
Definition init.c:112
bool km_expand_key(struct Keymap *map, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition lib.c:523
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition init.c:125
void km_expand_key_string(char *str, struct Buffer *buf)
Get a human-readable key string.
Definition lib.c:541
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#define STAILQ_HEAD(name, type)
Definition queue.h:312
Info about one keybinding.
Definition lib.h:95
const char * a[3]
Array of info.
Definition lib.h:96
String manipulation buffer.
Definition buffer.h:36
A key binding Event.
Definition lib.h:134
const char * key
Key string being bound (for new bind/macro)
Definition lib.h:136
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition lib.h:137
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition lib.h:135
An event such as a keypress.
Definition lib.h:82
int op
Function opcode, e.g. OP_HELP.
Definition lib.h:84
int ch
Raw key pressed.
Definition lib.h:83
A keyboard mapping.
Definition lib.h:67
keycode_t * keys
key sequence
Definition lib.h:73
char * macro
Macro expansion (op == OP_MACRO)
Definition lib.h:68
STAILQ_ENTRY(Keymap) entries
Linked list.
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
Mapping between user-readable string and a constant.
Definition mapping.h:33
Mapping between a function and an operation.
Definition lib.h:115
const char * name
Name of the function.
Definition lib.h:116
int op
Operation, e.g. OP_DELETE.
Definition lib.h:117
bool deprecated
Deprecated function.
Definition lib.h:118
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
Data passed to a notification function.
Definition observer.h:34
MenuType
Types of GUI selections.
Definition type.h:36