NeoMutt  2018-07-16 +1783-b00bd9
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:51
keycode_t * keys
key sequence
Definition: keymap.h:56
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:97
short keycode_t
Definition: keymap.h:36
A keyboard mapping.
Definition: keymap.h:48
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:55

+ 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: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:753
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:55
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:54
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:56
#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:53
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
struct Keymap * next
next key in map
Definition: keymap.h:52
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:769
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:50
char * data
pointer to data
Definition: buffer.h:35
short keycode_t
Definition: keymap.h:36
char * desc
description of a macro for the help menu
Definition: keymap.h:51
A keyboard mapping.
Definition: keymap.h:48
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:55
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:380
#define mutt_error(...)
Definition: logging.h:83
#define FREE(x)
Definition: memory.h:40
#define MAX_SEQ
Definition: keymap.h:33

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

+ 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:53
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:105
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h:104
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:659
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:55

+ 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:104
short op
operation to perform
Definition: keymap.h:53

+ 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:669
const char * name
Definition: pgpmicalg.c:45
short op
operation to perform
Definition: keymap.h:53
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:659
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1204
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:102

+ 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:785
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:700
Pager pager (email viewer)
Definition: keymap.h:77
Text entry area.
Definition: keymap.h:73
Generic selection list.
Definition: keymap.h:75

+ 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 && (menu != MENU_EDITOR))
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  if (!map)
671  return tmp.op;
672 
673  /* Nope. Business as usual */
674  while (LastKey > map->keys[pos])
675  {
676  if ((pos > map->eq) || !map->next)
677  return retry_generic(menu, map->keys, pos, LastKey);
678  map = map->next;
679  }
680 
681  if (LastKey != map->keys[pos])
682  return retry_generic(menu, map->keys, pos, LastKey);
683 
684  if (++pos == map->len)
685  {
686  if (map->op != OP_MACRO)
687  return map->op;
688 
690  {
691  mutt_error(_("Macros are currently disabled"));
692  return -1;
693  }
694 
695  if (n++ == 10)
696  {
697  mutt_flushinp();
698  mutt_error(_("Macro loop detected"));
699  return -1;
700  }
701 
703  map = Keymaps[menu];
704  pos = 0;
705  }
706  }
707 
708  /* not reached */
709 }
short eq
number of leading keys equal to next entry
Definition: keymap.h:54
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:737
int op
function id number
Definition: keymap.h:105
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:785
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:56
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:700
#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:108
Pager pager (email viewer)
Definition: keymap.h:77
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:53
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:84
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:158
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:52
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1204
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:52
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:50
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: globals.h:150
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:48
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:55
#define mutt_error(...)
Definition: logging.h:83
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:719
Text entry area.
Definition: keymap.h:73
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:595
const char * name
Definition: mapping.h:31
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:1052
Mapping between a user key and a function.
Definition: keymap.h:102
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 716 of file keymap.c.

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

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

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

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

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

798 {
799  struct Keymap *map = Keymaps[menu];
800 
801  for (; map; map = map->next)
802  if (map->op == func)
803  break;
804  return map;
805 }
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:53
struct Keymap * next
next key in map
Definition: keymap.h:52
A keyboard mapping.
Definition: keymap.h:48

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

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

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

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

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

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

1094 {
1096  if (MoreArgs(s))
1097  {
1098  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1099  return MUTT_CMD_ERROR;
1100  }
1101 
1103  return MUTT_CMD_SUCCESS;
1104 }
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:737
#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:77
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2656
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 1120 of file keymap.c.

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

1183 {
1184  for (int i = 0; bindings[i].name; i++)
1185  {
1186  if (mutt_str_strcmp(func, bindings[i].name) == 0)
1187  {
1188  return km_bindkey_err(key, menu, bindings[i].op, err);
1189  }
1190  }
1191  if (err)
1192  {
1193  mutt_buffer_printf(err, _("Function '%s' not available for menu '%s'"),
1194  func, mutt_map_get_name(menu, Menus));
1195  }
1196  return MUTT_CMD_ERROR; /* Couldn't find an existing function with this name */
1197 }
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:104
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:618

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

1205 {
1206  switch (menu)
1207  {
1208  case MENU_ALIAS:
1209  return OpAlias;
1210  case MENU_ATTACH:
1211  return OpAttach;
1212  case MENU_COMPOSE:
1213  return OpCompose;
1214  case MENU_EDITOR:
1215  return OpEditor;
1216  case MENU_FOLDER:
1217  return OpBrowser;
1218  case MENU_GENERIC:
1219  return OpGeneric;
1220 #ifdef CRYPT_BACKEND_GPGME
1221  case MENU_KEY_SELECT_PGP:
1222  return OpPgp;
1223  case MENU_KEY_SELECT_SMIME:
1224  return OpSmime;
1225 #endif
1226  case MENU_MAIN:
1227  return OpMain;
1228 #ifdef MIXMASTER
1229  case MENU_MIX:
1230  return OpMix;
1231 #endif
1232  case MENU_PAGER:
1233  return OpPager;
1234  case MENU_PGP:
1235  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1236  case MENU_POST:
1237  return OpPost;
1238  case MENU_QUERY:
1239  return OpQuery;
1240  case MENU_SUMMARY:
1241  return OpSummary;
1242  }
1243  return NULL;
1244 }
PGP encryption menu.
Definition: keymap.h:80
General file/mailbox browser.
Definition: keymap.h:74
Compose an email.
Definition: keymap.h:72
Index panel (list of emails)
Definition: keymap.h:76
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:89
Pager pager (email viewer)
Definition: keymap.h:77
Select from results of external query.
Definition: keymap.h:79
const struct Binding OpPgp[]
Key bindings for the pgp menu.
Definition: functions.h:627
const struct Binding OpAlias[]
Key bindings for the alias menu.
Definition: functions.h:522
const struct Binding OpSmime[]
Key bindings for the smime menu.
Definition: functions.h:636
Select an attachment.
Definition: keymap.h:71
const struct Binding OpSummary[]
Key bindings for the summary menu.
Definition: functions.h:663
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:513
Select an email address by its alias.
Definition: keymap.h:70
#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:531
const struct Binding OpCompose[]
Key bindings for the compose menu.
Definition: functions.h:446
const struct Binding OpAttach[]
Key bindings for the attachment menu.
Definition: functions.h:410
Text entry area.
Definition: keymap.h:73
const struct Binding OpEditor[]
Key bindings for the editor menu.
Definition: functions.h:595
Select a postponed email.
Definition: keymap.h:78
#define WithCrypto
Definition: ncrypt.h:155
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.h:584
Generic selection list.
Definition: keymap.h:75

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

1253 {
1254  const struct Binding *bindings = NULL;
1255  int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus;
1256  enum CommandResult rc = MUTT_CMD_SUCCESS;
1257 
1258  char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, true);
1259  if (!key)
1260  return MUTT_CMD_ERROR;
1261 
1262  /* function to execute */
1264  if (MoreArgs(s))
1265  {
1266  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1267  rc = MUTT_CMD_ERROR;
1268  }
1269  else if (mutt_str_strcasecmp("noop", buf->data) == 0)
1270  {
1271  for (int i = 0; i < nummenus; i++)
1272  {
1273  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1274  }
1275  }
1276  else
1277  {
1278  for (int i = 0; i < nummenus; i++)
1279  {
1280  /* The pager and editor menus don't use the generic map,
1281  * however for other menus try generic first. */
1282  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1283  {
1284  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1285  if (rc == 0)
1286  continue;
1287  if (rc == -2)
1288  break;
1289  }
1290 
1291  /* Clear any error message, we're going to try again */
1292  err->data[0] = '\0';
1293  bindings = km_get_table(menu[i]);
1294  if (bindings)
1295  {
1296  rc = try_bind(key, menu[i], buf->data, bindings, err);
1297  }
1298  }
1299  }
1300  FREE(&key);
1301  return rc;
1302 }
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:1120
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:77
#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:1181
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:1204
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:2656
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:631
#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:73
Mapping between a user key and a function.
Definition: keymap.h:102
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:75
Generic selection list.
Definition: keymap.h:75

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

1313 {
1314  char *menu_names_dup = mutt_str_strdup(s);
1315  char *menu_name = NULL;
1316 
1317  while ((menu_name = strsep(&menu_names_dup, ",")))
1318  {
1319  int value = mutt_map_get_value(menu_name, Menus);
1320  if (value == -1)
1321  {
1322  mutt_buffer_printf(err, _("%s: no such menu"), menu_name);
1323  FREE(&menu_names_dup);
1324  return NULL;
1325  }
1326  else
1327  menu[value] = true;
1328  }
1329 
1330  FREE(&menu_names_dup);
1331  return NULL;
1332 }
#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 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 1341 of file keymap.c.

1342 {
1343  struct Keymap *next = NULL;
1344  struct Keymap *first = NULL;
1345  struct Keymap *last = NULL;
1346  struct Keymap *cur = *map;
1347 
1348  while (cur)
1349  {
1350  next = cur->next;
1351  if (((mode & MUTT_UNBIND) && !cur->macro) || ((mode & MUTT_UNMACRO) && cur->macro))
1352  {
1353  FREE(&cur->macro);
1354  FREE(&cur->keys);
1355  FREE(&cur->desc);
1356  FREE(&cur);
1357  }
1358  else if (!first)
1359  {
1360  first = last = cur;
1361  }
1362  else if (last)
1363  {
1364  last->next = cur;
1365  last = cur;
1366  }
1367  else
1368  {
1369  last = cur;
1370  }
1371  cur = next;
1372  }
1373 
1374  if (last)
1375  last->next = NULL;
1376 
1377  *map = first;
1378 }
keycode_t * keys
key sequence
Definition: keymap.h:56
#define MUTT_UNMACRO
Definition: keymap.h:31
struct Keymap * next
next key in map
Definition: keymap.h:52
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:50
char * desc
description of a macro for the help menu
Definition: keymap.h:51
A keyboard mapping.
Definition: keymap.h:48
#define FREE(x)
Definition: memory.h:40
#define MUTT_UNBIND
Definition: keymap.h:30

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

1392 {
1393  int menu[MENU_MAX] = { 0 };
1394  bool all_keys = false;
1395  char *key = NULL;
1396 
1398  if (mutt_str_strcmp(buf->data, "*") == 0)
1399  {
1400  for (int i = 0; i < MENU_MAX; i++)
1401  menu[i] = 1;
1402  }
1403  else
1404  parse_menu(menu, buf->data, err);
1405 
1406  if (MoreArgs(s))
1407  {
1409  key = buf->data;
1410  }
1411  else
1412  all_keys = true;
1413 
1414  if (MoreArgs(s))
1415  {
1416  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1417 
1418  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1419  return MUTT_CMD_ERROR;
1420  }
1421 
1422  for (int i = 0; i < MENU_MAX; i++)
1423  {
1424  if (menu[i] != 1)
1425  continue;
1426  if (all_keys)
1427  {
1428  km_unbind_all(&Keymaps[i], data);
1429  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1430  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1431  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1432  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1433  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1434  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1435  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1436  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1437  if (i != MENU_EDITOR)
1438  {
1439  km_bindkey("?", i, OP_HELP);
1440  km_bindkey("q", i, OP_EXIT);
1441  }
1442  }
1443  else
1444  km_bindkey(key, i, OP_NULL);
1445  }
1446 
1447  return MUTT_CMD_SUCCESS;
1448 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:33
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:1341
Index panel (list of emails)
Definition: keymap.h:76
static void * parse_menu(int *menu, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1312
#define MUTT_UNMACRO
Definition: keymap.h:31
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:200
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:77
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2656
char * data
pointer to data
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:35
Text entry area.
Definition: keymap.h:73
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:75
Generic selection list.
Definition: keymap.h:75

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

1457 {
1458  int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus;
1459  enum CommandResult rc = MUTT_CMD_ERROR;
1460  char *seq = NULL;
1461 
1462  char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, false);
1463  if (!key)
1464  return MUTT_CMD_ERROR;
1465 
1467  /* make sure the macro sequence is not an empty string */
1468  if (buf->data[0] == '\0')
1469  {
1470  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1471  }
1472  else
1473  {
1474  if (MoreArgs(s))
1475  {
1476  seq = mutt_str_strdup(buf->data);
1478 
1479  if (MoreArgs(s))
1480  {
1481  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1482  }
1483  else
1484  {
1485  for (int i = 0; i < nummenus; i++)
1486  {
1487  rc = km_bind(key, menu[i], OP_MACRO, seq, buf->data);
1488  }
1489  }
1490 
1491  FREE(&seq);
1492  }
1493  else
1494  {
1495  for (int i = 0; i < nummenus; i++)
1496  {
1497  rc = km_bind(key, menu[i], OP_MACRO, buf->data, NULL);
1498  }
1499  }
1500  }
1501  FREE(&key);
1502  return rc;
1503 }
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:1120
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:77
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:322
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2656
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 1508 of file keymap.c.

1510 {
1511  int ops[128];
1512  int nops = 0;
1513  const struct Binding *bindings = NULL;
1514  char *function = NULL;
1515 
1516  if (!MoreArgs(s))
1517  {
1518  mutt_buffer_strcpy(err, _("exec: no arguments"));
1519  return MUTT_CMD_ERROR;
1520  }
1521 
1522  do
1523  {
1525  function = buf->data;
1526 
1527  bindings = km_get_table(CurrentMenu);
1528  if (!bindings && (CurrentMenu != MENU_PAGER))
1529  bindings = OpGeneric;
1530 
1531  ops[nops] = get_op(bindings, function, mutt_str_strlen(function));
1532  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1533  ops[nops] = get_op(OpGeneric, function, mutt_str_strlen(function));
1534 
1535  if (ops[nops] == OP_NULL)
1536  {
1537  mutt_flushinp();
1538  mutt_error(_("%s: no such function"), function);
1539  return MUTT_CMD_ERROR;
1540  }
1541  nops++;
1542  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1543 
1544  while (nops)
1545  mutt_push_macro_event(0, ops[--nops]);
1546 
1547  return MUTT_CMD_SUCCESS;
1548 }
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:737
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:785
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h:77
#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:322
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1204
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:2656
char * data
pointer to data
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:35
#define mutt_error(...)
Definition: logging.h:83
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:102
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:75

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

1556 {
1557  int ch;
1558 
1559  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (^G to abort): "));
1560  do
1561  {
1562  ch = getch();
1563  if ((ch != ERR) && (ch != ctrl('G')))
1564  {
1565  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1566  }
1567  } while (ch != ERR && ch != ctrl('G'));
1568 
1569  mutt_flushinp();
1570  mutt_clear_error();
1571 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:730
#define mutt_message(...)
Definition: logging.h:82
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:785
#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: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:220
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 1576 of file keymap.c.

1577 {
1578  struct Keymap *map = NULL;
1579  struct Keymap *next = NULL;
1580 
1581  for (int i = 0; i < MENU_MAX; i++)
1582  {
1583  for (map = Keymaps[i]; map; map = next)
1584  {
1585  next = map->next;
1586 
1587  FREE(&map->macro);
1588  FREE(&map->desc);
1589  FREE(&map->keys);
1590  FREE(&map);
1591  }
1592 
1593  Keymaps[i] = NULL;
1594  }
1595 }
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:56
struct Keymap * next
next key in map
Definition: keymap.h:52
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:50
char * desc
description of a macro for the help menu
Definition: keymap.h:51
A keyboard mapping.
Definition: keymap.h:48
#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:80
General file/mailbox browser.
Definition: keymap.h:74
Compose an email.
Definition: keymap.h:72
Index panel (list of emails)
Definition: keymap.h:76
SMIME encryption menu.
Definition: keymap.h:81
Pager pager (email viewer)
Definition: keymap.h:77
Select from results of external query.
Definition: keymap.h:79
Select an attachment.
Definition: keymap.h:71
Select an email address by its alias.
Definition: keymap.h:70
Text entry area.
Definition: keymap.h:73
Select a postponed email.
Definition: keymap.h:78
Generic selection list.
Definition: keymap.h:75

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.