1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/**
* @file
* Dump keybindings
*
* @authors
* Copyright (C) 2023 Richard Russon <rich@flatcap.org>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* 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/>.
*/
/**
* @page debug_keymap Dump keybindings
*
* Dump keybindings
*/
#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"
/**
* log_bind - Dumps all the binds maps of a menu into a buffer
* @param menu Menu to dump
* @param keystr Bound string
* @param map Keybinding
*/
void log_bind(enum MenuType menu, const char *keystr, struct Keymap *map)
{
if (map->op == OP_NULL)
{
mutt_debug(LL_DEBUG1, " bind %s noop\n", keystr);
return;
}
const char *fn_name = NULL;
/* The pager and editor menus don't use the generic map,
* however for other menus try generic first. */
if ((menu != MENU_PAGER) && (menu != MENU_EDITOR) && (menu != MENU_GENERIC))
{
fn_name = mutt_get_func(OpGeneric, map->op);
}
/* if it's one of the menus above or generic doesn't find the function,
* try with its own menu. */
if (!fn_name)
{
const struct MenuFuncOp *funcs = km_get_table(menu);
if (!funcs)
return;
fn_name = mutt_get_func(funcs, map->op);
}
mutt_debug(LL_DEBUG1, " bind %-8s <%s>\n", keystr, fn_name);
mutt_debug(LL_DEBUG1, " op = %d (%s)\n", map->op, opcodes_get_name(map->op));
mutt_debug(LL_DEBUG1, " eq = %d\n", map->eq);
struct Buffer *keys = buf_pool_get();
for (int i = 0; i < map->len; i++)
{
buf_add_printf(keys, "%d ", map->keys[i]);
}
mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
buf_pool_release(&keys);
}
/**
* log_macro - Dumps all the macros maps of a menu into a buffer
* @param keystr Bound string
* @param map Keybinding
*/
void log_macro(const char *keystr, struct Keymap *map)
{
struct Buffer *esc_macro = buf_pool_get();
escape_string(esc_macro, map->macro);
mutt_debug(LL_DEBUG1, " macro %-8s \"%s\"\n", keystr, buf_string(esc_macro));
if (map->desc)
mutt_debug(LL_DEBUG1, " %s\n", map->desc);
buf_pool_release(&esc_macro);
mutt_debug(LL_DEBUG1, " op = %d\n", map->op);
mutt_debug(LL_DEBUG1, " eq = %d\n", map->eq);
struct Buffer *keys = buf_pool_get();
for (int i = 0; i < map->len; i++)
{
buf_add_printf(keys, "%d ", map->keys[i]);
}
mutt_debug(LL_DEBUG1, " keys: %s\n", buf_string(keys));
buf_pool_release(&keys);
}
/**
* log_menu - Dump a Menu's keybindings to the log
* @param menu Menu to dump
* @param kml Map of keybindings
*/
void log_menu(enum MenuType menu, struct KeymapList *kml)
{
struct Keymap *map = NULL;
if (STAILQ_EMPTY(kml))
{
mutt_debug(LL_DEBUG1, " [NONE]\n");
return;
}
struct Buffer *binding = buf_pool_get();
struct Buffer *esc_key = buf_pool_get();
STAILQ_FOREACH(map, kml, entries)
{
buf_reset(binding);
km_expand_key(map, binding);
buf_reset(esc_key);
escape_string(esc_key, buf_string(binding));
if (map->op == OP_MACRO)
log_macro(buf_string(esc_key), map);
else
log_bind(menu, buf_string(esc_key), map);
}
buf_pool_release(&binding);
buf_pool_release(&esc_key);
}
/**
* dump_keybindings - Dump all the keybindings to the log
*/
void dump_keybindings(void)
{
mutt_debug(LL_DEBUG1, "Keybindings:\n");
for (int i = 1; i < MENU_MAX; i++)
{
mutt_debug(LL_DEBUG1, "Menu: %s\n", mutt_map_get_name(i, MenuNames));
log_menu(i, &Keymaps[i]);
}
}
|