NeoMutt  2025-09-05-43-g177ed6
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 "core/lib.h"
#include "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 int print_bind (enum MenuType menu, FILE *fp)
 Display the bindings for one menu.
 
static void colon_bind (enum MenuType menu, FILE *fp)
 Dump the key bindings.
 
static int print_macro (enum MenuType menu, FILE *fp)
 Display the macros for one menu.
 
static void colon_macro (enum MenuType menu, FILE *fp)
 Dump the macros.
 
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

◆ print_bind()

static int print_bind ( enum MenuType menu,
FILE * fp )
static

Display the bindings for one menu.

Parameters
menuMenu type
fpFile to write to
Return values
numNumber of bindings

Definition at line 47 of file dump.c.

48{
49 struct BindingInfoArray bia_bind = ARRAY_HEAD_INITIALIZER;
50
51 gather_menu(menu, &bia_bind, NULL);
52 if (ARRAY_EMPTY(&bia_bind))
53 return 0;
54
55 ARRAY_SORT(&bia_bind, binding_sort, NULL);
56 const int wb0 = measure_column(&bia_bind, 0);
57 const int wb1 = measure_column(&bia_bind, 1);
58
59 const char *menu_name = mutt_map_get_name(menu, MenuNames);
60
61 struct BindingInfo *bi = NULL;
62 ARRAY_FOREACH(bi, &bia_bind)
63 {
64 //XXX use description?
65 fprintf(fp, "bind %s %*s %*s # %s\n", menu_name, -wb0, bi->a[0], -wb1,
66 bi->a[1], bi->a[2]);
67 }
68
69 const int count = ARRAY_SIZE(&bia_bind);
70 ARRAY_FOREACH(bi, &bia_bind)
71 {
72 // we only need to free the keybinding
73 FREE(&bi->a[0]);
74 }
75
76 return count;
77}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition array.h:335
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
int binding_sort(const void *a, const void *b, void *sdata)
Compare two BindingInfo by their keybinding - Implements sort_t -.
Definition lib.c:411
int measure_column(struct BindingInfoArray *bia, int col)
Measure one column of a table.
Definition lib.c:430
void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
Gather info about one menu.
Definition lib.c:638
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition mapping.c:42
#define FREE(x)
Definition memory.h:62
Info about one keybinding.
Definition lib.h:95
const char * a[3]
Array of info.
Definition lib.h:96
const struct Mapping MenuNames[]
Menu name lookup table.
Definition type.c:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ colon_bind()

static void colon_bind ( enum MenuType menu,
FILE * fp )
static

Dump the key bindings.

Parameters
menuMenu type
fpFile to write to

Definition at line 84 of file dump.c.

85{
86 if (menu == MENU_MAX)
87 {
88 for (enum MenuType i = 1; i < MENU_MAX; i++)
89 {
90 if (print_bind(i, fp) > 0)
91 fprintf(fp, "\n");
92 }
93 }
94 else
95 {
96 print_bind(menu, fp);
97 }
98}
static int print_bind(enum MenuType menu, FILE *fp)
Display the bindings for one menu.
Definition dump.c:47
MenuType
Types of GUI selections.
Definition type.h:36
@ MENU_MAX
Definition type.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_macro()

static int print_macro ( enum MenuType menu,
FILE * fp )
static

Display the macros for one menu.

Parameters
menuMenu type
fpFile to write to
Return values
numNumber of macros

Definition at line 106 of file dump.c.

107{
108 struct BindingInfoArray bia_macro = ARRAY_HEAD_INITIALIZER;
109
110 gather_menu(menu, NULL, &bia_macro);
111 if (ARRAY_EMPTY(&bia_macro))
112 return 0;
113
114 ARRAY_SORT(&bia_macro, binding_sort, NULL);
115 const int wm0 = measure_column(&bia_macro, 0);
116
117 const char *menu_name = mutt_map_get_name(menu, MenuNames);
118
119 struct BindingInfo *bi = NULL;
120 ARRAY_FOREACH(bi, &bia_macro)
121 {
122 if (bi->a[2]) // description
123 {
124 fprintf(fp, "macro %s %*s \"%s\" \"%s\"\n", menu_name, -wm0, bi->a[0],
125 bi->a[1], bi->a[2]);
126 }
127 else
128 {
129 fprintf(fp, "macro %s %*s \"%s\"\n", menu_name, -wm0, bi->a[0], bi->a[1]);
130 }
131 }
132
133 const int count = ARRAY_SIZE(&bia_macro);
134 ARRAY_FOREACH(bi, &bia_macro)
135 {
136 // free the keybinding and the macro text
137 FREE(&bi->a[0]);
138 FREE(&bi->a[1]);
139 }
140
141 ARRAY_FREE(&bia_macro);
142 return count;
143}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:204
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ colon_macro()

static void colon_macro ( enum MenuType menu,
FILE * fp )
static

Dump the macros.

Parameters
menuMenu type
fpFile to write to

Definition at line 150 of file dump.c.

151{
152 if (menu == MENU_MAX)
153 {
154 for (enum MenuType i = 1; i < MENU_MAX; i++)
155 {
156 if (print_macro(i, fp) > 0)
157 {
158 //XXX need to elide last blank line
159 fprintf(fp, "\n");
160 }
161 }
162 }
163 else
164 {
165 print_macro(menu, fp);
166 }
167}
static int print_macro(enum MenuType menu, FILE *fp)
Display the macros for one menu.
Definition dump.c:106
+ Here is the call graph for this function:
+ Here is the caller graph for this function: