NeoMutt  2018-07-16 +1360-3df4a2
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...
 
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:51
keycode_t * keys
key sequence
Definition: keymap.h:54
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:99
short keycode_t
Definition: keymap.h:34
A keyboard mapping.
Definition: keymap.h:46
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 (ISSPACE(*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 ISSPACE(ch)
Definition: string2.h:37

+ 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:741
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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
enume.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:52
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:31
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
keycode_t * keys
key sequence
Definition: keymap.h:54
#define _(a)
Definition: message.h:28
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
size_t dsize
length of data
Definition: buffer.h:37
static size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: keymap.c:222
short op
operation to perform
Definition: keymap.h:51
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
struct Keymap * next
next key in map
Definition: keymap.h:50
static struct Keymap * alloc_keys(size_t len, keycode_t *keys)
Allocate space for a sequence of keys.
Definition: keymap.c:155
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:766
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
char * data
pointer to data
Definition: buffer.h:35
short keycode_t
Definition: keymap.h:34
char * desc
description of a macro for the help menu
Definition: keymap.h:49
A keyboard mapping.
Definition: keymap.h:46
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
Success: Command worked.
Definition: mutt_commands.h:35
Warning: Help given to the user.
Definition: mutt_commands.h:34
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:383
#define mutt_error(...)
Definition: logging.h:88
#define FREE(x)
Definition: memory.h:40
#define MAX_SEQ
Definition: keymap.h:31

+ 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
enume.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:51
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
char * desc
description of a macro for the help menu
Definition: keymap.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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
enume.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:51

+ 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
enume.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:51
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:103
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h:102
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:652
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:

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:102
short op
operation to perform
Definition: keymap.h:51

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

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

544 {
545  if ((menu != MENU_EDITOR) && (menu != MENU_GENERIC) && (menu != MENU_PAGER))
546  {
547  if (lastkey)
548  mutt_unget_event(lastkey, 0);
549  for (; keyslen; keyslen--)
550  mutt_unget_event(keys[keyslen - 1], 0);
551  return km_dokey(MENU_GENERIC);
552  }
553  if (menu != MENU_EDITOR)
554  {
555  /* probably a good idea to flush input here so we can abort macros */
556  mutt_flushinp();
557  }
558  return OP_NULL;
559 }
int km_dokey(int menu)
Determine what a keypress should do.
Definition: keymap.c:569
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:753
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:668
Pager pager (email viewer)
Definition: keymap.h:75
Text entry area.
Definition: keymap.h:71
Generic selection list.
Definition: keymap.h:73

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

570 {
571  struct Event tmp;
572  struct Keymap *map = Keymaps[menu];
573  int pos = 0;
574  int n = 0;
575 
576  if (!map)
577  return retry_generic(menu, NULL, 0, 0);
578 
579  while (true)
580  {
581  int i = C_Timeout > 0 ? C_Timeout : 60;
582 #ifdef USE_IMAP
583  /* keepalive may need to run more frequently than C_Timeout allows */
584  if (C_ImapKeepalive)
585  {
586  if (C_ImapKeepalive >= i)
587  imap_keepalive();
588  else
589  {
590  while (C_ImapKeepalive && C_ImapKeepalive < i)
591  {
593  tmp = mutt_getch();
594  mutt_getch_timeout(-1);
595  /* If a timeout was not received, or the window was resized, exit the
596  * loop now. Otherwise, continue to loop until reaching a total of
597  * $timeout seconds. */
598 #ifdef USE_INOTIFY
599  if ((tmp.ch != -2) || SigWinch || MonitorFilesChanged)
600 #else
601  if ((tmp.ch != -2) || SigWinch)
602 #endif
603  goto gotkey;
604  i -= C_ImapKeepalive;
605  imap_keepalive();
606  }
607  }
608  }
609 #endif
610 
611  mutt_getch_timeout(i * 1000);
612  tmp = mutt_getch();
613  mutt_getch_timeout(-1);
614 
615 #ifdef USE_IMAP
616  gotkey:
617 #endif
618  /* hide timeouts, but not window resizes, from the line editor. */
619  if ((menu == MENU_EDITOR) && (tmp.ch == -2) && !SigWinch)
620  continue;
621 
622  LastKey = tmp.ch;
623  if (LastKey < 0)
624  return LastKey;
625 
626  /* do we have an op already? */
627  if (tmp.op)
628  {
629  const char *func = NULL;
630  const struct Binding *bindings = NULL;
631 
632  /* is this a valid op for this menu? */
633  if ((bindings = km_get_table(menu)) && (func = mutt_get_func(bindings, tmp.op)))
634  return tmp.op;
635 
636  if ((menu == MENU_EDITOR) && mutt_get_func(OpEditor, tmp.op))
637  return tmp.op;
638 
639  if ((menu != MENU_EDITOR) && (menu != MENU_PAGER))
640  {
641  /* check generic menu */
642  bindings = OpGeneric;
643  func = mutt_get_func(bindings, tmp.op);
644  if (func)
645  return tmp.op;
646  }
647 
648  /* Sigh. Valid function but not in this context.
649  * Find the literal string and push it back */
650  for (i = 0; Menus[i].name; i++)
651  {
652  bindings = km_get_table(Menus[i].value);
653  if (bindings)
654  {
655  func = mutt_get_func(bindings, tmp.op);
656  if (func)
657  {
658  mutt_unget_event('>', 0);
659  mutt_unget_string(func);
660  mutt_unget_event('<', 0);
661  break;
662  }
663  }
664  }
665  /* continue to chew */
666  if (func)
667  continue;
668  }
669 
670  /* Nope. Business as usual */
671  while (LastKey > map->keys[pos])
672  {
673  if ((pos > map->eq) || !map->next)
674  return retry_generic(menu, map->keys, pos, LastKey);
675  map = map->next;
676  }
677 
678  if (LastKey != map->keys[pos])
679  return retry_generic(menu, map->keys, pos, LastKey);
680 
681  if (++pos == map->len)
682  {
683  if (map->op != OP_MACRO)
684  return map->op;
685 
687  {
688  mutt_error(_("Macros are currently disabled"));
689  return -1;
690  }
691 
692  if (n++ == 10)
693  {
694  mutt_flushinp();
695  mutt_error(_("Macro loop detected"));
696  return -1;
697  }
698 
700  map = Keymaps[menu];
701  pos = 0;
702  }
703  }
704 
705  /* not reached */
706 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:52
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:705
int op
function id number
Definition: keymap.h:103
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:753
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
keycode_t * keys
key sequence
Definition: keymap.h:54
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:668
#define _(a)
Definition: message.h:28
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:35
An event such as a keypress.
Definition: mutt_curses.h:107
Pager pager (email viewer)
Definition: keymap.h:75
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:51
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:92
int MonitorFilesChanged
true after a monitored file has changed
Definition: monitor.c:49
WHERE short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
Definition: globals.h:166
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
struct Event mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:180
struct Keymap * next
next key in map
Definition: keymap.h:50
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1201
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:52
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: globals.h:158
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
A keyboard mapping.
Definition: keymap.h:46
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
#define mutt_error(...)
Definition: logging.h:88
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:137
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:687
Text entry area.
Definition: keymap.h:71
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:594
const char * name
Definition: mapping.h:31
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:1058
Mapping between a user key and a function.
Definition: keymap.h:100
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:543

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

714 {
715  for (int i = 0; map[i].name; i++)
716  if (map[i].seq)
717  km_bindkey(map[i].seq, menu, map[i].op);
718 }
int op
function id number
Definition: keymap.h:103
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:102
const char * seq
default key binding
Definition: keymap.h:104

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

728 {
729  static char buf[10];
730 
731  const char *p = mutt_map_get_name(c, KeyNames);
732  if (p)
733  return p;
734 
735  if ((c < 256) && (c > -128) && iscntrl((unsigned char) c))
736  {
737  if (c < 0)
738  c += 256;
739 
740  if (c < 128)
741  {
742  buf[0] = '^';
743  buf[1] = (c + '@') & 0x7f;
744  buf[2] = '\0';
745  }
746  else
747  snprintf(buf, sizeof(buf), "\\%d%d%d", c >> 6, (c >> 3) & 7, c & 7);
748  }
749  else if ((c >= KEY_F0) && (c < KEY_F(256))) /* this maximum is just a guess */
750  sprintf(buf, "<F%d>", c - KEY_F0);
751  else if (IsPrint(c))
752  snprintf(buf, sizeof(buf), "%c", (unsigned char) c);
753  else
754  snprintf(buf, sizeof(buf), "\\x%hx", (unsigned short) c);
755  return buf;
756 }
#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 766 of file keymap.c.

767 {
768  int p = 0;
769 
770  if (!map)
771  return 0;
772 
773  while (true)
774  {
775  mutt_str_strfcpy(s, km_keyname(map->keys[p]), len);
776  const size_t l = mutt_str_strlen(s);
777  len -= l;
778 
779  if ((++p >= map->len) || !len)
780  return 1;
781 
782  s += l;
783  }
784 
785  /* not reached */
786 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:727
keycode_t * keys
key sequence
Definition: keymap.h:54
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
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:741
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:

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

795 {
796  struct Keymap *map = Keymaps[menu];
797 
798  for (; map; map = map->next)
799  if (map->op == func)
800  break;
801  return map;
802 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
short op
operation to perform
Definition: keymap.h:51
struct Keymap * next
next key in map
Definition: keymap.h:50
A keyboard mapping.
Definition: keymap.h:46

+ Here is the caller graph for this function:

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

881 {
882 #ifdef NCURSES_VERSION
883 
884  use_extended_names(true);
885 
886  for (int j = 0; KeyNames[j].name; j++)
887  {
888  if (KeyNames[j].value == -1)
889  {
890  const char *keyname = find_ext_name(KeyNames[j].name);
891 
892  if (keyname)
893  {
894  char *s = tigetstr((char *) keyname);
895  if (s && ((long) (s) != -1))
896  {
897  int code = key_defined(s);
898  if (code > 0)
899  KeyNames[j].value = code;
900  }
901  }
902  }
903  }
904 #endif
905 }
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 910 of file keymap.c.

911 {
912  memset(Keymaps, 0, sizeof(struct Keymap *) * MENU_MAX);
913 
922 
925 
928 
929 #ifdef CRYPT_BACKEND_GPGME
930  create_bindings(OpPgp, MENU_KEY_SELECT_PGP);
931  create_bindings(OpSmime, MENU_KEY_SELECT_SMIME);
932 #endif
933 
934 #ifdef MIXMASTER
935  create_bindings(OpMix, MENU_MIX);
936 
937  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
938  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
939  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
940 #endif
941 
942  /* bindings for the line editor */
944 
945  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
946  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
947  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
948  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
949  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
950  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
951  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
952  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
953  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
954 
955  /* generic menu keymap */
957 
958  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
959  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
960  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
961  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
962  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
963  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
964  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
965  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
966  km_bindkey("1", MENU_GENERIC, OP_JUMP);
967  km_bindkey("2", MENU_GENERIC, OP_JUMP);
968  km_bindkey("3", MENU_GENERIC, OP_JUMP);
969  km_bindkey("4", MENU_GENERIC, OP_JUMP);
970  km_bindkey("5", MENU_GENERIC, OP_JUMP);
971  km_bindkey("6", MENU_GENERIC, OP_JUMP);
972  km_bindkey("7", MENU_GENERIC, OP_JUMP);
973  km_bindkey("8", MENU_GENERIC, OP_JUMP);
974  km_bindkey("9", MENU_GENERIC, OP_JUMP);
975 
976  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
977  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
978 
979  /* Miscellaneous extra bindings */
980 
981  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
982  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
983  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
984  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
985  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
986  km_bindkey("x", MENU_MAIN, OP_EXIT);
987 
988  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
989  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
990 
991  km_bindkey("x", MENU_PAGER, OP_EXIT);
992  km_bindkey("i", MENU_PAGER, OP_EXIT);
993  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
994  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
995  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
996  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
997  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
998  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
999  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1000  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1001  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1002  km_bindkey("1", MENU_PAGER, OP_JUMP);
1003  km_bindkey("2", MENU_PAGER, OP_JUMP);
1004  km_bindkey("3", MENU_PAGER, OP_JUMP);
1005  km_bindkey("4", MENU_PAGER, OP_JUMP);
1006  km_bindkey("5", MENU_PAGER, OP_JUMP);
1007  km_bindkey("6", MENU_PAGER, OP_JUMP);
1008  km_bindkey("7", MENU_PAGER, OP_JUMP);
1009  km_bindkey("8", MENU_PAGER, OP_JUMP);
1010  km_bindkey("9", MENU_PAGER, OP_JUMP);
1011 
1012  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1013  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1014 
1015  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1016  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1017  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1018 
1019  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1020  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1021  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1022  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1023 
1024  /* edit-to (default "t") hides generic tag-entry in Compose menu
1025  * This will bind tag-entry to "T" in the Compose menu */
1026  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1027 }
PGP encryption menu.
Definition: keymap.h:78
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
General file/mailbox browser.
Definition: keymap.h:72
Compose an email.
Definition: keymap.h:70
Index panel (list of emails)
Definition: keymap.h:74
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.h:256
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.h:101
SMIME encryption menu.
Definition: keymap.h:79
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:75
Select from results of external query.
Definition: keymap.h:77
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.h:626
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.h:521
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.h:635
Select an attachment.
Definition: keymap.h:69
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:52
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.h:512
Select an email address by its alias.
Definition: keymap.h:68
A keyboard mapping.
Definition: keymap.h:46
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: ncrypt.h:129
static void create_bindings(const struct Binding *map, int menu)
Attach a set of keybindings to a Menu.
Definition: keymap.c:713
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.h:530
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.h:445
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.h:409
Text entry area.
Definition: keymap.h:71
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:594
Select a postponed email.
Definition: keymap.h:76
#define WithCrypto
Definition: ncrypt.h:155
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: ncrypt.h:130
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.h:583
Generic selection list.
Definition: keymap.h:73

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

1034 {
1035  char buf[128];
1036  int p, op;
1037 
1038  struct Keymap *key = km_find_func(menu, OP_HELP);
1039  if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER))
1040  key = km_find_func(MENU_GENERIC, OP_HELP);
1041  if (!key)
1042  {
1043  mutt_error(_("Key is not bound"));
1044  return;
1045  }
1046 
1047  /* Make sure the key is really the help key in this menu.
1048  *
1049  * OP_END_COND is used as a barrier to ensure nothing extra
1050  * is left in the unget buffer.
1051  *
1052  * Note that km_expand_key() + tokenize_unget_string() should
1053  * not be used here: control sequences are expanded to a form
1054  * (e.g. "^H") not recognized by km_dokey(). */
1055  mutt_unget_event(0, OP_END_COND);
1056  p = key->len;
1057  while (p--)
1058  mutt_unget_event(key->keys[p], 0);
1059 
1060  /* Note, e.g. for the index menu:
1061  * bind generic ? noop
1062  * bind generic ,a help
1063  * bind index ,ab quit
1064  * The index keybinding shadows the generic binding.
1065  * OP_END_COND will be read and returned as the op.
1066  *
1067  * bind generic ? noop
1068  * bind generic dq help
1069  * bind index d delete-message
1070  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1071  * in the unget buffer.
1072  */
1073  op = km_dokey(menu);
1074  if (op != OP_END_COND)
1076  if (op != OP_HELP)
1077  {
1078  mutt_error(_("Key is not bound"));
1079  return;
1080  }
1081 
1082  km_expand_key(buf, sizeof(buf), key);
1083  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1084 }
int km_dokey(int menu)
Determine what a keypress should do.
Definition: keymap.c:569
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:668
#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:794
Pager pager (email viewer)
Definition: keymap.h:75
short op
operation to perform
Definition: keymap.h:51
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:766
A keyboard mapping.
Definition: keymap.h:46
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:53
#define mutt_error(...)
Definition: logging.h:88
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: curs_lib.c:741
Text entry area.
Definition: keymap.h:71
Generic selection list.
Definition: keymap.h:73

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

1091 {
1093  if (MoreArgs(s))
1094  {
1095  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1096  return MUTT_CMD_ERROR;
1097  }
1098 
1100  return MUTT_CMD_SUCCESS;
1101 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:33
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:705
#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:200
#define MoreArgs(buf)
Definition: buffer.h:44
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:76
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2659
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:35

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

1119 {
1120  struct Buffer buf;
1121  int i = 0;
1122  char *q = NULL;
1123 
1124  mutt_buffer_init(&buf);
1125 
1126  /* menu name */
1127  mutt_extract_token(&buf, s, 0);
1128  char *p = buf.data;
1129  if (MoreArgs(s))
1130  {
1131  while (i < maxmenus)
1132  {
1133  q = strchr(p, ',');
1134  if (q)
1135  *q = '\0';
1136 
1137  menu[i] = mutt_map_get_value(p, Menus);
1138  if (menu[i] == -1)
1139  {
1140  mutt_buffer_printf(err, _("%s: no such menu"), p);
1141  goto error;
1142  }
1143  i++;
1144  if (q)
1145  p = q + 1;
1146  else
1147  break;
1148  }
1149  *nummenus = i;
1150  /* key sequence */
1151  mutt_extract_token(&buf, s, 0);
1152 
1153  if (buf.data[0] == '\0')
1154  {
1155  mutt_buffer_printf(err, _("%s: null key sequence"), bind ? "bind" : "macro");
1156  }
1157  else if (MoreArgs(s))
1158  return buf.data;
1159  }
1160  else
1161  {
1162  mutt_buffer_printf(err, _("%s: too few arguments"), bind ? "bind" : "macro");
1163  }
1164 error:
1165  FREE(&buf.data);
1166  return NULL;
1167 }
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:200
#define MoreArgs(buf)
Definition: buffer.h:44
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:2659
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:66
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
enume.g. MUTT_CMD_SUCCESS

Definition at line 1178 of file keymap.c.

1180 {
1181  for (int i = 0; bindings[i].name; i++)
1182  {
1183  if (mutt_str_strcmp(func, bindings[i].name) == 0)
1184  {
1185  return km_bindkey_err(key, menu, bindings[i].op, err);
1186  }
1187  }
1188  if (err)
1189  {
1190  mutt_buffer_printf(err, _("Function '%s' not available for menu '%s'"),
1191  func, mutt_map_get_name(menu, Menus));
1192  }
1193  return MUTT_CMD_ERROR; /* Couldn't find an existing function with this name */
1194 }
Error: Can&#39;t help the user.
Definition: mutt_commands.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:200
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:102
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:611

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

1202 {
1203  switch (menu)
1204  {
1205  case MENU_ALIAS:
1206  return OpAlias;
1207  case MENU_ATTACH:
1208  return OpAttach;
1209  case MENU_COMPOSE:
1210  return OpCompose;
1211  case MENU_EDITOR:
1212  return OpEditor;
1213  case MENU_FOLDER:
1214  return OpBrowser;
1215  case MENU_GENERIC:
1216  return OpGeneric;
1217 #ifdef CRYPT_BACKEND_GPGME
1218  case MENU_KEY_SELECT_PGP:
1219  return OpPgp;
1220  case MENU_KEY_SELECT_SMIME:
1221  return OpSmime;
1222 #endif
1223  case MENU_MAIN:
1224  return OpMain;
1225 #ifdef MIXMASTER
1226  case MENU_MIX:
1227  return OpMix;
1228 #endif
1229  case MENU_PAGER:
1230  return OpPager;
1231  case MENU_PGP:
1232  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1233  case MENU_POST:
1234  return OpPost;
1235  case MENU_QUERY:
1236  return OpQuery;
1237  case MENU_SUMMARY:
1238  return OpSummary;
1239  }
1240  return NULL;
1241 }
PGP encryption menu.
Definition: keymap.h:78
General file/mailbox browser.
Definition: keymap.h:72
Compose an email.
Definition: keymap.h:70
Index panel (list of emails)
Definition: keymap.h:74
const struct Binding OpPager[]
Key bindings for the pager menu.
Definition: functions.h:256
const struct Binding OpMain[]
Key bindings for the index menu.
Definition: functions.h:101
Summary pages.
Definition: keymap.h:87
Pager pager (email viewer)
Definition: keymap.h:75
Select from results of external query.
Definition: keymap.h:77
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.h:626
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.h:521
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.h:635
Select an attachment.
Definition: keymap.h:69
const struct Binding OpSummary[]
Key bindings for the summary menu.
Definition: functions.h:662
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:52
const struct Binding OpPost[]
Key bindings for the postpone menu.
Definition: functions.h:512
Select an email address by its alias.
Definition: keymap.h:68
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: ncrypt.h:129
const struct Binding OpBrowser[]
Key bindings for the file browser menu.
Definition: functions.h:530
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.h:445
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.h:409
Text entry area.
Definition: keymap.h:71
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:594
Select a postponed email.
Definition: keymap.h:76
#define WithCrypto
Definition: ncrypt.h:155
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.h:583
Generic selection list.
Definition: keymap.h:73

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

1250 {
1251  const struct Binding *bindings = NULL;
1252  int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus;
1253  enum CommandResult rc = MUTT_CMD_SUCCESS;
1254 
1255  char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, true);
1256  if (!key)
1257  return MUTT_CMD_ERROR;
1258 
1259  /* function to execute */
1260  mutt_extract_token(buf, s, 0);
1261  if (MoreArgs(s))
1262  {
1263  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1264  rc = MUTT_CMD_ERROR;
1265  }
1266  else if (mutt_str_strcasecmp("noop", buf->data) == 0)
1267  {
1268  for (int i = 0; i < nummenus; i++)
1269  {
1270  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1271  }
1272  }
1273  else
1274  {
1275  for (int i = 0; i < nummenus; i++)
1276  {
1277  /* The pager and editor menus don't use the generic map,
1278  * however for other menus try generic first. */
1279  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1280  {
1281  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1282  if (rc == 0)
1283  continue;
1284  if (rc == -2)
1285  break;
1286  }
1287 
1288  /* Clear any error message, we're going to try again */
1289  err->data[0] = '\0';
1290  bindings = km_get_table(menu[i]);
1291  if (bindings)
1292  {
1293  rc = try_bind(key, menu[i], buf->data, bindings, err);
1294  }
1295  }
1296  }
1297  FREE(&key);
1298  return rc;
1299 }
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:1117
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:31
Error: Can&#39;t help the user.
Definition: mutt_commands.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:200
#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:75
#define MoreArgs(buf)
Definition: buffer.h:44
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:1178
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:1201
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:52
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2659
char * data
pointer to data
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:35
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:624
#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:71
Mapping between a user key and a function.
Definition: keymap.h:100
Generic selection list.
Definition: keymap.h:73

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

1308 {
1309  int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus;
1310  enum CommandResult rc = MUTT_CMD_ERROR;
1311  char *seq = NULL;
1312 
1313  char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, false);
1314  if (!key)
1315  return MUTT_CMD_ERROR;
1316 
1318  /* make sure the macro sequence is not an empty string */
1319  if (buf->data[0] == '\0')
1320  {
1321  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1322  }
1323  else
1324  {
1325  if (MoreArgs(s))
1326  {
1327  seq = mutt_str_strdup(buf->data);
1329 
1330  if (MoreArgs(s))
1331  {
1332  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1333  }
1334  else
1335  {
1336  for (int i = 0; i < nummenus; i++)
1337  {
1338  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1339  }
1340  }
1341 
1342  FREE(&seq);
1343  }
1344  else
1345  {
1346  for (int i = 0; i < nummenus; i++)
1347  {
1348  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1349  }
1350  }
1351  }
1352  FREE(&key);
1353  return rc;
1354 }
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:1117
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:31
Error: Can&#39;t help the user.
Definition: mutt_commands.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:200
#define mutt_array_size(x)
Definition: memory.h:33
#define MoreArgs(buf)
Definition: buffer.h:44
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:76
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:316
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2659
char * data
pointer to data
Definition: buffer.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:383
const char * seq
default key binding
Definition: keymap.h:104
#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 1359 of file keymap.c.

1361 {
1362  int ops[128];
1363  int nops = 0;
1364  const struct Binding *bindings = NULL;
1365  char *function = NULL;
1366 
1367  if (!MoreArgs(s))
1368  {
1369  mutt_buffer_strcpy(err, _("exec: no arguments"));
1370  return MUTT_CMD_ERROR;
1371  }
1372 
1373  do
1374  {
1375  mutt_extract_token(buf, s, 0);
1376  function = buf->data;
1377 
1378  bindings = km_get_table(CurrentMenu);
1379  if (!bindings && (CurrentMenu != MENU_PAGER))
1380  bindings = OpGeneric;
1381 
1382  ops[nops] = get_op(bindings, function, mutt_str_strlen(function));
1383  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1384  ops[nops] = get_op(OpGeneric, function, mutt_str_strlen(function));
1385 
1386  if (ops[nops] == OP_NULL)
1387  {
1388  mutt_flushinp();
1389  mutt_error(_("%s: no such function"), function);
1390  return MUTT_CMD_ERROR;
1391  }
1392  nops++;
1393  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1394 
1395  while (nops)
1396  mutt_push_macro_event(0, ops[--nops]);
1397 
1398  return MUTT_CMD_SUCCESS;
1399 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:33
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:705
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:753
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h:75
#define MoreArgs(buf)
Definition: buffer.h:44
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:316
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1201
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:52
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2659
char * data
pointer to data
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:35
#define mutt_error(...)
Definition: logging.h:88
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:94
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:100

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

1407 {
1408  int ch;
1409 
1410  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (^G to abort): "));
1411  do
1412  {
1413  ch = getch();
1414  if ((ch != ERR) && (ch != ctrl('G')))
1415  {
1416  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1417  }
1418  } while (ch != ERR && ch != ctrl('G'));
1419 
1420  mutt_flushinp();
1421  mutt_clear_error();
1422 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:727
#define mutt_message(...)
Definition: logging.h:87
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:753
#define _(a)
Definition: message.h:28
#define ctrl(ch)
Definition: mutt_curses.h:96
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141
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:205
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41

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

1428 {
1429  struct Keymap *map = NULL;
1430  struct Keymap *next = NULL;
1431 
1432  for (int i = 0; i < MENU_MAX; i++)
1433  {
1434  for (map = Keymaps[i]; map; map = next)
1435  {
1436  next = map->next;
1437 
1438  FREE(&map->macro);
1439  FREE(&map->desc);
1440  FREE(&map->keys);
1441  FREE(&map);
1442  }
1443 
1444  Keymaps[i] = NULL;
1445  }
1446 }
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
keycode_t * keys
key sequence
Definition: keymap.h:54
struct Keymap * next
next key in map
Definition: keymap.h:50
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:48
char * desc
description of a macro for the help menu
Definition: keymap.h:49
A keyboard mapping.
Definition: keymap.h:46
#define FREE(x)
Definition: memory.h:40

+ Here is the caller graph for this function:

Variable Documentation

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_POST },
{ "pgp", MENU_PGP },
{ "smime", MENU_SMIME },
{ "query", MENU_QUERY },
{ "generic", MENU_GENERIC },
{ NULL, 0 },
}
PGP encryption menu.
Definition: keymap.h:78
General file/mailbox browser.
Definition: keymap.h:72
Compose an email.
Definition: keymap.h:70
Index panel (list of emails)
Definition: keymap.h:74
SMIME encryption menu.
Definition: keymap.h:79
Pager pager (email viewer)
Definition: keymap.h:75
Select from results of external query.
Definition: keymap.h:77
Select an attachment.
Definition: keymap.h:69
Select an email address by its alias.
Definition: keymap.h:68
Text entry area.
Definition: keymap.h:71
Select a postponed email.
Definition: keymap.h:76
Generic selection list.
Definition: keymap.h:73

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.