Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 753 lines (673 sloc) 18.517 kb
e577381 Initial revision
Thomas Roessler authored
1 /*
82cb256 Brendan Cully Update copyrights. Closes #3016.
bcully authored
2 * Copyright (C) 1996-2000,2007 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 2000-1 Edmund Grimley Evans <edmundo@rano.org>
e577381 Initial revision
Thomas Roessler authored
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
62255b8 Brendan Cully Gah, forgot the zip code when updating the FSF address...
bcully authored
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
e577381 Initial revision
Thomas Roessler authored
18 */
19
bd77e36 Brendan Cully Add config.h to the top of every C file that could possibly want it.
bcully authored
20 #if HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
e577381 Initial revision
Thomas Roessler authored
24 #include "mutt.h"
25 #include "mutt_menu.h"
26 #include "mutt_curses.h"
27 #include "keymap.h"
d63919f CVS branch clean-up.
Thomas Roessler authored
28 #include "history.h"
e577381 Initial revision
Thomas Roessler authored
29
30 #include <string.h>
31
32 /* redraw flags for mutt_enter_string() */
33 enum
34 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
35 M_REDRAW_INIT = 1, /* go to end of line and redraw */
36 M_REDRAW_LINE /* redraw entire line */
e577381 Initial revision
Thomas Roessler authored
37 };
38
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
39 static int my_wcwidth (wchar_t wc)
40 {
80f4bcd Extend the editor so it supports unprintable characters.
Thomas Roessler authored
41 int n = wcwidth (wc);
3d9d99a Try to fix nonprintable character input.
Thomas Roessler authored
42 if (IsWPrint (wc) && n > 0)
80f4bcd Extend the editor so it supports unprintable characters.
Thomas Roessler authored
43 return n;
44 if (!(wc & ~0x7f))
45 return 2;
46 if (!(wc & ~0xffff))
47 return 6;
48 return 10;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
49 }
50
af2bc4f More wide-char patches from EGE.
Thomas Roessler authored
51 /* combining mark / non-spacing character */
52 #define COMB_CHAR(wc) (IsWPrint (wc) && !wcwidth (wc))
53
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
54 static int my_wcswidth (const wchar_t *s, size_t n)
55 {
56 int w = 0;
57 while (n--)
58 w += my_wcwidth (*s++);
59 return w;
60 }
61
62 static int my_addwch (wchar_t wc)
63 {
80f4bcd Extend the editor so it supports unprintable characters.
Thomas Roessler authored
64 int n = wcwidth (wc);
3d9d99a Try to fix nonprintable character input.
Thomas Roessler authored
65 if (IsWPrint (wc) && n > 0)
80f4bcd Extend the editor so it supports unprintable characters.
Thomas Roessler authored
66 return mutt_addwch (wc);
67 if (!(wc & ~0x7f))
68 return printw ("^%c", ((int)wc + 0x40) & 0x7f);
69 if (!(wc & ~0xffff))
70 return printw ("\\u%04x", (int)wc);
71 return printw ("\\u%08x", (int)wc);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
72 }
73
74 static size_t width_ceiling (const wchar_t *s, size_t n, int w1)
75 {
76 const wchar_t *s0 = s;
77 int w = 0;
78 for (; n; s++, n--)
79 if ((w += my_wcwidth (*s)) > w1)
80 break;
81 return s - s0;
82 }
83
a47483c Make my_wcstombs more robust. From EGE.
Thomas Roessler authored
84 static void my_wcstombs (char *dest, size_t dlen, const wchar_t *src, size_t slen)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
85 {
86 mbstate_t st;
a47483c Make my_wcstombs more robust. From EGE.
Thomas Roessler authored
87 size_t k;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
88
a47483c Make my_wcstombs more robust. From EGE.
Thomas Roessler authored
89 /* First convert directly into the destination buffer */
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
90 memset (&st, 0, sizeof (st));
a47483c Make my_wcstombs more robust. From EGE.
Thomas Roessler authored
91 for (; slen && dlen >= MB_LEN_MAX; dest += k, dlen -= k, src++, slen--)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
92 if ((k = wcrtomb (dest, *src, &st)) == (size_t)(-1))
93 break;
a47483c Make my_wcstombs more robust. From EGE.
Thomas Roessler authored
94
95 /* If this works, we can stop now */
96 if (dlen >= MB_LEN_MAX) {
97 wcrtomb (dest, 0, &st);
98 return;
99 }
100
101 /* Otherwise convert any remaining data into a local buffer */
102 {
103 char buf[3 * MB_LEN_MAX];
104 char *p = buf;
105
106 for (; slen && p - buf < dlen; p += k, src++, slen--)
107 if ((k = wcrtomb (p, *src, &st)) == (size_t)(-1))
108 break;
109 p += wcrtomb (p, 0, &st);
110
111 /* If it fits into the destination buffer, we can stop now */
112 if (p - buf <= dlen) {
113 memcpy (dest, buf, p - buf);
114 return;
115 }
116
117 /* Otherwise we truncate the string in an ugly fashion */
118 memcpy (dest, buf, dlen);
119 dest[dlen - 1] = '\0'; /* assume original dlen > 0 */
120 }
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
121 }
122
0f6ca57 Make some functions static.
Emanuele Giaquinta authored
123 static size_t my_mbstowcs (wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
124 {
125 wchar_t wc;
126 mbstate_t st;
127 size_t k;
128 wchar_t *wbuf;
129 size_t wbuflen;
130
131 wbuf = *pwbuf, wbuflen = *pwbuflen;
f7fdfdc - my_mbtowcs didn't recover from bad multibyte sequences
Thomas Roessler authored
132
133 while (*buf)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
134 {
f7fdfdc - my_mbtowcs didn't recover from bad multibyte sequences
Thomas Roessler authored
135 memset (&st, 0, sizeof (st));
136 for (; (k = mbrtowc (&wc, buf, MB_LEN_MAX, &st)) &&
137 k != (size_t)(-1) && k != (size_t)(-2); buf += k)
138 {
139 if (i >= wbuflen)
140 {
141 wbuflen = i + 20;
142 safe_realloc (&wbuf, wbuflen * sizeof (*wbuf));
143 }
144 wbuf[i++] = wc;
145 }
146 if (*buf && (k == (size_t) -1 || k == (size_t) -2))
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
147 {
f7fdfdc - my_mbtowcs didn't recover from bad multibyte sequences
Thomas Roessler authored
148 if (i >= wbuflen)
149 {
150 wbuflen = i + 20;
151 safe_realloc (&wbuf, wbuflen * sizeof (*wbuf));
152 }
153 wbuf[i++] = replacement_char();
154 buf++;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
155 }
156 }
157 *pwbuf = wbuf, *pwbuflen = wbuflen;
158 return i;
159 }
160
161 /*
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
162 * Replace part of the wchar_t buffer, from FROM to CURPOS, by BUF.
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
163 */
164
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
165 static void replace_part (ENTER_STATE *state, size_t from, char *buf)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
166 {
167 /* Save the suffix */
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
168 size_t savelen = state->lastchar - state->curpos;
ab9b43a Try to catch a couple of cases in which parameters for malloc calls
Thomas Roessler authored
169 wchar_t *savebuf = safe_calloc (savelen, sizeof (wchar_t));
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
170 memcpy (savebuf, state->wbuf + state->curpos, savelen * sizeof (wchar_t));
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
171
172 /* Convert to wide characters */
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
173 state->curpos = my_mbstowcs (&state->wbuf, &state->wbuflen, from, buf);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
174
175 /* Make space for suffix */
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
176 if (state->curpos + savelen > state->wbuflen)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
177 {
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
178 state->wbuflen = state->curpos + savelen;
0be4889 As the ones of you who compile with new gcc's probably have noticed,
Mads Martin Joergensen authored
179 safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t));
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
180 }
181
182 /* Restore suffix */
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
183 memcpy (state->wbuf + state->curpos, savebuf, savelen * sizeof (wchar_t));
184 state->lastchar = state->curpos + savelen;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
185
cbab567 Replace safe_free calls by the FREE macro.
Thomas Roessler authored
186 FREE (&savebuf);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
187 }
188
189 /*
b33de31 "complete" function should consider shell chars to be word boundaries wh...
Michael Elkins authored
190 * Return 1 if the character is not typically part of a pathname
191 */
62e25c2 Brendan Cully Make is_shell_char static. Closes #2907.
bcully authored
192 static inline int is_shell_char(wchar_t ch)
b33de31 "complete" function should consider shell chars to be word boundaries wh...
Michael Elkins authored
193 {
9689735 Dan Fandrich Declare many structures const (closes #3552)
dfandrich authored
194 static const wchar_t shell_chars[] = L"<>&()$?*;{}| "; /* ! not included because it can be part of a pathname in Mutt */
b33de31 "complete" function should consider shell chars to be word boundaries wh...
Michael Elkins authored
195 return wcschr(shell_chars, ch) != NULL;
196 }
197
198 /*
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
199 * Returns:
e577381 Initial revision
Thomas Roessler authored
200 * 1 need to redraw the screen and call me again
201 * 0 if input was given
202 * -1 if abort.
203 */
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
204
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
205 int mutt_enter_string(char *buf, size_t buflen, int y, int x, int flags)
206 {
207 int rv;
208 ENTER_STATE *es = mutt_new_enter_state ();
209 rv = _mutt_enter_string (buf, buflen, y, x, flags, 0, NULL, NULL, es);
210 mutt_free_enter_state (&es);
211 return rv;
212 }
213
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
214 int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
215 int flags, int multiple, char ***files, int *numfiles,
216 ENTER_STATE *state)
e577381 Initial revision
Thomas Roessler authored
217 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
218 int width = COLS - x - 1;
219 int redraw;
220 int pass = (flags & M_PASS);
e577381 Initial revision
Thomas Roessler authored
221 int first = 1;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
222 int ch, w, r;
223 size_t i;
224 wchar_t *tempbuf = 0;
225 size_t templen = 0;
226 history_class_t hclass;
1ddde09 Entering multibyte characters. From Edmund Grimley Evans.
Thomas Roessler authored
227 wchar_t wc;
228 mbstate_t mbstate;
a5205ca patch-1.1.2.mg.autocomplete.1 - from Marius Gedminas
Thomas Roessler authored
229
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
230 int rv = 0;
1ddde09 Entering multibyte characters. From Edmund Grimley Evans.
Thomas Roessler authored
231 memset (&mbstate, 0, sizeof (mbstate));
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
232
233 if (state->wbuf)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
234 {
235 /* Coming back after return 1 */
236 redraw = M_REDRAW_LINE;
ab0bbbd Brendan Cully Do not clobber string field on keypress when returning from file browser...
bcully authored
237 first = 0;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
238 }
239 else
a5205ca patch-1.1.2.mg.autocomplete.1 - from Marius Gedminas
Thomas Roessler authored
240 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
241 /* Initialise wbuf from buf */
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
242 state->wbuflen = 0;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
243 state->lastchar = my_mbstowcs (&state->wbuf, &state->wbuflen, 0, buf);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
244 redraw = M_REDRAW_INIT;
a5205ca patch-1.1.2.mg.autocomplete.1 - from Marius Gedminas
Thomas Roessler authored
245 }
246
3ff84b2 Maintain different history lists for files and mailboxes. Closes #2999.
Rocco Rutte authored
247 if (flags & M_FILE)
d63919f CVS branch clean-up.
Thomas Roessler authored
248 hclass = HC_FILE;
3ff84b2 Maintain different history lists for files and mailboxes. Closes #2999.
Rocco Rutte authored
249 else if (flags & M_EFILE)
250 hclass = HC_MBOX;
9793ab9 When entering a 'set' command on the command-line,
Thomas Roessler authored
251 else if (flags & M_CMD)
d63919f CVS branch clean-up.
Thomas Roessler authored
252 hclass = HC_CMD;
9793ab9 When entering a 'set' command on the command-line,
Thomas Roessler authored
253 else if (flags & M_ALIAS)
d63919f CVS branch clean-up.
Thomas Roessler authored
254 hclass = HC_ALIAS;
9793ab9 When entering a 'set' command on the command-line,
Thomas Roessler authored
255 else if (flags & M_COMMAND)
4181caa Use the proper history class when entering mutt commands.
Thomas Roessler authored
256 hclass = HC_COMMAND;
9793ab9 When entering a 'set' command on the command-line,
Thomas Roessler authored
257 else if (flags & M_PATTERN)
258 hclass = HC_PATTERN;
d63919f CVS branch clean-up.
Thomas Roessler authored
259 else
260 hclass = HC_OTHER;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
261
262 for (;;)
e577381 Initial revision
Thomas Roessler authored
263 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
264 if (redraw && !pass)
e577381 Initial revision
Thomas Roessler authored
265 {
266 if (redraw == M_REDRAW_INIT)
267 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
268 /* Go to end of line */
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
269 state->curpos = state->lastchar;
270 state->begin = width_ceiling (state->wbuf, state->lastchar, my_wcswidth (state->wbuf, state->lastchar) - width + 1);
a5205ca patch-1.1.2.mg.autocomplete.1 - from Marius Gedminas
Thomas Roessler authored
271 }
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
272 if (state->curpos < state->begin ||
273 my_wcswidth (state->wbuf + state->begin, state->curpos - state->begin) >= width)
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
274 state->begin = width_ceiling (state->wbuf, state->lastchar, my_wcswidth (state->wbuf, state->curpos) - width / 2);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
275 move (y, x);
276 w = 0;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
277 for (i = state->begin; i < state->lastchar; i++)
e577381 Initial revision
Thomas Roessler authored
278 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
279 w += my_wcwidth (state->wbuf[i]);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
280 if (w > width)
e577381 Initial revision
Thomas Roessler authored
281 break;
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
282 my_addwch (state->wbuf[i]);
e9aadf6 Edmund Grimley Evans' UTF-8 patch.
Thomas Roessler authored
283 }
e577381 Initial revision
Thomas Roessler authored
284 clrtoeol ();
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
285 move (y, x + my_wcswidth (state->wbuf + state->begin, state->curpos - state->begin));
e577381 Initial revision
Thomas Roessler authored
286 }
287 mutt_refresh ();
288
4757d02 Brendan Cully This patch redoes yesterday's unbuffered input patch. Now it uses a
bcully authored
289 if ((ch = km_dokey (MENU_EDITOR)) == -1)
e577381 Initial revision
Thomas Roessler authored
290 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
291 rv = -1;
292 goto bye;
e577381 Initial revision
Thomas Roessler authored
293 }
294
f5e41c1 Vikas' macro_function patch.
Thomas Roessler authored
295 if (ch != OP_NULL)
e577381 Initial revision
Thomas Roessler authored
296 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
297 first = 0;
4f79a72 Introduce fall-back from complete-query to complete for the edit
TAKAHASHI Tamotsu authored
298 if (ch != OP_EDITOR_COMPLETE && ch != OP_EDITOR_COMPLETE_QUERY)
344f8b4 Some more changes to the enter code.
Thomas Roessler authored
299 state->tabs = 0;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
300 redraw = M_REDRAW_LINE;
e577381 Initial revision
Thomas Roessler authored
301 switch (ch)
302 {
303 case OP_EDITOR_HISTORY_UP:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
304 state->curpos = state->lastchar;
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
305 replace_part (state, 0, mutt_history_prev (hclass));
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
306 redraw = M_REDRAW_INIT;
e577381 Initial revision
Thomas Roessler authored
307 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
308
e577381 Initial revision
Thomas Roessler authored
309 case OP_EDITOR_HISTORY_DOWN:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
310 state->curpos = state->lastchar;
1cf876b Fix #801.
Thomas Roessler authored
311 replace_part (state, 0, mutt_history_next (hclass));
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
312 redraw = M_REDRAW_INIT;
e577381 Initial revision
Thomas Roessler authored
313 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
314
e577381 Initial revision
Thomas Roessler authored
315 case OP_EDITOR_BACKSPACE:
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
316 if (state->curpos == 0)
e577381 Initial revision
Thomas Roessler authored
317 BEEP ();
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
318 else
e577381 Initial revision
Thomas Roessler authored
319 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
320 i = state->curpos;
af2bc4f More wide-char patches from EGE.
Thomas Roessler authored
321 while (i && COMB_CHAR (state->wbuf[i - 1]))
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
322 --i;
323 if (i)
324 --i;
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
325 memmove (state->wbuf + i, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof (wchar_t));
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
326 state->lastchar -= state->curpos - i;
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
327 state->curpos = i;
e577381 Initial revision
Thomas Roessler authored
328 }
329 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
330
e577381 Initial revision
Thomas Roessler authored
331 case OP_EDITOR_BOL:
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
332 state->curpos = 0;
e577381 Initial revision
Thomas Roessler authored
333 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
334
e577381 Initial revision
Thomas Roessler authored
335 case OP_EDITOR_EOL:
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
336 redraw= M_REDRAW_INIT;
e577381 Initial revision
Thomas Roessler authored
337 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
338
e577381 Initial revision
Thomas Roessler authored
339 case OP_EDITOR_KILL_LINE:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
340 state->curpos = state->lastchar = 0;
e577381 Initial revision
Thomas Roessler authored
341 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
342
e577381 Initial revision
Thomas Roessler authored
343 case OP_EDITOR_KILL_EOL:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
344 state->lastchar = state->curpos;
e577381 Initial revision
Thomas Roessler authored
345 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
346
e577381 Initial revision
Thomas Roessler authored
347 case OP_EDITOR_BACKWARD_CHAR:
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
348 if (state->curpos == 0)
e577381 Initial revision
Thomas Roessler authored
349 BEEP ();
350 else
351 {
af2bc4f More wide-char patches from EGE.
Thomas Roessler authored
352 while (state->curpos && COMB_CHAR (state->wbuf[state->curpos - 1]))
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
353 state->curpos--;
354 if (state->curpos)
355 state->curpos--;
e577381 Initial revision
Thomas Roessler authored
356 }
357 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
358
e577381 Initial revision
Thomas Roessler authored
359 case OP_EDITOR_FORWARD_CHAR:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
360 if (state->curpos == state->lastchar)
e577381 Initial revision
Thomas Roessler authored
361 BEEP ();
362 else
363 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
364 ++state->curpos;
af2bc4f More wide-char patches from EGE.
Thomas Roessler authored
365 while (state->curpos < state->lastchar && COMB_CHAR (state->wbuf[state->curpos]))
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
366 ++state->curpos;
e577381 Initial revision
Thomas Roessler authored
367 }
368 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
369
33f77e9 Add forward-word and backward-word functions to the editor.
Thomas Roessler authored
370 case OP_EDITOR_BACKWARD_WORD:
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
371 if (state->curpos == 0)
33f77e9 Add forward-word and backward-word functions to the editor.
Thomas Roessler authored
372 BEEP ();
373 else
374 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
375 while (state->curpos && iswspace (state->wbuf[state->curpos - 1]))
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
376 --state->curpos;
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
377 while (state->curpos && !iswspace (state->wbuf[state->curpos - 1]))
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
378 --state->curpos;
33f77e9 Add forward-word and backward-word functions to the editor.
Thomas Roessler authored
379 }
380 break;
381
382 case OP_EDITOR_FORWARD_WORD:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
383 if (state->curpos == state->lastchar)
33f77e9 Add forward-word and backward-word functions to the editor.
Thomas Roessler authored
384 BEEP ();
385 else
386 {
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
387 while (state->curpos < state->lastchar && iswspace (state->wbuf[state->curpos]))
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
388 ++state->curpos;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
389 while (state->curpos < state->lastchar && !iswspace (state->wbuf[state->curpos]))
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
390 ++state->curpos;
33f77e9 Add forward-word and backward-word functions to the editor.
Thomas Roessler authored
391 }
392 break;
393
b606a7b Add capitalize-word, upcase-word, downcase-word functions to the
Thomas Roessler authored
394 case OP_EDITOR_CAPITALIZE_WORD:
395 case OP_EDITOR_UPCASE_WORD:
396 case OP_EDITOR_DOWNCASE_WORD:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
397 if (state->curpos == state->lastchar)
b606a7b Add capitalize-word, upcase-word, downcase-word functions to the
Thomas Roessler authored
398 {
8941e9e A nicer version of {capitalize,...}-word functions.
Thomas Roessler authored
399 BEEP ();
b606a7b Add capitalize-word, upcase-word, downcase-word functions to the
Thomas Roessler authored
400 break;
401 }
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
402 while (state->curpos && !iswspace (state->wbuf[state->curpos]))
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
403 --state->curpos;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
404 while (state->curpos < state->lastchar && iswspace (state->wbuf[state->curpos]))
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
405 ++state->curpos;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
406 while (state->curpos < state->lastchar && !iswspace (state->wbuf[state->curpos]))
b606a7b Add capitalize-word, upcase-word, downcase-word functions to the
Thomas Roessler authored
407 {
8941e9e A nicer version of {capitalize,...}-word functions.
Thomas Roessler authored
408 if (ch == OP_EDITOR_DOWNCASE_WORD)
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
409 state->wbuf[state->curpos] = towlower (state->wbuf[state->curpos]);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
410 else
8941e9e A nicer version of {capitalize,...}-word functions.
Thomas Roessler authored
411 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
412 state->wbuf[state->curpos] = towupper (state->wbuf[state->curpos]);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
413 if (ch == OP_EDITOR_CAPITALIZE_WORD)
414 ch = OP_EDITOR_DOWNCASE_WORD;
8941e9e A nicer version of {capitalize,...}-word functions.
Thomas Roessler authored
415 }
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
416 state->curpos++;
b606a7b Add capitalize-word, upcase-word, downcase-word functions to the
Thomas Roessler authored
417 }
418 break;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
419
e577381 Initial revision
Thomas Roessler authored
420 case OP_EDITOR_DELETE_CHAR:
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
421 if (state->curpos == state->lastchar)
e577381 Initial revision
Thomas Roessler authored
422 BEEP ();
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
423 else
e577381 Initial revision
Thomas Roessler authored
424 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
425 i = state->curpos;
af2bc4f More wide-char patches from EGE.
Thomas Roessler authored
426 while (i < state->lastchar && COMB_CHAR (state->wbuf[i]))
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
427 ++i;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
428 if (i < state->lastchar)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
429 ++i;
af2bc4f More wide-char patches from EGE.
Thomas Roessler authored
430 while (i < state->lastchar && COMB_CHAR (state->wbuf[i]))
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
431 ++i;
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
432 memmove (state->wbuf + state->curpos, state->wbuf + i, (state->lastchar - i) * sizeof (wchar_t));
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
433 state->lastchar -= i - state->curpos;
e577381 Initial revision
Thomas Roessler authored
434 }
435 break;
5e2ebad Add a kill-eow function to the line editor.
Thomas Roessler authored
436
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
437 case OP_EDITOR_KILL_WORD:
438 /* delete to begining of word */
439 if (state->curpos != 0)
440 {
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
441 i = state->curpos;
442 while (i && iswspace (state->wbuf[i - 1]))
443 --i;
444 if (i)
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
445 {
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
446 if (iswalnum (state->wbuf[i - 1]))
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
447 {
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
448 for (--i; i && iswalnum (state->wbuf[i - 1]); i--)
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
449 ;
450 }
451 else
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
452 --i;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
453 }
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
454 memmove (state->wbuf + i, state->wbuf + state->curpos,
455 (state->lastchar - state->curpos) * sizeof (wchar_t));
456 state->lastchar += i - state->curpos;
457 state->curpos = i;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
458 }
459 break;
460
461 case OP_EDITOR_KILL_EOW:
462 /* delete to end of word */
8016287 make kill-eow and kill-word consistent in considering words to consist o...
Michael Elkins authored
463
464 /* first skip over whitespace */
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
465 for (i = state->curpos;
466 i < state->lastchar && iswspace (state->wbuf[i]); i++)
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
467 ;
8016287 make kill-eow and kill-word consistent in considering words to consist o...
Michael Elkins authored
468
469 /* if there are any characters left.. */
470 if (i < state->lastchar)
471 {
472 /* if the current character is alphanumeric.. */
473 if (iswalnum (state->wbuf[i]))
474 {
475 /* skip over the rest of the word consistent of only alphanumerics */
476 for (; i < state->lastchar && iswalnum (state->wbuf[i]); i++)
477 ;
478 }
479 else
480 {
481 /* skip over one non-alphanumeric character */
482 ++i;
483 }
484 }
485
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
486 memmove (state->wbuf + state->curpos, state->wbuf + i,
487 (state->lastchar - i) * sizeof (wchar_t));
488 state->lastchar += state->curpos - i;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
489 break;
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
490
e577381 Initial revision
Thomas Roessler authored
491 case OP_EDITOR_BUFFY_CYCLE:
492 if (flags & M_EFILE)
493 {
494 first = 1; /* clear input if user types a real key later */
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
495 my_wcstombs (buf, buflen, state->wbuf, state->curpos);
aa17120 Going through possible security problems with a fine comb. If you
Thomas Roessler authored
496 mutt_buffy (buf, buflen);
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
497 state->curpos = state->lastchar = my_mbstowcs (&state->wbuf, &state->wbuflen, 0, buf);
e577381 Initial revision
Thomas Roessler authored
498 break;
499 }
500 else if (!(flags & M_FILE))
501 goto self_insert;
502 /* fall through to completion routine (M_FILE) */
503
504 case OP_EDITOR_COMPLETE:
4f79a72 Introduce fall-back from complete-query to complete for the edit
TAKAHASHI Tamotsu authored
505 case OP_EDITOR_COMPLETE_QUERY:
344f8b4 Some more changes to the enter code.
Thomas Roessler authored
506 state->tabs++;
e577381 Initial revision
Thomas Roessler authored
507 if (flags & M_CMD)
508 {
b33de31 "complete" function should consider shell chars to be word boundaries wh...
Michael Elkins authored
509 for (i = state->curpos; i && !is_shell_char(state->wbuf[i-1]); i--)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
510 ;
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
511 my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i);
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
512 if (tempbuf && templen == state->lastchar - i &&
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
513 !memcmp (tempbuf, state->wbuf + i, (state->lastchar - i) * sizeof (wchar_t)))
e577381 Initial revision
Thomas Roessler authored
514 {
6bc7bfd Make browser behaviour more consistent with expectations.
Thomas Roessler authored
515 mutt_select_file (buf, buflen, (flags & M_EFILE) ? M_SEL_FOLDER : 0);
e577381 Initial revision
Thomas Roessler authored
516 set_option (OPTNEEDREDRAW);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
517 if (*buf)
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
518 replace_part (state, i, buf);
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
519 rv = 1;
520 goto bye;
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
521 }
522 if (!mutt_complete (buf, buflen))
523 {
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
524 templen = state->lastchar - i;
0be4889 As the ones of you who compile with new gcc's probably have noticed,
Mads Martin Joergensen authored
525 safe_realloc (&tempbuf, templen * sizeof (wchar_t));
e577381 Initial revision
Thomas Roessler authored
526 }
527 else
528 BEEP ();
a5205ca patch-1.1.2.mg.autocomplete.1 - from Marius Gedminas
Thomas Roessler authored
529
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
530 replace_part (state, i, buf);
e577381 Initial revision
Thomas Roessler authored
531 }
4f79a72 Introduce fall-back from complete-query to complete for the edit
TAKAHASHI Tamotsu authored
532 else if (flags & M_ALIAS && ch == OP_EDITOR_COMPLETE)
e577381 Initial revision
Thomas Roessler authored
533 {
534 /* invoke the alias-menu to get more addresses */
51176a3 Fix alias completion when the alias is entered as part of a group.
Thomas Roessler authored
535 for (i = state->curpos; i && state->wbuf[i-1] != ',' &&
536 state->wbuf[i-1] != ':'; i--)
f8cbf4e Completion fixes from Gero Treuner <gero@faveve.uni-stuttgart.de>.
Thomas Roessler authored
537 ;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
538 for (; i < state->lastchar && state->wbuf[i] == ' '; i++)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
539 ;
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
540 my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
541 r = mutt_alias_complete (buf, buflen);
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
542 replace_part (state, i, buf);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
543 if (!r)
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
544 {
545 rv = 1;
546 goto bye;
547 }
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
548 break;
e577381 Initial revision
Thomas Roessler authored
549 }
4f79a72 Introduce fall-back from complete-query to complete for the edit
TAKAHASHI Tamotsu authored
550 else if (flags & M_ALIAS && ch == OP_EDITOR_COMPLETE_QUERY)
551 {
552 /* invoke the query-menu to get more addresses */
553 if ((i = state->curpos))
554 {
555 for (; i && state->wbuf[i - 1] != ','; i--)
556 ;
557 for (; i < state->curpos && state->wbuf[i] == ' '; i++)
558 ;
559 }
560
561 my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i);
562 mutt_query_complete (buf, buflen);
563 replace_part (state, i, buf);
564
565 rv = 1;
566 goto bye;
567 }
9a63bf0 Mutt 0.92.9i.
Thomas Roessler authored
568 else if (flags & M_COMMAND)
569 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
570 my_wcstombs (buf, buflen, state->wbuf, state->curpos);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
571 i = strlen (buf);
e2780d9 Fix "tab-tab" at the change-folder prompt.
Thomas Roessler authored
572 if (i && buf[i - 1] == '=' &&
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
573 mutt_var_value_complete (buf, buflen, i))
344f8b4 Some more changes to the enter code.
Thomas Roessler authored
574 state->tabs = 0;
575 else if (!mutt_command_complete (buf, buflen, i, state->tabs))
a5205ca patch-1.1.2.mg.autocomplete.1 - from Marius Gedminas
Thomas Roessler authored
576 BEEP ();
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
577 replace_part (state, 0, buf);
9a63bf0 Mutt 0.92.9i.
Thomas Roessler authored
578 }
e577381 Initial revision
Thomas Roessler authored
579 else if (flags & (M_FILE | M_EFILE))
580 {
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
581 my_wcstombs (buf, buflen, state->wbuf, state->curpos);
e577381 Initial revision
Thomas Roessler authored
582
583 /* see if the path has changed from the last time */
4a20402 More file name completion fixes.
Thomas Roessler authored
584 if ((!tempbuf && !state->lastchar) || (tempbuf && templen == state->lastchar &&
e2780d9 Fix "tab-tab" at the change-folder prompt.
Thomas Roessler authored
585 !memcmp (tempbuf, state->wbuf, state->lastchar * sizeof (wchar_t))))
e577381 Initial revision
Thomas Roessler authored
586 {
6bc7bfd Make browser behaviour more consistent with expectations.
Thomas Roessler authored
587 _mutt_select_file (buf, buflen,
588 ((flags & M_EFILE) ? M_SEL_FOLDER : 0) | (multiple ? M_SEL_MULTI : 0),
589 files, numfiles);
e577381 Initial revision
Thomas Roessler authored
590 set_option (OPTNEEDREDRAW);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
591 if (*buf)
e577381 Initial revision
Thomas Roessler authored
592 {
db860dd Use realpath() in mutt_pretty_mailbox() for paths that may need it.
Rocco Rutte authored
593 mutt_pretty_mailbox (buf, buflen);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
594 if (!pass)
d858235 Add $history_file and $save_history, for saving command history across
Vincent Lefevre authored
595 mutt_history_add (hclass, buf, 1);
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
596 rv = 0;
597 goto bye;
e577381 Initial revision
Thomas Roessler authored
598 }
a5205ca patch-1.1.2.mg.autocomplete.1 - from Marius Gedminas
Thomas Roessler authored
599
600 /* file selection cancelled */
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
601 rv = 1;
602 goto bye;
e577381 Initial revision
Thomas Roessler authored
603 }
604
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
605 if (!mutt_complete (buf, buflen))
606 {
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
607 templen = state->lastchar;
0be4889 As the ones of you who compile with new gcc's probably have noticed,
Mads Martin Joergensen authored
608 safe_realloc (&tempbuf, templen * sizeof (wchar_t));
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
609 memcpy (tempbuf, state->wbuf, templen * sizeof (wchar_t));
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
610 }
e577381 Initial revision
Thomas Roessler authored
611 else
612 BEEP (); /* let the user know that nothing matched */
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
613 replace_part (state, 0, buf);
e577381 Initial revision
Thomas Roessler authored
614 }
615 else
616 goto self_insert;
617 break;
618
619 case OP_EDITOR_QUOTE_CHAR:
84ece0b Add a transpose-character function to the editor. From Aaron Schrab.
Thomas Roessler authored
620 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
621 event_t event;
622 /*ADDCH (LastKey);*/
623 event = mutt_getch ();
a9fc81b Brendan Cully Rework timeout handling to support keepalive in the line editor.
bcully authored
624 if (event.ch >= 0)
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
625 {
626 LastKey = event.ch;
627 goto self_insert;
628 }
84ece0b Add a transpose-character function to the editor. From Aaron Schrab.
Thomas Roessler authored
629 }
630
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
631 case OP_EDITOR_TRANSPOSE_CHARS:
632 if (state->lastchar < 2)
633 BEEP ();
634 else
635 {
636 wchar_t t;
637
638 if (state->curpos == 0)
639 state->curpos = 2;
640 else if (state->curpos < state->lastchar)
641 ++state->curpos;
642
643 t = state->wbuf[state->curpos - 2];
644 state->wbuf[state->curpos - 2] = state->wbuf[state->curpos - 1];
645 state->wbuf[state->curpos - 1] = t;
646 }
647 break;
648
e577381 Initial revision
Thomas Roessler authored
649 default:
650 BEEP ();
651 }
652 }
653 else
654 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
655
e577381 Initial revision
Thomas Roessler authored
656 self_insert:
657
344f8b4 Some more changes to the enter code.
Thomas Roessler authored
658 state->tabs = 0;
e577381 Initial revision
Thomas Roessler authored
659 /* use the raw keypress */
660 ch = LastKey;
661
93669dc Fix KEY_ENTER. From EGE.
Thomas Roessler authored
662 #ifdef KEY_ENTER
663 /* treat ENTER the same as RETURN */
664 if (ch == KEY_ENTER)
665 ch = '\r';
666 #endif
667
668 /* quietly ignore all other function keys */
1ddde09 Entering multibyte characters. From Edmund Grimley Evans.
Thomas Roessler authored
669 if (ch & ~0xff)
670 continue;
671
672 /* gather the octets into a wide character */
673 {
674 char c;
675 size_t k;
676
677 c = ch;
678 k = mbrtowc (&wc, &c, 1, &mbstate);
679 if (k == (size_t)(-2))
680 continue;
681 else if (k && k != 1)
682 {
683 memset (&mbstate, 0, sizeof (mbstate));
684 continue;
685 }
686 }
687
e577381 Initial revision
Thomas Roessler authored
688 if (first && (flags & M_CLEAR))
689 {
690 first = 0;
1ddde09 Entering multibyte characters. From Edmund Grimley Evans.
Thomas Roessler authored
691 if (IsWPrint (wc)) /* why? */
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
692 state->curpos = state->lastchar = 0;
e577381 Initial revision
Thomas Roessler authored
693 }
694
1ddde09 Entering multibyte characters. From Edmund Grimley Evans.
Thomas Roessler authored
695 if (wc == '\r' || wc == '\n')
e577381 Initial revision
Thomas Roessler authored
696 {
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
697 /* Convert from wide characters */
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
698 my_wcstombs (buf, buflen, state->wbuf, state->lastchar);
e577381 Initial revision
Thomas Roessler authored
699 if (!pass)
d858235 Add $history_file and $save_history, for saving command history across
Vincent Lefevre authored
700 mutt_history_add (hclass, buf, 1);
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
701
dc7cb03 Fix the attach-multi patch.
Thomas Roessler authored
702 if (multiple)
703 {
704 char **tfiles;
705 *numfiles = 1;
ab9b43a Try to catch a couple of cases in which parameters for malloc calls
Thomas Roessler authored
706 tfiles = safe_calloc (*numfiles, sizeof (char *));
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
707 mutt_expand_path (buf, buflen);
708 tfiles[0] = safe_strdup (buf);
dc7cb03 Fix the attach-multi patch.
Thomas Roessler authored
709 *files = tfiles;
710 }
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
711 rv = 0;
712 goto bye;
e577381 Initial revision
Thomas Roessler authored
713 }
1ddde09 Entering multibyte characters. From Edmund Grimley Evans.
Thomas Roessler authored
714 else if (wc && (wc < ' ' || IsWPrint (wc))) /* why? */
e577381 Initial revision
Thomas Roessler authored
715 {
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
716 if (state->lastchar >= state->wbuflen)
e577381 Initial revision
Thomas Roessler authored
717 {
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
718 state->wbuflen = state->lastchar + 20;
0be4889 As the ones of you who compile with new gcc's probably have noticed,
Mads Martin Joergensen authored
719 safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t));
e577381 Initial revision
Thomas Roessler authored
720 }
5fd017f More enter.c updates. From E.G.E..
Thomas Roessler authored
721 memmove (state->wbuf + state->curpos + 1, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof (wchar_t));
1ddde09 Entering multibyte characters. From Edmund Grimley Evans.
Thomas Roessler authored
722 state->wbuf[state->curpos++] = wc;
4a5c572 More changes to the utf-8 friendly line editor: Implement some
Thomas Roessler authored
723 state->lastchar++;
e577381 Initial revision
Thomas Roessler authored
724 }
725 else
726 {
727 mutt_flushinp ();
728 BEEP ();
729 }
730 }
731 }
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
732
733 bye:
734
cbab567 Replace safe_free calls by the FREE macro.
Thomas Roessler authored
735 FREE (&tempbuf);
cd4ebbf Make _mutt_enter_string() re-entrant.
Thomas Roessler authored
736 return rv;
737 }
738
739 void mutt_free_enter_state (ENTER_STATE **esp)
740 {
741 if (!esp) return;
742
cbab567 Replace safe_free calls by the FREE macro.
Thomas Roessler authored
743 FREE (&(*esp)->wbuf);
850e0a9 Avoid safe_free() usage and add security checks
Rocco Rutte authored
744 FREE (esp); /* __FREE_CHECKED__ */
e577381 Initial revision
Thomas Roessler authored
745 }
5d71b3c Make the line editor utf-8 friendly. First take from Edmund Grimley
Thomas Roessler authored
746
747 /*
748 * TODO:
749 * very narrow screen might crash it
750 * sort out the input side
751 * unprintable chars
752 */
Something went wrong with that request. Please try again.