NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
enter.c File Reference

Enter buffer. More...

#include "config.h"
#include <stddef.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)   (IsWPrint(wc) && (wcwidth(wc) == 0))
 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)    (IsWPrint(wc) && (wcwidth(wc) == 0))

combining mark / non-spacing character

Definition at line 39 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 47 of file enter.c.

48{
49 if (!es || (es->curpos == 0))
50 return FR_ERROR;
51
52 size_t i = es->curpos;
53 while ((i > 0) && COMB_CHAR(es->wbuf[i - 1]))
54 i--;
55 if (i > 0)
56 i--;
57 wmemmove(es->wbuf + i, es->wbuf + es->curpos, es->lastchar - es->curpos);
58 es->lastchar -= es->curpos - i;
59 es->curpos = i;
60
61 return FR_SUCCESS;
62}
@ 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:39
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 70 of file enter.c.

71{
72 if (!es || (es->curpos == 0))
73 return FR_ERROR;
74
75 while (es->curpos && COMB_CHAR(es->wbuf[es->curpos - 1]))
76 es->curpos--;
77 if (es->curpos)
78 es->curpos--;
79
80 return FR_SUCCESS;
81}
+ 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 89 of file enter.c.

90{
91 if (!es || (es->curpos == 0))
92 return FR_ERROR;
93
94 while (es->curpos && iswspace(es->wbuf[es->curpos - 1]))
95 es->curpos--;
96 while (es->curpos && !iswspace(es->wbuf[es->curpos - 1]))
97 es->curpos--;
98
99 return FR_SUCCESS;
100}
+ 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 108 of file enter.c.

109{
110 if (!es)
111 return FR_ERROR;
112
113 es->curpos = 0;
114 return FR_SUCCESS;
115}
+ 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 124 of file enter.c.

125{
126 if (!es || (es->curpos == es->lastchar))
127 return FR_ERROR;
128
129 while ((es->curpos < es->lastchar) && iswspace(es->wbuf[es->curpos]))
130 {
131 es->curpos++;
132 }
133 while ((es->curpos < es->lastchar) && !iswspace(es->wbuf[es->curpos]))
134 {
135 if (ec == EC_DOWNCASE)
136 {
137 es->wbuf[es->curpos] = towlower(es->wbuf[es->curpos]);
138 }
139 else
140 {
141 es->wbuf[es->curpos] = towupper(es->wbuf[es->curpos]);
142 if (ec == EC_CAPITALIZE)
143 ec = EC_DOWNCASE;
144 }
145 es->curpos++;
146 }
147 return FR_SUCCESS;
148}
@ 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 156 of file enter.c.

157{
158 if (!es || (es->curpos == es->lastchar))
159 return FR_ERROR;
160
161 size_t i = es->curpos;
162 if (i < es->lastchar)
163 i++;
164 while ((i < es->lastchar) && COMB_CHAR(es->wbuf[i]))
165 i++;
166 wmemmove(es->wbuf + es->curpos, es->wbuf + i, es->lastchar - i);
167 es->lastchar -= i - es->curpos;
168
169 return FR_SUCCESS;
170}
+ 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 178 of file enter.c.

179{
180 if (!es)
181 return FR_ERROR;
182
183 es->curpos = es->lastchar;
184 return FR_SUCCESS;
185}
+ 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 193 of file enter.c.

194{
195 if (!es || (es->curpos == es->lastchar))
196 return FR_ERROR;
197
198 es->curpos++;
199 while ((es->curpos < es->lastchar) && COMB_CHAR(es->wbuf[es->curpos]))
200 {
201 es->curpos++;
202 }
203
204 return FR_SUCCESS;
205}
+ 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 213 of file enter.c.

214{
215 if (!es || (es->curpos == es->lastchar))
216 return FR_ERROR;
217
218 while ((es->curpos < es->lastchar) && iswspace(es->wbuf[es->curpos]))
219 {
220 es->curpos++;
221 }
222 while ((es->curpos < es->lastchar) && !iswspace(es->wbuf[es->curpos]))
223 {
224 es->curpos++;
225 }
226
227 return FR_SUCCESS;
228}
+ 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 236 of file enter.c.

237{
238 if (!es)
239 return FR_ERROR;
240
241 es->lastchar = es->curpos;
242 return FR_SUCCESS;
243}
+ 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 251 of file enter.c.

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

291{
292 if (!es)
293 return FR_ERROR;
294
295 size_t len = es->lastchar - es->curpos;
296
297 wmemmove(es->wbuf, es->wbuf + es->curpos, len);
298
299 es->lastchar = len;
300 es->curpos = 0;
301
302 return FR_SUCCESS;
303}
+ 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 311 of file enter.c.

312{
313 if (!es)
314 return FR_ERROR;
315
316 es->lastchar = 0;
317 es->curpos = 0;
318
319 return FR_SUCCESS;
320}
+ 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 328 of file enter.c.

329{
330 if (!es || (es->curpos == 0))
331 return FR_ERROR;
332
333 size_t i = es->curpos;
334 while (i && iswspace(es->wbuf[i - 1]))
335 i--;
336 if (i > 0)
337 {
338 if (iswalnum(es->wbuf[i - 1]))
339 {
340 for (--i; (i > 0) && iswalnum(es->wbuf[i - 1]); i--)
341 ; // do nothing
342 }
343 else
344 {
345 i--;
346 }
347 }
348 wmemmove(es->wbuf + i, es->wbuf + es->curpos, es->lastchar - es->curpos);
349 es->lastchar += i - es->curpos;
350 es->curpos = i;
351
352 return FR_SUCCESS;
353}
+ 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 361 of file enter.c.

362{
363 if (!es || (es->lastchar < 2))
364 return FR_ERROR;
365
366 if (es->curpos == 0)
367 es->curpos = 2;
368 else if (es->curpos < es->lastchar)
369 es->curpos++;
370
371 wchar_t wc = es->wbuf[es->curpos - 2];
372 es->wbuf[es->curpos - 2] = es->wbuf[es->curpos - 1];
373 es->wbuf[es->curpos - 1] = wc;
374
375 return FR_SUCCESS;
376}
+ 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 385 of file enter.c.

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