NeoMutt  2019-12-07-60-g0cfa53
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 "gui/lib.h"
#include "mutt.h"
#include "keymap.h"
#include "functions.h"
#include "globals.h"
#include "mutt_commands.h"
#include "mutt_logging.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 202 of file keymap.c.

203 {
204  struct Keymap *p = mutt_mem_calloc(1, sizeof(struct Keymap));
205  p->len = len;
206  p->keys = mutt_mem_malloc(len * sizeof(keycode_t));
207  memcpy(p->keys, keys, len * sizeof(keycode_t));
208  return p;
209 }
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 218 of file keymap.c.

219 {
220  char *t = NULL;
221  int n = 0;
222 
223  if ((s[0] != '<') || (tolower(s[1]) != 'f'))
224  return -1;
225 
226  for (t = s + 2; *t && isdigit((unsigned char) *t); t++)
227  {
228  n *= 10;
229  n += *t - '0';
230  }
231 
232  if (*t != '>')
233  return -1;
234  return n;
235 }
+ 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 245 of file keymap.c.

246 {
247  char *end_char = NULL;
248  long int result = strtol(s + 1, &end_char, 8);
249  /* allow trailing whitespace, eg. < 1001 > */
250  while (IS_SPACE(*end_char))
251  end_char++;
252  /* negative keycodes don't make sense, also detect overflow */
253  if ((*end_char != '>') || (result < 0) || (result == LONG_MAX))
254  {
255  return -1;
256  }
257 
258  return result;
259 }
#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 268 of file keymap.c.

269 {
270  int n;
271  size_t len = max;
272  char buf[128];
273  char c;
274  char *t = NULL;
275 
276  mutt_str_strfcpy(buf, str, sizeof(buf));
277  char *s = buf;
278 
279  while (*s && len)
280  {
281  *d = '\0';
282  if ((*s == '<') && (t = strchr(s, '>')))
283  {
284  t++;
285  c = *t;
286  *t = '\0';
287 
289  if (n != -1)
290  {
291  s = t;
292  *d = n;
293  }
294  else if ((n = parse_fkey(s)) > 0)
295  {
296  s = t;
297  *d = KEY_F(n);
298  }
299  else if ((n = parse_keycode(s)) > 0)
300  {
301  s = t;
302  *d = n;
303  }
304 
305  *t = c;
306  }
307 
308  if (!*d)
309  {
310  *d = (unsigned char) *s;
311  s++;
312  }
313  d++;
314  len--;
315  }
316 
317  return max - len;
318 }
static int parse_keycode(const char *s)
Parse a numeric keycode.
Definition: keymap.c:245
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:86
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:218
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 333 of file keymap.c.

335 {
337  struct Keymap *last = NULL, *next = NULL;
338  keycode_t buf[MAX_SEQ];
339  size_t pos = 0, lastpos = 0;
340 
341  size_t len = parsekeys(s, buf, MAX_SEQ);
342 
343  struct Keymap *map = alloc_keys(len, buf);
344  map->op = op;
345  map->macro = mutt_str_strdup(macro);
346  map->desc = mutt_str_strdup(desc);
347 
348  struct Keymap *tmp = Keymaps[menu];
349 
350  while (tmp)
351  {
352  if ((pos >= len) || (pos >= tmp->len))
353  {
354  /* map and tmp match so overwrite */
355  do
356  {
357  /* Don't warn on overwriting a 'noop' binding */
358  if ((tmp->len != len) && (tmp->op != OP_NULL))
359  {
360  /* Overwrite with the different lengths, warn */
361  /* TODO: MAX_SEQ here is wrong */
362  char old_binding[MAX_SEQ];
363  char new_binding[MAX_SEQ];
364  km_expand_key(old_binding, MAX_SEQ, map);
365  km_expand_key(new_binding, MAX_SEQ, tmp);
366  if (err)
367  {
368  /* err was passed, put the string there */
369  snprintf(
370  err->data, err->dsize,
371  _("Binding '%s' will alias '%s' Before, try: 'bind %s %s "
372  "noop' "
373  "https://neomutt.org/guide/configuration.html#bind-warnings"),
374  old_binding, new_binding, mutt_map_get_name(menu, Menus), new_binding);
375  }
376  else
377  {
378  mutt_error(
379  _("Binding '%s' will alias '%s' Before, try: 'bind %s %s "
380  "noop' "
381  "https://neomutt.org/guide/configuration.html#bind-warnings"),
382  old_binding, new_binding, mutt_map_get_name(menu, Menus), new_binding);
383  }
384  rc = MUTT_CMD_WARNING;
385  }
386  len = tmp->eq;
387  next = tmp->next;
388  FREE(&tmp->macro);
389  FREE(&tmp->keys);
390  FREE(&tmp->desc);
391  FREE(&tmp);
392  tmp = next;
393  } while (tmp && len >= pos);
394  map->eq = len;
395  break;
396  }
397  else if (buf[pos] == tmp->keys[pos])
398  pos++;
399  else if (buf[pos] < tmp->keys[pos])
400  {
401  /* found location to insert between last and tmp */
402  map->eq = pos;
403  break;
404  }
405  else /* buf[pos] > tmp->keys[pos] */
406  {
407  last = tmp;
408  lastpos = pos;
409  if (pos > tmp->eq)
410  pos = tmp->eq;
411  tmp = tmp->next;
412  }
413  }
414 
415  map->next = tmp;
416  if (last)
417  {
418  last->next = map;
419  last->eq = lastpos;
420  }
421  else
422  {
423  Keymaps[menu] = map;
424  }
425 
426  return rc;
427 }
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:147
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:268
short op
operation to perform
Definition: keymap.h:51
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
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:202
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:826
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 438 of file keymap.c.

439 {
440  return km_bind_err(s, menu, op, macro, desc, NULL);
441 }
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:333
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 451 of file keymap.c.

453 {
454  return km_bind_err(s, menu, op, NULL, NULL, err);
455 }
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:333
+ 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 464 of file keymap.c.

465 {
466  return km_bindkey_err(s, menu, op, NULL);
467 }
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:451
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 476 of file keymap.c.

477 {
478  for (int i = 0; bindings[i].name; i++)
479  {
480  if ((mutt_str_strncasecmp(start, bindings[i].name, len) == 0) &&
481  (mutt_str_strlen(bindings[i].name) == len))
482  {
483  return bindings[i].op;
484  }
485  }
486 
487  return OP_NULL;
488 }
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:46
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 499 of file keymap.c.

500 {
501  for (int i = 0; bindings[i].name; i++)
502  {
503  if (bindings[i].op == op)
504  return bindings[i].name;
505  }
506 
507  return NULL;
508 }
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 519 of file keymap.c.

520 {
521  char *pp = NULL;
522  char *p = s + mutt_str_strlen(s) - 1;
523  size_t l;
524  int i, op = OP_NULL;
525 
526  while (p >= s)
527  {
528  /* if we see something like "<PageUp>", look to see if it is a real
529  * function name and return the corresponding value */
530  if (*p == '>')
531  {
532  for (pp = p - 1; pp >= s && *pp != '<'; pp--)
533  ;
534  if (pp >= s)
535  {
536  i = parse_fkey(pp);
537  if (i > 0)
538  {
539  generic_push(KEY_F(i), 0);
540  p = pp - 1;
541  continue;
542  }
543 
544  l = p - pp + 1;
545  for (i = 0; KeyNames[i].name; i++)
546  {
547  if (mutt_str_strncasecmp(pp, KeyNames[i].name, l) == 0)
548  break;
549  }
550  if (KeyNames[i].name)
551  {
552  /* found a match */
553  generic_push(KeyNames[i].value, 0);
554  p = pp - 1;
555  continue;
556  }
557 
558  /* See if it is a valid command
559  * skip the '<' and the '>' when comparing */
560  for (enum MenuType j = 0; Menus[j].name; j++)
561  {
562  const struct Binding *binding = km_get_table(Menus[j].value);
563  if (binding)
564  {
565  op = get_op(binding, pp + 1, l - 2);
566  if (op != OP_NULL)
567  break;
568  }
569  }
570 
571  if (op != OP_NULL)
572  {
573  generic_push(0, op);
574  p = pp - 1;
575  continue;
576  }
577  }
578  }
579  generic_push((unsigned char) *p--, 0); /* independent 8 bits chars */
580  }
581 }
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:46
short op
operation to perform
Definition: keymap.h:51
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:86
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:218
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:1221
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:476
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 591 of file keymap.c.

592 {
593  if ((menu != MENU_EDITOR) && (menu != MENU_GENERIC) && (menu != MENU_PAGER))
594  {
595  if (lastkey)
596  mutt_unget_event(lastkey, 0);
597  for (; keyslen; keyslen--)
598  mutt_unget_event(keys[keyslen - 1], 0);
599  return km_dokey(MENU_GENERIC);
600  }
601  if (menu != MENU_EDITOR)
602  {
603  /* probably a good idea to flush input here so we can abort macros */
604  mutt_flushinp();
605  }
606  return OP_NULL;
607 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:617
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:919
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:834
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 617 of file keymap.c.

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

774 {
775  for (int i = 0; map[i].name; i++)
776  if (map[i].seq)
777  km_bindkey(map[i].seq, menu, map[i].op);
778 }
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:464
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 787 of file keymap.c.

788 {
789  static char buf[35];
790 
791  const char *p = mutt_map_get_name(c, KeyNames);
792  if (p)
793  return p;
794 
795  if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
796  {
797  if (c < 0)
798  c += 256;
799 
800  if (c < 128)
801  {
802  buf[0] = '^';
803  buf[1] = (c + '@') & 0x7f;
804  buf[2] = '\0';
805  }
806  else
807  snprintf(buf, sizeof(buf), "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
808  }
809  else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
810  sprintf(buf, "<F%d>", c - KEY_F0);
811  else if (IsPrint(c))
812  snprintf(buf, sizeof(buf), "%c", (unsigned char) c);
813  else
814  snprintf(buf, sizeof(buf), "\\x%hx", (unsigned short) c);
815  return buf;
816 }
#define IsPrint(ch)
Definition: mbyte.h:39
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:86
+ 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 826 of file keymap.c.

827 {
828  if (!map)
829  return 0;
830 
831  int p = 0;
832 
833  while (true)
834  {
835  mutt_str_strfcpy(s, km_keyname(map->keys[p]), len);
836  const size_t l = mutt_str_strlen(s);
837  len -= l;
838 
839  if ((++p >= map->len) || !len)
840  return 1;
841 
842  s += l;
843  }
844 
845  /* not reached */
846 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:787
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 854 of file keymap.c.

855 {
856  struct Keymap *map = Keymaps[menu];
857 
858  for (; map; map = map->next)
859  if (map->op == func)
860  break;
861  return map;
862 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
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 895 of file keymap.c.

896 {
897 #ifdef NCURSES_VERSION
898 
899  use_extended_names(true);
900 
901  for (int j = 0; KeyNames[j].name; j++)
902  {
903  if (KeyNames[j].value == -1)
904  {
905  const char *keyname = find_ext_name(KeyNames[j].name);
906 
907  if (keyname)
908  {
909  char *s = tigetstr((char *) keyname);
910  if (s && ((long) (s) != -1))
911  {
912  int code = key_defined(s);
913  if (code > 0)
914  KeyNames[j].value = code;
915  }
916  }
917  }
918  }
919 #endif
920 }
int value
Definition: mapping.h:32
const char * name
Definition: pgpmicalg.c:46
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:86
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 925 of file keymap.c.

926 {
927  memset(Keymaps, 0, sizeof(struct Keymap *) * MENU_MAX);
928 
937 
940 
943 
944 #ifdef CRYPT_BACKEND_GPGME
945  create_bindings(OpPgp, MENU_KEY_SELECT_PGP);
946  create_bindings(OpSmime, MENU_KEY_SELECT_SMIME);
947 #endif
948 
949 #ifdef MIXMASTER
950  create_bindings(OpMix, MENU_MIX);
951 
952  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
953  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
954  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
955 #endif
956 
957 #ifdef USE_AUTOCRYPT
959 #endif
960 
961  /* bindings for the line editor */
963 
964  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
965  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
966  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
967  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
968  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
969  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
970  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
971  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
972  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
973 
974  /* generic menu keymap */
976 
977  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
978  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
979  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
980  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
981  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
982  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
983  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
984  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
985  km_bindkey("1", MENU_GENERIC, OP_JUMP);
986  km_bindkey("2", MENU_GENERIC, OP_JUMP);
987  km_bindkey("3", MENU_GENERIC, OP_JUMP);
988  km_bindkey("4", MENU_GENERIC, OP_JUMP);
989  km_bindkey("5", MENU_GENERIC, OP_JUMP);
990  km_bindkey("6", MENU_GENERIC, OP_JUMP);
991  km_bindkey("7", MENU_GENERIC, OP_JUMP);
992  km_bindkey("8", MENU_GENERIC, OP_JUMP);
993  km_bindkey("9", MENU_GENERIC, OP_JUMP);
994 
995  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
996  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
997 
998  /* Miscellaneous extra bindings */
999 
1000  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1001  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1002  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1003  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1004  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1005  km_bindkey("x", MENU_MAIN, OP_EXIT);
1006 
1007  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1008  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1009 
1010  km_bindkey("x", MENU_PAGER, OP_EXIT);
1011  km_bindkey("i", MENU_PAGER, OP_EXIT);
1012  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1013  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1014  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1015  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1016  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1017  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1018  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1019  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1020  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1021  km_bindkey("1", MENU_PAGER, OP_JUMP);
1022  km_bindkey("2", MENU_PAGER, OP_JUMP);
1023  km_bindkey("3", MENU_PAGER, OP_JUMP);
1024  km_bindkey("4", MENU_PAGER, OP_JUMP);
1025  km_bindkey("5", MENU_PAGER, OP_JUMP);
1026  km_bindkey("6", MENU_PAGER, OP_JUMP);
1027  km_bindkey("7", MENU_PAGER, OP_JUMP);
1028  km_bindkey("8", MENU_PAGER, OP_JUMP);
1029  km_bindkey("9", MENU_PAGER, OP_JUMP);
1030 
1031  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1032  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1033 
1034  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1035  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1036  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1037 
1038  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1039  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1040  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1041  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1042 
1043  /* edit-to (default "t") hides generic tag-entry in Compose menu
1044  * This will bind tag-entry to "T" in the Compose menu */
1045  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1046 }
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:147
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:464
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:773
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 1052 of file keymap.c.

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

1110 {
1112  if (MoreArgs(s))
1113  {
1114  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1115  return MUTT_CMD_ERROR;
1116  }
1117 
1119  return MUTT_CMD_SUCCESS;
1120 }
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:871
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:43
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:78
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
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:519
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 1136 of file keymap.c.

1138 {
1139  struct Buffer buf;
1140  int i = 0;
1141  char *q = NULL;
1142 
1143  mutt_buffer_init(&buf);
1144 
1145  /* menu name */
1147  char *p = buf.data;
1148  if (MoreArgs(s))
1149  {
1150  while (i < max_menus)
1151  {
1152  q = strchr(p, ',');
1153  if (q)
1154  *q = '\0';
1155 
1156  int val = mutt_map_get_value(p, Menus);
1157  if (val == -1)
1158  {
1159  mutt_buffer_printf(err, _("%s: no such menu"), p);
1160  goto error;
1161  }
1162  menu[i] = val;
1163  i++;
1164  if (q)
1165  p = q + 1;
1166  else
1167  break;
1168  }
1169  *num_menus = i;
1170  /* key sequence */
1172 
1173  if (buf.data[0] == '\0')
1174  {
1175  mutt_buffer_printf(err, _("%s: null key sequence"), bind ? "bind" : "macro");
1176  }
1177  else if (MoreArgs(s))
1178  return buf.data;
1179  }
1180  else
1181  {
1182  mutt_buffer_printf(err, _("%s: too few arguments"), bind ? "bind" : "macro");
1183  }
1184 error:
1185  FREE(&buf.data);
1186  return NULL;
1187 }
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:60
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
#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 1198 of file keymap.c.

1200 {
1201  for (int i = 0; bindings[i].name; i++)
1202  {
1203  if (mutt_str_strcmp(func, bindings[i].name) == 0)
1204  {
1205  return km_bindkey_err(key, menu, bindings[i].op, err);
1206  }
1207  }
1208  if (err)
1209  {
1210  mutt_buffer_printf(err, _("Function '%s' not available for menu '%s'"),
1211  func, mutt_map_get_name(menu, Menus));
1212  }
1213  return MUTT_CMD_ERROR; /* Couldn't find an existing function with this name */
1214 }
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:451
#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:46
const char * name
name of the function
Definition: keymap.h:116
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
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 1221 of file keymap.c.

1222 {
1223  switch (menu)
1224  {
1225  case MENU_ALIAS:
1226  return OpAlias;
1227  case MENU_ATTACH:
1228  return OpAttach;
1229 #ifdef USE_AUTOCRYPT
1230  case MENU_AUTOCRYPT_ACCT:
1231  return OpAutocryptAcct;
1232 #endif
1233  case MENU_COMPOSE:
1234  return OpCompose;
1235  case MENU_EDITOR:
1236  return OpEditor;
1237  case MENU_FOLDER:
1238  return OpBrowser;
1239  case MENU_GENERIC:
1240  return OpGeneric;
1241 #ifdef CRYPT_BACKEND_GPGME
1242  case MENU_KEY_SELECT_PGP:
1243  return OpPgp;
1244  case MENU_KEY_SELECT_SMIME:
1245  return OpSmime;
1246 #endif
1247  case MENU_MAIN:
1248  return OpMain;
1249 #ifdef MIXMASTER
1250  case MENU_MIX:
1251  return OpMix;
1252 #endif
1253  case MENU_PAGER:
1254  return OpPager;
1255  case MENU_PGP:
1256  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1257  case MENU_POSTPONE:
1258  return OpPost;
1259  case MENU_QUERY:
1260  return OpQuery;
1261  default:
1262  return NULL;
1263  }
1264 }
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 1271 of file keymap.c.

1273 {
1274  const struct Binding *bindings = NULL;
1275  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1276  int num_menus = 0;
1277  enum CommandResult rc = MUTT_CMD_SUCCESS;
1278 
1279  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true);
1280  if (!key)
1281  return MUTT_CMD_ERROR;
1282 
1283  /* function to execute */
1285  if (MoreArgs(s))
1286  {
1287  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1288  rc = MUTT_CMD_ERROR;
1289  }
1290  else if (mutt_str_strcasecmp("noop", buf->data) == 0)
1291  {
1292  for (int i = 0; i < num_menus; i++)
1293  {
1294  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1295  }
1296  }
1297  else
1298  {
1299  for (int i = 0; i < num_menus; i++)
1300  {
1301  /* The pager and editor menus don't use the generic map,
1302  * however for other menus try generic first. */
1303  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1304  {
1305  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1306  if (rc == 0)
1307  continue;
1308  if (rc == -2)
1309  break;
1310  }
1311 
1312  /* Clear any error message, we're going to try again */
1313  err->data[0] = '\0';
1314  bindings = km_get_table(menu[i]);
1315  if (bindings)
1316  {
1317  rc = try_bind(key, menu[i], buf->data, bindings, err);
1318  }
1319  }
1320  }
1321  FREE(&key);
1322  return rc;
1323 }
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:1136
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:464
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:60
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:2674
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:1198
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:1221
#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 1333 of file keymap.c.

1334 {
1335  char *menu_names_dup = mutt_str_strdup(s);
1336  char *marker = menu_names_dup;
1337  char *menu_name = NULL;
1338 
1339  while ((menu_name = strsep(&marker, ",")))
1340  {
1341  int value = mutt_map_get_value(menu_name, Menus);
1342  if (value == -1)
1343  {
1344  mutt_buffer_printf(err, _("%s: no such menu"), menu_name);
1345  break;
1346  }
1347  else
1348  menu[value] = true;
1349  }
1350 
1351  FREE(&menu_names_dup);
1352  return NULL;
1353 }
#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:60
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 1362 of file keymap.c.

1363 {
1364  struct Keymap *next = NULL;
1365  struct Keymap *first = NULL;
1366  struct Keymap *last = NULL;
1367  struct Keymap *cur = *map;
1368 
1369  while (cur)
1370  {
1371  next = cur->next;
1372  if (((mode & MUTT_UNBIND) && !cur->macro) || ((mode & MUTT_UNMACRO) && cur->macro))
1373  {
1374  FREE(&cur->macro);
1375  FREE(&cur->keys);
1376  FREE(&cur->desc);
1377  FREE(&cur);
1378  }
1379  else if (!first)
1380  {
1381  first = cur;
1382  last = cur;
1383  }
1384  else if (last)
1385  {
1386  last->next = cur;
1387  last = cur;
1388  }
1389  else
1390  {
1391  last = cur;
1392  }
1393  cur = next;
1394  }
1395 
1396  if (last)
1397  last->next = NULL;
1398 
1399  *map = first;
1400 }
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 1412 of file keymap.c.

1414 {
1415  bool menu[MENU_MAX] = { 0 };
1416  bool all_keys = false;
1417  char *key = NULL;
1418 
1420  if (mutt_str_strcmp(buf->data, "*") == 0)
1421  {
1422  for (enum MenuType i = 0; i < MENU_MAX; i++)
1423  menu[i] = true;
1424  }
1425  else
1426  parse_menu(menu, buf->data, err);
1427 
1428  if (MoreArgs(s))
1429  {
1431  key = buf->data;
1432  }
1433  else
1434  all_keys = true;
1435 
1436  if (MoreArgs(s))
1437  {
1438  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1439 
1440  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1441  return MUTT_CMD_ERROR;
1442  }
1443 
1444  for (enum MenuType i = 0; i < MENU_MAX; i++)
1445  {
1446  if (!menu[i])
1447  continue;
1448  if (all_keys)
1449  {
1450  km_unbind_all(&Keymaps[i], data);
1451  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1452  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1453  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1454  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1455  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1456  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1457  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1458  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1459  if (i != MENU_EDITOR)
1460  {
1461  km_bindkey("?", i, OP_HELP);
1462  km_bindkey("q", i, OP_EXIT);
1463  }
1464  }
1465  else
1466  km_bindkey(key, i, OP_NULL);
1467  }
1468 
1469  return MUTT_CMD_SUCCESS;
1470 }
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:147
#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:1362
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:464
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:2674
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:1333
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 1477 of file keymap.c.

1479 {
1480  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1481  int num_menus = 0;
1482  enum CommandResult rc = MUTT_CMD_ERROR;
1483  char *seq = NULL;
1484 
1485  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false);
1486  if (!key)
1487  return MUTT_CMD_ERROR;
1488 
1490  /* make sure the macro sequence is not an empty string */
1491  if (buf->data[0] == '\0')
1492  {
1493  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1494  }
1495  else
1496  {
1497  if (MoreArgs(s))
1498  {
1499  seq = mutt_str_strdup(buf->data);
1501 
1502  if (MoreArgs(s))
1503  {
1504  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1505  }
1506  else
1507  {
1508  for (int i = 0; i < num_menus; i++)
1509  {
1510  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1511  }
1512  }
1513 
1514  FREE(&seq);
1515  }
1516  else
1517  {
1518  for (int i = 0; i < num_menus; i++)
1519  {
1520  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1521  }
1522  }
1523  }
1524  FREE(&key);
1525  return rc;
1526 }
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:1136
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:60
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
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:438
+ 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 1531 of file keymap.c.

1533 {
1534  int ops[128];
1535  int nops = 0;
1536  const struct Binding *bindings = NULL;
1537  char *function = NULL;
1538 
1539  if (!MoreArgs(s))
1540  {
1541  mutt_buffer_strcpy(err, _("exec: no arguments"));
1542  return MUTT_CMD_ERROR;
1543  }
1544 
1545  do
1546  {
1548  function = buf->data;
1549 
1550  bindings = km_get_table(CurrentMenu);
1551  if (!bindings && (CurrentMenu != MENU_PAGER))
1552  bindings = OpGeneric;
1553 
1554  ops[nops] = get_op(bindings, function, mutt_str_strlen(function));
1555  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1556  ops[nops] = get_op(OpGeneric, function, mutt_str_strlen(function));
1557 
1558  if (ops[nops] == OP_NULL)
1559  {
1560  mutt_flushinp();
1561  mutt_error(_("%s: no such function"), function);
1562  return MUTT_CMD_ERROR;
1563  }
1564  nops++;
1565  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1566 
1567  while (nops)
1568  mutt_push_macro_event(0, ops[--nops]);
1569 
1570  return MUTT_CMD_SUCCESS;
1571 }
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:871
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:919
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:82
#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:2674
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:1221
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:476
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 1578 of file keymap.c.

1579 {
1580  int ch;
1581 
1582  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (^G to abort): "));
1583  do
1584  {
1585  ch = getch();
1586  if ((ch != ERR) && (ch != ctrl('G')))
1587  {
1588  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1589  }
1590  } while (ch != ERR && ch != ctrl('G'));
1591 
1592  mutt_flushinp();
1593  mutt_clear_error();
1594 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:787
#define mutt_message(...)
Definition: logging.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:919
#define _(a)
Definition: message.h:28
#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:113
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:312
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:47
+ 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 1599 of file keymap.c.

1600 {
1601  struct Keymap *map = NULL;
1602  struct Keymap *next = NULL;
1603 
1604  for (int i = 0; i < MENU_MAX; i++)
1605  {
1606  for (map = Keymaps[i]; map; map = next)
1607  {
1608  next = map->next;
1609 
1610  FREE(&map->macro);
1611  FREE(&map->desc);
1612  FREE(&map->keys);
1613  FREE(&map);
1614  }
1615 
1616  Keymaps[i] = NULL;
1617  }
1618 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
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 60 of file keymap.c.

◆ KeyNames

struct Mapping KeyNames[]
static

Key name lookup table.

Definition at line 86 of file keymap.c.

◆ LastKey

int LastKey

contains the last key the user pressed

Last real key pressed, recorded by dokey()

Definition at line 145 of file keymap.c.

◆ Keymaps

struct Keymap* Keymaps[MENU_MAX]

Array of Keymap keybindings, one for each Menu.

Definition at line 147 of file keymap.c.