NeoMutt  2025-12-11-694-ga89709
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 "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 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 EnterWindowData *wdata, const struct KeyEvent *event)
 Complete filename or alias - Implements enter_function_t -.
 
static int op_editor_history_down (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Scroll down through the history list - Implements enter_function_t -.
 
static int op_editor_history_search (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Search through the history list - Implements enter_function_t -.
 
static int op_editor_history_up (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Scroll up through the history list - Implements enter_function_t -.
 
static int op_editor_backspace (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Delete the char in front of the cursor - Implements enter_function_t -.
 
static int op_editor_backward_char (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Move the cursor one character to the left - Implements enter_function_t -.
 
static int op_editor_backward_word (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Move the cursor to the beginning of the word - Implements enter_function_t -.
 
static int op_editor_bol (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Jump to the beginning of the line - Implements enter_function_t -.
 
static int op_editor_capitalize_word (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Capitalize the word - Implements enter_function_t - This function handles:
 
static int op_editor_delete_char (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Delete the char under the cursor - Implements enter_function_t -.
 
static int op_editor_eol (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Jump to the end of the line - Implements enter_function_t -.
 
static int op_editor_forward_char (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Move the cursor one character to the right - Implements enter_function_t -.
 
static int op_editor_forward_word (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Move the cursor to the end of the word - Implements enter_function_t -.
 
static int op_editor_kill_eol (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Delete chars from cursor to end of line - Implements enter_function_t -.
 
static int op_editor_kill_eow (struct EnterWindowData *wdata, 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 EnterWindowData *wdata, const struct KeyEvent *event)
 Delete all chars on the line - Implements enter_function_t -.
 
static int op_editor_kill_whole_line (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Delete all chars on the line - Implements enter_function_t -.
 
static int op_editor_kill_word (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Delete the word in front of the cursor - Implements enter_function_t -.
 
static int op_editor_quote_char (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Quote the next typed key - Implements enter_function_t -.
 
static int op_editor_transpose_chars (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Transpose character under cursor with previous - Implements enter_function_t -.
 
static int op_help (struct EnterWindowData *wdata, const struct KeyEvent *event)
 Display Help - Implements enter_function_t -.
 
static int op_redraw (struct EnterWindowData *wdata, 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 -.
 

Variables

struct MenuDefinitionMdEditor = NULL
 Editor Menu Definition.
 
struct SubMenuSmEditor = NULL
 Editor functions.
 
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 SubMenu * sm_generic)

Initialise the Editor Keybindings - Implements ::init_keys_api.

Definition at line 131 of file functions.c.

132{
133 struct MenuDefinition *md = NULL;
134 struct SubMenu *sm = NULL;
135
137 md = km_register_menu(MENU_EDITOR, "editor");
138 km_menu_add_submenu(md, sm);
140
141 MdEditor = md;
142 SmEditor = sm;
143}
static const struct MenuOpSeq EditorDefaultBindings[]
Key bindings for the Editor Menu.
Definition functions.c:90
struct SubMenu * SmEditor
Editor functions.
Definition functions.c:49
static const struct MenuFuncOp OpEditor[]
Functions for the Editor Menu.
Definition functions.c:55
struct MenuDefinition * MdEditor
Editor Menu Definition.
Definition functions.c:46
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:123
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:91
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:107
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:136
Functions for a Dialog or Window.
Definition menu.h:80
Collection of related functions.
Definition menu.h:68
@ 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 151 of file functions.c.

152{
153 /* Save the suffix */
154 size_t savelen = es->lastchar - es->curpos;
155 wchar_t *savebuf = NULL;
156
157 if (savelen)
158 {
159 savebuf = MUTT_MEM_CALLOC(savelen, wchar_t);
160 wmemcpy(savebuf, es->wbuf + es->curpos, savelen);
161 }
162
163 /* Convert to wide characters */
164 es->curpos = mutt_mb_mbstowcs(&es->wbuf, &es->wbuflen, from, buf);
165
166 if (savelen)
167 {
168 /* Make space for suffix */
169 if (es->curpos + savelen > es->wbuflen)
170 {
171 es->wbuflen = es->curpos + savelen;
172 MUTT_MEM_REALLOC(&es->wbuf, es->wbuflen, wchar_t);
173 }
174
175 /* Restore suffix */
176 wmemcpy(es->wbuf + es->curpos, savebuf, savelen);
177 FREE(&savebuf);
178 }
179
180 es->lastchar = es->curpos + savelen;
181}
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:

Variable Documentation

◆ MdEditor

struct MenuDefinition* MdEditor = NULL

Editor Menu Definition.

Definition at line 46 of file functions.c.

◆ SmEditor

struct SubMenu* SmEditor = NULL

Editor functions.

Definition at line 49 of file functions.c.

◆ OpEditor

const struct MenuFuncOp OpEditor[]
static

Functions for the Editor Menu.

Definition at line 55 of file functions.c.

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

◆ EditorDefaultBindings

const struct MenuOpSeq EditorDefaultBindings[]
static

Key bindings for the Editor Menu.

Definition at line 90 of file functions.c.

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

◆ EnterFunctions

const struct EnterFunction EnterFunctions[]
static

All the NeoMutt functions that Enter supports.

Definition at line 475 of file functions.c.

475 {
476 // clang-format off
477 { OP_EDITOR_BACKSPACE, op_editor_backspace },
478 { OP_EDITOR_BACKWARD_CHAR, op_editor_backward_char },
479 { OP_EDITOR_BACKWARD_WORD, op_editor_backward_word },
480 { OP_EDITOR_BOL, op_editor_bol },
481 { OP_EDITOR_CAPITALIZE_WORD, op_editor_capitalize_word },
482 { OP_EDITOR_COMPLETE, op_editor_complete },
483 { OP_EDITOR_COMPLETE_QUERY, op_editor_complete },
484 { OP_EDITOR_DELETE_CHAR, op_editor_delete_char },
485 { OP_EDITOR_DOWNCASE_WORD, op_editor_capitalize_word },
486 { OP_EDITOR_EOL, op_editor_eol },
487 { OP_EDITOR_FORWARD_CHAR, op_editor_forward_char },
488 { OP_EDITOR_FORWARD_WORD, op_editor_forward_word },
489 { OP_EDITOR_HISTORY_DOWN, op_editor_history_down },
490 { OP_EDITOR_HISTORY_SEARCH, op_editor_history_search },
491 { OP_EDITOR_HISTORY_UP, op_editor_history_up },
492 { OP_EDITOR_KILL_EOL, op_editor_kill_eol },
493 { OP_EDITOR_KILL_EOW, op_editor_kill_eow },
494 { OP_EDITOR_KILL_LINE, op_editor_kill_line },
495 { OP_EDITOR_KILL_WHOLE_LINE, op_editor_kill_whole_line },
496 { OP_EDITOR_KILL_WORD, op_editor_kill_word },
497 { OP_EDITOR_MAILBOX_CYCLE, op_editor_complete },
498 { OP_EDITOR_QUOTE_CHAR, op_editor_quote_char },
499 { OP_EDITOR_TRANSPOSE_CHARS, op_editor_transpose_chars },
500 { OP_EDITOR_UPCASE_WORD, op_editor_capitalize_word },
501 { OP_HELP, op_help },
502 { OP_REDRAW, op_redraw },
503 { 0, NULL },
504 // clang-format on
505};
static int op_editor_eol(struct EnterWindowData *wdata, const struct KeyEvent *event)
Jump to the end of the line - Implements enter_function_t -.
Definition functions.c:351
static int op_editor_kill_eow(struct EnterWindowData *wdata, const struct KeyEvent *event)
Delete chars from the cursor to the end of the word - Implements enter_function_t -.
Definition functions.c:385
static int op_editor_forward_word(struct EnterWindowData *wdata, const struct KeyEvent *event)
Move the cursor to the end of the word - Implements enter_function_t -.
Definition functions.c:369
static int op_redraw(struct EnterWindowData *wdata, const struct KeyEvent *event)
Redraw the screen - Implements enter_function_t -.
Definition functions.c:461
static int op_editor_delete_char(struct EnterWindowData *wdata, const struct KeyEvent *event)
Delete the char under the cursor - Implements enter_function_t -.
Definition functions.c:343
static int op_editor_history_up(struct EnterWindowData *wdata, const struct KeyEvent *event)
Scroll up through the history list - Implements enter_function_t -.
Definition functions.c:250
static int op_editor_history_search(struct EnterWindowData *wdata, const struct KeyEvent *event)
Search through the history list - Implements enter_function_t -.
Definition functions.c:235
static int op_editor_kill_whole_line(struct EnterWindowData *wdata, const struct KeyEvent *event)
Delete all chars on the line - Implements enter_function_t -.
Definition functions.c:401
static int op_editor_capitalize_word(struct EnterWindowData *wdata, const struct KeyEvent *event)
Capitalize the word - Implements enter_function_t - This function handles:
Definition functions.c:320
static int op_editor_kill_line(struct EnterWindowData *wdata, const struct KeyEvent *event)
Delete all chars on the line - Implements enter_function_t -.
Definition functions.c:393
static int op_editor_bol(struct EnterWindowData *wdata, const struct KeyEvent *event)
Jump to the beginning of the line - Implements enter_function_t -.
Definition functions.c:308
static int op_editor_forward_char(struct EnterWindowData *wdata, const struct KeyEvent *event)
Move the cursor one character to the right - Implements enter_function_t -.
Definition functions.c:361
static int op_editor_complete(struct EnterWindowData *wdata, const struct KeyEvent *event)
Complete filename or alias - Implements enter_function_t -.
Definition functions.c:192
static int op_help(struct EnterWindowData *wdata, const struct KeyEvent *event)
Display Help - Implements enter_function_t -.
Definition functions.c:452
static int op_editor_quote_char(struct EnterWindowData *wdata, const struct KeyEvent *event)
Quote the next typed key - Implements enter_function_t -.
Definition functions.c:421
static int op_editor_kill_eol(struct EnterWindowData *wdata, const struct KeyEvent *event)
Delete chars from cursor to end of line - Implements enter_function_t -.
Definition functions.c:377
static int op_editor_backspace(struct EnterWindowData *wdata, const struct KeyEvent *event)
Delete the char in front of the cursor - Implements enter_function_t -.
Definition functions.c:271
static int op_editor_history_down(struct EnterWindowData *wdata, const struct KeyEvent *event)
Scroll down through the history list - Implements enter_function_t -.
Definition functions.c:216
static int op_editor_kill_word(struct EnterWindowData *wdata, const struct KeyEvent *event)
Delete the word in front of the cursor - Implements enter_function_t -.
Definition functions.c:409
static int op_editor_transpose_chars(struct EnterWindowData *wdata, const struct KeyEvent *event)
Transpose character under cursor with previous - Implements enter_function_t -.
Definition functions.c:444
static int op_editor_backward_char(struct EnterWindowData *wdata, const struct KeyEvent *event)
Move the cursor one character to the left - Implements enter_function_t -.
Definition functions.c:292
static int op_editor_backward_word(struct EnterWindowData *wdata, const struct KeyEvent *event)
Move the cursor to the beginning of the word - Implements enter_function_t -.
Definition functions.c:300