NeoMutt  2024-10-02-37-gfa9146
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 89 of file window.c.

90{
91 if (!wdata)
92 return true;
93
94 wdata->tabs = 0;
95 wchar_t wc = 0;
96
97 /* quietly ignore all other function keys */
98 if (ch & ~0xff)
99 return false;
100
101 /* gather the bytes into a wide character */
102 {
103 char c = ch;
104 size_t k = mbrtowc(&wc, &c, 1, wdata->mbstate);
105 if (k == ICONV_BUF_TOO_SMALL)
106 {
107 return false;
108 }
109 else if ((k != 0) && (k != 1))
110 {
111 memset(wdata->mbstate, 0, sizeof(*wdata->mbstate));
112 return false;
113 }
114 }
115
116 if (wdata->first && (wdata->flags & MUTT_COMP_CLEAR))
117 {
118 wdata->first = false;
119 if (IsWPrint(wc)) /* why? */
120 {
121 wdata->state->curpos = 0;
122 wdata->state->lastchar = 0;
123 }
124 }
125
126 if ((wc == '\r') || (wc == '\n'))
127 {
128 /* Convert from wide characters */
129 buf_mb_wcstombs(wdata->buffer, wdata->state->wbuf, wdata->state->lastchar);
130 if (!wdata->pass)
131 mutt_hist_add(wdata->hclass, buf_string(wdata->buffer), true);
132
133 if (wdata->cdata)
134 {
135 struct FileCompletionData *cdata = wdata->cdata;
136 if (cdata->multiple)
137 {
138 char **tfiles = NULL;
139 *cdata->numfiles = 1;
140 tfiles = mutt_mem_calloc(*cdata->numfiles, sizeof(char *));
141 buf_expand_path_regex(wdata->buffer, false);
142 tfiles[0] = buf_strdup(wdata->buffer);
143 *cdata->files = tfiles;
144 }
145 }
146 return true;
147 }
148 else if (wc && ((wc < ' ') || IsWPrint(wc))) /* why? */
149 {
150 if (wdata->state->lastchar >= wdata->state->wbuflen)
151 {
152 wdata->state->wbuflen = wdata->state->lastchar + 20;
153 mutt_mem_realloc(&wdata->state->wbuf, wdata->state->wbuflen * sizeof(wchar_t));
154 }
155 memmove(wdata->state->wbuf + wdata->state->curpos + 1,
156 wdata->state->wbuf + wdata->state->curpos,
157 (wdata->state->lastchar - wdata->state->curpos) * sizeof(wchar_t));
158 wdata->state->wbuf[wdata->state->curpos++] = wc;
159 wdata->state->lastchar++;
160 }
161 else
162 {
164 mutt_beep(false);
165 }
166
167 return false;
168}
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
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:490
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
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:115
#define ICONV_BUF_TOO_SMALL
Error value for iconv() - Buffer too small.
Definition: charset.h:107
#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:122
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:40
char *** files
List of files selected.
Definition: curs_lib.h:43
bool multiple
Allow multiple selections.
Definition: curs_lib.h:41
int * numfiles
Number of files selected.
Definition: curs_lib.h:44
+ 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, sizeof(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 * sizeof(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:45