NeoMutt  2024-12-12-14-g7b49f7
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 STAILQ_FOREACH(map, &Keymaps[menu], entries)
57 {
58 if (map->op == OP_MACRO)
59 continue;
60
61 char key_binding[128] = { 0 };
62 const char *fn_name = NULL;
63
64 km_expand_key(key_binding, sizeof(key_binding), map);
65 if (map->op == OP_NULL)
66 {
67 buf_add_printf(buf, "bind %s %s noop\n", name, key_binding);
68 continue;
69 }
70
71 /* The pager and editor menus don't use the generic map,
72 * however for other menus try generic first. */
73 if ((menu != MENU_PAGER) && (menu != MENU_EDITOR) && (menu != MENU_GENERIC))
74 {
75 fn_name = mutt_get_func(OpGeneric, map->op);
76 }
77
78 /* if it's one of the menus above or generic doesn't find
79 * the function, try with its own menu. */
80 if (!fn_name)
81 {
82 const struct MenuFuncOp *funcs = km_get_table(menu);
83 if (!funcs)
84 continue;
85
86 fn_name = mutt_get_func(funcs, map->op);
87 }
88
89 buf_add_printf(buf, "bind %s %s %s\n", name, key_binding, fn_name);
90 empty = false;
91 }
92
93 return empty;
94}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
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:125
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: lib.c:457
const char * mutt_get_func(const struct MenuFuncOp *funcs, int op)
Get the name of a function.
Definition: lib.c:321
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:525
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A keyboard mapping.
Definition: lib.h:65
short op
Operation to perform.
Definition: lib.h:68
Mapping between a function and an operation.
Definition: lib.h:101
const char * name
Name of the function.
Definition: lib.h:102
@ 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 100 of file dump.c.

101{
102 for (enum MenuType i = 1; i < MENU_MAX; i++)
103 {
104 const bool empty = dump_bind(buf, i, mutt_map_get_name(i, MenuNames));
105
106 /* Add a new line for readability between menus. */
107 if (!empty && (i < (MENU_MAX - 1)))
108 buf_addch(buf, '\n');
109 }
110}
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 120 of file dump.c.

121{
122 bool empty = true;
123 struct Keymap *map = NULL;
124
125 STAILQ_FOREACH(map, &Keymaps[menu], entries)
126 {
127 if (map->op != OP_MACRO)
128 continue;
129
130 char key_binding[128] = { 0 };
131 km_expand_key(key_binding, sizeof(key_binding), map);
132
133 struct Buffer *tmp = buf_pool_get();
134 escape_string(tmp, map->macro);
135
136 if (map->desc)
137 {
138 buf_add_printf(buf, "macro %s %s \"%s\" \"%s\"\n", name, key_binding,
139 tmp->data, map->desc);
140 }
141 else
142 {
143 buf_add_printf(buf, "macro %s %s \"%s\"\n", name, key_binding, tmp->data);
144 }
145
146 buf_pool_release(&tmp);
147 empty = false;
148 }
149
150 return empty;
151}
size_t escape_string(struct Buffer *buf, const char *src)
Write a string to a buffer, escaping special characters.
Definition: dump.c:48
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
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
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:

◆ 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 157 of file dump.c.

158{
159 for (enum MenuType i = 1; i < MENU_MAX; i++)
160 {
161 const bool empty = dump_macro(buf, i, mutt_map_get_name(i, MenuNames));
162
163 /* Add a new line for legibility between menus. */
164 if (!empty && (i < (MENU_MAX - 1)))
165 buf_addch(buf, '\n');
166 }
167}
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:120
+ Here is the call graph for this function:
+ Here is the caller graph for this function: