NeoMutt  2024-02-01-23-g345d7b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
enter.h File Reference

Enter buffer. More...

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

Go to the source code of this file.

Enumerations

enum  EnterCase { EC_CAPITALIZE , EC_UPCASE , EC_DOWNCASE }
 Change the case of a word. More...
 

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

Enumeration Type Documentation

◆ EnterCase

enum EnterCase

Change the case of a word.

Enumerator
EC_CAPITALIZE 

Capitalize word (first character only)

EC_UPCASE 

Upper case (all characters)

EC_DOWNCASE 

Lower case (all characters)

Definition at line 33 of file enter.h.

34{
36 EC_UPCASE,
38};
@ EC_UPCASE
Upper case (all characters)
Definition: enter.h:36
@ EC_DOWNCASE
Lower case (all characters)
Definition: enter.h:37
@ EC_CAPITALIZE
Capitalize word (first character only)
Definition: enter.h:35

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 memmove(es->wbuf + i, es->wbuf + es->curpos,
58 (es->lastchar - es->curpos) * sizeof(wchar_t));
59 es->lastchar -= es->curpos - i;
60 es->curpos = i;
61
62 return FR_SUCCESS;
63}
@ 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 71 of file enter.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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