NeoMutt  2025-01-09-104-g5de5ef
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 "key/lib.h"
#include "menu/lib.h"
#include "pager/lib.h"
#include "parse/lib.h"
#include <libintl.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 50 of file dump.c.

51{
52 struct BindingInfoArray bia_bind = ARRAY_HEAD_INITIALIZER;
53
54 gather_menu(menu, &bia_bind, NULL);
55 if (ARRAY_EMPTY(&bia_bind))
56 return 0;
57
58 ARRAY_SORT(&bia_bind, binding_sort, NULL);
59 const int wb0 = measure_column(&bia_bind, 0);
60 const int wb1 = measure_column(&bia_bind, 1);
61
62 const char *menu_name = mutt_map_get_name(menu, MenuNames);
63
64 struct BindingInfo *bi = NULL;
65 ARRAY_FOREACH(bi, &bia_bind)
66 {
67 //XXX use description?
68 fprintf(fp, "bind %s %*s %*s # %s\n", menu_name, -wb0, bi->a[0], -wb1,
69 bi->a[1], bi->a[2]);
70 }
71
72 const int count = ARRAY_SIZE(&bia_bind);
73 ARRAY_FOREACH(bi, &bia_bind)
74 {
75 // we only need to free the keybinding
76 FREE(&bi->a[0]);
77 }
78
79 return count;
80}
#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:405
int measure_column(struct BindingInfoArray *bia, int col)
Measure one column of a table.
Definition: lib.c:419
void gather_menu(enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
Gather info about one menu.
Definition: lib.c:624
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:55
Info about one keybinding.
Definition: lib.h:94
const char * a[3]
Array of info.
Definition: lib.h:95
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 87 of file dump.c.

88{
89 if (menu == MENU_MAX)
90 {
91 for (enum MenuType i = 1; i < MENU_MAX; i++)
92 {
93 print_bind(i, fp);
94
95 //XXX need to elide last blank line
96 fprintf(fp, "\n");
97 }
98 }
99 else
100 {
101 print_bind(menu, fp);
102 }
103}
static int print_bind(enum MenuType menu, FILE *fp)
Display the bindings for one menu.
Definition: dump.c:50
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 111 of file dump.c.

112{
113 struct BindingInfoArray bia_macro = ARRAY_HEAD_INITIALIZER;
114
115 gather_menu(menu, NULL, &bia_macro);
116 if (ARRAY_EMPTY(&bia_macro))
117 return 0;
118
119 ARRAY_SORT(&bia_macro, binding_sort, NULL);
120 const int wm0 = measure_column(&bia_macro, 0);
121
122 const char *menu_name = mutt_map_get_name(menu, MenuNames);
123
124 struct BindingInfo *bi = NULL;
125 ARRAY_FOREACH(bi, &bia_macro)
126 {
127 if (bi->a[2]) // description
128 {
129 fprintf(fp, "macro %s %*s \"%s\" \"%s\"\n", menu_name, -wm0, bi->a[0],
130 bi->a[1], bi->a[2]);
131 }
132 else
133 {
134 fprintf(fp, "macro %s %*s \"%s\"\n", menu_name, -wm0, bi->a[0], bi->a[1]);
135 }
136 }
137
138 const int count = ARRAY_SIZE(&bia_macro);
139 ARRAY_FOREACH(bi, &bia_macro)
140 {
141 // free the keybinding and the macro text
142 FREE(&bi->a[0]);
143 FREE(&bi->a[1]);
144 }
145
146 ARRAY_FREE(&bia_macro);
147 return count;
148}
#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 155 of file dump.c.

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