NeoMutt  2021-02-05-329-g9e03b7
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 "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "keymap.h"
#include "menu/lib.h"
#include "ncrypt/lib.h"
#include "functions.h"
#include "init.h"
#include "mutt_commands.h"
#include "mutt_globals.h"
#include "mutt_logging.h"
#include "opcodes.h"
#include "options.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 void mutt_keymap_free (struct Keymap **km)
 Free a Keymap. More...
 
static void mutt_keymaplist_free (struct KeymapList *km_list)
 Free a List of Keymaps. More...
 
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 struct Keymapkm_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos)
 Compare two keymaps' keyscodes and return the bigger one. 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 KeymapList *km_list, 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 KeymapList Keymaps [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

◆ mutt_keymap_free()

static void mutt_keymap_free ( struct Keymap **  km)
static

Free a Keymap.

Parameters
kmKeymap to free

Definition at line 205 of file keymap.c.

206 {
207  if (!km || !*km)
208  return;
209 
210  FREE(&(*km)->macro);
211  FREE(&(*km)->desc);
212  FREE(&(*km)->keys);
213  FREE(km);
214 }
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ mutt_keymaplist_free()

static void mutt_keymaplist_free ( struct KeymapList *  km_list)
static

Free a List of Keymaps.

Parameters
km_listList of Keymaps to free

Definition at line 220 of file keymap.c.

221 {
222  struct Keymap *np = NULL, *tmp = NULL;
223  STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
224  {
225  STAILQ_REMOVE(km_list, np, Keymap, entries);
226  mutt_keymap_free(&np);
227  }
228 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
A keyboard mapping.
Definition: keymap.h:47
static void mutt_keymap_free(struct Keymap **km)
Free a Keymap.
Definition: keymap.c:205
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

237 {
238  struct Keymap *p = mutt_mem_calloc(1, sizeof(struct Keymap));
239  p->len = len;
240  p->keys = mutt_mem_calloc(len, sizeof(keycode_t));
241  memcpy(p->keys, keys, len * sizeof(keycode_t));
242  return p;
243 }
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
short keycode_t
Definition: keymap.h:38
A keyboard mapping.
Definition: keymap.h:47
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 252 of file keymap.c.

253 {
254  char *t = NULL;
255  int n = 0;
256 
257  if ((s[0] != '<') || (tolower(s[1]) != 'f'))
258  return -1;
259 
260  for (t = s + 2; *t && isdigit((unsigned char) *t); t++)
261  {
262  n *= 10;
263  n += *t - '0';
264  }
265 
266  if (*t != '>')
267  return -1;
268  return n;
269 }
+ 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 279 of file keymap.c.

280 {
281  char *end_char = NULL;
282  long int result = strtol(s + 1, &end_char, 8);
283  /* allow trailing whitespace, eg. < 1001 > */
284  while (IS_SPACE(*end_char))
285  end_char++;
286  /* negative keycodes don't make sense, also detect overflow */
287  if ((*end_char != '>') || (result < 0) || (result == LONG_MAX))
288  {
289  return -1;
290  }
291 
292  return result;
293 }
#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 302 of file keymap.c.

303 {
304  int n;
305  size_t len = max;
306  char buf[128];
307  char c;
308  char *t = NULL;
309 
310  mutt_str_copy(buf, str, sizeof(buf));
311  char *s = buf;
312 
313  while (*s && len)
314  {
315  *d = '\0';
316  if ((*s == '<') && (t = strchr(s, '>')))
317  {
318  t++;
319  c = *t;
320  *t = '\0';
321 
323  if (n != -1)
324  {
325  s = t;
326  *d = n;
327  }
328  else if ((n = parse_fkey(s)) > 0)
329  {
330  s = t;
331  *d = KEY_F(n);
332  }
333  else if ((n = parse_keycode(s)) > 0)
334  {
335  s = t;
336  *d = n;
337  }
338 
339  *t = c;
340  }
341 
342  if (!*d)
343  {
344  *d = (unsigned char) *s;
345  s++;
346  }
347  d++;
348  len--;
349  }
350 
351  return max - len;
352 }
static int parse_keycode(const char *s)
Parse a numeric keycode.
Definition: keymap.c:279
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:90
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:252
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:716
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_compare_keys()

static struct Keymap* km_compare_keys ( struct Keymap k1,
struct Keymap k2,
size_t *  pos 
)
static

Compare two keymaps' keyscodes and return the bigger one.

Parameters
k1first keymap to compare
k2second keymap to compare
posposition where the two keycodes differ
Return values
ptrKeymap with a bigger ASCII keycode

Definition at line 361 of file keymap.c.

362 {
363  while (*pos < k1->len && *pos < k2->len)
364  {
365  if (k1->keys[*pos] < k2->keys[*pos])
366  return k2;
367  else if (k1->keys[*pos] > k2->keys[*pos])
368  return k1;
369  else
370  *pos = *pos + 1;
371  }
372 
373  return NULL;
374 }
keycode_t * keys
key sequence
Definition: keymap.h:54
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
+ 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 389 of file keymap.c.

391 {
393  struct Keymap *last = NULL, *np = NULL, *compare = NULL;
394  keycode_t buf[MAX_SEQ];
395  size_t pos = 0, lastpos = 0;
396 
397  size_t len = parsekeys(s, buf, MAX_SEQ);
398 
399  struct Keymap *map = alloc_keys(len, buf);
400  map->op = op;
401  map->macro = mutt_str_dup(macro);
402  map->desc = mutt_str_dup(desc);
403 
404  /* find position to place new keymap */
405  STAILQ_FOREACH(np, &Keymaps[menu], entries)
406  {
407  compare = km_compare_keys(map, np, &pos);
408 
409  if (compare == map) /* map's keycode is bigger */
410  {
411  last = np;
412  lastpos = pos;
413  if (pos > np->eq)
414  pos = np->eq;
415  }
416  else if (compare == np) /* np's keycode is bigger, found insert location */
417  {
418  map->eq = pos;
419  break;
420  }
421  else /* equal keycodes */
422  {
423  /* Don't warn on overwriting a 'noop' binding */
424  if ((np->len != len) && (np->op != OP_NULL))
425  {
426  /* Overwrite with the different lengths, warn */
427  /* TODO: MAX_SEQ here is wrong */
428  char old_binding[MAX_SEQ];
429  char new_binding[MAX_SEQ];
430  km_expand_key(old_binding, MAX_SEQ, map);
431  km_expand_key(new_binding, MAX_SEQ, np);
432  char *err_msg =
433  _("Binding '%s' will alias '%s' Before, try: 'bind %s %s noop' "
434  "https://neomutt.org/guide/configuration.html#bind-warnings");
435  if (err)
436  {
437  /* err was passed, put the string there */
438  snprintf(err->data, err->dsize, err_msg, old_binding, new_binding,
439  mutt_map_get_name(menu, Menus), new_binding);
440  }
441  else
442  {
443  mutt_error(err_msg, old_binding, new_binding,
444  mutt_map_get_name(menu, Menus), new_binding);
445  }
446  rc = MUTT_CMD_WARNING;
447  }
448 
449  map->eq = np->eq;
450  STAILQ_REMOVE(&Keymaps[menu], np, Keymap, entries);
451  mutt_keymap_free(&np);
452  break;
453  }
454  }
455 
456  if (last) /* if queue has at least one entry */
457  {
458  if (STAILQ_NEXT(last, entries))
459  STAILQ_INSERT_AFTER(&Keymaps[menu], last, map, entries);
460  else /* last entry in the queue */
461  STAILQ_INSERT_TAIL(&Keymaps[menu], map, entries);
462  last->eq = lastpos;
463  }
464  else /* queue is empty, so insert from head */
465  {
466  STAILQ_INSERT_HEAD(&Keymaps[menu], map, entries);
467  }
468 
469  return rc;
470 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:52
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:386
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:302
short op
operation to perform
Definition: keymap.h:51
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
static struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition: keymap.c:236
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:921
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:49
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:380
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
short keycode_t
Definition: keymap.h:38
char * desc
description of a macro for the help menu
Definition: keymap.h:50
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
A keyboard mapping.
Definition: keymap.h:47
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define mutt_error(...)
Definition: logging.h:84
static void mutt_keymap_free(struct Keymap **km)
Free a Keymap.
Definition: keymap.c:205
static struct Keymap * km_compare_keys(struct Keymap *k1, struct Keymap *k2, size_t *pos)
Compare two keymaps&#39; keyscodes and return the bigger one.
Definition: keymap.c:361
#define MAX_SEQ
Definition: keymap.h:35
#define STAILQ_INSERT_AFTER(head, tqelm, elm, field)
Definition: queue.h:374
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_bind()

enum CommandResult km_bind ( char *  s,
enum MenuType  menu,
int  op,
char *  macro,
char *  desc 
)

Bind a key to a macro.

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

Definition at line 481 of file keymap.c.

482 {
483  return km_bind_err(s, menu, op, macro, desc, NULL);
484 }
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:389
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:49
char * desc
description of a macro for the help menu
Definition: keymap.h:50
+ 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 494 of file keymap.c.

496 {
497  return km_bind_err(s, menu, op, NULL, NULL, err);
498 }
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:389
+ 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 507 of file keymap.c.

508 {
509  return km_bindkey_err(s, menu, op, NULL);
510 }
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:494
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 519 of file keymap.c.

520 {
521  for (int i = 0; bindings[i].name; i++)
522  {
523  if (mutt_istrn_equal(start, bindings[i].name, len) &&
524  (mutt_str_len(bindings[i].name) == len))
525  {
526  return bindings[i].op;
527  }
528  }
529 
530  return OP_NULL;
531 }
int op
function id number
Definition: keymap.h:123
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:621
const char * name
name of the function
Definition: keymap.h:122
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
+ 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 542 of file keymap.c.

543 {
544  for (int i = 0; bindings[i].name; i++)
545  {
546  if (bindings[i].op == op)
547  return bindings[i].name;
548  }
549 
550  return NULL;
551 }
const char * name
name of the function
Definition: keymap.h:122
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 562 of file keymap.c.

563 {
564  char *pp = NULL;
565  char *p = s + mutt_str_len(s) - 1;
566  size_t l;
567  int i, op = OP_NULL;
568 
569  while (p >= s)
570  {
571  /* if we see something like "<PageUp>", look to see if it is a real
572  * function name and return the corresponding value */
573  if (*p == '>')
574  {
575  for (pp = p - 1; pp >= s && *pp != '<'; pp--)
576  ; // do nothing
577 
578  if (pp >= s)
579  {
580  i = parse_fkey(pp);
581  if (i > 0)
582  {
583  generic_push(KEY_F(i), 0);
584  p = pp - 1;
585  continue;
586  }
587 
588  l = p - pp + 1;
589  for (i = 0; KeyNames[i].name; i++)
590  {
591  if (mutt_istrn_equal(pp, KeyNames[i].name, l))
592  break;
593  }
594  if (KeyNames[i].name)
595  {
596  /* found a match */
597  generic_push(KeyNames[i].value, 0);
598  p = pp - 1;
599  continue;
600  }
601 
602  /* See if it is a valid command
603  * skip the '<' and the '>' when comparing */
604  for (enum MenuType j = 0; Menus[j].name; j++)
605  {
606  const struct Binding *binding = km_get_table(Menus[j].value);
607  if (binding)
608  {
609  op = get_op(binding, pp + 1, l - 2);
610  if (op != OP_NULL)
611  break;
612  }
613  }
614 
615  if (op != OP_NULL)
616  {
617  generic_push(0, op);
618  p = pp - 1;
619  continue;
620  }
621  }
622  }
623  generic_push((unsigned char) *p--, 0); /* independent 8 bits chars */
624  }
625 }
MenuType
Types of GUI selections.
Definition: keymap.h:72
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:621
short op
operation to perform
Definition: keymap.h:51
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:90
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:252
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1316
const char * name
Definition: mapping.h:33
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:519
Mapping between a user key and a function.
Definition: keymap.h:120
+ 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 635 of file keymap.c.

636 {
637  if ((menu != MENU_EDITOR) && (menu != MENU_GENERIC) && (menu != MENU_PAGER))
638  {
639  if (lastkey)
640  mutt_unget_event(lastkey, 0);
641  for (; keyslen; keyslen--)
642  mutt_unget_event(keys[keyslen - 1], 0);
643  return km_dokey(MENU_GENERIC);
644  }
645  if (menu != MENU_EDITOR)
646  {
647  /* probably a good idea to flush input here so we can abort macros */
648  mutt_flushinp();
649  }
650  return OP_NULL;
651 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:661
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:810
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:725
Pager pager (email viewer)
Definition: keymap.h:81
Text entry area.
Definition: keymap.h:77
Generic selection list.
Definition: keymap.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey()

int km_dokey ( enum MenuType  menu)

Determine what a keypress should do.

Parameters
menuMenu ID, e.g. MENU_EDITOR
Return values
>0Function to execute
OP_NULLNo function bound to key sequence
-1Error occurred while reading input
-2A timeout or sigwinch occurred

Definition at line 661 of file keymap.c.

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

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

824 {
825  STAILQ_INIT(&Keymaps[menu]);
826 
827  for (int i = 0; map[i].name; i++)
828  if (map[i].seq)
829  km_bindkey(map[i].seq, menu, map[i].op);
830 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
int op
function id number
Definition: keymap.h:123
static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:507
#define STAILQ_INIT(head)
Definition: queue.h:369
const char * name
name of the function
Definition: keymap.h:122
const char * seq
default key binding
Definition: keymap.h:124
+ 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 839 of file keymap.c.

840 {
841  static char buf[35];
842 
843  const char *p = mutt_map_get_name(c, KeyNames);
844  if (p)
845  return p;
846 
847  if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
848  {
849  if (c < 0)
850  c += 256;
851 
852  if (c < 128)
853  {
854  buf[0] = '^';
855  buf[1] = (c + '@') & 0x7f;
856  buf[2] = '\0';
857  }
858  else
859  snprintf(buf, sizeof(buf), "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
860  }
861  else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
862  sprintf(buf, "<F%d>", c - KEY_F0);
863  else if (IsPrint(c))
864  snprintf(buf, sizeof(buf), "%c", (unsigned char) c);
865  else
866  snprintf(buf, sizeof(buf), "\\x%hx", (unsigned short) c);
867  return buf;
868 }
#define IsPrint(ch)
Definition: mbyte.h:38
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_init_abort_key()

void mutt_init_abort_key ( void  )

Parse the abort_key config string.

Parse the string into $abort_key and put the keycode into AbortKey.

Definition at line 875 of file keymap.c.

876 {
877  keycode_t buf[2];
878  const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
879  size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
880  if (len == 0)
881  {
882  mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
883  AbortKey = ctrl('G');
884  return;
885  }
886  if (len > 1)
887  {
888  mutt_warning(
889  _("Specified abort key sequence (%s) will be truncated to first key"), c_abort_key);
890  }
891  AbortKey = buf[0];
892 }
#define mutt_warning(...)
Definition: logging.h:82
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define mutt_array_size(x)
Definition: memory.h:33
static size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: keymap.c:302
#define ctrl(ch)
Definition: mutt_curses.h:66
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:295
short keycode_t
Definition: keymap.h:38
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:150
#define mutt_error(...)
Definition: logging.h:84
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_abort_key_config_observer()

int mutt_abort_key_config_observer ( struct NotifyCallback nc)

Listen for abort_key config changes - Implements observer_t.

Definition at line 897 of file keymap.c.

898 {
899  if (!nc->event_data)
900  return -1;
901  if (nc->event_type != NT_CONFIG)
902  return 0;
903 
904  struct EventConfig *ec = nc->event_data;
905 
906  if (!mutt_str_equal(ec->name, "abort_key"))
907  return 0;
908 
910  return 0;
911 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
A config-change event.
Definition: subset.h:70
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: keymap.c:875
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:41
const char * name
Name of config item that changed.
Definition: subset.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_expand_key()

int km_expand_key ( char *  s,
size_t  len,
struct Keymap map 
)

Get the key string bound to a Keymap.

Parameters
sBuffer for the key string
lenLength of buffer
mapKeybinding map
Return values
1Success
0Error

Definition at line 921 of file keymap.c.

922 {
923  if (!map)
924  return 0;
925 
926  int p = 0;
927 
928  while (true)
929  {
930  mutt_str_copy(s, km_keyname(map->keys[p]), len);
931  const size_t l = mutt_str_len(s);
932  len -= l;
933 
934  if ((++p >= map->len) || !len)
935  return 1;
936 
937  s += l;
938  }
939 
940  /* not reached */
941 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:839
keycode_t * keys
key sequence
Definition: keymap.h:54
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:716
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_find_func()

struct Keymap* km_find_func ( enum MenuType  menu,
int  func 
)

Find a function's mapping in a Menu.

Parameters
menuMenu id, e.g. MENU_PAGER
funcFunction, e.g. OP_DELETE
Return values
ptrKeymap for the function

Definition at line 949 of file keymap.c.

950 {
951  struct Keymap *np = NULL;
952  STAILQ_FOREACH(np, &Keymaps[menu], entries)
953  {
954  if (np->op == func)
955  break;
956  }
957  return np;
958 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
short op
operation to perform
Definition: keymap.h:51
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
A keyboard mapping.
Definition: keymap.h:47
+ Here is the caller graph for this function:

◆ init_extended_keys()

void init_extended_keys ( void  )

Initialise map of ncurses extended keys.

Determine the keycodes for ncurses extended keys and fill in the KeyNames array.

This function must be called after initscr(), or tigetstr() returns -1. This creates a bit of a chicken-and-egg problem because km_init() is called prior to start_curses(). This means that the default keybindings can't include any of the extended keys because they won't be defined until later.

Definition at line 991 of file keymap.c.

992 {
993 #ifdef NCURSES_VERSION
994  use_extended_names(true);
995 
996  for (int j = 0; KeyNames[j].name; j++)
997  {
998  if (KeyNames[j].value == -1)
999  {
1000  const char *keyname = find_ext_name(KeyNames[j].name);
1001 
1002  if (keyname)
1003  {
1004  char *s = tigetstr((char *) keyname);
1005  if (s && ((long) (s) != -1))
1006  {
1007  int code = key_defined(s);
1008  if (code > 0)
1009  KeyNames[j].value = code;
1010  }
1011  }
1012  }
1013  }
1014 #endif
1015 }
int value
Definition: mapping.h:34
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:90
const char * name
Definition: mapping.h:33
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 1020 of file keymap.c.

1021 {
1022  memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
1023 
1032 
1035 
1038 
1039 #ifdef CRYPT_BACKEND_GPGME
1042 #endif
1043 
1044 #ifdef MIXMASTER
1046 
1047  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
1048  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
1049  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
1050 #endif
1051 
1052 #ifdef USE_AUTOCRYPT
1054 #endif
1055 
1056  /* bindings for the line editor */
1058 
1059  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
1060  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
1061  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
1062  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
1063  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
1064  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
1065  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1066  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
1067  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1068 
1069  /* generic menu keymap */
1071 
1072  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
1073  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
1074  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
1075  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
1076  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
1077  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
1078  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
1079  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
1080  km_bindkey("1", MENU_GENERIC, OP_JUMP);
1081  km_bindkey("2", MENU_GENERIC, OP_JUMP);
1082  km_bindkey("3", MENU_GENERIC, OP_JUMP);
1083  km_bindkey("4", MENU_GENERIC, OP_JUMP);
1084  km_bindkey("5", MENU_GENERIC, OP_JUMP);
1085  km_bindkey("6", MENU_GENERIC, OP_JUMP);
1086  km_bindkey("7", MENU_GENERIC, OP_JUMP);
1087  km_bindkey("8", MENU_GENERIC, OP_JUMP);
1088  km_bindkey("9", MENU_GENERIC, OP_JUMP);
1089 
1090  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1091  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1092 
1093  /* Miscellaneous extra bindings */
1094 
1095  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
1096  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
1097  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
1098  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
1099  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
1100  km_bindkey("x", MENU_MAIN, OP_EXIT);
1101 
1102  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1103  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1104 
1105  km_bindkey("x", MENU_PAGER, OP_EXIT);
1106  km_bindkey("i", MENU_PAGER, OP_EXIT);
1107  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
1108  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
1109  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1110  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1111  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1112  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1113  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1114  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1115  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1116  km_bindkey("1", MENU_PAGER, OP_JUMP);
1117  km_bindkey("2", MENU_PAGER, OP_JUMP);
1118  km_bindkey("3", MENU_PAGER, OP_JUMP);
1119  km_bindkey("4", MENU_PAGER, OP_JUMP);
1120  km_bindkey("5", MENU_PAGER, OP_JUMP);
1121  km_bindkey("6", MENU_PAGER, OP_JUMP);
1122  km_bindkey("7", MENU_PAGER, OP_JUMP);
1123  km_bindkey("8", MENU_PAGER, OP_JUMP);
1124  km_bindkey("9", MENU_PAGER, OP_JUMP);
1125 
1126  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1127  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1128 
1129  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1130  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1131  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1132 
1133  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1134  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1135  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1136  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1137 
1138  /* edit-to (default "t") hides generic tag-entry in Compose menu
1139  * This will bind tag-entry to "T" in the Compose menu */
1140  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1141 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:262
PGP encryption menu.
Definition: keymap.h:84
#define WithCrypto
Definition: lib.h:113
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:646
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
General file/mailbox browser.
Definition: keymap.h:78
Autocrypt Account menu.
Definition: keymap.h:94
Compose an email.
Definition: keymap.h:76
Index panel (list of emails)
Definition: keymap.h:80
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:456
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:655
static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:507
SMIME encryption menu.
Definition: keymap.h:85
Pager pager (email viewer)
Definition: keymap.h:81
Select from results of external query.
Definition: keymap.h:83
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:667
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:535
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:526
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
Select an attachment.
Definition: keymap.h:75
Select a PGP key.
Definition: keymap.h:87
static void create_bindings(const struct Binding *map, enum MenuType menu)
Attach a set of keybindings to a Menu.
Definition: keymap.c:823
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:600
Select an email address by its alias.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:614
Create/edit a Mixmaster chain.
Definition: keymap.h:91
Select a SMIME key.
Definition: keymap.h:88
Text entry area.
Definition: keymap.h:77
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:102
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:683
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:547
Select a postponed email.
Definition: keymap.h:82
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:419
Generic selection list.
Definition: keymap.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_error_key()

void km_error_key ( enum MenuType  menu)

Handle an unbound key sequence.

Parameters
menuMenu id, e.g. MENU_PAGER

Definition at line 1147 of file keymap.c.

1148 {
1149  char buf[128];
1150  int p, op;
1151 
1152  struct Keymap *key = km_find_func(menu, OP_HELP);
1153  if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER))
1154  key = km_find_func(MENU_GENERIC, OP_HELP);
1155  if (!key)
1156  {
1157  mutt_error(_("Key is not bound"));
1158  return;
1159  }
1160 
1161  /* Make sure the key is really the help key in this menu.
1162  *
1163  * OP_END_COND is used as a barrier to ensure nothing extra
1164  * is left in the unget buffer.
1165  *
1166  * Note that km_expand_key() + tokenize_unget_string() should
1167  * not be used here: control sequences are expanded to a form
1168  * (e.g. "^H") not recognized by km_dokey(). */
1169  mutt_unget_event(0, OP_END_COND);
1170  p = key->len;
1171  while (p--)
1172  mutt_unget_event(key->keys[p], 0);
1173 
1174  /* Note, e.g. for the index menu:
1175  * bind generic ? noop
1176  * bind generic ,a help
1177  * bind index ,ab quit
1178  * The index keybinding shadows the generic binding.
1179  * OP_END_COND will be read and returned as the op.
1180  *
1181  * bind generic ? noop
1182  * bind generic dq help
1183  * bind index d delete-message
1184  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1185  * in the unget buffer.
1186  */
1187  op = km_dokey(menu);
1188  if (op != OP_END_COND)
1190  if (op != OP_HELP)
1191  {
1192  mutt_error(_("Key is not bound"));
1193  return;
1194  }
1195 
1196  km_expand_key(buf, sizeof(buf), key);
1197  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1198 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:661
keycode_t * keys
key sequence
Definition: keymap.h:54
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:725
#define _(a)
Definition: message.h:28
Pager pager (email viewer)
Definition: keymap.h:81
short op
operation to perform
Definition: keymap.h:51
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function&#39;s mapping in a Menu.
Definition: keymap.c:949
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:921
A keyboard mapping.
Definition: keymap.h:47
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
#define mutt_error(...)
Definition: logging.h:84
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: curs_lib.c:798
Text entry area.
Definition: keymap.h:77
Generic selection list.
Definition: keymap.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_push()

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

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

Definition at line 1203 of file keymap.c.

1205 {
1207  if (MoreArgs(s))
1208  {
1209  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1210  return MUTT_CMD_ERROR;
1211  }
1212 
1214  return MUTT_CMD_SUCCESS;
1215 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:762
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:40
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:68
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a &#39;push&#39; command.
Definition: keymap.c:562
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

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

1233 {
1234  struct Buffer buf;
1235  int i = 0;
1236  char *q = NULL;
1237 
1238  mutt_buffer_init(&buf);
1239 
1240  /* menu name */
1242  char *p = buf.data;
1243  if (MoreArgs(s))
1244  {
1245  while (i < max_menus)
1246  {
1247  q = strchr(p, ',');
1248  if (q)
1249  *q = '\0';
1250 
1251  int val = mutt_map_get_value(p, Menus);
1252  if (val == -1)
1253  {
1254  mutt_buffer_printf(err, _("%s: no such menu"), p);
1255  goto error;
1256  }
1257  menu[i] = val;
1258  i++;
1259  if (q)
1260  p = q + 1;
1261  else
1262  break;
1263  }
1264  *num_menus = i;
1265  /* key sequence */
1267 
1268  if (buf.data[0] == '\0')
1269  {
1270  mutt_buffer_printf(err, _("%s: null key sequence"), bind ? "bind" : "macro");
1271  }
1272  else if (MoreArgs(s))
1273  return buf.data;
1274  }
1275  else
1276  {
1277  mutt_buffer_printf(err, _("%s: too few arguments"), bind ? "bind" : "macro");
1278  }
1279 error:
1280  FREE(&buf.data);
1281  return NULL;
1282 }
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:40
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
#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:66
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 1293 of file keymap.c.

1295 {
1296  for (int i = 0; bindings[i].name; i++)
1297  {
1298  if (mutt_str_equal(func, bindings[i].name))
1299  {
1300  return km_bindkey_err(key, menu, bindings[i].op, err);
1301  }
1302  }
1303  if (err)
1304  {
1305  mutt_buffer_printf(err, _("Function '%s' not available for menu '%s'"),
1306  func, mutt_map_get_name(menu, Menus));
1307  }
1308  return MUTT_CMD_ERROR; /* Couldn't find an existing function with this name */
1309 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
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:494
#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
name of the function
Definition: keymap.h:122
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_get_table()

const struct Binding* km_get_table ( enum MenuType  menu)

Lookup a menu's keybindings.

Parameters
menuMenu id, e.g. MENU_EDITOR
Return values
ptrArray of keybindings

Definition at line 1316 of file keymap.c.

1317 {
1318  switch (menu)
1319  {
1320  case MENU_ALIAS:
1321  return OpAlias;
1322  case MENU_ATTACH:
1323  return OpAttach;
1324 #ifdef USE_AUTOCRYPT
1325  case MENU_AUTOCRYPT_ACCT:
1326  return OpAutocryptAcct;
1327 #endif
1328  case MENU_COMPOSE:
1329  return OpCompose;
1330  case MENU_EDITOR:
1331  return OpEditor;
1332  case MENU_FOLDER:
1333  return OpBrowser;
1334  case MENU_GENERIC:
1335  return OpGeneric;
1336 #ifdef CRYPT_BACKEND_GPGME
1337  case MENU_KEY_SELECT_PGP:
1338  return OpPgp;
1339  case MENU_KEY_SELECT_SMIME:
1340  return OpSmime;
1341 #endif
1342  case MENU_MAIN:
1343  return OpMain;
1344 #ifdef MIXMASTER
1345  case MENU_MIX:
1346  return OpMix;
1347 #endif
1348  case MENU_PAGER:
1349  return OpPager;
1350  case MENU_PGP:
1351  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1352  case MENU_POSTPONE:
1353  return OpPost;
1354  case MENU_QUERY:
1355  return OpQuery;
1356  default:
1357  return NULL;
1358  }
1359 }
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.c:262
PGP encryption menu.
Definition: keymap.h:84
#define WithCrypto
Definition: lib.h:113
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.c:646
General file/mailbox browser.
Definition: keymap.h:78
Autocrypt Account menu.
Definition: keymap.h:94
Compose an email.
Definition: keymap.h:76
Index panel (list of emails)
Definition: keymap.h:80
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.c:456
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.c:655
Pager pager (email viewer)
Definition: keymap.h:81
Select from results of external query.
Definition: keymap.h:83
const struct Binding OpMix[]
Key bindings for the mixmaster menu.
Definition: functions.c:667
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.c:535
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.c:526
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
Select an attachment.
Definition: keymap.h:75
Select a PGP key.
Definition: keymap.h:87
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.c:600
Select an email address by its alias.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.c:614
Create/edit a Mixmaster chain.
Definition: keymap.h:91
Select a SMIME key.
Definition: keymap.h:88
Text entry area.
Definition: keymap.h:77
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.c:102
const struct Binding OpAutocryptAcct[]
Key bindings for the autocrypt account.
Definition: functions.c:683
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.c:547
Select a postponed email.
Definition: keymap.h:82
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.c:419
Generic selection list.
Definition: keymap.h:79
+ Here is the caller graph for this function:

◆ mutt_parse_bind()

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

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

bind menu-name <key_sequence> function-name

Definition at line 1366 of file keymap.c.

1368 {
1369  const struct Binding *bindings = NULL;
1370  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1371  int num_menus = 0;
1372  enum CommandResult rc = MUTT_CMD_SUCCESS;
1373 
1374  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, true);
1375  if (!key)
1376  return MUTT_CMD_ERROR;
1377 
1378  /* function to execute */
1380  if (MoreArgs(s))
1381  {
1382  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1383  rc = MUTT_CMD_ERROR;
1384  }
1385  else if (mutt_istr_equal("noop", buf->data))
1386  {
1387  for (int i = 0; i < num_menus; i++)
1388  {
1389  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1390  bindings = km_get_table(menu[i]);
1391  if (bindings)
1392  {
1393  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1394  struct EventBinding ev_bind = { menu[i], key, op };
1396  }
1397  }
1398  }
1399  else
1400  {
1401  for (int i = 0; i < num_menus; i++)
1402  {
1403  /* The pager and editor menus don't use the generic map,
1404  * however for other menus try generic first. */
1405  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1406  {
1407  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1408  if (rc == MUTT_CMD_SUCCESS)
1409  {
1410  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1411  struct EventBinding ev_bind = { menu[i], key, op };
1413  continue;
1414  }
1415  if (rc == MUTT_CMD_WARNING)
1416  break;
1417  }
1418 
1419  /* Clear any error message, we're going to try again */
1420  err->data[0] = '\0';
1421  bindings = km_get_table(menu[i]);
1422  if (bindings)
1423  {
1424  rc = try_bind(key, menu[i], buf->data, bindings, err);
1425  if (rc == MUTT_CMD_SUCCESS)
1426  {
1427  int op = get_op(bindings, buf->data, mutt_str_len(buf->data));
1428  struct EventBinding ev_bind = { menu[i], key, op };
1430  continue;
1431  }
1432  }
1433  }
1434  }
1435  FREE(&key);
1436  return rc;
1437 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
int op
function id number
Definition: keymap.h:123
A key binding has been created.
Definition: keymap.h:144
int op
Operation the key&#39;s bound to (for bind), e.g. OP_DELETE.
Definition: keymap.h:134
#define _(a)
Definition: message.h:28
static char * parse_keymap(enum MenuType *menu, struct Buffer *s, int max_menus, int *num_menus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1231
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:133
#define mutt_array_size(x)
Definition: memory.h:33
static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:507
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:40
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
A key binding has been deleted.
Definition: keymap.h:145
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
static enum CommandResult try_bind(char *key, enum MenuType menu, char *func, const struct Binding *bindings, struct Buffer *err)
Try to make a key binding.
Definition: keymap.c:1293
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1316
#define FREE(x)
Definition: memory.h:40
Mapping between user-readable string and a constant.
Definition: mapping.h:31
Text entry area.
Definition: keymap.h:77
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:519
Mapping between a user key and a function.
Definition: keymap.h:120
A key binding Event.
Definition: keymap.h:130
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
Generic selection list.
Definition: keymap.h:79
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:

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

1448 {
1449  char *menu_names_dup = mutt_str_dup(s);
1450  char *marker = menu_names_dup;
1451  char *menu_name = NULL;
1452 
1453  while ((menu_name = strsep(&marker, ",")))
1454  {
1455  int value = mutt_map_get_value(menu_name, Menus);
1456  if (value == -1)
1457  {
1458  mutt_buffer_printf(err, _("%s: no such menu"), menu_name);
1459  break;
1460  }
1461  else
1462  menu[value] = true;
1463  }
1464 
1465  FREE(&menu_names_dup);
1466  return NULL;
1467 }
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#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
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition: keymap.h:132
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
#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 KeymapList *  km_list,
unsigned long  mode 
)
static

Free all the keys in the supplied Keymap.

Parameters
km_listKeymap 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 1476 of file keymap.c.

1477 {
1478  struct Keymap *np = NULL, *tmp = NULL;
1479 
1480  STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
1481  {
1482  if (((mode & MUTT_UNBIND) && !np->macro) || ((mode & MUTT_UNMACRO) && np->macro))
1483  {
1484  STAILQ_REMOVE(km_list, np, Keymap, entries);
1485  mutt_keymap_free(&np);
1486  }
1487  }
1488 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
#define MUTT_UNMACRO
Definition: keymap.h:33
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:49
A keyboard mapping.
Definition: keymap.h:47
static void mutt_keymap_free(struct Keymap **km)
Free a Keymap.
Definition: keymap.c:205
#define MUTT_UNBIND
Definition: keymap.h:32
+ Here is the call graph for this function:
+ 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 1500 of file keymap.c.

1502 {
1503  bool menu[MENU_MAX] = { 0 };
1504  bool all_keys = false;
1505  char *key = NULL;
1506 
1508  if (mutt_str_equal(buf->data, "*"))
1509  {
1510  for (enum MenuType i = 0; i < MENU_MAX; i++)
1511  menu[i] = true;
1512  }
1513  else
1514  parse_menu(menu, buf->data, err);
1515 
1516  if (MoreArgs(s))
1517  {
1519  key = buf->data;
1520  }
1521  else
1522  all_keys = true;
1523 
1524  if (MoreArgs(s))
1525  {
1526  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1527 
1528  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1529  return MUTT_CMD_ERROR;
1530  }
1531 
1532  for (enum MenuType i = 0; i < MENU_MAX; i++)
1533  {
1534  if (!menu[i])
1535  continue;
1536  if (all_keys)
1537  {
1538  km_unbind_all(&Keymaps[i], data);
1539  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1540  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1541  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1542  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1543  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1544  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1545  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1546  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1547  if (i != MENU_EDITOR)
1548  {
1549  km_bindkey("?", i, OP_HELP);
1550  km_bindkey("q", i, OP_EXIT);
1551  }
1552  struct EventBinding ev_bind = { i, NULL, OP_NULL };
1555  &ev_bind);
1556  }
1557  else
1558  {
1559  km_bindkey(key, i, OP_NULL);
1560  struct EventBinding ev_bind = { i, key, OP_NULL };
1562  (data & MUTT_UNMACRO) ? NT_MACRO_DELETED : NT_BINDING_DELETED, &ev_bind);
1563  }
1564  }
1565 
1566  return MUTT_CMD_SUCCESS;
1567 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
#define _(a)
Definition: message.h:28
A key macro has been deleted.
Definition: keymap.h:149
Index panel (list of emails)
Definition: keymap.h:80
#define MUTT_UNMACRO
Definition: keymap.h:33
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
All key bindings are about to be deleted.
Definition: keymap.h:146
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:133
static enum CommandResult km_bindkey(const char *s, enum MenuType menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:507
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:40
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
All key macros are about to be deleted.
Definition: keymap.h:150
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
A key binding has been deleted.
Definition: keymap.h:145
Success: Command worked.
Definition: mutt_commands.h:38
static void * parse_menu(bool *menu, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1447
Text entry area.
Definition: keymap.h:77
A key binding Event.
Definition: keymap.h:130
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
static void km_unbind_all(struct KeymapList *km_list, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1476
Generic selection list.
Definition: keymap.h:79
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:

◆ mutt_parse_macro()

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

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

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

Definition at line 1574 of file keymap.c.

1576 {
1577  enum MenuType menu[sizeof(Menus) / sizeof(struct Mapping) - 1];
1578  int num_menus = 0;
1579  enum CommandResult rc = MUTT_CMD_ERROR;
1580 
1581  char *key = parse_keymap(menu, s, mutt_array_size(menu), &num_menus, err, false);
1582  if (!key)
1583  return MUTT_CMD_ERROR;
1584 
1586  /* make sure the macro sequence is not an empty string */
1587  if (buf->data[0] == '\0')
1588  {
1589  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1590  }
1591  else
1592  {
1593  if (MoreArgs(s))
1594  {
1595  char *seq = mutt_str_dup(buf->data);
1597 
1598  if (MoreArgs(s))
1599  {
1600  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1601  }
1602  else
1603  {
1604  for (int i = 0; i < num_menus; i++)
1605  {
1606  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1607  if (rc == MUTT_CMD_SUCCESS)
1608  {
1609  struct EventBinding ev_bind = { menu[i], key, OP_MACRO };
1611  continue;
1612  }
1613  }
1614  }
1615 
1616  FREE(&seq);
1617  }
1618  else
1619  {
1620  for (int i = 0; i < num_menus; i++)
1621  {
1622  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1623  if (rc == MUTT_CMD_SUCCESS)
1624  {
1625  struct EventBinding ev_bind = { menu[i], key, OP_MACRO };
1627  continue;
1628  }
1629  }
1630  }
1631  }
1632  FREE(&key);
1633  return rc;
1634 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
static char * parse_keymap(enum MenuType *menu, struct Buffer *s, int max_menus, int *num_menus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1231
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:133
#define mutt_array_size(x)
Definition: memory.h:33
#define MoreArgs(buf)
Definition: buffer.h:40
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition: keymap.h:132
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:68
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:64
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:38
#define FREE(x)
Definition: memory.h:40
Mapping between user-readable string and a constant.
Definition: mapping.h:31
enum CommandResult km_bind(char *s, enum MenuType menu, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: keymap.c:481
A key macro has been created.
Definition: keymap.h:148
A key binding Event.
Definition: keymap.h:130
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:

◆ mutt_parse_exec()

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

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

Definition at line 1639 of file keymap.c.

1641 {
1642  int ops[128];
1643  int nops = 0;
1644  const struct Binding *bindings = NULL;
1645  char *function = NULL;
1646 
1647  if (!MoreArgs(s))
1648  {
1649  mutt_buffer_strcpy(err, _("exec: no arguments"));
1650  return MUTT_CMD_ERROR;
1651  }
1652 
1653  do
1654  {
1656  function = buf->data;
1657 
1658  const enum MenuType mtype = menu_get_current_type();
1659  bindings = km_get_table(mtype);
1660  if (!bindings && (mtype != MENU_PAGER))
1661  bindings = OpGeneric;
1662 
1663  ops[nops] = get_op(bindings, function, mutt_str_len(function));
1664  if ((ops[nops] == OP_NULL) && (mtype != MENU_PAGER))
1665  ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
1666 
1667  if (ops[nops] == OP_NULL)
1668  {
1669  mutt_flushinp();
1670  mutt_error(_("%s: no such function"), function);
1671  return MUTT_CMD_ERROR;
1672  }
1673  nops++;
1674  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1675 
1676  while (nops)
1677  mutt_push_macro_event(0, ops[--nops]);
1678 
1679  return MUTT_CMD_SUCCESS;
1680 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
MenuType
Types of GUI selections.
Definition: keymap.h:72
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:762
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:810
#define _(a)
Definition: message.h:28
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h:81
#define MoreArgs(buf)
Definition: buffer.h:40
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
Success: Command worked.
Definition: mutt_commands.h:38
#define mutt_error(...)
Definition: logging.h:84
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1316
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:519
Mapping between a user key and a function.
Definition: keymap.h:120
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ mutt_what_key()

void mutt_what_key ( void  )

Ask the user to press a key.

Displays the octal value back to the user.

Definition at line 1687 of file keymap.c.

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

◆ mutt_keys_free()

void mutt_keys_free ( void  )

Free the key maps.

Definition at line 1709 of file keymap.c.

1710 {
1711  for (int i = 0; i < MENU_MAX; i++)
1712  {
1714  }
1715 }
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:152
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: keymap.c:220
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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:84
General file/mailbox browser.
Definition: keymap.h:78
Compose an email.
Definition: keymap.h:76
Index panel (list of emails)
Definition: keymap.h:80
SMIME encryption menu.
Definition: keymap.h:85
Pager pager (email viewer)
Definition: keymap.h:81
Select from results of external query.
Definition: keymap.h:83
Select an attachment.
Definition: keymap.h:75
Select a PGP key.
Definition: keymap.h:87
Select an email address by its alias.
Definition: keymap.h:74
Create/edit a Mixmaster chain.
Definition: keymap.h:91
Select a SMIME key.
Definition: keymap.h:88
Text entry area.
Definition: keymap.h:77
Select a postponed email.
Definition: keymap.h:82
Generic selection list.
Definition: keymap.h:79

Menu name lookup table.

Definition at line 64 of file keymap.c.

◆ KeyNames

struct Mapping KeyNames[]
static

Key name lookup table.

Definition at line 90 of file keymap.c.

◆ LastKey

int LastKey

contains the last key the user pressed

Last real key pressed, recorded by dokey()

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

◆ Keymaps

struct KeymapList Keymaps[MENU_MAX]

Array of Keymap keybindings, one for each Menu.

Definition at line 152 of file keymap.c.