NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.h File Reference

Editor functions. More...

#include <stdbool.h>
#include <stddef.h>
+ Include dependency graph for functions.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  EnterFunction
 A NeoMutt function. More...
 

Typedefs

typedef int(* enter_function_t) (struct EnterWindowData *wdata, const struct KeyEvent *event)
 

Functions

int enter_function_dispatcher (struct MuttWindow *win, const struct KeyEvent *event)
 Perform an Enter function - Implements function_dispatcher_t -.
 
bool self_insert (struct EnterWindowData *wdata, int ch)
 Insert a normal character.
 
void replace_part (struct EnterState *es, size_t from, const char *buf)
 Search and replace on a buffer.
 

Variables

struct MenuDefinitionMdEditor
 Editor Menu Definition.
 
struct SubMenuSmEditor
 Editor functions.
 

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

Typedef Documentation

◆ enter_function_t

typedef int(* enter_function_t) (struct EnterWindowData *wdata, const struct KeyEvent *event)

Definition at line 49 of file functions.h.

Function Documentation

◆ self_insert()

bool self_insert ( struct EnterWindowData * wdata,
int ch )

Insert a normal character.

Parameters
wdataEnter window data
chRaw keypress
Return values
trueIf done (enter pressed)

Definition at line 86 of file window.c.

87{
88 if (!wdata)
89 return true;
90
91 wdata->tabs = 0;
92 wchar_t wc = 0;
93
94 /* quietly ignore all other function keys */
95 if (ch & ~0xff)
96 return false;
97
98 /* gather the bytes into a wide character */
99 {
100 char c = ch;
101 size_t k = mbrtowc(&wc, &c, 1, wdata->mbstate);
102 if (k == ICONV_BUF_TOO_SMALL)
103 {
104 return false;
105 }
106 else if ((k != 0) && (k != 1))
107 {
108 memset(wdata->mbstate, 0, sizeof(*wdata->mbstate));
109 return false;
110 }
111 }
112
113 if (wdata->first && (wdata->flags & MUTT_COMP_CLEAR))
114 {
115 wdata->first = false;
116 if (IsWPrint(wc)) /* why? */
117 {
118 wdata->state->curpos = 0;
119 wdata->state->lastchar = 0;
120 }
121 }
122
123 if ((wc == '\r') || (wc == '\n'))
124 {
125 /* Convert from wide characters */
126 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->lastchar);
127 if (!wdata->pass)
128 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
129
130 if (wdata->cdata)
131 {
132 struct FileCompletionData *cdata = wdata->cdata;
133 if (cdata->multiple)
134 {
135 char **tfiles = NULL;
136 *cdata->numfiles = 1;
137 tfiles = MUTT_MEM_CALLOC(*cdata->numfiles, char *);
138 expand_path(wdata->buffer, false);
139 tfiles[0] = buf_strdup(wdata->buffer);
140 *cdata->files = tfiles;
141 }
142 }
143 return true;
144 }
145 else if (wc && ((wc < ' ') || IsWPrint(wc))) /* why? */
146 {
147 if (wdata->state->lastchar >= wdata->state->wbuflen)
148 {
149 wdata->state->wbuflen = wdata->state->lastchar + 20;
150 MUTT_MEM_REALLOC(&wdata->state->wbuf, wdata->state->wbuflen, wchar_t);
151 }
152 memmove(wdata->state->wbuf + wdata->state->curpos + 1,
153 wdata->state->wbuf + wdata->state->curpos,
154 (wdata->state->lastchar - wdata->state->curpos) * sizeof(wchar_t));
155 wdata->state->wbuf[wdata->state->curpos++] = wc;
156 wdata->state->lastchar++;
157 }
158 else
159 {
161 mutt_beep(false);
162 }
163
164 return false;
165}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
void mutt_beep(bool force)
Irritate the user.
Definition curs_lib.c:68
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
Definition wdata.h:43
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition get.c:65
void mutt_hist_add(enum HistoryClass hclass, const char *str, bool save)
Add a string to a history.
Definition history.c:482
void buf_mb_wcstombs(struct Buffer *dest, const wchar_t *wstr, size_t wlen)
Convert a string from wide to multibyte characters.
Definition mbyte.c:257
#define IsWPrint(wc)
Definition mbyte.h:40
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:55
#define ICONV_BUF_TOO_SMALL
Error value for iconv() - Buffer too small.
Definition charset.h:116
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:121
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
bool pass
Password mode, conceal characters.
Definition wdata.h:63
int tabs
Number of times the user has hit tab.
Definition wdata.h:68
void * cdata
Auto-Completion private data.
Definition wdata.h:58
CompletionFlags flags
Flags, see CompletionFlags.
Definition wdata.h:54
struct Buffer * buffer
struct Buffer for the result
Definition wdata.h:53
bool first
First time through, no input yet.
Definition wdata.h:64
struct EnterState * state
Current state of text entry.
Definition wdata.h:55
mbstate_t * mbstate
Multi-byte state.
Definition wdata.h:67
enum HistoryClass hclass
History to use, e.g. HC_NEO_COMMAND.
Definition wdata.h:56
Input for the file completion function.
Definition curs_lib.h:39
char *** files
List of files selected.
Definition curs_lib.h:42
bool multiple
Allow multiple selections.
Definition curs_lib.h:40
int * numfiles
Number of files selected.
Definition curs_lib.h:43
+ 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

Variable Documentation

◆ MdEditor

struct MenuDefinition* MdEditor
extern

Editor Menu Definition.

Definition at line 46 of file functions.c.

◆ SmEditor

struct SubMenu* SmEditor
extern

Editor functions.

Definition at line 49 of file functions.c.