NeoMutt  2020-03-20-65-g141838
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/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "keymap.h"
#include "functions.h"
#include "globals.h"
#include "init.h"
#include "mutt_commands.h"
#include "mutt_logging.h"
#include "opcodes.h"
#include "options.h"
#include "ncrypt/lib.h"
#include <strings.h>
#include "imap/lib.h"
#include "monitor.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...
 
void mutt_init_abort_key (void)
 Parse the abort_key config string. More...
 
int mutt_abort_key_config_observer (struct NotifyCallback *nc)
 Listen for abort_key config changes - Implements observer_t. More...
 
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, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() 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, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() 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, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() More...
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() More...
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::parse() 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...
 
keycode_t AbortKey
 code of key to abort prompts, normally Ctrl-G 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 }
int n
Definition: acutest.h:477
+ 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:87
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:773
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
int n
Definition: acutest.h:477
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
+ 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:61
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:870
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:120
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:689
const char * name
Definition: pgpmicalg.c:46
const char * name
name of the function
Definition: keymap.h:119
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:679
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:119
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:689
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:87
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
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:679
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1264
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:117
+ 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:897
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:812
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:849
int op
function id number
Definition: keymap.h:120
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:1094
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:897
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:812
#define _(a)
Definition: message.h:28
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:38
bool MonitorFilesChanged
true after a monitored file has changed
Definition: monitor.c:50
Pager pager (email viewer)
Definition: keymap.h:78
const char * mutt_get_func(const struct Binding *bindings, int op)
Get the name of a function.
Definition: keymap.c:501
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:55
int LastKey
contains the last key the user pressed
Definition: keymap.c:146
short op
operation to perform
Definition: keymap.h: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:156
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
struct Keymap * next
next key in map
Definition: keymap.h:50
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:152
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:188
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
int n
Definition: acutest.h:477
#define mutt_error(...)
Definition: logging.h:84
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:145
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:604
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1264
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:831
Text entry area.
Definition: keymap.h:74
const char * name
Definition: mapping.h:31
Mapping between a user key and a function.
Definition: keymap.h:117
+ 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:120
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:119
const char * seq
default key binding
Definition: keymap.h:121
+ 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: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:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_init_abort_key()

void mutt_init_abort_key ( void  )

Parse the abort_key config string.

Parse the string into C_AbortKey and put the keycode into AbortKey.

Definition at line 825 of file keymap.c.

826 {
827  keycode_t buf[2];
828  size_t len = parsekeys(C_AbortKey, buf, mutt_array_size(buf));
829  if (len == 0)
830  {
831  mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
832  AbortKey = ctrl('G');
833  return;
834  }
835  if (len > 1)
836  {
837  mutt_warning(
838  _("Specified abort key sequence (%s) will be truncated to first key"), C_AbortKey);
839  }
840  AbortKey = buf[0];
841 }
#define mutt_warning(...)
Definition: logging.h:82
#define _(a)
Definition: message.h:28
WHERE char * C_AbortKey
Config: String representation of key to abort prompts.
Definition: globals.h:97
#define mutt_array_size(x)
Definition: memory.h:33
static size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: keymap.c:270
#define ctrl(ch)
Definition: mutt_curses.h:66
short keycode_t
Definition: keymap.h:37
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:147
#define mutt_error(...)
Definition: logging.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_abort_key_config_observer()

int mutt_abort_key_config_observer ( struct NotifyCallback nc)

Listen for abort_key config changes - Implements observer_t.

Definition at line 846 of file keymap.c.

847 {
848  if (!nc->event_data)
849  return -1;
850  if (nc->event_type != NT_CONFIG)
851  return 0;
852 
853  struct EventConfig *ec = nc->event_data;
854 
855  if (mutt_str_strcmp(ec->name, "abort_key") != 0)
856  return 0;
857 
859  return 0;
860 }
A config-change event.
Definition: subset.h:70
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:41
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: keymap.c:825
void * event_data
Data from notify_send()
Definition: observer.h:43
Config has changed.
Definition: notify_type.h:34
const char * name
Name of config item that changed.
Definition: subset.h:73
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
+ 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 870 of file keymap.c.

871 {
872  if (!map)
873  return 0;
874 
875  int p = 0;
876 
877  while (true)
878  {
879  mutt_str_strfcpy(s, km_keyname(map->keys[p]), len);
880  const size_t l = mutt_str_strlen(s);
881  len -= l;
882 
883  if ((++p >= map->len) || !len)
884  return 1;
885 
886  s += l;
887  }
888 
889  /* not reached */
890 }
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:689
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:773
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 898 of file keymap.c.

899 {
900  struct Keymap *map = Keymaps[menu];
901 
902  for (; map; map = map->next)
903  if (map->op == func)
904  break;
905  return map;
906 }
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 939 of file keymap.c.

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

969 {
970  memset(Keymaps, 0, sizeof(struct Keymap *) * MENU_MAX);
971 
980 
983 
986 
987 #ifdef CRYPT_BACKEND_GPGME
990 #endif
991 
992 #ifdef MIXMASTER
994 
995  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
996  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
997  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
998 #endif
999 
1000 #ifdef USE_AUTOCRYPT
1002 #endif
1003 
1004  /* bindings for the line editor */
1006 
1007  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
1008  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
1009  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
1010  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
1011  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
1012  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
1013  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1014  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
1015  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1016 
1017  /* generic menu keymap */
1019 
1020  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
1021  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
1022  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
1023  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
1024  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
1025  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
1026  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
1027  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
1028  km_bindkey("1", MENU_GENERIC, OP_JUMP);
1029  km_bindkey("2", MENU_GENERIC, OP_JUMP);
1030  km_bindkey("3", MENU_GENERIC, OP_JUMP);
1031  km_bindkey("4", MENU_GENERIC, OP_JUMP);
1032  km_bindkey("5", MENU_GENERIC, OP_JUMP);
1033  km_bindkey("6", MENU_GENERIC, OP_JUMP);
1034  km_bindkey("7", MENU_GENERIC, OP_JUMP);
1035  km_bindkey("8", MENU_GENERIC, OP_JUMP);
1036  km_bindkey("9", MENU_GENERIC, OP_JUMP);
1037 
1038  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1039  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1040 
1041  /* Miscellaneous extra bindings */
1042 
1043  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1044  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1045  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1046  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1047  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1048  km_bindkey("x", MENU_MAIN, OP_EXIT);
1049 
1050  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1051  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1052 
1053  km_bindkey("x", MENU_PAGER, OP_EXIT);
1054  km_bindkey("i", MENU_PAGER, OP_EXIT);
1055  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1056  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1057  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1058  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1059  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1060  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1061  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1062  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1063  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1064  km_bindkey("1", MENU_PAGER, OP_JUMP);
1065  km_bindkey("2", MENU_PAGER, OP_JUMP);
1066  km_bindkey("3", MENU_PAGER, OP_JUMP);
1067  km_bindkey("4", MENU_PAGER, OP_JUMP);
1068  km_bindkey("5", MENU_PAGER, OP_JUMP);
1069  km_bindkey("6", MENU_PAGER, OP_JUMP);
1070  km_bindkey("7", MENU_PAGER, OP_JUMP);
1071  km_bindkey("8", MENU_PAGER, OP_JUMP);
1072  km_bindkey("9", MENU_PAGER, OP_JUMP);
1073 
1074  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1075  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1076 
1077  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1078  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1079  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1080 
1081  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1082  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1083  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1084  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1085 
1086  /* edit-to (default "t") hides generic tag-entry in Compose menu
1087  * This will bind tag-entry to "T" in the Compose menu */
1088  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1089 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:262
PGP encryption menu.
Definition: keymap.h:81
#define WithCrypto
Definition: lib.h:163
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:636
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 OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:452
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:645
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 OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:657
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:531
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:55
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:522
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
Select an attachment.
Definition: keymap.h:72
Select a PGP key.
Definition: keymap.h:84
static void create_bindings(const struct Binding *map, enum MenuType menu)
Attach a set of keybindings to a Menu.
Definition: keymap.c:775
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:593
Select an email address by its alias.
Definition: keymap.h:71
A keyboard mapping.
Definition: keymap.h:46
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:604
Create/edit a Mixmaster chain.
Definition: keymap.h:88
Select a SMIME key.
Definition: keymap.h:85
Text entry area.
Definition: keymap.h:74
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:104
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:673
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:540
Select a postponed email.
Definition: keymap.h:79
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:416
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 1095 of file keymap.c.

1096 {
1097  char buf[128];
1098  int p, op;
1099 
1100  struct Keymap *key = km_find_func(menu, OP_HELP);
1101  if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER))
1102  key = km_find_func(MENU_GENERIC, OP_HELP);
1103  if (!key)
1104  {
1105  mutt_error(_("Key is not bound"));
1106  return;
1107  }
1108 
1109  /* Make sure the key is really the help key in this menu.
1110  *
1111  * OP_END_COND is used as a barrier to ensure nothing extra
1112  * is left in the unget buffer.
1113  *
1114  * Note that km_expand_key() + tokenize_unget_string() should
1115  * not be used here: control sequences are expanded to a form
1116  * (e.g. "^H") not recognized by km_dokey(). */
1117  mutt_unget_event(0, OP_END_COND);
1118  p = key->len;
1119  while (p--)
1120  mutt_unget_event(key->keys[p], 0);
1121 
1122  /* Note, e.g. for the index menu:
1123  * bind generic ? noop
1124  * bind generic ,a help
1125  * bind index ,ab quit
1126  * The index keybinding shadows the generic binding.
1127  * OP_END_COND will be read and returned as the op.
1128  *
1129  * bind generic ? noop
1130  * bind generic dq help
1131  * bind index d delete-message
1132  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1133  * in the unget buffer.
1134  */
1135  op = km_dokey(menu);
1136  if (op != OP_END_COND)
1138  if (op != OP_HELP)
1139  {
1140  mutt_error(_("Key is not bound"));
1141  return;
1142  }
1143 
1144  km_expand_key(buf, sizeof(buf), key);
1145  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1146 }
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:812
#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:898
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:870
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:885
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,
intptr_t  data,
struct Buffer err 
)

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

Definition at line 1151 of file keymap.c.

1153 {
1155  if (MoreArgs(s))
1156  {
1157  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1158  return MUTT_CMD_ERROR;
1159  }
1160 
1162  return MUTT_CMD_SUCCESS;
1163 }
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:849
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:43
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:72
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:416
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 1179 of file keymap.c.

1181 {
1182  struct Buffer buf;
1183  int i = 0;
1184  char *q = NULL;
1185 
1186  mutt_buffer_init(&buf);
1187 
1188  /* menu name */
1190  char *p = buf.data;
1191  if (MoreArgs(s))
1192  {
1193  while (i < max_menus)
1194  {
1195  q = strchr(p, ',');
1196  if (q)
1197  *q = '\0';
1198 
1199  int val = mutt_map_get_value(p, Menus);
1200  if (val == -1)
1201  {
1202  mutt_buffer_printf(err, _("%s: no such menu"), p);
1203  goto error;
1204  }
1205  menu[i] = val;
1206  i++;
1207  if (q)
1208  p = q + 1;
1209  else
1210  break;
1211  }
1212  *num_menus = i;
1213  /* key sequence */
1215 
1216  if (buf.data[0] == '\0')
1217  {
1218  mutt_buffer_printf(err, _("%s: null key sequence"), bind ? "bind" : "macro");
1219  }
1220  else if (MoreArgs(s))
1221  return buf.data;
1222  }
1223  else
1224  {
1225  mutt_buffer_printf(err, _("%s: too few arguments"), bind ? "bind" : "macro");
1226  }
1227 error:
1228  FREE(&buf.data);
1229  return NULL;
1230 }
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:61
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:416
#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:70
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
+ 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 1241 of file keymap.c.

1243 {
1244  for (int i = 0; bindings[i].name; i++)
1245  {
1246  if (mutt_str_strcmp(func, bindings[i].name) == 0)
1247  {
1248  return km_bindkey_err(key, menu, bindings[i].op, err);
1249  }
1250  }
1251  if (err)
1252  {
1253  mutt_buffer_printf(err, _("Function '%s' not available for menu '%s'"),
1254  func, mutt_map_get_name(menu, Menus));
1255  }
1256  return MUTT_CMD_ERROR; /* Couldn't find an existing function with this name */
1257 }
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:46
const char * name
name of the function
Definition: keymap.h:119
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
+ 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 1264 of file keymap.c.

1265 {
1266  switch (menu)
1267  {
1268  case MENU_ALIAS:
1269  return OpAlias;
1270  case MENU_ATTACH:
1271  return OpAttach;
1272 #ifdef USE_AUTOCRYPT
1273  case MENU_AUTOCRYPT_ACCT:
1274  return OpAutocryptAcct;
1275 #endif
1276  case MENU_COMPOSE:
1277  return OpCompose;
1278  case MENU_EDITOR:
1279  return OpEditor;
1280  case MENU_FOLDER:
1281  return OpBrowser;
1282  case MENU_GENERIC:
1283  return OpGeneric;
1284 #ifdef CRYPT_BACKEND_GPGME
1285  case MENU_KEY_SELECT_PGP:
1286  return OpPgp;
1287  case MENU_KEY_SELECT_SMIME:
1288  return OpSmime;
1289 #endif
1290  case MENU_MAIN:
1291  return OpMain;
1292 #ifdef MIXMASTER
1293  case MENU_MIX:
1294  return OpMix;
1295 #endif
1296  case MENU_PAGER:
1297  return OpPager;
1298  case MENU_PGP:
1299  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1300  case MENU_POSTPONE:
1301  return OpPost;
1302  case MENU_QUERY:
1303  return OpQuery;
1304  default:
1305  return NULL;
1306  }
1307 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:262
PGP encryption menu.
Definition: keymap.h:81
#define WithCrypto
Definition: lib.h:163
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:636
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 OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:452
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:645
Pager pager (email viewer)
Definition: keymap.h:78
Select from results of external query.
Definition: keymap.h:80
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:657
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:531
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:55
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:522
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
Select an attachment.
Definition: keymap.h:72
Select a PGP key.
Definition: keymap.h:84
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:593
Select an email address by its alias.
Definition: keymap.h:71
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:604
Create/edit a Mixmaster chain.
Definition: keymap.h:88
Select a SMIME key.
Definition: keymap.h:85
Text entry area.
Definition: keymap.h:74
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:104
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:673
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:540
Select a postponed email.
Definition: keymap.h:79
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:416
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,
intptr_t  data,
struct Buffer err 
)

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

bind menu-name <key_sequence> function-name

Definition at line 1314 of file keymap.c.

1316 {
1317  const struct Binding *bindings = NULL;
1318  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1319  int num_menus = 0;
1320  enum CommandResult rc = MUTT_CMD_SUCCESS;
1321 
1322  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true);
1323  if (!key)
1324  return MUTT_CMD_ERROR;
1325 
1326  /* function to execute */
1328  if (MoreArgs(s))
1329  {
1330  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1331  rc = MUTT_CMD_ERROR;
1332  }
1333  else if (mutt_str_strcasecmp("noop", buf->data) == 0)
1334  {
1335  for (int i = 0; i < num_menus; i++)
1336  {
1337  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1338  }
1339  }
1340  else
1341  {
1342  for (int i = 0; i < num_menus; i++)
1343  {
1344  /* The pager and editor menus don't use the generic map,
1345  * however for other menus try generic first. */
1346  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1347  {
1348  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1349  if (rc == 0)
1350  continue;
1351  if (rc == -2)
1352  break;
1353  }
1354 
1355  /* Clear any error message, we're going to try again */
1356  err->data[0] = '\0';
1357  bindings = km_get_table(menu[i]);
1358  if (bindings)
1359  {
1360  rc = try_bind(key, menu[i], buf->data, bindings, err);
1361  }
1362  }
1363  }
1364  FREE(&key);
1365  return rc;
1366 }
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:1179
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 Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:55
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:416
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:1241
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:651
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1264
#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:117
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
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 1376 of file keymap.c.

1377 {
1378  char *menu_names_dup = mutt_str_strdup(s);
1379  char *marker = menu_names_dup;
1380  char *menu_name = NULL;
1381 
1382  while ((menu_name = strsep(&marker, ",")))
1383  {
1384  int value = mutt_map_get_value(menu_name, Menus);
1385  if (value == -1)
1386  {
1387  mutt_buffer_printf(err, _("%s: no such menu"), menu_name);
1388  break;
1389  }
1390  else
1391  menu[value] = true;
1392  }
1393 
1394  FREE(&menu_names_dup);
1395  return NULL;
1396 }
#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:61
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:85
+ 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 1405 of file keymap.c.

1406 {
1407  struct Keymap *next = NULL;
1408  struct Keymap *first = NULL;
1409  struct Keymap *last = NULL;
1410  struct Keymap *cur = *map;
1411 
1412  while (cur)
1413  {
1414  next = cur->next;
1415  if (((mode & MUTT_UNBIND) && !cur->macro) || ((mode & MUTT_UNMACRO) && cur->macro))
1416  {
1417  FREE(&cur->macro);
1418  FREE(&cur->keys);
1419  FREE(&cur->desc);
1420  FREE(&cur);
1421  }
1422  else if (!first)
1423  {
1424  first = cur;
1425  last = cur;
1426  }
1427  else if (last)
1428  {
1429  last->next = cur;
1430  last = cur;
1431  }
1432  else
1433  {
1434  last = cur;
1435  }
1436  cur = next;
1437  }
1438 
1439  if (last)
1440  last->next = NULL;
1441 
1442  *map = first;
1443 }
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,
intptr_t  data,
struct Buffer err 
)

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

Command unbinds:

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

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

Definition at line 1455 of file keymap.c.

1457 {
1458  bool menu[MENU_MAX] = { 0 };
1459  bool all_keys = false;
1460  char *key = NULL;
1461 
1463  if (mutt_str_strcmp(buf->data, "*") == 0)
1464  {
1465  for (enum MenuType i = 0; i < MENU_MAX; i++)
1466  menu[i] = true;
1467  }
1468  else
1469  parse_menu(menu, buf->data, err);
1470 
1471  if (MoreArgs(s))
1472  {
1474  key = buf->data;
1475  }
1476  else
1477  all_keys = true;
1478 
1479  if (MoreArgs(s))
1480  {
1481  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1482 
1483  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1484  return MUTT_CMD_ERROR;
1485  }
1486 
1487  for (enum MenuType i = 0; i < MENU_MAX; i++)
1488  {
1489  if (!menu[i])
1490  continue;
1491  if (all_keys)
1492  {
1493  km_unbind_all(&Keymaps[i], data);
1494  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1495  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1496  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1497  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1498  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1499  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1500  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1501  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1502  if (i != MENU_EDITOR)
1503  {
1504  km_bindkey("?", i, OP_HELP);
1505  km_bindkey("q", i, OP_EXIT);
1506  }
1507  }
1508  else
1509  km_bindkey(key, i, OP_NULL);
1510  }
1511 
1512  return MUTT_CMD_SUCCESS;
1513 }
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:1405
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:416
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:1376
Text entry area.
Definition: keymap.h:74
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
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,
intptr_t  data,
struct Buffer err 
)

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

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

Definition at line 1520 of file keymap.c.

1522 {
1523  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1524  int num_menus = 0;
1525  enum CommandResult rc = MUTT_CMD_ERROR;
1526  char *seq = NULL;
1527 
1528  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false);
1529  if (!key)
1530  return MUTT_CMD_ERROR;
1531 
1533  /* make sure the macro sequence is not an empty string */
1534  if (buf->data[0] == '\0')
1535  {
1536  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1537  }
1538  else
1539  {
1540  if (MoreArgs(s))
1541  {
1542  seq = mutt_str_strdup(buf->data);
1544 
1545  if (MoreArgs(s))
1546  {
1547  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1548  }
1549  else
1550  {
1551  for (int i = 0; i < num_menus; i++)
1552  {
1553  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1554  }
1555  }
1556 
1557  FREE(&seq);
1558  }
1559  else
1560  {
1561  for (int i = 0; i < num_menus; i++)
1562  {
1563  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1564  }
1565  }
1566  }
1567  FREE(&key);
1568  return rc;
1569 }
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:1179
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define mutt_array_size(x)
Definition: memory.h:33
#define MoreArgs(buf)
Definition: buffer.h:43
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:72
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:61
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:416
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,
intptr_t  data,
struct Buffer err 
)

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

Definition at line 1574 of file keymap.c.

1576 {
1577  int ops[128];
1578  int nops = 0;
1579  const struct Binding *bindings = NULL;
1580  char *function = NULL;
1581 
1582  if (!MoreArgs(s))
1583  {
1584  mutt_buffer_strcpy(err, _("exec: no arguments"));
1585  return MUTT_CMD_ERROR;
1586  }
1587 
1588  do
1589  {
1591  function = buf->data;
1592 
1593  bindings = km_get_table(CurrentMenu);
1594  if (!bindings && (CurrentMenu != MENU_PAGER))
1595  bindings = OpGeneric;
1596 
1597  ops[nops] = get_op(bindings, function, mutt_str_strlen(function));
1598  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1599  ops[nops] = get_op(OpGeneric, function, mutt_str_strlen(function));
1600 
1601  if (ops[nops] == OP_NULL)
1602  {
1603  mutt_flushinp();
1604  mutt_error(_("%s: no such function"), function);
1605  return MUTT_CMD_ERROR;
1606  }
1607  nops++;
1608  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1609 
1610  while (nops)
1611  mutt_push_macro_event(0, ops[--nops]);
1612 
1613  return MUTT_CMD_SUCCESS;
1614 }
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:849
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:897
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:689
#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.c:55
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:416
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:1264
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:117
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
+ 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 1621 of file keymap.c.

1622 {
1623  int ch;
1624 
1625  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (%s to abort): "),
1626  km_keyname(AbortKey));
1627  do
1628  {
1629  ch = getch();
1630  if ((ch != ERR) && (ch != AbortKey))
1631  {
1632  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1633  }
1634  } while (ch != ERR && ch != AbortKey);
1635 
1636  mutt_flushinp();
1637  mutt_clear_error();
1638 }
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:897
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:147
int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt,...)
Move the cursor and write a formatted string to a Window.
Definition: mutt_window.c:311
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_keys_free()

void mutt_keys_free ( void  )

Free the key maps.

Definition at line 1643 of file keymap.c.

1644 {
1645  struct Keymap *map = NULL;
1646  struct Keymap *next = NULL;
1647 
1648  for (int i = 0; i < MENU_MAX; i++)
1649  {
1650  for (map = Keymaps[i]; map; map = next)
1651  {
1652  next = map->next;
1653 
1654  FREE(&map->macro);
1655  FREE(&map->desc);
1656  FREE(&map->keys);
1657  FREE(&map);
1658  }
1659 
1660  Keymaps[i] = NULL;
1661  }
1662 }
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 },
{ "key_select_pgp", MENU_KEY_SELECT_PGP },
{ "key_select_smime", MENU_KEY_SELECT_SMIME },
{ "mix", MENU_MIX },
{ "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 a PGP key.
Definition: keymap.h:84
Select an email address by its alias.
Definition: keymap.h:71
Create/edit a Mixmaster chain.
Definition: keymap.h:88
Select a SMIME key.
Definition: keymap.h:85
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 61 of file keymap.c.

◆ KeyNames

struct Mapping KeyNames[]
static

Key name lookup table.

Definition at line 87 of file keymap.c.

◆ LastKey

int LastKey

contains the last key the user pressed

Last real key pressed, recorded by dokey()

Definition at line 146 of file keymap.c.

◆ AbortKey

keycode_t AbortKey

code of key to abort prompts, normally Ctrl-G

key to abort edits etc, normally Ctrl-G

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.