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/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "keymap.h"
#include "color/lib.h"
#include "menu/lib.h"
#include "ncrypt/lib.h"
#include "pager/lib.h"
#include "parse/lib.h"
#include "functions.h"
#include "globals.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "opcodes.h"
#include "imap/lib.h"
#include "monitor.h"
Go to the source code of this file.
Data Structures | |
struct | Extkey |
Map key names from NeoMutt's style to Curses style. More... | |
Functions | |
static void | mutt_keymap_free (struct Keymap **km) |
Free a Keymap. More... | |
static void | mutt_keymaplist_free (struct KeymapList *km_list) |
Free a List of Keymaps. More... | |
static struct Keymap * | alloc_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 struct Keymap * | km_compare_keys (struct Keymap *k1, struct Keymap *k2, size_t *pos) |
Compare two keymaps' keyscodes and return the bigger one. More... | |
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. More... | |
enum CommandResult | km_bind (char *s, enum MenuType mtype, int op, char *macro, char *desc) |
Bind a key to a macro. More... | |
static enum CommandResult | km_bindkey_err (const char *s, enum MenuType mtype, 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, enum MenuType mtype, int op) |
Bind a key in a Menu to an operation. More... | |
static int | get_op (const struct MenuFuncOp *funcs, const char *start, size_t len) |
Get the function by its name. More... | |
const char * | mutt_get_func (const struct MenuFuncOp *funcs, 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 struct KeyEvent | retry_generic (enum MenuType mtype, keycode_t *keys, int keyslen, int lastkey) |
Try to find the key in the generic menu bindings. More... | |
struct KeyEvent | km_dokey_event (enum MenuType mtype) |
Determine what a keypress should do. More... | |
int | km_dokey (enum MenuType mtype) |
Determine what a keypress should do. More... | |
static void | create_bindings (const struct MenuOpSeq *map, enum MenuType mtype) |
Attach a set of keybindings to a Menu. More... | |
static const char * | km_keyname (int c) |
Get the human name for 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... | |
static int | km_expand_key_string (char *str, char *buf, size_t buflen) |
Get a human-readable key string. More... | |
int | km_expand_key (char *s, size_t len, struct Keymap *map) |
Get the key string bound to a Keymap. More... | |
struct Keymap * | km_find_func (enum MenuType mtype, int func) |
Find a function's mapping in a Menu. More... | |
static const char * | find_ext_name (const char *key) |
Find the curses name for a key. 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 (enum MenuType mtype) |
Handle an unbound key sequence. 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... | |
static char * | parse_keymap (enum MenuType *mtypes, struct Buffer *s, int max_menus, int *num_menus, struct Buffer *err, bool bind) |
Parse a user-config key binding. More... | |
static enum CommandResult | try_bind (char *key, enum MenuType mtype, char *func, const struct MenuFuncOp *funcs, struct Buffer *err) |
Try to make a key binding. More... | |
const struct MenuFuncOp * | km_get_table (enum MenuType mtype) |
Lookup a Menu's functions. More... | |
static bool | dump_bind (struct Buffer *buf, struct Mapping *menu) |
Dumps all the binds maps of a menu into a buffer. More... | |
static void | dump_all_binds (struct Buffer *buf) |
Dumps all the binds inside every menu. More... | |
static bool | dump_macro (struct Buffer *buf, struct Mapping *menu) |
Dumps all the macros maps of a menu into a buffer. More... | |
static void | dump_all_macros (struct Buffer *buf) |
Dumps all the macros inside every menu. More... | |
static enum CommandResult | dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err) |
Parse 'bind' and 'macro' commands - Implements ICommand::parse() 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... | |
static void * | parse_menu (bool *menus, char *s, struct Buffer *err) |
Parse menu-names into an array. More... | |
static void | km_unbind_all (struct KeymapList *km_list, unsigned long mode) |
Free all the keys in the supplied Keymap. 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_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_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err) |
Parse the 'exec' command - Implements Command::parse() -. More... | |
void | mutt_what_key (void) |
Ask the user to press a key. More... | |
void | mutt_keys_free (void) |
Free the key maps. More... | |
Variables | |
static struct Mapping | KeyNames [] |
Key name lookup table. More... | |
keycode_t | AbortKey |
code of key to abort prompts, normally Ctrl-G More... | |
struct KeymapList | Keymaps [MENU_MAX] |
Array of Keymap keybindings, one for each Menu. More... | |
static const struct Extkey | ExtKeys [] |
Manage keymappings.
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.
|
static |
|
static |
Free a List of Keymaps.
km_list | List of Keymaps to free |
Definition at line 193 of file keymap.c.
Allocate space for a sequence of keys.
len | Number of keys |
keys | Array of keys |
ptr | Sequence of keys |
Definition at line 209 of file keymap.c.
|
static |
Parse a function key string.
s | String to parse |
num | Number of the key |
Given "<f8>", it will return 8.
Definition at line 225 of file keymap.c.
|
static |
Parse a numeric keycode.
s | String to parse |
num | Number of the key |
This function parses the string <NNN>
and uses the octal value as the key to bind.
Definition at line 252 of file keymap.c.
|
static |
Parse a key string into key codes.
str | Key string |
d | Array for key codes |
max | Maximum length of key sequence |
num | Length of key sequence |
Definition at line 275 of file keymap.c.
|
static |
Compare two keymaps' keyscodes and return the bigger one.
k1 | first keymap to compare |
k2 | second keymap to compare |
pos | position where the two keycodes differ |
ptr | Keymap with a bigger ASCII keycode |
Definition at line 334 of file keymap.c.
|
static |
Set up a key binding.
s | Key string |
mtype | Menu type, e.g. MENU_EDITOR |
op | Operation, e.g. OP_DELETE |
macro | Macro string |
desc | Description of macro (OPTIONAL) |
err | Buffer for error message |
CommandResult | Result 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 362 of file keymap.c.
enum CommandResult km_bind | ( | char * | s, |
enum MenuType | mtype, | ||
int | op, | ||
char * | macro, | ||
char * | desc | ||
) |
Bind a key to a macro.
s | Key string |
mtype | Menu type, e.g. MENU_EDITOR |
op | Operation, e.g. OP_DELETE |
macro | Macro string |
desc | Description of macro (OPTIONAL) |
CommandResult | Result e.g. MUTT_CMD_SUCCESS |
Definition at line 459 of file keymap.c.
|
static |
Bind a key in a Menu to an operation (with error message)
s | Key string |
mtype | Menu type, e.g. MENU_PAGER |
op | Operation, e.g. OP_DELETE |
err | Buffer for error message |
CommandResult | Result e.g. MUTT_CMD_SUCCESS |
Definition at line 472 of file keymap.c.
|
static |
Bind a key in a Menu to an operation.
s | Key string |
mtype | Menu type, e.g. MENU_PAGER |
op | Operation, e.g. OP_DELETE |
CommandResult | Result e.g. MUTT_CMD_SUCCESS |
Definition at line 485 of file keymap.c.
|
static |
Get the function by its name.
funcs | Functions table |
start | Name of function to find |
len | Length of string to match |
num | Operation, e.g. OP_DELETE |
Definition at line 497 of file keymap.c.
const char * mutt_get_func | ( | const struct MenuFuncOp * | funcs, |
int | op | ||
) |
Get the name of a function.
funcs | Functions table |
op | Operation, e.g. OP_DELETE |
ptr | Name of function |
NULL | Operation not found |
Definition at line 519 of file keymap.c.
|
static |
Parse and queue a 'push' command.
s | String to push into the key queue |
generic_push | Callback 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 539 of file keymap.c.
|
static |
Try to find the key in the generic menu bindings.
mtype | Menu type, e.g. MENU_PAGER |
keys | Array of keys to return to the input queue |
keyslen | Number of keys in the array |
lastkey | Last key pressed (to return to input queue) |
num | Operation, e.g. OP_DELETE |
Definition at line 612 of file keymap.c.
Determine what a keypress should do.
mtype | Menu type, e.g. MENU_EDITOR |
ptr | Event |
Definition at line 638 of file keymap.c.
int km_dokey | ( | enum MenuType | mtype | ) |
Determine what a keypress should do.
mtype | Menu type, e.g. MENU_EDITOR |
>0 | Function to execute |
OP_NULL | No function bound to key sequence |
-1 | Error occurred while reading input |
-2 | A timeout or sigwinch occurred |
Definition at line 796 of file keymap.c.
Attach a set of keybindings to a Menu.
map | Key bindings |
mtype | Menu type, e.g. MENU_PAGER |
Definition at line 806 of file keymap.c.
|
static |
Get the human name for a key.
c | Key code |
ptr | Name of the key |
Definition at line 822 of file keymap.c.
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.
|
static |
Get a human-readable key string.
str | Raw key string |
buf | Buffer for the key string |
buflen | Length of buffer |
num | Length of string |
Definition at line 904 of file keymap.c.
int km_expand_key | ( | char * | s, |
size_t | len, | ||
struct Keymap * | map | ||
) |
Get the key string bound to a Keymap.
s | Buffer for the key string |
len | Length of buffer |
map | Keybinding map |
1 | Success |
0 | Error |
Definition at line 929 of file keymap.c.
|
static |
Find the curses name for a key.
key | Key name |
ptr | Curses name |
Look up NeoMutt's name for a key and find the ncurses extended name for it.
Definition at line 977 of file keymap.c.
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.
void km_init | ( | void | ) |
Initialise all the menu keybindings.
Definition at line 1026 of file keymap.c.
void km_error_key | ( | enum MenuType | mtype | ) |
Handle an unbound key sequence.
mtype | Menu type, e.g. MENU_PAGER |
Definition at line 1062 of file keymap.c.
|
static |
Parse a user-config key binding.
mtypes | Array for results |
s | Buffer containing config string |
max_menus | Total number of menus |
num_menus | Number of menus this config applies to |
err | Buffer for error messages |
bind | If true 'bind', otherwise 'macro' |
ptr | Key string for the binding |
Expects to see: <menu-string>,<menu-string>,... <key-string>
Definition at line 1146 of file keymap.c.
|
static |
Try to make a key binding.
key | Key name |
mtype | Menu type, e.g. MENU_PAGER |
func | Function name |
funcs | Functions table |
err | Buffer for error message |
CommandResult | Result e.g. MUTT_CMD_SUCCESS |
Definition at line 1208 of file keymap.c.
const struct MenuFuncOp * km_get_table | ( | enum MenuType | mtype | ) |
mtype | Menu type, e.g. MENU_EDITOR |
ptr | Array of functions |
Definition at line 1231 of file keymap.c.
Dumps all the binds maps of a menu into a buffer.
buf | Output buffer |
menu | Menu to dump |
Definition at line 1283 of file keymap.c.
|
static |
Dumps all the binds inside every menu.
buf | Output buffer |
Definition at line 1333 of file keymap.c.
Dumps all the macros maps of a menu into a buffer.
buf | Output buffer |
menu | Menu to dump |
Definition at line 1355 of file keymap.c.
|
static |
Dumps all the macros inside every menu.
buf | Output buffer |
Definition at line 1392 of file keymap.c.
|
static |
Parse 'bind' and 'macro' commands - Implements ICommand::parse()
Definition at line 1410 of file keymap.c.
|
static |
Parse menu-names into an array.
menus | Array for results |
s | String containing menu-names |
err | Buffer for error messages |
NULL | Always |
Expects to see: <menu-string>[,<menu-string>]
Definition at line 1605 of file keymap.c.
|
static |
Free all the keys in the supplied Keymap.
km_list | Keymap mapping |
mode | Undo bind or macro, e.g. MUTT_UNBIND, MUTT_UNMACRO |
Iterate through Keymap and free keys defined either by "macro" or "bind".
Definition at line 1634 of file keymap.c.
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.
void mutt_keys_free | ( | void | ) |
Free the key maps.
Definition at line 1907 of file keymap.c.
keycode_t AbortKey |
struct KeymapList Keymaps[MENU_MAX] |