NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
init.c File Reference

Set up the key bindings. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "ncrypt/lib.h"
+ Include dependency graph for init.c:

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 const char * find_ext_name (const char *key)
 Find the curses name for a key.
 
void init_extended_keys (void)
 Initialise map of ncurses extended keys.
 
static void create_bindings (const struct MenuOpSeq *map, enum MenuType mtype)
 Attach a set of keybindings to a Menu.
 
void km_init (void)
 Initialise all the menu keybindings.
 
static void mutt_keymaplist_free (struct KeymapList *km_list)
 Free a List of Keymaps.
 
void mutt_keys_cleanup (void)
 Free the key maps.
 
void mutt_init_abort_key (void)
 Parse the abort_key config string.
 
int main_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 

Variables

const struct MenuOpSeq AliasDefaultBindings []
 Key bindings for the Alias Menu.
 
const struct MenuOpSeq AttachmentDefaultBindings []
 Key bindings for the Attachment Menu.
 
const struct MenuOpSeq AutocryptDefaultBindings []
 Key bindings for the Autocrypt Account.
 
const struct MenuOpSeq BrowserDefaultBindings []
 Key bindings for the file Browser Menu.
 
const struct MenuOpSeq ComposeDefaultBindings []
 Key bindings for the Compose Menu.
 
const struct MenuOpSeq EditorDefaultBindings []
 Key bindings for the Editor Menu.
 
const struct MenuOpSeq IndexDefaultBindings []
 Key bindings for the Index Menu.
 
const struct MenuOpSeq MixmasterDefaultBindings []
 Key bindings for the Mixmaster Menu.
 
const struct MenuOpSeq PagerDefaultBindings []
 Key bindings for the Pager Menu.
 
const struct MenuOpSeq PgpDefaultBindings []
 Key bindings for the Pgp Menu.
 
const struct MenuOpSeq PostponedDefaultBindings []
 Key bindings for the Postpone Menu.
 
const struct MenuOpSeq QueryDefaultBindings []
 Key bindings for the external Query Menu.
 
const struct MenuOpSeq SmimeDefaultBindings []
 Key bindings for the Smime Menu.
 
static const struct Extkey ExtKeys []
 Mapping between NeoMutt and Curses key names.
 

Detailed Description

Set up the key bindings.

Authors
  • Richard Russon

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 init.c.

Function Documentation

◆ find_ext_name()

static const char * find_ext_name ( const char *  key)
static

Find the curses name for a key.

Parameters
keyKey name
Return values
ptrCurses name

Look up NeoMutt's name for a key and find the ncurses extended name for it.

Note
This returns a static string.

Definition at line 117 of file init.c.

118{
119 for (int j = 0; ExtKeys[j].name; j++)
120 {
121 if (strcasecmp(key, ExtKeys[j].name) == 0)
122 return ExtKeys[j].sym;
123 }
124 return 0;
125}
static const struct Extkey ExtKeys[]
Mapping between NeoMutt and Curses key names.
Definition: init.c:72
const char * sym
Curses key name.
Definition: init.c:66
const char * name
NeoMutt key name.
Definition: init.c:65
+ Here is the caller graph for this function:

◆ 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 mutt_tigetstr() fails. 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 137 of file init.c.

138{
139#ifdef HAVE_USE_EXTENDED_NAMES
140 use_extended_names(true);
141
142 for (int j = 0; KeyNames[j].name; j++)
143 {
144 if (KeyNames[j].value == -1)
145 {
146 const char *keyname = find_ext_name(KeyNames[j].name);
147
148 if (keyname)
149 {
150 const char *s = mutt_tigetstr((char *) keyname);
151 if (s && ((long) (s) != -1))
152 {
153 int code = key_defined(s);
154 if (code > 0)
155 KeyNames[j].value = code;
156 }
157 }
158 }
159 }
160#endif
161}
static const char * find_ext_name(const char *key)
Find the curses name for a key.
Definition: init.c:117
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:63
int value
Integer value.
Definition: mapping.h:35
const char * name
String value.
Definition: mapping.h:34
const char * mutt_tigetstr(const char *name)
Get terminal capabilities.
Definition: terminal.c:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_bindings()

static void create_bindings ( const struct MenuOpSeq map,
enum MenuType  mtype 
)
static

Attach a set of keybindings to a Menu.

Parameters
mapKey bindings
mtypeMenu type, e.g. MENU_PAGER

Definition at line 168 of file init.c.

169{
170 STAILQ_INIT(&Keymaps[mtype]);
171
172 for (int i = 0; map[i].op != OP_NULL; i++)
173 if (map[i].seq)
174 km_bindkey(map[i].seq, mtype, map[i].op);
175}
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:128
enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: parse.c:186
#define STAILQ_INIT(head)
Definition: queue.h:372
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ km_init()

void km_init ( void  )

Initialise all the menu keybindings.

Definition at line 180 of file init.c.

181{
182 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
183
186#ifdef USE_AUTOCRYPT
188#endif
195#ifdef MIXMASTER
197#endif
201
206
207#ifdef CRYPT_BACKEND_GPGME
210#endif
211}
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition: functions.c:138
const struct MenuOpSeq DialogDefaultBindings[]
Key bindings for Simple Dialogs.
Definition: functions.c:130
const struct MenuOpSeq AttachmentDefaultBindings[]
Key bindings for the Attachment Menu.
Definition: functions.c:100
const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition: functions.c:88
const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition: functions.c:103
const struct MenuOpSeq PostponedDefaultBindings[]
Key bindings for the Postpone Menu.
Definition: functions.c:62
const struct MenuOpSeq BrowserDefaultBindings[]
Key bindings for the file Browser Menu.
Definition: functions.c:108
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:88
const struct MenuOpSeq PagerDefaultBindings[]
Key bindings for the Pager Menu.
Definition: functions.c:229
const struct MenuOpSeq IndexDefaultBindings[]
Key bindings for the Index Menu.
Definition: functions.c:239
const struct MenuOpSeq MixmasterDefaultBindings[]
Key bindings for the Mixmaster Menu.
Definition: functions.c:65
const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:66
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: init.c:168
const struct MenuOpSeq PgpDefaultBindings[]
Key bindings for the Pgp Menu.
Definition: functions.c:64
const struct MenuOpSeq ComposeDefaultBindings[]
Key bindings for the Compose Menu.
Definition: functions.c:159
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition: functions.c:74
#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:48
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:51
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_MIXMASTER
Create/edit a Mixmaster chain.
Definition: type.h:53
@ MENU_KEY_SELECT_SMIME
Select a SMIME key.
Definition: type.h:49
@ MENU_QUERY
Select from results of external query.
Definition: type.h:58
@ MENU_AUTOCRYPT
Autocrypt Account menu.
Definition: type.h:40
@ MENU_COMPOSE
Compose an email.
Definition: type.h:42
@ MENU_ATTACHMENT
Select an attachment.
Definition: type.h:38
@ MENU_PGP
PGP encryption menu.
Definition: type.h:56
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:55
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:59
@ MENU_MAX
Definition: type.h:60
@ MENU_EDITOR
Text entry area.
Definition: type.h:44
@ MENU_ALIAS
Select an email address by its alias.
Definition: type.h:37
@ MENU_FOLDER
General file/mailbox browser.
Definition: type.h:45
@ MENU_POSTPONED
Select a postponed email.
Definition: type.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_keymaplist_free()

static void mutt_keymaplist_free ( struct KeymapList *  km_list)
static

Free a List of Keymaps.

Parameters
km_listList of Keymaps to free

Definition at line 217 of file init.c.

218{
219 struct Keymap *np = NULL, *tmp = NULL;
220 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
221 {
222 STAILQ_REMOVE(km_list, np, Keymap, entries);
223 mutt_keymap_free(&np);
224 }
225}
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:134
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
A keyboard mapping.
Definition: lib.h:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_keys_cleanup()

void mutt_keys_cleanup ( void  )

Free the key maps.

Definition at line 230 of file init.c.

231{
232 for (enum MenuType i = 1; i < MENU_MAX; i++)
233 {
235 }
236}
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: init.c:217
MenuType
Types of GUI selections.
Definition: type.h:36
+ 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 243 of file init.c.

244{
245 keycode_t buf[2];
246 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
247 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
248 if (len == 0)
249 {
250 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
251 AbortKey = ctrl('G');
252 return;
253 }
254 if (len > 1)
255 {
256 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
257 c_abort_key);
258 }
259 AbortKey = buf[0];
260}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
#define mutt_warning(...)
Definition: logging2.h:90
#define mutt_error(...)
Definition: logging2.h:92
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: lib.c:125
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:219
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:55
#define mutt_array_size(x)
Definition: memory.h:38
#define _(a)
Definition: message.h:28
#define ctrl(ch)
Definition: mutt_curses.h:52
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ AliasDefaultBindings

const struct MenuOpSeq AliasDefaultBindings[]
extern

Key bindings for the Alias Menu.

Definition at line 88 of file functions.c.

◆ AttachmentDefaultBindings

const struct MenuOpSeq AttachmentDefaultBindings[]
extern

Key bindings for the Attachment Menu.

Definition at line 100 of file functions.c.

◆ AutocryptDefaultBindings

const struct MenuOpSeq AutocryptDefaultBindings[]
extern

Key bindings for the Autocrypt Account.

Definition at line 66 of file functions.c.

◆ BrowserDefaultBindings

const struct MenuOpSeq BrowserDefaultBindings[]
extern

Key bindings for the file Browser Menu.

Definition at line 108 of file functions.c.

◆ ComposeDefaultBindings

const struct MenuOpSeq ComposeDefaultBindings[]
extern

Key bindings for the Compose Menu.

Definition at line 159 of file functions.c.

◆ EditorDefaultBindings

const struct MenuOpSeq EditorDefaultBindings[]
extern

Key bindings for the Editor Menu.

Definition at line 88 of file functions.c.

◆ IndexDefaultBindings

const struct MenuOpSeq IndexDefaultBindings[]
extern

Key bindings for the Index Menu.

Definition at line 239 of file functions.c.

◆ MixmasterDefaultBindings

const struct MenuOpSeq MixmasterDefaultBindings[]
extern

Key bindings for the Mixmaster Menu.

Definition at line 65 of file functions.c.

◆ PagerDefaultBindings

const struct MenuOpSeq PagerDefaultBindings[]
extern

Key bindings for the Pager Menu.

Definition at line 229 of file functions.c.

◆ PgpDefaultBindings

const struct MenuOpSeq PgpDefaultBindings[]
extern

Key bindings for the Pgp Menu.

Definition at line 64 of file functions.c.

◆ PostponedDefaultBindings

const struct MenuOpSeq PostponedDefaultBindings[]
extern

Key bindings for the Postpone Menu.

Definition at line 62 of file functions.c.

◆ QueryDefaultBindings

const struct MenuOpSeq QueryDefaultBindings[]
extern

Key bindings for the external Query Menu.

Definition at line 103 of file functions.c.

◆ SmimeDefaultBindings

const struct MenuOpSeq SmimeDefaultBindings[]
extern

Key bindings for the Smime Menu.

Definition at line 74 of file functions.c.

◆ ExtKeys

const struct Extkey ExtKeys[]
static

Mapping between NeoMutt and Curses key names.

Definition at line 72 of file init.c.