NeoMutt  2018-07-16 +2388-bcedc8
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 <strings.h>
#include "mutt/mutt.h"
#include "mutt.h"
#include "keymap.h"
#include "curs_lib.h"
#include "functions.h"
#include "globals.h"
#include "mutt_commands.h"
#include "mutt_curses.h"
#include "mutt_logging.h"
#include "mutt_window.h"
#include "ncrypt/ncrypt.h"
#include "opcodes.h"
#include "options.h"
#include "imap/imap.h"
+ Include dependency graph for keymap.c:

Go to the source code of this file.

Functions

static struct Keymapalloc_keys (size_t len, keycode_t *keys)
 Allocate space for a sequence of keys. More...
 
static int parse_fkey (char *s)
 Parse a function key string. More...
 
static int parse_keycode (const char *s)
 Parse a numeric keycode. More...
 
static size_t parsekeys (const char *str, keycode_t *d, size_t max)
 Parse a key string into key codes. More...
 
static enum CommandResult km_bind_err (const char *s, int menu, int op, char *macro, char *desc, struct Buffer *err)
 Set up a key binding. More...
 
enum CommandResult km_bind (char *s, int menu, int op, char *macro, char *desc)
 Bind a key to a macro. More...
 
static enum CommandResult km_bindkey_err (const char *s, int 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, int 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 (int menu, keycode_t *keys, int keyslen, int lastkey)
 Try to find the key in the generic menu bindings. More...
 
int km_dokey (int menu)
 Determine what a keypress should do. More...
 
static void create_bindings (const struct Binding *map, int menu)
 Attach a set of keybindings to a Menu. More...
 
static const char * km_keyname (int c)
 Get the human name for a key. More...
 
int km_expand_key (char *s, size_t len, struct Keymap *map)
 Get the key string bound to a Keymap. More...
 
struct Keymapkm_find_func (int 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 (int menu)
 Handle an unbound key sequence. More...
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'push' command - Implements command_t. More...
 
static char * parse_keymap (int *menu, struct Buffer *s, int maxmenus, int *nummenus, struct Buffer *err, bool bind)
 Parse a user-config key binding. More...
 
static enum CommandResult try_bind (char *key, int menu, char *func, const struct Binding *bindings, struct Buffer *err)
 Try to make a key binding. More...
 
const struct Bindingkm_get_table (int menu)
 Lookup a menu's keybindings. More...
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'bind' command - Implements command_t. More...
 
static void * parse_menu (int *menu, char *s, struct Buffer *err)
 Parse menu-names into an array. More...
 
static void km_unbind_all (struct Keymap **map, unsigned long mode)
 Free all the keys in the supplied Keymap. More...
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unbind' command - Implements command_t. More...
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'macro' command - Implements command_t. More...
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'exec' command - Implements command_t. More...
 
void mutt_what_key (void)
 Ask the user to press a key. More...
 
void mutt_free_keys (void)
 Free the key maps. More...
 

Variables

const struct Mapping Menus []
 Menu name lookup table. More...
 
static struct Mapping KeyNames []
 Key name lookup table. More...
 
int LastKey
 contains the last key the user pressed More...
 
struct KeymapKeymaps [MENU_MAX]
 Array of Keymap keybindings, one for each Menu. More...
 

Detailed Description

Manage keymappings.

Authors
  • Michael R. Elkins

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file keymap.c.

Function Documentation

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

156 {
157  struct Keymap *p = mutt_mem_calloc(1, sizeof(struct Keymap));
158  p->len = len;
159  p->keys = mutt_mem_malloc(len * sizeof(keycode_t));
160  memcpy(p->keys, keys, len * sizeof(keycode_t));
161  return p;
162 }
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:57
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:49
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

172 {
173  char *t = NULL;
174  int n = 0;
175 
176  if ((s[0] != '<') || (tolower(s[1]) != 'f'))
177  return -1;
178 
179  for (t = s + 2; *t && isdigit((unsigned char) *t); t++)
180  {
181  n *= 10;
182  n += *t - '0';
183  }
184 
185  if (*t != '>')
186  return -1;
187  else
188  return n;
189 }

+ Here is the caller graph for this function:

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

200 {
201  char *end_char = NULL;
202  long int result = strtol(s + 1, &end_char, 8);
203  /* allow trailing whitespace, eg. < 1001 > */
204  while (IS_SPACE(*end_char))
205  end_char++;
206  /* negative keycodes don't make sense, also detect overflow */
207  if ((*end_char != '>') || (result < 0) || (result == LONG_MAX))
208  {
209  return -1;
210  }
211 
212  return result;
213 }
#define IS_SPACE(ch)
Definition: string2.h:38

+ Here is the caller graph for this function:

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

223 {
224  int n;
225  size_t len = max;
226  char buf[128];
227  char c;
228  char *t = NULL;
229 
230  mutt_str_strfcpy(buf, str, sizeof(buf));
231  char *s = buf;
232 
233  while (*s && len)
234  {
235  *d = '\0';
236  if ((*s == '<') && (t = strchr(s, '>')))
237  {
238  t++;
239  c = *t;
240  *t = '\0';
241 
243  if (n != -1)
244  {
245  s = t;
246  *d = n;
247  }
248  else if ((n = parse_fkey(s)) > 0)
249  {
250  s = t;
251  *d = KEY_F(n);
252  }
253  else if ((n = parse_keycode(s)) > 0)
254  {
255  s = t;
256  *d = n;
257  }
258 
259  *t = c;
260  }
261 
262  if (!*d)
263  {
264  *d = (unsigned char) *s;
265  s++;
266  }
267  d++;
268  len--;
269  }
270 
271  return max - len;
272 }
static int parse_keycode(const char *s)
Parse a numeric keycode.
Definition: keymap.c:199
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:86
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:171
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:56
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static enum CommandResult km_bind_err ( const char *  s,
int  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 287 of file keymap.c.

289 {
291  struct Keymap *last = NULL, *next = NULL;
292  keycode_t buf[MAX_SEQ];
293  size_t pos = 0, lastpos = 0;
294 
295  size_t len = parsekeys(s, buf, MAX_SEQ);
296 
297  struct Keymap *map = alloc_keys(len, buf);
298  map->op = op;
299  map->macro = mutt_str_strdup(macro);
300  map->desc = mutt_str_strdup(desc);
301 
302  struct Keymap *tmp = Keymaps[menu];
303 
304  while (tmp)
305  {
306  if ((pos >= len) || (pos >= tmp->len))
307  {
308  /* map and tmp match so overwrite */
309  do
310  {
311  /* Don't warn on overwriting a 'noop' binding */
312  if ((tmp->len != len) && (tmp->op != OP_NULL))
313  {
314  /* Overwrite with the different lengths, warn */
315  /* TODO: MAX_SEQ here is wrong */
316  char old_binding[MAX_SEQ];
317  char new_binding[MAX_SEQ];
318  km_expand_key(old_binding, MAX_SEQ, map);
319  km_expand_key(new_binding, MAX_SEQ, tmp);
320  if (err)
321  {
322  /* err was passed, put the string there */
323  snprintf(
324  err->data, err->dsize,
325  _("Binding '%s' will alias '%s' Before, try: 'bind %s %s "
326  "noop' "
327  "https://neomutt.org/guide/configuration.html#bind-warnings"),
328  old_binding, new_binding, mutt_map_get_name(menu, Menus), new_binding);
329  }
330  else
331  {
332  mutt_error(
333  _("Binding '%s' will alias '%s' Before, try: 'bind %s %s "
334  "noop' "
335  "https://neomutt.org/guide/configuration.html#bind-warnings"),
336  old_binding, new_binding, mutt_map_get_name(menu, Menus), new_binding);
337  }
338  rc = MUTT_CMD_WARNING;
339  }
340  len = tmp->eq;
341  next = tmp->next;
342  FREE(&tmp->macro);
343  FREE(&tmp->keys);
344  FREE(&tmp->desc);
345  FREE(&tmp);
346  tmp = next;
347  } while (tmp && len >= pos);
348  map->eq = len;
349  break;
350  }
351  else if (buf[pos] == tmp->keys[pos])
352  pos++;
353  else if (buf[pos] < tmp->keys[pos])
354  {
355  /* found location to insert between last and tmp */
356  map->eq = pos;
357  break;
358  }
359  else /* buf[pos] > tmp->keys[pos] */
360  {
361  last = tmp;
362  lastpos = pos;
363  if (pos > tmp->eq)
364  pos = tmp->eq;
365  tmp = tmp->next;
366  }
367  }
368 
369  map->next = tmp;
370  if (last)
371  {
372  last->next = map;
373  last->eq = lastpos;
374  }
375  else
376  {
377  Keymaps[menu] = map;
378  }
379 
380  return rc;
381 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:55
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
keycode_t * keys
key sequence
Definition: keymap.h:57
#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:222
short op
operation to perform
Definition: keymap.h:54
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
struct Keymap * next
next key in map
Definition: keymap.h:53
static struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition: keymap.c:155
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:779
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:51
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:52
A keyboard mapping.
Definition: keymap.h:49
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:56
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:

enum CommandResult km_bind ( char *  s,
int  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 392 of file keymap.c.

393 {
394  return km_bind_err(s, menu, op, macro, desc, NULL);
395 }
static enum CommandResult km_bind_err(const char *s, int menu, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition: keymap.c:287
short op
operation to perform
Definition: keymap.h:54
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:51
char * desc
description of a macro for the help menu
Definition: keymap.h:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static enum CommandResult km_bindkey_err ( const char *  s,
int  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 405 of file keymap.c.

406 {
407  return km_bind_err(s, menu, op, NULL, NULL, err);
408 }
static enum CommandResult km_bind_err(const char *s, int menu, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition: keymap.c:287
short op
operation to perform
Definition: keymap.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static enum CommandResult km_bindkey ( const char *  s,
int  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 417 of file keymap.c.

418 {
419  return km_bindkey_err(s, menu, op, NULL);
420 }
short op
operation to perform
Definition: keymap.h:54
static enum CommandResult km_bindkey_err(const char *s, int menu, int op, struct Buffer *err)
Bind a key in a Menu to an operation (with error message)
Definition: keymap.c:405

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

430 {
431  for (int i = 0; bindings[i].name; i++)
432  {
433  if ((mutt_str_strncasecmp(start, bindings[i].name, len) == 0) &&
434  (mutt_str_strlen(bindings[i].name) == len))
435  {
436  return bindings[i].op;
437  }
438  }
439 
440  return OP_NULL;
441 }
int op
function id number
Definition: keymap.h:108
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h:107
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

453 {
454  for (int i = 0; bindings[i].name; i++)
455  {
456  if (bindings[i].op == op)
457  return bindings[i].name;
458  }
459 
460  return NULL;
461 }
const char * name
name of the function
Definition: keymap.h:107
short op
operation to perform
Definition: keymap.h:54

+ Here is the caller graph for this function:

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

473 {
474  char *pp = NULL;
475  char *p = s + mutt_str_strlen(s) - 1;
476  size_t l;
477  int i, op = OP_NULL;
478 
479  while (p >= s)
480  {
481  /* if we see something like "<PageUp>", look to see if it is a real
482  * function name and return the corresponding value */
483  if (*p == '>')
484  {
485  for (pp = p - 1; pp >= s && *pp != '<'; pp--)
486  ;
487  if (pp >= s)
488  {
489  i = parse_fkey(pp);
490  if (i > 0)
491  {
492  generic_push(KEY_F(i), 0);
493  p = pp - 1;
494  continue;
495  }
496 
497  l = p - pp + 1;
498  for (i = 0; KeyNames[i].name; i++)
499  {
500  if (mutt_str_strncasecmp(pp, KeyNames[i].name, l) == 0)
501  break;
502  }
503  if (KeyNames[i].name)
504  {
505  /* found a match */
506  generic_push(KeyNames[i].value, 0);
507  p = pp - 1;
508  continue;
509  }
510 
511  /* See if it is a valid command
512  * skip the '<' and the '>' when comparing */
513  for (i = 0; Menus[i].name; i++)
514  {
515  const struct Binding *binding = km_get_table(Menus[i].value);
516  if (binding)
517  {
518  op = get_op(binding, pp + 1, l - 2);
519  if (op != OP_NULL)
520  break;
521  }
522  }
523 
524  if (op != OP_NULL)
525  {
526  generic_push(0, op);
527  p = pp - 1;
528  continue;
529  }
530  }
531  }
532  generic_push((unsigned char) *p--, 0); /* independent 8 bits chars */
533  }
534 }
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
const char * name
Definition: pgpmicalg.c:45
short op
operation to perform
Definition: keymap.h:54
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:86
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
static int parse_fkey(char *s)
Parse a function key string.
Definition: keymap.c:171
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1218
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:429
Mapping between a user key and a function.
Definition: keymap.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int retry_generic ( int  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 544 of file keymap.c.

545 {
546  if ((menu != MENU_EDITOR) && (menu != MENU_GENERIC) && (menu != MENU_PAGER))
547  {
548  if (lastkey)
549  mutt_unget_event(lastkey, 0);
550  for (; keyslen; keyslen--)
551  mutt_unget_event(keys[keyslen - 1], 0);
552  return km_dokey(MENU_GENERIC);
553  }
554  if (menu != MENU_EDITOR)
555  {
556  /* probably a good idea to flush input here so we can abort macros */
557  mutt_flushinp();
558  }
559  return OP_NULL;
560 }
int km_dokey(int menu)
Determine what a keypress should do.
Definition: keymap.c:570
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:715
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:

int km_dokey ( int  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 570 of file keymap.c.

571 {
572  struct KeyEvent tmp;
573  struct Keymap *map = Keymaps[menu];
574  int pos = 0;
575  int n = 0;
576 
577  if (!map && (menu != MENU_EDITOR))
578  return retry_generic(menu, NULL, 0, 0);
579 
580  while (true)
581  {
582  int i = (C_Timeout > 0) ? C_Timeout : 60;
583 #ifdef USE_IMAP
584  /* keepalive may need to run more frequently than C_Timeout allows */
585  if (C_ImapKeepalive)
586  {
587  if (C_ImapKeepalive >= i)
588  imap_keepalive();
589  else
590  {
591  while (C_ImapKeepalive && (C_ImapKeepalive < i))
592  {
594  tmp = mutt_getch();
595  mutt_getch_timeout(-1);
596  /* If a timeout was not received, or the window was resized, exit the
597  * loop now. Otherwise, continue to loop until reaching a total of
598  * $timeout seconds. */
599  if ((tmp.ch != -2) || SigWinch)
600  goto gotkey;
601 #ifdef USE_INOTIFY
603  goto gotkey;
604 #endif
605  i -= C_ImapKeepalive;
606  imap_keepalive();
607  }
608  }
609  }
610 #endif
611 
612  mutt_getch_timeout(i * 1000);
613  tmp = mutt_getch();
614  mutt_getch_timeout(-1);
615 
616 #ifdef USE_IMAP
617  gotkey:
618 #endif
619  /* hide timeouts, but not window resizes, from the line editor. */
620  if ((menu == MENU_EDITOR) && (tmp.ch == -2) && !SigWinch)
621  continue;
622 
623  LastKey = tmp.ch;
624  if (LastKey < 0)
625  return LastKey;
626 
627  /* do we have an op already? */
628  if (tmp.op)
629  {
630  const char *func = NULL;
631  const struct Binding *bindings = NULL;
632 
633  /* is this a valid op for this menu? */
634  if ((bindings = km_get_table(menu)) && (func = mutt_get_func(bindings, tmp.op)))
635  return tmp.op;
636 
637  if ((menu == MENU_EDITOR) && mutt_get_func(OpEditor, tmp.op))
638  return tmp.op;
639 
640  if ((menu != MENU_EDITOR) && (menu != MENU_PAGER))
641  {
642  /* check generic menu */
643  bindings = OpGeneric;
644  func = mutt_get_func(bindings, tmp.op);
645  if (func)
646  return tmp.op;
647  }
648 
649  /* Sigh. Valid function but not in this context.
650  * Find the literal string and push it back */
651  for (i = 0; Menus[i].name; i++)
652  {
653  bindings = km_get_table(Menus[i].value);
654  if (bindings)
655  {
656  func = mutt_get_func(bindings, tmp.op);
657  if (func)
658  {
659  mutt_unget_event('>', 0);
660  mutt_unget_string(func);
661  mutt_unget_event('<', 0);
662  break;
663  }
664  }
665  }
666  /* continue to chew */
667  if (func)
668  continue;
669  }
670 
671  if (!map)
672  return tmp.op;
673 
674  /* Nope. Business as usual */
675  while (LastKey > map->keys[pos])
676  {
677  if ((pos > map->eq) || !map->next)
678  return retry_generic(menu, map->keys, pos, LastKey);
679  map = map->next;
680  }
681 
682  if (LastKey != map->keys[pos])
683  return retry_generic(menu, map->keys, pos, LastKey);
684 
685  if (++pos == map->len)
686  {
687  if (map->op != OP_MACRO)
688  return map->op;
689 
690  /* OptIgnoreMacroEvents turns off processing the MacroEvents buffer
691  * in mutt_getch(). Generating new macro events during that time would
692  * result in undesired behavior once the option is turned off.
693  *
694  * Originally this returned -1, however that results in an unbuffered
695  * username or password prompt being aborted. Returning OP_NULL allows
696  * mutt_enter_string_full() to display the keybinding pressed instead.
697  *
698  * It may be unexpected for a macro's keybinding to be returned,
699  * but less so than aborting the prompt. */
701  {
702  return OP_NULL;
703  }
704 
705  if (n++ == 10)
706  {
707  mutt_flushinp();
708  mutt_error(_("Macro loop detected"));
709  return -1;
710  }
711 
713  map = Keymaps[menu];
714  pos = 0;
715  }
716  }
717 
718  /* not reached */
719 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:55
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:752
int op
function id number
Definition: keymap.h:108
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
keycode_t * keys
key sequence
Definition: keymap.h:57
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:715
#define _(a)
Definition: message.h:28
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:36
bool MonitorFilesChanged
true after a monitored file has changed
Definition: monitor.c:47
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:452
int LastKey
contains the last key the user pressed
Definition: keymap.c:145
short op
operation to perform
Definition: keymap.h:54
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:84
WHERE short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
Definition: globals.h:167
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
struct Keymap * next
next key in map
Definition: keymap.h:53
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1218
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:51
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: globals.h:159
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a &#39;push&#39; command.
Definition: keymap.c:472
An event such as a keypress.
Definition: mutt_curses.h:108
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:175
A keyboard mapping.
Definition: keymap.h:49
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:56
#define mutt_error(...)
Definition: logging.h:84
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:132
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:734
Text entry area.
Definition: keymap.h:74
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:603
const char * name
Definition: mapping.h:31
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:1054
Mapping between a user key and a function.
Definition: keymap.h:105
static int retry_generic(int menu, keycode_t *keys, int keyslen, int lastkey)
Try to find the key in the generic menu bindings.
Definition: keymap.c:544

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void create_bindings ( const struct Binding map,
int  menu 
)
static

Attach a set of keybindings to a Menu.

Parameters
mapKey bindings
menuMenu id, e.g. MENU_PAGER

Definition at line 726 of file keymap.c.

727 {
728  for (int i = 0; map[i].name; i++)
729  if (map[i].seq)
730  km_bindkey(map[i].seq, menu, map[i].op);
731 }
int op
function id number
Definition: keymap.h:108
static enum CommandResult km_bindkey(const char *s, int menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:417
const char * name
name of the function
Definition: keymap.h:107
const char * seq
default key binding
Definition: keymap.h:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

741 {
742  static char buf[35];
743 
744  const char *p = mutt_map_get_name(c, KeyNames);
745  if (p)
746  return p;
747 
748  if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
749  {
750  if (c < 0)
751  c += 256;
752 
753  if (c < 128)
754  {
755  buf[0] = '^';
756  buf[1] = (c + '@') & 0x7f;
757  buf[2] = '\0';
758  }
759  else
760  snprintf(buf, sizeof(buf), "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
761  }
762  else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
763  sprintf(buf, "<F%d>", c - KEY_F0);
764  else if (IsPrint(c))
765  snprintf(buf, sizeof(buf), "%c", (unsigned char) c);
766  else
767  snprintf(buf, sizeof(buf), "\\x%hx", (unsigned short) c);
768  return buf;
769 }
#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:86

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

780 {
781  if (!map)
782  return 0;
783 
784  int p = 0;
785 
786  while (true)
787  {
788  mutt_str_strfcpy(s, km_keyname(map->keys[p]), len);
789  const size_t l = mutt_str_strlen(s);
790  len -= l;
791 
792  if ((++p >= map->len) || !len)
793  return 1;
794 
795  s += l;
796  }
797 
798  /* not reached */
799 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:740
keycode_t * keys
key sequence
Definition: keymap.h:57
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

struct Keymap* km_find_func ( int  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 807 of file keymap.c.

808 {
809  struct Keymap *map = Keymaps[menu];
810 
811  for (; map; map = map->next)
812  if (map->op == func)
813  break;
814  return map;
815 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
short op
operation to perform
Definition: keymap.h:54
struct Keymap * next
next key in map
Definition: keymap.h:53
A keyboard mapping.
Definition: keymap.h:49

+ Here is the caller graph for this function:

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

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

+ Here is the caller graph for this function:

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 923 of file keymap.c.

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void km_error_key ( int  menu)

Handle an unbound key sequence.

Parameters
menuMenu id, e.g. MENU_PAGER

Definition at line 1050 of file keymap.c.

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

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

Parse the 'push' command - Implements command_t.

Definition at line 1106 of file keymap.c.

1108 {
1110  if (MoreArgs(s))
1111  {
1112  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1113  return MUTT_CMD_ERROR;
1114  }
1115 
1117  return MUTT_CMD_SUCCESS;
1118 }
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:752
#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:191
#define MoreArgs(buf)
Definition: buffer.h:43
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:79
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:472
Success: Command worked.
Definition: mutt_commands.h:37

+ Here is the call graph for this function:

static char* parse_keymap ( int *  menu,
struct Buffer s,
int  maxmenus,
int *  nummenus,
struct Buffer err,
bool  bind 
)
static

Parse a user-config key binding.

Parameters
menuArray for results
sBuffer containing config string
maxmenusTotal number of menus
nummenusNumber 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 1134 of file keymap.c.

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static enum CommandResult try_bind ( char *  key,
int  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 1195 of file keymap.c.

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const struct Binding* km_get_table ( int  menu)

Lookup a menu's keybindings.

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

Definition at line 1218 of file keymap.c.

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

+ Here is the caller graph for this function:

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

Parse the 'bind' command - Implements command_t.

bind menu-name <key_sequence> function-name

Definition at line 1267 of file keymap.c.

1269 {
1270  const struct Binding *bindings = NULL;
1271  int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus;
1272  enum CommandResult rc = MUTT_CMD_SUCCESS;
1273 
1274  char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, true);
1275  if (!key)
1276  return MUTT_CMD_ERROR;
1277 
1278  /* function to execute */
1280  if (MoreArgs(s))
1281  {
1282  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1283  rc = MUTT_CMD_ERROR;
1284  }
1285  else if (mutt_str_strcasecmp("noop", buf->data) == 0)
1286  {
1287  for (int i = 0; i < nummenus; i++)
1288  {
1289  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1290  }
1291  }
1292  else
1293  {
1294  for (int i = 0; i < nummenus; i++)
1295  {
1296  /* The pager and editor menus don't use the generic map,
1297  * however for other menus try generic first. */
1298  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1299  {
1300  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1301  if (rc == 0)
1302  continue;
1303  if (rc == -2)
1304  break;
1305  }
1306 
1307  /* Clear any error message, we're going to try again */
1308  err->data[0] = '\0';
1309  bindings = km_get_table(menu[i]);
1310  if (bindings)
1311  {
1312  rc = try_bind(key, menu[i], buf->data, bindings, err);
1313  }
1314  }
1315  }
1316  FREE(&key);
1317  return rc;
1318 }
static char * parse_keymap(int *menu, struct Buffer *s, int maxmenus, int *nummenus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1134
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
#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:191
#define mutt_array_size(x)
Definition: memory.h:33
static enum CommandResult km_bindkey(const char *s, int menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:417
Pager pager (email viewer)
Definition: keymap.h:78
#define MoreArgs(buf)
Definition: buffer.h:43
static enum CommandResult try_bind(char *key, int menu, char *func, const struct Binding *bindings, struct Buffer *err)
Try to make a key binding.
Definition: keymap.c:1195
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1218
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#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:105
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77
Generic selection list.
Definition: keymap.h:76

+ Here is the call graph for this function:

static void* parse_menu ( int *  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 1328 of file keymap.c.

1329 {
1330  char *menu_names_dup = mutt_str_strdup(s);
1331  char *menu_name = NULL;
1332 
1333  while ((menu_name = strsep(&menu_names_dup, ",")))
1334  {
1335  int value = mutt_map_get_value(menu_name, Menus);
1336  if (value == -1)
1337  {
1338  mutt_buffer_printf(err, _("%s: no such menu"), menu_name);
1339  FREE(&menu_names_dup);
1340  return NULL;
1341  }
1342  else
1343  menu[value] = true;
1344  }
1345 
1346  FREE(&menu_names_dup);
1347  return NULL;
1348 }
#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:191
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1358 {
1359  struct Keymap *next = NULL;
1360  struct Keymap *first = NULL;
1361  struct Keymap *last = NULL;
1362  struct Keymap *cur = *map;
1363 
1364  while (cur)
1365  {
1366  next = cur->next;
1367  if (((mode & MUTT_UNBIND) && !cur->macro) || ((mode & MUTT_UNMACRO) && cur->macro))
1368  {
1369  FREE(&cur->macro);
1370  FREE(&cur->keys);
1371  FREE(&cur->desc);
1372  FREE(&cur);
1373  }
1374  else if (!first)
1375  {
1376  first = cur;
1377  last = cur;
1378  }
1379  else if (last)
1380  {
1381  last->next = cur;
1382  last = cur;
1383  }
1384  else
1385  {
1386  last = cur;
1387  }
1388  cur = next;
1389  }
1390 
1391  if (last)
1392  last->next = NULL;
1393 
1394  *map = first;
1395 }
keycode_t * keys
key sequence
Definition: keymap.h:57
#define MUTT_UNMACRO
Definition: keymap.h:32
struct Keymap * next
next key in map
Definition: keymap.h:53
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:51
char * desc
description of a macro for the help menu
Definition: keymap.h:52
A keyboard mapping.
Definition: keymap.h:49
#define FREE(x)
Definition: memory.h:40
#define MUTT_UNBIND
Definition: keymap.h:31

+ Here is the caller graph for this function:

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

Parse the 'unbind' command - Implements command_t.

Command unbinds:

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

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

Definition at line 1407 of file keymap.c.

1409 {
1410  int menu[MENU_MAX] = { 0 };
1411  bool all_keys = false;
1412  char *key = NULL;
1413 
1415  if (mutt_str_strcmp(buf->data, "*") == 0)
1416  {
1417  for (int i = 0; i < MENU_MAX; i++)
1418  menu[i] = 1;
1419  }
1420  else
1421  parse_menu(menu, buf->data, err);
1422 
1423  if (MoreArgs(s))
1424  {
1426  key = buf->data;
1427  }
1428  else
1429  all_keys = true;
1430 
1431  if (MoreArgs(s))
1432  {
1433  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1434 
1435  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1436  return MUTT_CMD_ERROR;
1437  }
1438 
1439  for (int i = 0; i < MENU_MAX; i++)
1440  {
1441  if (menu[i] != 1)
1442  continue;
1443  if (all_keys)
1444  {
1445  km_unbind_all(&Keymaps[i], data);
1446  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1447  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1448  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1449  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1450  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1451  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1452  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1453  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1454  if (i != MENU_EDITOR)
1455  {
1456  km_bindkey("?", i, OP_HELP);
1457  km_bindkey("q", i, OP_EXIT);
1458  }
1459  }
1460  else
1461  km_bindkey(key, i, OP_NULL);
1462  }
1463 
1464  return MUTT_CMD_SUCCESS;
1465 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
#define _(a)
Definition: message.h:28
static void km_unbind_all(struct Keymap **map, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1357
Index panel (list of emails)
Definition: keymap.h:77
static void * parse_menu(int *menu, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1328
#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:191
static enum CommandResult km_bindkey(const char *s, int menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:417
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:2638
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Text entry area.
Definition: keymap.h:74
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77
Generic selection list.
Definition: keymap.h:76

+ Here is the call graph for this function:

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

Parse the 'macro' command - Implements command_t.

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

Definition at line 1472 of file keymap.c.

1474 {
1475  int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus;
1476  enum CommandResult rc = MUTT_CMD_ERROR;
1477  char *seq = NULL;
1478 
1479  char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, false);
1480  if (!key)
1481  return MUTT_CMD_ERROR;
1482 
1484  /* make sure the macro sequence is not an empty string */
1485  if (buf->data[0] == '\0')
1486  {
1487  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1488  }
1489  else
1490  {
1491  if (MoreArgs(s))
1492  {
1493  seq = mutt_str_strdup(buf->data);
1495 
1496  if (MoreArgs(s))
1497  {
1498  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1499  }
1500  else
1501  {
1502  for (int i = 0; i < nummenus; i++)
1503  {
1504  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1505  }
1506  }
1507 
1508  FREE(&seq);
1509  }
1510  else
1511  {
1512  for (int i = 0; i < nummenus; i++)
1513  {
1514  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1515  }
1516  }
1517  }
1518  FREE(&key);
1519  return rc;
1520 }
enum CommandResult km_bind(char *s, int menu, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: keymap.c:392
static char * parse_keymap(int *menu, struct Buffer *s, int maxmenus, int *nummenus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1134
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
#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:191
#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:79
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
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

+ Here is the call graph for this function:

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

Parse the 'exec' command - Implements command_t.

Definition at line 1525 of file keymap.c.

1527 {
1528  int ops[128];
1529  int nops = 0;
1530  const struct Binding *bindings = NULL;
1531  char *function = NULL;
1532 
1533  if (!MoreArgs(s))
1534  {
1535  mutt_buffer_strcpy(err, _("exec: no arguments"));
1536  return MUTT_CMD_ERROR;
1537  }
1538 
1539  do
1540  {
1542  function = buf->data;
1543 
1544  bindings = km_get_table(CurrentMenu);
1545  if (!bindings && (CurrentMenu != MENU_PAGER))
1546  bindings = OpGeneric;
1547 
1548  ops[nops] = get_op(bindings, function, mutt_str_strlen(function));
1549  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1550  ops[nops] = get_op(OpGeneric, function, mutt_str_strlen(function));
1551 
1552  if (ops[nops] == OP_NULL)
1553  {
1554  mutt_flushinp();
1555  mutt_error(_("%s: no such function"), function);
1556  return MUTT_CMD_ERROR;
1557  }
1558  nops++;
1559  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1560 
1561  while (nops)
1562  mutt_push_macro_event(0, ops[--nops]);
1563 
1564  return MUTT_CMD_SUCCESS;
1565 }
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:752
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h:78
#define MoreArgs(buf)
Definition: buffer.h:43
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1218
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
#define mutt_error(...)
Definition: logging.h:84
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:429
Mapping between a user key and a function.
Definition: keymap.h:105
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

void mutt_what_key ( void  )

Ask the user to press a key.

Displays the octal value back to the user.

Definition at line 1572 of file keymap.c.

1573 {
1574  int ch;
1575 
1576  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (^G to abort): "));
1577  do
1578  {
1579  ch = getch();
1580  if ((ch != ERR) && (ch != ctrl('G')))
1581  {
1582  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1583  }
1584  } while (ch != ERR && ch != ctrl('G'));
1585 
1586  mutt_flushinp();
1587  mutt_clear_error();
1588 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:740
#define mutt_message(...)
Definition: logging.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
#define _(a)
Definition: message.h:28
#define ctrl(ch)
Definition: mutt_curses.h:97
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:143
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:217
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_free_keys ( void  )

Free the key maps.

Definition at line 1593 of file keymap.c.

1594 {
1595  struct Keymap *map = NULL;
1596  struct Keymap *next = NULL;
1597 
1598  for (int i = 0; i < MENU_MAX; i++)
1599  {
1600  for (map = Keymaps[i]; map; map = next)
1601  {
1602  next = map->next;
1603 
1604  FREE(&map->macro);
1605  FREE(&map->desc);
1606  FREE(&map->keys);
1607  FREE(&map);
1608  }
1609 
1610  Keymaps[i] = NULL;
1611  }
1612 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
keycode_t * keys
key sequence
Definition: keymap.h:57
struct Keymap * next
next key in map
Definition: keymap.h:53
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:51
char * desc
description of a macro for the help menu
Definition: keymap.h:52
A keyboard mapping.
Definition: keymap.h:49
#define FREE(x)
Definition: memory.h:40

+ Here is the caller graph for this function:

Variable Documentation

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

Menu name lookup table.

Definition at line 60 of file keymap.c.

struct Mapping KeyNames[]
static

Key name lookup table.

Definition at line 86 of file keymap.c.

int LastKey

contains the last key the user pressed

Last real key pressed, recorded by dokey()

Definition at line 145 of file keymap.c.

struct Keymap* Keymaps[MENU_MAX]

Array of Keymap keybindings, one for each Menu.

Definition at line 147 of file keymap.c.