1 /* $NetBSD: v_event.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
11 #include <sys/cdefs.h>
14 static const char sccsid
[] = "Id: v_event.c,v 8.21 2001/06/25 15:19:31 skimo Exp (Berkeley) Date: 2001/06/25 15:19:31 ";
17 __RCSID("$NetBSD: v_event.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #include <sys/types.h>
21 #include <sys/queue.h>
24 #include <bitstring.h>
33 #include "../common/common.h"
34 #include "../ipc/ip.h"
42 v_c_settop(SCR
*sp
, VICMD
*vp
)
45 size_t x
= 0, y
= LASTLINE(sp
); /* Future: change to -1 to not
51 * We want to scroll the screen, without changing the cursor position.
52 * So, we fill the screen map and then flush it to the screen. Then,
53 * set the VIP_S_REFRESH flag so the main vi loop doesn't update the
54 * screen. When the next real command happens, the refresh code will
55 * notice that the screen map is way wrong and fix it.
58 * There may be a serious performance problem here -- we're doing no
59 * optimization whatsoever, which means that we're copying the entire
60 * screen out to the X11 screen code on each change.
62 if (vs_sm_fill(sp
, vp
->ev
.e_lno
, P_TOP
))
64 for (smp
= HMAP
; smp
<= TMAP
; ++smp
) {
66 if (vs_line(sp
, smp
, &ty
, &tx
))
68 if (ty
!= (size_t)-1) {
73 (void)sp
->gp
->scr_move(sp
, y
, x
);
75 F_SET(VIP(sp
), VIP_S_REFRESH
);
77 return (sp
->gp
->scr_refresh(sp
, 0));
85 v_edit(SCR
*sp
, VICMD
*vp
)
89 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
90 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
91 return (v_exec_ex(sp
, vp
, &cmd
));
96 * Set an option value.
99 v_editopt(SCR
*sp
, VICMD
*vp
)
106 INT2CHAR(sp
, vp
->ev
.e_str2
, STRLEN(vp
->ev
.e_str2
)+1, np
, nlen
);
108 rval
= api_opts_set(sp
, vp
->ev
.e_str1
, p2
,
109 vp
->ev
.e_val1
, vp
->ev
.e_val1
);
110 if (sp
->gp
->scr_reply
!= NULL
)
111 (void)sp
->gp
->scr_reply(sp
, rval
, NULL
);
118 * Edit in a split screen.
121 v_editsplit(SCR
*sp
, VICMD
*vp
)
125 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
126 F_SET(&cmd
, E_NEWSCREEN
);
127 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
128 return (v_exec_ex(sp
, vp
, &cmd
));
136 v_tag(SCR
*sp
, VICMD
*vp
)
143 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
144 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
145 return (v_exec_ex(sp
, vp
, &cmd
));
150 * Tag on the supplied string.
153 v_tagas(SCR
*sp
, VICMD
*vp
)
157 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
158 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
159 return (v_exec_ex(sp
, vp
, &cmd
));
164 * Tag in a split screen.
167 v_tagsplit(SCR
*sp
, VICMD
*vp
)
174 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
175 F_SET(&cmd
, E_NEWSCREEN
);
176 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
177 return (v_exec_ex(sp
, vp
, &cmd
));
185 v_quit(SCR
*sp
, VICMD
*vp
)
189 ex_cinit(sp
, &cmd
, C_QUIT
, 0, OOBLNO
, OOBLNO
, 0);
190 return (v_exec_ex(sp
, vp
, &cmd
));
195 * Repaint selected lines from the screen.
197 * PUBLIC: int v_erepaint __P((SCR *, EVENT *));
200 v_erepaint(SCR
*sp
, EVENT
*evp
)
204 for (; evp
->e_flno
<= evp
->e_tlno
; ++evp
->e_flno
) {
205 smp
= HMAP
+ evp
->e_flno
- 1;
207 if (vs_line(sp
, smp
, NULL
, NULL
))
218 v_sel_end(SCR
*sp
, EVENT
*evp
)
223 smp
= HMAP
+ evp
->e_lno
;
230 vip
->sel
.lno
= smp
->lno
;
232 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
241 v_sel_start(SCR
*sp
, EVENT
*evp
)
246 smp
= HMAP
+ evp
->e_lno
;
253 vip
->sel
.lno
= smp
->lno
;
255 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
261 * Write and quit command.
264 v_wq(SCR
*sp
, VICMD
*vp
)
268 ex_cinit(sp
, &cmd
, C_WQ
, 0, OOBLNO
, OOBLNO
, 0);
271 if (db_last(sp
, &cmd
.addr2
.lno
))
273 return (v_exec_ex(sp
, vp
, &cmd
));
281 v_write(SCR
*sp
, VICMD
*vp
)
285 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
288 if (db_last(sp
, &cmd
.addr2
.lno
))
290 return (v_exec_ex(sp
, vp
, &cmd
));
298 v_writeas(SCR
*sp
, VICMD
*vp
)
302 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
303 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
306 if (db_last(sp
, &cmd
.addr2
.lno
))
308 return (v_exec_ex(sp
, vp
, &cmd
));
313 * Find the event associated with a function.
315 * PUBLIC: int v_event __P((SCR *, VICMD *));
318 v_event(SCR
*sp
, VICMD
*vp
)
320 /* This array maps events to vi command functions. */
321 #define VIKEYDEF(a, b) { a, b, NULL, NULL }
322 static VIKEYS
const vievents
[] = {
323 #define V_C_SETTOP 0 /* VI_C_SETTOP */
324 VIKEYDEF(v_c_settop
, 0),
325 #define V_EDIT 1 /* VI_EDIT */
327 #define V_EDITOPT 2 /* VI_EDITOPT */
328 VIKEYDEF(v_editopt
, 0),
329 #define V_EDITSPLIT 3 /* VI_EDITSPLIT */
330 VIKEYDEF(v_editsplit
, 0),
331 #define V_EMARK 4 /* VI_MOUSE_MOVE */
332 VIKEYDEF(v_emark
, V_ABS_L
|V_MOVE
),
333 #define V_QUIT 5 /* VI_QUIT */
335 #define V_SEARCH 6 /* VI_SEARCH */
336 VIKEYDEF(v_esearch
, V_ABS_L
|V_MOVE
),
337 #define V_TAG 7 /* VI_TAG */
339 #define V_TAGAS 8 /* VI_TAGAS */
340 VIKEYDEF(v_tagas
, 0),
341 #define V_TAGSPLIT 9 /* VI_TAGSPLIT */
342 VIKEYDEF(v_tagsplit
, 0),
343 #define V_WQ 10 /* VI_WQ */
345 #define V_WRITE 11 /* VI_WRITE */
346 VIKEYDEF(v_write
, 0),
347 #define V_WRITEAS 12 /* VI_WRITEAS */
348 VIKEYDEF(v_writeas
, 0),
351 switch (vp
->ev
.e_ipcom
) {
353 vp
->kp
= &vikeys
['0'];
356 vp
->kp
= &vikeys
['G'];
359 vp
->kp
= &vikeys
['x'];
363 vp
->count
= vp
->ev
.e_lno
;
364 vp
->kp
= &vikeys
['\012'];
367 vp
->kp
= &vikeys
['$'];
370 vp
->kp
= &vikeys
['i'];
373 vp
->kp
= &vikeys
['\010'];
377 vp
->count
= vp
->ev
.e_lno
;
378 vp
->kp
= &vikeys
['\006'];
382 vp
->count
= vp
->ev
.e_lno
;
383 vp
->kp
= &vikeys
['\002'];
386 vp
->kp
= &vikeys
['\040'];
389 vp
->kp
= &vievents
[V_SEARCH
];
392 vp
->kp
= &vievents
[V_C_SETTOP
];
397 vp
->kp
= &vikeys
['G'];
401 vp
->count
= vp
->ev
.e_lno
;
402 vp
->kp
= &vikeys
['\020'];
405 vp
->kp
= &vievents
[V_EDIT
];
408 vp
->kp
= &vievents
[V_EDITOPT
];
411 vp
->kp
= &vievents
[V_EDITSPLIT
];
414 vp
->kp
= &vievents
[V_EMARK
];
417 v_sel_end(sp
, &vp
->ev
);
418 /* XXX RETURN IGNORE */
421 v_sel_start(sp
, &vp
->ev
);
422 /* XXX RETURN IGNORE */
425 vp
->kp
= &vievents
[V_QUIT
];
428 vp
->kp
= &vievents
[V_TAG
];
431 vp
->kp
= &vievents
[V_TAGAS
];
434 vp
->kp
= &vievents
[V_TAGSPLIT
];
437 vp
->kp
= &vikeys
['u'];
440 vp
->kp
= &vievents
[V_WQ
];
443 vp
->kp
= &vievents
[V_WRITE
];
446 vp
->kp
= &vievents
[V_WRITEAS
];