NeoMutt  2021-02-05-329-g9e03b7
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 991 of file keymap.c.

992 {
993 #ifdef NCURSES_VERSION
994  use_extended_names(true);
995 
996  for (int j = 0; KeyNames[j].name; j++)
997  {
998  if (KeyNames[j].value == -1)
999  {
1000  const char *keyname = find_ext_name(KeyNames[j].name);
1001 
1002  if (keyname)
1003  {
1004  char *s = tigetstr((char *) keyname);
1005  if (s && ((long) (s) != -1))
1006  {
1007  int code = key_defined(s);
1008  if (code > 0)
1009  KeyNames[j].value = code;
1010  }
1011  }
1012  }
1013  }
1014 #endif
1015 }
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:90
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 921 of file keymap.c.

922 {
923  if (!map)
924  return 0;
925 
926  int p = 0;
927 
928  while (true)
929  {
930  mutt_str_copy(s, km_keyname(map->keys[p]), len);
931  const size_t l = mutt_str_len(s);
932  len -= l;
933 
934  if ((++p >= map->len) || !len)
935  return 1;
936 
937  s += l;
938  }
939 
940  /* not reached */
941 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:839
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 949 of file keymap.c.

950 {
951  struct Keymap *np = NULL;
952  STAILQ_FOREACH(np, &Keymaps[menu], entries)
953  {
954  if (np->op == func)
955  break;
956  }
957  return np;
958 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
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 1020 of file keymap.c.

1021 {
1022  memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
1023 
1032 
1035 
1038 
1039 #ifdef CRYPT_BACKEND_GPGME
1042 #endif
1043 
1044 #ifdef MIXMASTER
1046 
1047  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
1048  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
1049  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
1050 #endif
1051 
1052 #ifdef USE_AUTOCRYPT
1054 #endif
1055 
1056  /* bindings for the line editor */
1058 
1059  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
1060  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
1061  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
1062  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
1063  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
1064  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
1065  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1066  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
1067  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1068 
1069  /* generic menu keymap */
1071 
1072  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
1073  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
1074  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
1075  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
1076  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
1077  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
1078  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
1079  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
1080  km_bindkey("1", MENU_GENERIC, OP_JUMP);
1081  km_bindkey("2", MENU_GENERIC, OP_JUMP);
1082  km_bindkey("3", MENU_GENERIC, OP_JUMP);
1083  km_bindkey("4", MENU_GENERIC, OP_JUMP);
1084  km_bindkey("5", MENU_GENERIC, OP_JUMP);
1085  km_bindkey("6", MENU_GENERIC, OP_JUMP);
1086  km_bindkey("7", MENU_GENERIC, OP_JUMP);
1087  km_bindkey("8", MENU_GENERIC, OP_JUMP);
1088  km_bindkey("9", MENU_GENERIC, OP_JUMP);
1089 
1090  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1091  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1092 
1093  /* Miscellaneous extra bindings */
1094 
1095  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1096  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1097  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1098  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1099  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1100  km_bindkey("x", MENU_MAIN, OP_EXIT);
1101 
1102  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1103  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1104 
1105  km_bindkey("x", MENU_PAGER, OP_EXIT);
1106  km_bindkey("i", MENU_PAGER, OP_EXIT);
1107  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1108  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1109  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1110  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1111  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1112  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1113  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1114  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1115  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1116  km_bindkey("1", MENU_PAGER, OP_JUMP);
1117  km_bindkey("2", MENU_PAGER, OP_JUMP);
1118  km_bindkey("3", MENU_PAGER, OP_JUMP);
1119  km_bindkey("4", MENU_PAGER, OP_JUMP);
1120  km_bindkey("5", MENU_PAGER, OP_JUMP);
1121  km_bindkey("6", MENU_PAGER, OP_JUMP);
1122  km_bindkey("7", MENU_PAGER, OP_JUMP);
1123  km_bindkey("8", MENU_PAGER, OP_JUMP);
1124  km_bindkey("9", MENU_PAGER, OP_JUMP);
1125 
1126  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1127  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1128 
1129  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1130  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1131  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1132 
1133  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1134  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1135  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1136  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1137 
1138  /* edit-to (default "t") hides generic tag-entry in Compose menu
1139  * This will bind tag-entry to "T" in the Compose menu */
1140  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1141 }
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:113
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:646
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
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:456
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:655
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:507
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:667
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:535
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:526
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
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:823
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:600
Select an email address by its alias.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:614
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:683
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:547
Select a postponed email.
Definition: keymap.h:82
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:419
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 1147 of file keymap.c.

1148 {
1149  char buf[128];
1150  int p, op;
1151 
1152  struct Keymap *key = km_find_func(menu, OP_HELP);
1153  if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER))
1154  key = km_find_func(MENU_GENERIC, OP_HELP);
1155  if (!key)
1156  {
1157  mutt_error(_("Key is not bound"));
1158  return;
1159  }
1160 
1161  /* Make sure the key is really the help key in this menu.
1162  *
1163  * OP_END_COND is used as a barrier to ensure nothing extra
1164  * is left in the unget buffer.
1165  *
1166  * Note that km_expand_key() + tokenize_unget_string() should
1167  * not be used here: control sequences are expanded to a form
1168  * (e.g. "^H") not recognized by km_dokey(). */
1169  mutt_unget_event(0, OP_END_COND);
1170  p = key->len;
1171  while (p--)
1172  mutt_unget_event(key->keys[p], 0);
1173 
1174  /* Note, e.g. for the index menu:
1175  * bind generic ? noop
1176  * bind generic ,a help
1177  * bind index ,ab quit
1178  * The index keybinding shadows the generic binding.
1179  * OP_END_COND will be read and returned as the op.
1180  *
1181  * bind generic ? noop
1182  * bind generic dq help
1183  * bind index d delete-message
1184  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1185  * in the unget buffer.
1186  */
1187  op = km_dokey(menu);
1188  if (op != OP_END_COND)
1190  if (op != OP_HELP)
1191  {
1192  mutt_error(_("Key is not bound"));
1193  return;
1194  }
1195 
1196  km_expand_key(buf, sizeof(buf), key);
1197  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1198 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:661
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:725
#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:949
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:921
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:798
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 1687 of file keymap.c.

1688 {
1689  int ch;
1690 
1691  mutt_window_mvprintw(MessageWindow, 0, 0, _("Enter keys (%s to abort): "),
1692  km_keyname(AbortKey));
1693  do
1694  {
1695  ch = getch();
1696  if ((ch != ERR) && (ch != AbortKey))
1697  {
1698  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1699  }
1700  } while (ch != ERR && ch != AbortKey);
1701 
1702  mutt_flushinp();
1703  mutt_clear_error();
1704 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:839
#define mutt_message(...)
Definition: logging.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:810
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:112
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:45
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:150
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:415
+ 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 875 of file keymap.c.

876 {
877  keycode_t buf[2];
878  const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
879  size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
880  if (len == 0)
881  {
882  mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
883  AbortKey = ctrl('G');
884  return;
885  }
886  if (len > 1)
887  {
888  mutt_warning(
889  _("Specified abort key sequence (%s) will be truncated to first key"), c_abort_key);
890  }
891  AbortKey = buf[0];
892 }
#define mutt_warning(...)
Definition: logging.h:82
#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:302
#define ctrl(ch)
Definition: mutt_curses.h:66
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:295
short keycode_t
Definition: keymap.h:38
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:150
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
#define mutt_error(...)
Definition: logging.h:84
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:

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

898 {
899  if (!nc->event_data)
900  return -1;
901  if (nc->event_type != NT_CONFIG)
902  return 0;
903 
904  struct EventConfig *ec = nc->event_data;
905 
906  if (!mutt_str_equal(ec->name, "abort_key"))
907  return 0;
908 
910  return 0;
911 }
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:875
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:41
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 481 of file keymap.c.

482 {
483  return km_bind_err(s, menu, op, macro, desc, NULL);
484 }
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:389
+ 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 661 of file keymap.c.

662 {
663  struct KeyEvent tmp;
664  struct Keymap *map = STAILQ_FIRST(&Keymaps[menu]);
665  int pos = 0;
666  int n = 0;
667 
668  if (!map && (menu != MENU_EDITOR))
669  return retry_generic(menu, NULL, 0, 0);
670 
671 #ifdef USE_IMAP
672  const short c_imap_keepalive =
673  cs_subset_number(NeoMutt->sub, "imap_keepalive");
674 #endif
675 
676  while (true)
677  {
678  const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
679  int i = (c_timeout > 0) ? c_timeout : 60;
680 #ifdef USE_IMAP
681  /* keepalive may need to run more frequently than `$timeout` allows */
682  if (c_imap_keepalive)
683  {
684  if (c_imap_keepalive >= i)
685  imap_keepalive();
686  else
687  {
688  while (c_imap_keepalive && (c_imap_keepalive < i))
689  {
690  mutt_getch_timeout(c_imap_keepalive * 1000);
691  tmp = mutt_getch();
692  mutt_getch_timeout(-1);
693  /* If a timeout was not received, or the window was resized, exit the
694  * loop now. Otherwise, continue to loop until reaching a total of
695  * $timeout seconds. */
696  if ((tmp.ch != -2) || SigWinch)
697  goto gotkey;
698 #ifdef USE_INOTIFY
700  goto gotkey;
701 #endif
702  i -= c_imap_keepalive;
703  imap_keepalive();
704  }
705  }
706  }
707 #endif
708 
709  mutt_getch_timeout(i * 1000);
710  tmp = mutt_getch();
711  mutt_getch_timeout(-1);
712 
713 #ifdef USE_IMAP
714  gotkey:
715 #endif
716  /* hide timeouts, but not window resizes, from the line editor. */
717  if ((menu == MENU_EDITOR) && (tmp.ch == -2) && !SigWinch)
718  continue;
719 
720  LastKey = tmp.ch;
721  if (LastKey < 0)
722  return LastKey;
723 
724  /* do we have an op already? */
725  if (tmp.op)
726  {
727  const char *func = NULL;
728  const struct Binding *bindings = NULL;
729 
730  /* is this a valid op for this menu? */
731  if ((bindings = km_get_table(menu)) && (func = mutt_get_func(bindings, tmp.op)))
732  return tmp.op;
733 
734  if ((menu == MENU_EDITOR) && mutt_get_func(OpEditor, tmp.op))
735  return tmp.op;
736 
737  if ((menu != MENU_EDITOR) && (menu != MENU_PAGER))
738  {
739  /* check generic menu */
740  bindings = OpGeneric;
741  func = mutt_get_func(bindings, tmp.op);
742  if (func)
743  return tmp.op;
744  }
745 
746  /* Sigh. Valid function but not in this context.
747  * Find the literal string and push it back */
748  for (i = 0; Menus[i].name; i++)
749  {
750  bindings = km_get_table(Menus[i].value);
751  if (bindings)
752  {
753  func = mutt_get_func(bindings, tmp.op);
754  if (func)
755  {
756  mutt_unget_event('>', 0);
757  mutt_unget_string(func);
758  mutt_unget_event('<', 0);
759  break;
760  }
761  }
762  }
763  /* continue to chew */
764  if (func)
765  continue;
766  }
767 
768  if (!map)
769  return tmp.op;
770 
771  /* Nope. Business as usual */
772  while (LastKey > map->keys[pos])
773  {
774  if ((pos > map->eq) || !STAILQ_NEXT(map, entries))
775  return retry_generic(menu, map->keys, pos, LastKey);
776  map = STAILQ_NEXT(map, entries);
777  }
778 
779  if (LastKey != map->keys[pos])
780  return retry_generic(menu, map->keys, pos, LastKey);
781 
782  if (++pos == map->len)
783  {
784  if (map->op != OP_MACRO)
785  return map->op;
786 
787  /* OptIgnoreMacroEvents turns off processing the MacroEvents buffer
788  * in mutt_getch(). Generating new macro events during that time would
789  * result in undesired behavior once the option is turned off.
790  *
791  * Originally this returned -1, however that results in an unbuffered
792  * username or password prompt being aborted. Returning OP_NULL allows
793  * mutt_enter_string_full() to display the keybinding pressed instead.
794  *
795  * It may be unexpected for a macro's keybinding to be returned,
796  * but less so than aborting the prompt. */
798  {
799  return OP_NULL;
800  }
801 
802  if (n++ == 10)
803  {
804  mutt_flushinp();
805  mutt_error(_("Macro loop detected"));
806  return -1;
807  }
808 
810  map = STAILQ_FIRST(&Keymaps[menu]);
811  pos = 0;
812  }
813  }
814 
815  /* not reached */
816 }
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:152
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:762
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:948
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:810
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:725
#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:51
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:159
Container for Accounts, Notifications.
Definition: neomutt.h:36
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:542
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:149
short op
operation to perform
Definition: keymap.h:51
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
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:562
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:183
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
A keyboard mapping.
Definition: keymap.h: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:635
#define mutt_error(...)
Definition: logging.h:84
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:140
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:614
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1316
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:744
Text entry area.
Definition: keymap.h:77
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: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 1316 of file keymap.c.

1317 {
1318  switch (menu)
1319  {
1320  case MENU_ALIAS:
1321  return OpAlias;
1322  case MENU_ATTACH:
1323  return OpAttach;
1324 #ifdef USE_AUTOCRYPT
1325  case MENU_AUTOCRYPT_ACCT:
1326  return OpAutocryptAcct;
1327 #endif
1328  case MENU_COMPOSE:
1329  return OpCompose;
1330  case MENU_EDITOR:
1331  return OpEditor;
1332  case MENU_FOLDER:
1333  return OpBrowser;
1334  case MENU_GENERIC:
1335  return OpGeneric;
1336 #ifdef CRYPT_BACKEND_GPGME
1337  case MENU_KEY_SELECT_PGP:
1338  return OpPgp;
1339  case MENU_KEY_SELECT_SMIME:
1340  return OpSmime;
1341 #endif
1342  case MENU_MAIN:
1343  return OpMain;
1344 #ifdef MIXMASTER
1345  case MENU_MIX:
1346  return OpMix;
1347 #endif
1348  case MENU_PAGER:
1349  return OpPager;
1350  case MENU_PGP:
1351  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1352  case MENU_POSTPONE:
1353  return OpPost;
1354  case MENU_QUERY:
1355  return OpQuery;
1356  default:
1357  return NULL;
1358  }
1359 }
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:113
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:646
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:456
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:655
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:667
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:535
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:526
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
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:600
Select an email address by its alias.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:614
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:683
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:547
Select a postponed email.
Definition: keymap.h:82
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:419
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 542 of file keymap.c.

543 {
544  for (int i = 0; bindings[i].name; i++)
545  {
546  if (bindings[i].op == op)
547  return bindings[i].name;
548  }
549 
550  return NULL;
551 }
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 1709 of file keymap.c.

1710 {
1711  for (int i = 0; i < MENU_MAX; i++)
1712  {
1714  }
1715 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: keymap.c:220
+ 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 1366 of file keymap.c.

1368 {
1369  const struct Binding *bindings = NULL;
1370  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1371  int num_menus = 0;
1372  enum CommandResult rc = MUTT_CMD_SUCCESS;
1373 
1374  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true);
1375  if (!key)
1376  return MUTT_CMD_ERROR;
1377 
1378  /* function to execute */
1380  if (MoreArgs(s))
1381  {
1382  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1383  rc = MUTT_CMD_ERROR;
1384  }
1385  else if (mutt_istr_equal("noop", buf->data))
1386  {
1387  for (int i = 0; i < num_menus; i++)
1388  {
1389  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1390  bindings = km_get_table(menu[i]);
1391  if (bindings)
1392  {
1393  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1394  struct EventBinding ev_bind = { menu[i], key, op };
1396  }
1397  }
1398  }
1399  else
1400  {
1401  for (int i = 0; i < num_menus; i++)
1402  {
1403  /* The pager and editor menus don't use the generic map,
1404  * however for other menus try generic first. */
1405  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1406  {
1407  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1408  if (rc == MUTT_CMD_SUCCESS)
1409  {
1410  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1411  struct EventBinding ev_bind = { menu[i], key, op };
1413  continue;
1414  }
1415  if (rc == MUTT_CMD_WARNING)
1416  break;
1417  }
1418 
1419  /* Clear any error message, we're going to try again */
1420  err->data[0] = '\0';
1421  bindings = km_get_table(menu[i]);
1422  if (bindings)
1423  {
1424  rc = try_bind(key, menu[i], buf->data, bindings, err);
1425  if (rc == MUTT_CMD_SUCCESS)
1426  {
1427  int op = get_op(bindings, buf->data, mutt_str_len(buf->data));
1428  struct EventBinding ev_bind = { menu[i], key, op };
1430  continue;
1431  }
1432  }
1433  }
1434  }
1435  FREE(&key);
1436  return rc;
1437 }
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:1231
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:507
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:40
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
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:64
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
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:1293
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:1316
#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:519
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:66
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:156
+ 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 1639 of file keymap.c.

1641 {
1642  int ops[128];
1643  int nops = 0;
1644  const struct Binding *bindings = NULL;
1645  char *function = NULL;
1646 
1647  if (!MoreArgs(s))
1648  {
1649  mutt_buffer_strcpy(err, _("exec: no arguments"));
1650  return MUTT_CMD_ERROR;
1651  }
1652 
1653  do
1654  {
1656  function = buf->data;
1657 
1658  const enum MenuType mtype = menu_get_current_type();
1659  bindings = km_get_table(mtype);
1660  if (!bindings && (mtype != MENU_PAGER))
1661  bindings = OpGeneric;
1662 
1663  ops[nops] = get_op(bindings, function, mutt_str_len(function));
1664  if ((ops[nops] == OP_NULL) && (mtype != MENU_PAGER))
1665  ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
1666 
1667  if (ops[nops] == OP_NULL)
1668  {
1669  mutt_flushinp();
1670  mutt_error(_("%s: no such function"), function);
1671  return MUTT_CMD_ERROR;
1672  }
1673  nops++;
1674  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1675 
1676  while (nops)
1677  mutt_push_macro_event(0, ops[--nops]);
1678 
1679  return MUTT_CMD_SUCCESS;
1680 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:762
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:810
#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:40
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:395
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:1316
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:519
Mapping between a user key and a function.
Definition: keymap.h:120
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ 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 1574 of file keymap.c.

1576 {
1577  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1578  int num_menus = 0;
1579  enum CommandResult rc = MUTT_CMD_ERROR;
1580 
1581  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false);
1582  if (!key)
1583  return MUTT_CMD_ERROR;
1584 
1586  /* make sure the macro sequence is not an empty string */
1587  if (buf->data[0] == '\0')
1588  {
1589  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1590  }
1591  else
1592  {
1593  if (MoreArgs(s))
1594  {
1595  char *seq = mutt_str_dup(buf->data);
1597 
1598  if (MoreArgs(s))
1599  {
1600  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1601  }
1602  else
1603  {
1604  for (int i = 0; i < num_menus; i++)
1605  {
1606  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1607  if (rc == MUTT_CMD_SUCCESS)
1608  {
1609  struct EventBinding ev_bind = { menu[i], key, OP_MACRO };
1611  continue;
1612  }
1613  }
1614  }
1615 
1616  FREE(&seq);
1617  }
1618  else
1619  {
1620  for (int i = 0; i < num_menus; i++)
1621  {
1622  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1623  if (rc == MUTT_CMD_SUCCESS)
1624  {
1625  struct EventBinding ev_bind = { menu[i], key, OP_MACRO };
1627  continue;
1628  }
1629  }
1630  }
1631  }
1632  FREE(&key);
1633  return rc;
1634 }
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:1231
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:40
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:68
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
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:481
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:156
+ 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 1203 of file keymap.c.

1205 {
1207  if (MoreArgs(s))
1208  {
1209  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1210  return MUTT_CMD_ERROR;
1211  }
1212 
1214  return MUTT_CMD_SUCCESS;
1215 }
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:762
#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:40
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:68
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
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:562
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 1500 of file keymap.c.

1502 {
1503  bool menu[MENU_MAX] = { 0 };
1504  bool all_keys = false;
1505  char *key = NULL;
1506 
1508  if (mutt_str_equal(buf->data, "*"))
1509  {
1510  for (enum MenuType i = 0; i < MENU_MAX; i++)
1511  menu[i] = true;
1512  }
1513  else
1514  parse_menu(menu, buf->data, err);
1515 
1516  if (MoreArgs(s))
1517  {
1519  key = buf->data;
1520  }
1521  else
1522  all_keys = true;
1523 
1524  if (MoreArgs(s))
1525  {
1526  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1527 
1528  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1529  return MUTT_CMD_ERROR;
1530  }
1531 
1532  for (enum MenuType i = 0; i < MENU_MAX; i++)
1533  {
1534  if (!menu[i])
1535  continue;
1536  if (all_keys)
1537  {
1538  km_unbind_all(&Keymaps[i], data);
1539  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1540  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1541  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1542  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1543  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1544  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1545  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1546  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1547  if (i != MENU_EDITOR)
1548  {
1549  km_bindkey("?", i, OP_HELP);
1550  km_bindkey("q", i, OP_EXIT);
1551  }
1552  struct EventBinding ev_bind = { i, NULL, OP_NULL };
1555  &ev_bind);
1556  }
1557  else
1558  {
1559  km_bindkey(key, i, OP_NULL);
1560  struct EventBinding ev_bind = { i, key, OP_NULL };
1562  (data & MUTT_UNMACRO) ? NT_MACRO_DELETED : NT_BINDING_DELETED, &ev_bind);
1563  }
1564  }
1565 
1566  return MUTT_CMD_SUCCESS;
1567 }
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:152
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:507
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:40
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
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:395
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:1447
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:66
static void km_unbind_all(struct KeymapList *km_list, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1476
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:156
+ 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 152 of file keymap.c.

◆ LastKey

int LastKey

Last real key pressed, recorded by dokey()

Last real key pressed, recorded by dokey()

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

◆ Menus

const struct Mapping Menus[]

Menu name lookup table.

Definition at line 64 of file keymap.c.