NeoMutt  2025-12-11-600-ge0eaf0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
keymap.c File Reference

Dump keybindings. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "key/lib.h"
+ Include dependency graph for keymap.c:

Go to the source code of this file.

Data Structures

struct  SubMenuId
 

Functions

 ARRAY_HEAD (SubMenuIdArray, struct SubMenuId)
 
void log_bind (const struct MenuDefinition *md, const char *keystr, struct Keymap *km)
 Log a key binding.
 
void log_macro (const char *keystr, struct Keymap *km)
 Dumps all the macros maps of a menu into a buffer.
 
void dump_submenu_functions (const struct SubMenu *sm, bool brief)
 Dump submenu functions.
 
void dump_submenu_bindings (const struct MenuDefinition *md, const struct SubMenu *sm, bool brief)
 Dump submenu bindings.
 
void dump_submenus (bool brief, struct SubMenuIdArray *smia)
 Dump all submenus.
 
void dump_menus (struct SubMenuIdArray *smia)
 Dump all menus.
 
void dump_menu_funcs (bool brief)
 Dump all menu functions.
 
void dump_menu_binds (bool brief)
 Dump all menu bindings.
 

Detailed Description

Dump keybindings.

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 keymap.c.

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( SubMenuIdArray ,
struct SubMenuId  )

◆ log_bind()

void log_bind ( const struct MenuDefinition * md,
const char * keystr,
struct Keymap * km )

Log a key binding.

Parameters
mdMenu definition
keystrKey string
kmKey mapping

Definition at line 51 of file keymap.c.

52{
53 const char *fn_name = NULL;
54
55 struct SubMenu **smp = NULL;
56 ARRAY_FOREACH(smp, &md->submenus)
57 {
58 fn_name = help_lookup_function(md, km->op);
59 if (fn_name)
60 break;
61 }
62
63 mutt_debug(LL_DEBUG1, " bind %-8s <%s>\n", keystr, fn_name);
64 mutt_debug(LL_DEBUG1, " op = %d (%s)\n", km->op, opcodes_get_name(km->op));
65 mutt_debug(LL_DEBUG1, " eq = %d\n", km->eq);
66
67 struct Buffer *keys = buf_pool_get();
68 for (int i = 0; i < km->len; i++)
69 {
70 buf_add_printf(keys, "%d ", km->keys[i]);
71 }
72 mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
73 buf_pool_release(&keys);
74}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
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
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
const char * help_lookup_function(const struct MenuDefinition *md, int op)
Find a keybinding for an operation.
Definition dump.c:108
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
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:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
keycode_t * keys
Key sequence.
Definition keymap.h:49
short eq
Number of leading keys equal to next entry.
Definition keymap.h:47
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition keymap.h:48
short op
Operation to perform.
Definition keymap.h:46
struct SubMenuPArray submenus
Parts making up the Menu.
Definition menu.h:83
Collection of related functions.
Definition menu.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ log_macro()

void log_macro ( const char * keystr,
struct Keymap * km )

Dumps all the macros maps of a menu into a buffer.

Parameters
keystrBound string
kmKeybinding

Definition at line 81 of file keymap.c.

82{
83 struct Buffer *esc_macro = buf_pool_get();
84 escape_string(esc_macro, km->macro);
85
86 mutt_debug(LL_DEBUG1, " macro %-8s \"%s\"\n", keystr, buf_string(esc_macro));
87 if (km->desc)
88 mutt_debug(LL_DEBUG1, " %s\n", km->desc);
89
90 buf_pool_release(&esc_macro);
91
92 mutt_debug(LL_DEBUG1, " op = %d\n", km->op);
93 mutt_debug(LL_DEBUG1, " eq = %d\n", km->eq);
94 struct Buffer *keys = buf_pool_get();
95 for (int i = 0; i < km->len; i++)
96 {
97 buf_add_printf(keys, "%d ", km->keys[i]);
98 }
99 mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
100 buf_pool_release(&keys);
101}
size_t escape_string(struct Buffer *buf, const char *src)
Write a string to a buffer, escaping special characters.
Definition dump.c:47
char * macro
Macro expansion (op == OP_MACRO)
Definition keymap.h:44
char * desc
Description of a macro for the help menu.
Definition keymap.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_submenu_functions()

void dump_submenu_functions ( const struct SubMenu * sm,
bool brief )

Dump submenu functions.

Parameters
smSubmenu to dump
briefTrue for brief output

Definition at line 108 of file keymap.c.

109{
110 for (int i = 0; sm->functions[i].name; i++)
111 {
112 if (brief && (i > 2))
113 {
114 mutt_debug(LL_DEBUG1, " ...\n");
115 break;
116 }
117
118 const struct MenuFuncOp *mfo = &sm->functions[i];
119 mutt_debug(LL_DEBUG1, " \"%s\" -> %s (%d)\n", mfo->name,
120 opcodes_get_name(mfo->op), mfo->op);
121 }
122}
Mapping between a function and an operation.
Definition menu.h:38
const char * name
Name of the function.
Definition menu.h:39
int op
Operation, e.g. OP_DELETE.
Definition menu.h:40
const struct MenuFuncOp * functions
All available functions.
Definition menu.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_submenu_bindings()

void dump_submenu_bindings ( const struct MenuDefinition * md,
const struct SubMenu * sm,
bool brief )

Dump submenu bindings.

Parameters
mdMenu definition
smSubmenu to dump
briefTrue for brief output

Definition at line 130 of file keymap.c.

131{
132 if (STAILQ_EMPTY(&sm->keymaps))
133 {
134 mutt_debug(LL_DEBUG1, " [NONE]\n");
135 return;
136 }
137
138 struct Buffer *binding = buf_pool_get();
139 struct Buffer *esc_key = buf_pool_get();
140
141 int count = 0;
142 struct Keymap *km = NULL;
143 STAILQ_FOREACH(km, &sm->keymaps, entries)
144 {
145 if (brief && (count++ > 2))
146 {
147 mutt_debug(LL_DEBUG1, " ...\n");
148 break;
149 }
150
151 buf_reset(binding);
152 keymap_expand_key(km, binding);
153
154 buf_reset(esc_key);
155 escape_string(esc_key, buf_string(binding));
156
157 if (km->op == OP_MACRO)
158 log_macro(buf_string(esc_key), km);
159 else
160 log_bind(md, buf_string(esc_key), km);
161 }
162
163 buf_pool_release(&binding);
164 buf_pool_release(&esc_key);
165}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
void log_macro(const char *keystr, struct Keymap *km)
Dumps all the macros maps of a menu into a buffer.
Definition keymap.c:81
void log_bind(const struct MenuDefinition *md, const char *keystr, struct Keymap *km)
Log a key binding.
Definition keymap.c:51
bool keymap_expand_key(struct Keymap *km, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition keymap.c:229
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define STAILQ_EMPTY(head)
Definition queue.h:382
A keyboard mapping.
Definition keymap.h:43
struct KeymapList keymaps
All keybindings.
Definition menu.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_submenus()

void dump_submenus ( bool brief,
struct SubMenuIdArray * smia )

Dump all submenus.

Parameters
briefTrue for brief output
smiaSubmenu ID array to populate

Definition at line 172 of file keymap.c.

173{
174 struct SubMenu *sm = NULL;
176 {
177 struct SubMenuId smi = { ARRAY_FOREACH_IDX_sm, sm };
178 ARRAY_ADD(smia, smi);
179
180 int i = 0;
181 for (; sm->functions[i].name; i++)
182 ; // Do nothing
183
184 if (sm->parent)
185 mutt_debug(LL_DEBUG1, "SubMenu ID %d (%d functions) -- %s:\n",
186 ARRAY_FOREACH_IDX_sm, i, sm->parent->name);
187 else
188 mutt_debug(LL_DEBUG1, "SubMenu ID %d (%d functions):\n", ARRAY_FOREACH_IDX_sm, i);
189
191 mutt_debug(LL_DEBUG1, "\n");
192 }
193}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
void dump_submenu_functions(const struct SubMenu *sm, bool brief)
Dump submenu functions.
Definition keymap.c:108
struct SubMenuArray SubMenus
All the registered SubMenus.
Definition init.c:45
const char * name
Menu name, e.g. "alias".
Definition menu.h:82
struct SubMenu * sm
Definition keymap.c:41
struct MenuDefinition * parent
Primary parent.
Definition menu.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_menus()

void dump_menus ( struct SubMenuIdArray * smia)

Dump all menus.

Parameters
smiaSubmenu ID array

Definition at line 199 of file keymap.c.

200{
201 struct Buffer *buf = buf_pool_get();
202
203 mutt_debug(LL_DEBUG1, "Menus:\n");
204 struct MenuDefinition **mdp = NULL;
206 {
207 struct MenuDefinition *md = *mdp;
208
209 buf_printf(buf, " \"%s\" - %s (%d) - SubMenu IDs: ", md->name,
210 name_menu_type(md->id), md->id);
211
212 struct SubMenu **smp = NULL;
213 ARRAY_FOREACH(smp, &md->submenus)
214 {
215 struct SubMenuId *smi = NULL;
216 struct SubMenu *sm = *smp;
217 int id = -1;
218
219 ARRAY_FOREACH(smi, smia)
220 {
221 if (smi->sm == sm)
222 {
223 id = smi->id;
224 break;
225 }
226 }
227
228 const char *name = sm->parent ? sm->parent->name : "UNKNOWN";
229 buf_add_printf(buf, "%s (%d)", name, id);
230
231 if (ARRAY_FOREACH_IDX_smp < (ARRAY_SIZE(&md->submenus) - 1))
232 {
233 buf_add_printf(buf, ", ");
234 }
235 }
236 mutt_debug(LL_DEBUG1, "%s\n", buf_string(buf));
237 }
238
239 buf_pool_release(&buf);
240}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
const char * name_menu_type(enum MenuType mt)
Get the name of a menu type.
Definition names.c:275
struct MenuDefinitionArray MenuDefs
All the registered Menus.
Definition init.c:42
Functions for a Dialog or Window.
Definition menu.h:80
int id
Menu ID, e.g. MENU_ALIAS.
Definition menu.h:81
int id
Definition keymap.c:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_menu_funcs()

void dump_menu_funcs ( bool brief)

Dump all menu functions.

Parameters
briefTrue for brief output

Definition at line 246 of file keymap.c.

247{
248 struct SubMenuIdArray smia = ARRAY_HEAD_INITIALIZER;
249
250 dump_submenus(brief, &smia);
251 dump_menus(&smia);
252
253 ARRAY_FREE(&smia);
254}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
void dump_menus(struct SubMenuIdArray *smia)
Dump all menus.
Definition keymap.c:199
void dump_submenus(bool brief, struct SubMenuIdArray *smia)
Dump all submenus.
Definition keymap.c:172
+ Here is the call graph for this function:

◆ dump_menu_binds()

void dump_menu_binds ( bool brief)

Dump all menu bindings.

Parameters
briefTrue for brief output

Definition at line 260 of file keymap.c.

261{
262 struct MenuDefinition **mdp = NULL;
264 {
265 struct MenuDefinition *md = *mdp;
266
267 struct SubMenu *sm = *ARRAY_FIRST(&md->submenus);
268
269 int count = 0;
270 struct Keymap *km = NULL;
271 STAILQ_FOREACH(km, &sm->keymaps, entries)
272 {
273 count++;
274 }
275
276 mutt_debug(LL_DEBUG1, "Menu %s (%s/%d) - (%d bindings):\n", md->name,
277 name_menu_type(md->id), md->id, count);
278 dump_submenu_bindings(md, sm, brief);
279 mutt_debug(LL_DEBUG1, "\n");
280 }
281}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
void dump_submenu_bindings(const struct MenuDefinition *md, const struct SubMenu *sm, bool brief)
Dump submenu bindings.
Definition keymap.c:130
+ Here is the call graph for this function: