NeoMutt  2025-09-05-55-g97fc89
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, int op)
 

Functions

int enter_function_dispatcher (struct MuttWindow *win, int op)
 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.
 

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, int op)

Definition at line 42 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 88 of file window.c.

89{
90 if (!wdata)
91 return true;
92
93 wdata->tabs = 0;
94 wchar_t wc = 0;
95
96 /* quietly ignore all other function keys */
97 if (ch & ~0xff)
98 return false;
99
100 /* gather the bytes into a wide character */
101 {
102 char c = ch;
103 size_t k = mbrtowc(&wc, &c, 1, wdata->mbstate);
104 if (k == ICONV_BUF_TOO_SMALL)
105 {
106 return false;
107 }
108 else if ((k != 0) && (k != 1))
109 {
110 memset(wdata->mbstate, 0, sizeof(*wdata->mbstate));
111 return false;
112 }
113 }
114
115 if (wdata->first && (wdata->flags & MUTT_COMP_CLEAR))
116 {
117 wdata->first = false;
118 if (IsWPrint(wc)) /* why? */
119 {
120 wdata->state->curpos = 0;
121 wdata->state->lastchar = 0;
122 }
123 }
124
125 if ((wc == '\r') || (wc == '\n'))
126 {
127 /* Convert from wide characters */
128 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->lastchar);
129 if (!wdata->pass)
130 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
131
132 if (wdata->cdata)
133 {
134 struct FileCompletionData *cdata = wdata->cdata;
135 if (cdata->multiple)
136 {
137 char **tfiles = NULL;
138 *cdata->numfiles = 1;
139 tfiles = MUTT_MEM_CALLOC(*cdata->numfiles, char *);
140 buf_expand_path_regex(wdata->buffer, false);
141 tfiles[0] = buf_strdup(wdata->buffer);
142 *cdata->files = tfiles;
143 }
144 }
145 return true;
146 }
147 else if (wc && ((wc < ' ') || IsWPrint(wc))) /* why? */
148 {
149 if (wdata->state->lastchar >= wdata->state->wbuflen)
150 {
151 wdata->state->wbuflen = wdata->state->lastchar + 20;
152 MUTT_MEM_REALLOC(&wdata->state->wbuf, wdata->state->wbuflen, wchar_t);
153 }
154 memmove(wdata->state->wbuf + wdata->state->curpos + 1,
155 wdata->state->wbuf + wdata->state->curpos,
156 (wdata->state->lastchar - wdata->state->curpos) * sizeof(wchar_t));
157 wdata->state->wbuf[wdata->state->curpos++] = wc;
158 wdata->state->lastchar++;
159 }
160 else
161 {
163 mutt_beep(false);
164 }
165
166 return false;
167}
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:69
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition get.c:58
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:256
#define IsWPrint(wc)
Definition mbyte.h:41
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:50
#define ICONV_BUF_TOO_SMALL
Error value for iconv() - Buffer too small.
Definition charset.h:98
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
Definition mutt.h:57
void buf_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
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:58
int tabs
Number of times the user has hit tab.
Definition wdata.h:63
void * cdata
Auto-Completion private data.
Definition wdata.h:53
CompletionFlags flags
Flags, see CompletionFlags.
Definition wdata.h:49
struct Buffer * buffer
struct Buffer for the result
Definition wdata.h:48
bool first
First time through, no input yet.
Definition wdata.h:59
struct EnterState * state
Current state of text entry.
Definition wdata.h:50
mbstate_t * mbstate
Multi-byte state.
Definition wdata.h:62
enum HistoryClass hclass
History to use, e.g. HC_NEO_COMMAND.
Definition wdata.h:51
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 132 of file functions.c.

133{
134 /* Save the suffix */
135 size_t savelen = es->lastchar - es->curpos;
136 wchar_t *savebuf = NULL;
137
138 if (savelen)
139 {
140 savebuf = MUTT_MEM_CALLOC(savelen, wchar_t);
141 wmemcpy(savebuf, es->wbuf + es->curpos, savelen);
142 }
143
144 /* Convert to wide characters */
145 es->curpos = mutt_mb_mbstowcs(&es->wbuf, &es->wbuflen, from, buf);
146
147 if (savelen)
148 {
149 /* Make space for suffix */
150 if (es->curpos + savelen > es->wbuflen)
151 {
152 es->wbuflen = es->curpos + savelen;
153 MUTT_MEM_REALLOC(&es->wbuf, es->wbuflen, wchar_t);
154 }
155
156 /* Restore suffix */
157 wmemcpy(es->wbuf + es->curpos, savebuf, savelen);
158 FREE(&savebuf);
159 }
160
161 es->lastchar = es->curpos + savelen;
162}
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:291
#define FREE(x)
Definition memory.h:62