NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Manage keymappings. More...

#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "menu/lib.h"
+ Include dependency graph for lib.h:

Go to the source code of this file.

Data Structures

struct  Keymap
 A keyboard mapping. More...
 
struct  KeyEvent
 An event such as a keypress. More...
 
struct  MenuFuncOp
 Mapping between a function and an operation. More...
 
struct  MenuOpSeq
 Mapping between an operation and a key sequence. More...
 
struct  EventBinding
 A key binding Event. More...
 

Macros

#define MUTT_UNBIND   (1 << 0)
 Parse 'unbind' command.
 
#define MUTT_UNMACRO   (1 << 1)
 Parse 'unmacro' command.
 
#define GETCH_NO_FLAGS   0
 No flags are set.
 
#define GETCH_IGNORE_MACRO   (1 << 0)
 Don't use MacroEvents.
 

Typedefs

typedef uint8_t GetChFlags
 Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.
 
typedef short keycode_t
 Type for key storage, the rest of neomutt works fine with int type.
 

Enumerations

enum  NotifyBinding {
  NT_BINDING_ADD = 1 , NT_BINDING_DELETE , NT_BINDING_DELETE_ALL , NT_MACRO_ADD ,
  NT_MACRO_DELETE , NT_MACRO_DELETE_ALL
}
 Key Binding notification types. More...
 

Functions

 STAILQ_HEAD (KeymapList, Keymap)
 
 ARRAY_HEAD (KeyEventArray, struct KeyEvent)
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_unmacro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 
enum CommandResult km_bind (char *s, enum MenuType menu, int op, char *macro, char *desc)
 Bind a key to a macro.
 
int km_dokey (enum MenuType menu, GetChFlags flags)
 Determine what a keypress should do.
 
struct KeyEvent km_dokey_event (enum MenuType menu, GetChFlags flags)
 Determine what a keypress should do.
 
void km_error_key (enum MenuType menu)
 Handle an unbound key sequence.
 
int km_expand_key (char *s, size_t len, struct Keymap *map)
 Get the key string bound to a Keymap.
 
int km_expand_key_string (char *str, char *buf, size_t buflen)
 Get a human-readable key string.
 
struct Keymapkm_find_func (enum MenuType menu, int func)
 Find a function's mapping in a Menu.
 
const struct MenuFuncOpkm_get_table (enum MenuType mtype)
 Lookup a Menu's functions.
 
void km_init (void)
 Initialise all the menu keybindings.
 
const char * km_keyname (int c)
 Get the human name for a key.
 
void init_extended_keys (void)
 Initialise map of ncurses extended keys.
 
int main_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
void mutt_flush_macro_to_endcond (void)
 Drop a macro from the input buffer.
 
void mutt_init_abort_key (void)
 Parse the abort_key config string.
 
void mutt_keys_cleanup (void)
 Free the key maps.
 
void mw_what_key (void)
 Display the value of a key -.
 
struct Keymapalloc_keys (size_t len, keycode_t *keys)
 Allocate space for a sequence of keys.
 
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() -.
 
void generic_tokenize_push_string (char *s)
 Parse and queue a 'push' command.
 
int get_op (const struct MenuFuncOp *funcs, const char *start, size_t len)
 Get the function by its name.
 
enum CommandResult km_bindkey (const char *s, enum MenuType mtype, int op)
 Bind a key in a Menu to an operation.
 
struct Keymapkm_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos)
 Compare two keymaps' keyscodes and return the bigger one.
 
const char * mutt_get_func (const struct MenuFuncOp *bindings, int op)
 Get the name of a function.
 
void mutt_keymap_free (struct Keymap **ptr)
 Free a Keymap.
 
size_t parsekeys (const char *str, keycode_t *d, size_t max)
 Parse a key string into key codes.
 

Variables

struct KeyEventArray MacroEvents
 These are used for macros and exec/push commands.
 
struct KeymapList Keymaps []
 Array of Keymap keybindings, one for each Menu.
 
struct Mapping KeyNames []
 Key name lookup table.
 
keycode_t AbortKey
 key to abort edits etc, normally Ctrl-G
 
const struct Mapping Menus []
 

Detailed Description

Manage keymappings.

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.h.

Macro Definition Documentation

◆ MUTT_UNBIND

#define MUTT_UNBIND   (1 << 0)

Parse 'unbind' command.

Definition at line 47 of file lib.h.

◆ MUTT_UNMACRO

#define MUTT_UNMACRO   (1 << 1)

Parse 'unmacro' command.

Definition at line 48 of file lib.h.

◆ GETCH_NO_FLAGS

#define GETCH_NO_FLAGS   0

No flags are set.

Definition at line 51 of file lib.h.

◆ GETCH_IGNORE_MACRO

#define GETCH_IGNORE_MACRO   (1 << 0)

Don't use MacroEvents.

Definition at line 52 of file lib.h.

Typedef Documentation

◆ GetChFlags

typedef uint8_t GetChFlags

Flags for mutt_getch(), e.g. GETCH_NO_FLAGS.

Definition at line 50 of file lib.h.

◆ keycode_t

typedef short keycode_t

Type for key storage, the rest of neomutt works fine with int type.

Definition at line 55 of file lib.h.

Enumeration Type Documentation

◆ NotifyBinding

Key Binding notification types.

Observers of NT_BINDING will be passed an EventBinding.

Note
Notifications are sent after the event.
Enumerator
NT_BINDING_ADD 

Key binding has been added.

NT_BINDING_DELETE 

Key binding has been deleted.

NT_BINDING_DELETE_ALL 

All key bindings have been deleted.

NT_MACRO_ADD 

Key macro has been added.

NT_MACRO_DELETE 

Key macro has been deleted.

NT_MACRO_DELETE_ALL 

All key macros have been deleted.

Definition at line 132 of file lib.h.

133{
134 NT_BINDING_ADD = 1,
137
141};
@ NT_MACRO_ADD
Key macro has been added.
Definition: lib.h:138
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: lib.h:139
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: lib.h:140
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: lib.h:135
@ NT_BINDING_ADD
Key binding has been added.
Definition: lib.h:134
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: lib.h:136

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( KeymapList  ,
Keymap   
)

◆ ARRAY_HEAD()

ARRAY_HEAD ( KeyEventArray  ,
struct KeyEvent   
)

◆ mutt_parse_unmacro()

enum CommandResult mutt_parse_unmacro ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

◆ km_bind()

enum CommandResult km_bind ( char *  s,
enum MenuType  mtype,
int  op,
char *  macro,
char *  desc 
)

Bind a key to a macro.

Parameters
sKey string
mtypeMenu type, e.g. MENU_EDITOR
opOperation, e.g. OP_DELETE
macroMacro string
descDescription of macro (OPTIONAL)
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 160 of file parse.c.

161{
162 return km_bind_err(s, mtype, op, macro, desc, NULL);
163}
static enum CommandResult km_bind_err(const char *s, enum MenuType mtype, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition: parse.c:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey()

int km_dokey ( enum MenuType  mtype,
GetChFlags  flags 
)

Determine what a keypress should do.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
flagsFlags, e.g. GETCH_IGNORE_MACRO
Return values
>0Function to execute
OP_NULLNo function bound to key sequence
-1Error occurred while reading input
-2A timeout or sigwinch occurred

Definition at line 463 of file get.c.

464{
465 return km_dokey_event(mtype, flags).op;
466}
struct KeyEvent km_dokey_event(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:345
int op
Function opcode, e.g. OP_HELP.
Definition: lib.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey_event()

struct KeyEvent km_dokey_event ( enum MenuType  mtype,
GetChFlags  flags 
)

Determine what a keypress should do.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
flagsFlags, e.g. GETCH_IGNORE_MACRO
Return values
ptrEvent

Definition at line 345 of file get.c.

346{
347 struct KeyEvent event = { 0, OP_NULL };
348 struct Keymap *map = STAILQ_FIRST(&Keymaps[mtype]);
349 int pos = 0;
350 int n = 0;
351
352 if (!map && (mtype != MENU_EDITOR))
353 return retry_generic(mtype, NULL, 0, 0, flags);
354
355 while (true)
356 {
357 event = mutt_getch(flags);
358
359 // abort, timeout, repaint
360 if (event.op < OP_NULL)
361 return event;
362
363 /* do we have an op already? */
364 if (event.op != OP_NULL)
365 {
366 const char *func = NULL;
367 const struct MenuFuncOp *funcs = NULL;
368
369 /* is this a valid op for this menu type? */
370 if ((funcs = km_get_table(mtype)) && (func = mutt_get_func(funcs, event.op)))
371 return event;
372
373 if ((mtype != MENU_EDITOR) && (mtype != MENU_PAGER) && (mtype != MENU_GENERIC))
374 {
375 /* check generic menu type */
376 funcs = OpGeneric;
377 func = mutt_get_func(funcs, event.op);
378 if (func)
379 return event;
380 }
381
382 /* Sigh. Valid function but not in this context.
383 * Find the literal string and push it back */
384 for (int i = 0; MenuNames[i].name; i++)
385 {
386 funcs = km_get_table(MenuNames[i].value);
387 if (funcs)
388 {
389 func = mutt_get_func(funcs, event.op);
390 if (func)
391 {
392 mutt_unget_ch('>');
393 mutt_unget_string(func);
394 mutt_unget_ch('<');
395 break;
396 }
397 }
398 }
399 /* continue to chew */
400 if (func)
401 continue;
402 }
403
404 if (!map)
405 return event;
406
407 /* Nope. Business as usual */
408 while (event.ch > map->keys[pos])
409 {
410 if ((pos > map->eq) || !STAILQ_NEXT(map, entries))
411 return retry_generic(mtype, map->keys, pos, event.ch, flags);
412 map = STAILQ_NEXT(map, entries);
413 }
414
415 if (event.ch != map->keys[pos])
416 return retry_generic(mtype, map->keys, pos, event.ch, flags);
417
418 if (++pos == map->len)
419 {
420 if (map->op != OP_MACRO)
421 return (struct KeyEvent){ event.ch, map->op };
422
423 /* #GETCH_IGNORE_MACRO turns off processing the MacroEvents buffer
424 * in mutt_getch(). Generating new macro events during that time would
425 * result in undesired behavior once the option is turned off.
426 *
427 * Originally this returned -1, however that results in an unbuffered
428 * username or password prompt being aborted. Returning OP_NULL allows
429 * mw_get_field() to display the keybinding pressed instead.
430 *
431 * It may be unexpected for a macro's keybinding to be returned,
432 * but less so than aborting the prompt. */
433 if (flags & GETCH_IGNORE_MACRO)
434 {
435 return (struct KeyEvent){ event.ch, OP_NULL };
436 }
437
438 if (n++ == 10)
439 {
441 mutt_error(_("Macro loop detected"));
442 return (struct KeyEvent){ '\0', OP_ABORT };
443 }
444
446 map = STAILQ_FIRST(&Keymaps[mtype]);
447 pos = 0;
448 }
449 }
450
451 /* not reached */
452}
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: get.c:57
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: get.c:136
struct KeyEvent mutt_getch(GetChFlags flags)
Read a character from the input buffer.
Definition: get.c:209
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition: get.c:114
static struct KeyEvent retry_generic(enum MenuType mtype, keycode_t *keys, int keyslen, int lastkey, GetChFlags flags)
Try to find the key in the generic menu bindings.
Definition: get.c:318
#define mutt_error(...)
Definition: logging2.h:92
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:68
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition: lib.c:341
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:128
const char * mutt_get_func(const struct MenuFuncOp *funcs, int op)
Get the name of a function.
Definition: lib.c:324
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:528
#define GETCH_IGNORE_MACRO
Don't use MacroEvents.
Definition: lib.h:52
#define _(a)
Definition: message.h:28
#define OP_ABORT
$abort_key pressed (Ctrl-G)
Definition: opcodes.h:37
#define STAILQ_FIRST(head)
Definition: queue.h:350
#define STAILQ_NEXT(elm, field)
Definition: queue.h:400
An event such as a keypress.
Definition: lib.h:81
int ch
Raw key pressed.
Definition: lib.h:82
A keyboard mapping.
Definition: lib.h:65
keycode_t * keys
key sequence
Definition: lib.h:71
char * macro
Macro expansion (op == OP_MACRO)
Definition: lib.h:66
short eq
Number of leading keys equal to next entry.
Definition: lib.h:69
short len
Length of key sequence (unit: sizeof (keycode_t))
Definition: lib.h:70
short op
Operation to perform.
Definition: lib.h:68
const char * name
String value.
Definition: mapping.h:34
Mapping between a function and an operation.
Definition: lib.h:101
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:55
@ 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:

◆ km_error_key()

void km_error_key ( enum MenuType  mtype)

Handle an unbound key sequence.

Parameters
mtypeMenu type, e.g. MENU_PAGER

Definition at line 293 of file get.c.

294{
295 struct Keymap *key = km_find_func(mtype, OP_HELP);
296 if (!key && (mtype != MENU_EDITOR) && (mtype != MENU_PAGER))
297 key = km_find_func(MENU_GENERIC, OP_HELP);
298 if (!key)
299 {
300 mutt_error(_("Key is not bound"));
301 return;
302 }
303
304 char buf[128] = { 0 };
305 km_expand_key(buf, sizeof(buf), key);
306 mutt_error(_("Key is not bound. Press '%s' for help."), buf);
307}
struct Keymap * km_find_func(enum MenuType mtype, int func)
Find a function's mapping in a Menu.
Definition: lib.c:512
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: lib.c:460
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_expand_key()

int km_expand_key ( char *  s,
size_t  len,
struct Keymap map 
)

Get the key string bound to a Keymap.

Parameters
sBuffer for the key string
lenLength of buffer
mapKeybinding map
Return values
1Success
0Error

Definition at line 460 of file lib.c.

461{
462 if (!map)
463 return 0;
464
465 int p = 0;
466
467 while (true)
468 {
469 mutt_str_copy(s, km_keyname(map->keys[p]), len);
470 const size_t l = mutt_str_len(s);
471 len -= l;
472
473 if ((++p >= map->len) || !len)
474 return 1;
475
476 s += l;
477 }
478
479 /* not reached */
480}
const char * km_keyname(int c)
Get the human name for a key.
Definition: lib.c:413
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:490
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:575
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_expand_key_string()

int km_expand_key_string ( char *  str,
char *  buf,
size_t  buflen 
)

Get a human-readable key string.

Parameters
strRaw key string
bufBuffer for the key string
buflenLength of buffer
Return values
numLength of string

Definition at line 489 of file lib.c.

490{
491 size_t len = 0;
492 for (; *str; str++)
493 {
494 const char *key = km_keyname(*str);
495 size_t keylen = mutt_str_len(key);
496
497 mutt_str_copy(buf, key, buflen);
498 buf += keylen;
499 buflen -= keylen;
500 len += keylen;
501 }
502
503 return len;
504}
+ 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 512 of file lib.c.

513{
514 struct Keymap *np = NULL;
515 STAILQ_FOREACH(np, &Keymaps[mtype], entries)
516 {
517 if (np->op == func)
518 break;
519 }
520 return np;
521}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
+ 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 528 of file lib.c.

529{
530 switch (mtype)
531 {
532 case MENU_ALIAS:
533 return OpAlias;
534 case MENU_ATTACHMENT:
535 return OpAttachment;
536#ifdef USE_AUTOCRYPT
537 case MENU_AUTOCRYPT:
538 return OpAutocrypt;
539#endif
540 case MENU_COMPOSE:
541 return OpCompose;
542 case MENU_DIALOG:
543 return OpDialog;
544 case MENU_EDITOR:
545 return OpEditor;
546 case MENU_FOLDER:
547 return OpBrowser;
548 case MENU_GENERIC:
549 return OpGeneric;
550 case MENU_INDEX:
551 return OpIndex;
552#ifdef CRYPT_BACKEND_GPGME
554 return OpPgp;
556 return OpSmime;
557#endif
558#ifdef MIXMASTER
559 case MENU_MIXMASTER:
560 return OpMixmaster;
561#endif
562 case MENU_PAGER:
563 return OpPager;
564 case MENU_PGP:
565 return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
566 case MENU_POSTPONED:
567 return OpPostponed;
568 case MENU_QUERY:
569 return OpQuery;
570 default:
571 return NULL;
572 }
573}
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:73
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:94
const struct MenuFuncOp OpCompose[]
Functions for the Compose Menu.
Definition: functions.c:90
const struct MenuFuncOp OpMixmaster[]
Functions for the Mixmaster Menu.
Definition: functions.c:49
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:74
const struct MenuFuncOp OpAutocrypt[]
Functions for the Autocrypt Account.
Definition: functions.c:52
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:64
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:59
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define WithCrypto
Definition: lib.h:116
@ MENU_KEY_SELECT_PGP
Select a PGP key.
Definition: type.h:48
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:51
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_MIXMASTER
Create/edit a Mixmaster chain.
Definition: type.h:53
@ MENU_KEY_SELECT_SMIME
Select a SMIME key.
Definition: type.h:49
@ MENU_QUERY
Select from results of external query.
Definition: type.h:58
@ 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:56
@ 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:57
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 180 of file init.c.

181{
182 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
183
186#ifdef USE_AUTOCRYPT
188#endif
195#ifdef MIXMASTER
197#endif
201
206
207#ifdef CRYPT_BACKEND_GPGME
210#endif
211}
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition: functions.c:138
const struct MenuOpSeq DialogDefaultBindings[]
Key bindings for Simple Dialogs.
Definition: functions.c:130
const struct MenuOpSeq AttachmentDefaultBindings[]
Key bindings for the Attachment Menu.
Definition: functions.c:100
const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition: functions.c:88
const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition: functions.c:103
const struct MenuOpSeq PostponedDefaultBindings[]
Key bindings for the Postpone Menu.
Definition: functions.c:62
const struct MenuOpSeq BrowserDefaultBindings[]
Key bindings for the file Browser Menu.
Definition: functions.c:108
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:88
const struct MenuOpSeq PagerDefaultBindings[]
Key bindings for the Pager Menu.
Definition: functions.c:229
const struct MenuOpSeq IndexDefaultBindings[]
Key bindings for the Index Menu.
Definition: functions.c:239
const struct MenuOpSeq MixmasterDefaultBindings[]
Key bindings for the Mixmaster Menu.
Definition: functions.c:65
const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:66
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: init.c:168
const struct MenuOpSeq PgpDefaultBindings[]
Key bindings for the Pgp Menu.
Definition: functions.c:64
const struct MenuOpSeq ComposeDefaultBindings[]
Key bindings for the Compose Menu.
Definition: functions.c:159
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition: functions.c:74
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:59
@ MENU_MAX
Definition: type.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_keyname()

const char * km_keyname ( int  c)

Get the human name for a key.

Parameters
cKey code
Return values
ptrName of the key
Note
This returns a pointer to a static buffer.

Definition at line 413 of file lib.c.

414{
415 static char buf[35];
416
417 const char *p = mutt_map_get_name(c, KeyNames);
418 if (p)
419 return p;
420
421 if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
422 {
423 if (c < 0)
424 c += 256;
425
426 if (c < 128)
427 {
428 buf[0] = '^';
429 buf[1] = (c + '@') & 0x7f;
430 buf[2] = '\0';
431 }
432 else
433 {
434 snprintf(buf, sizeof(buf), "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
435 }
436 }
437 else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
438 {
439 snprintf(buf, sizeof(buf), "<F%d>", c - KEY_F0);
440 }
441 else if ((c < 256) && (c >= -128) && IsPrint(c))
442 {
443 snprintf(buf, sizeof(buf), "%c", (unsigned char) c);
444 }
445 else
446 {
447 snprintf(buf, sizeof(buf), "<%ho>", (unsigned short) c);
448 }
449 return buf;
450}
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:63
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:

◆ init_extended_keys()

void init_extended_keys ( void  )

Initialise map of ncurses extended keys.

Determine the keycodes for ncurses extended keys and fill in the KeyNames array.

This function must be called after initscr(), or mutt_tigetstr() fails. This creates a bit of a chicken-and-egg problem because km_init() is called prior to start_curses(). This means that the default keybindings can't include any of the extended keys because they won't be defined until later.

Definition at line 137 of file init.c.

138{
139#ifdef HAVE_USE_EXTENDED_NAMES
140 use_extended_names(true);
141
142 for (int j = 0; KeyNames[j].name; j++)
143 {
144 if (KeyNames[j].value == -1)
145 {
146 const char *keyname = find_ext_name(KeyNames[j].name);
147
148 if (keyname)
149 {
150 const char *s = mutt_tigetstr((char *) keyname);
151 if (s && ((long) (s) != -1))
152 {
153 int code = key_defined(s);
154 if (code > 0)
155 KeyNames[j].value = code;
156 }
157 }
158 }
159 }
160#endif
161}
static const char * find_ext_name(const char *key)
Find the curses name for a key.
Definition: init.c:117
int value
Integer value.
Definition: mapping.h:35
const char * mutt_tigetstr(const char *name)
Get terminal capabilities.
Definition: terminal.c:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_flush_macro_to_endcond()

void mutt_flush_macro_to_endcond ( void  )

Drop a macro from the input buffer.

All the macro text is deleted until an OP_END_COND command, or the buffer is empty.

Definition at line 165 of file get.c.

166{
168}
struct KeyEventArray MacroEvents
These are used for macros and exec/push commands.
Definition: get.c:48
static void array_to_endcond(struct KeyEventArray *a)
Clear the array until an OP_END_COND.
Definition: get.c:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_init_abort_key()

void mutt_init_abort_key ( void  )

Parse the abort_key config string.

Parse the string into $abort_key and put the keycode into AbortKey.

Definition at line 243 of file init.c.

244{
245 keycode_t buf[2];
246 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
247 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
248 if (len == 0)
249 {
250 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
251 AbortKey = ctrl('G');
252 return;
253 }
254 if (len > 1)
255 {
256 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
257 c_abort_key);
258 }
259 AbortKey = buf[0];
260}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
#define mutt_warning(...)
Definition: logging2.h:90
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: lib.c:125
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:219
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:55
#define mutt_array_size(x)
Definition: memory.h:38
#define ctrl(ch)
Definition: mutt_curses.h:52
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_keys_cleanup()

void mutt_keys_cleanup ( void  )

Free the key maps.

Definition at line 230 of file init.c.

231{
232 for (enum MenuType i = 1; i < MENU_MAX; i++)
233 {
235 }
236}
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: init.c:217
MenuType
Types of GUI selections.
Definition: type.h:36
+ Here is the call graph for this function:
+ 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 153 of file lib.c.

154{
155 struct Keymap *p = mutt_mem_calloc(1, sizeof(struct Keymap));
156 p->len = len;
157 p->keys = mutt_mem_calloc(len, sizeof(keycode_t));
158 memcpy(p->keys, keys, len * sizeof(keycode_t));
159 return p;
160}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generic_tokenize_push_string()

void generic_tokenize_push_string ( char *  s)

Parse and queue a 'push' command.

Parameters
sString to push into the key queue

Parses s for <function> syntax and adds the whole sequence the macro buffer.

Definition at line 341 of file lib.c.

342{
343 char *pp = NULL;
344 char *p = s + mutt_str_len(s) - 1;
345 size_t l;
346 int i, op = OP_NULL;
347
348 while (p >= s)
349 {
350 /* if we see something like "<PageUp>", look to see if it is a real
351 * function name and return the corresponding value */
352 if (*p == '>')
353 {
354 for (pp = p - 1; pp >= s && *pp != '<'; pp--)
355 ; // do nothing
356
357 if (pp >= s)
358 {
359 i = parse_fkey(pp);
360 if (i > 0)
361 {
362 mutt_push_macro_event(KEY_F(i), 0);
363 p = pp - 1;
364 continue;
365 }
366
367 l = p - pp + 1;
368 for (i = 0; KeyNames[i].name; i++)
369 {
370 if (mutt_istrn_equal(pp, KeyNames[i].name, l))
371 break;
372 }
373 if (KeyNames[i].name)
374 {
375 /* found a match */
376 mutt_push_macro_event(KeyNames[i].value, 0);
377 p = pp - 1;
378 continue;
379 }
380
381 /* See if it is a valid command
382 * skip the '<' and the '>' when comparing */
383 for (enum MenuType j = 0; MenuNames[j].name; j++)
384 {
385 const struct MenuFuncOp *funcs = km_get_table(MenuNames[j].value);
386 if (funcs)
387 {
388 op = get_op(funcs, pp + 1, l - 2);
389 if (op != OP_NULL)
390 break;
391 }
392 }
393
394 if (op != OP_NULL)
395 {
397 p = pp - 1;
398 continue;
399 }
400 }
401 }
402 mutt_push_macro_event((unsigned char) *p--, 0); /* independent 8 bits chars */
403 }
404}
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: get.c:154
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition: lib.c:302
static int parse_fkey(char *s)
Parse a function key string.
Definition: lib.c:169
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:447
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:103
+ Here is the call graph for this function:
+ 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 302 of file lib.c.

303{
304 for (int i = 0; funcs[i].name; i++)
305 {
306 if (mutt_istrn_equal(start, funcs[i].name, len) && (mutt_str_len(funcs[i].name) == len))
307 {
308 return funcs[i].op;
309 }
310 }
311
312 return OP_NULL;
313}
const char * name
Name of the function.
Definition: lib.h:102
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_bindkey()

enum CommandResult km_bindkey ( const char *  s,
enum MenuType  mtype,
int  op 
)

Bind a key in a Menu to an operation.

Parameters
sKey string
mtypeMenu type, e.g. MENU_PAGER
opOperation, e.g. OP_DELETE
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 186 of file parse.c.

187{
188 return km_bindkey_err(s, mtype, op, NULL);
189}
static enum CommandResult km_bindkey_err(const char *s, enum MenuType mtype, int op, struct Buffer *err)
Bind a key in a Menu to an operation (with error message)
Definition: parse.c:173
+ 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 278 of file lib.c.

279{
280 *pos = 0;
281
282 while (*pos < k1->len && *pos < k2->len)
283 {
284 if (k1->keys[*pos] < k2->keys[*pos])
285 return k2;
286 else if (k1->keys[*pos] > k2->keys[*pos])
287 return k1;
288 else
289 *pos = *pos + 1;
290 }
291
292 return NULL;
293}
+ 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 324 of file lib.c.

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

◆ mutt_keymap_free()

void mutt_keymap_free ( struct Keymap **  ptr)

Free a Keymap.

Parameters
ptrKeymap to free

Definition at line 134 of file lib.c.

135{
136 if (!ptr || !*ptr)
137 return;
138
139 struct Keymap *km = *ptr;
140 FREE(&km->macro);
141 FREE(&km->desc);
142 FREE(&km->keys);
143
144 FREE(ptr);
145}
#define FREE(x)
Definition: memory.h:45
char * desc
Description of a macro for the help menu.
Definition: lib.h:67
+ 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 219 of file lib.c.

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

Variable Documentation

◆ MacroEvents

struct KeyEventArray MacroEvents
extern

These are used for macros and exec/push commands.

They can be temporarily ignored by passing GETCH_IGNORE_MACRO

Definition at line 48 of file get.c.

◆ Keymaps

struct KeymapList Keymaps[]
extern

Array of Keymap keybindings, one for each Menu.

Array of Keymap keybindings, one for each Menu.

Definition at line 128 of file lib.c.

◆ KeyNames

struct Mapping KeyNames[]
extern

Key name lookup table.

Definition at line 63 of file lib.c.

◆ AbortKey

keycode_t AbortKey
extern

key to abort edits etc, normally Ctrl-G

key to abort edits etc, normally Ctrl-G

Definition at line 125 of file lib.c.

◆ Menus

const struct Mapping Menus[]
extern