NeoMutt  2023-03-22
Teaching an old dog new tricks
DOXYGEN
keymap.h File Reference

Manage keymappings. More...

#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "menu/lib.h"
+ Include dependency graph for keymap.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Keymap
 A keyboard mapping. More...
 
struct  KeyEvent
 An event such as a keypress. More...
 
struct  MenuFuncOp
 Mapping between a function and an operation. More...
 
struct  MenuOpSeq
 Mapping between an operation and a key sequence. More...
 
struct  EventBinding
 A key binding Event. More...
 

Macros

#define MUTT_UNBIND   1<<0
 
#define MUTT_UNMACRO   1<<1
 
#define MAX_SEQ   8
 

Typedefs

typedef short keycode_t
 Type for key storage, the rest of neomutt works fine with int type. More...
 

Enumerations

enum  NotifyBinding {
  NT_BINDING_ADD = 1 , NT_BINDING_DELETE , NT_BINDING_DELETE_ALL , NT_MACRO_ADD ,
  NT_MACRO_DELETE , NT_MACRO_DELETE_ALL
}
 Key Binding notification types. More...
 

Functions

void init_extended_keys (void)
 Initialise map of ncurses extended keys. More...
 
 STAILQ_HEAD (KeymapList, Keymap)
 
int km_expand_key (char *s, size_t len, struct Keymap *map)
 Get the key string bound to a Keymap. More...
 
struct Keymapkm_find_func (enum MenuType menu, int func)
 Find a function's mapping in a Menu. More...
 
void km_init (void)
 Initialise all the menu keybindings. More...
 
void km_error_key (enum MenuType menu)
 Handle an unbound key sequence. More...
 
void mutt_what_key (void)
 Ask the user to press a key. More...
 
void mutt_init_abort_key (void)
 Parse the abort_key config string. More...
 
int main_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
 
enum CommandResult km_bind (char *s, enum MenuType menu, int op, char *macro, char *desc)
 Bind a key to a macro. More...
 
int km_dokey (enum MenuType menu)
 Determine what a keypress should do. More...
 
struct KeyEvent km_dokey_event (enum MenuType menu)
 Determine what a keypress should do. More...
 
const struct MenuFuncOpkm_get_table (enum MenuType mtype)
 Lookup a Menu's functions. More...
 
const char * mutt_get_func (const struct MenuFuncOp *bindings, int op)
 Get the name of a function. More...
 
void mutt_keys_free (void)
 Free the key maps. More...
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unmacro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 

Variables

struct KeymapList Keymaps []
 Array of Keymap keybindings, one for each Menu. More...
 
keycode_t AbortKey
 key to abort edits etc, normally Ctrl-G More...
 
const struct Mapping Menus []
 

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.h.

Macro Definition Documentation

◆ MUTT_UNBIND

#define MUTT_UNBIND   1<<0

Definition at line 33 of file keymap.h.

◆ MUTT_UNMACRO

#define MUTT_UNMACRO   1<<1

Definition at line 34 of file keymap.h.

◆ MAX_SEQ

#define MAX_SEQ   8

Definition at line 36 of file keymap.h.

Typedef Documentation

◆ keycode_t

typedef short keycode_t

Type for key storage, the rest of neomutt works fine with int type.

Definition at line 39 of file keymap.h.

Enumeration Type Documentation

◆ NotifyBinding

Key Binding notification types.

Observers of NT_BINDING will be passed an EventBinding.

Note
Notifications are sent after the event.
Enumerator
NT_BINDING_ADD 

Key binding has been added.

NT_BINDING_DELETE 

Key binding has been deleted.

NT_BINDING_DELETE_ALL 

All key bindings have been deleted.

NT_MACRO_ADD 

Key macro has been added.

NT_MACRO_DELETE 

Key macro has been deleted.

NT_MACRO_DELETE_ALL 

All key macros have been deleted.

Definition at line 123 of file keymap.h.

124{
125 NT_BINDING_ADD = 1,
128
132};
@ NT_MACRO_ADD
Key macro has been added.
Definition: keymap.h:129
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: keymap.h:130
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: keymap.h:131
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: keymap.h:126
@ NT_BINDING_ADD
Key binding has been added.
Definition: keymap.h:125
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: keymap.h:127

Function Documentation

◆ init_extended_keys()

void init_extended_keys ( void  )

Initialise map of ncurses extended keys.

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

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

Definition at line 997 of file keymap.c.

998{
999#ifdef HAVE_USE_EXTENDED_NAMES
1000 use_extended_names(true);
1001
1002 for (int j = 0; KeyNames[j].name; j++)
1003 {
1004 if (KeyNames[j].value == -1)
1005 {
1006 const char *keyname = find_ext_name(KeyNames[j].name);
1007
1008 if (keyname)
1009 {
1010 char *s = tigetstr((char *) keyname);
1011 if (s && ((long) (s) != -1))
1012 {
1013 int code = key_defined(s);
1014 if (code > 0)
1015 KeyNames[j].value = code;
1016 }
1017 }
1018 }
1019 }
1020#endif
1021}
static const char * find_ext_name(const char *key)
Find the curses name for a key.
Definition: keymap.c:977
static struct Mapping KeyNames[]
Key name lookup table.
Definition: keymap.c:63
int value
Integer value.
Definition: mapping.h:34
const char * name
String value.
Definition: mapping.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ STAILQ_HEAD()

STAILQ_HEAD ( KeymapList  ,
Keymap   
)

◆ km_expand_key()

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

Get the key string bound to a Keymap.

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

Definition at line 929 of file keymap.c.

930{
931 if (!map)
932 return 0;
933
934 int p = 0;
935
936 while (true)
937 {
938 mutt_str_copy(s, km_keyname(map->keys[p]), len);
939 const size_t l = mutt_str_len(s);
940 len -= l;
941
942 if ((++p >= map->len) || !len)
943 return 1;
944
945 s += l;
946 }
947
948 /* not reached */
949}
static const char * km_keyname(int c)
Get the human name for a key.
Definition: keymap.c:822
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:567
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:652
keycode_t * keys
key sequence
Definition: keymap.h:55
short len
length of key sequence (unit: sizeof (keycode_t))
Definition: keymap.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_find_func()

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

Find a function's mapping in a Menu.

Parameters
mtypeMenu type, e.g. MENU_PAGER
funcFunction, e.g. OP_DELETE
Return values
ptrKeymap for the function

Definition at line 957 of file keymap.c.

958{
959 struct Keymap *np = NULL;
960 STAILQ_FOREACH(np, &Keymaps[mtype], entries)
961 {
962 if (np->op == func)
963 break;
964 }
965 return np;
966}
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:127
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A keyboard mapping.
Definition: keymap.h:49
short op
operation to perform
Definition: keymap.h:52
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 1026 of file keymap.c.

1027{
1028 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
1029
1032#ifdef USE_AUTOCRYPT
1034#endif
1040#ifdef MIXMASTER
1042#endif
1046
1051
1052#ifdef CRYPT_BACKEND_GPGME
1055#endif
1056}
const struct MenuOpSeq AutocryptAcctDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:794
const struct MenuOpSeq PostDefaultBindings[]
Key bindings for the Postpone Menu.
Definition: functions.c:1224
const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition: functions.c:907
const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition: functions.c:1234
const struct MenuOpSeq BrowserDefaultBindings[]
Key bindings for the file Browser Menu.
Definition: functions.c:807
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:748
const struct MenuOpSeq PagerDefaultBindings[]
Key bindings for the Pager Menu.
Definition: functions.c:1110
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition: functions.c:945
const struct MenuOpSeq AttachDefaultBindings[]
Key bindings for the Attachment Menu.
Definition: functions.c:763
const struct MenuOpSeq IndexDefaultBindings[]
Key bindings for the Index Menu.
Definition: functions.c:994
const struct MenuOpSeq MixDefaultBindings[]
Key bindings for the Mixmaster Menu.
Definition: functions.c:1090
const struct MenuOpSeq PgpDefaultBindings[]
Key bindings for the Pgp Menu.
Definition: functions.c:1214
const struct MenuOpSeq ComposeDefaultBindings[]
Key bindings for the Compose Menu.
Definition: functions.c:844
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition: functions.c:1249
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: keymap.c:806
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define WithCrypto
Definition: lib.h:116
@ MENU_KEY_SELECT_PGP
Select a PGP key.
Definition: type.h:47
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50
@ MENU_KEY_SELECT_SMIME
Select a SMIME key.
Definition: type.h:48
@ MENU_ATTACH
Select an attachment.
Definition: type.h:38
@ MENU_QUERY
Select from results of external query.
Definition: type.h:57
@ MENU_COMPOSE
Compose an email.
Definition: type.h:42
@ MENU_MIX
Create/edit a Mixmaster chain.
Definition: type.h:52
@ MENU_PGP
PGP encryption menu.
Definition: type.h:55
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:54
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:58
@ MENU_MAX
Definition: type.h:59
@ MENU_EDITOR
Text entry area.
Definition: type.h:43
@ MENU_POSTPONE
Select a postponed email.
Definition: type.h:56
@ MENU_ALIAS
Select an email address by its alias.
Definition: type.h:37
@ MENU_FOLDER
General file/mailbox browser.
Definition: type.h:44
@ MENU_AUTOCRYPT_ACCT
Autocrypt Account menu.
Definition: type.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_error_key()

void km_error_key ( enum MenuType  mtype)

Handle an unbound key sequence.

Parameters
mtypeMenu type, e.g. MENU_PAGER

Definition at line 1062 of file keymap.c.

1063{
1064 char buf[128] = { 0 };
1065 int p, op;
1066
1067 struct Keymap *key = km_find_func(mtype, OP_HELP);
1068 if (!key && (mtype != MENU_EDITOR) && (mtype != MENU_PAGER))
1069 key = km_find_func(MENU_GENERIC, OP_HELP);
1070 if (!key)
1071 {
1072 mutt_error(_("Key is not bound"));
1073 return;
1074 }
1075
1076 /* Make sure the key is really the help key in this menu.
1077 *
1078 * OP_END_COND is used as a barrier to ensure nothing extra
1079 * is left in the unget buffer.
1080 *
1081 * Note that km_expand_key() + tokenize_unget_string() should
1082 * not be used here: control sequences are expanded to a form
1083 * (e.g. "^H") not recognized by km_dokey(). */
1084 mutt_unget_op(OP_END_COND);
1085 p = key->len;
1086 while (p--)
1087 mutt_unget_ch(key->keys[p]);
1088
1089 /* Note, e.g. for the index menu:
1090 * bind generic ? noop
1091 * bind generic ,a help
1092 * bind index ,ab quit
1093 * The index keybinding shadows the generic binding.
1094 * OP_END_COND will be read and returned as the op.
1095 *
1096 * bind generic ? noop
1097 * bind generic dq help
1098 * bind index d delete-message
1099 * OP_DELETE will be returned as the op, leaving "q" + OP_END_COND
1100 * in the unget buffer.
1101 */
1102 op = km_dokey(mtype);
1103 if (op != OP_END_COND)
1105 if (op != OP_HELP)
1106 {
1107 mutt_error(_("Key is not bound"));
1108 return;
1109 }
1110
1111 km_expand_key(buf, sizeof(buf), key);
1112 mutt_error(_("Key is not bound. Press '%s' for help."), buf);
1113}
void mutt_unget_op(int op)
Return an operation to the input buffer.
Definition: curs_lib.c:531
void mutt_flush_unget_to_endcond(void)
Clear entries from UngetKeyEvents.
Definition: curs_lib.c:583
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition: curs_lib.c:520
#define mutt_error(...)
Definition: logging.h:87
struct Keymap * km_find_func(enum MenuType mtype, int func)
Find a function's mapping in a Menu.
Definition: keymap.c:957
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:796
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:929
#define _(a)
Definition: message.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_what_key()

void mutt_what_key ( void  )

Ask the user to press a key.

Displays the octal value back to the user.

Definition at line 1877 of file keymap.c.

1878{
1879 int ch;
1880
1881 struct MuttWindow *win = msgwin_get_window();
1882 if (!win)
1883 return;
1884
1886 mutt_window_mvprintw(win, 0, 0, _("Enter keys (%s to abort): "), km_keyname(AbortKey));
1889 do
1890 {
1891 ch = getch();
1892 if ((ch != ERR) && (ch != AbortKey))
1893 {
1894 mutt_message(_("Char = %s, Octal = %o, Decimal = %d"), km_keyname(ch), ch, ch);
1895 mutt_window_move(win, 0, 0);
1896 }
1897 } while (ch != ERR && ch != AbortKey);
1898 mutt_curses_set_cursor(cursor);
1899
1900 mutt_flushinp();
1902}
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:57
@ MT_COLOR_PROMPT
Question/user input.
Definition: color.h:60
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:591
#define mutt_message(...)
Definition: logging.h:86
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: keymap.c:125
struct MuttWindow * msgwin_get_window(void)
Get the Message Window pointer.
Definition: msgwin.c:260
enum MuttCursorState mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:96
struct AttrColor * mutt_curses_set_normal_backed_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:65
struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:81
MuttCursorState
Cursor states for mutt_curses_set_cursor()
Definition: mutt_curses.h:52
@ MUTT_CURSOR_VISIBLE
Display a normal cursor.
Definition: mutt_curses.h:54
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:292
int mutt_window_mvprintw(struct MuttWindow *win, int col, int row, const char *fmt,...)
Move the cursor and write a formatted string to a Window.
Definition: mutt_window.c:321
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_init_abort_key()

void mutt_init_abort_key ( void  )

Parse the abort_key config string.

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

Definition at line 858 of file keymap.c.

859{
860 keycode_t buf[2];
861 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
862 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
863 if (len == 0)
864 {
865 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
866 AbortKey = ctrl('G');
867 return;
868 }
869 if (len > 1)
870 {
871 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
872 c_abort_key);
873 }
874 AbortKey = buf[0];
875}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
#define mutt_warning(...)
Definition: logging.h:85
static size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: keymap.c:275
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: keymap.h:39
#define mutt_array_size(x)
Definition: memory.h:36
#define ctrl(ch)
Definition: mutt_curses.h:40
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_bind()

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

Bind a key to a macro.

Parameters
sKey string
mtypeMenu type, 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 459 of file keymap.c.

460{
461 return km_bind_err(s, mtype, op, macro, desc, NULL);
462}
static enum CommandResult km_bind_err(const char *s, enum MenuType mtype, int op, char *macro, char *desc, struct Buffer *err)
Set up a key binding.
Definition: keymap.c:362
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey()

int km_dokey ( enum MenuType  mtype)

Determine what a keypress should do.

Parameters
mtypeMenu type, 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 796 of file keymap.c.

797{
798 return km_dokey_event(mtype).op;
799}
struct KeyEvent km_dokey_event(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:638
int op
Function opcode, e.g. OP_HELP.
Definition: keymap.h:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_dokey_event()

struct KeyEvent km_dokey_event ( enum MenuType  mtype)

Determine what a keypress should do.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
Return values
ptrEvent

Definition at line 638 of file keymap.c.

639{
640 struct KeyEvent tmp = { OP_NULL, OP_NULL };
641 struct Keymap *map = STAILQ_FIRST(&Keymaps[mtype]);
642 int pos = 0;
643 int n = 0;
644
645 if (!map && (mtype != MENU_EDITOR))
646 return retry_generic(mtype, NULL, 0, 0);
647
648#ifdef USE_IMAP
649 const short c_imap_keepalive = cs_subset_number(NeoMutt->sub, "imap_keepalive");
650#endif
651
652 while (true)
653 {
654 const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
655 int i = (c_timeout > 0) ? c_timeout : 60;
656#ifdef USE_IMAP
657 /* keepalive may need to run more frequently than `$timeout` allows */
658 if (c_imap_keepalive)
659 {
660 if (c_imap_keepalive >= i)
662 else
663 {
664 while (c_imap_keepalive && (c_imap_keepalive < i))
665 {
666 tmp = mutt_getch_timeout(c_imap_keepalive * 1000);
667 /* If a timeout was not received, or the window was resized, exit the
668 * loop now. Otherwise, continue to loop until reaching a total of
669 * $timeout seconds. */
670 if ((tmp.op != OP_TIMEOUT) || SigWinch)
671 goto gotkey;
672#ifdef USE_INOTIFY
674 goto gotkey;
675#endif
676 i -= c_imap_keepalive;
678 }
679 }
680 }
681#endif
682
683 tmp = mutt_getch_timeout(i * 1000);
684
685#ifdef USE_IMAP
686 gotkey:
687#endif
688 /* hide timeouts, but not window resizes, from the line editor. */
689 if ((mtype == MENU_EDITOR) && (tmp.op == OP_TIMEOUT) && !SigWinch)
690 continue;
691
692 if ((tmp.op == OP_TIMEOUT) || (tmp.op == OP_ABORT))
693 {
694 return tmp;
695 }
696
697 /* do we have an op already? */
698 if (tmp.op != OP_NULL)
699 {
700 const char *func = NULL;
701 const struct MenuFuncOp *funcs = NULL;
702
703 /* is this a valid op for this menu type? */
704 if ((funcs = km_get_table(mtype)) && (func = mutt_get_func(funcs, tmp.op)))
705 return tmp;
706
707 if ((mtype != MENU_EDITOR) && (mtype != MENU_PAGER) && (mtype != MENU_GENERIC))
708 {
709 /* check generic menu type */
710 funcs = OpGeneric;
711 func = mutt_get_func(funcs, tmp.op);
712 if (func)
713 return tmp;
714 }
715
716 /* Sigh. Valid function but not in this context.
717 * Find the literal string and push it back */
718 for (i = 0; MenuNames[i].name; i++)
719 {
720 funcs = km_get_table(MenuNames[i].value);
721 if (funcs)
722 {
723 func = mutt_get_func(funcs, tmp.op);
724 if (func)
725 {
726 mutt_unget_ch('>');
727 mutt_unget_string(func);
728 mutt_unget_ch('<');
729 break;
730 }
731 }
732 }
733 /* continue to chew */
734 if (func)
735 continue;
736 }
737
738 if (!map)
739 return tmp;
740
741 /* Nope. Business as usual */
742 while (tmp.ch > map->keys[pos])
743 {
744 if ((pos > map->eq) || !STAILQ_NEXT(map, entries))
745 return retry_generic(mtype, map->keys, pos, tmp.ch);
746 map = STAILQ_NEXT(map, entries);
747 }
748
749 if (tmp.ch != map->keys[pos])
750 return retry_generic(mtype, map->keys, pos, tmp.ch);
751
752 if (++pos == map->len)
753 {
754 if (map->op != OP_MACRO)
755 return (struct KeyEvent){ .ch = tmp.ch, .op = map->op };
756
757 /* OptIgnoreMacroEvents turns off processing the MacroEvents buffer
758 * in mutt_getch(). Generating new macro events during that time would
759 * result in undesired behavior once the option is turned off.
760 *
761 * Originally this returned -1, however that results in an unbuffered
762 * username or password prompt being aborted. Returning OP_NULL allows
763 * mutt_enter_string_full() to display the keybinding pressed instead.
764 *
765 * It may be unexpected for a macro's keybinding to be returned,
766 * but less so than aborting the prompt. */
768 {
769 return (struct KeyEvent){ .ch = tmp.ch, .op = OP_NULL };
770 }
771
772 if (n++ == 10)
773 {
775 mutt_error(_("Macro loop detected"));
776 return (struct KeyEvent){ .ch = '\0', .op = -1 };
777 }
778
780 map = STAILQ_FIRST(&Keymaps[mtype]);
781 pos = 0;
782 }
783 }
784
785 /* not reached */
786}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
struct KeyEvent mutt_getch_timeout(int delay)
Get an event with a timeout.
Definition: curs_lib.c:196
void mutt_unget_string(const char *s)
Return a string to the input buffer.
Definition: curs_lib.c:542
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:560
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:288
SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.c:59
bool OptIgnoreMacroEvents
(pseudo) don't process macro/push/exec events while set
Definition: globals.c:71
void imap_keepalive(void)
Poll the current folder to keep the connection alive.
Definition: util.c:937
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a 'push' command.
Definition: keymap.c:539
const char * mutt_get_func(const struct MenuFuncOp *funcs, int op)
Get the name of a function.
Definition: keymap.c:519
static struct KeyEvent retry_generic(enum MenuType mtype, keycode_t *keys, int keyslen, int lastkey)
Try to find the key in the generic menu bindings.
Definition: keymap.c:612
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: keymap.c:1231
bool MonitorFilesChanged
true after a monitored file has changed
Definition: monitor.c:49
#define OP_TIMEOUT
Definition: opcodes.h:32
#define OP_ABORT
Definition: opcodes.h:33
#define STAILQ_FIRST(head)
Definition: queue.h:350
#define STAILQ_NEXT(elm, field)
Definition: queue.h:400
An event such as a keypress.
Definition: keymap.h:65
int ch
Raw key pressed.
Definition: keymap.h:66
char * macro
macro expansion (op == OP_MACRO)
Definition: keymap.h:50
short eq
number of leading keys equal to next entry
Definition: keymap.h:53
Mapping between a function and an operation.
Definition: keymap.h:92
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_get_table()

const struct MenuFuncOp * km_get_table ( enum MenuType  mtype)

Lookup a Menu's functions.

Parameters
mtypeMenu type, e.g. MENU_EDITOR
Return values
ptrArray of functions

Definition at line 1231 of file keymap.c.

1232{
1233 switch (mtype)
1234 {
1235 case MENU_ALIAS:
1236 return OpAlias;
1237 case MENU_ATTACH:
1238 return OpAttach;
1239#ifdef USE_AUTOCRYPT
1241 return OpAutocrypt;
1242#endif
1243 case MENU_COMPOSE:
1244 return OpCompose;
1245 case MENU_EDITOR:
1246 return OpEditor;
1247 case MENU_FOLDER:
1248 return OpBrowser;
1249 case MENU_GENERIC:
1250 return OpGeneric;
1251 case MENU_INDEX:
1252 return OpIndex;
1253#ifdef CRYPT_BACKEND_GPGME
1255 return OpPgp;
1257 return OpSmime;
1258#endif
1259#ifdef MIXMASTER
1260 case MENU_MIX:
1261 return OpMix;
1262#endif
1263 case MENU_PAGER:
1264 return OpPager;
1265 case MENU_PGP:
1266 return (WithCrypto & APPLICATION_PGP) ? OpPgp : NULL;
1267 case MENU_POSTPONE:
1268 return OpPostpone;
1269 case MENU_QUERY:
1270 return OpQuery;
1271 default:
1272 return NULL;
1273 }
1274}
const struct MenuFuncOp OpQuery[]
Functions for the external Query Menu.
Definition: functions.c:721
const struct MenuFuncOp OpMix[]
Functions for the Mixmaster Menu.
Definition: functions.c:514
const struct MenuFuncOp OpAttach[]
Functions for the Attachment Menu.
Definition: functions.c:69
const struct MenuFuncOp OpIndex[]
Functions for the Index Menu.
Definition: functions.c:349
const struct MenuFuncOp OpCompose[]
Functions for the Compose Menu.
Definition: functions.c:177
const struct MenuFuncOp OpSmime[]
Functions for the Smime Menu.
Definition: functions.c:736
const struct MenuFuncOp OpBrowser[]
Functions for the file Browser Menu.
Definition: functions.c:123
const struct MenuFuncOp OpAutocrypt[]
Functions for the Autocrypt Account.
Definition: functions.c:110
const struct MenuFuncOp OpPager[]
Functions for the Pager Menu.
Definition: functions.c:529
const struct MenuFuncOp OpEditor[]
Functions for the Editor Menu.
Definition: functions.c:254
const struct MenuFuncOp OpPgp[]
Functions for the Pgp Menu.
Definition: functions.c:701
const struct MenuFuncOp OpPostpone[]
Functions for the Postpone Menu.
Definition: functions.c:711
const struct MenuFuncOp OpAlias[]
Functions for the Alias Menu.
Definition: functions.c:55
+ Here is the caller graph for this function:

◆ mutt_get_func()

const char * mutt_get_func ( const struct MenuFuncOp funcs,
int  op 
)

Get the name of a function.

Parameters
funcsFunctions table
opOperation, e.g. OP_DELETE
Return values
ptrName of function
NULLOperation not found
Note
This returns a static string.

Definition at line 519 of file keymap.c.

520{
521 for (int i = 0; funcs[i].name; i++)
522 {
523 if (funcs[i].op == op)
524 return funcs[i].name;
525 }
526
527 return NULL;
528}
const char * name
Name of the function.
Definition: keymap.h:93
+ Here is the caller graph for this function:

◆ mutt_keys_free()

void mutt_keys_free ( void  )

Free the key maps.

Definition at line 1907 of file keymap.c.

1908{
1909 for (int i = 0; i < MENU_MAX; i++)
1910 {
1912 }
1913}
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: keymap.c:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_unmacro()

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

Variable Documentation

◆ Keymaps

struct KeymapList Keymaps[]
extern

Array of Keymap keybindings, one for each Menu.

Definition at line 127 of file keymap.c.

◆ AbortKey

keycode_t AbortKey
extern

key to abort edits etc, normally Ctrl-G

key to abort edits etc, normally Ctrl-G

Definition at line 125 of file keymap.c.

◆ Menus

const struct Mapping Menus[]
extern