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 "functions.h"
#include "init.h"
#include "mutt_globals.h"
#include "mutt_logging.h"
#include "opcodes.h"
#include "options.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... | |
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 192 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 208 of file keymap.c.
|
static |
|
static |
|
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 274 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 |
|
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 333 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 333 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 |
|
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 333 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 496 of file keymap.c.
const char* mutt_get_func | ( | const struct MenuFuncOp * | funcs, |
int | op | ||
) |
|
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 538 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 538 of file keymap.c.
Determine what a keypress should do.
mtype | Menu type, e.g. MENU_EDITOR |
ptr | Event |
Definition at line 538 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 795 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 805 of file keymap.c.
|
static |
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 857 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 901 of file keymap.c.
int km_expand_key | ( | char * | s, |
size_t | len, | ||
struct Keymap * | map | ||
) |
|
static |
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 994 of file keymap.c.
void km_init | ( | void | ) |
Initialise all the menu keybindings.
Definition at line 1023 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 1059 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 1143 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 1143 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 1228 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 1375 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 1404 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 1636 of file keymap.c.
void mutt_keys_free | ( | void | ) |
Free the key maps.
Definition at line 1666 of file keymap.c.
keycode_t AbortKey |
struct KeymapList Keymaps[MENU_MAX] |