NeoMutt  2024-02-01-23-g345d7b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
keymap.c File Reference

Dump keybindings. More...

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

Go to the source code of this file.

Functions

void log_bind (enum MenuType menu, const char *keystr, struct Keymap *map)
 Dumps all the binds maps of a menu into a buffer.
 
void log_macro (const char *keystr, struct Keymap *map)
 Dumps all the macros maps of a menu into a buffer.
 
void log_menu (enum MenuType menu, struct KeymapList *kml)
 Dump a Menu's keybindings to the log.
 
void dump_keybindings (void)
 Dump all the keybindings to the log.
 

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

◆ log_bind()

void log_bind ( enum MenuType  menu,
const char *  keystr,
struct Keymap map 
)

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

Parameters
menuMenu to dump
keystrBound string
mapKeybinding

Definition at line 43 of file keymap.c.

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}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:221
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:68
const char * mutt_get_func(const struct MenuFuncOp *funcs, int op)
Get the name of a function.
Definition: lib.c:324
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:528
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
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
String manipulation buffer.
Definition: buffer.h:36
keycode_t * keys
key sequence
Definition: lib.h:71
short eq
Number of leading keys equal to next entry.
Definition: lib.h:69
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
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:55
@ MENU_EDITOR
Text entry area.
Definition: type.h:44
+ 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 map 
)

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

Parameters
keystrBound string
mapKeybinding

Definition at line 88 of file keymap.c.

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}
size_t escape_string(struct Buffer *buf, const char *src)
Write a string to a buffer, escaping special characters.
Definition: dump.c:48
char * macro
Macro expansion (op == OP_MACRO)
Definition: lib.h:66
char * desc
Description of a macro for the help menu.
Definition: lib.h:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ log_menu()

void log_menu ( enum MenuType  menu,
struct KeymapList *  kml 
)

Dump a Menu's keybindings to the log.

Parameters
menuMenu to dump
kmlMap of keybindings

Definition at line 115 of file keymap.c.

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}
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: lib.c:460
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
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
A keyboard mapping.
Definition: lib.h:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_keybindings()

void dump_keybindings ( void  )

Dump all the keybindings to the log.

Definition at line 145 of file keymap.c.

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}
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:128
void log_menu(enum MenuType menu, struct KeymapList *kml)
Dump a Menu's keybindings to the log.
Definition: keymap.c:115
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
@ MENU_MAX
Definition: type.h:60
+ Here is the call graph for this function: