NeoMutt  2018-07-16 +2225-8687db
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"

Go to the source code of this file.

Functions

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

Variables

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

Detailed Description

Manage keymappings.

Authors
  • Michael R. Elkins

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

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

Definition in file keymap.c.

Function Documentation

static struct Keymap* alloc_keys ( size_t  len,
keycode_t keys 
)
static

Allocate space for a sequence of keys.

Parameters
lenNumber of keys
keysArray of keys
Return values
ptrSequence of keys

Definition at line 155 of file keymap.c.

156 {
157  struct Keymap *p = mutt_mem_calloc(1, sizeof(struct Keymap));
158  p->len = len;
159  p->keys = mutt_mem_malloc(len * sizeof(keycode_t));
160  memcpy(p->keys, keys, len * sizeof(keycode_t));
161  return p;
162 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
keycode_t * keys
key sequence
Definition: keymap.h:56
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
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
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 }
static int parse_keycode ( const char *  s)
static

Parse a numeric keycode.

Parameters
sString to parse
Return values
numNumber of the key

This function parses the string <NNN> and uses the octal value as the key to bind.

Definition at line 199 of file keymap.c.

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

Parse a key string into key codes.

Parameters
strKey string
dArray for key codes
maxMaximum length of key sequence
Return values
numLength of key sequence

Definition at line 222 of file keymap.c.

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

Parse and queue a 'push' command.

Parameters
sString to push into the key queue
generic_pushCallback function to add events to macro queue

Parses s for <function> syntax and adds the whole sequence to either the macro or unget buffer. This function is invoked by the next two defines below.

Definition at line 472 of file keymap.c.

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

Try to find the key in the generic menu bindings.

Parameters
menuMenu id, e.g. MENU_PAGER
keysArray of keys to return to the input queue
keyslenNumber of keys in the array
lastkeyLast key pressed (to return to input queue)
Return values
numOperation, e.g. OP_DELETE

Definition at line 544 of file keymap.c.

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

Determine what a keypress should do.

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

Definition at line 570 of file keymap.c.

571 {
572  struct KeyEvent tmp;
573  struct Keymap *map = Keymaps[menu];
574  int pos = 0;
575  int n = 0;
576 
577  if (!map && (menu != MENU_EDITOR))
578  return retry_generic(menu, NULL, 0, 0);
579 
580  while (true)
581  {
582  int i = (C_Timeout > 0) ? C_Timeout : 60;
583 #ifdef USE_IMAP
584  /* keepalive may need to run more frequently than C_Timeout allows */
585  if (C_ImapKeepalive)
586  {
587  if (C_ImapKeepalive >= i)
588  imap_keepalive();
589  else
590  {
591  while (C_ImapKeepalive && (C_ImapKeepalive < i))
592  {
594  tmp = mutt_getch();
595  mutt_getch_timeout(-1);
596  /* If a timeout was not received, or the window was resized, exit the
597  * loop now. Otherwise, continue to loop until reaching a total of
598  * $timeout seconds. */
599  if ((tmp.ch != -2) || SigWinch)
600  goto gotkey;
601 #ifdef USE_INOTIFY
603  goto gotkey;
604 #endif
605  i -= C_ImapKeepalive;
606  imap_keepalive();
607  }
608  }
609  }
610 #endif
611 
612  mutt_getch_timeout(i * 1000);
613  tmp = mutt_getch();
614  mutt_getch_timeout(-1);
615 
616 #ifdef USE_IMAP
617  gotkey:
618 #endif
619  /* hide timeouts, but not window resizes, from the line editor. */
620  if ((menu == MENU_EDITOR) && (tmp.ch == -2) && !SigWinch)
621  continue;
622 
623  LastKey = tmp.ch;
624  if (LastKey < 0)
625  return LastKey;
626 
627  /* do we have an op already? */
628  if (tmp.op)
629  {
630  const char *func = NULL;
631  const struct Binding *bindings = NULL;
632 
633  /* is this a valid op for this menu? */
634  if ((bindings = km_get_table(menu)) && (func = mutt_get_func(bindings, tmp.op)))
635  return tmp.op;
636 
637  if ((menu == MENU_EDITOR) && mutt_get_func(OpEditor, tmp.op))
638  return tmp.op;
639 
640  if ((menu != MENU_EDITOR) && (menu != MENU_PAGER))
641  {
642  /* check generic menu */
643  bindings = OpGeneric;
644  func = mutt_get_func(bindings, tmp.op);
645  if (func)
646  return tmp.op;
647  }
648 
649  /* Sigh. Valid function but not in this context.
650  * Find the literal string and push it back */
651  for (i = 0; Menus[i].name; i++)
652  {
653  bindings = km_get_table(Menus[i].value);
654  if (bindings)
655  {
656  func = mutt_get_func(bindings, tmp.op);
657  if (func)
658  {
659  mutt_unget_event('>', 0);
660  mutt_unget_string(func);
661  mutt_unget_event('<', 0);
662  break;
663  }
664  }
665  }
666  /* continue to chew */
667  if (func)
668  continue;
669  }
670 
671  if (!map)
672  return tmp.op;
673 
674  /* Nope. Business as usual */
675  while (LastKey > map->keys[pos])
676  {
677  if ((pos > map->eq) || !map->next)
678  return retry_generic(menu, map->keys, pos, LastKey);
679  map = map->next;
680  }
681 
682  if (LastKey != map->keys[pos])
683  return retry_generic(menu, map->keys, pos, LastKey);
684 
685  if (++pos == map->len)
686  {
687  if (map->op != OP_MACRO)
688  return map->op;
689 
691  {
692  mutt_error(_("Macros are currently disabled"));
693  return -1;
694  }
695 
696  if (n++ == 10)
697  {
698  mutt_flushinp();
699  mutt_error(_("Macro loop detected"));
700  return -1;
701  }
702 
704  map = Keymaps[menu];
705  pos = 0;
706  }
707  }
708 
709  /* not reached */
710 }
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:752
int op
function id number
Definition: keymap.h:105
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
struct Keymap * Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:147
keycode_t * keys
key sequence
Definition: keymap.h:56
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:715
#define _(a)
Definition: message.h:28
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:35
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 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:1205
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
An event such as a keypress.
Definition: mutt_curses.h:108
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:180
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:84
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:734
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:1054
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:544
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 717 of file keymap.c.

718 {
719  for (int i = 0; map[i].name; i++)
720  if (map[i].seq)
721  km_bindkey(map[i].seq, menu, map[i].op);
722 }
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
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 731 of file keymap.c.

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

771 {
772  if (!map)
773  return 0;
774 
775  int p = 0;
776 
777  while (true)
778  {
779  mutt_str_strfcpy(s, km_keyname(map->keys[p]), len);
780  const size_t l = mutt_str_strlen(s);
781  len -= l;
782 
783  if ((++p >= map->len) || !len)
784  return 1;
785 
786  s += l;
787  }
788 
789  /* not reached */
790 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:731
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:666
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:55
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 798 of file keymap.c.

799 {
800  struct Keymap *map = Keymaps[menu];
801 
802  for (; map; map = map->next)
803  if (map->op == func)
804  break;
805  return map;
806 }
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
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 884 of file keymap.c.

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

Initialise all the menu keybindings.

Definition at line 914 of file keymap.c.

915 {
916  memset(Keymaps, 0, sizeof(struct Keymap *) * MENU_MAX);
917 
926 
929 
932 
933 #ifdef CRYPT_BACKEND_GPGME
934  create_bindings(OpPgp, MENU_KEY_SELECT_PGP);
935  create_bindings(OpSmime, MENU_KEY_SELECT_SMIME);
936 #endif
937 
938 #ifdef MIXMASTER
939  create_bindings(OpMix, MENU_MIX);
940 
941  km_bindkey("<space>", MENU_MIX, OP_GENERIC_SELECT_ENTRY);
942  km_bindkey("h", MENU_MIX, OP_MIX_CHAIN_PREV);
943  km_bindkey("l", MENU_MIX, OP_MIX_CHAIN_NEXT);
944 #endif
945 
946  /* bindings for the line editor */
948 
949  km_bindkey("<up>", MENU_EDITOR, OP_EDITOR_HISTORY_UP);
950  km_bindkey("<down>", MENU_EDITOR, OP_EDITOR_HISTORY_DOWN);
951  km_bindkey("<left>", MENU_EDITOR, OP_EDITOR_BACKWARD_CHAR);
952  km_bindkey("<right>", MENU_EDITOR, OP_EDITOR_FORWARD_CHAR);
953  km_bindkey("<home>", MENU_EDITOR, OP_EDITOR_BOL);
954  km_bindkey("<end>", MENU_EDITOR, OP_EDITOR_EOL);
955  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
956  km_bindkey("<delete>", MENU_EDITOR, OP_EDITOR_DELETE_CHAR);
957  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
958 
959  /* generic menu keymap */
961 
962  km_bindkey("<home>", MENU_GENERIC, OP_FIRST_ENTRY);
963  km_bindkey("<end>", MENU_GENERIC, OP_LAST_ENTRY);
964  km_bindkey("<pagedown>", MENU_GENERIC, OP_NEXT_PAGE);
965  km_bindkey("<pageup>", MENU_GENERIC, OP_PREV_PAGE);
966  km_bindkey("<right>", MENU_GENERIC, OP_NEXT_PAGE);
967  km_bindkey("<left>", MENU_GENERIC, OP_PREV_PAGE);
968  km_bindkey("<up>", MENU_GENERIC, OP_PREV_ENTRY);
969  km_bindkey("<down>", MENU_GENERIC, OP_NEXT_ENTRY);
970  km_bindkey("1", MENU_GENERIC, OP_JUMP);
971  km_bindkey("2", MENU_GENERIC, OP_JUMP);
972  km_bindkey("3", MENU_GENERIC, OP_JUMP);
973  km_bindkey("4", MENU_GENERIC, OP_JUMP);
974  km_bindkey("5", MENU_GENERIC, OP_JUMP);
975  km_bindkey("6", MENU_GENERIC, OP_JUMP);
976  km_bindkey("7", MENU_GENERIC, OP_JUMP);
977  km_bindkey("8", MENU_GENERIC, OP_JUMP);
978  km_bindkey("9", MENU_GENERIC, OP_JUMP);
979 
980  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
981  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
982 
983  /* Miscellaneous extra bindings */
984 
985  km_bindkey(" ", MENU_MAIN, OP_DISPLAY_MESSAGE);
986  km_bindkey("<up>", MENU_MAIN, OP_MAIN_PREV_UNDELETED);
987  km_bindkey("<down>", MENU_MAIN, OP_MAIN_NEXT_UNDELETED);
988  km_bindkey("J", MENU_MAIN, OP_NEXT_ENTRY);
989  km_bindkey("K", MENU_MAIN, OP_PREV_ENTRY);
990  km_bindkey("x", MENU_MAIN, OP_EXIT);
991 
992  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
993  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
994 
995  km_bindkey("x", MENU_PAGER, OP_EXIT);
996  km_bindkey("i", MENU_PAGER, OP_EXIT);
997  km_bindkey("<backspace>", MENU_PAGER, OP_PREV_LINE);
998  km_bindkey("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
999  km_bindkey("<pageup>", MENU_PAGER, OP_PREV_PAGE);
1000  km_bindkey("<up>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1001  km_bindkey("<right>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1002  km_bindkey("<down>", MENU_PAGER, OP_MAIN_NEXT_UNDELETED);
1003  km_bindkey("<left>", MENU_PAGER, OP_MAIN_PREV_UNDELETED);
1004  km_bindkey("<home>", MENU_PAGER, OP_PAGER_TOP);
1005  km_bindkey("<end>", MENU_PAGER, OP_PAGER_BOTTOM);
1006  km_bindkey("1", MENU_PAGER, OP_JUMP);
1007  km_bindkey("2", MENU_PAGER, OP_JUMP);
1008  km_bindkey("3", MENU_PAGER, OP_JUMP);
1009  km_bindkey("4", MENU_PAGER, OP_JUMP);
1010  km_bindkey("5", MENU_PAGER, OP_JUMP);
1011  km_bindkey("6", MENU_PAGER, OP_JUMP);
1012  km_bindkey("7", MENU_PAGER, OP_JUMP);
1013  km_bindkey("8", MENU_PAGER, OP_JUMP);
1014  km_bindkey("9", MENU_PAGER, OP_JUMP);
1015 
1016  km_bindkey("<return>", MENU_PAGER, OP_NEXT_LINE);
1017  km_bindkey("<enter>", MENU_PAGER, OP_NEXT_LINE);
1018 
1019  km_bindkey("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1020  km_bindkey("<enter>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
1021  km_bindkey("<space>", MENU_ALIAS, OP_TAG);
1022 
1023  km_bindkey("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
1024  km_bindkey("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
1025  km_bindkey("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
1026  km_bindkey("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
1027 
1028  /* edit-to (default "t") hides generic tag-entry in Compose menu
1029  * This will bind tag-entry to "T" in the Compose menu */
1030  km_bindkey("T", MENU_COMPOSE, OP_TAG);
1031 }
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:130
static void create_bindings(const struct Binding *map, int menu)
Attach a set of keybindings to a Menu.
Definition: keymap.c:717
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:156
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: ncrypt.h:131
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.h:584
Generic selection list.
Definition: keymap.h:75
void km_error_key ( int  menu)

Handle an unbound key sequence.

Parameters
menuMenu id, e.g. MENU_PAGER

Definition at line 1037 of file keymap.c.

1038 {
1039  char buf[128];
1040  int p, op;
1041 
1042  struct Keymap *key = km_find_func(menu, OP_HELP);
1043  if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER))
1044  key = km_find_func(MENU_GENERIC, OP_HELP);
1045  if (!key)
1046  {
1047  mutt_error(_("Key is not bound"));
1048  return;
1049  }
1050 
1051  /* Make sure the key is really the help key in this menu.
1052  *
1053  * OP_END_COND is used as a barrier to ensure nothing extra
1054  * is left in the unget buffer.
1055  *
1056  * Note that km_expand_key() + tokenize_unget_string() should
1057  * not be used here: control sequences are expanded to a form
1058  * (e.g. "^H") not recognized by km_dokey(). */
1059  mutt_unget_event(0, OP_END_COND);
1060  p = key->len;
1061  while (p--)
1062  mutt_unget_event(key->keys[p], 0);
1063 
1064  /* Note, e.g. for the index menu:
1065  * bind generic ? noop
1066  * bind generic ,a help
1067  * bind index ,ab quit
1068  * The index keybinding shadows the generic binding.
1069  * OP_END_COND will be read and returned as the op.
1070  *
1071  * bind generic ? noop
1072  * bind generic dq help
1073  * bind index d delete-message
1074  * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1075  * in the unget buffer.
1076  */
1077  op = km_dokey(menu);
1078  if (op != OP_END_COND)
1080  if (op != OP_HELP)
1081  {
1082  mutt_error(_("Key is not bound"));
1083  return;
1084  }
1085 
1086  km_expand_key(buf, sizeof(buf), key);
1087  mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1088 }
int km_dokey(int menu)
Determine what a keypress should do.
Definition: keymap.c:570
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:715
#define _(a)
Definition: message.h:28
struct Keymap * km_find_func(int menu, int func)
Find a function&#39;s mapping in a Menu.
Definition: keymap.c:798
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:770
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:84
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: curs_lib.c:788
Text entry area.
Definition: keymap.h:73
Generic selection list.
Definition: keymap.h:75
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 1093 of file keymap.c.

1095 {
1097  if (MoreArgs(s))
1098  {
1099  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1100  return MUTT_CMD_ERROR;
1101  }
1102 
1104  return MUTT_CMD_SUCCESS;
1105 }
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:752
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:191
#define MoreArgs(buf)
Definition: buffer.h:44
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:78
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2614
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
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 1121 of file keymap.c.

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

1184 {
1185  for (int i = 0; bindings[i].name; i++)
1186  {
1187  if (mutt_str_strcmp(func, bindings[i].name) == 0)
1188  {
1189  return km_bindkey_err(key, menu, bindings[i].op, err);
1190  }
1191  }
1192  if (err)
1193  {
1194  mutt_buffer_printf(err, _("Function '%s' not available for menu '%s'"),
1195  func, mutt_map_get_name(menu, Menus));
1196  }
1197  return MUTT_CMD_ERROR; /* Couldn't find an existing function with this name */
1198 }
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:191
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h: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:615
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 1205 of file keymap.c.

1206 {
1207  switch (menu)
1208  {
1209  case MENU_ALIAS:
1210  return OpAlias;
1211  case MENU_ATTACH:
1212  return OpAttach;
1213  case MENU_COMPOSE:
1214  return OpCompose;
1215  case MENU_EDITOR:
1216  return OpEditor;
1217  case MENU_FOLDER:
1218  return OpBrowser;
1219  case MENU_GENERIC:
1220  return OpGeneric;
1221 #ifdef CRYPT_BACKEND_GPGME
1222  case MENU_KEY_SELECT_PGP:
1223  return OpPgp;
1224  case MENU_KEY_SELECT_SMIME:
1225  return OpSmime;
1226 #endif
1227  case MENU_MAIN:
1228  return OpMain;
1229 #ifdef MIXMASTER
1230  case MENU_MIX:
1231  return OpMix;
1232 #endif
1233  case MENU_PAGER:
1234  return OpPager;
1235  case MENU_PGP:
1236  return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1237  case MENU_POST:
1238  return OpPost;
1239  case MENU_QUERY:
1240  return OpQuery;
1241  case MENU_SUMMARY:
1242  return OpSummary;
1243  }
1244  return NULL;
1245 }
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:130
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:156
const struct Binding OpQuery[]
Key bindings for the external query menu.
Definition: functions.h:584
Generic selection list.
Definition: keymap.h:75
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 1252 of file keymap.c.

1254 {
1255  const struct Binding *bindings = NULL;
1256  int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], nummenus;
1257  enum CommandResult rc = MUTT_CMD_SUCCESS;
1258 
1259  char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, true);
1260  if (!key)
1261  return MUTT_CMD_ERROR;
1262 
1263  /* function to execute */
1265  if (MoreArgs(s))
1266  {
1267  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1268  rc = MUTT_CMD_ERROR;
1269  }
1270  else if (mutt_str_strcasecmp("noop", buf->data) == 0)
1271  {
1272  for (int i = 0; i < nummenus; i++)
1273  {
1274  km_bindkey(key, menu[i], OP_NULL); /* the 'unbind' command */
1275  }
1276  }
1277  else
1278  {
1279  for (int i = 0; i < nummenus; i++)
1280  {
1281  /* The pager and editor menus don't use the generic map,
1282  * however for other menus try generic first. */
1283  if ((menu[i] != MENU_PAGER) && (menu[i] != MENU_EDITOR) && (menu[i] != MENU_GENERIC))
1284  {
1285  rc = try_bind(key, menu[i], buf->data, OpGeneric, err);
1286  if (rc == 0)
1287  continue;
1288  if (rc == -2)
1289  break;
1290  }
1291 
1292  /* Clear any error message, we're going to try again */
1293  err->data[0] = '\0';
1294  bindings = km_get_table(menu[i]);
1295  if (bindings)
1296  {
1297  rc = try_bind(key, menu[i], buf->data, bindings, err);
1298  }
1299  }
1300  }
1301  FREE(&key);
1302  return rc;
1303 }
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:1121
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:191
#define mutt_array_size(x)
Definition: memory.h:33
static enum CommandResult km_bindkey(const char *s, int menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:417
Pager pager (email viewer)
Definition: keymap.h: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:1182
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:1205
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:2614
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:628
#define FREE(x)
Definition: memory.h:40
Mapping between user-readable string and a constant.
Definition: mapping.h:29
Text entry area.
Definition: keymap.h: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:76
Generic selection list.
Definition: keymap.h:75
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 1313 of file keymap.c.

1314 {
1315  char *menu_names_dup = mutt_str_strdup(s);
1316  char *menu_name = NULL;
1317 
1318  while ((menu_name = strsep(&menu_names_dup, ",")))
1319  {
1320  int value = mutt_map_get_value(menu_name, Menus);
1321  if (value == -1)
1322  {
1323  mutt_buffer_printf(err, _("%s: no such menu"), menu_name);
1324  FREE(&menu_names_dup);
1325  return NULL;
1326  }
1327  else
1328  menu[value] = true;
1329  }
1330 
1331  FREE(&menu_names_dup);
1332  return NULL;
1333 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:191
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:61
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 1342 of file keymap.c.

1343 {
1344  struct Keymap *next = NULL;
1345  struct Keymap *first = NULL;
1346  struct Keymap *last = NULL;
1347  struct Keymap *cur = *map;
1348 
1349  while (cur)
1350  {
1351  next = cur->next;
1352  if (((mode & MUTT_UNBIND) && !cur->macro) || ((mode & MUTT_UNMACRO) && cur->macro))
1353  {
1354  FREE(&cur->macro);
1355  FREE(&cur->keys);
1356  FREE(&cur->desc);
1357  FREE(&cur);
1358  }
1359  else if (!first)
1360  {
1361  first = cur;
1362  last = cur;
1363  }
1364  else if (last)
1365  {
1366  last->next = cur;
1367  last = cur;
1368  }
1369  else
1370  {
1371  last = cur;
1372  }
1373  cur = next;
1374  }
1375 
1376  if (last)
1377  last->next = NULL;
1378 
1379  *map = first;
1380 }
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
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 1392 of file keymap.c.

1394 {
1395  int menu[MENU_MAX] = { 0 };
1396  bool all_keys = false;
1397  char *key = NULL;
1398 
1400  if (mutt_str_strcmp(buf->data, "*") == 0)
1401  {
1402  for (int i = 0; i < MENU_MAX; i++)
1403  menu[i] = 1;
1404  }
1405  else
1406  parse_menu(menu, buf->data, err);
1407 
1408  if (MoreArgs(s))
1409  {
1411  key = buf->data;
1412  }
1413  else
1414  all_keys = true;
1415 
1416  if (MoreArgs(s))
1417  {
1418  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1419 
1420  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1421  return MUTT_CMD_ERROR;
1422  }
1423 
1424  for (int i = 0; i < MENU_MAX; i++)
1425  {
1426  if (menu[i] != 1)
1427  continue;
1428  if (all_keys)
1429  {
1430  km_unbind_all(&Keymaps[i], data);
1431  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1432  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1433  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1434  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1435  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1436  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1437  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1438  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1439  if (i != MENU_EDITOR)
1440  {
1441  km_bindkey("?", i, OP_HELP);
1442  km_bindkey("q", i, OP_EXIT);
1443  }
1444  }
1445  else
1446  km_bindkey(key, i, OP_NULL);
1447  }
1448 
1449  return MUTT_CMD_SUCCESS;
1450 }
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:1342
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:1313
#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:191
static enum CommandResult km_bindkey(const char *s, int menu, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:417
Pager pager (email viewer)
Definition: keymap.h: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:2614
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:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
Generic selection list.
Definition: keymap.h:75
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 1457 of file keymap.c.

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

1512 {
1513  int ops[128];
1514  int nops = 0;
1515  const struct Binding *bindings = NULL;
1516  char *function = NULL;
1517 
1518  if (!MoreArgs(s))
1519  {
1520  mutt_buffer_strcpy(err, _("exec: no arguments"));
1521  return MUTT_CMD_ERROR;
1522  }
1523 
1524  do
1525  {
1527  function = buf->data;
1528 
1529  bindings = km_get_table(CurrentMenu);
1530  if (!bindings && (CurrentMenu != MENU_PAGER))
1531  bindings = OpGeneric;
1532 
1533  ops[nops] = get_op(bindings, function, mutt_str_strlen(function));
1534  if ((ops[nops] == OP_NULL) && (CurrentMenu != MENU_PAGER))
1535  ops[nops] = get_op(OpGeneric, function, mutt_str_strlen(function));
1536 
1537  if (ops[nops] == OP_NULL)
1538  {
1539  mutt_flushinp();
1540  mutt_error(_("%s: no such function"), function);
1541  return MUTT_CMD_ERROR;
1542  }
1543  nops++;
1544  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1545 
1546  while (nops)
1547  mutt_push_macro_event(0, ops[--nops]);
1548 
1549  return MUTT_CMD_SUCCESS;
1550 }
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:752
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: keymap.h: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:314
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1205
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:2614
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:35
#define mutt_error(...)
Definition: logging.h:84
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:429
Mapping between a user key and a function.
Definition: keymap.h:102
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
void mutt_what_key ( void  )

Ask the user to press a key.

Displays the octal value back to the user.

Definition at line 1557 of file keymap.c.

1558 {
1559  int ch;
1560 
1561  mutt_window_mvprintw(MuttMessageWindow, 0, 0, _("Enter keys (^G to abort): "));
1562  do
1563  {
1564  ch = getch();
1565  if ((ch != ERR) && (ch != ctrl('G')))
1566  {
1567  mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1568  }
1569  } while (ch != ERR && ch != ctrl('G'));
1570 
1571  mutt_flushinp();
1572  mutt_clear_error();
1573 }
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:731
#define mutt_message(...)
Definition: logging.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
#define _(a)
Definition: message.h:28
#define ctrl(ch)
Definition: mutt_curses.h:97
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c: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
void mutt_free_keys ( void  )

Free the key maps.

Definition at line 1578 of file keymap.c.

1579 {
1580  struct Keymap *map = NULL;
1581  struct Keymap *next = NULL;
1582 
1583  for (int i = 0; i < MENU_MAX; i++)
1584  {
1585  for (map = Keymaps[i]; map; map = next)
1586  {
1587  next = map->next;
1588 
1589  FREE(&map->macro);
1590  FREE(&map->desc);
1591  FREE(&map->keys);
1592  FREE(&map);
1593  }
1594 
1595  Keymaps[i] = NULL;
1596  }
1597 }
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

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.