NeoMutt  2025-01-09-81-g753ae0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dump.c File Reference

Dump key bindings. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "pager/lib.h"
#include "parse/lib.h"
+ Include dependency graph for dump.c:

Go to the source code of this file.

Functions

static bool dump_bind (struct Buffer *buf, enum MenuType menu, const char *name)
 Dumps all the binds maps of a menu into a buffer.
 
static void dump_all_binds (struct Buffer *buf)
 Dumps all the binds inside every menu.
 
static bool dump_macro (struct Buffer *buf, enum MenuType menu, const char *name)
 Dumps all the macros maps of a menu into a buffer.
 
static void dump_all_macros (struct Buffer *buf)
 Dumps all the macros inside every menu.
 
enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse 'bind' and 'macro' commands - Implements Command::parse() -.
 

Detailed Description

Dump key bindings.

Authors
  • Richard Russon
  • Dennis Schön

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

Function Documentation

◆ dump_bind()

static bool dump_bind ( struct Buffer buf,
enum MenuType  menu,
const char *  name 
)
static

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

Parameters
bufOutput buffer
menuMenu to dump
nameMenu name
Return values
trueMenu is empty
falseMenu is not empty

Definition at line 51 of file dump.c.

52{
53 bool empty = true;
54 struct Keymap *map = NULL;
55
56 struct Buffer *key_binding = buf_pool_get();
57
58 STAILQ_FOREACH(map, &Keymaps[menu], entries)
59 {
60 if (map->op == OP_MACRO)
61 continue;
62
63 const char *fn_name = NULL;
64
65 buf_reset(key_binding);
66 km_expand_key(map, key_binding);
67 if (map->op == OP_NULL)
68 {
69 buf_add_printf(buf, "bind %s %s noop\n", name, buf_string(key_binding));
70 continue;
71 }
72
73 /* The pager and editor menus don't use the generic map,
74 * however for other menus try generic first. */
75 if ((menu != MENU_PAGER) && (menu != MENU_EDITOR) && (menu != MENU_GENERIC))
76 {
77 fn_name = mutt_get_func(OpGeneric, map->op);
78 }
79
80 /* if it's one of the menus above or generic doesn't find
81 * the function, try with its own menu. */
82 if (!fn_name)
83 {
84 const struct MenuFuncOp *funcs = km_get_table(menu);
85 if (!funcs)
86 continue;
87
88 fn_name = mutt_get_func(funcs, map->op);
89 }
90
91 buf_add_printf(buf, "bind %s %s %s\n", name, buf_string(key_binding), fn_name);
92 empty = false;
93 }
94
95 buf_pool_release(&key_binding);
96 return empty;
97}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:68
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:124
const char * mutt_get_func(const struct MenuFuncOp *funcs, int op)
Get the name of a function.
Definition: lib.c:320
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:499
bool km_expand_key(struct Keymap *map, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition: lib.c:451
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:390
String manipulation buffer.
Definition: buffer.h:36
A keyboard mapping.
Definition: lib.h:66
short op
Operation to perform.
Definition: lib.h:69
Mapping between a function and an operation.
Definition: lib.h:102
const char * name
Name of the function.
Definition: lib.h:103
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:52
@ 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:

◆ dump_all_binds()

static void dump_all_binds ( struct Buffer buf)
static

Dumps all the binds inside every menu.

Parameters
bufOutput buffer

Definition at line 103 of file dump.c.

104{
105 for (enum MenuType i = 1; i < MENU_MAX; i++)
106 {
107 const bool empty = dump_bind(buf, i, mutt_map_get_name(i, MenuNames));
108
109 /* Add a new line for readability between menus. */
110 if (!empty && (i < (MENU_MAX - 1)))
111 buf_addch(buf, '\n');
112 }
113}
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:241
static bool dump_bind(struct Buffer *buf, enum MenuType menu, const char *name)
Dumps all the binds maps of a menu into a buffer.
Definition: dump.c:51
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
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_MAX
Definition: type.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_macro()

static bool dump_macro ( struct Buffer buf,
enum MenuType  menu,
const char *  name 
)
static

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

Parameters
bufOutput buffer
menuMenu to dump
nameMenu name
Return values
trueMenu is empty
falseMenu is not empty

Definition at line 123 of file dump.c.

124{
125 bool empty = true;
126 struct Keymap *map = NULL;
127
128 struct Buffer *key_binding = buf_pool_get();
129
130 STAILQ_FOREACH(map, &Keymaps[menu], entries)
131 {
132 if (map->op != OP_MACRO)
133 continue;
134
135 buf_reset(key_binding);
136 km_expand_key(map, key_binding);
137
138 struct Buffer *tmp = buf_pool_get();
139 escape_string(tmp, map->macro);
140
141 if (map->desc)
142 {
143 buf_add_printf(buf, "macro %s %s \"%s\" \"%s\"\n", name,
144 buf_string(key_binding), buf_string(tmp), map->desc);
145 }
146 else
147 {
148 buf_add_printf(buf, "macro %s %s \"%s\"\n", name, buf_string(key_binding),
149 buf_string(tmp));
150 }
151
152 buf_pool_release(&tmp);
153 empty = false;
154 }
155
156 buf_pool_release(&key_binding);
157 return empty;
158}
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:67
char * desc
Description of a macro for the help menu.
Definition: lib.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_all_macros()

static void dump_all_macros ( struct Buffer buf)
static

Dumps all the macros inside every menu.

Parameters
bufOutput buffer

Definition at line 164 of file dump.c.

165{
166 for (enum MenuType i = 1; i < MENU_MAX; i++)
167 {
168 const bool empty = dump_macro(buf, i, mutt_map_get_name(i, MenuNames));
169
170 /* Add a new line for legibility between menus. */
171 if (!empty && (i < (MENU_MAX - 1)))
172 buf_addch(buf, '\n');
173 }
174}
static bool dump_macro(struct Buffer *buf, enum MenuType menu, const char *name)
Dumps all the macros maps of a menu into a buffer.
Definition: dump.c:123
+ Here is the call graph for this function:
+ Here is the caller graph for this function: