NeoMutt  2025-09-05-7-geaa2bd
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 "lib.h"
#include "menu/lib.h"
+ Include dependency graph for init.c:

Go to the source code of this file.

Functions

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

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

◆ 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 135 of file init.c.

136{
137#ifdef HAVE_USE_EXTENDED_NAMES
138 use_extended_names(true);
139
140 for (int j = 0; KeyNames[j].name; j++)
141 {
142 if (KeyNames[j].value == -1)
143 {
144 const char *keyname = find_ext_name(KeyNames[j].name);
145
146 if (keyname)
147 {
148 const char *s = mutt_tigetstr((char *) keyname);
149 if (s && ((long) (s) != -1))
150 {
151 int code = key_defined(s);
152 if (code > 0)
153 KeyNames[j].value = code;
154 }
155 }
156 }
157 }
158#endif
159}
struct Mapping KeyNames[]
Key name lookup table.
Definition: lib.c:59
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:68
+ 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 166 of file init.c.

167{
168 STAILQ_INIT(&Keymaps[mtype]);
169
170 for (int i = 0; map[i].op != OP_NULL; i++)
171 if (map[i].seq)
172 km_bindkey(map[i].seq, mtype, map[i].op);
173}
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:124
enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: parse.c:191
#define STAILQ_INIT(head)
Definition: queue.h:410
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:122
+ 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 178 of file init.c.

179{
180 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
181
184#ifdef USE_AUTOCRYPT
186#endif
198}
const struct MenuOpSeq GenericDefaultBindings[]
Key bindings for the Generic Menu.
Definition: functions.c:139
const struct MenuOpSeq DialogDefaultBindings[]
Key bindings for Simple Dialogs.
Definition: functions.c:131
const struct MenuOpSeq AttachmentDefaultBindings[]
Key bindings for the Attachment Menu.
Definition: functions.c:98
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:110
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:106
const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition: functions.c:93
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:235
const struct MenuOpSeq AutocryptDefaultBindings[]
Key bindings for the Autocrypt Account.
Definition: functions.c:68
static void create_bindings(const struct MenuOpSeq *map, enum MenuType mtype)
Attach a set of keybindings to a Menu.
Definition: init.c:166
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:155
const struct MenuOpSeq SmimeDefaultBindings[]
Key bindings for the Smime Menu.
Definition: functions.c:74
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:47
@ MENU_DIALOG
Simple Dialog.
Definition: type.h:43
@ MENU_QUERY
Select from results of external query.
Definition: type.h:51
@ 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:49
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:48
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:52
@ MENU_MAX
Definition: type.h:53
@ 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:50
+ 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 204 of file init.c.

205{
206 struct Keymap *np = NULL, *tmp = NULL;
207 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
208 {
209 STAILQ_REMOVE(km_list, np, Keymap, entries);
210 mutt_keymap_free(&np);
211 }
212}
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:130
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:441
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:400
A keyboard mapping.
Definition: lib.h:66
+ 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 217 of file init.c.

218{
219 for (enum MenuType i = 1; i < MENU_MAX; i++)
220 {
222 }
223}
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: init.c:204
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 230 of file init.c.

231{
232 keycode_t buf[2];
233 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
234 size_t len = parsekeys(c_abort_key, buf, countof(buf));
235 if (len == 0)
236 {
237 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
238 AbortKey = ctrl('G');
239 return;
240 }
241 if (len > 1)
242 {
243 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
244 c_abort_key);
245 }
246 AbortKey = buf[0];
247}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
#define mutt_warning(...)
Definition: logging2.h:91
#define mutt_error(...)
Definition: logging2.h:93
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: lib.c:121
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:215
short keycode_t
Type for key storage, the rest of neomutt works fine with int type.
Definition: lib.h:56
#define countof(x)
Definition: memory.h:44
#define _(a)
Definition: message.h:28
#define ctrl(ch)
Definition: mutt_curses.h:52
Container for Accounts, Notifications.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47
+ 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 93 of file functions.c.

◆ AttachmentDefaultBindings

const struct MenuOpSeq AttachmentDefaultBindings[]
extern

Key bindings for the Attachment Menu.

Definition at line 98 of file functions.c.

◆ AutocryptDefaultBindings

const struct MenuOpSeq AutocryptDefaultBindings[]
extern

Key bindings for the Autocrypt Account.

Definition at line 68 of file functions.c.

◆ BrowserDefaultBindings

const struct MenuOpSeq BrowserDefaultBindings[]
extern

Key bindings for the file Browser Menu.

Definition at line 106 of file functions.c.

◆ ComposeDefaultBindings

const struct MenuOpSeq ComposeDefaultBindings[]
extern

Key bindings for the Compose Menu.

Definition at line 155 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 235 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 110 of file functions.c.

◆ SmimeDefaultBindings

const struct MenuOpSeq SmimeDefaultBindings[]
extern

Key bindings for the Smime Menu.

Definition at line 74 of file functions.c.