NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
enter.c File Reference

Enter buffer. More...

#include "config.h"
#include <wchar.h>
#include <wctype.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "enter.h"
#include "state.h"
+ Include dependency graph for enter.c:

Go to the source code of this file.

Macros

#define COMB_CHAR(wc)
 combining mark / non-spacing character
 

Functions

int editor_backspace (struct EnterState *es)
 Delete the char in front of the cursor.
 
int editor_backward_char (struct EnterState *es)
 Move the cursor one character to the left.
 
int editor_backward_word (struct EnterState *es)
 Move the cursor to the beginning of the word.
 
int editor_bol (struct EnterState *es)
 Jump to the beginning of the line.
 
int editor_case_word (struct EnterState *es, enum EnterCase ec)
 Change the case of the word.
 
int editor_delete_char (struct EnterState *es)
 Delete the char under the cursor.
 
int editor_eol (struct EnterState *es)
 Jump to the end of the line.
 
int editor_forward_char (struct EnterState *es)
 Move the cursor one character to the right.
 
int editor_forward_word (struct EnterState *es)
 Move the cursor to the end of the word.
 
int editor_kill_eol (struct EnterState *es)
 Delete chars from cursor to end of line.
 
int editor_kill_eow (struct EnterState *es)
 Delete chars from the cursor to the end of the word.
 
int editor_kill_line (struct EnterState *es)
 Delete chars from cursor to beginning the line.
 
int editor_kill_whole_line (struct EnterState *es)
 Delete all chars on the line.
 
int editor_kill_word (struct EnterState *es)
 Delete the word in front of the cursor.
 
int editor_transpose_chars (struct EnterState *es)
 Transpose character under cursor with previous.
 
bool editor_buffer_is_empty (struct EnterState *es)
 Is the Enter buffer empty?
 

Detailed Description

Enter buffer.

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

Macro Definition Documentation

◆ COMB_CHAR

#define COMB_CHAR ( wc)
Value:
(IsWPrint(wc) && (wcwidth(wc) == 0))
#define IsWPrint(wc)
Definition mbyte.h:41

combining mark / non-spacing character

Definition at line 38 of file enter.c.

Function Documentation

◆ editor_backspace()

int editor_backspace ( struct EnterState * es)

Delete the char in front of the cursor.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacter deleted
FR_ERRORFailed, cursor was at the start of the buffer

Definition at line 46 of file enter.c.

47{
48 if (!es || (es->curpos == 0))
49 return FR_ERROR;
50
51 size_t i = es->curpos;
52 while ((i > 0) && COMB_CHAR(es->wbuf[i - 1]))
53 i--;
54 if (i > 0)
55 i--;
56 wmemmove(es->wbuf + i, es->wbuf + es->curpos, es->lastchar - es->curpos);
57 es->lastchar -= es->curpos - i;
58 es->curpos = i;
59
60 return FR_SUCCESS;
61}
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:39
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:38
#define COMB_CHAR(wc)
combining mark / non-spacing character
Definition enter.c:38
size_t curpos
Position of the cursor.
Definition state.h:36
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 caller graph for this function:

◆ editor_backward_char()

int editor_backward_char ( struct EnterState * es)

Move the cursor one character to the left.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCursor moved
FR_ERRORFailed, cursor was at the start of the buffer

Definition at line 69 of file enter.c.

70{
71 if (!es || (es->curpos == 0))
72 return FR_ERROR;
73
74 while (es->curpos && COMB_CHAR(es->wbuf[es->curpos - 1]))
75 es->curpos--;
76 if (es->curpos)
77 es->curpos--;
78
79 return FR_SUCCESS;
80}
+ Here is the caller graph for this function:

◆ editor_backward_word()

int editor_backward_word ( struct EnterState * es)

Move the cursor to the beginning of the word.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCursor moved
FR_ERRORFailed, cursor was at the start of the buffer

Definition at line 88 of file enter.c.

89{
90 if (!es || (es->curpos == 0))
91 return FR_ERROR;
92
93 while (es->curpos && iswspace(es->wbuf[es->curpos - 1]))
94 es->curpos--;
95 while (es->curpos && !iswspace(es->wbuf[es->curpos - 1]))
96 es->curpos--;
97
98 return FR_SUCCESS;
99}
+ Here is the caller graph for this function:

◆ editor_bol()

int editor_bol ( struct EnterState * es)

Jump to the beginning of the line.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCursor moved
FR_ERRORError

Definition at line 107 of file enter.c.

108{
109 if (!es)
110 return FR_ERROR;
111
112 es->curpos = 0;
113 return FR_SUCCESS;
114}
+ Here is the caller graph for this function:

◆ editor_case_word()

int editor_case_word ( struct EnterState * es,
enum EnterCase ec )

Change the case of the word.

Parameters
esState of the Enter buffer
ecCase change to make, e.g. EC_UPCASE
Return values
FR_SUCCESSCase changed
FR_ERRORError

Definition at line 123 of file enter.c.

124{
125 if (!es || (es->curpos == es->lastchar))
126 return FR_ERROR;
127
128 while ((es->curpos < es->lastchar) && iswspace(es->wbuf[es->curpos]))
129 {
130 es->curpos++;
131 }
132 while ((es->curpos < es->lastchar) && !iswspace(es->wbuf[es->curpos]))
133 {
134 if (ec == EC_DOWNCASE)
135 {
136 es->wbuf[es->curpos] = towlower(es->wbuf[es->curpos]);
137 }
138 else
139 {
140 es->wbuf[es->curpos] = towupper(es->wbuf[es->curpos]);
141 if (ec == EC_CAPITALIZE)
142 ec = EC_DOWNCASE;
143 }
144 es->curpos++;
145 }
146 return FR_SUCCESS;
147}
@ EC_DOWNCASE
Lower case (all characters)
Definition enter.h:37
@ EC_CAPITALIZE
Capitalize word (first character only)
Definition enter.h:35
+ Here is the caller graph for this function:

◆ editor_delete_char()

int editor_delete_char ( struct EnterState * es)

Delete the char under the cursor.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacter deleted
FR_ERRORFailed, cursor was at the end of the buffer

Definition at line 155 of file enter.c.

156{
157 if (!es || (es->curpos == es->lastchar))
158 return FR_ERROR;
159
160 size_t i = es->curpos;
161 if (i < es->lastchar)
162 i++;
163 while ((i < es->lastchar) && COMB_CHAR(es->wbuf[i]))
164 i++;
165 wmemmove(es->wbuf + es->curpos, es->wbuf + i, es->lastchar - i);
166 es->lastchar -= i - es->curpos;
167
168 return FR_SUCCESS;
169}
+ Here is the caller graph for this function:

◆ editor_eol()

int editor_eol ( struct EnterState * es)

Jump to the end of the line.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCursor moved
FR_ERRORError

Definition at line 177 of file enter.c.

178{
179 if (!es)
180 return FR_ERROR;
181
182 es->curpos = es->lastchar;
183 return FR_SUCCESS;
184}
+ Here is the caller graph for this function:

◆ editor_forward_char()

int editor_forward_char ( struct EnterState * es)

Move the cursor one character to the right.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCursor moved
FR_ERRORFailed, cursor was at the end of the buffer

Definition at line 192 of file enter.c.

193{
194 if (!es || (es->curpos == es->lastchar))
195 return FR_ERROR;
196
197 es->curpos++;
198 while ((es->curpos < es->lastchar) && COMB_CHAR(es->wbuf[es->curpos]))
199 {
200 es->curpos++;
201 }
202
203 return FR_SUCCESS;
204}
+ Here is the caller graph for this function:

◆ editor_forward_word()

int editor_forward_word ( struct EnterState * es)

Move the cursor to the end of the word.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCursor moved
FR_ERRORFailed, cursor was at the end of the buffer

Definition at line 212 of file enter.c.

213{
214 if (!es || (es->curpos == es->lastchar))
215 return FR_ERROR;
216
217 while ((es->curpos < es->lastchar) && iswspace(es->wbuf[es->curpos]))
218 {
219 es->curpos++;
220 }
221 while ((es->curpos < es->lastchar) && !iswspace(es->wbuf[es->curpos]))
222 {
223 es->curpos++;
224 }
225
226 return FR_SUCCESS;
227}
+ Here is the caller graph for this function:

◆ editor_kill_eol()

int editor_kill_eol ( struct EnterState * es)

Delete chars from cursor to end of line.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacters deleted
FR_ERRORError

Definition at line 235 of file enter.c.

236{
237 if (!es)
238 return FR_ERROR;
239
240 es->lastchar = es->curpos;
241 return FR_SUCCESS;
242}
+ Here is the caller graph for this function:

◆ editor_kill_eow()

int editor_kill_eow ( struct EnterState * es)

Delete chars from the cursor to the end of the word.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacters deleted
FR_ERRORError

Definition at line 250 of file enter.c.

251{
252 if (!es)
253 return FR_ERROR;
254
255 /* first skip over whitespace */
256 size_t i;
257 for (i = es->curpos; (i < es->lastchar) && iswspace(es->wbuf[i]); i++)
258 {
259 // do nothing
260 }
261
262 /* if there are any characters left.. */
263 if (i < es->lastchar)
264 {
265 /* if the current character is alphanumeric.. */
266 if (iswalnum(es->wbuf[i]))
267 {
268 /* skip over the rest of the word consistent of only alphanumerics */
269 for (; (i < es->lastchar) && iswalnum(es->wbuf[i]); i++)
270 ; // do nothing
271 }
272 else
273 {
274 i++; // skip over one non-alphanumeric character
275 }
276 }
277
278 wmemmove(es->wbuf + es->curpos, es->wbuf + i, es->lastchar - i);
279 es->lastchar += es->curpos - i;
280 return FR_SUCCESS;
281}
+ Here is the caller graph for this function:

◆ editor_kill_line()

int editor_kill_line ( struct EnterState * es)

Delete chars from cursor to beginning the line.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacters deleted
FR_ERRORError

Definition at line 289 of file enter.c.

290{
291 if (!es)
292 return FR_ERROR;
293
294 size_t len = es->lastchar - es->curpos;
295
296 wmemmove(es->wbuf, es->wbuf + es->curpos, len);
297
298 es->lastchar = len;
299 es->curpos = 0;
300
301 return FR_SUCCESS;
302}
+ Here is the caller graph for this function:

◆ editor_kill_whole_line()

int editor_kill_whole_line ( struct EnterState * es)

Delete all chars on the line.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacters deleted
FR_ERRORError

Definition at line 310 of file enter.c.

311{
312 if (!es)
313 return FR_ERROR;
314
315 es->lastchar = 0;
316 es->curpos = 0;
317
318 return FR_SUCCESS;
319}
+ Here is the caller graph for this function:

◆ editor_kill_word()

int editor_kill_word ( struct EnterState * es)

Delete the word in front of the cursor.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacters deleted
FR_ERRORFailed, cursor was at the start of the buffer

Definition at line 327 of file enter.c.

328{
329 if (!es || (es->curpos == 0))
330 return FR_ERROR;
331
332 size_t i = es->curpos;
333 while (i && iswspace(es->wbuf[i - 1]))
334 i--;
335 if (i > 0)
336 {
337 if (iswalnum(es->wbuf[i - 1]))
338 {
339 for (--i; (i > 0) && iswalnum(es->wbuf[i - 1]); i--)
340 ; // do nothing
341 }
342 else
343 {
344 i--;
345 }
346 }
347 wmemmove(es->wbuf + i, es->wbuf + es->curpos, es->lastchar - es->curpos);
348 es->lastchar += i - es->curpos;
349 es->curpos = i;
350
351 return FR_SUCCESS;
352}
+ Here is the caller graph for this function:

◆ editor_transpose_chars()

int editor_transpose_chars ( struct EnterState * es)

Transpose character under cursor with previous.

Parameters
esState of the Enter buffer
Return values
FR_SUCCESSCharacters switched
FR_ERRORFailed, too few characters

Definition at line 360 of file enter.c.

361{
362 if (!es || (es->lastchar < 2))
363 return FR_ERROR;
364
365 if (es->curpos == 0)
366 es->curpos = 2;
367 else if (es->curpos < es->lastchar)
368 es->curpos++;
369
370 wchar_t wc = es->wbuf[es->curpos - 2];
371 es->wbuf[es->curpos - 2] = es->wbuf[es->curpos - 1];
372 es->wbuf[es->curpos - 1] = wc;
373
374 return FR_SUCCESS;
375}
+ Here is the caller graph for this function:

◆ editor_buffer_is_empty()

bool editor_buffer_is_empty ( struct EnterState * es)

Is the Enter buffer empty?

Parameters
esState of the Enter buffer
Return values
trueIf buffer is empty

Definition at line 384 of file enter.c.

385{
386 if (!es)
387 return true;
388
389 return (es->lastchar == 0);
390}
+ Here is the caller graph for this function: