NeoMutt  2020-09-25
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 "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
 

Enumerations

enum  MenuType {
  MENU_ALIAS, MENU_ATTACH, MENU_COMPOSE, MENU_EDITOR,
  MENU_FOLDER, MENU_GENERIC, MENU_MAIN, MENU_PAGER,
  MENU_POSTPONE, MENU_QUERY, MENU_PGP, MENU_SMIME,
  MENU_KEY_SELECT_PGP, MENU_KEY_SELECT_SMIME, MENU_MIX, MENU_AUTOCRYPT_ACCT,
  MENU_MAX
}
 Types of GUI selections. More...
 
enum  NotifyBinding {
  NT_BINDING_NEW = 1, NT_BINDING_DELETED, NT_BINDING_DELETE_ALL, NT_MACRO_NEW,
  NT_MACRO_DELETED, 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 mutt_abort_key_config_observer (struct NotifyCallback *nc)
 Listen for abort_key config changes - 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() 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...
 
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 []
 Menu name lookup table. More...
 

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 32 of file keymap.h.

◆ MUTT_UNMACRO

#define MUTT_UNMACRO   1<<1

Definition at line 33 of file keymap.h.

◆ MAX_SEQ

#define MAX_SEQ   8

Definition at line 35 of file keymap.h.

Typedef Documentation

◆ keycode_t

typedef short keycode_t

Definition at line 38 of file keymap.h.

Enumeration Type Documentation

◆ MenuType

enum MenuType

Types of GUI selections.

Enumerator
MENU_ALIAS 

Select an email address by its alias.

MENU_ATTACH 

Select an attachment.

MENU_COMPOSE 

Compose an email.

MENU_EDITOR 

Text entry area.

MENU_FOLDER 

General file/mailbox browser.

MENU_GENERIC 

Generic selection list.

MENU_MAIN 

Index panel (list of emails)

MENU_PAGER 

Pager pager (email viewer)

MENU_POSTPONE 

Select a postponed email.

MENU_QUERY 

Select from results of external query.

MENU_PGP 

PGP encryption menu.

MENU_SMIME 

SMIME encryption menu.

MENU_KEY_SELECT_PGP 

Select a PGP key.

MENU_KEY_SELECT_SMIME 

Select a SMIME key.

MENU_MIX 

Create/edit a Mixmaster chain.

MENU_AUTOCRYPT_ACCT 

Autocrypt Account menu.

MENU_MAX 

Definition at line 72 of file keymap.h.

73 {
74  MENU_ALIAS,
75  MENU_ATTACH,
76  MENU_COMPOSE,
77  MENU_EDITOR,
78  MENU_FOLDER,
79  MENU_GENERIC,
80  MENU_MAIN,
81  MENU_PAGER,
83  MENU_QUERY,
84  MENU_PGP,
85  MENU_SMIME,
86 #ifdef CRYPT_BACKEND_GPGME
89 #endif
90 #ifdef MIXMASTER
91  MENU_MIX,
92 #endif
93 #ifdef USE_AUTOCRYPT
95 #endif
96  MENU_MAX,
97 };
PGP encryption menu.
Definition: keymap.h:84
General file/mailbox browser.
Definition: keymap.h:78
Autocrypt Account menu.
Definition: keymap.h:94
Compose an email.
Definition: keymap.h:76
Index panel (list of emails)
Definition: keymap.h:80
SMIME encryption menu.
Definition: keymap.h:85
Pager pager (email viewer)
Definition: keymap.h:81
Select from results of external query.
Definition: keymap.h:83
Select an attachment.
Definition: keymap.h:75
Select a PGP key.
Definition: keymap.h:87
Select an email address by its alias.
Definition: keymap.h:74
Create/edit a Mixmaster chain.
Definition: keymap.h:91
Select a SMIME key.
Definition: keymap.h:88
Text entry area.
Definition: keymap.h:77
Select a postponed email.
Definition: keymap.h:82
Generic selection list.
Definition: keymap.h:79

◆ NotifyBinding

Key Binding notification types.

Observers of NT_BINDING will be passed an EventBinding.

Enumerator
NT_BINDING_NEW 

A key binding has been created.

NT_BINDING_DELETED 

A key binding has been deleted.

NT_BINDING_DELETE_ALL 

All key bindings are about to be deleted.

NT_MACRO_NEW 

A key macro has been created.

NT_MACRO_DELETED 

A key macro has been deleted.

NT_MACRO_DELETE_ALL 

All key macros are about to be deleted.

Definition at line 142 of file keymap.h.

143 {
144  NT_BINDING_NEW = 1,
147 
148  NT_MACRO_NEW,
151 };
A key binding has been created.
Definition: keymap.h:144
A key macro has been deleted.
Definition: keymap.h:149
All key bindings are about to be deleted.
Definition: keymap.h:146
All key macros are about to be deleted.
Definition: keymap.h:150
A key binding has been deleted.
Definition: keymap.h:145
A key macro has been created.
Definition: keymap.h:148

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

982 {
983 #ifdef NCURSES_VERSION
984  use_extended_names(true);
985 
986  for (int j = 0; KeyNames[j].name; j++)
987  {
988  if (KeyNames[j].value == -1)
989  {
990  const char *keyname = find_ext_name(KeyNames[j].name);
991 
992  if (keyname)
993  {
994  char *s = tigetstr((char *) keyname);
995  if (s && ((long) (s) != -1))
996  {
997  int code = key_defined(s);
998  if (code > 0)
999  KeyNames[j].value = code;
1000  }
1001  }
1002  }
1003  }
1004 #endif
1005 }
int value
Definition: mapping.h:34
const char * name
name of the function
Definition: keymap.h:122
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:87
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 911 of file keymap.c.

912 {
913  if (!map)
914  return 0;
915 
916  int p = 0;
917 
918  while (true)
919  {
920  mutt_str_copy(s, km_keyname(map->keys[p]), len);
921  const size_t l = mutt_str_len(s);
922  len -= l;
923 
924  if ((++p >= map->len) || !len)
925  return 1;
926 
927  s += l;
928  }
929 
930  /* not reached */
931 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:830
keycode_t * keys
key sequence
Definition: keymap.h:54
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
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:716
+ 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  menu,
int  func 
)

Find a function's mapping in a Menu.

Parameters
menuMenu id, e.g. MENU_PAGER
funcFunction, e.g. OP_DELETE
Return values
ptrKeymap for the function

Definition at line 939 of file keymap.c.

940 {
941  struct Keymap *np = NULL;
942  STAILQ_FOREACH(np, &Keymaps[menu], entries)
943  {
944  if (np->op == func)
945  break;
946  }
947  return np;
948 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
short op
operation to perform
Definition: keymap.h:51
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
A keyboard mapping.
Definition: keymap.h:47
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 1010 of file keymap.c.

1011 {
1012  memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
1013 
1022 
1025 
1028 
1029 #ifdef CRYPT_BACKEND_GPGME
1032 #endif
1033 
1034 #ifdef MIXMASTER
1036 
1037  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
1038  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
1039  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
1040 #endif
1041 
1042 #ifdef USE_AUTOCRYPT
1044 #endif
1045 
1046  /* bindings for the line editor */
1048 
1049  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
1050  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
1051  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
1052  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
1053  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
1054  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
1055  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1056  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
1057  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1058 
1059  /* generic menu keymap */
1061 
1062  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
1063  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
1064  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
1065  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
1066  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
1067  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
1068  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
1069  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
1070  km_bindkey("1", MENU_GENERIC, OP_JUMP);
1071  km_bindkey("2", MENU_GENERIC, OP_JUMP);
1072  km_bindkey("3", MENU_GENERIC, OP_JUMP);
1073  km_bindkey("4", MENU_GENERIC, OP_JUMP);
1074  km_bindkey("5", MENU_GENERIC, OP_JUMP);
1075  km_bindkey("6", MENU_GENERIC, OP_JUMP);
1076  km_bindkey("7", MENU_GENERIC, OP_JUMP);
1077  km_bindkey("8", MENU_GENERIC, OP_JUMP);
1078  km_bindkey("9", MENU_GENERIC, OP_JUMP);
1079 
1080  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1081  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1082 
1083  /* Miscellaneous extra bindings */
1084 
1085  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1086  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1087  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1088  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1089  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1090  km_bindkey("x", MENU_MAIN, OP_EXIT);
1091 
1092  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1093  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1094 
1095  km_bindkey("x", MENU_PAGER, OP_EXIT);
1096  km_bindkey("i", MENU_PAGER, OP_EXIT);
1097  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1098  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1099  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1100  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1101  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1102  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1103  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1104  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1105  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1106  km_bindkey("1", MENU_PAGER, OP_JUMP);
1107  km_bindkey("2", MENU_PAGER, OP_JUMP);
1108  km_bindkey("3", MENU_PAGER, OP_JUMP);
1109  km_bindkey("4", MENU_PAGER, OP_JUMP);
1110  km_bindkey("5", MENU_PAGER, OP_JUMP);
1111  km_bindkey("6", MENU_PAGER, OP_JUMP);
1112  km_bindkey("7", MENU_PAGER, OP_JUMP);
1113  km_bindkey("8", MENU_PAGER, OP_JUMP);
1114  km_bindkey("9", MENU_PAGER, OP_JUMP);
1115 
1116  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1117  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1118 
1119  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1120  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1121  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1122 
1123  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1124  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1125  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1126  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1127 
1128  /* edit-to (default "t") hides generic tag-entry in Compose menu
1129  * This will bind tag-entry to "T" in the Compose menu */
1130  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1131 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:262
PGP encryption menu.
Definition: keymap.h:84
#define WithCrypto
Definition: lib.h:123
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:642
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
General file/mailbox browser.
Definition: keymap.h:78
Autocrypt Account menu.
Definition: keymap.h:94
Compose an email.
Definition: keymap.h:76
Index panel (list of emails)
Definition: keymap.h:80
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:454
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:651
static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:504
SMIME encryption menu.
Definition: keymap.h:85
Pager pager (email viewer)
Definition: keymap.h:81
Select from results of external query.
Definition: keymap.h:83
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:663
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:533
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:524
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:98
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:97
Select an attachment.
Definition: keymap.h:75
Select a PGP key.
Definition: keymap.h:87
static void create_bindings(const struct Binding *map, enum MenuType menu)
Attach a set of keybindings to a Menu.
Definition: keymap.c:814
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:597
Select an email address by its alias.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:610
Create/edit a Mixmaster chain.
Definition: keymap.h:91
Select a SMIME key.
Definition: keymap.h:88
Text entry area.
Definition: keymap.h:77
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:102
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:679
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:544
Select a postponed email.
Definition: keymap.h:82
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:418
Generic selection list.
Definition: keymap.h:79
+ 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  menu)

Handle an unbound key sequence.

Parameters
menuMenu id, e.g. MENU_PAGER

Definition at line 1137 of file keymap.c.

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

1677 {
1678  int ch;
1679 
1680  mutt_window_mvprintw(MessageWindow, 0, 0, _("Enter keys (%s to abort): "),
1681  km_keyname(AbortKey));
1682  do
1683  {
1684  ch = getch();
1685  if ((ch != ERR) && (ch != AbortKey))
1686  {
1687  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1688  }
1689  } while (ch != ERR && ch != AbortKey);
1690 
1691  mutt_flushinp();
1692  mutt_clear_error();
1693 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:830
#define mutt_message(...)
Definition: logging.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:919
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:47
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:147
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:425
+ 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 C_AbortKey and put the keycode into AbortKey.

Definition at line 866 of file keymap.c.

867 {
868  keycode_t buf[2];
869  size_t len = parsekeys(C_AbortKey, buf, mutt_array_size(buf));
870  if (len == 0)
871  {
872  mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
873  AbortKey = ctrl('G');
874  return;
875  }
876  if (len > 1)
877  {
878  mutt_warning(
879  _("Specified abort key sequence (%s) will be truncated to first key"), C_AbortKey);
880  }
881  AbortKey = buf[0];
882 }
#define mutt_warning(...)
Definition: logging.h:82
#define _(a)
Definition: message.h:28
WHERE char * C_AbortKey
Config: String representation of key to abort prompts.
Definition: mutt_globals.h:84
#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:299
#define ctrl(ch)
Definition: mutt_curses.h:66
short keycode_t
Definition: keymap.h:38
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:147
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
#define mutt_error(...)
Definition: logging.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_abort_key_config_observer()

int mutt_abort_key_config_observer ( struct NotifyCallback nc)

Listen for abort_key config changes - Implements observer_t.

Definition at line 887 of file keymap.c.

888 {
889  if (!nc->event_data)
890  return -1;
891  if (nc->event_type != NT_CONFIG)
892  return 0;
893 
894  struct EventConfig *ec = nc->event_data;
895 
896  if (!mutt_str_equal(ec->name, "abort_key"))
897  return 0;
898 
900  return 0;
901 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
A config-change event.
Definition: subset.h:70
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:866
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:37
const char * name
Name of config item that changed.
Definition: subset.h:73
+ 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  menu,
int  op,
char *  macro,
char *  desc 
)

Bind a key to a macro.

Parameters
sKey string
menuMenu id, 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 478 of file keymap.c.

479 {
480  return km_bind_err(s, menu, op, macro, desc, NULL);
481 }
static enum CommandResult km_bind_err(const char *s, enum MenuType menu, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition: keymap.c:386
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey()

int km_dokey ( enum MenuType  menu)

Determine what a keypress should do.

Parameters
menuMenu ID, 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 658 of file keymap.c.

659 {
660  struct KeyEvent tmp;
661  struct Keymap *map = STAILQ_FIRST(&Keymaps[menu]);
662  int pos = 0;
663  int n = 0;
664 
665  if (!map && (menu != MENU_EDITOR))
666  return retry_generic(menu, NULL, 0, 0);
667 
668  while (true)
669  {
670  int i = (C_Timeout > 0) ? C_Timeout : 60;
671 #ifdef USE_IMAP
672  /* keepalive may need to run more frequently than C_Timeout allows */
673  if (C_ImapKeepalive)
674  {
675  if (C_ImapKeepalive >= i)
676  imap_keepalive();
677  else
678  {
679  while (C_ImapKeepalive && (C_ImapKeepalive < i))
680  {
682  tmp = mutt_getch();
683  mutt_getch_timeout(-1);
684  /* If a timeout was not received, or the window was resized, exit the
685  * loop now. Otherwise, continue to loop until reaching a total of
686  * $timeout seconds. */
687  if ((tmp.ch != -2) || SigWinch)
688  goto gotkey;
689 #ifdef USE_INOTIFY
691  goto gotkey;
692 #endif
693  i -= C_ImapKeepalive;
694  imap_keepalive();
695  }
696  }
697  }
698 #endif
699 
700  mutt_getch_timeout(i * 1000);
701  tmp = mutt_getch();
702  mutt_getch_timeout(-1);
703 
704 #ifdef USE_IMAP
705  gotkey:
706 #endif
707  /* hide timeouts, but not window resizes, from the line editor. */
708  if ((menu == MENU_EDITOR) && (tmp.ch == -2) && !SigWinch)
709  continue;
710 
711  LastKey = tmp.ch;
712  if (LastKey < 0)
713  return LastKey;
714 
715  /* do we have an op already? */
716  if (tmp.op)
717  {
718  const char *func = NULL;
719  const struct Binding *bindings = NULL;
720 
721  /* is this a valid op for this menu? */
722  if ((bindings = km_get_table(menu)) && (func = mutt_get_func(bindings, tmp.op)))
723  return tmp.op;
724 
725  if ((menu == MENU_EDITOR) && mutt_get_func(OpEditor, tmp.op))
726  return tmp.op;
727 
728  if ((menu != MENU_EDITOR) && (menu != MENU_PAGER))
729  {
730  /* check generic menu */
731  bindings = OpGeneric;
732  func = mutt_get_func(bindings, tmp.op);
733  if (func)
734  return tmp.op;
735  }
736 
737  /* Sigh. Valid function but not in this context.
738  * Find the literal string and push it back */
739  for (i = 0; Menus[i].name; i++)
740  {
741  bindings = km_get_table(Menus[i].value);
742  if (bindings)
743  {
744  func = mutt_get_func(bindings, tmp.op);
745  if (func)
746  {
747  mutt_unget_event('>', 0);
748  mutt_unget_string(func);
749  mutt_unget_event('<', 0);
750  break;
751  }
752  }
753  }
754  /* continue to chew */
755  if (func)
756  continue;
757  }
758 
759  if (!map)
760  return tmp.op;
761 
762  /* Nope. Business as usual */
763  while (LastKey > map->keys[pos])
764  {
765  if ((pos > map->eq) || !STAILQ_NEXT(map, entries))
766  return retry_generic(menu, map->keys, pos, LastKey);
767  map = STAILQ_NEXT(map, entries);
768  }
769 
770  if (LastKey != map->keys[pos])
771  return retry_generic(menu, map->keys, pos, LastKey);
772 
773  if (++pos == map->len)
774  {
775  if (map->op != OP_MACRO)
776  return map->op;
777 
778  /* OptIgnoreMacroEvents turns off processing the MacroEvents buffer
779  * in mutt_getch(). Generating new macro events during that time would
780  * result in undesired behavior once the option is turned off.
781  *
782  * Originally this returned -1, however that results in an unbuffered
783  * username or password prompt being aborted. Returning OP_NULL allows
784  * mutt_enter_string_full() to display the keybinding pressed instead.
785  *
786  * It may be unexpected for a macro's keybinding to be returned,
787  * but less so than aborting the prompt. */
789  {
790  return OP_NULL;
791  }
792 
793  if (n++ == 10)
794  {
795  mutt_flushinp();
796  mutt_error(_("Macro loop detected"));
797  return -1;
798  }
799 
801  map = STAILQ_FIRST(&Keymaps[menu]);
802  pos = 0;
803  }
804  }
805 
806  /* not reached */
807 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:52
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: mutt_globals.h:115
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:871
int op
function id number
Definition: keymap.h:123
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:1079
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:919
keycode_t * keys
key sequence
Definition: keymap.h:54
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:834
#define _(a)
Definition: message.h:28
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:38
bool MonitorFilesChanged
true after a monitored file has changed
Definition: monitor.c:50
Pager pager (email viewer)
Definition: keymap.h:81
const char * mutt_get_func(const struct Binding *bindings, int op)
Get the name of a function.
Definition: keymap.c:539
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:146
short op
operation to perform
Definition: keymap.h:51
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:49
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a &#39;push&#39; command.
Definition: keymap.c:559
An event such as a keypress.
Definition: keymap.h:63
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:189
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
A keyboard mapping.
Definition: keymap.h:47
short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
Definition: config.c:47
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
static int retry_generic(enum MenuType menu, keycode_t *keys, int keyslen, int lastkey)
Try to find the key in the generic menu bindings.
Definition: keymap.c:632
#define mutt_error(...)
Definition: logging.h:84
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:146
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:610
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1306
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:853
Text entry area.
Definition: keymap.h:77
const char * name
Definition: mapping.h:33
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:75
#define STAILQ_FIRST(head)
Definition: queue.h:347
Mapping between a user key and a function.
Definition: keymap.h:120
+ 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  menu)

Lookup a menu's keybindings.

Parameters
menuMenu id, e.g. MENU_EDITOR
Return values
ptrArray of keybindings

Definition at line 1306 of file keymap.c.

1307 {
1308  switch (menu)
1309  {
1310  case MENU_ALIAS:
1311  return OpAlias;
1312  case MENU_ATTACH:
1313  return OpAttach;
1314 #ifdef USE_AUTOCRYPT
1315  case MENU_AUTOCRYPT_ACCT:
1316  return OpAutocryptAcct;
1317 #endif
1318  case MENU_COMPOSE:
1319  return OpCompose;
1320  case MENU_EDITOR:
1321  return OpEditor;
1322  case MENU_FOLDER:
1323  return OpBrowser;
1324  case MENU_GENERIC:
1325  return OpGeneric;
1326 #ifdef CRYPT_BACKEND_GPGME
1327  case MENU_KEY_SELECT_PGP:
1328  return OpPgp;
1329  case MENU_KEY_SELECT_SMIME:
1330  return OpSmime;
1331 #endif
1332  case MENU_MAIN:
1333  return OpMain;
1334 #ifdef MIXMASTER
1335  case MENU_MIX:
1336  return OpMix;
1337 #endif
1338  case MENU_PAGER:
1339  return OpPager;
1340  case MENU_PGP:
1341  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1342  case MENU_POSTPONE:
1343  return OpPost;
1344  case MENU_QUERY:
1345  return OpQuery;
1346  default:
1347  return NULL;
1348  }
1349 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:262
PGP encryption menu.
Definition: keymap.h:84
#define WithCrypto
Definition: lib.h:123
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:642
General file/mailbox browser.
Definition: keymap.h:78
Autocrypt Account menu.
Definition: keymap.h:94
Compose an email.
Definition: keymap.h:76
Index panel (list of emails)
Definition: keymap.h:80
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:454
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:651
Pager pager (email viewer)
Definition: keymap.h:81
Select from results of external query.
Definition: keymap.h:83
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:663
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:533
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:524
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:97
Select an attachment.
Definition: keymap.h:75
Select a PGP key.
Definition: keymap.h:87
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:597
Select an email address by its alias.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:610
Create/edit a Mixmaster chain.
Definition: keymap.h:91
Select a SMIME key.
Definition: keymap.h:88
Text entry area.
Definition: keymap.h:77
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:102
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:679
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:544
Select a postponed email.
Definition: keymap.h:82
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:418
Generic selection list.
Definition: keymap.h:79
+ 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 539 of file keymap.c.

540 {
541  for (int i = 0; bindings[i].name; i++)
542  {
543  if (bindings[i].op == op)
544  return bindings[i].name;
545  }
546 
547  return NULL;
548 }
int op
function id number
Definition: keymap.h:123
const char * name
name of the function
Definition: keymap.h:122
+ Here is the caller graph for this function:

◆ mutt_keys_free()

void mutt_keys_free ( void  )

Free the key maps.

Definition at line 1698 of file keymap.c.

1699 {
1700  for (int i = 0; i < MENU_MAX; i++)
1701  {
1703  }
1704 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: keymap.c:217
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_bind()

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

Definition at line 1356 of file keymap.c.

1358 {
1359  const struct Binding *bindings = NULL;
1360  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1361  int num_menus = 0;
1362  enum CommandResult rc = MUTT_CMD_SUCCESS;
1363 
1364  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true);
1365  if (!key)
1366  return MUTT_CMD_ERROR;
1367 
1368  /* function to execute */
1370  if (MoreArgs(s))
1371  {
1372  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1373  rc = MUTT_CMD_ERROR;
1374  }
1375  else if (mutt_istr_equal("noop", buf->data))
1376  {
1377  for (int i = 0; i < num_menus; i++)
1378  {
1379  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1380  bindings = km_get_table(menu[i]);
1381  if (bindings)
1382  {
1383  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1384  struct EventBinding ev_bind = { menu[i], key, op };
1386  }
1387  }
1388  }
1389  else
1390  {
1391  for (int i = 0; i < num_menus; i++)
1392  {
1393  /* The pager and editor menus don't use the generic map,
1394  * however for other menus try generic first. */
1395  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1396  {
1397  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1398  if (rc == MUTT_CMD_SUCCESS)
1399  {
1400  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1401  struct EventBinding ev_bind = { menu[i], key, op };
1403  continue;
1404  }
1405  if (rc == MUTT_CMD_WARNING)
1406  break;
1407  }
1408 
1409  /* Clear any error message, we're going to try again */
1410  err->data[0] = '\0';
1411  bindings = km_get_table(menu[i]);
1412  if (bindings)
1413  {
1414  rc = try_bind(key, menu[i], buf->data, bindings, err);
1415  if (rc == MUTT_CMD_SUCCESS)
1416  {
1417  int op = get_op(bindings, buf->data, mutt_str_len(buf->data));
1418  struct EventBinding ev_bind = { menu[i], key, op };
1420  continue;
1421  }
1422  }
1423  }
1424  }
1425  FREE(&key);
1426  return rc;
1427 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
int op
function id number
Definition: keymap.h:123
A key binding has been created.
Definition: keymap.h:144
int op
Operation the key&#39;s bound to (for bind), e.g. OP_DELETE.
Definition: keymap.h:134
#define _(a)
Definition: message.h:28
static char * parse_keymap(enum MenuType *menu, struct Buffer *s, int max_menus, int *num_menus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1221
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:133
#define mutt_array_size(x)
Definition: memory.h:33
static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:504
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:43
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:44
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:394
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
A key binding has been deleted.
Definition: keymap.h:145
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
static enum CommandResult try_bind(char *key, enum MenuType menu, char *func, const struct Binding *bindings, struct Buffer *err)
Try to make a key binding.
Definition: keymap.c:1283
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1306
#define FREE(x)
Definition: memory.h:40
Mapping between user-readable string and a constant.
Definition: mapping.h:31
Text entry area.
Definition: keymap.h:77
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:516
Mapping between a user key and a function.
Definition: keymap.h:120
A key binding Event.
Definition: keymap.h:130
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
Generic selection list.
Definition: keymap.h:79
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
+ Here is the call graph for this function:

◆ mutt_parse_exec()

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

Parse the 'exec' command - Implements Command::parse()

Definition at line 1629 of file keymap.c.

1631 {
1632  int ops[128];
1633  int nops = 0;
1634  const struct Binding *bindings = NULL;
1635  char *function = NULL;
1636 
1637  if (!MoreArgs(s))
1638  {
1639  mutt_buffer_strcpy(err, _("exec: no arguments"));
1640  return MUTT_CMD_ERROR;
1641  }
1642 
1643  do
1644  {
1646  function = buf->data;
1647 
1648  bindings = km_get_table(CurrentMenu);
1649  if (!bindings && (CurrentMenu != MENU_PAGER))
1650  bindings = OpGeneric;
1651 
1652  ops[nops] = get_op(bindings, function, mutt_str_len(function));
1653  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1654  ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
1655 
1656  if (ops[nops] == OP_NULL)
1657  {
1658  mutt_flushinp();
1659  mutt_error(_("%s: no such function"), function);
1660  return MUTT_CMD_ERROR;
1661  }
1662  nops++;
1663  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1664 
1665  while (nops)
1666  mutt_push_macro_event(0, ops[--nops]);
1667 
1668  return MUTT_CMD_SUCCESS;
1669 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:871
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:919
#define _(a)
Definition: message.h:28
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:43
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: mutt_globals.h:77
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:394
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
Success: Command worked.
Definition: mutt_commands.h:38
#define mutt_error(...)
Definition: logging.h:84
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1306
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:516
Mapping between a user key and a function.
Definition: keymap.h:120
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
+ Here is the call graph for this function:

◆ mutt_parse_macro()

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>

Definition at line 1564 of file keymap.c.

1566 {
1567  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1568  int num_menus = 0;
1569  enum CommandResult rc = MUTT_CMD_ERROR;
1570 
1571  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false);
1572  if (!key)
1573  return MUTT_CMD_ERROR;
1574 
1576  /* make sure the macro sequence is not an empty string */
1577  if (buf->data[0] == '\0')
1578  {
1579  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1580  }
1581  else
1582  {
1583  if (MoreArgs(s))
1584  {
1585  char *seq = mutt_str_dup(buf->data);
1587 
1588  if (MoreArgs(s))
1589  {
1590  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1591  }
1592  else
1593  {
1594  for (int i = 0; i < num_menus; i++)
1595  {
1596  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1597  if (rc == MUTT_CMD_SUCCESS)
1598  {
1599  struct EventBinding ev_bind = { menu[i], key, OP_MACRO };
1601  continue;
1602  }
1603  }
1604  }
1605 
1606  FREE(&seq);
1607  }
1608  else
1609  {
1610  for (int i = 0; i < num_menus; i++)
1611  {
1612  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1613  if (rc == MUTT_CMD_SUCCESS)
1614  {
1615  struct EventBinding ev_bind = { menu[i], key, OP_MACRO };
1617  continue;
1618  }
1619  }
1620  }
1621  }
1622  FREE(&key);
1623  return rc;
1624 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
static char * parse_keymap(enum MenuType *menu, struct Buffer *s, int max_menus, int *num_menus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1221
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:133
#define mutt_array_size(x)
Definition: memory.h:33
#define MoreArgs(buf)
Definition: buffer.h:43
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:44
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:72
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:394
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:38
const char * seq
default key binding
Definition: keymap.h:124
#define FREE(x)
Definition: memory.h:40
Mapping between user-readable string and a constant.
Definition: mapping.h:31
enum CommandResult km_bind(char *s, enum MenuType menu, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: keymap.c:478
A key macro has been created.
Definition: keymap.h:148
A key binding Event.
Definition: keymap.h:130
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
+ Here is the call graph for this function:

◆ mutt_parse_push()

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

Parse the 'push' command - Implements Command::parse()

Definition at line 1193 of file keymap.c.

1195 {
1197  if (MoreArgs(s))
1198  {
1199  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1200  return MUTT_CMD_ERROR;
1201  }
1202 
1204  return MUTT_CMD_SUCCESS;
1205 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:871
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:43
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:72
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:394
char * data
Pointer to data.
Definition: buffer.h:35
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a &#39;push&#39; command.
Definition: keymap.c:559
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ mutt_parse_unbind()

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:

  • one binding in one menu-name
  • one binding in all menu-names
  • all bindings in all menu-names

unbind <menu-name[,...]|*> [<key_sequence>]

Definition at line 1490 of file keymap.c.

1492 {
1493  bool menu[MENU_MAX] = { 0 };
1494  bool all_keys = false;
1495  char *key = NULL;
1496 
1498  if (mutt_str_equal(buf->data, "*"))
1499  {
1500  for (enum MenuType i = 0; i < MENU_MAX; i++)
1501  menu[i] = true;
1502  }
1503  else
1504  parse_menu(menu, buf->data, err);
1505 
1506  if (MoreArgs(s))
1507  {
1509  key = buf->data;
1510  }
1511  else
1512  all_keys = true;
1513 
1514  if (MoreArgs(s))
1515  {
1516  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1517 
1518  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1519  return MUTT_CMD_ERROR;
1520  }
1521 
1522  for (enum MenuType i = 0; i < MENU_MAX; i++)
1523  {
1524  if (!menu[i])
1525  continue;
1526  if (all_keys)
1527  {
1528  km_unbind_all(&Keymaps[i], data);
1529  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1530  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1531  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1532  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1533  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1534  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1535  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1536  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1537  if (i != MENU_EDITOR)
1538  {
1539  km_bindkey("?", i, OP_HELP);
1540  km_bindkey("q", i, OP_EXIT);
1541  }
1542  struct EventBinding ev_bind = { i, NULL, OP_NULL };
1545  &ev_bind);
1546  }
1547  else
1548  {
1549  km_bindkey(key, i, OP_NULL);
1550  struct EventBinding ev_bind = { i, key, OP_NULL };
1552  (data & MUTT_UNMACRO) ? NT_MACRO_DELETED : NT_BINDING_DELETED, &ev_bind);
1553  }
1554  }
1555 
1556  return MUTT_CMD_SUCCESS;
1557 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
#define _(a)
Definition: message.h:28
A key macro has been deleted.
Definition: keymap.h:149
Index panel (list of emails)
Definition: keymap.h:80
#define MUTT_UNMACRO
Definition: keymap.h:33
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
All key bindings are about to be deleted.
Definition: keymap.h:146
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:133
static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:504
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:43
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:44
All key macros are about to be deleted.
Definition: keymap.h:150
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition: keymap.h:132
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:394
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
A key binding has been deleted.
Definition: keymap.h:145
Success: Command worked.
Definition: mutt_commands.h:38
static void * parse_menu(bool *menu, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1437
Text entry area.
Definition: keymap.h:77
A key binding Event.
Definition: keymap.h:130
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
static void km_unbind_all(struct KeymapList *km_list, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1466
Generic selection list.
Definition: keymap.h:79
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
+ Here is the call 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 149 of file keymap.c.

◆ LastKey

int LastKey

Last real key pressed, recorded by dokey()

Last real key pressed, recorded by dokey()

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

◆ Menus

const struct Mapping Menus[]

Menu name lookup table.

Definition at line 61 of file keymap.c.