NeoMutt  2024-10-02-34-g9dd811
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
keymap.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdio.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "gui/lib.h"
34#include "key/lib.h"
35#include "menu/lib.h"
36
43void log_bind(enum MenuType menu, const char *keystr, struct Keymap *map)
44{
45 if (map->op == OP_NULL)
46 {
47 mutt_debug(LL_DEBUG1, " bind %s noop\n", keystr);
48 return;
49 }
50
51 const char *fn_name = NULL;
52 /* The pager and editor menus don't use the generic map,
53 * however for other menus try generic first. */
54 if ((menu != MENU_PAGER) && (menu != MENU_EDITOR) && (menu != MENU_GENERIC))
55 {
56 fn_name = mutt_get_func(OpGeneric, map->op);
57 }
58
59 /* if it's one of the menus above or generic doesn't find the function,
60 * try with its own menu. */
61 if (!fn_name)
62 {
63 const struct MenuFuncOp *funcs = km_get_table(menu);
64 if (!funcs)
65 return;
66
67 fn_name = mutt_get_func(funcs, map->op);
68 }
69
70 mutt_debug(LL_DEBUG1, " bind %-8s <%s>\n", keystr, fn_name);
71 mutt_debug(LL_DEBUG1, " op = %d (%s)\n", map->op, opcodes_get_name(map->op));
72 mutt_debug(LL_DEBUG1, " eq = %d\n", map->eq);
73
74 struct Buffer *keys = buf_pool_get();
75 for (int i = 0; i < map->len; i++)
76 {
77 buf_add_printf(keys, "%d ", map->keys[i]);
78 }
79 mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
80 buf_pool_release(&keys);
81}
82
88void log_macro(const char *keystr, struct Keymap *map)
89{
90 struct Buffer *esc_macro = buf_pool_get();
91 escape_string(esc_macro, map->macro);
92
93 mutt_debug(LL_DEBUG1, " macro %-8s \"%s\"\n", keystr, buf_string(esc_macro));
94 if (map->desc)
95 mutt_debug(LL_DEBUG1, " %s\n", map->desc);
96
97 buf_pool_release(&esc_macro);
98
99 mutt_debug(LL_DEBUG1, " op = %d\n", map->op);
100 mutt_debug(LL_DEBUG1, " eq = %d\n", map->eq);
101 struct Buffer *keys = buf_pool_get();
102 for (int i = 0; i < map->len; i++)
103 {
104 buf_add_printf(keys, "%d ", map->keys[i]);
105 }
106 mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
107 buf_pool_release(&keys);
108}
109
115void log_menu(enum MenuType menu, struct KeymapList *kml)
116{
117 struct Keymap *map = NULL;
118
119 if (STAILQ_EMPTY(kml))
120 {
121 mutt_debug(LL_DEBUG1, " [NONE]\n");
122 return;
123 }
124
125 STAILQ_FOREACH(map, kml, entries)
126 {
127 char key_binding[128] = { 0 };
128 km_expand_key(key_binding, sizeof(key_binding), map);
129
130 struct Buffer *esc_key = buf_pool_get();
131 escape_string(esc_key, key_binding);
132
133 if (map->op == OP_MACRO)
134 log_macro(buf_string(esc_key), map);
135 else
136 log_bind(menu, buf_string(esc_key), map);
137
138 buf_pool_release(&esc_key);
139 }
140}
141
146{
147 mutt_debug(LL_DEBUG1, "Keybindings:\n");
148 for (int i = 1; i < MENU_MAX; i++)
149 {
151 log_menu(i, &Keymaps[i]);
152 }
153}
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
size_t escape_string(struct Buffer *buf, const char *src)
Write a string to a buffer, escaping special characters.
Definition: dump.c:48
Convenience wrapper for the config headers.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:68
Convenience wrapper for the gui headers.
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:125
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: lib.c:457
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:525
Manage keymappings.
void log_macro(const char *keystr, struct Keymap *map)
Dumps all the macros maps of a menu into a buffer.
Definition: keymap.c:88
void log_bind(enum MenuType menu, const char *keystr, struct Keymap *map)
Dumps all the binds maps of a menu into a buffer.
Definition: keymap.c:43
void log_menu(enum MenuType menu, struct KeymapList *kml)
Dump a Menu's keybindings to the log.
Definition: keymap.c:115
void dump_keybindings(void)
Dump all the keybindings to the log.
Definition: keymap.c:145
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
String manipulation buffer.
Definition: buffer.h:36
A keyboard mapping.
Definition: lib.h:65
keycode_t * keys
key sequence
Definition: lib.h:71
char * macro
Macro expansion (op == OP_MACRO)
Definition: lib.h:66
short eq
Number of leading keys equal to next entry.
Definition: lib.h:69
char * desc
Description of a macro for the help menu.
Definition: lib.h:67
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition: lib.h:70
short op
Operation to perform.
Definition: lib.h:68
Mapping between a function and an operation.
Definition: lib.h:101
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:52
@ MENU_MAX
Definition: type.h:57
@ MENU_EDITOR
Text entry area.
Definition: type.h:44