NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.c File Reference

Key helper functions. More...

#include "config.h"
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "mutt/lib.h"
#include "gui/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
+ Include dependency graph for lib.c:

Go to the source code of this file.

Functions

void mutt_keymap_free (struct Keymap **ptr)
 Free a Keymap.
 
struct Keymapalloc_keys (size_t len, keycode_t *keys)
 Allocate space for a sequence of keys.
 
int parse_fkey (char *s)
 Parse a function key string.
 
static int parse_keycode (const char *s)
 Parse a numeric keycode.
 
size_t parsekeys (const char *str, keycode_t *d, size_t max)
 Parse a key string into key codes.
 
struct Keymapkm_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos)
 Compare two keymaps' keyscodes and return the bigger one.
 
int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len)
 Get the function by its name.
 
const char * mutt_get_func (const struct MenuFuncOp *funcs, int op)
 Get the name of a function.
 
void escape_macro (const char *macro, struct Buffer *buf)
 Escape any special characters in a macro.
 
bool is_bound (const struct KeymapList *km_list, int op)
 Does a function have a keybinding?
 
int binding_sort (const void *a, const void *b, void *sdata)
 Compare two BindingInfo by their keybinding - Implements sort_t -.
 
int measure_column (struct BindingInfoArray *bia, int col)
 Measure one column of a table.
 
int gather_unbound (const struct MenuFuncOp *funcs, const struct KeymapList *km_menu, const struct KeymapList *km_aux, struct BindingInfoArray *bia_unbound)
 Gather info about unbound functions for one menu.
 
void km_keyname (int c, struct Buffer *buf)
 Get the human name for a key.
 
bool km_expand_key (struct Keymap *map, struct Buffer *buf)
 Get the key string bound to a Keymap.
 
void km_expand_key_string (char *str, struct Buffer *buf)
 Get a human-readable key string.
 
struct Keymapkm_find_func (enum MenuType mtype, int func)
 Find a function's mapping in a Menu.
 
const struct MenuFuncOpkm_get_table (enum MenuType mtype)
 Lookup a Menu's functions.
 
const char * help_lookup_function (int op, enum MenuType menu)
 Find a keybinding for an operation.
 
void gather_menu (enum MenuType menu, struct BindingInfoArray *bia_bind, struct BindingInfoArray *bia_macro)
 Gather info about one menu.
 

Variables

const struct MenuFuncOp OpAlias []
 Functions for the Alias Menu.
 
const struct MenuFuncOp OpAttachment []
 Functions for the Attachment Menu.
 
const struct MenuFuncOp OpAutocrypt []
 Functions for the Autocrypt Account.
 
const struct MenuFuncOp OpBrowser []
 Functions for the file Browser Menu.
 
const struct MenuFuncOp OpCompose []
 Functions for the Compose Menu.
 
const struct MenuFuncOp OpEditor []
 Functions for the Editor Menu.
 
const struct MenuFuncOp OpIndex []
 Functions for the Index Menu.
 
const struct MenuFuncOp OpPager []
 Functions for the Pager Menu.
 
const struct MenuFuncOp OpPgp []
 Functions for the Pgp Menu.
 
const struct MenuFuncOp OpPostponed []
 Functions for the Postpone Menu.
 
const struct MenuFuncOp OpQuery []
 Functions for the external Query Menu.
 
const struct MenuFuncOp OpSmime []
 Functions for the Smime Menu.
 
struct Mapping KeyNames []
 Key name lookup table.
 
keycode_t AbortKey
 code of key to abort prompts, normally Ctrl-G
 
struct KeymapList Keymaps [MENU_MAX]
 Array of key mappings, one for each MenuType.
 

Detailed Description

Key helper functions.

Authors
  • Richard Russon

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

Function Documentation

◆ mutt_keymap_free()

void mutt_keymap_free ( struct Keymap **  ptr)

Free a Keymap.

Parameters
ptrKeymap to free

Definition at line 130 of file lib.c.

131{
132 if (!ptr || !*ptr)
133 return;
134
135 struct Keymap *km = *ptr;
136 FREE(&km->macro);
137 FREE(&km->desc);
138 FREE(&km->keys);
139
140 FREE(ptr);
141}
#define FREE(x)
Definition: memory.h:55
A keyboard mapping.
Definition: lib.h:66
keycode_t * keys
key sequence
Definition: lib.h:72
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 caller graph for this function:

◆ alloc_keys()

struct Keymap * alloc_keys ( size_t  len,
keycode_t keys 
)

Allocate space for a sequence of keys.

Parameters
lenNumber of keys
keysArray of keys
Return values
ptrSequence of keys

Definition at line 149 of file lib.c.

150{
151 struct Keymap *p = MUTT_MEM_CALLOC(1, struct Keymap);
152 p->len = len;
154 memcpy(p->keys, keys, len * sizeof(keycode_t));
155 return p;
156}
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:56
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition: lib.h:71
+ Here is the caller graph for this function:

◆ parse_fkey()

int parse_fkey ( char *  s)

Parse a function key string.

Parameters
sString to parse
Return values
numNumber of the key

Given "<f8>", it will return 8.

Definition at line 165 of file lib.c.

166{
167 char *t = NULL;
168 int n = 0;
169
170 if ((s[0] != '<') || (tolower(s[1]) != 'f'))
171 return -1;
172
173 for (t = s + 2; *t && isdigit((unsigned char) *t); t++)
174 {
175 n *= 10;
176 n += *t - '0';
177 }
178
179 if (*t != '>')
180 return -1;
181 return n;
182}
+ Here is the caller graph for this function:

◆ parse_keycode()

static int parse_keycode ( const char *  s)
static

Parse a numeric keycode.

Parameters
sString to parse
Return values
numNumber of the key

This function parses the string <NNN> and uses the octal value as the key to bind.

Definition at line 192 of file lib.c.

193{
194 char *end_char = NULL;
195 long int result = strtol(s + 1, &end_char, 8);
196 /* allow trailing whitespace, eg. < 1001 > */
197 while (isspace(*end_char))
198 end_char++;
199 /* negative keycodes don't make sense, also detect overflow */
200 if ((*end_char != '>') || (result < 0) || (result == LONG_MAX))
201 {
202 return -1;
203 }
204
205 return result;
206}
+ Here is the caller graph for this function:

◆ parsekeys()

size_t parsekeys ( const char *  str,
keycode_t d,
size_t  max 
)

Parse a key string into key codes.

Parameters
strKey string
dArray for key codes
maxMaximum length of key sequence
Return values
numLength of key sequence

Definition at line 215 of file lib.c.

216{
217 int n;
218 size_t len = max;
219 char buf[128] = { 0 };
220 char c;
221 char *t = NULL;
222
223 mutt_str_copy(buf, str, sizeof(buf));
224 char *s = buf;
225
226 while (*s && len)
227 {
228 *d = '\0';
229 if ((*s == '<') && (t = strchr(s, '>')))
230 {
231 t++;
232 c = *t;
233 *t = '\0';
234
236 if (n != -1)
237 {
238 s = t;
239 *d = n;
240 }
241 else if ((n = parse_fkey(s)) > 0)
242 {
243 s = t;
244 *d = KEY_F(n);
245 }
246 else if ((n = parse_keycode(s)) > 0)
247 {
248 s = t;
249 *d = n;
250 }
251
252 *t = c;
253 }
254
255 if (!*d)
256 {
257 *d = (unsigned char) *s;
258 s++;
259 }
260 d++;
261 len--;
262 }
263
264 return max - len;
265}
int parse_fkey(char *s)
Parse a function key string.
Definition: lib.c:165
static int parse_keycode(const char *s)
Parse a numeric keycode.
Definition: lib.c:192
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:59
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:582
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_compare_keys()

struct Keymap * km_compare_keys ( struct Keymap k1,
struct Keymap k2,
size_t *  pos 
)

Compare two keymaps' keyscodes and return the bigger one.

Parameters
k1first keymap to compare
k2second keymap to compare
posposition where the two keycodes differ
Return values
ptrKeymap with a bigger ASCII keycode

Definition at line 274 of file lib.c.

275{
276 *pos = 0;
277
278 while (*pos < k1->len && *pos < k2->len)
279 {
280 if (k1->keys[*pos] < k2->keys[*pos])
281 return k2;
282 else if (k1->keys[*pos] > k2->keys[*pos])
283 return k1;
284 else
285 *pos = *pos + 1;
286 }
287
288 return NULL;
289}
+ Here is the caller graph for this function:

◆ get_op()

int get_op ( const struct MenuFuncOp funcs,
const char *  start,
size_t  len 
)

Get the function by its name.

Parameters
funcsFunctions table
startName of function to find
lenLength of string to match
Return values
numOperation, e.g. OP_DELETE

Definition at line 298 of file lib.c.

299{
300 for (int i = 0; funcs[i].name; i++)
301 {
302 if (mutt_istrn_equal(start, funcs[i].name, len) && (mutt_str_len(funcs[i].name) == len))
303 {
304 return funcs[i].op;
305 }
306 }
307
308 return OP_NULL;
309}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:497
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:454
const char * name
Name of the function.
Definition: lib.h:113
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_get_func()

const char * mutt_get_func ( const struct MenuFuncOp funcs,
int  op 
)

Get the name of a function.

Parameters
funcsFunctions table
opOperation, e.g. OP_DELETE
Return values
ptrName of function
NULLOperation not found
Note
This returns a static string.

Definition at line 320 of file lib.c.

321{
322 for (int i = 0; funcs[i].name; i++)
323 {
324 if (funcs[i].op == op)
325 return funcs[i].name;
326 }
327
328 return NULL;
329}
+ Here is the caller graph for this function:

◆ escape_macro()

void escape_macro ( const char *  macro,
struct Buffer buf 
)

Escape any special characters in a macro.

Parameters
[in]macroMacro string
[out]bufBuffer for the result

Replace characters, such as <Enter> with the literal "\n"

Definition at line 338 of file lib.c.

339{
340 wchar_t wc = 0;
341 size_t k;
342 size_t len = mutt_str_len(macro);
343 mbstate_t mbstate1 = { 0 };
344 mbstate_t mbstate2 = { 0 };
345
346 for (; (len > 0) && (k = mbrtowc(&wc, macro, MB_LEN_MAX, &mbstate1)); macro += k, len -= k)
347 {
348 if ((k == ICONV_ILLEGAL_SEQ) || (k == ICONV_BUF_TOO_SMALL))
349 {
350 if (k == ICONV_ILLEGAL_SEQ)
351 memset(&mbstate1, 0, sizeof(mbstate1));
352 k = (k == ICONV_ILLEGAL_SEQ) ? 1 : len;
353 wc = ReplacementChar;
354 }
355
356 const int w = wcwidth(wc);
357 if (IsWPrint(wc) && (w >= 0))
358 {
359 char tmp[MB_LEN_MAX * 2] = { 0 };
360 if (wcrtomb(tmp, wc, &mbstate2) != ICONV_ILLEGAL_SEQ)
361 {
362 buf_addstr(buf, tmp);
363 }
364 }
365 else if ((wc < 0x20) || (wc == 0x7f))
366 {
367 if (wc == '\033') // Escape
368 buf_addstr(buf, "\\e");
369 else if (wc == '\n')
370 buf_addstr(buf, "\\n");
371 else if (wc == '\r')
372 buf_addstr(buf, "\\r");
373 else if (wc == '\t')
374 buf_addstr(buf, "\\t");
375 else
376 buf_add_printf(buf, "^%c", (char) ((wc + '@') & 0x7f));
377 }
378 else
379 {
380 buf_addch(buf, '?');
381 }
382 }
383}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
#define IsWPrint(wc)
Definition: mbyte.h:41
wchar_t ReplacementChar
When a Unicode character can't be displayed, use this instead.
Definition: charset.c:61
#define ICONV_BUF_TOO_SMALL
Error value for iconv() - Buffer too small.
Definition: charset.h:98
#define ICONV_ILLEGAL_SEQ
Error value for iconv() - Illegal sequence.
Definition: charset.h:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_bound()

bool is_bound ( const struct KeymapList *  km_list,
int  op 
)

Does a function have a keybinding?

Parameters
km_listKeymap to examine
opOperation, e.g. OP_DELETE
Return values
trueA key is bound to that operation

Definition at line 391 of file lib.c.

392{
393 struct Keymap *map = NULL;
394 STAILQ_FOREACH(map, km_list, entries)
395 {
396 if (map->op == op)
397 return true;
398 }
399 return false;
400}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:390
short op
Operation to perform.
Definition: lib.h:69
+ Here is the caller graph for this function:

◆ measure_column()

int measure_column ( struct BindingInfoArray *  bia,
int  col 
)

Measure one column of a table.

Parameters
biaArray of binding info
colColumn to measure
Return values
numWidth of widest column

Definition at line 419 of file lib.c.

420{
421 int max_width = 0;
422
423 struct BindingInfo *bi = NULL;
424 ARRAY_FOREACH(bi, bia)
425 {
426 const int col_width = mutt_strwidth(bi->a[col]);
427 max_width = MAX(max_width, col_width);
428 }
429
430 return max_width;
431}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:214
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:445
#define MAX(a, b)
Definition: memory.h:31
Info about one keybinding.
Definition: lib.h:94
const char * a[3]
Array of info.
Definition: lib.h:95
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gather_unbound()

int gather_unbound ( const struct MenuFuncOp funcs,
const struct KeymapList *  km_menu,
const struct KeymapList *  km_aux,
struct BindingInfoArray *  bia_unbound 
)

Gather info about unbound functions for one menu.

Parameters
funcsList of functions
km_menuKeymaps for the menu
km_auxKeymaps for generic
bia_unboundUnbound functions
Return values
numNumber of unbound functions

Definition at line 441 of file lib.c.

443{
444 for (int i = 0; funcs[i].name; i++)
445 {
446 if (!is_bound(km_menu, funcs[i].op) &&
447 (!km_aux || !is_bound(km_aux, funcs[i].op)))
448 {
449 struct BindingInfo bi = { 0 };
450 bi.a[0] = NULL;
451 bi.a[1] = funcs[i].name;
452 bi.a[2] = _(opcodes_get_description(funcs[i].op));
453 ARRAY_ADD(bia_unbound, bi);
454 }
455 }
456
457 return ARRAY_SIZE(bia_unbound);
458}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
bool is_bound(const struct KeymapList *km_list, int op)
Does a function have a keybinding?
Definition: lib.c:391
#define _(a)
Definition: message.h:28
const char * opcodes_get_description(int op)
Get the description of an opcode.
Definition: opcodes.c:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_keyname()

void km_keyname ( int  c,
struct Buffer buf 
)

Get the human name for a key.

Parameters
[in]cKey code
[out]bufBuffer for the result

Definition at line 465 of file lib.c.

466{
467 const char *name = mutt_map_get_name(c, KeyNames);
468 if (name)
469 {
470 buf_addstr(buf, name);
471 return;
472 }
473
474 if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
475 {
476 if (c < 0)
477 c += 256;
478
479 if (c < 128)
480 {
481 buf_addch(buf, '^');
482 buf_addch(buf, (c + '@') & 0x7f);
483 }
484 else
485 {
486 buf_add_printf(buf, "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
487 }
488 }
489 else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
490 {
491 buf_add_printf(buf, "<F%d>", c - KEY_F0);
492 }
493 else if ((c < 256) && (c >= -128) && IsPrint(c))
494 {
495 buf_add_printf(buf, "%c", (unsigned char) c);
496 }
497 else
498 {
499 buf_add_printf(buf, "<%ho>", (unsigned short) c);
500 }
501}
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
#define IsPrint(ch)
Definition: mbyte.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_expand_key()

bool km_expand_key ( struct Keymap map,
struct Buffer buf 
)

Get the key string bound to a Keymap.

Parameters
[in]mapKeybinding map
[out]bufBuffer for the result
Return values
trueSuccess

Definition at line 509 of file lib.c.

510{
511 if (!map || !buf)
512 return false;
513
514 for (int i = 0; i < map->len; i++)
515 {
516 km_keyname(map->keys[i], buf);
517 }
518
519 return true;
520}
void km_keyname(int c, struct Buffer *buf)
Get the human name for a key.
Definition: lib.c:465
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_expand_key_string()

void km_expand_key_string ( char *  str,
struct Buffer buf 
)

Get a human-readable key string.

Parameters
[in]strRaw key string
[out]bufBuffer for the key string

Definition at line 527 of file lib.c.

528{
529 for (; *str; str++)
530 {
531 km_keyname(*str, buf);
532 }
533}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_find_func()

struct Keymap * km_find_func ( enum MenuType  mtype,
int  func 
)

Find a function's mapping in a Menu.

Parameters
mtypeMenu type, e.g. MENU_PAGER
funcFunction, e.g. OP_DELETE
Return values
ptrKeymap for the function

Definition at line 541 of file lib.c.

542{
543 struct Keymap *np = NULL;
544 STAILQ_FOREACH(np, &Keymaps[mtype], entries)
545 {
546 if (np->op == func)
547 break;
548 }
549 return np;
550}
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:124
+ Here is the caller graph for this function:

◆ km_get_table()

const struct MenuFuncOp * km_get_table ( enum MenuType  mtype)

Lookup a Menu's functions.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
Return values
ptrArray of functions

Definition at line 557 of file lib.c.

558{
559 switch (mtype)
560 {
561 case MENU_ALIAS:
562 return OpAlias;
563 case MENU_ATTACHMENT:
564 return OpAttachment;
565#ifdef USE_AUTOCRYPT
566 case MENU_AUTOCRYPT:
567 return OpAutocrypt;
568#endif
569 case MENU_COMPOSE:
570 return OpCompose;
571 case MENU_DIALOG:
572 return OpDialog;
573 case MENU_EDITOR:
574 return OpEditor;
575 case MENU_FOLDER:
576 return OpBrowser;
577 case MENU_GENERIC:
578 return OpGeneric;
579 case MENU_INDEX:
580 return OpIndex;
581 case MENU_PAGER:
582 return OpPager;
583 case MENU_PGP:
584 return OpPgp;
585 case MENU_POSTPONED:
586 return OpPostponed;
587 case MENU_QUERY:
588 return OpQuery;
589 case MENU_SMIME:
590 return OpSmime;
591 default:
592 return NULL;
593 }
594}
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:69
const struct MenuFuncOp OpDialog[]
Functions for Simple Dialogs.
Definition: functions.c:60
const struct MenuFuncOp OpQuery[]
Functions for the external Query Menu.
Definition: functions.c:76
const struct MenuFuncOp OpPostponed[]
Functions for the Postpone Menu.
Definition: functions.c:52
const struct MenuFuncOp OpIndex[]
Functions for the Index Menu.
Definition: functions.c:90
const struct MenuFuncOp OpCompose[]
Functions for the Compose Menu.
Definition: functions.c:87
const struct MenuFuncOp OpSmime[]
Functions for the Smime Menu.
Definition: functions.c:52
const struct MenuFuncOp OpBrowser[]
Functions for the file Browser Menu.
Definition: functions.c:72
const struct MenuFuncOp OpAutocrypt[]
Functions for the Autocrypt Account.
Definition: functions.c:54
const struct MenuFuncOp OpPager[]
Functions for the Pager Menu.
Definition: functions.c:71
const struct MenuFuncOp OpEditor[]
Functions for the Editor Menu.
Definition: functions.c:53
const struct MenuFuncOp OpAttachment[]
Functions for the Attachment Menu.
Definition: functions.c:62
const struct MenuFuncOp OpPgp[]
Functions for the Pgp Menu.
Definition: functions.c:42
const struct MenuFuncOp OpAlias[]
Functions for the Alias Menu.
Definition: functions.c:60
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:47
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_QUERY
Select from results of external query.
Definition: type.h:51
@ MENU_AUTOCRYPT
Autocrypt Account menu.
Definition: type.h:40
@ MENU_COMPOSE
Compose an email.
Definition: type.h:42
@ MENU_ATTACHMENT
Select an attachment.
Definition: type.h:38
@ MENU_PGP
PGP encryption menu.
Definition: type.h:49
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:48
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:52
@ MENU_EDITOR
Text entry area.
Definition: type.h:44
@ MENU_ALIAS
Select an email address by its alias.
Definition: type.h:37
@ MENU_FOLDER
General file/mailbox browser.
Definition: type.h:45
@ MENU_POSTPONED
Select a postponed email.
Definition: type.h:50
+ Here is the caller graph for this function:

◆ help_lookup_function()

const char * help_lookup_function ( int  op,
enum MenuType  menu 
)

Find a keybinding for an operation.

Parameters
opOperation, e.g. OP_DELETE
menuCurrent Menu, e.g. MENU_PAGER
Return values
strKey binding
NULLNo key binding found

Definition at line 603 of file lib.c.

604{
605 if ((menu != MENU_PAGER) && (menu != MENU_EDITOR) && (menu != MENU_GENERIC))
606 {
607 /* first look in the generic map for the function */
608 const char *fn_name = mutt_get_func(OpGeneric, op);
609 if (fn_name)
610 return fn_name;
611 }
612
613 const struct MenuFuncOp *funcs = km_get_table(menu);
614
615 return mutt_get_func(funcs, op);
616}
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:557
Mapping between a function and an operation.
Definition: lib.h:112
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gather_menu()

void gather_menu ( enum MenuType  menu,
struct BindingInfoArray *  bia_bind,
struct BindingInfoArray *  bia_macro 
)

Gather info about one menu.

Parameters
menuMenu type
bia_bindArray for bind results (may be NULL)
bia_macroArray for macro results (may be NULL)

Definition at line 624 of file lib.c.

626{
627 struct Buffer *key_binding = buf_pool_get();
628 struct Buffer *macro = buf_pool_get();
629
630 struct Keymap *map = NULL;
631 STAILQ_FOREACH(map, &Keymaps[menu], entries)
632 {
633 struct BindingInfo bi = { 0 };
634
635 buf_reset(key_binding);
636 km_expand_key(map, key_binding);
637
638 if (map->op == OP_MACRO)
639 {
640 if (!bia_macro || (map->op == OP_NULL))
641 continue;
642
643 buf_reset(macro);
644 escape_macro(map->macro, macro);
645 bi.a[0] = buf_strdup(key_binding);
646 bi.a[1] = buf_strdup(macro);
647 bi.a[2] = map->desc;
648 ARRAY_ADD(bia_macro, bi);
649 }
650 else
651 {
652 if (!bia_bind)
653 continue;
654
655 if (map->op == OP_NULL)
656 {
657 bi.a[0] = buf_strdup(key_binding);
658 bi.a[1] = "noop";
659 ARRAY_ADD(bia_bind, bi);
660 continue;
661 }
662
663 bi.a[0] = buf_strdup(key_binding);
664 bi.a[1] = help_lookup_function(map->op, menu);
665 bi.a[2] = _(opcodes_get_description(map->op));
666 ARRAY_ADD(bia_bind, bi);
667 }
668 }
669
670 buf_pool_release(&key_binding);
671 buf_pool_release(&macro);
672}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
const char * help_lookup_function(int op, enum MenuType menu)
Find a keybinding for an operation.
Definition: lib.c:603
void escape_macro(const char *macro, struct Buffer *buf)
Escape any special characters in a macro.
Definition: lib.c:338
bool km_expand_key(struct Keymap *map, struct Buffer *buf)
Get the key string bound to a Keymap.
Definition: lib.c:509
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ OpAlias

const struct MenuFuncOp OpAlias[]
extern

Functions for the Alias Menu.

Definition at line 60 of file functions.c.

◆ OpAttachment

const struct MenuFuncOp OpAttachment[]
extern

Functions for the Attachment Menu.

Definition at line 62 of file functions.c.

◆ OpAutocrypt

const struct MenuFuncOp OpAutocrypt[]
extern

Functions for the Autocrypt Account.

Definition at line 54 of file functions.c.

◆ OpBrowser

const struct MenuFuncOp OpBrowser[]
extern

Functions for the file Browser Menu.

Definition at line 72 of file functions.c.

◆ OpCompose

const struct MenuFuncOp OpCompose[]
extern

Functions for the Compose Menu.

Definition at line 87 of file functions.c.

◆ OpEditor

const struct MenuFuncOp OpEditor[]
extern

Functions for the Editor Menu.

Definition at line 53 of file functions.c.

◆ OpIndex

const struct MenuFuncOp OpIndex[]
extern

Functions for the Index Menu.

Definition at line 90 of file functions.c.

◆ OpPager

const struct MenuFuncOp OpPager[]
extern

Functions for the Pager Menu.

Definition at line 71 of file functions.c.

◆ OpPgp

const struct MenuFuncOp OpPgp[]
extern

Functions for the Pgp Menu.

Definition at line 42 of file functions.c.

◆ OpPostponed

const struct MenuFuncOp OpPostponed[]
extern

Functions for the Postpone Menu.

Definition at line 52 of file functions.c.

◆ OpQuery

const struct MenuFuncOp OpQuery[]
extern

Functions for the external Query Menu.

Definition at line 76 of file functions.c.

◆ OpSmime

const struct MenuFuncOp OpSmime[]
extern

Functions for the Smime Menu.

Definition at line 52 of file functions.c.

◆ KeyNames

struct Mapping KeyNames[]

Key name lookup table.

Definition at line 59 of file lib.c.

◆ AbortKey

keycode_t AbortKey

code of key to abort prompts, normally Ctrl-G

key to abort edits etc, normally Ctrl-G

Definition at line 121 of file lib.c.

◆ Keymaps

struct KeymapList Keymaps[MENU_MAX]

Array of key mappings, one for each MenuType.

Array of Keymap keybindings, one for each Menu.

Definition at line 124 of file lib.c.