NeoMutt  2025-12-11-899-ga9216f
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 "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "key/lib.h"
#include "key/module_data.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 53 of file keymap.c.

54{
55 const char *fn_name = NULL;
56
57 struct SubMenu **smp = NULL;
58 ARRAY_FOREACH(smp, &md->submenus)
59 {
60 fn_name = help_lookup_function(md, km->op);
61 if (fn_name)
62 break;
63 }
64
65 mutt_debug(LL_DEBUG1, " bind %-8s <%s>\n", keystr, fn_name);
66 mutt_debug(LL_DEBUG1, " op = %d (%s)\n", km->op, opcodes_get_name(km->op));
67 mutt_debug(LL_DEBUG1, " eq = %d\n", km->eq);
68
69 struct Buffer *keys = buf_pool_get();
70 for (int i = 0; i < km->len; i++)
71 {
72 buf_add_printf(keys, "%d ", km->keys[i]);
73 }
74 mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
75 buf_pool_release(&keys);
76}
#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:80
Collection of related functions.
Definition menu.h:65
+ 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 83 of file keymap.c.

84{
85 struct Buffer *esc_macro = buf_pool_get();
86 escape_string(esc_macro, km->macro);
87
88 mutt_debug(LL_DEBUG1, " macro %-8s \"%s\"\n", keystr, buf_string(esc_macro));
89 if (km->desc)
90 mutt_debug(LL_DEBUG1, " %s\n", km->desc);
91
92 buf_pool_release(&esc_macro);
93
94 mutt_debug(LL_DEBUG1, " op = %d\n", km->op);
95 mutt_debug(LL_DEBUG1, " eq = %d\n", km->eq);
96 struct Buffer *keys = buf_pool_get();
97 for (int i = 0; i < km->len; i++)
98 {
99 buf_add_printf(keys, "%d ", km->keys[i]);
100 }
101 mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
102 buf_pool_release(&keys);
103}
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 110 of file keymap.c.

111{
112 for (int i = 0; sm->functions[i].name; i++)
113 {
114 if (brief && (i > 2))
115 {
116 mutt_debug(LL_DEBUG1, " ...\n");
117 break;
118 }
119
120 const struct MenuFuncOp *mfo = &sm->functions[i];
121 mutt_debug(LL_DEBUG1, " \"%s\" -> %s (%d)\n", mfo->name,
122 opcodes_get_name(mfo->op), mfo->op);
123 }
124}
Mapping between a function and an operation.
Definition menu.h:35
const char * name
Name of the function.
Definition menu.h:36
int op
Operation, e.g. OP_DELETE.
Definition menu.h:37
const struct MenuFuncOp * functions
All available functions.
Definition menu.h:67
+ 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 132 of file keymap.c.

133{
134 if (STAILQ_EMPTY(&sm->keymaps))
135 {
136 mutt_debug(LL_DEBUG1, " [NONE]\n");
137 return;
138 }
139
140 struct Buffer *binding = buf_pool_get();
141 struct Buffer *esc_key = buf_pool_get();
142
143 int count = 0;
144 struct Keymap *km = NULL;
145 STAILQ_FOREACH(km, &sm->keymaps, entries)
146 {
147 if (brief && (count++ > 2))
148 {
149 mutt_debug(LL_DEBUG1, " ...\n");
150 break;
151 }
152
153 buf_reset(binding);
154 keymap_expand_key(km, binding);
155
156 buf_reset(esc_key);
157 escape_string(esc_key, buf_string(binding));
158
159 if (km->op == OP_MACRO)
160 log_macro(buf_string(esc_key), km);
161 else
162 log_bind(md, buf_string(esc_key), km);
163 }
164
165 buf_pool_release(&binding);
166 buf_pool_release(&esc_key);
167}
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:83
void log_bind(const struct MenuDefinition *md, const char *keystr, struct Keymap *km)
Log a key binding.
Definition keymap.c:53
bool keymap_expand_key(struct Keymap *km, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition keymap.c:248
#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:68
+ 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 174 of file keymap.c.

175{
177 struct SubMenu *sm = NULL;
178 ARRAY_FOREACH(sm, &mod_data->sub_menus)
179 {
180 struct SubMenuId smi = { ARRAY_FOREACH_IDX_sm, sm };
181 ARRAY_ADD(smia, smi);
182
183 int i = 0;
184 for (; sm->functions[i].name; i++)
185 ; // Do nothing
186
187 if (sm->parent)
188 mutt_debug(LL_DEBUG1, "SubMenu ID %d (%d functions) -- %s:\n",
189 ARRAY_FOREACH_IDX_sm, i, sm->parent->name);
190 else
191 mutt_debug(LL_DEBUG1, "SubMenu ID %d (%d functions):\n", ARRAY_FOREACH_IDX_sm, i);
192
194 mutt_debug(LL_DEBUG1, "\n");
195 }
196}
#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:110
@ MODULE_ID_KEY
ModuleKey, Key mappings
Definition module_api.h:73
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
Key private Module data.
Definition module_data.h:34
struct SubMenuArray sub_menus
All registered SubMenus.
Definition module_data.h:40
const char * name
Menu name, e.g. "alias".
Definition menu.h:79
Container for Accounts, Notifications.
Definition neomutt.h:41
struct SubMenu * sm
Definition keymap.c:43
struct MenuDefinition * parent
Primary parent.
Definition menu.h:66
+ 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 202 of file keymap.c.

203{
205 struct Buffer *buf = buf_pool_get();
206
207 mutt_debug(LL_DEBUG1, "Menus:\n");
208 struct MenuDefinition **mdp = NULL;
209 ARRAY_FOREACH(mdp, &mod_data->menu_defs)
210 {
211 struct MenuDefinition *md = *mdp;
212
213 buf_printf(buf, " \"%s\" - %s (%d) - SubMenu IDs: ", md->name,
214 name_menu_type(md->id), md->id);
215
216 struct SubMenu **smp = NULL;
217 ARRAY_FOREACH(smp, &md->submenus)
218 {
219 struct SubMenuId *smi = NULL;
220 struct SubMenu *sm = *smp;
221 int id = -1;
222
223 ARRAY_FOREACH(smi, smia)
224 {
225 if (smi->sm == sm)
226 {
227 id = smi->id;
228 break;
229 }
230 }
231
232 const char *name = sm->parent ? sm->parent->name : "UNKNOWN";
233 buf_add_printf(buf, "%s (%d)", name, id);
234
235 if (ARRAY_FOREACH_IDX_smp < (ARRAY_SIZE(&md->submenus) - 1))
236 {
237 buf_add_printf(buf, ", ");
238 }
239 }
240 mutt_debug(LL_DEBUG1, "%s\n", buf_string(buf));
241 }
242
243 buf_pool_release(&buf);
244}
#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 menu_defs
All registered Menus.
Definition module_data.h:39
Functions for a Dialog or Window.
Definition menu.h:77
int id
Menu ID, e.g. MENU_ALIAS.
Definition menu.h:78
int id
Definition keymap.c:42
+ 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 250 of file keymap.c.

251{
252 struct SubMenuIdArray smia = ARRAY_HEAD_INITIALIZER;
253
254 dump_submenus(brief, &smia);
255 dump_menus(&smia);
256
257 ARRAY_FREE(&smia);
258}
#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:202
void dump_submenus(bool brief, struct SubMenuIdArray *smia)
Dump all submenus.
Definition keymap.c:174
+ 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 264 of file keymap.c.

265{
267 struct MenuDefinition **mdp = NULL;
268 ARRAY_FOREACH(mdp, &mod_data->menu_defs)
269 {
270 struct MenuDefinition *md = *mdp;
271
272 struct SubMenu *sm = *ARRAY_FIRST(&md->submenus);
273
274 int count = 0;
275 struct Keymap *km = NULL;
276 STAILQ_FOREACH(km, &sm->keymaps, entries)
277 {
278 count++;
279 }
280
281 mutt_debug(LL_DEBUG1, "Menu %s (%s/%d) - (%d bindings):\n", md->name,
282 name_menu_type(md->id), md->id, count);
283 dump_submenu_bindings(md, sm, brief);
284 mutt_debug(LL_DEBUG1, "\n");
285 }
286}
#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:132
+ Here is the call graph for this function: