NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
keymap.c File Reference

Manage keymappings. More...

#include "config.h"
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mutt/mutt.h"
#include "mutt.h"
#include "keymap.h"
#include "curs_lib.h"
#include "functions.h"
#include "globals.h"
#include "mutt_commands.h"
#include "mutt_curses.h"
#include "mutt_logging.h"
#include "mutt_window.h"
#include "ncrypt/ncrypt.h"
#include "opcodes.h"
#include "options.h"
#include <strings.h>
#include "imap/imap.h"
+ Include dependency graph for keymap.c:

Go to the source code of this file.

Functions

static struct Keymapalloc_keys (size_t len, keycode_t *keys)
 Allocate space for a sequence of keys. More...
 
static int parse_fkey (char *s)
 Parse a function key string. More...
 
static int parse_keycode (const char *s)
 Parse a numeric keycode. More...
 
static size_t parsekeys (const char *str, keycode_t *d, size_t max)
 Parse a key string into key codes. More...
 
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. More...
 
enum CommandResult km_bind (char *s, enum MenuType menu, int op, char *macro, char *desc)
 Bind a key to a macro. More...
 
static enum CommandResult km_bindkey_err (const char *s, enum MenuType menu, int op, struct Buffer *err)
 Bind a key in a Menu to an operation (with error message) More...
 
static enum CommandResult km_bindkey (const char *s, enum MenuType menu, int op)
 Bind a key in a Menu to an operation. More...
 
static int get_op (const struct Binding *bindings, const char *start, size_t len)
 Get the function by its name. More...
 
const char * mutt_get_func (const struct Binding *bindings, int op)
 Get the name of a function. More...
 
static void generic_tokenize_push_string (char *s, void(*generic_push)(int, int))
 Parse and queue a 'push' command. More...
 
static int retry_generic (enum MenuType menu, keycode_t *keys, int keyslen, int lastkey)
 Try to find the key in the generic menu bindings. More...
 
int km_dokey (enum MenuType menu)
 Determine what a keypress should do. More...
 
static void create_bindings (const struct Binding *map, enum MenuType menu)
 Attach a set of keybindings to a Menu. More...
 
static const char * km_keyname (int c)
 Get the human name for a key. 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 init_extended_keys (void)
 Initialise map of ncurses extended keys. More...
 
void km_init (void)
 Initialise all the menu keybindings. More...
 
void km_error_key (enum MenuType menu)
 Handle an unbound key sequence. More...
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'push' command - Implements command_t. More...
 
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. More...
 
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. More...
 
const struct Bindingkm_get_table (enum MenuType menu)
 Lookup a menu's keybindings. More...
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'bind' command - Implements command_t. More...
 
static void * parse_menu (bool *menu, char *s, struct Buffer *err)
 Parse menu-names into an array. More...
 
static void km_unbind_all (struct Keymap **map, unsigned long mode)
 Free all the keys in the supplied Keymap. More...
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unbind' command - Implements command_t. More...
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'macro' command - Implements command_t. More...
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'exec' command - Implements command_t. More...
 
void mutt_what_key (void)
 Ask the user to press a key. More...
 
void mutt_keys_free (void)
 Free the key maps. More...
 

Variables

const struct Mapping Menus []
 Menu name lookup table. More...
 
static struct Mapping KeyNames []
 Key name lookup table. More...
 
int LastKey
 contains the last key the user pressed More...
 
struct KeymapKeymaps [MENU_MAX]
 Array of Keymap keybindings, one for each Menu. 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.c.

Function Documentation

◆ alloc_keys()

static struct Keymap* alloc_keys ( size_t  len,
keycode_t keys 
)
static

Allocate space for a sequence of keys.

Parameters
lenNumber of keys
keysArray of keys
Return values
ptrSequence of keys

Definition at line 204 of file keymap.c.

205 {
206  struct Keymap *p = mutt_mem_calloc(1, sizeof(struct Keymap));
207  p->len = len;
208  p->keys = mutt_mem_malloc(len * sizeof(keycode_t));
209  memcpy(p->keys, keys, len * sizeof(keycode_t));
210  return p;
211 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
keycode_t * keys
key sequence
Definition: keymap.h:54
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
short keycode_t
Definition: keymap.h:37
A keyboard mapping.
Definition: keymap.h:46
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_fkey()

static int parse_fkey ( char *  s)
static

Parse a function key string.

Parameters
sString to parse
Return values
numNumber of the key

Given "<f8>", it will return 8.

Definition at line 220 of file keymap.c.

221 {
222  char *t = NULL;
223  int n = 0;
224 
225  if ((s[0] != '<') || (tolower(s[1]) != 'f'))
226  return -1;
227 
228  for (t = s + 2; *t && isdigit((unsigned char) *t); t++)
229  {
230  n *= 10;
231  n += *t - '0';
232  }
233 
234  if (*t != '>')
235  return -1;
236  return n;
237 }
+ Here is the caller graph for this function:

◆ parse_keycode()

static int parse_keycode ( const char *  s)
static

Parse a numeric keycode.

Parameters
sString to parse
Return values
numNumber of the key

This function parses the string <NNN> and uses the octal value as the key to bind.

Definition at line 247 of file keymap.c.

248 {
249  char *end_char = NULL;
250  long int result = strtol(s + 1, &end_char, 8);
251  /* allow trailing whitespace, eg. < 1001 > */
252  while (IS_SPACE(*end_char))
253  end_char++;
254  /* negative keycodes don't make sense, also detect overflow */
255  if ((*end_char != '>') || (result < 0) || (result == LONG_MAX))
256  {
257  return -1;
258  }
259 
260  return result;
261 }
#define IS_SPACE(ch)
Definition: string2.h:38
+ Here is the caller graph for this function:

◆ parsekeys()

static size_t parsekeys ( const char *  str,
keycode_t d,
size_t  max 
)
static

Parse a key string into key codes.

Parameters
strKey string
dArray for key codes
maxMaximum length of key sequence
Return values
numLength of key sequence

Definition at line 270 of file keymap.c.

271 {
272  int n;
273  size_t len = max;
274  char buf[128];
275  char c;
276  char *t = NULL;
277 
278  mutt_str_strfcpy(buf, str, sizeof(buf));
279  char *s = buf;
280 
281  while (*s && len)
282  {
283  *d = '\0';
284  if ((*s == '<') && (t = strchr(s, '>')))
285  {
286  t++;
287  c = *t;
288  *t = '\0';
289 
291  if (n != -1)
292  {
293  s = t;
294  *d = n;
295  }
296  else if ((n = parse_fkey(s)) > 0)
297  {
298  s = t;
299  *d = KEY_F(n);
300  }
301  else if ((n = parse_keycode(s)) > 0)
302  {
303  s = t;
304  *d = n;
305  }
306 
307  *t = c;
308  }
309 
310  if (!*d)
311  {
312  *d = (unsigned char) *s;
313  s++;
314  }
315  d++;
316  len--;
317  }
318 
319  return max - len;
320 }
static int parse_keycode(const char *s)
Parse a numeric keycode.
Definition: keymap.c:247
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:88
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:220
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_bind_err()

static enum CommandResult km_bind_err ( const char *  s,
enum MenuType  menu,
int  op,
char *  macro,
char *  desc,
struct Buffer err 
)
static

Set up a key binding.

Parameters
sKey string
menuMenu id, e.g. MENU_EDITOR
opOperation, e.g. OP_DELETE
macroMacro string
descDescription of macro (OPTIONAL)
errBuffer for error message
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Insert a key sequence into the specified map. The map is sorted by ASCII value (lowest to highest)

Definition at line 335 of file keymap.c.

337 {
339  struct Keymap *last = NULL, *next = NULL;
340  keycode_t buf[MAX_SEQ];
341  size_t pos = 0, lastpos = 0;
342 
343  size_t len = parsekeys(s, buf, MAX_SEQ);
344 
345  struct Keymap *map = alloc_keys(len, buf);
346  map->op = op;
347  map->macro = mutt_str_strdup(macro);
348  map->desc = mutt_str_strdup(desc);
349 
350  struct Keymap *tmp = Keymaps[menu];
351 
352  while (tmp)
353  {
354  if ((pos >= len) || (pos >= tmp->len))
355  {
356  /* map and tmp match so overwrite */
357  do
358  {
359  /* Don't warn on overwriting a 'noop' binding */
360  if ((tmp->len != len) && (tmp->op != OP_NULL))
361  {
362  /* Overwrite with the different lengths, warn */
363  /* TODO: MAX_SEQ here is wrong */
364  char old_binding[MAX_SEQ];
365  char new_binding[MAX_SEQ];
366  km_expand_key(old_binding, MAX_SEQ, map);
367  km_expand_key(new_binding, MAX_SEQ, tmp);
368  if (err)
369  {
370  /* err was passed, put the string there */
371  snprintf(
372  err->data, err->dsize,
373  _("Binding '%s' will alias '%s' Before, try: 'bind %s %s "
374  "noop' "
375  "https://neomutt.org/guide/configuration.html#bind-warnings"),
376  old_binding, new_binding, mutt_map_get_name(menu, Menus), new_binding);
377  }
378  else
379  {
380  mutt_error(
381  _("Binding '%s' will alias '%s' Before, try: 'bind %s %s "
382  "noop' "
383  "https://neomutt.org/guide/configuration.html#bind-warnings"),
384  old_binding, new_binding, mutt_map_get_name(menu, Menus), new_binding);
385  }
386  rc = MUTT_CMD_WARNING;
387  }
388  len = tmp->eq;
389  next = tmp->next;
390  FREE(&tmp->macro);
391  FREE(&tmp->keys);
392  FREE(&tmp->desc);
393  FREE(&tmp);
394  tmp = next;
395  } while (tmp && len >= pos);
396  map->eq = len;
397  break;
398  }
399  else if (buf[pos] == tmp->keys[pos])
400  pos++;
401  else if (buf[pos] < tmp->keys[pos])
402  {
403  /* found location to insert between last and tmp */
404  map->eq = pos;
405  break;
406  }
407  else /* buf[pos] > tmp->keys[pos] */
408  {
409  last = tmp;
410  lastpos = pos;
411  if (pos > tmp->eq)
412  pos = tmp->eq;
413  tmp = tmp->next;
414  }
415  }
416 
417  map->next = tmp;
418  if (last)
419  {
420  last->next = map;
421  last->eq = lastpos;
422  }
423  else
424  {
425  Keymaps[menu] = map;
426  }
427 
428  return rc;
429 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:52
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
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:54
#define _(a)
Definition: message.h:28
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
size_t dsize
Length of data.
Definition: buffer.h:37
static size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: keymap.c:270
short op
operation to perform
Definition: keymap.h:51
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
struct Keymap * next
next key in map
Definition: keymap.h:50
static struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition: keymap.c:204
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:828
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
char * data
Pointer to data.
Definition: buffer.h:35
short keycode_t
Definition: keymap.h:37
char * desc
description of a macro for the help menu
Definition: keymap.h:49
A keyboard mapping.
Definition: keymap.h:46
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
#define MAX_SEQ
Definition: keymap.h:34
+ 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 }
short op
operation to perform
Definition: keymap.h:51
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
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
char * desc
description of a macro for the help menu
Definition: keymap.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_bindkey_err()

static enum CommandResult km_bindkey_err ( const char *  s,
enum MenuType  menu,
int  op,
struct Buffer err 
)
static

Bind a key in a Menu to an operation (with error message)

Parameters
sKey string
menuMenu id, e.g. MENU_PAGER
opOperation, e.g. OP_DELETE
errBuffer for error message
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 453 of file keymap.c.

455 {
456  return km_bind_err(s, menu, op, NULL, NULL, err);
457 }
short op
operation to perform
Definition: keymap.h:51
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_bindkey()

static enum CommandResult km_bindkey ( const char *  s,
enum MenuType  menu,
int  op 
)
static

Bind a key in a Menu to an operation.

Parameters
sKey string
menuMenu id, e.g. MENU_PAGER
opOperation, e.g. OP_DELETE
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 466 of file keymap.c.

467 {
468  return km_bindkey_err(s, menu, op, NULL);
469 }
static enum CommandResult km_bindkey_err(const char *s, enum MenuType menu, int op, struct Buffer *err)
Bind a key in a Menu to an operation (with error message)
Definition: keymap.c:453
short op
operation to perform
Definition: keymap.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_op()

static int get_op ( const struct Binding bindings,
const char *  start,
size_t  len 
)
static

Get the function by its name.

Parameters
bindingsKey bindings table
startName of function to find
lenLength of string to match
Return values
numOperation, e.g. OP_DELETE

Definition at line 478 of file keymap.c.

479 {
480  for (int i = 0; bindings[i].name; i++)
481  {
482  if ((mutt_str_strncasecmp(start, bindings[i].name, len) == 0) &&
483  (mutt_str_strlen(bindings[i].name) == len))
484  {
485  return bindings[i].op;
486  }
487  }
488 
489  return OP_NULL;
490 }
int op
function id number
Definition: keymap.h:117
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h:116
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
+ Here is the call graph for this function:
+ 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 }
const char * name
name of the function
Definition: keymap.h:116
short op
operation to perform
Definition: keymap.h:51
+ Here is the caller graph for this function:

◆ generic_tokenize_push_string()

static void generic_tokenize_push_string ( char *  s,
void(*)(int, int)  generic_push 
)
static

Parse and queue a 'push' command.

Parameters
sString to push into the key queue
generic_pushCallback function to add events to macro queue

Parses s for <function> syntax and adds the whole sequence to either the macro or unget buffer. This function is invoked by the next two defines below.

Definition at line 521 of file keymap.c.

522 {
523  char *pp = NULL;
524  char *p = s + mutt_str_strlen(s) - 1;
525  size_t l;
526  int i, op = OP_NULL;
527 
528  while (p >= s)
529  {
530  /* if we see something like "<PageUp>", look to see if it is a real
531  * function name and return the corresponding value */
532  if (*p == '>')
533  {
534  for (pp = p - 1; pp >= s && *pp != '<'; pp--)
535  ;
536  if (pp >= s)
537  {
538  i = parse_fkey(pp);
539  if (i > 0)
540  {
541  generic_push(KEY_F(i), 0);
542  p = pp - 1;
543  continue;
544  }
545 
546  l = p - pp + 1;
547  for (i = 0; KeyNames[i].name; i++)
548  {
549  if (mutt_str_strncasecmp(pp, KeyNames[i].name, l) == 0)
550  break;
551  }
552  if (KeyNames[i].name)
553  {
554  /* found a match */
555  generic_push(KeyNames[i].value, 0);
556  p = pp - 1;
557  continue;
558  }
559 
560  /* See if it is a valid command
561  * skip the '<' and the '>' when comparing */
562  for (enum MenuType j = 0; Menus[j].name; j++)
563  {
564  const struct Binding *binding = km_get_table(Menus[j].value);
565  if (binding)
566  {
567  op = get_op(binding, pp + 1, l - 2);
568  if (op != OP_NULL)
569  break;
570  }
571  }
572 
573  if (op != OP_NULL)
574  {
575  generic_push(0, op);
576  p = pp - 1;
577  continue;
578  }
579  }
580  }
581  generic_push((unsigned char) *p--, 0); /* independent 8 bits chars */
582  }
583 }
MenuType
Types of GUI selections.
Definition: keymap.h:69
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
const char * name
Definition: pgpmicalg.c:45
short op
operation to perform
Definition: keymap.h:51
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:88
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:220
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1223
const char * name
Definition: mapping.h:31
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:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retry_generic()

static int retry_generic ( enum MenuType  menu,
keycode_t keys,
int  keyslen,
int  lastkey 
)
static

Try to find the key in the generic menu bindings.

Parameters
menuMenu id, e.g. MENU_PAGER
keysArray of keys to return to the input queue
keyslenNumber of keys in the array
lastkeyLast key pressed (to return to input queue)
Return values
numOperation, e.g. OP_DELETE

Definition at line 593 of file keymap.c.

594 {
595  if ((menu != MENU_EDITOR) && (menu != MENU_GENERIC) && (menu != MENU_PAGER))
596  {
597  if (lastkey)
598  mutt_unget_event(lastkey, 0);
599  for (; keyslen; keyslen--)
600  mutt_unget_event(keys[keyslen - 1], 0);
601  return km_dokey(MENU_GENERIC);
602  }
603  if (menu != MENU_EDITOR)
604  {
605  /* probably a good idea to flush input here so we can abort macros */
606  mutt_flushinp();
607  }
608  return OP_NULL;
609 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:619
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:848
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:763
Pager pager (email viewer)
Definition: keymap.h:78
Text entry area.
Definition: keymap.h:74
Generic selection list.
Definition: keymap.h:76
+ 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 619 of file keymap.c.

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

◆ create_bindings()

static void create_bindings ( const struct Binding map,
enum MenuType  menu 
)
static

Attach a set of keybindings to a Menu.

Parameters
mapKey bindings
menuMenu id, e.g. MENU_PAGER

Definition at line 775 of file keymap.c.

776 {
777  for (int i = 0; map[i].name; i++)
778  if (map[i].seq)
779  km_bindkey(map[i].seq, menu, map[i].op);
780 }
int op
function id number
Definition: keymap.h:117
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
const char * name
name of the function
Definition: keymap.h:116
const char * seq
default key binding
Definition: keymap.h:118
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_keyname()

static const char* km_keyname ( int  c)
static

Get the human name for a key.

Parameters
cKey code
Return values
ptrName of the key
Note
This returns a pointer to a static buffer.

Definition at line 789 of file keymap.c.

790 {
791  static char buf[35];
792 
793  const char *p = mutt_map_get_name(c, KeyNames);
794  if (p)
795  return p;
796 
797  if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
798  {
799  if (c < 0)
800  c += 256;
801 
802  if (c < 128)
803  {
804  buf[0] = '^';
805  buf[1] = (c + '@') & 0x7f;
806  buf[2] = '\0';
807  }
808  else
809  snprintf(buf, sizeof(buf), "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
810  }
811  else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
812  sprintf(buf, "<F%d>", c - KEY_F0);
813  else if (IsPrint(c))
814  snprintf(buf, sizeof(buf), "%c", (unsigned char) c);
815  else
816  snprintf(buf, sizeof(buf), "\\x%hx", (unsigned short) c);
817  return buf;
818 }
#define IsPrint(ch)
Definition: mbyte.h:38
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:88
+ Here is the call graph for this function:
+ 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 828 of file keymap.c.

829 {
830  if (!map)
831  return 0;
832 
833  int p = 0;
834 
835  while (true)
836  {
837  mutt_str_strfcpy(s, km_keyname(map->keys[p]), len);
838  const size_t l = mutt_str_strlen(s);
839  len -= l;
840 
841  if ((++p >= map->len) || !len)
842  return 1;
843 
844  s += l;
845  }
846 
847  /* not reached */
848 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:789
keycode_t * keys
key sequence
Definition: keymap.h:54
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
+ 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 856 of file keymap.c.

857 {
858  struct Keymap *map = Keymaps[menu];
859 
860  for (; map; map = map->next)
861  if (map->op == func)
862  break;
863  return map;
864 }
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:51
struct Keymap * next
next key in map
Definition: keymap.h:50
A keyboard mapping.
Definition: keymap.h:46
+ Here is the caller graph for this function:

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

898 {
899 #ifdef NCURSES_VERSION
900 
901  use_extended_names(true);
902 
903  for (int j = 0; KeyNames[j].name; j++)
904  {
905  if (KeyNames[j].value == -1)
906  {
907  const char *keyname = find_ext_name(KeyNames[j].name);
908 
909  if (keyname)
910  {
911  char *s = tigetstr((char *) keyname);
912  if (s && ((long) (s) != -1))
913  {
914  int code = key_defined(s);
915  if (code > 0)
916  KeyNames[j].value = code;
917  }
918  }
919  }
920  }
921 #endif
922 }
int value
Definition: mapping.h:32
const char * name
Definition: pgpmicalg.c:45
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:88
const char * name
Definition: mapping.h:31
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 927 of file keymap.c.

928 {
929  memset(Keymaps, 0, sizeof(struct Keymap *) * MENU_MAX);
930 
939 
942 
945 
946 #ifdef CRYPT_BACKEND_GPGME
947  create_bindings(OpPgp, MENU_KEY_SELECT_PGP);
948  create_bindings(OpSmime, MENU_KEY_SELECT_SMIME);
949 #endif
950 
951 #ifdef MIXMASTER
952  create_bindings(OpMix, MENU_MIX);
953 
954  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
955  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
956  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
957 #endif
958 
959 #ifdef USE_AUTOCRYPT
961 #endif
962 
963  /* bindings for the line editor */
965 
966  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
967  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
968  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
969  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
970  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
971  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
972  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
973  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
974  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
975 
976  /* generic menu keymap */
978 
979  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
980  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
981  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
982  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
983  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
984  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
985  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
986  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
987  km_bindkey("1", MENU_GENERIC, OP_JUMP);
988  km_bindkey("2", MENU_GENERIC, OP_JUMP);
989  km_bindkey("3", MENU_GENERIC, OP_JUMP);
990  km_bindkey("4", MENU_GENERIC, OP_JUMP);
991  km_bindkey("5", MENU_GENERIC, OP_JUMP);
992  km_bindkey("6", MENU_GENERIC, OP_JUMP);
993  km_bindkey("7", MENU_GENERIC, OP_JUMP);
994  km_bindkey("8", MENU_GENERIC, OP_JUMP);
995  km_bindkey("9", MENU_GENERIC, OP_JUMP);
996 
997  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
998  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
999 
1000  /* Miscellaneous extra bindings */
1001 
1002  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1003  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1004  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1005  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1006  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1007  km_bindkey("x", MENU_MAIN, OP_EXIT);
1008 
1009  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1010  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1011 
1012  km_bindkey("x", MENU_PAGER, OP_EXIT);
1013  km_bindkey("i", MENU_PAGER, OP_EXIT);
1014  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1015  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1016  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1017  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1018  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1019  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1020  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1021  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1022  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1023  km_bindkey("1", MENU_PAGER, OP_JUMP);
1024  km_bindkey("2", MENU_PAGER, OP_JUMP);
1025  km_bindkey("3", MENU_PAGER, OP_JUMP);
1026  km_bindkey("4", MENU_PAGER, OP_JUMP);
1027  km_bindkey("5", MENU_PAGER, OP_JUMP);
1028  km_bindkey("6", MENU_PAGER, OP_JUMP);
1029  km_bindkey("7", MENU_PAGER, OP_JUMP);
1030  km_bindkey("8", MENU_PAGER, OP_JUMP);
1031  km_bindkey("9", MENU_PAGER, OP_JUMP);
1032 
1033  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1034  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1035 
1036  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1037  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1038  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1039 
1040  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1041  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1042  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1043  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1044 
1045  /* edit-to (default "t") hides generic tag-entry in Compose menu
1046  * This will bind tag-entry to "T" in the Compose menu */
1047  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1048 }
PGP encryption menu.
Definition: keymap.h:81
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.h:672
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:149
General file/mailbox browser.
Definition: keymap.h:75
Compose an email.
Definition: keymap.h:73
Index panel (list of emails)
Definition: keymap.h:77
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.h:261
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.h:103
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:82
Pager pager (email viewer)
Definition: keymap.h:78
Select from results of external query.
Definition: keymap.h:80
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.h:635
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.h:530
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.h:644
Select an attachment.
Definition: keymap.h:72
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.h:521
static void create_bindings(const struct Binding *map, enum MenuType menu)
Attach a set of keybindings to a Menu.
Definition: keymap.c:775
Select an email address by its alias.
Definition: keymap.h:71
A keyboard mapping.
Definition: keymap.h:46
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: ncrypt.h:134
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.h:539
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.h:451
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.h:415
Text entry area.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:603
#define WithCrypto
Definition: ncrypt.h:160
Select a postponed email.
Definition: keymap.h:79
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: ncrypt.h:135
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.h:592
Generic selection list.
Definition: keymap.h:76
+ 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 1054 of file keymap.c.

1055 {
1056  char buf[128];
1057  int p, op;
1058 
1059  struct Keymap *key = km_find_func(menu, OP_HELP);
1060  if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER))
1061  key = km_find_func(MENU_GENERIC, OP_HELP);
1062  if (!key)
1063  {
1064  mutt_error(_("Key is not bound"));
1065  return;
1066  }
1067 
1068  /* Make sure the key is really the help key in this menu.
1069  *
1070  * OP_END_COND is used as a barrier to ensure nothing extra
1071  * is left in the unget buffer.
1072  *
1073  * Note that km_expand_key() + tokenize_unget_string() should
1074  * not be used here: control sequences are expanded to a form
1075  * (e.g. "^H") not recognized by km_dokey(). */
1076  mutt_unget_event(0, OP_END_COND);
1077  p = key->len;
1078  while (p--)
1079  mutt_unget_event(key->keys[p], 0);
1080 
1081  /* Note, e.g. for the index menu:
1082  * bind generic ? noop
1083  * bind generic ,a help
1084  * bind index ,ab quit
1085  * The index keybinding shadows the generic binding.
1086  * OP_END_COND will be read and returned as the op.
1087  *
1088  * bind generic ? noop
1089  * bind generic dq help
1090  * bind index d delete-message
1091  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1092  * in the unget buffer.
1093  */
1094  op = km_dokey(menu);
1095  if (op != OP_END_COND)
1097  if (op != OP_HELP)
1098  {
1099  mutt_error(_("Key is not bound"));
1100  return;
1101  }
1102 
1103  km_expand_key(buf, sizeof(buf), key);
1104  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1105 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:619
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:763
#define _(a)
Definition: message.h:28
Pager pager (email viewer)
Definition: keymap.h:78
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:856
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:828
A keyboard mapping.
Definition: keymap.h:46
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:836
Text entry area.
Definition: keymap.h:74
Generic selection list.
Definition: keymap.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_push()

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

Parse the 'push' command - Implements command_t.

Definition at line 1110 of file keymap.c.

1112 {
1114  if (MoreArgs(s))
1115  {
1116  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1117  return MUTT_CMD_ERROR;
1118  }
1119 
1121  return MUTT_CMD_SUCCESS;
1122 }
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:800
#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:78
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
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:

◆ parse_keymap()

static char* parse_keymap ( enum MenuType menu,
struct Buffer s,
int  max_menus,
int *  num_menus,
struct Buffer err,
bool  bind 
)
static

Parse a user-config key binding.

Parameters
menuArray for results
sBuffer containing config string
max_menusTotal number of menus
num_menusNumber of menus this config applies to
errBuffer for error messages
bindIf true 'bind', otherwise 'macro'
Return values
ptrKey string for the binding

Expects to see: <menu-string>,<menu-string>,... <key-string>

Note
Caller needs to free the returned string

Definition at line 1138 of file keymap.c.

1140 {
1141  struct Buffer buf;
1142  int i = 0;
1143  char *q = NULL;
1144 
1145  mutt_buffer_init(&buf);
1146 
1147  /* menu name */
1149  char *p = buf.data;
1150  if (MoreArgs(s))
1151  {
1152  while (i < max_menus)
1153  {
1154  q = strchr(p, ',');
1155  if (q)
1156  *q = '\0';
1157 
1158  int val = mutt_map_get_value(p, Menus);
1159  if (val == -1)
1160  {
1161  mutt_buffer_printf(err, _("%s: no such menu"), p);
1162  goto error;
1163  }
1164  menu[i] = val;
1165  i++;
1166  if (q)
1167  p = q + 1;
1168  else
1169  break;
1170  }
1171  *num_menus = i;
1172  /* key sequence */
1174 
1175  if (buf.data[0] == '\0')
1176  {
1177  mutt_buffer_printf(err, _("%s: null key sequence"), bind ? "bind" : "macro");
1178  }
1179  else if (MoreArgs(s))
1180  return buf.data;
1181  }
1182  else
1183  {
1184  mutt_buffer_printf(err, _("%s: too few arguments"), bind ? "bind" : "macro");
1185  }
1186 error:
1187  FREE(&buf.data);
1188  return NULL;
1189 }
String manipulation buffer.
Definition: buffer.h:33
#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
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ try_bind()

static enum CommandResult try_bind ( char *  key,
enum MenuType  menu,
char *  func,
const struct Binding bindings,
struct Buffer err 
)
static

Try to make a key binding.

Parameters
keyKey name
menuMenu id, e.g. MENU_PAGER
funcFunction name
bindingsKey bindings table
errBuffer for error message
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 1200 of file keymap.c.

1202 {
1203  for (int i = 0; bindings[i].name; i++)
1204  {
1205  if (mutt_str_strcmp(func, bindings[i].name) == 0)
1206  {
1207  return km_bindkey_err(key, menu, bindings[i].op, err);
1208  }
1209  }
1210  if (err)
1211  {
1212  mutt_buffer_printf(err, _("Function '%s' not available for menu '%s'"),
1213  func, mutt_map_get_name(menu, Menus));
1214  }
1215  return MUTT_CMD_ERROR; /* Couldn't find an existing function with this name */
1216 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
static enum CommandResult km_bindkey_err(const char *s, enum MenuType menu, int op, struct Buffer *err)
Bind a key in a Menu to an operation (with error message)
Definition: keymap.c:453
#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
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h:116
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ 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 1223 of file keymap.c.

1224 {
1225  switch (menu)
1226  {
1227  case MENU_ALIAS:
1228  return OpAlias;
1229  case MENU_ATTACH:
1230  return OpAttach;
1231 #ifdef USE_AUTOCRYPT
1232  case MENU_AUTOCRYPT_ACCT:
1233  return OpAutocryptAcct;
1234 #endif
1235  case MENU_COMPOSE:
1236  return OpCompose;
1237  case MENU_EDITOR:
1238  return OpEditor;
1239  case MENU_FOLDER:
1240  return OpBrowser;
1241  case MENU_GENERIC:
1242  return OpGeneric;
1243 #ifdef CRYPT_BACKEND_GPGME
1244  case MENU_KEY_SELECT_PGP:
1245  return OpPgp;
1246  case MENU_KEY_SELECT_SMIME:
1247  return OpSmime;
1248 #endif
1249  case MENU_MAIN:
1250  return OpMain;
1251 #ifdef MIXMASTER
1252  case MENU_MIX:
1253  return OpMix;
1254 #endif
1255  case MENU_PAGER:
1256  return OpPager;
1257  case MENU_PGP:
1258  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1259  case MENU_POSTPONE:
1260  return OpPost;
1261  case MENU_QUERY:
1262  return OpQuery;
1263  default:
1264  return NULL;
1265  }
1266 }
PGP encryption menu.
Definition: keymap.h:81
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.h:672
General file/mailbox browser.
Definition: keymap.h:75
Compose an email.
Definition: keymap.h:73
Index panel (list of emails)
Definition: keymap.h:77
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.h:261
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.h:103
Pager pager (email viewer)
Definition: keymap.h:78
Select from results of external query.
Definition: keymap.h:80
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.h:635
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.h:530
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.h:644
Select an attachment.
Definition: keymap.h:72
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.h:521
Select an email address by its alias.
Definition: keymap.h:71
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: ncrypt.h:134
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.h:539
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.h:451
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.h:415
Text entry area.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:603
#define WithCrypto
Definition: ncrypt.h:160
Select a postponed email.
Definition: keymap.h:79
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.h:592
Generic selection list.
Definition: keymap.h:76
+ Here is the caller graph for this function:

◆ mutt_parse_bind()

enum CommandResult mutt_parse_bind ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)

Parse the 'bind' command - Implements command_t.

bind menu-name <key_sequence> function-name

Definition at line 1273 of file keymap.c.

1275 {
1276  const struct Binding *bindings = NULL;
1277  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1278  int num_menus = 0;
1279  enum CommandResult rc = MUTT_CMD_SUCCESS;
1280 
1281  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true);
1282  if (!key)
1283  return MUTT_CMD_ERROR;
1284 
1285  /* function to execute */
1287  if (MoreArgs(s))
1288  {
1289  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1290  rc = MUTT_CMD_ERROR;
1291  }
1292  else if (mutt_str_strcasecmp("noop", buf->data) == 0)
1293  {
1294  for (int i = 0; i < num_menus; i++)
1295  {
1296  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1297  }
1298  }
1299  else
1300  {
1301  for (int i = 0; i < num_menus; i++)
1302  {
1303  /* The pager and editor menus don't use the generic map,
1304  * however for other menus try generic first. */
1305  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1306  {
1307  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1308  if (rc == 0)
1309  continue;
1310  if (rc == -2)
1311  break;
1312  }
1313 
1314  /* Clear any error message, we're going to try again */
1315  err->data[0] = '\0';
1316  bindings = km_get_table(menu[i]);
1317  if (bindings)
1318  {
1319  rc = try_bind(key, menu[i], buf->data, bindings, err);
1320  }
1321  }
1322  }
1323  FREE(&key);
1324  return rc;
1325 }
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:69
#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:1138
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:78
#define MoreArgs(buf)
Definition: buffer.h:43
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
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:1200
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1223
#define FREE(x)
Definition: memory.h:40
Mapping between user-readable string and a constant.
Definition: mapping.h:29
Text entry area.
Definition: keymap.h:74
Mapping between a user key and a function.
Definition: keymap.h:114
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
Generic selection list.
Definition: keymap.h:76
+ Here is the call graph for this function:

◆ parse_menu()

static void* parse_menu ( bool *  menu,
char *  s,
struct Buffer err 
)
static

Parse menu-names into an array.

Parameters
menuArray for results
sString containing menu-names
errBuffer for error messages

Expects to see: <menu-string>[,<menu-string>]

Definition at line 1335 of file keymap.c.

1336 {
1337  char *menu_names_dup = mutt_str_strdup(s);
1338  char *marker = menu_names_dup;
1339  char *menu_name = NULL;
1340 
1341  while ((menu_name = strsep(&marker, ",")))
1342  {
1343  int value = mutt_map_get_value(menu_name, Menus);
1344  if (value == -1)
1345  {
1346  mutt_buffer_printf(err, _("%s: no such menu"), menu_name);
1347  break;
1348  }
1349  else
1350  menu[value] = true;
1351  }
1352 
1353  FREE(&menu_names_dup);
1354  return NULL;
1355 }
#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
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_unbind_all()

static void km_unbind_all ( struct Keymap **  map,
unsigned long  mode 
)
static

Free all the keys in the supplied Keymap.

Parameters
mapKeymap mapping
modeUndo bind or macro, e.g. MUTT_UNBIND, MUTT_UNMACRO

Iterate through Keymap and free keys defined either by "macro" or "bind".

Definition at line 1364 of file keymap.c.

1365 {
1366  struct Keymap *next = NULL;
1367  struct Keymap *first = NULL;
1368  struct Keymap *last = NULL;
1369  struct Keymap *cur = *map;
1370 
1371  while (cur)
1372  {
1373  next = cur->next;
1374  if (((mode & MUTT_UNBIND) && !cur->macro) || ((mode & MUTT_UNMACRO) && cur->macro))
1375  {
1376  FREE(&cur->macro);
1377  FREE(&cur->keys);
1378  FREE(&cur->desc);
1379  FREE(&cur);
1380  }
1381  else if (!first)
1382  {
1383  first = cur;
1384  last = cur;
1385  }
1386  else if (last)
1387  {
1388  last->next = cur;
1389  last = cur;
1390  }
1391  else
1392  {
1393  last = cur;
1394  }
1395  cur = next;
1396  }
1397 
1398  if (last)
1399  last->next = NULL;
1400 
1401  *map = first;
1402 }
keycode_t * keys
key sequence
Definition: keymap.h:54
#define MUTT_UNMACRO
Definition: keymap.h:32
struct Keymap * next
next key in map
Definition: keymap.h:50
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
char * desc
description of a macro for the help menu
Definition: keymap.h:49
A keyboard mapping.
Definition: keymap.h:46
#define FREE(x)
Definition: memory.h:40
#define MUTT_UNBIND
Definition: keymap.h:31
+ Here is the caller graph for this function:

◆ mutt_parse_unbind()

enum CommandResult mutt_parse_unbind ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)

Parse the 'unbind' command - Implements command_t.

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

1416 {
1417  bool menu[MENU_MAX] = { 0 };
1418  bool all_keys = false;
1419  char *key = NULL;
1420 
1422  if (mutt_str_strcmp(buf->data, "*") == 0)
1423  {
1424  for (enum MenuType i = 0; i < MENU_MAX; i++)
1425  menu[i] = true;
1426  }
1427  else
1428  parse_menu(menu, buf->data, err);
1429 
1430  if (MoreArgs(s))
1431  {
1433  key = buf->data;
1434  }
1435  else
1436  all_keys = true;
1437 
1438  if (MoreArgs(s))
1439  {
1440  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1441 
1442  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1443  return MUTT_CMD_ERROR;
1444  }
1445 
1446  for (enum MenuType i = 0; i < MENU_MAX; i++)
1447  {
1448  if (!menu[i])
1449  continue;
1450  if (all_keys)
1451  {
1452  km_unbind_all(&Keymaps[i], data);
1453  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1454  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1455  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1456  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1457  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1458  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1459  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1460  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1461  if (i != MENU_EDITOR)
1462  {
1463  km_bindkey("?", i, OP_HELP);
1464  km_bindkey("q", i, OP_EXIT);
1465  }
1466  }
1467  else
1468  km_bindkey(key, i, OP_NULL);
1469  }
1470 
1471  return MUTT_CMD_SUCCESS;
1472 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
MenuType
Types of GUI selections.
Definition: keymap.h:69
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:1364
Index panel (list of emails)
Definition: keymap.h:77
#define MUTT_UNMACRO
Definition: keymap.h:32
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:78
#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:2655
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:1335
Text entry area.
Definition: keymap.h:74
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
Generic selection list.
Definition: keymap.h:76
+ Here is the call graph for this function:

◆ mutt_parse_macro()

enum CommandResult mutt_parse_macro ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)

Parse the 'macro' command - Implements command_t.

macro <menu> <key> <macro> <description>

Definition at line 1479 of file keymap.c.

1481 {
1482  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1483  int num_menus = 0;
1484  enum CommandResult rc = MUTT_CMD_ERROR;
1485  char *seq = NULL;
1486 
1487  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false);
1488  if (!key)
1489  return MUTT_CMD_ERROR;
1490 
1492  /* make sure the macro sequence is not an empty string */
1493  if (buf->data[0] == '\0')
1494  {
1495  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1496  }
1497  else
1498  {
1499  if (MoreArgs(s))
1500  {
1501  seq = mutt_str_strdup(buf->data);
1503 
1504  if (MoreArgs(s))
1505  {
1506  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1507  }
1508  else
1509  {
1510  for (int i = 0; i < num_menus; i++)
1511  {
1512  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1513  }
1514  }
1515 
1516  FREE(&seq);
1517  }
1518  else
1519  {
1520  for (int i = 0; i < num_menus; i++)
1521  {
1522  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1523  }
1524  }
1525  }
1526  FREE(&key);
1527  return rc;
1528 }
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:69
#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:1138
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:78
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
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
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
Mapping between user-readable string and a constant.
Definition: mapping.h:29
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_exec()

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

Parse the 'exec' command - Implements command_t.

Definition at line 1533 of file keymap.c.

1535 {
1536  int ops[128];
1537  int nops = 0;
1538  const struct Binding *bindings = NULL;
1539  char *function = NULL;
1540 
1541  if (!MoreArgs(s))
1542  {
1543  mutt_buffer_strcpy(err, _("exec: no arguments"));
1544  return MUTT_CMD_ERROR;
1545  }
1546 
1547  do
1548  {
1550  function = buf->data;
1551 
1552  bindings = km_get_table(CurrentMenu);
1553  if (!bindings && (CurrentMenu != MENU_PAGER))
1554  bindings = OpGeneric;
1555 
1556  ops[nops] = get_op(bindings, function, mutt_str_strlen(function));
1557  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1558  ops[nops] = get_op(OpGeneric, function, mutt_str_strlen(function));
1559 
1560  if (ops[nops] == OP_NULL)
1561  {
1562  mutt_flushinp();
1563  mutt_error(_("%s: no such function"), function);
1564  return MUTT_CMD_ERROR;
1565  }
1566  nops++;
1567  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1568 
1569  while (nops)
1570  mutt_push_macro_event(0, ops[--nops]);
1571 
1572  return MUTT_CMD_SUCCESS;
1573 }
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:800
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:848
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:84
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h:78
#define MoreArgs(buf)
Definition: buffer.h:43
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
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
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:1223
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:114
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call 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 1580 of file keymap.c.

1581 {
1582  int ch;
1583 
1584  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (^G to abort): "));
1585  do
1586  {
1587  ch = getch();
1588  if ((ch != ERR) && (ch != ctrl('G')))
1589  {
1590  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1591  }
1592  } while (ch != ERR && ch != ctrl('G'));
1593 
1594  mutt_flushinp();
1595  mutt_clear_error();
1596 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:789
#define mutt_message(...)
Definition: logging.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:848
#define _(a)
Definition: message.h:28
#define ctrl(ch)
Definition: mutt_curses.h:67
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:115
int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt,...)
Move the cursor and write a formatted string to a Window.
Definition: mutt_window.c:231
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_keys_free()

void mutt_keys_free ( void  )

Free the key maps.

Definition at line 1601 of file keymap.c.

1602 {
1603  struct Keymap *map = NULL;
1604  struct Keymap *next = NULL;
1605 
1606  for (int i = 0; i < MENU_MAX; i++)
1607  {
1608  for (map = Keymaps[i]; map; map = next)
1609  {
1610  next = map->next;
1611 
1612  FREE(&map->macro);
1613  FREE(&map->desc);
1614  FREE(&map->keys);
1615  FREE(&map);
1616  }
1617 
1618  Keymaps[i] = NULL;
1619  }
1620 }
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:54
struct Keymap * next
next key in map
Definition: keymap.h:50
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
char * desc
description of a macro for the help menu
Definition: keymap.h:49
A keyboard mapping.
Definition: keymap.h:46
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

Variable Documentation

◆ Menus

const struct Mapping Menus[]
Initial value:
= {
{ "alias", MENU_ALIAS },
{ "attach", MENU_ATTACH },
{ "browser", MENU_FOLDER },
{ "compose", MENU_COMPOSE },
{ "editor", MENU_EDITOR },
{ "index", MENU_MAIN },
{ "pager", MENU_PAGER },
{ "postpone", MENU_POSTPONE },
{ "pgp", MENU_PGP },
{ "smime", MENU_SMIME },
{ "query", MENU_QUERY },
{ "generic", MENU_GENERIC },
{ NULL, 0 },
}
PGP encryption menu.
Definition: keymap.h:81
General file/mailbox browser.
Definition: keymap.h:75
Compose an email.
Definition: keymap.h:73
Index panel (list of emails)
Definition: keymap.h:77
SMIME encryption menu.
Definition: keymap.h:82
Pager pager (email viewer)
Definition: keymap.h:78
Select from results of external query.
Definition: keymap.h:80
Select an attachment.
Definition: keymap.h:72
Select an email address by its alias.
Definition: keymap.h:71
Text entry area.
Definition: keymap.h:74
Select a postponed email.
Definition: keymap.h:79
Generic selection list.
Definition: keymap.h:76

Menu name lookup table.

Definition at line 62 of file keymap.c.

◆ KeyNames

struct Mapping KeyNames[]
static

Key name lookup table.

Definition at line 88 of file keymap.c.

◆ LastKey

int LastKey

contains the last key the user pressed

Last real key pressed, recorded by dokey()

Definition at line 147 of file keymap.c.

◆ Keymaps

struct Keymap* Keymaps[MENU_MAX]

Array of Keymap keybindings, one for each Menu.

Definition at line 149 of file keymap.c.