Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 957 lines (865 sloc) 26.06 kb
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
1 /* input.c */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
2 /* Copyright 1995 by Steve Kirkendall */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
3
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
4 char id_input[] = "$Id: input.c,v 2.46 1996/09/21 05:26:35 steve Exp $";
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
5
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
6 #include "elvis.h"
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
7
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
8 /* These data types are used to store the parsing state for input mode
9 * commands. This is very simple, since most commands are only one keystroke
10 * long. (The only exceptions are that INP_QUOTE is two keystrokes long, and
11 * INP_HEX1/INP_HEX2 is three keystrokes long.)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
12 */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
13 typedef enum {
14 INP_NORMAL, /* a normal character to insert/replace */
15 INP_NEWLINE, /* insert a newline */
16 INP_QUOTE, /* we're in the middle of a ^V sequence */
17 INP_HEX1, /* we're expecting the first of two hex digits */
18 INP_HEX2, /* we're expecting the second of two hex digits */
19 INP_DIG1, /* we're expecting the first of two digraph chars */
20 INP_DIG2, /* we're expecting the second of two digraph chars */
21 INP_TAB, /* ^I - insert a bunch of spaces to look like a tab */
22 INP_ONEVI, /* ^O - execute one vi command */
23 INP_MULTIVI, /* ESC - execute many vi commands */
24 INP_BACKSPACE, /* ^H - backspace one character */
25 INP_BACKWORD, /* ^W - backspace one word */
26 INP_BACKLINE, /* ^U - backspace one line */
27 INP_SHIFTL, /* ^D - reduce indentation */
28 INP_SHIFTR, /* ^T - increase indentation */
29 INP_EXPOSE, /* ^R/^L - redraw the screen */
30 INP_PREVIOUS, /* ^@ - insert a copy of previous text, then exit */
31 INP_AGAIN, /* ^A - insert a copy of previous text, continue */
32 INP_PUT /* ^P - insert a copy of anonymous cut buffer */
33 } INPCMD;
34 typedef struct
35 {
36 BOOLEAN setbottom; /* Set bottom = cursor before drawing cursor? */
37 BOOLEAN replacing; /* True if we're in "replace" mode */
38 INPCMD cmd; /* the command to perform */
39 CHAR arg; /* argument -- usually a key to insert */
40 CHAR backsp; /* char backspaced over, or '\0' */
41 CHAR prev; /* previously input char, or '\0' */
42 } INPUTINFO;
43
44
45 #if USE_PROTOTYPES
46 static void cleanup(WINDOW win, BOOLEAN del, BOOLEAN backsp, BOOLEAN yank);
47 static void addchar(MARK cursor, MARK top, MARK bottom, INPUTINFO *info);
48 static BOOLEAN tryabbr(WINDOW win, _CHAR_ nextc);
49 static RESULT perform(WINDOW win);
50 static RESULT parse(_CHAR_ key, void *info);
51 static ELVCURSOR shape(WINDOW win);
52 #endif
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
53
54
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
55 /* This function deletes everything between "cursor" and "bottom" of the
56 * current state. This is used, for example, when the user hits <Esc>
57 * after using "cw" to change a long word into a short one. It should be
58 * called for the INP_ONEVI command with backsp=False, and before INP_MULTIVI
59 * backup=True.
60 */
61 static void cleanup(win, del, backsp, yank)
62 WINDOW win; /* window where input took place */
63 BOOLEAN del; /* if True, delete text after the cursor */
64 BOOLEAN backsp; /* if True, move to the left */
65 BOOLEAN yank; /* if True, yank input text into ". buffer */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
66 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
67 /* delete the excess in the edited region */
68 if (del && markoffset(win->state->cursor) < markoffset(win->state->bottom))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
69 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
70 bufreplace(win->state->cursor, win->state->bottom, NULL, 0);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
71 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
72 else
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
73 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
74 marksetoffset(win->state->bottom, markoffset(win->state->cursor));
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
75 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
76 assert(markoffset(win->state->cursor) == markoffset(win->state->bottom));
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
77
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
78 /* save the newly input text in the "previous input" buffer */
79 if (yank)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
80 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
81 cutyank('.', win->state->top, win->state->bottom, 'c', False);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
82 }
83
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
84 /* move the cursor back one character, unless it is already at the
85 * start of a line.
86 */
87 if (backsp && markoffset(win->state->cursor) > 0)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
88 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
89 markaddoffset(win->state->cursor, -1);
90 if (scanchar(win->state->cursor) == '\n')
91 {
92 markaddoffset(win->state->cursor, 1);
93 }
94 marksetoffset(win->state->top, markoffset(win->state->cursor));
95 marksetoffset(win->state->bottom, markoffset(win->state->cursor));
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
96 }
97
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
98 /* Force the screen to be regenerated */
99 if (win->di->logic == DRAW_NORMAL)
100 win->di->logic = DRAW_CHANGED;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
101 }
102
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
103 /* This function inserts/replaces a single character in a buffer, and
104 * advances the cursor and (if necessary) bottom mark.
105 */
106 static void addchar(cursor, top, bottom, info)
107 MARK cursor; /* where to add a character */
108 MARK top; /* start of edit bounds */
109 MARK bottom; /* end of edit bounds */
110 INPUTINFO *info; /* other info, including char to be inserted */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
111 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
112 MARKBUF replaced;
113
114 /* decide whether to insert or replace */
115 replaced = *cursor;
116 if (markoffset(cursor) < markoffset(bottom))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
117 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
118 replaced.offset++;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
119 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
120 else if (info->replacing && markoffset(cursor) < o_bufchars(markbuffer(cursor)))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
121 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
122 if (scanchar(cursor) != '\n')
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
123 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
124 replaced.offset++;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
125 }
126 }
127
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
128 /* do it */
129 bufreplace(cursor, &replaced, &info->arg, 1);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
130
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
131 /* we need to advance the cursor, and maybe bottom */
132 markaddoffset(cursor, 1);
133 if (markoffset(cursor) > markoffset(bottom))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
134 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
135 marksetoffset(bottom, markoffset(cursor));
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
136 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
137 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
138
139
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
140 /* This function attempts to expand an abbreviation at the cursor location,
141 * if there is one. If so, it deletes the short form, and pushes the long
142 * form an following character back onto the type-ahead buffer. Else it
143 * returns False.
144 */
145 static BOOLEAN tryabbr(win, nextc)
146 WINDOW win; /* window where abbreviation may need expanding */
147 _CHAR_ nextc; /* character after the word */
148 {
149 MARKBUF from, to;
150 CHAR *cp, *build;
151 long slen, llen;
152 CHAR cbuf[1];
153
154 /* Try to do an abbreviation. To do this, we collect
155 * characters backward to the preceding whitespace. We
156 * go to the preceding whitespace because abbreviations
157 * can't contain whitespace; we know we'll never need
158 * more characters to recognize an abbreviation. We
159 * collect the characters backwards just because it is
160 * easier.
161 */
162 for (scanalloc(&cp, win->state->cursor), build = NULL;
163 cp && scanprev(&cp) && !isspace(*cp);
164 )
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
165 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
166 buildCHAR(&build, *cp);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
167 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
168 scanfree(&cp);
169 if (build)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
170 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
171 cp = mapabbr(build, &slen, &llen, (BOOLEAN)(win->state->acton != NULL));
172 if (cp)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
173 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
174 /* yes, we have an abbreviation! */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
175
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
176 /* delete the short form */
177 cleanup(win, True, False, False);
178 (void)marktmp(from, markbuffer(win->state->cursor), markoffset(win->state->cursor) - slen);
179 (void)marktmp(to, markbuffer(win->state->cursor), markoffset(win->state->cursor));
180 bufreplace(&from, &to, NULL, 0);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
181
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
182 /* stuff the long form, and the user's
183 * non-alnum character, into the queue
184 */
185 if (nextc)
186 {
187 cbuf[0] = nextc;
188 mapunget(cbuf, 1, False);
189 }
190 mapunget(cp, (int)llen, False);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
191
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
192 /* move cursor to where word goes */
193 marksetoffset(win->state->bottom, markoffset(&from));
194 marksetoffset(win->state->cursor, markoffset(&from));
195 safefree(build);
196 return True;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
197 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
198 safefree(build);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
199 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
200 return False;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
201 }
202
203
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
204 /* This function performs an input-mode command. Usually, this will be a
205 * character to insert/replace in the text.
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
206 */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
207 static RESULT perform(win)
208 WINDOW win; /* window where inputting should be done */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
209 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
210 STATE *state = win->state;
211 INPUTINFO *ii = (INPUTINFO *)state->info;
212 MARK cursor = state->cursor;
213 MARK tmp;
214 MARKBUF from, to;
215 CHAR *cp;
216 char *littlecp, ch;
217 EXINFO xinfb;
218 VIINFO vinfb;
219 union
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
220 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
221 char partial[256];
222 CHAR full[256];
223 } name;
224 long col, len;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
225
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
226 safeinspect();
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
227
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
228 /* initially assume there is no matching parenthesis */
229 win->match = -4;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
230
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
231 /* if cursor has been moved outside the top & bottom, then reset
232 * the top & bottom to match cursor
233 */
234 if (markbuffer(state->top) != markbuffer(state->cursor))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
235 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
236 marksetbuffer(state->top, markbuffer(state->cursor));
237 marksetoffset(state->top, markoffset(state->cursor));
238 marksetbuffer(state->bottom, markbuffer(state->cursor));
239 marksetoffset(state->bottom, markoffset(state->cursor));
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
240 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
241 else if (markoffset(state->top) > markoffset(state->cursor)
242 || markoffset(state->cursor) > markoffset(state->bottom))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
243 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
244 marksetoffset(state->top, markoffset(state->cursor));
245 marksetoffset(state->bottom, markoffset(state->cursor));
246 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
247
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
248 /* process the keystroke */
249 switch (ii->cmd)
250 {
251 case INP_NORMAL:
252 /* maybe try to do a digraph */
253 if (ii->backsp && o_digraph)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
254 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
255 ii->arg = digraph(ii->backsp, ii->arg);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
256 }
257
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
258 /* If next character is non-alphanumeric, check for abbrev.
259 * (Note: Since we never expand abbreviations except in the
260 * main buffer or the ex history buffer, we can skip it if
261 * we're editing some other buffer such as regexp history.
262 * Assume only the ex history buffer has inputtab=filename.)
263 */
264 if (!isalnum(ii->arg)
265 && ii->arg != '_'
266 && (state->acton == NULL || o_inputtab(markbuffer(cursor)) == 'f'))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
267 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
268 if (tryabbr(win, ii->arg))
269 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
270 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
271 /* fall through... */
272
273 case INP_HEX1: /* can't happen */
274 case INP_HEX2:
275 case INP_DIG1: /* can't happen */
276 case INP_DIG2:
277 case INP_QUOTE:
278 /* add the character */
279 addchar(cursor, state->top, state->bottom, ii);
280
281 /* if it wasn't whitespace, then maybe do wordwrap */
282 if (!isspace(ii->arg)
283 && cursor == win->cursor
284 && win->md->wordwrap
285 && o_textwidth(markbuffer(cursor)) > 0
286 && dispmark2col(win) >= o_textwidth(markbuffer(cursor)))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
287 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
288 /* Figure out where the current word started */
289 for (scanalloc(&cp, cursor);
290 scanprev(&cp) && !isspace(*cp);
291 )
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
292 {
293 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
294 if (cp)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
295 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
296 to = *scanmark(&cp);
297 markaddoffset(&to, 1L);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
298 }
299
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
300 /* Locate the front of this line. We won't look past
301 * back before this character.
302 */
303 tmp = dispmove(win, 0L, 0L);
304
305 /* scan backward over any whitespace */
306 for (len = markoffset(&to) - markoffset(tmp);
307 len > 0 && scanprev(&cp) && isspace(*cp);
308 len--)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
309 {
310 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
311 if (cp)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
312 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
313 from = *scanmark(&cp);
314 markaddoffset(&from, 1L);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
315 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
316 assert(cp || len <= 0);
317 scanfree(&cp);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
318
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
319 /* We can only do the word wrap stuff if the current
320 * word isn't the line's first word.
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
321 */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
322 if (len > 0)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
323 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
324 /* replace the whitespace with a newline */
325 bufreplace(&from, &to, toCHAR("\n"), 1L);
326 marksetoffset(&to, markoffset(&from) + 1);
327
328 /* handle autoindent */
329 dispindent(win, &to, -1L);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
330 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
331 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
332
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
333 /* remember digraph hints */
334 ii->backsp = '\0';
335 ii->prev = ii->arg;
336
337 /* If the character was a parenthesis, and the showmatch
338 * option is set, then try to locate its match.
339 */
340 if (o_showmatch(win) && CHARchr(toCHAR(")}]"), ii->arg))
341 {
342 from = *cursor;
343 assert(markoffset(cursor) > 0);
344 markaddoffset(cursor, -1);
345 memset((char *)&vinfb, 0, sizeof vinfb);
346 vinfb.command = '%';
347 if (m_absolute(win, &vinfb) == RESULT_COMPLETE)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
348 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
349 win->match = markoffset(cursor);
350 }
351 assert(markbuffer(cursor) == markbuffer(&from));
352 *cursor = from;
353 }
354 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
355
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
356 case INP_NEWLINE:
357 cleanup(win, True, False, False);
358 if (!tryabbr(win, '\n'))
359 {
360 ii->arg = '\n';
361 ii->cmd = INP_NORMAL;
362 perform(win);
363 dispindent(win, cursor, -1);
364 }
365 ii->backsp = ii->prev = '\0';
366 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
367
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
368 case INP_TAB:
369 if (!tryabbr(win, '\n'))
370 {
371 switch (o_inputtab(markbuffer(cursor)))
372 {
373 case 't':
374 /* insert a tab */
375 addchar(cursor, state->top, state->bottom, ii);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
376 break;
377
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
378 case 's':
379 /* insert enough spaces to look like a tab */
380 col = dispmark2col(win);
381 ii->arg = ' ';
382 do
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
383 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
384 addchar(cursor, state->top, state->bottom, ii);
385 } while ((++col) % o_tabstop(markbuffer(cursor)) != 0);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
386 break;
387
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
388 case 'f':
389 /* filename completion */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
390
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
391 /* if at start of input, then fail */
392 if (markoffset(cursor) == markoffset(state->top))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
393 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
394 guibeep(win);
395 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
396 }
397
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
398 /* locate the previous character */
399 tmp = markdup(cursor);
400 markaddoffset(tmp, -1);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
401
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
402 /* if previous is whitespace, then fail */
403 if (isspace(scanchar(tmp)) || scanchar(tmp) == '(')
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
404 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
405 markfree(tmp);
406 guibeep(win);
407 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
408 }
409
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
410 /* collect the partial name into char array */
411 littlecp = &name.partial[QTY(name.partial)];
412 *--littlecp = '\0';
413 ch = scanchar(tmp);
414 do
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
415 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
416 *--littlecp = ch;
417 markaddoffset(tmp, -1);
418 ch = (markoffset(tmp) >= markoffset(state->top)) ? scanchar(tmp) : ' ';
419 } while (!isspace(ch) && ch != '(');
420 markaddoffset(tmp, 1);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
421
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
422 /* try to expand the filename */
423 littlecp = iofilename(littlecp, (ch == '(') ? ')' : '\t');
424 if (!littlecp)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
425 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
426 markfree(tmp);
427 guibeep(win);
428 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
429 }
430
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
431 /* name found -- replace old word with expanded name */
432 for (cp = name.full, col = 0;
433 (*cp++ = *littlecp++) != '\0'; /* yes, ASSIGNMENT! */
434 col++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
435 {
436 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
437 bufreplace(tmp, win->state->bottom, name.full, col);
438 marksetoffset(cursor, markoffset(tmp) + col);
439 marksetoffset(win->state->bottom, markoffset(cursor));
440 markfree(tmp);
441 }
442 }
443 ii->backsp = ii->prev = '\0';
444 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
445
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
446 case INP_ONEVI:
447 cleanup(win, True, False, True);
448 vipush(win, ELVIS_ONCE, NULL);
449 ii->backsp = ii->prev = '\0';
450 ii->setbottom = True;
451 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
452
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
453 case INP_MULTIVI:
454 cleanup(win, True, True, True);
455 win->state->flags |= ELVIS_POP;
456 ii->backsp = ii->prev = '\0';
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
457
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
458 #if 1
459 /* if blank line in autoindent mode, then delete any whitespace */
460 if (o_autoindent(markbuffer(cursor)))
461 {
462 for (from = *dispmove(win,0L,0L), scanalloc(&cp, &from);
463 cp && (*cp == ' ' || *cp == '\t');
464 scannext(&cp))
465 {
466 }
467 if (cp && *cp == '\n')
468 {
469 to = *scanmark(&cp);
470 scanfree(&cp);
471 if (markoffset(&to) > markoffset(&from) &&
472 markoffset(&to) - 1 == markoffset(cursor))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
473 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
474 bufreplace(&from, &to, NULL, 0L);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
475 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
476 }
477 else
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
478 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
479 scanfree(&cp);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
480 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
481 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
482 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
483 break;
484
485 case INP_BACKSPACE:
486 ii->backsp = '\0';
487 if (markoffset(win->state->top) < markoffset(cursor))
488 {
489 /* backspace within the newly typed text */
490 markaddoffset(cursor, -1);
491 ii->backsp = ii->prev;
492 }
493 else if (win->state->acton != NULL
494 && (win->state->flags & ELVIS_1LINE) != 0)
495 {
496 /* backspace out of an ex command line or regexp line */
497 cleanup(win, True, True, True);
498 win->state->flags |= ELVIS_POP;
499 win->state->pop->flags &= ~(ELVIS_MORE | ELVIS_ONCE);
500 if (win->state->pop->perform == _viperform)
501 {
502 viinitcmd((VIINFO *)win->state->pop->info);
503 }
504 ii->backsp = '\0';
505 }
506 else
507 {
508 /* bump into left edge of new text */
509 guibeep(win);
510 }
511 ii->prev = '\0';
512 break;
513
514 case INP_BACKWORD:
515 if (markoffset(win->state->top) < markoffset(cursor))
516 {
517 /* expect to back up at least one character */
518 markaddoffset(cursor, -1);
519 scanalloc(&cp, cursor);
520
521 /* if on whitespace, then back up to non-whitespace */
522 while (markoffset(win->state->top) < markoffset(win->state->cursor)
523 && isspace(*cp))
524 {
525 markaddoffset(cursor, -1);
526 scanprev(&cp);
527 }
528
529 /* back up to whitespace */
530 while (markoffset(win->state->top) < markoffset(win->state->cursor)
531 && !isspace(*cp))
532 {
533 markaddoffset(cursor, -1);
534 scanprev(&cp);
535 }
536
537 /* if we hit whitespace, then leave cursor after it */
538 if (isspace(*cp))
539 {
540 markaddoffset(cursor, 1);
541 }
542 scanfree(&cp);
543 }
544 else
545 {
546 guibeep(win);
547 }
548 ii->backsp = ii->prev = '\0';
549 break;
550
551 case INP_BACKLINE:
552 /* find the start of this line, or if the cursor is already
553 * there, then the start of the preceding line.
554 */
555 tmp = (*win->md->move)(win, cursor, 0, 0, False);
556 if (markoffset(tmp) == markoffset(cursor))
557 {
558 tmp = (*win->md->move)(win, cursor, -1, 0, False);
559 }
560
561 /* move to either the start of the line or the top of the
562 * edited region, whichever is closer.
563 */
564 if (markoffset(tmp) > markoffset(win->state->top))
565 {
566 marksetoffset(cursor, markoffset(tmp));
567 }
568 else if (markoffset(state->top) < markoffset(cursor))
569 {
570 marksetoffset(cursor, markoffset(state->top));
571 }
572 else
573 {
574 guibeep(win);
575 }
576 ii->backsp = ii->prev = '\0';
577 break;
578
579 case INP_SHIFTL:
580 case INP_SHIFTR:
581 /* build a :< or :> ex command */
582 memset((char *)&xinfb, 0, sizeof xinfb);
583 xinfb.defaddr = *cursor;
584 xinfb.from = xinfb.to = markline(cursor);
585 xinfb.fromaddr = marktmp(from, markbuffer(cursor), lowline(bufbufinfo(markbuffer(cursor)), xinfb.from));
586 xinfb.toaddr = marktmp(to, markbuffer(cursor), lowline(bufbufinfo(markbuffer(cursor)), xinfb.to + 1));;
587 xinfb.command = (ii->cmd == INP_SHIFTL) ? EX_SHIFTL : EX_SHIFTR;
588 xinfb.multi = 1;
589 xinfb.bang = True;
590
591 /* execute the command */
592 len = o_bufchars(markbuffer(cursor)) - markoffset(cursor);
593 assert(len >= 0);
594 (void)ex_shift(&xinfb);
595 ii->backsp = ii->prev = '\0';
596 assert(o_bufchars(markbuffer(cursor)) >= len);
597 marksetoffset(cursor, o_bufchars(markbuffer(cursor)) - len);
598 break;
599
600 case INP_EXPOSE:
601 drawexpose(win, 0, 0, (int)(o_lines(win) - 1), (int)(o_columns(win) - 1));
602 break;
603
604 case INP_PREVIOUS:
605 case INP_AGAIN:
606 case INP_PUT:
607 cleanup(win, True, False, False);
608
609 /* Copy the text. Be careful not to change the "top" mark. */
610 from = *state->top;
611 tmp = cutput((ii->cmd == INP_PUT ? '1' : '.'),
612 win, cursor, False, True, True);
613 marksetoffset(state->top, markoffset(&from));
614
615 /* if successful, tweak the "cursor" and "bottom" marks. */
616 if (tmp)
617 {
618 marksetoffset(cursor, markoffset(tmp) + 1);
619 marksetoffset(state->bottom, markoffset(cursor));
620 if (ii->cmd == INP_PREVIOUS)
621 {
622 cleanup(win, True, True, True);
623 state->flags |= ELVIS_POP;
624 }
625 }
626 ii->backsp = ii->prev = '\0';
627 break;
628
629 }
630
631 /* set wantcol to the cursor's current column */
632 win->wantcol = dispmark2col(win);
633
634 /* prepare for next command */
635 ii->cmd = INP_NORMAL;
636
637 return RESULT_COMPLETE;
638 }
639
640 /* This function parses a command. This involves remembering whether we're
641 * in the middle of a ^V quoted character, and also recognizing some special
642 * characters.
643 */
644 static RESULT parse(key, info)
645 _CHAR_ key; /* next keystroke */
646 void *info; /* current parsing state */
647 {
648 INPUTINFO *ii = (INPUTINFO *)info;
649
650 /* parse the input command */
651 if (ii->cmd == INP_HEX1 || ii->cmd == INP_HEX2)
652 {
653 /* convert hex digit from ASCII to binary */
654 if (key >= '0' && key <= '9')
655 {
656 key -= '0';
657 }
658 else if (key >= 'a' && key <= 'f')
659 {
660 key -= 'a' - 10;
661 }
662 else if (key >= 'A' && key <= 'F')
663 {
664 key -= 'A' - 10;
665 }
666 else
667 {
668 /* this command is invalid; prepare for next command */
669 ii->cmd = INP_NORMAL;
670 return RESULT_ERROR;
671 }
672
673 /* merge into arg */
674 if (ii->cmd == INP_HEX1)
675 {
676 ii->arg = (key << 4);
677 ii->cmd = INP_HEX2;
678 windefault->state->mapflags |= MAP_DISABLE;
679 return RESULT_MORE;
680 }
681 else
682 {
683 ii->arg |= key;
684 return RESULT_COMPLETE;
685 }
686 }
687 else if (ii->cmd == INP_DIG1 || ii->cmd == INP_DIG2)
688 {
689 if (ii->cmd == INP_DIG1)
690 {
691 ii->arg = key;
692 ii->cmd = INP_DIG2;
693 windefault->state->mapflags |= MAP_DISABLE;
694 return RESULT_MORE;
695 }
696 else
697 {
698 ii->arg = digraph(ii->arg, key);
699 return RESULT_COMPLETE;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
700 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
701 }
702 else if (ii->cmd == INP_QUOTE)
703 {
704 ii->arg = key;
705 }
706 else
707 {
708 ii->arg = key;
709 switch (key)
710 {
711 case ELVCTRL('@'): ii->cmd = INP_PREVIOUS; break;
712 case ELVCTRL('A'): ii->cmd = INP_AGAIN; break;
713 case ELVCTRL('D'): ii->cmd = INP_SHIFTL; break;
714 case '\177': /* usually mapped to "visual x", else... */
715 case ELVCTRL('H'): ii->cmd = INP_BACKSPACE; break;
716 case ELVCTRL('I'): ii->cmd = INP_TAB; break;
717 case ELVCTRL('J'): ii->cmd = INP_NEWLINE; break;
718 case ELVCTRL('K'): ii->cmd = INP_DIG1; break;
719 case ELVCTRL('L'): ii->cmd = INP_EXPOSE; break;
720 case ELVCTRL('M'): ii->cmd = INP_NEWLINE; break;
721 case ELVCTRL('O'): ii->cmd = INP_ONEVI; break;
722 case ELVCTRL('P'): ii->cmd = INP_PUT; break;
723 case ELVCTRL('R'): ii->cmd = INP_EXPOSE; break;
724 case ELVCTRL('T'): ii->cmd = INP_SHIFTR; break;
725 case ELVCTRL('U'): ii->cmd = INP_BACKLINE; break;
726 case ELVCTRL('V'): ii->cmd = INP_QUOTE; break;
727 case ELVCTRL('W'): ii->cmd = INP_BACKWORD; break;
728 case ELVCTRL('X'): ii->cmd = INP_HEX1; break;
729 case ELVCTRL('['): ii->cmd = INP_MULTIVI; break;
730 default: ii->cmd = INP_NORMAL;
731 }
732
733 /* ^V, ^X, and ^K require more keystrokes... */
734 if (ii->cmd == INP_QUOTE || ii->cmd == INP_HEX1 || ii->cmd == INP_DIG1)
735 {
736 windefault->state->mapflags |= MAP_DISABLE;
737 return RESULT_MORE;
738 }
739 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
740
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
741 /* the command is complete */
742 return RESULT_COMPLETE;
743 }
744
745 /* This function decides on a cursor shape */
746 static ELVCURSOR shape(win)
747 WINDOW win; /* window whose shape should be returned */
748 {
749 STATE *state = win->state;
750 INPUTINFO *info = (INPUTINFO *)state->info;
751 MARK cursor = state->cursor;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
752
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
753 /* if in the middle of ^V, then always CURSOR_QUOTE */
754 if (info->cmd == INP_QUOTE)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
755 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
756 state->mapflags &= ~(MAP_INPUT|MAP_COMMAND);
757 return CURSOR_QUOTE;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
758 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
759 state->mapflags |= MAP_INPUT;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
760
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
761 /* decide whether to insert or replace */
762 if (markoffset(state->top) <= markoffset(cursor)
763 && markoffset(cursor) < markoffset(state->bottom))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
764 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
765 if (info->setbottom)
766 {
767 marksetoffset(state->bottom, markoffset(cursor));
768 info->setbottom = False;
769 return CURSOR_INSERT;
770 }
771 return CURSOR_REPLACE;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
772 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
773 else if (info->replacing && markoffset(cursor) < o_bufchars(markbuffer(cursor)))
774 {
775 if (scanchar(cursor) != '\n')
776 {
777 info->setbottom = False;
778 return CURSOR_REPLACE;
779 }
780 }
781 info->setbottom = False;
782 return CURSOR_INSERT;
783 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
784
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
785
786 /* This function pushes a state onto the state stack, and then initializes it
787 * to be either an input or replace state, with the cursor at a given location.
788 * The "mode" argument can be 'R' for replace, or anything else for input.
789 * The input cursor is "cursor", which should generally the result of a
790 * markalloc() or markdup() function call. Ditto for the top and bottom of
791 * the edit region.
792 */
793 void inputpush(win, flags, mode)
794 WINDOW win; /* window that should be switched to input mode */
795 ELVISSTATE flags; /* flags describing this state */
796 _char_ mode; /* 'R' for replace, or anything else for insert */
797 {
798 /* push the state */
799 flags |= ELVIS_REGION;
800 statepush(win, flags);
801
802 /* initialize the state */
803 win->state->parse = parse;
804 win->state->perform = perform;
805 win->state->shape = shape;
806 win->state->info = safealloc(1, sizeof (INPUTINFO));
807 win->state->mapflags |= MAP_INPUT;
808 if (mode == 'R')
809 {
810 ((INPUTINFO *)win->state->info)->replacing = True;
811 win->state->modename = "Replace";
812 }
813 else
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
814 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
815 ((INPUTINFO *)win->state->info)->replacing = False;
816 win->state->modename = " Input ";
817 }
818 }
819
820 /* This function tweaks the most recent "input" or "replace" state.
821 * The "mode" can be 't' to toggle "input" to "replace" or vice verse,
822 * 'R' to force the mode to be "replace", or anything else to force the
823 * mode to be "input". This function is called by vi mode's perform()
824 * function.
825 */
826 void inputtoggle(win, mode)
827 WINDOW win; /* window to be toggled */
828 _char_ mode; /* 'R' for replace, 't' to toggle, else insert */
829 {
830 STATE *state;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
831
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
832 /* find the most recent "input" or "replace" state */
833 for (state = win->state; state && state->perform != perform; state = state->pop)
834 {
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
835 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
836 assert(state != NULL);
837
838 /* change the mode */
839 switch (mode)
840 {
841 case 't':
842 ((INPUTINFO *)state->info)->replacing = (BOOLEAN)!((INPUTINFO *)state->info)->replacing;
843 break;
844
845 case 'R':
846 ((INPUTINFO *)state->info)->replacing = True;
847 break;
848
849 default:
850 ((INPUTINFO *)state->info)->replacing = False;
851 }
852
853 if (((INPUTINFO *)state->info)->replacing)
854 {
855 state->modename = "Replace";
856 }
857 else
858 {
859 state->modename = " Input";
860 }
861 }
862
863 /* This function sets the edit boundaries of an "input" state. If there
864 * is no input state on the state stack, then this function will push one.
865 * This function is used to implement the <c> operator, among other things.
866 */
867 void inputchange(win, from, to, linemd)
868 WINDOW win; /* window to be affected */
869 MARK from; /* new start of edit bounds */
870 MARK to; /* new end of edit bounds */
871 BOOLEAN linemd; /* replace old text with a new line? */
872 {
873 MARKBUF tmp;
874 CHAR ch;
875
876 assert(markbuffer(from) == markbuffer(win->state->cursor));
877 assert(markbuffer(from) == markbuffer(to));
878 assert(markoffset(from) <= markoffset(to));
879
880 /* Was this command issued via <Control-O> from input mode?
881 * If not, then we'll need to push one.
882 */
883 if (!win->state->pop)
884 {
885 inputpush(win, 0, 'i');
886 }
887
888 /* replace the last char with '$', if there is a last char
889 * and it is on the same line. If it is on a different line,
890 * then delete the old text. If from==to, then do nothing.
891 */
892 if (markoffset(from) == markoffset(to))
893 {
894 /* do nothing */
895 }
896 else if (markoffset(to) > markoffset(dispmove(win, 0, INFINITY)))
897 {
898 /* delete the old text */
899 if (linemd)
900 {
901 if (o_autoindent(markbuffer(from)))
902 {
903 for (ch = scanchar(from);
904 markoffset(from) < markoffset(to) && (ch == ' ' || ch == '\t');
905 markaddoffset(from, 1), ch = scanchar(from))
906 {
907 }
908 }
909 bufreplace(from, to, toCHAR("\n"), 1);
910 }
911 else
912 {
913 bufreplace(from, to, NULL, 0);
914 }
915 marksetoffset(to, markoffset(from));
916 }
917 else
918 {
919 /* replace the last character with a '$' */
920 tmp = *to;
921 tmp.offset--;
922 bufreplace(&tmp, to, toCHAR("$"), 1);
923 }
924
925 /* set the edit boundaries and the cursor */
926 marksetbuffer(win->state->top, markbuffer(from));
927 marksetbuffer(win->state->bottom, markbuffer(to));
928 marksetoffset(win->state->top, markoffset(from));
929 marksetoffset(win->state->bottom, markoffset(to));
930 marksetoffset(win->state->cursor, markoffset(from));
931 }
932
933
934 /* This function is called by statekey() when the user hits <Enter>, before
935 * calling the stratum's enter() function. This function deletes extra
936 * characters after the cursor, and adjusts the endpoints of the edited
937 * region to make them be whole lines.
938 */
939 void inputbeforeenter(win)
940 WINDOW win; /* window where <Enter> was just pressed */
941 {
942 /* Make sure "win->state->bottom" includes the cursor position */
943 if (markoffset(win->state->bottom) < markoffset(win->state->cursor))
944 {
945 marksetoffset(win->state->bottom, markoffset(win->state->cursor));
946 }
947
948 /* Delete stuff from after the cursor */
949 cleanup(win, True, False, False);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
950
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
951 /* adjust the endpoints of the edited area to be whole lines */
952 marksetoffset(win->state->top,
953 markoffset((*dmnormal.move)(win, win->state->top, 0, 0, False)));
954 marksetoffset(win->state->bottom,
955 markoffset((*dmnormal.move)(win, win->state->bottom, 0, INFINITY, False)));
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
956 }
Something went wrong with that request. Please try again.