NeoMutt  2024-04-25-100-gcb3684
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 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 114 of file init.c.

115{
116 for (int j = 0; ExtKeys[j].name; j++)
117 {
118 if (strcasecmp(key, ExtKeys[j].name) == 0)
119 return ExtKeys[j].sym;
120 }
121 return 0;
122}
static const struct Extkey ExtKeys[]
Mapping between NeoMutt and Curses key names.
Definition: init.c:69
const char * sym
Curses key name.
Definition: init.c:63
const char * name
NeoMutt key name.
Definition: init.c:62
+ 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 134 of file init.c.

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

166{
167 STAILQ_INIT(&Keymaps[mtype]);
168
169 for (int i = 0; map[i].op != OP_NULL; i++)
170 if (map[i].seq)
171 km_bindkey(map[i].seq, mtype, map[i].op);
172}
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:125
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 177 of file init.c.

178{
179 memset(Keymaps, 0, sizeof(struct KeymapList) * MENU_MAX);
180
183#ifdef USE_AUTOCRYPT
185#endif
195
200
201#ifdef CRYPT_BACKEND_GPGME
204#endif
205}
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 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:165
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:153
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_KEY_SELECT_SMIME
Select a SMIME key.
Definition: type.h:49
@ MENU_QUERY
Select from results of external query.
Definition: type.h:55
@ 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:53
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:52
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:56
@ MENU_MAX
Definition: type.h:57
@ 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:54
+ 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 211 of file init.c.

212{
213 struct Keymap *np = NULL, *tmp = NULL;
214 STAILQ_FOREACH_SAFE(np, km_list, entries, tmp)
215 {
216 STAILQ_REMOVE(km_list, np, Keymap, entries);
217 mutt_keymap_free(&np);
218 }
219}
void mutt_keymap_free(struct Keymap **ptr)
Free a Keymap.
Definition: lib.c:131
#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 224 of file init.c.

225{
226 for (enum MenuType i = 1; i < MENU_MAX; i++)
227 {
229 }
230}
static void mutt_keymaplist_free(struct KeymapList *km_list)
Free a List of Keymaps.
Definition: init.c:211
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 237 of file init.c.

238{
239 keycode_t buf[2];
240 const char *const c_abort_key = cs_subset_string(NeoMutt->sub, "abort_key");
241 size_t len = parsekeys(c_abort_key, buf, mutt_array_size(buf));
242 if (len == 0)
243 {
244 mutt_error(_("Abort key is not set, defaulting to Ctrl-G"));
245 AbortKey = ctrl('G');
246 return;
247 }
248 if (len > 1)
249 {
250 mutt_warning(_("Specified abort key sequence (%s) will be truncated to first key"),
251 c_abort_key);
252 }
253 AbortKey = buf[0];
254}
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:90
#define mutt_error(...)
Definition: logging2.h:92
keycode_t AbortKey
code of key to abort prompts, normally Ctrl-G
Definition: lib.c:122
size_t parsekeys(const char *str, keycode_t *d, size_t max)
Parse a key string into key codes.
Definition: lib.c:216
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:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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 153 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.

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