NeoMutt  2021-02-05-666-ge300cd
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 "menu/lib.h"
#include "mutt_commands.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  Binding
 Mapping between a user key and a function. 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...
 
const struct Bindingkm_get_table (enum MenuType menu)
 Lookup a menu's keybindings. More...
 
const char * mutt_get_func (const struct Binding *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() -bind menu-name <key_sequence> function-name. 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() -macro <menu> <key> <macro> <description> 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() -Command unbinds: 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...
 
int LastKey
 Last real key pressed, recorded by dokey() 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 115 of file keymap.h.

116 {
117  NT_BINDING_ADD = 1,
120 
121  NT_MACRO_ADD,
124 };
Key macro has been added.
Definition: keymap.h:121
All key bindings have been deleted.
Definition: keymap.h:119
Key macro has been deleted.
Definition: keymap.h:122
All key macros have been deleted.
Definition: keymap.h:123
Key binding has been added.
Definition: keymap.h:117
Key binding has been deleted.
Definition: keymap.h:118

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

989 {
990 #ifdef NCURSES_VERSION
991  use_extended_names(true);
992 
993  for (int j = 0; KeyNames[j].name; j++)
994  {
995  if (KeyNames[j].value == -1)
996  {
997  const char *keyname = find_ext_name(KeyNames[j].name);
998 
999  if (keyname)
1000  {
1001  char *s = tigetstr((char *) keyname);
1002  if (s && ((long) (s) != -1))
1003  {
1004  int code = key_defined(s);
1005  if (code > 0)
1006  KeyNames[j].value = code;
1007  }
1008  }
1009  }
1010  }
1011 #endif
1012 }
int value
Definition: mapping.h:34
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:64
const char * name
Definition: mapping.h:33
+ 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 918 of file keymap.c.

919 {
920  if (!map)
921  return 0;
922 
923  int p = 0;
924 
925  while (true)
926  {
927  mutt_str_copy(s, km_keyname(map->keys[p]), len);
928  const size_t l = mutt_str_len(s);
929  len -= l;
930 
931  if ((++p >= map->len) || !len)
932  return 1;
933 
934  s += l;
935  }
936 
937  /* not reached */
938 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:813
keycode_t * keys
key sequence
Definition: keymap.h:55
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
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:749
+ 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 946 of file keymap.c.

947 {
948  struct Keymap *np = NULL;
949  STAILQ_FOREACH(np, &Keymaps[mtype], entries)
950  {
951  if (np->op == func)
952  break;
953  }
954  return np;
955 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:126
short op
operation to perform
Definition: keymap.h:52
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A keyboard mapping.
Definition: keymap.h:48
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 1017 of file keymap.c.

1018 {
1019  memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
1020 
1029 
1032 
1035 
1036 #ifdef CRYPT_BACKEND_GPGME
1039 #endif
1040 
1041 #ifdef MIXMASTER
1043 
1044  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
1045  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
1046  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
1047 #endif
1048 
1049 #ifdef USE_AUTOCRYPT
1051 #endif
1052 
1053  /* bindings for the line editor */
1055 
1056  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
1057  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
1058  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
1059  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
1060  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
1061  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
1062  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1063  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
1064  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1065 
1066  /* generic menu keymap */
1068 
1069  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
1070  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
1071  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
1072  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
1073  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
1074  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
1075  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
1076  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
1077  km_bindkey("1", MENU_GENERIC, OP_JUMP);
1078  km_bindkey("2", MENU_GENERIC, OP_JUMP);
1079  km_bindkey("3", MENU_GENERIC, OP_JUMP);
1080  km_bindkey("4", MENU_GENERIC, OP_JUMP);
1081  km_bindkey("5", MENU_GENERIC, OP_JUMP);
1082  km_bindkey("6", MENU_GENERIC, OP_JUMP);
1083  km_bindkey("7", MENU_GENERIC, OP_JUMP);
1084  km_bindkey("8", MENU_GENERIC, OP_JUMP);
1085  km_bindkey("9", MENU_GENERIC, OP_JUMP);
1086 
1087  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1088  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1089 
1090  /* Miscellaneous extra bindings */
1091 
1092  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1093  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1094  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1095  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1096  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1097  km_bindkey("x", MENU_MAIN, OP_EXIT);
1098 
1099  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1100  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1101 
1102  km_bindkey("x", MENU_PAGER, OP_EXIT);
1103  km_bindkey("i", MENU_PAGER, OP_EXIT);
1104  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1105  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1106  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1107  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1108  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1109  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1110  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1111  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1112  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1113  km_bindkey("1", MENU_PAGER, OP_JUMP);
1114  km_bindkey("2", MENU_PAGER, OP_JUMP);
1115  km_bindkey("3", MENU_PAGER, OP_JUMP);
1116  km_bindkey("4", MENU_PAGER, OP_JUMP);
1117  km_bindkey("5", MENU_PAGER, OP_JUMP);
1118  km_bindkey("6", MENU_PAGER, OP_JUMP);
1119  km_bindkey("7", MENU_PAGER, OP_JUMP);
1120  km_bindkey("8", MENU_PAGER, OP_JUMP);
1121  km_bindkey("9", MENU_PAGER, OP_JUMP);
1122 
1123  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1124  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1125 
1126  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1127  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1128  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1129 
1130  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1131  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1132  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1133  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1134 
1135  /* edit-to (default "t") hides generic tag-entry in Compose menu
1136  * This will bind tag-entry to "T" in the Compose menu */
1137  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1138 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:263
#define WithCrypto
Definition: lib.h:113
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:647
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:126
PGP encryption menu.
Definition: type.h:55
static void create_bindings(const struct Binding *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: keymap.c:797
Generic selection list.
Definition: type.h:45
Compose an email.
Definition: type.h:42
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:457
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:656
Definition: type.h:59
Pager pager (email viewer)
Definition: type.h:54
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:668
Text entry area.
Definition: type.h:43
static enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:481
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:536
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
Select a PGP key.
Definition: type.h:47
Select an attachment.
Definition: type.h:38
Select from results of external query.
Definition: type.h:57
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:527
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
Select a postponed email.
Definition: type.h:56
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
Create/edit a Mixmaster chain.
Definition: type.h:52
Index panel (list of emails)
Definition: type.h:50
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:601
Autocrypt Account menu.
Definition: type.h:40
General file/mailbox browser.
Definition: type.h:44
Select a SMIME key.
Definition: type.h:48
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:615
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:102
SMIME encryption menu.
Definition: type.h:58
Select an email address by its alias.
Definition: type.h:37
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:684
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:548
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:420
+ 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 1144 of file keymap.c.

1145 {
1146  char buf[128];
1147  int p, op;
1148 
1149  struct Keymap *key = km_find_func(mtype, OP_HELP);
1150  if (!key && (mtype != MENU_EDITOR) && (mtype != MENU_PAGER))
1151  key = km_find_func(MENU_GENERIC, OP_HELP);
1152  if (!key)
1153  {
1154  mutt_error(_("Key is not bound"));
1155  return;
1156  }
1157 
1158  /* Make sure the key is really the help key in this menu.
1159  *
1160  * OP_END_COND is used as a barrier to ensure nothing extra
1161  * is left in the unget buffer.
1162  *
1163  * Note that km_expand_key() + tokenize_unget_string() should
1164  * not be used here: control sequences are expanded to a form
1165  * (e.g. "^H") not recognized by km_dokey(). */
1166  mutt_unget_event(0, OP_END_COND);
1167  p = key->len;
1168  while (p--)
1169  mutt_unget_event(key->keys[p], 0);
1170 
1171  /* Note, e.g. for the index menu:
1172  * bind generic ? noop
1173  * bind generic ,a help
1174  * bind index ,ab quit
1175  * The index keybinding shadows the generic binding.
1176  * OP_END_COND will be read and returned as the op.
1177  *
1178  * bind generic ? noop
1179  * bind generic dq help
1180  * bind index d delete-message
1181  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1182  * in the unget buffer.
1183  */
1184  op = km_dokey(mtype);
1185  if (op != OP_END_COND)
1187  if (op != OP_HELP)
1188  {
1189  mutt_error(_("Key is not bound"));
1190  return;
1191  }
1192 
1193  km_expand_key(buf, sizeof(buf), key);
1194  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1195 }
struct Keymap * km_find_func(enum MenuType mtype, int func)
Find a function&#39;s mapping in a Menu.
Definition: keymap.c:946
#define mutt_error(...)
Definition: logging.h:88
Generic selection list.
Definition: type.h:45
keycode_t * keys
key sequence
Definition: keymap.h:55
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:583
#define _(a)
Definition: message.h:28
Pager pager (email viewer)
Definition: type.h:54
Text entry area.
Definition: type.h:43
short op
operation to perform
Definition: keymap.h:52
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:918
A keyboard mapping.
Definition: keymap.h:48
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: curs_lib.c:656
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:635
+ 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 1718 of file keymap.c.

1719 {
1720  int ch;
1721 
1722  struct MuttWindow *win = msgwin_get_window();
1723  if (!win)
1724  return;
1725 
1726  mutt_window_mvprintw(win, 0, 0, _("Enter keys (%s to abort): "), km_keyname(AbortKey));
1727  do
1728  {
1729  ch = getch();
1730  if ((ch != ERR) && (ch != AbortKey))
1731  {
1732  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1733  }
1734  } while (ch != ERR && ch != AbortKey);
1735 
1736  mutt_flushinp();
1737  mutt_clear_error();
1738 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:813
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:668
#define _(a)
Definition: message.h:28
struct MuttWindow * msgwin_get_window(void)
Get the Message Window pointer.
Definition: msgwin.c:253
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:112
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:124
#define mutt_message(...)
Definition: logging.h:87
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:343
+ 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 849 of file keymap.c.

850 {
851  keycode_t buf[2];
852  const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
853  size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
854  if (len == 0)
855  {
856  mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
857  AbortKey = ctrl('G');
858  return;
859  }
860  if (len > 1)
861  {
862  mutt_warning(
863  _("Specified abort key sequence (%s) will be truncated to first key"), c_abort_key);
864  }
865  AbortKey = buf[0];
866 }
#define mutt_error(...)
Definition: logging.h:88
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define mutt_array_size(x)
Definition: memory.h:33
static size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: keymap.c:276
#define ctrl(ch)
Definition: mutt_curses.h:66
#define mutt_warning(...)
Definition: logging.h:86
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: keymap.h:39
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:124
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:

◆ main_config_observer()

int main_config_observer ( struct NotifyCallback nc)

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 871 of file keymap.c.

872 {
873  if ((nc->event_type != NT_CONFIG) || !nc->event_data)
874  return -1;
875 
876  struct EventConfig *ev_c = nc->event_data;
877 
878  if (!mutt_str_equal(ev_c->name, "abort_key"))
879  return 0;
880 
882  mutt_debug(LL_DEBUG5, "config done\n");
883  return 0;
884 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
A config-change event.
Definition: subset.h:69
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: keymap.c:849
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
+ 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 455 of file keymap.c.

456 {
457  return km_bind_err(s, mtype, op, macro, desc, NULL);
458 }
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:363
+ 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 635 of file keymap.c.

636 {
637  struct KeyEvent tmp;
638  struct Keymap *map = STAILQ_FIRST(&Keymaps[mtype]);
639  int pos = 0;
640  int n = 0;
641 
642  if (!map && (mtype != MENU_EDITOR))
643  return retry_generic(mtype, NULL, 0, 0);
644 
645 #ifdef USE_IMAP
646  const short c_imap_keepalive =
647  cs_subset_number(NeoMutt->sub, "imap_keepalive");
648 #endif
649 
650  while (true)
651  {
652  const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
653  int i = (c_timeout > 0) ? c_timeout : 60;
654 #ifdef USE_IMAP
655  /* keepalive may need to run more frequently than `$timeout` allows */
656  if (c_imap_keepalive)
657  {
658  if (c_imap_keepalive >= i)
659  imap_keepalive();
660  else
661  {
662  while (c_imap_keepalive && (c_imap_keepalive < i))
663  {
664  mutt_getch_timeout(c_imap_keepalive * 1000);
665  tmp = mutt_getch();
666  mutt_getch_timeout(-1);
667  /* If a timeout was not received, or the window was resized, exit the
668  * loop now. Otherwise, continue to loop until reaching a total of
669  * $timeout seconds. */
670  if ((tmp.ch != -2) || SigWinch)
671  goto gotkey;
672 #ifdef USE_INOTIFY
674  goto gotkey;
675 #endif
676  i -= c_imap_keepalive;
677  imap_keepalive();
678  }
679  }
680  }
681 #endif
682 
683  mutt_getch_timeout(i * 1000);
684  tmp = mutt_getch();
685  mutt_getch_timeout(-1);
686 
687 #ifdef USE_IMAP
688  gotkey:
689 #endif
690  /* hide timeouts, but not window resizes, from the line editor. */
691  if ((mtype == MENU_EDITOR) && (tmp.ch == -2) && !SigWinch)
692  continue;
693 
694  LastKey = tmp.ch;
695  if (LastKey < 0)
696  return LastKey;
697 
698  /* do we have an op already? */
699  if (tmp.op)
700  {
701  const char *func = NULL;
702  const struct Binding *bindings = NULL;
703 
704  /* is this a valid op for this menu type? */
705  if ((bindings = km_get_table(mtype)) && (func = mutt_get_func(bindings, tmp.op)))
706  return tmp.op;
707 
708  if ((mtype == MENU_EDITOR) && mutt_get_func(OpEditor, tmp.op))
709  return tmp.op;
710 
711  if ((mtype != MENU_EDITOR) && (mtype != MENU_PAGER))
712  {
713  /* check generic menu type */
714  bindings = OpGeneric;
715  func = mutt_get_func(bindings, tmp.op);
716  if (func)
717  return tmp.op;
718  }
719 
720  /* Sigh. Valid function but not in this context.
721  * Find the literal string and push it back */
722  for (i = 0; MenuNames[i].name; i++)
723  {
724  bindings = km_get_table(MenuNames[i].value);
725  if (bindings)
726  {
727  func = mutt_get_func(bindings, tmp.op);
728  if (func)
729  {
730  mutt_unget_event('>', 0);
731  mutt_unget_string(func);
732  mutt_unget_event('<', 0);
733  break;
734  }
735  }
736  }
737  /* continue to chew */
738  if (func)
739  continue;
740  }
741 
742  if (!map)
743  return tmp.op;
744 
745  /* Nope. Business as usual */
746  while (LastKey > map->keys[pos])
747  {
748  if ((pos > map->eq) || !STAILQ_NEXT(map, entries))
749  return retry_generic(mtype, map->keys, pos, LastKey);
750  map = STAILQ_NEXT(map, entries);
751  }
752 
753  if (LastKey != map->keys[pos])
754  return retry_generic(mtype, map->keys, pos, LastKey);
755 
756  if (++pos == map->len)
757  {
758  if (map->op != OP_MACRO)
759  return map->op;
760 
761  /* OptIgnoreMacroEvents turns off processing the MacroEvents buffer
762  * in mutt_getch(). Generating new macro events during that time would
763  * result in undesired behavior once the option is turned off.
764  *
765  * Originally this returned -1, however that results in an unbuffered
766  * username or password prompt being aborted. Returning OP_NULL allows
767  * mutt_enter_string_full() to display the keybinding pressed instead.
768  *
769  * It may be unexpected for a macro's keybinding to be returned,
770  * but less so than aborting the prompt. */
772  {
773  return OP_NULL;
774  }
775 
776  if (n++ == 10)
777  {
778  mutt_flushinp();
779  mutt_error(_("Macro loop detected"));
780  return -1;
781  }
782 
784  map = STAILQ_FIRST(&Keymaps[mtype]);
785  pos = 0;
786  }
787  }
788 
789  /* not reached */
790 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:53
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:126
#define mutt_error(...)
Definition: logging.h:88
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:620
int op
function id number
Definition: keymap.h:94
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:948
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:668
keycode_t * keys
key sequence
Definition: keymap.h:55
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:583
#define _(a)
Definition: message.h:28
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:37
bool MonitorFilesChanged
true after a monitored file has changed
Definition: monitor.c:51
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
Pager pager (email viewer)
Definition: type.h:54
const char * mutt_get_func(const struct Binding *bindings, int op)
Get the name of a function.
Definition: keymap.c:516
Text entry area.
Definition: type.h:43
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
int LastKey
contains the last key the user pressed
Definition: keymap.c:123
short op
operation to perform
Definition: keymap.h:52
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:50
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a &#39;push&#39; command.
Definition: keymap.c:536
static int 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:609
An event such as a keypress.
Definition: keymap.h:64
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:196
#define STAILQ_NEXT(elm, field)
Definition: queue.h:400
const struct Binding * km_get_table(enum MenuType mtype)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1313
A keyboard mapping.
Definition: keymap.h:48
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:153
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:615
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:31
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:602
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
const char * name
Definition: mapping.h:33
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:68
#define STAILQ_FIRST(head)
Definition: queue.h:350
Mapping between a user key and a function.
Definition: keymap.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_get_table()

const struct Binding* km_get_table ( enum MenuType  mtype)

Lookup a menu's keybindings.

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

Definition at line 1313 of file keymap.c.

1314 {
1315  switch (mtype)
1316  {
1317  case MENU_ALIAS:
1318  return OpAlias;
1319  case MENU_ATTACH:
1320  return OpAttach;
1321 #ifdef USE_AUTOCRYPT
1322  case MENU_AUTOCRYPT_ACCT:
1323  return OpAutocryptAcct;
1324 #endif
1325  case MENU_COMPOSE:
1326  return OpCompose;
1327  case MENU_EDITOR:
1328  return OpEditor;
1329  case MENU_FOLDER:
1330  return OpBrowser;
1331  case MENU_GENERIC:
1332  return OpGeneric;
1333 #ifdef CRYPT_BACKEND_GPGME
1334  case MENU_KEY_SELECT_PGP:
1335  return OpPgp;
1336  case MENU_KEY_SELECT_SMIME:
1337  return OpSmime;
1338 #endif
1339  case MENU_MAIN:
1340  return OpMain;
1341 #ifdef MIXMASTER
1342  case MENU_MIX:
1343  return OpMix;
1344 #endif
1345  case MENU_PAGER:
1346  return OpPager;
1347  case MENU_PGP:
1348  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1349  case MENU_POSTPONE:
1350  return OpPost;
1351  case MENU_QUERY:
1352  return OpQuery;
1353  default:
1354  return NULL;
1355  }
1356 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:263
#define WithCrypto
Definition: lib.h:113
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:647
PGP encryption menu.
Definition: type.h:55
Generic selection list.
Definition: type.h:45
Compose an email.
Definition: type.h:42
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:457
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:656
Pager pager (email viewer)
Definition: type.h:54
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:668
Text entry area.
Definition: type.h:43
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:536
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
Select a PGP key.
Definition: type.h:47
Select an attachment.
Definition: type.h:38
Select from results of external query.
Definition: type.h:57
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:527
Select a postponed email.
Definition: type.h:56
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
Create/edit a Mixmaster chain.
Definition: type.h:52
Index panel (list of emails)
Definition: type.h:50
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:601
Autocrypt Account menu.
Definition: type.h:40
General file/mailbox browser.
Definition: type.h:44
Select a SMIME key.
Definition: type.h:48
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:615
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:102
Select an email address by its alias.
Definition: type.h:37
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:684
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:548
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:420
+ Here is the caller graph for this function:

◆ mutt_get_func()

const char* mutt_get_func ( const struct Binding bindings,
int  op 
)

Get the name of a function.

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

Definition at line 516 of file keymap.c.

517 {
518  for (int i = 0; bindings[i].name; i++)
519  {
520  if (bindings[i].op == op)
521  return bindings[i].name;
522  }
523 
524  return NULL;
525 }
int op
function id number
Definition: keymap.h:94
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 1743 of file keymap.c.

1744 {
1745  for (int i = 0; i < MENU_MAX; i++)
1746  {
1748  }
1749 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:126
Definition: type.h:59
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: keymap.c:194
+ 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[]

Array of Keymap keybindings, one for each Menu.

Definition at line 126 of file keymap.c.

◆ LastKey

int LastKey

Last real key pressed, recorded by dokey()

Last real key pressed, recorded by dokey()

Definition at line 123 of file keymap.c.

◆ AbortKey

keycode_t AbortKey

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[]