NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
keymap.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 keymap.h:
+ This graph shows which files directly or indirectly include this file:

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
 
#define MUTT_UNMACRO   1<<1
 
#define MAX_SEQ   8
 

Typedefs

typedef short keycode_t
 Type for key storage, the rest of neomutt works fine with int type. More...
 

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

void init_extended_keys (void)
 Initialise map of ncurses extended keys. More...
 
 STAILQ_HEAD (KeymapList, Keymap)
 
int km_expand_key (char *s, size_t len, struct Keymap *map)
 Get the key string bound to a Keymap. More...
 
struct Keymapkm_find_func (enum MenuType menu, int func)
 Find a function's mapping in a Menu. More...
 
void km_init (void)
 Initialise all the menu keybindings. More...
 
void km_error_key (enum MenuType menu)
 Handle an unbound key sequence. More...
 
void mutt_what_key (void)
 Ask the user to press a key. More...
 
void mutt_init_abort_key (void)
 Parse the abort_key config string. More...
 
int main_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
 
enum CommandResult km_bind (char *s, enum MenuType menu, int op, char *macro, char *desc)
 Bind a key to a macro. More...
 
int km_dokey (enum MenuType menu)
 Determine what a keypress should do. More...
 
struct KeyEvent km_dokey_event (enum MenuType menu)
 Determine what a keypress should do. More...
 
const struct MenuFuncOpkm_get_table (enum MenuType mtype)
 Lookup a Menu's functions. More...
 
const char * mutt_get_func (const struct MenuFuncOp *bindings, int op)
 Get the name of a function. More...
 
void mutt_keys_free (void)
 Free the key maps. More...
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unmacro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 

Variables

struct KeymapList Keymaps []
 Array of Keymap keybindings, one for each Menu. More...
 
keycode_t AbortKey
 key to abort edits etc, normally Ctrl-G More...
 
const struct Mapping Menus []
 

Detailed Description

Manage keymappings.

Authors
  • Michael R. Elkins

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

Macro Definition Documentation

◆ MUTT_UNBIND

#define MUTT_UNBIND   1<<0

Definition at line 33 of file keymap.h.

◆ MUTT_UNMACRO

#define MUTT_UNMACRO   1<<1

Definition at line 34 of file keymap.h.

◆ MAX_SEQ

#define MAX_SEQ   8

Definition at line 36 of file keymap.h.

Typedef Documentation

◆ keycode_t

typedef short keycode_t

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

Definition at line 39 of file keymap.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 123 of file keymap.h.

124{
125 NT_BINDING_ADD = 1,
128
132};
@ NT_MACRO_ADD
Key macro has been added.
Definition: keymap.h:129
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: keymap.h:130
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: keymap.h:131
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: keymap.h:126
@ NT_BINDING_ADD
Key binding has been added.
Definition: keymap.h:125
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: keymap.h:127

Function Documentation

◆ 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 tigetstr() returns -1. 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 996 of file keymap.c.

997{
998#ifdef HAVE_USE_EXTENDED_NAMES
999 use_extended_names(true);
1000
1001 for (int j = 0; KeyNames[j].name; j++)
1002 {
1003 if (KeyNames[j].value == -1)
1004 {
1005 const char *keyname = find_ext_name(KeyNames[j].name);
1006
1007 if (keyname)
1008 {
1009 char *s = tigetstr((char *) keyname);
1010 if (s && ((long) (s) != -1))
1011 {
1012 int code = key_defined(s);
1013 if (code > 0)
1014 KeyNames[j].value = code;
1015 }
1016 }
1017 }
1018 }
1019#endif
1020}
static const char * find_ext_name(const char *key)
Find the curses name for a key.
Definition: keymap.c:976
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:62
int value
Integer value.
Definition: mapping.h:34
const char * name
String value.
Definition: mapping.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ STAILQ_HEAD()

STAILQ_HEAD ( KeymapList  ,
Keymap   
)

◆ 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 928 of file keymap.c.

929{
930 if (!map)
931 return 0;
932
933 int p = 0;
934
935 while (true)
936 {
937 mutt_str_copy(s, km_keyname(map->keys[p]), len);
938 const size_t l = mutt_str_len(s);
939 len -= l;
940
941 if ((++p >= map->len) || !len)
942 return 1;
943
944 s += l;
945 }
946
947 /* not reached */
948}
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:821
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:567
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:652
keycode_t * keys
key sequence
Definition: keymap.h:55
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
+ 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 956 of file keymap.c.

957{
958 struct Keymap *np = NULL;
959 STAILQ_FOREACH(np, &Keymaps[mtype], entries)
960 {
961 if (np->op == func)
962 break;
963 }
964 return np;
965}
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:126
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A keyboard mapping.
Definition: keymap.h:49
short op
operation to perform
Definition: keymap.h:52
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 1025 of file keymap.c.

1026{
1027 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
1028
1031#ifdef USE_AUTOCRYPT
1033#endif
1039#ifdef MIXMASTER
1041#endif
1045
1050
1051#ifdef CRYPT_BACKEND_GPGME
1054#endif
1055}
const struct MenuOpSeq AutocryptAcctDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:794
const struct MenuOpSeq PostDefaultBindings[]
Key bindings for the Postpone Menu.
Definition: functions.c:1224
const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition: functions.c:907
const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition: functions.c:1234
const struct MenuOpSeq BrowserDefaultBindings[]
Key bindings for the file Browser Menu.
Definition: functions.c:807
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:748
const struct MenuOpSeq PagerDefaultBindings[]
Key bindings for the Pager Menu.
Definition: functions.c:1110
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition: functions.c:945
const struct MenuOpSeq AttachDefaultBindings[]
Key bindings for the Attachment Menu.
Definition: functions.c:763
const struct MenuOpSeq IndexDefaultBindings[]
Key bindings for the Index Menu.
Definition: functions.c:994
const struct MenuOpSeq MixDefaultBindings[]
Key bindings for the Mixmaster Menu.
Definition: functions.c:1090
const struct MenuOpSeq PgpDefaultBindings[]
Key bindings for the Pgp Menu.
Definition: functions.c:1214
const struct MenuOpSeq ComposeDefaultBindings[]
Key bindings for the Compose Menu.
Definition: functions.c:844
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition: functions.c:1249
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: keymap.c:805
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define WithCrypto
Definition: lib.h:116
@ MENU_KEY_SELECT_PGP
Select a PGP key.
Definition: type.h:47
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50
@ MENU_KEY_SELECT_SMIME
Select a SMIME key.
Definition: type.h:48
@ MENU_ATTACH
Select an attachment.
Definition: type.h:38
@ MENU_QUERY
Select from results of external query.
Definition: type.h:57
@ MENU_COMPOSE
Compose an email.
Definition: type.h:42
@ MENU_MIX
Create/edit a Mixmaster chain.
Definition: type.h:52
@ MENU_PGP
PGP encryption menu.
Definition: type.h:55
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:54
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:58
@ MENU_MAX
Definition: type.h:59
@ MENU_EDITOR
Text entry area.
Definition: type.h:43
@ MENU_POSTPONE
Select a postponed email.
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:44
@ MENU_AUTOCRYPT_ACCT
Autocrypt Account menu.
Definition: type.h:40
+ 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 1061 of file keymap.c.

1062{
1063 char buf[128] = { 0 };
1064 int p, op;
1065
1066 struct Keymap *key = km_find_func(mtype, OP_HELP);
1067 if (!key && (mtype != MENU_EDITOR) && (mtype != MENU_PAGER))
1068 key = km_find_func(MENU_GENERIC, OP_HELP);
1069 if (!key)
1070 {
1071 mutt_error(_("Key is not bound"));
1072 return;
1073 }
1074
1075 /* Make sure the key is really the help key in this menu.
1076 *
1077 * OP_END_COND is used as a barrier to ensure nothing extra
1078 * is left in the unget buffer.
1079 *
1080 * Note that km_expand_key() + tokenize_unget_string() should
1081 * not be used here: control sequences are expanded to a form
1082 * (e.g. "^H") not recognized by km_dokey(). */
1083 mutt_unget_op(OP_END_COND);
1084 p = key->len;
1085 while (p--)
1086 mutt_unget_ch(key->keys[p]);
1087
1088 /* Note, e.g. for the index menu:
1089 * bind generic ? noop
1090 * bind generic ,a help
1091 * bind index ,ab quit
1092 * The index keybinding shadows the generic binding.
1093 * OP_END_COND will be read and returned as the op.
1094 *
1095 * bind generic ? noop
1096 * bind generic dq help
1097 * bind index d delete-message
1098 * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1099 * in the unget buffer.
1100 */
1101 op = km_dokey(mtype);
1102 if (op != OP_END_COND)
1104 if (op != OP_HELP)
1105 {
1106 mutt_error(_("Key is not bound"));
1107 return;
1108 }
1109
1110 km_expand_key(buf, sizeof(buf), key);
1111 mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1112}
void mutt_unget_op(int op)
Return an operation to the input buffer.
Definition: curs_lib.c:532
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: curs_lib.c:584
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition: curs_lib.c:521
#define mutt_error(...)
Definition: logging.h:87
struct Keymap * km_find_func(enum MenuType mtype, int func)
Find a function's mapping in a Menu.
Definition: keymap.c:956
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:795
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:928
#define _(a)
Definition: message.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_what_key()

void mutt_what_key ( void  )

Ask the user to press a key.

Displays the octal value back to the user.

Definition at line 1638 of file keymap.c.

1639{
1640 int ch;
1641
1642 struct MuttWindow *win = msgwin_get_window();
1643 if (!win)
1644 return;
1645
1647 mutt_window_mvprintw(win, 0, 0, _("Enter keys (%s to abort): "), km_keyname(AbortKey));
1650 do
1651 {
1652 ch = getch();
1653 if ((ch != ERR) && (ch != AbortKey))
1654 {
1655 mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1656 mutt_window_move(win, 0, 0);
1657 }
1658 } while (ch != ERR && ch != AbortKey);
1659 mutt_curses_set_cursor(cursor);
1660
1661 mutt_flushinp();
1663}
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:54
@ MT_COLOR_PROMPT
Question/user input.
Definition: color.h:57
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:592
#define mutt_message(...)
Definition: logging.h:86
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:124
struct MuttWindow * msgwin_get_window(void)
Get the Message Window pointer.
Definition: msgwin.c:260
enum MuttCursorState mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:96
struct AttrColor * mutt_curses_set_normal_backed_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:65
struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:81
MuttCursorState
Cursor states for mutt_curses_set_cursor()
Definition: mutt_curses.h:52
@ MUTT_CURSOR_VISIBLE
Display a normal cursor.
Definition: mutt_curses.h:54
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:293
int mutt_window_mvprintw(struct MuttWindow *win, int col, int row, const char *fmt,...)
Move the cursor and write a formatted string to a Window.
Definition: mutt_window.c:322
+ 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 857 of file keymap.c.

858{
859 keycode_t buf[2];
860 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
861 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
862 if (len == 0)
863 {
864 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
865 AbortKey = ctrl('G');
866 return;
867 }
868 if (len > 1)
869 {
870 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
871 c_abort_key);
872 }
873 AbortKey = buf[0];
874}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
#define mutt_warning(...)
Definition: logging.h:85
static size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: keymap.c:274
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: keymap.h:39
#define mutt_array_size(x)
Definition: memory.h:36
#define ctrl(ch)
Definition: mutt_curses.h:40
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 458 of file keymap.c.

459{
460 return km_bind_err(s, mtype, op, macro, desc, NULL);
461}
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: keymap.c:361
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey()

int km_dokey ( enum MenuType  mtype)

Determine what a keypress should do.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
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 795 of file keymap.c.

796{
797 return km_dokey_event(mtype).op;
798}
struct KeyEvent km_dokey_event(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:637
int op
Function opcode, e.g. OP_HELP.
Definition: keymap.h:67
+ 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)

Determine what a keypress should do.

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

Definition at line 637 of file keymap.c.

638{
639 struct KeyEvent tmp = { OP_NULL, OP_NULL };
640 struct Keymap *map = STAILQ_FIRST(&Keymaps[mtype]);
641 int pos = 0;
642 int n = 0;
643
644 if (!map && (mtype != MENU_EDITOR))
645 return retry_generic(mtype, NULL, 0, 0);
646
647#ifdef USE_IMAP
648 const short c_imap_keepalive = cs_subset_number(NeoMutt->sub, "imap_keepalive");
649#endif
650
651 while (true)
652 {
653 const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
654 int i = (c_timeout > 0) ? c_timeout : 60;
655#ifdef USE_IMAP
656 /* keepalive may need to run more frequently than `$timeout` allows */
657 if (c_imap_keepalive)
658 {
659 if (c_imap_keepalive >= i)
661 else
662 {
663 while (c_imap_keepalive && (c_imap_keepalive < i))
664 {
665 tmp = mutt_getch_timeout(c_imap_keepalive * 1000);
666 /* If a timeout was not received, or the window was resized, exit the
667 * loop now. Otherwise, continue to loop until reaching a total of
668 * $timeout seconds. */
669 if ((tmp.op != OP_TIMEOUT) || SigWinch)
670 goto gotkey;
671#ifdef USE_INOTIFY
673 goto gotkey;
674#endif
675 i -= c_imap_keepalive;
677 }
678 }
679 }
680#endif
681
682 tmp = mutt_getch_timeout(i * 1000);
683
684#ifdef USE_IMAP
685 gotkey:
686#endif
687 /* hide timeouts, but not window resizes, from the line editor. */
688 if ((mtype == MENU_EDITOR) && (tmp.op == OP_TIMEOUT) && !SigWinch)
689 continue;
690
691 if ((tmp.op == OP_TIMEOUT) || (tmp.op == OP_ABORT))
692 {
693 return tmp;
694 }
695
696 /* do we have an op already? */
697 if (tmp.op != OP_NULL)
698 {
699 const char *func = NULL;
700 const struct MenuFuncOp *funcs = NULL;
701
702 /* is this a valid op for this menu type? */
703 if ((funcs = km_get_table(mtype)) && (func = mutt_get_func(funcs, tmp.op)))
704 return tmp;
705
706 if ((mtype != MENU_EDITOR) && (mtype != MENU_PAGER) && (mtype != MENU_GENERIC))
707 {
708 /* check generic menu type */
709 funcs = OpGeneric;
710 func = mutt_get_func(funcs, tmp.op);
711 if (func)
712 return tmp;
713 }
714
715 /* Sigh. Valid function but not in this context.
716 * Find the literal string and push it back */
717 for (i = 0; MenuNames[i].name; i++)
718 {
719 funcs = km_get_table(MenuNames[i].value);
720 if (funcs)
721 {
722 func = mutt_get_func(funcs, tmp.op);
723 if (func)
724 {
725 mutt_unget_ch('>');
726 mutt_unget_string(func);
727 mutt_unget_ch('<');
728 break;
729 }
730 }
731 }
732 /* continue to chew */
733 if (func)
734 continue;
735 }
736
737 if (!map)
738 return tmp;
739
740 /* Nope. Business as usual */
741 while (tmp.ch > map->keys[pos])
742 {
743 if ((pos > map->eq) || !STAILQ_NEXT(map, entries))
744 return retry_generic(mtype, map->keys, pos, tmp.ch);
745 map = STAILQ_NEXT(map, entries);
746 }
747
748 if (tmp.ch != map->keys[pos])
749 return retry_generic(mtype, map->keys, pos, tmp.ch);
750
751 if (++pos == map->len)
752 {
753 if (map->op != OP_MACRO)
754 return (struct KeyEvent){ .ch = tmp.ch, .op = map->op };
755
756 /* OptIgnoreMacroEvents turns off processing the MacroEvents buffer
757 * in mutt_getch(). Generating new macro events during that time would
758 * result in undesired behavior once the option is turned off.
759 *
760 * Originally this returned -1, however that results in an unbuffered
761 * username or password prompt being aborted. Returning OP_NULL allows
762 * mutt_enter_string_full() to display the keybinding pressed instead.
763 *
764 * It may be unexpected for a macro's keybinding to be returned,
765 * but less so than aborting the prompt. */
767 {
768 return (struct KeyEvent){ .ch = tmp.ch, .op = OP_NULL };
769 }
770
771 if (n++ == 10)
772 {
774 mutt_error(_("Macro loop detected"));
775 return (struct KeyEvent){ .ch = '\0', .op = -1 };
776 }
777
779 map = STAILQ_FIRST(&Keymaps[mtype]);
780 pos = 0;
781 }
782 }
783
784 /* not reached */
785}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
struct KeyEvent mutt_getch_timeout(int delay)
Get an event with a timeout.
Definition: curs_lib.c:197
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:543
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:561
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:288
void imap_keepalive(void)
Poll the current folder to keep the connection alive.
Definition: util.c:945
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a 'push' command.
Definition: keymap.c:538
const char * mutt_get_func(const struct MenuFuncOp *funcs, int op)
Get the name of a function.
Definition: keymap.c:518
static struct KeyEvent retry_generic(enum MenuType mtype, keycode_t *keys, int keyslen, int lastkey)
Try to find the key in the generic menu bindings.
Definition: keymap.c:611
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: keymap.c:1230
bool MonitorFilesChanged
true after a monitored file has changed
Definition: monitor.c:50
SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:70
#define OP_TIMEOUT
Definition: opcodes.h:32
#define OP_ABORT
Definition: opcodes.h:33
bool OptIgnoreMacroEvents
(pseudo) don't process macro/push/exec events while set
Definition: options.h:43
#define STAILQ_FIRST(head)
Definition: queue.h:350
#define STAILQ_NEXT(elm, field)
Definition: queue.h:400
An event such as a keypress.
Definition: keymap.h:65
int ch
Raw key pressed.
Definition: keymap.h:66
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:50
short eq
number of leading keys equal to next entry
Definition: keymap.h:53
Mapping between a function and an operation.
Definition: keymap.h:92
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:31
+ Here is the call graph for this function:
+ 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 1230 of file keymap.c.

1231{
1232 switch (mtype)
1233 {
1234 case MENU_ALIAS:
1235 return OpAlias;
1236 case MENU_ATTACH:
1237 return OpAttach;
1238#ifdef USE_AUTOCRYPT
1240 return OpAutocrypt;
1241#endif
1242 case MENU_COMPOSE:
1243 return OpCompose;
1244 case MENU_EDITOR:
1245 return OpEditor;
1246 case MENU_FOLDER:
1247 return OpBrowser;
1248 case MENU_GENERIC:
1249 return OpGeneric;
1250 case MENU_INDEX:
1251 return OpIndex;
1252#ifdef CRYPT_BACKEND_GPGME
1254 return OpPgp;
1256 return OpSmime;
1257#endif
1258#ifdef MIXMASTER
1259 case MENU_MIX:
1260 return OpMix;
1261#endif
1262 case MENU_PAGER:
1263 return OpPager;
1264 case MENU_PGP:
1265 return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1266 case MENU_POSTPONE:
1267 return OpPostpone;
1268 case MENU_QUERY:
1269 return OpQuery;
1270 default:
1271 return NULL;
1272 }
1273}
const struct MenuFuncOp OpQuery[]
Functions for the external Query Menu.
Definition: functions.c:721
const struct MenuFuncOp OpMix[]
Functions for the Mixmaster Menu.
Definition: functions.c:514
const struct MenuFuncOp OpAttach[]
Functions for the Attachment Menu.
Definition: functions.c:69
const struct MenuFuncOp OpIndex[]
Functions for the Index Menu.
Definition: functions.c:349
const struct MenuFuncOp OpCompose[]
Functions for the Compose Menu.
Definition: functions.c:177
const struct MenuFuncOp OpSmime[]
Functions for the Smime Menu.
Definition: functions.c:736
const struct MenuFuncOp OpBrowser[]
Functions for the file Browser Menu.
Definition: functions.c:123
const struct MenuFuncOp OpAutocrypt[]
Functions for the Autocrypt Account.
Definition: functions.c:110
const struct MenuFuncOp OpPager[]
Functions for the Pager Menu.
Definition: functions.c:529
const struct MenuFuncOp OpEditor[]
Functions for the Editor Menu.
Definition: functions.c:254
const struct MenuFuncOp OpPgp[]
Functions for the Pgp Menu.
Definition: functions.c:701
const struct MenuFuncOp OpPostpone[]
Functions for the Postpone Menu.
Definition: functions.c:711
const struct MenuFuncOp OpAlias[]
Functions for the Alias Menu.
Definition: functions.c:55
+ 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 518 of file keymap.c.

519{
520 for (int i = 0; funcs[i].name; i++)
521 {
522 if (funcs[i].op == op)
523 return funcs[i].name;
524 }
525
526 return NULL;
527}
const char * name
Name of the function.
Definition: keymap.h:93
+ Here is the caller graph for this function:

◆ mutt_keys_free()

void mutt_keys_free ( void  )

Free the key maps.

Definition at line 1668 of file keymap.c.

1669{
1670 for (int i = 0; i < MENU_MAX; i++)
1671 {
1673 }
1674}
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: keymap.c:192
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_unmacro()

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

Variable Documentation

◆ Keymaps

struct KeymapList Keymaps[]
extern

Array of Keymap keybindings, one for each Menu.

Definition at line 126 of file keymap.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 124 of file keymap.c.

◆ Menus

const struct Mapping Menus[]
extern