NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c File Reference

Editor functions. More...

#include "config.h"
#include <wchar.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "functions.h"
#include "complete/lib.h"
#include "history/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "enter.h"
#include "module_data.h"
#include "mutt_logging.h"
#include "state.h"
#include "wdata.h"
+ Include dependency graph for functions.c:

Go to the source code of this file.

Functions

void editor_init_keys (struct NeoMutt *n, struct SubMenu *sm_generic)
 Initialise the Editor Keybindings - Implements ::init_keys_api.
 
void replace_part (struct EnterState *es, size_t from, const char *buf)
 Search and replace on a buffer.
 
static int op_editor_complete (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Complete filename or alias - Implements enter_function_t -.
 
static int op_editor_history_down (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Scroll down through the history list - Implements enter_function_t -.
 
static int op_editor_history_search (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Search through the history list - Implements enter_function_t -.
 
static int op_editor_history_up (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Scroll up through the history list - Implements enter_function_t -.
 
static int op_editor_backspace (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Delete the char in front of the cursor - Implements enter_function_t -.
 
static int op_editor_backward_char (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Move the cursor one character to the left - Implements enter_function_t -.
 
static int op_editor_backward_word (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Move the cursor to the beginning of the word - Implements enter_function_t -.
 
static int op_editor_bol (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Jump to the beginning of the line - Implements enter_function_t -.
 
static int op_editor_capitalize_word (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Capitalize the word - Implements enter_function_t - This function handles:
 
static int op_editor_delete_char (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Delete the char under the cursor - Implements enter_function_t -.
 
static int op_editor_eol (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Jump to the end of the line - Implements enter_function_t -.
 
static int op_editor_forward_char (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Move the cursor one character to the right - Implements enter_function_t -.
 
static int op_editor_forward_word (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Move the cursor to the end of the word - Implements enter_function_t -.
 
static int op_editor_kill_eol (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Delete chars from cursor to end of line - Implements enter_function_t -.
 
static int op_editor_kill_eow (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Delete chars from the cursor to the end of the word - Implements enter_function_t -.
 
static int op_editor_kill_line (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Delete all chars on the line - Implements enter_function_t -.
 
static int op_editor_kill_whole_line (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Delete all chars on the line - Implements enter_function_t -.
 
static int op_editor_kill_word (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Delete the word in front of the cursor - Implements enter_function_t -.
 
static int op_editor_quote_char (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Quote the next typed key - Implements enter_function_t -.
 
static int op_editor_transpose_chars (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Transpose character under cursor with previous - Implements enter_function_t -.
 
static int op_help (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Display Help - Implements enter_function_t -.
 
static int op_redraw (struct EnterFunctionData *fdata, const struct KeyEvent *event)
 Redraw the screen - Implements enter_function_t -.
 
int enter_function_dispatcher (struct MuttWindow *win, const struct KeyEvent *event)
 Perform an Enter function - Implements function_dispatcher_t -.
 
struct MenuDefinitioneditor_get_menu_definition (void)
 Get the Editor Menu Definition.
 
struct SubMenueditor_get_submenu (void)
 Get the Editor SubMenu.
 

Variables

static const struct MenuFuncOp OpEditor []
 Functions for the Editor Menu.
 
static const struct MenuOpSeq EditorDefaultBindings []
 Key bindings for the Editor Menu.
 
static const struct EnterFunction EnterFunctions []
 All the NeoMutt functions that Enter supports.
 

Detailed Description

Editor functions.

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

Function Documentation

◆ editor_init_keys()

void editor_init_keys ( struct NeoMutt * n,
struct SubMenu * sm_generic )

Initialise the Editor Keybindings - Implements ::init_keys_api.

Definition at line 127 of file functions.c.

128{
130 ASSERT(mod_data);
131
132 struct MenuDefinition *md = NULL;
133 struct SubMenu *sm = NULL;
134
136 md = km_register_menu(MENU_EDITOR, "editor");
137 km_menu_add_submenu(md, sm);
139
140 mod_data->md_editor = md;
141 mod_data->sm_editor = sm;
142}
static const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition functions.c:86
static const struct MenuFuncOp OpEditor[]
Functions for the Editor Menu.
Definition functions.c:51
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:121
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:87
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:104
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:134
@ MODULE_ID_EDITOR
ModuleEditor, Edit a string
Definition module_api.h:63
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
#define ASSERT(COND)
Definition signal2.h:59
Editor private Module data.
Definition module_data.h:30
struct SubMenu * sm_editor
Editor functions.
Definition module_data.h:33
struct MenuDefinition * md_editor
Editor Menu Definition.
Definition module_data.h:32
Functions for a Dialog or Window.
Definition menu.h:77
Collection of related functions.
Definition menu.h:65
@ MENU_EDITOR
Text entry area.
Definition type.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replace_part()

void replace_part ( struct EnterState * es,
size_t from,
const char * buf )

Search and replace on a buffer.

Parameters
esCurrent state of the input buffer
fromStarting point for the replacement
bufReplacement string

Definition at line 150 of file functions.c.

151{
152 /* Save the suffix */
153 size_t savelen = es->lastchar - es->curpos;
154 wchar_t *savebuf = NULL;
155
156 if (savelen)
157 {
158 savebuf = MUTT_MEM_CALLOC(savelen, wchar_t);
159 wmemcpy(savebuf, es->wbuf + es->curpos, savelen);
160 }
161
162 /* Convert to wide characters */
163 es->curpos = mutt_mb_mbstowcs(&es->wbuf, &es->wbuflen, from, buf);
164
165 if (savelen)
166 {
167 /* Make space for suffix */
168 if (es->curpos + savelen > es->wbuflen)
169 {
170 es->wbuflen = es->curpos + savelen;
171 MUTT_MEM_REALLOC(&es->wbuf, es->wbuflen, wchar_t);
172 }
173
174 /* Restore suffix */
175 wmemcpy(es->wbuf + es->curpos, savebuf, savelen);
176 FREE(&savebuf);
177 }
178
179 es->lastchar = es->curpos + savelen;
180}
size_t mutt_mb_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, const char *buf)
Convert a string from multibyte to wide characters.
Definition mbyte.c:292
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:55
size_t curpos
Position of the cursor.
Definition state.h:36
size_t wbuflen
Length of buffer.
Definition state.h:34
wchar_t * wbuf
Buffer for the string being entered.
Definition state.h:33
size_t lastchar
Position of the last character.
Definition state.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ editor_get_menu_definition()

struct MenuDefinition * editor_get_menu_definition ( void )

Get the Editor Menu Definition.

Return values
ptrEditor Menu Definition

Definition at line 575 of file functions.c.

576{
578 ASSERT(mod_data);
579
580 return mod_data->md_editor;
581}
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:

◆ editor_get_submenu()

struct SubMenu * editor_get_submenu ( void )

Get the Editor SubMenu.

Return values
ptrEditor SubMenu

Definition at line 587 of file functions.c.

588{
590 ASSERT(mod_data);
591
592 return mod_data->sm_editor;
593}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ OpEditor

const struct MenuFuncOp OpEditor[]
static

Functions for the Editor Menu.

Definition at line 51 of file functions.c.

51 { /* map: editor */
52 { "backspace", OP_EDITOR_BACKSPACE },
53 { "backward-char", OP_EDITOR_BACKWARD_CHAR },
54 { "backward-word", OP_EDITOR_BACKWARD_WORD },
55 { "bol", OP_EDITOR_BOL },
56 { "capitalize-word", OP_EDITOR_CAPITALIZE_WORD },
57 { "complete", OP_EDITOR_COMPLETE },
58 { "complete-query", OP_EDITOR_COMPLETE_QUERY },
59 { "delete-char", OP_EDITOR_DELETE_CHAR },
60 { "downcase-word", OP_EDITOR_DOWNCASE_WORD },
61 { "eol", OP_EDITOR_EOL },
62 { "forward-char", OP_EDITOR_FORWARD_CHAR },
63 { "forward-word", OP_EDITOR_FORWARD_WORD },
64 { "help", OP_HELP },
65 { "history-down", OP_EDITOR_HISTORY_DOWN },
66 { "history-search", OP_EDITOR_HISTORY_SEARCH },
67 { "history-up", OP_EDITOR_HISTORY_UP },
68 { "kill-eol", OP_EDITOR_KILL_EOL },
69 { "kill-eow", OP_EDITOR_KILL_EOW },
70 { "kill-line", OP_EDITOR_KILL_LINE },
71 { "kill-whole-line", OP_EDITOR_KILL_WHOLE_LINE },
72 { "kill-word", OP_EDITOR_KILL_WORD },
73 { "mailbox-cycle", OP_EDITOR_MAILBOX_CYCLE },
74 { "quote-char", OP_EDITOR_QUOTE_CHAR },
75 { "redraw-screen", OP_REDRAW },
76 { "transpose-chars", OP_EDITOR_TRANSPOSE_CHARS },
77 { "upcase-word", OP_EDITOR_UPCASE_WORD },
78 // Deprecated
79 { "buffy-cycle", OP_EDITOR_MAILBOX_CYCLE, MFF_DEPRECATED },
80 { NULL, 0 },
81};
@ MFF_DEPRECATED
Function is deprecated.
Definition get.h:67

◆ EditorDefaultBindings

const struct MenuOpSeq EditorDefaultBindings[]
static

Key bindings for the Editor Menu.

Definition at line 86 of file functions.c.

86 { /* map: editor */
87 { OP_EDITOR_BACKSPACE, "<backspace>" },
88 { OP_EDITOR_BACKSPACE, "\010" }, // <Ctrl-H>
89 { OP_EDITOR_BACKSPACE, "\177" }, // <Backspace>
90 { OP_EDITOR_BACKWARD_CHAR, "<left>" },
91 { OP_EDITOR_BACKWARD_CHAR, "\002" }, // <Ctrl-B>
92 { OP_EDITOR_BACKWARD_WORD, "\033b" }, // <Alt-b>
93 { OP_EDITOR_BOL, "<home>" },
94 { OP_EDITOR_BOL, "\001" }, // <Ctrl-A>
95 { OP_EDITOR_CAPITALIZE_WORD, "\033c" }, // <Alt-c>
96 { OP_EDITOR_COMPLETE, "\t" }, // <Tab>
97 { OP_EDITOR_COMPLETE_QUERY, "\024" }, // <Ctrl-T>
98 { OP_EDITOR_DELETE_CHAR, "<delete>" },
99 { OP_EDITOR_DELETE_CHAR, "\004" }, // <Ctrl-D>
100 { OP_EDITOR_DOWNCASE_WORD, "\033l" }, // <Alt-l>
101 { OP_EDITOR_EOL, "<end>" },
102 { OP_EDITOR_EOL, "\005" }, // <Ctrl-E>
103 { OP_EDITOR_FORWARD_CHAR, "<right>" },
104 { OP_EDITOR_FORWARD_CHAR, "\006" }, // <Ctrl-F>
105 { OP_EDITOR_FORWARD_WORD, "\033f" }, // <Alt-f>
106 { OP_EDITOR_HISTORY_DOWN, "<down>" },
107 { OP_EDITOR_HISTORY_DOWN, "\016" }, // <Ctrl-N>
108 { OP_EDITOR_HISTORY_SEARCH, "\022" }, // <Ctrl-R>
109 { OP_EDITOR_HISTORY_UP, "<up>" },
110 { OP_EDITOR_HISTORY_UP, "\020" }, // <Ctrl-P>
111 { OP_EDITOR_KILL_EOL, "\013" }, // <Ctrl-K>
112 { OP_EDITOR_KILL_EOW, "\033d" }, // <Alt-d>
113 { OP_EDITOR_KILL_LINE, "\025" }, // <Ctrl-U>
114 { OP_EDITOR_KILL_WORD, "\027" }, // <Ctrl-W>
115 { OP_EDITOR_MAILBOX_CYCLE, " " }, // <Space>
116 { OP_EDITOR_QUOTE_CHAR, "\026" }, // <Ctrl-V>
117 { OP_EDITOR_UPCASE_WORD, "\033u" }, // <Alt-u>
118 { OP_HELP, "\033?" }, // <Alt-?>
119 { OP_REDRAW, "\014" }, // <Ctrl-L>
120 { 0, NULL },
121};

◆ EnterFunctions

const struct EnterFunction EnterFunctions[]
static

All the NeoMutt functions that Enter supports.

Definition at line 500 of file functions.c.

500 {
501 // clang-format off
502 { OP_EDITOR_BACKSPACE, op_editor_backspace },
503 { OP_EDITOR_BACKWARD_CHAR, op_editor_backward_char },
504 { OP_EDITOR_BACKWARD_WORD, op_editor_backward_word },
505 { OP_EDITOR_BOL, op_editor_bol },
506 { OP_EDITOR_CAPITALIZE_WORD, op_editor_capitalize_word },
507 { OP_EDITOR_COMPLETE, op_editor_complete },
508 { OP_EDITOR_COMPLETE_QUERY, op_editor_complete },
509 { OP_EDITOR_DELETE_CHAR, op_editor_delete_char },
510 { OP_EDITOR_DOWNCASE_WORD, op_editor_capitalize_word },
511 { OP_EDITOR_EOL, op_editor_eol },
512 { OP_EDITOR_FORWARD_CHAR, op_editor_forward_char },
513 { OP_EDITOR_FORWARD_WORD, op_editor_forward_word },
514 { OP_EDITOR_HISTORY_DOWN, op_editor_history_down },
515 { OP_EDITOR_HISTORY_SEARCH, op_editor_history_search },
516 { OP_EDITOR_HISTORY_UP, op_editor_history_up },
517 { OP_EDITOR_KILL_EOL, op_editor_kill_eol },
518 { OP_EDITOR_KILL_EOW, op_editor_kill_eow },
519 { OP_EDITOR_KILL_LINE, op_editor_kill_line },
520 { OP_EDITOR_KILL_WHOLE_LINE, op_editor_kill_whole_line },
521 { OP_EDITOR_KILL_WORD, op_editor_kill_word },
522 { OP_EDITOR_MAILBOX_CYCLE, op_editor_complete },
523 { OP_EDITOR_QUOTE_CHAR, op_editor_quote_char },
524 { OP_EDITOR_TRANSPOSE_CHARS, op_editor_transpose_chars },
525 { OP_EDITOR_UPCASE_WORD, op_editor_capitalize_word },
526 { OP_HELP, op_help },
527 { OP_REDRAW, op_redraw },
528 { 0, NULL },
529 // clang-format on
530};
static int op_editor_delete_char(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Delete the char under the cursor - Implements enter_function_t -.
Definition functions.c:354
static int op_editor_history_up(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Scroll up through the history list - Implements enter_function_t -.
Definition functions.c:254
static int op_editor_backspace(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Delete the char in front of the cursor - Implements enter_function_t -.
Definition functions.c:276
static int op_editor_bol(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Jump to the beginning of the line - Implements enter_function_t -.
Definition functions.c:316
static int op_editor_complete(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Complete filename or alias - Implements enter_function_t -.
Definition functions.c:192
static int op_editor_kill_eol(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Delete chars from cursor to end of line - Implements enter_function_t -.
Definition functions.c:392
static int op_editor_forward_word(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Move the cursor to the end of the word - Implements enter_function_t -.
Definition functions.c:383
static int op_editor_backward_word(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Move the cursor to the beginning of the word - Implements enter_function_t -.
Definition functions.c:307
static int op_editor_history_down(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Scroll down through the history list - Implements enter_function_t -.
Definition functions.c:217
static int op_editor_capitalize_word(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Capitalize the word - Implements enter_function_t - This function handles:
Definition functions.c:329
static int op_help(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Display Help - Implements enter_function_t -.
Definition functions.c:476
static int op_editor_kill_eow(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Delete chars from the cursor to the end of the word - Implements enter_function_t -.
Definition functions.c:401
static int op_editor_kill_word(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Delete the word in front of the cursor - Implements enter_function_t -.
Definition functions.c:429
static int op_editor_quote_char(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Quote the next typed key - Implements enter_function_t -.
Definition functions.c:442
static int op_editor_forward_char(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Move the cursor one character to the right - Implements enter_function_t -.
Definition functions.c:374
static int op_editor_kill_line(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Delete all chars on the line - Implements enter_function_t -.
Definition functions.c:410
static int op_editor_backward_char(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Move the cursor one character to the left - Implements enter_function_t -.
Definition functions.c:298
static int op_editor_eol(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Jump to the end of the line - Implements enter_function_t -.
Definition functions.c:363
static int op_editor_kill_whole_line(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Delete all chars on the line - Implements enter_function_t -.
Definition functions.c:419
static int op_redraw(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Redraw the screen - Implements enter_function_t -.
Definition functions.c:485
static int op_editor_transpose_chars(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Transpose character under cursor with previous - Implements enter_function_t -.
Definition functions.c:466
static int op_editor_history_search(struct EnterFunctionData *fdata, const struct KeyEvent *event)
Search through the history list - Implements enter_function_t -.
Definition functions.c:237