NeoMutt  2020-06-26-89-g172cd3
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...
 

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

Functions

void init_extended_keys (void)
 Initialise map of ncurses extended keys. More...
 
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 KeymapKeymaps []
 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 70 of file keymap.h.

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

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

941 {
942 #ifdef NCURSES_VERSION
943  use_extended_names(true);
944 
945  for (int j = 0; KeyNames[j].name; j++)
946  {
947  if (KeyNames[j].value == -1)
948  {
949  const char *keyname = find_ext_name(KeyNames[j].name);
950 
951  if (keyname)
952  {
953  char *s = tigetstr((char *) keyname);
954  if (s && ((long) (s) != -1))
955  {
956  int code = key_defined(s);
957  if (code > 0)
958  KeyNames[j].value = code;
959  }
960  }
961  }
962  }
963 #endif
964 }
int value
Definition: mapping.h:34
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:

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

872 {
873  if (!map)
874  return 0;
875 
876  int p = 0;
877 
878  while (true)
879  {
880  mutt_str_copy(s, km_keyname(map->keys[p]), len);
881  const size_t l = mutt_str_len(s);
882  len -= l;
883 
884  if ((++p >= map->len) || !len)
885  return 1;
886 
887  s += l;
888  }
889 
890  /* not reached */
891 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:790
keycode_t * keys
key sequence
Definition: keymap.h:55
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:636
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:721
+ 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 899 of file keymap.c.

900 {
901  struct Keymap *map = Keymaps[menu];
902 
903  for (; map; map = map->next)
904  if (map->op == func)
905  break;
906  return map;
907 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
short op
operation to perform
Definition: keymap.h:52
struct Keymap * next
next key in map
Definition: keymap.h:51
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 969 of file keymap.c.

970 {
971  memset(Keymaps, 0, sizeof(struct Keymap *) * MENU_MAX);
972 
981 
984 
987 
988 #ifdef CRYPT_BACKEND_GPGME
991 #endif
992 
993 #ifdef MIXMASTER
995 
996  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
997  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
998  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
999 #endif
1000 
1001 #ifdef USE_AUTOCRYPT
1003 #endif
1004 
1005  /* bindings for the line editor */
1007 
1008  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
1009  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
1010  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
1011  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
1012  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
1013  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
1014  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1015  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
1016  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1017 
1018  /* generic menu keymap */
1020 
1021  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
1022  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
1023  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
1024  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
1025  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
1026  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
1027  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
1028  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
1029  km_bindkey("1", MENU_GENERIC, OP_JUMP);
1030  km_bindkey("2", MENU_GENERIC, OP_JUMP);
1031  km_bindkey("3", MENU_GENERIC, OP_JUMP);
1032  km_bindkey("4", MENU_GENERIC, OP_JUMP);
1033  km_bindkey("5", MENU_GENERIC, OP_JUMP);
1034  km_bindkey("6", MENU_GENERIC, OP_JUMP);
1035  km_bindkey("7", MENU_GENERIC, OP_JUMP);
1036  km_bindkey("8", MENU_GENERIC, OP_JUMP);
1037  km_bindkey("9", MENU_GENERIC, OP_JUMP);
1038 
1039  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1040  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1041 
1042  /* Miscellaneous extra bindings */
1043 
1044  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1045  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1046  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1047  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1048  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1049  km_bindkey("x", MENU_MAIN, OP_EXIT);
1050 
1051  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1052  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1053 
1054  km_bindkey("x", MENU_PAGER, OP_EXIT);
1055  km_bindkey("i", MENU_PAGER, OP_EXIT);
1056  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1057  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1058  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1059  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1060  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1061  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1062  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1063  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1064  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1065  km_bindkey("1", MENU_PAGER, OP_JUMP);
1066  km_bindkey("2", MENU_PAGER, OP_JUMP);
1067  km_bindkey("3", MENU_PAGER, OP_JUMP);
1068  km_bindkey("4", MENU_PAGER, OP_JUMP);
1069  km_bindkey("5", MENU_PAGER, OP_JUMP);
1070  km_bindkey("6", MENU_PAGER, OP_JUMP);
1071  km_bindkey("7", MENU_PAGER, OP_JUMP);
1072  km_bindkey("8", MENU_PAGER, OP_JUMP);
1073  km_bindkey("9", MENU_PAGER, OP_JUMP);
1074 
1075  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1076  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1077 
1078  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1079  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1080  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1081 
1082  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1083  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1084  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1085  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1086 
1087  /* edit-to (default "t") hides generic tag-entry in Compose menu
1088  * This will bind tag-entry to "T" in the Compose menu */
1089  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1090 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:264
PGP encryption menu.
Definition: keymap.h:82
#define WithCrypto
Definition: lib.h:118
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:640
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
General file/mailbox browser.
Definition: keymap.h:76
Autocrypt Account menu.
Definition: keymap.h:92
Compose an email.
Definition: keymap.h:74
Index panel (list of emails)
Definition: keymap.h:78
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:649
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:466
SMIME encryption menu.
Definition: keymap.h:83
Pager pager (email viewer)
Definition: keymap.h:79
Select from results of external query.
Definition: keymap.h:81
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:661
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:55
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:93
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:92
Select an attachment.
Definition: keymap.h:73
Select a PGP key.
Definition: keymap.h:85
static void create_bindings(const struct Binding *map, enum MenuType menu)
Attach a set of keybindings to a Menu.
Definition: keymap.c:776
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:72
A keyboard mapping.
Definition: keymap.h:47
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:608
Create/edit a Mixmaster chain.
Definition: keymap.h:89
Select a SMIME key.
Definition: keymap.h:86
Text entry area.
Definition: keymap.h:75
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:104
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:677
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:544
Select a postponed email.
Definition: keymap.h:80
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:420
Generic selection list.
Definition: keymap.h:77
+ 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 1096 of file keymap.c.

1097 {
1098  char buf[128];
1099  int p, op;
1100 
1101  struct Keymap *key = km_find_func(menu, OP_HELP);
1102  if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER))
1103  key = km_find_func(MENU_GENERIC, OP_HELP);
1104  if (!key)
1105  {
1106  mutt_error(_("Key is not bound"));
1107  return;
1108  }
1109 
1110  /* Make sure the key is really the help key in this menu.
1111  *
1112  * OP_END_COND is used as a barrier to ensure nothing extra
1113  * is left in the unget buffer.
1114  *
1115  * Note that km_expand_key() + tokenize_unget_string() should
1116  * not be used here: control sequences are expanded to a form
1117  * (e.g. "^H") not recognized by km_dokey(). */
1118  mutt_unget_event(0, OP_END_COND);
1119  p = key->len;
1120  while (p--)
1121  mutt_unget_event(key->keys[p], 0);
1122 
1123  /* Note, e.g. for the index menu:
1124  * bind generic ? noop
1125  * bind generic ,a help
1126  * bind index ,ab quit
1127  * The index keybinding shadows the generic binding.
1128  * OP_END_COND will be read and returned as the op.
1129  *
1130  * bind generic ? noop
1131  * bind generic dq help
1132  * bind index d delete-message
1133  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1134  * in the unget buffer.
1135  */
1136  op = km_dokey(menu);
1137  if (op != OP_END_COND)
1139  if (op != OP_HELP)
1140  {
1141  mutt_error(_("Key is not bound"));
1142  return;
1143  }
1144 
1145  km_expand_key(buf, sizeof(buf), key);
1146  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1147 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:620
keycode_t * keys
key sequence
Definition: keymap.h:55
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:831
#define _(a)
Definition: message.h:28
Pager pager (email viewer)
Definition: keymap.h:79
short op
operation to perform
Definition: keymap.h:52
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function&#39;s mapping in a Menu.
Definition: keymap.c:899
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:871
A keyboard mapping.
Definition: keymap.h:47
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
#define mutt_error(...)
Definition: logging.h:84
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: curs_lib.c:904
Text entry area.
Definition: keymap.h:75
Generic selection list.
Definition: keymap.h:77
+ 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 1622 of file keymap.c.

1623 {
1624  int ch;
1625 
1626  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (%s to abort): "),
1627  km_keyname(AbortKey));
1628  do
1629  {
1630  ch = getch();
1631  if ((ch != ERR) && (ch != AbortKey))
1632  {
1633  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1634  }
1635  } while (ch != ERR && ch != AbortKey);
1636 
1637  mutt_flushinp();
1638  mutt_clear_error();
1639 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:790
#define mutt_message(...)
Definition: logging.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:916
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
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:395
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:46
+ 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 826 of file keymap.c.

827 {
828  keycode_t buf[2];
829  size_t len = parsekeys(C_AbortKey, buf, mutt_array_size(buf));
830  if (len == 0)
831  {
832  mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
833  AbortKey = ctrl('G');
834  return;
835  }
836  if (len > 1)
837  {
838  mutt_warning(
839  _("Specified abort key sequence (%s) will be truncated to first key"), C_AbortKey);
840  }
841  AbortKey = buf[0];
842 }
#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:85
#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:270
#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:54
#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 847 of file keymap.c.

848 {
849  if (!nc->event_data)
850  return -1;
851  if (nc->event_type != NT_CONFIG)
852  return 0;
853 
854  struct EventConfig *ec = nc->event_data;
855 
856  if (!mutt_str_equal(ec->name, "abort_key"))
857  return 0;
858 
860  return 0;
861 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
A config-change event.
Definition: subset.h:70
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:41
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: keymap.c:826
void * event_data
Data from notify_send()
Definition: observer.h:43
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:36
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 440 of file keymap.c.

441 {
442  return km_bind_err(s, menu, op, macro, desc, NULL);
443 }
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:335
+ 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 620 of file keymap.c.

621 {
622  struct KeyEvent tmp;
623  struct Keymap *map = Keymaps[menu];
624  int pos = 0;
625  int n = 0;
626 
627  if (!map && (menu != MENU_EDITOR))
628  return retry_generic(menu, NULL, 0, 0);
629 
630  while (true)
631  {
632  int i = (C_Timeout > 0) ? C_Timeout : 60;
633 #ifdef USE_IMAP
634  /* keepalive may need to run more frequently than C_Timeout allows */
635  if (C_ImapKeepalive)
636  {
637  if (C_ImapKeepalive >= i)
638  imap_keepalive();
639  else
640  {
641  while (C_ImapKeepalive && (C_ImapKeepalive < i))
642  {
644  tmp = mutt_getch();
645  mutt_getch_timeout(-1);
646  /* If a timeout was not received, or the window was resized, exit the
647  * loop now. Otherwise, continue to loop until reaching a total of
648  * $timeout seconds. */
649  if ((tmp.ch != -2) || SigWinch)
650  goto gotkey;
651 #ifdef USE_INOTIFY
653  goto gotkey;
654 #endif
655  i -= C_ImapKeepalive;
656  imap_keepalive();
657  }
658  }
659  }
660 #endif
661 
662  mutt_getch_timeout(i * 1000);
663  tmp = mutt_getch();
664  mutt_getch_timeout(-1);
665 
666 #ifdef USE_IMAP
667  gotkey:
668 #endif
669  /* hide timeouts, but not window resizes, from the line editor. */
670  if ((menu == MENU_EDITOR) && (tmp.ch == -2) && !SigWinch)
671  continue;
672 
673  LastKey = tmp.ch;
674  if (LastKey < 0)
675  return LastKey;
676 
677  /* do we have an op already? */
678  if (tmp.op)
679  {
680  const char *func = NULL;
681  const struct Binding *bindings = NULL;
682 
683  /* is this a valid op for this menu? */
684  if ((bindings = km_get_table(menu)) && (func = mutt_get_func(bindings, tmp.op)))
685  return tmp.op;
686 
687  if ((menu == MENU_EDITOR) && mutt_get_func(OpEditor, tmp.op))
688  return tmp.op;
689 
690  if ((menu != MENU_EDITOR) && (menu != MENU_PAGER))
691  {
692  /* check generic menu */
693  bindings = OpGeneric;
694  func = mutt_get_func(bindings, tmp.op);
695  if (func)
696  return tmp.op;
697  }
698 
699  /* Sigh. Valid function but not in this context.
700  * Find the literal string and push it back */
701  for (i = 0; Menus[i].name; i++)
702  {
703  bindings = km_get_table(Menus[i].value);
704  if (bindings)
705  {
706  func = mutt_get_func(bindings, tmp.op);
707  if (func)
708  {
709  mutt_unget_event('>', 0);
710  mutt_unget_string(func);
711  mutt_unget_event('<', 0);
712  break;
713  }
714  }
715  }
716  /* continue to chew */
717  if (func)
718  continue;
719  }
720 
721  if (!map)
722  return tmp.op;
723 
724  /* Nope. Business as usual */
725  while (LastKey > map->keys[pos])
726  {
727  if ((pos > map->eq) || !map->next)
728  return retry_generic(menu, map->keys, pos, LastKey);
729  map = map->next;
730  }
731 
732  if (LastKey != map->keys[pos])
733  return retry_generic(menu, map->keys, pos, LastKey);
734 
735  if (++pos == map->len)
736  {
737  if (map->op != OP_MACRO)
738  return map->op;
739 
740  /* OptIgnoreMacroEvents turns off processing the MacroEvents buffer
741  * in mutt_getch(). Generating new macro events during that time would
742  * result in undesired behavior once the option is turned off.
743  *
744  * Originally this returned -1, however that results in an unbuffered
745  * username or password prompt being aborted. Returning OP_NULL allows
746  * mutt_enter_string_full() to display the keybinding pressed instead.
747  *
748  * It may be unexpected for a macro's keybinding to be returned,
749  * but less so than aborting the prompt. */
751  {
752  return OP_NULL;
753  }
754 
755  if (n++ == 10)
756  {
757  mutt_flushinp();
758  mutt_error(_("Macro loop detected"));
759  return -1;
760  }
761 
763  map = Keymaps[menu];
764  pos = 0;
765  }
766  }
767 
768  /* not reached */
769 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:53
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: mutt_globals.h:118
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:868
int op
function id number
Definition: keymap.h:121
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:1081
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:916
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
keycode_t * keys
key sequence
Definition: keymap.h:55
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:831
#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:79
const char * mutt_get_func(const struct Binding *bindings, int op)
Get the name of a function.
Definition: keymap.c:501
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:55
int LastKey
contains the last key the user pressed
Definition: keymap.c:146
short op
operation to perform
Definition: keymap.h:52
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
struct Keymap * next
next key in map
Definition: keymap.h:51
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:521
An event such as a keypress.
Definition: keymap.h:61
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:187
A keyboard mapping.
Definition: keymap.h:47
short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
Definition: config.c:46
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
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:594
int n
Definition: acutest.h:492
#define mutt_error(...)
Definition: logging.h:84
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:144
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:608
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1265
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:850
Text entry area.
Definition: keymap.h:75
const char * name
Definition: mapping.h:33
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:76
Mapping between a user key and a function.
Definition: keymap.h:118
+ 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 1265 of file keymap.c.

1266 {
1267  switch (menu)
1268  {
1269  case MENU_ALIAS:
1270  return OpAlias;
1271  case MENU_ATTACH:
1272  return OpAttach;
1273 #ifdef USE_AUTOCRYPT
1274  case MENU_AUTOCRYPT_ACCT:
1275  return OpAutocryptAcct;
1276 #endif
1277  case MENU_COMPOSE:
1278  return OpCompose;
1279  case MENU_EDITOR:
1280  return OpEditor;
1281  case MENU_FOLDER:
1282  return OpBrowser;
1283  case MENU_GENERIC:
1284  return OpGeneric;
1285 #ifdef CRYPT_BACKEND_GPGME
1286  case MENU_KEY_SELECT_PGP:
1287  return OpPgp;
1288  case MENU_KEY_SELECT_SMIME:
1289  return OpSmime;
1290 #endif
1291  case MENU_MAIN:
1292  return OpMain;
1293 #ifdef MIXMASTER
1294  case MENU_MIX:
1295  return OpMix;
1296 #endif
1297  case MENU_PAGER:
1298  return OpPager;
1299  case MENU_PGP:
1300  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1301  case MENU_POSTPONE:
1302  return OpPost;
1303  case MENU_QUERY:
1304  return OpQuery;
1305  default:
1306  return NULL;
1307  }
1308 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:264
PGP encryption menu.
Definition: keymap.h:82
#define WithCrypto
Definition: lib.h:118
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:640
General file/mailbox browser.
Definition: keymap.h:76
Autocrypt Account menu.
Definition: keymap.h:92
Compose an email.
Definition: keymap.h:74
Index panel (list of emails)
Definition: keymap.h:78
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:649
Pager pager (email viewer)
Definition: keymap.h:79
Select from results of external query.
Definition: keymap.h:81
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:661
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:55
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:92
Select an attachment.
Definition: keymap.h:73
Select a PGP key.
Definition: keymap.h:85
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:72
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:608
Create/edit a Mixmaster chain.
Definition: keymap.h:89
Select a SMIME key.
Definition: keymap.h:86
Text entry area.
Definition: keymap.h:75
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:104
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:677
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:544
Select a postponed email.
Definition: keymap.h:80
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:420
Generic selection list.
Definition: keymap.h:77
+ 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 501 of file keymap.c.

502 {
503  for (int i = 0; bindings[i].name; i++)
504  {
505  if (bindings[i].op == op)
506  return bindings[i].name;
507  }
508 
509  return NULL;
510 }
int op
function id number
Definition: keymap.h:121
const char * name
name of the function
Definition: keymap.h:120
+ Here is the caller graph for this function:

◆ mutt_keys_free()

void mutt_keys_free ( void  )

Free the key maps.

Definition at line 1644 of file keymap.c.

1645 {
1646  struct Keymap *map = NULL;
1647  struct Keymap *next = NULL;
1648 
1649  for (int i = 0; i < MENU_MAX; i++)
1650  {
1651  for (map = Keymaps[i]; map; map = next)
1652  {
1653  next = map->next;
1654 
1655  FREE(&map->macro);
1656  FREE(&map->desc);
1657  FREE(&map->keys);
1658  FREE(&map);
1659  }
1660 
1661  Keymaps[i] = NULL;
1662  }
1663 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
keycode_t * keys
key sequence
Definition: keymap.h:55
struct Keymap * next
next key in map
Definition: keymap.h:51
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:49
char * desc
description of a macro for the help menu
Definition: keymap.h:50
A keyboard mapping.
Definition: keymap.h:47
#define FREE(x)
Definition: memory.h:40
+ 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 1315 of file keymap.c.

1317 {
1318  const struct Binding *bindings = NULL;
1319  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1320  int num_menus = 0;
1321  enum CommandResult rc = MUTT_CMD_SUCCESS;
1322 
1323  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true);
1324  if (!key)
1325  return MUTT_CMD_ERROR;
1326 
1327  /* function to execute */
1329  if (MoreArgs(s))
1330  {
1331  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1332  rc = MUTT_CMD_ERROR;
1333  }
1334  else if (mutt_istr_equal("noop", buf->data))
1335  {
1336  for (int i = 0; i < num_menus; i++)
1337  {
1338  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1339  }
1340  }
1341  else
1342  {
1343  for (int i = 0; i < num_menus; i++)
1344  {
1345  /* The pager and editor menus don't use the generic map,
1346  * however for other menus try generic first. */
1347  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1348  {
1349  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1350  if (rc == 0)
1351  continue;
1352  if (rc == -2)
1353  break;
1354  }
1355 
1356  /* Clear any error message, we're going to try again */
1357  err->data[0] = '\0';
1358  bindings = km_get_table(menu[i]);
1359  if (bindings)
1360  {
1361  rc = try_bind(key, menu[i], buf->data, bindings, err);
1362  }
1363  }
1364  }
1365  FREE(&key);
1366  return rc;
1367 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
MenuType
Types of GUI selections.
Definition: keymap.h:70
#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:1180
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#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:466
Pager pager (email viewer)
Definition: keymap.h:79
#define MoreArgs(buf)
Definition: buffer.h:43
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:55
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:888
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:422
char * data
Pointer to data.
Definition: buffer.h:35
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:1242
Success: Command worked.
Definition: mutt_commands.h:37
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1265
#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:75
Mapping between a user key and a function.
Definition: keymap.h:118
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
Generic selection list.
Definition: keymap.h:77
+ 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 1575 of file keymap.c.

1577 {
1578  int ops[128];
1579  int nops = 0;
1580  const struct Binding *bindings = NULL;
1581  char *function = NULL;
1582 
1583  if (!MoreArgs(s))
1584  {
1585  mutt_buffer_strcpy(err, _("exec: no arguments"));
1586  return MUTT_CMD_ERROR;
1587  }
1588 
1589  do
1590  {
1592  function = buf->data;
1593 
1594  bindings = km_get_table(CurrentMenu);
1595  if (!bindings && (CurrentMenu != MENU_PAGER))
1596  bindings = OpGeneric;
1597 
1598  ops[nops] = get_op(bindings, function, mutt_str_len(function));
1599  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1600  ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
1601 
1602  if (ops[nops] == OP_NULL)
1603  {
1604  mutt_flushinp();
1605  mutt_error(_("%s: no such function"), function);
1606  return MUTT_CMD_ERROR;
1607  }
1608  nops++;
1609  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1610 
1611  while (nops)
1612  mutt_push_macro_event(0, ops[--nops]);
1613 
1614  return MUTT_CMD_SUCCESS;
1615 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:868
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:916
#define _(a)
Definition: message.h:28
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h:79
#define MoreArgs(buf)
Definition: buffer.h:43
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: mutt_globals.h:78
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:55
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:422
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:636
Success: Command worked.
Definition: mutt_commands.h:37
#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:1265
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:478
Mapping between a user key and a function.
Definition: keymap.h:118
#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 1521 of file keymap.c.

1523 {
1524  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1525  int num_menus = 0;
1526  enum CommandResult rc = MUTT_CMD_ERROR;
1527  char *seq = NULL;
1528 
1529  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false);
1530  if (!key)
1531  return MUTT_CMD_ERROR;
1532 
1534  /* make sure the macro sequence is not an empty string */
1535  if (buf->data[0] == '\0')
1536  {
1537  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1538  }
1539  else
1540  {
1541  if (MoreArgs(s))
1542  {
1543  seq = mutt_str_dup(buf->data);
1545 
1546  if (MoreArgs(s))
1547  {
1548  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1549  }
1550  else
1551  {
1552  for (int i = 0; i < num_menus; i++)
1553  {
1554  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1555  }
1556  }
1557 
1558  FREE(&seq);
1559  }
1560  else
1561  {
1562  for (int i = 0; i < num_menus; i++)
1563  {
1564  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1565  }
1566  }
1567  }
1568  FREE(&key);
1569  return rc;
1570 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
MenuType
Types of GUI selections.
Definition: keymap.h:70
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
#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:1180
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define mutt_array_size(x)
Definition: memory.h:33
#define MoreArgs(buf)
Definition: buffer.h:43
#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:422
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
const char * seq
default key binding
Definition: keymap.h:122
#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:440
+ 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 1152 of file keymap.c.

1154 {
1156  if (MoreArgs(s))
1157  {
1158  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1159  return MUTT_CMD_ERROR;
1160  }
1161 
1163  return MUTT_CMD_SUCCESS;
1164 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:868
#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:422
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:521
Success: Command worked.
Definition: mutt_commands.h:37
+ 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 1456 of file keymap.c.

1458 {
1459  bool menu[MENU_MAX] = { 0 };
1460  bool all_keys = false;
1461  char *key = NULL;
1462 
1464  if (mutt_str_equal(buf->data, "*"))
1465  {
1466  for (enum MenuType i = 0; i < MENU_MAX; i++)
1467  menu[i] = true;
1468  }
1469  else
1470  parse_menu(menu, buf->data, err);
1471 
1472  if (MoreArgs(s))
1473  {
1475  key = buf->data;
1476  }
1477  else
1478  all_keys = true;
1479 
1480  if (MoreArgs(s))
1481  {
1482  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1483 
1484  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1485  return MUTT_CMD_ERROR;
1486  }
1487 
1488  for (enum MenuType i = 0; i < MENU_MAX; i++)
1489  {
1490  if (!menu[i])
1491  continue;
1492  if (all_keys)
1493  {
1494  km_unbind_all(&Keymaps[i], data);
1495  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1496  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1497  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1498  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1499  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1500  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1501  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1502  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1503  if (i != MENU_EDITOR)
1504  {
1505  km_bindkey("?", i, OP_HELP);
1506  km_bindkey("q", i, OP_EXIT);
1507  }
1508  }
1509  else
1510  km_bindkey(key, i, OP_NULL);
1511  }
1512 
1513  return MUTT_CMD_SUCCESS;
1514 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
MenuType
Types of GUI selections.
Definition: keymap.h:70
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
#define _(a)
Definition: message.h:28
static void km_unbind_all(struct Keymap **map, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1406
Index panel (list of emails)
Definition: keymap.h:78
#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
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:466
Pager pager (email viewer)
Definition: keymap.h:79
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:422
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
static void * parse_menu(bool *menu, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1377
Text entry area.
Definition: keymap.h:75
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
Generic selection list.
Definition: keymap.h:77
+ 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 Keymap* 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.