1 /* $NetBSD: v_event.c,v 1.2 2013/11/22 15:52:06 christos Exp $ */
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
12 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 ";
15 #include <sys/types.h>
16 #include <sys/queue.h>
19 #include <bitstring.h>
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
37 v_c_settop(SCR
*sp
, VICMD
*vp
)
40 size_t x
= 0, y
= LASTLINE(sp
); /* Future: change to -1 to not
46 * We want to scroll the screen, without changing the cursor position.
47 * So, we fill the screen map and then flush it to the screen. Then,
48 * set the VIP_S_REFRESH flag so the main vi loop doesn't update the
49 * screen. When the next real command happens, the refresh code will
50 * notice that the screen map is way wrong and fix it.
53 * There may be a serious performance problem here -- we're doing no
54 * optimization whatsoever, which means that we're copying the entire
55 * screen out to the X11 screen code on each change.
57 if (vs_sm_fill(sp
, vp
->ev
.e_lno
, P_TOP
))
59 for (smp
= HMAP
; smp
<= TMAP
; ++smp
) {
61 if (vs_line(sp
, smp
, &ty
, &tx
))
63 if (ty
!= (size_t)-1) {
68 (void)sp
->gp
->scr_move(sp
, y
, x
);
70 F_SET(VIP(sp
), VIP_S_REFRESH
);
72 return (sp
->gp
->scr_refresh(sp
, 0));
80 v_edit(SCR
*sp
, VICMD
*vp
)
84 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
85 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
86 return (v_exec_ex(sp
, vp
, &cmd
));
91 * Set an option value.
94 v_editopt(SCR
*sp
, VICMD
*vp
)
101 INT2CHAR(sp
, vp
->ev
.e_str2
, STRLEN(vp
->ev
.e_str2
)+1, np
, nlen
);
103 rval
= api_opts_set(sp
, vp
->ev
.e_str1
, p2
,
104 vp
->ev
.e_val1
, vp
->ev
.e_val1
);
105 if (sp
->gp
->scr_reply
!= NULL
)
106 (void)sp
->gp
->scr_reply(sp
, rval
, NULL
);
113 * Edit in a split screen.
116 v_editsplit(SCR
*sp
, VICMD
*vp
)
120 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
121 F_SET(&cmd
, E_NEWSCREEN
);
122 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
123 return (v_exec_ex(sp
, vp
, &cmd
));
131 v_tag(SCR
*sp
, VICMD
*vp
)
138 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
139 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
140 return (v_exec_ex(sp
, vp
, &cmd
));
145 * Tag on the supplied string.
148 v_tagas(SCR
*sp
, VICMD
*vp
)
152 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
153 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
154 return (v_exec_ex(sp
, vp
, &cmd
));
159 * Tag in a split screen.
162 v_tagsplit(SCR
*sp
, VICMD
*vp
)
169 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
170 F_SET(&cmd
, E_NEWSCREEN
);
171 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
172 return (v_exec_ex(sp
, vp
, &cmd
));
180 v_quit(SCR
*sp
, VICMD
*vp
)
184 ex_cinit(sp
, &cmd
, C_QUIT
, 0, OOBLNO
, OOBLNO
, 0);
185 return (v_exec_ex(sp
, vp
, &cmd
));
190 * Repaint selected lines from the screen.
192 * PUBLIC: int v_erepaint __P((SCR *, EVENT *));
195 v_erepaint(SCR
*sp
, EVENT
*evp
)
199 for (; evp
->e_flno
<= evp
->e_tlno
; ++evp
->e_flno
) {
200 smp
= HMAP
+ evp
->e_flno
- 1;
202 if (vs_line(sp
, smp
, NULL
, NULL
))
213 v_sel_end(SCR
*sp
, EVENT
*evp
)
218 smp
= HMAP
+ evp
->e_lno
;
225 vip
->sel
.lno
= smp
->lno
;
227 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
236 v_sel_start(SCR
*sp
, EVENT
*evp
)
241 smp
= HMAP
+ evp
->e_lno
;
248 vip
->sel
.lno
= smp
->lno
;
250 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
256 * Write and quit command.
259 v_wq(SCR
*sp
, VICMD
*vp
)
263 ex_cinit(sp
, &cmd
, C_WQ
, 0, OOBLNO
, OOBLNO
, 0);
266 if (db_last(sp
, &cmd
.addr2
.lno
))
268 return (v_exec_ex(sp
, vp
, &cmd
));
276 v_write(SCR
*sp
, VICMD
*vp
)
280 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
283 if (db_last(sp
, &cmd
.addr2
.lno
))
285 return (v_exec_ex(sp
, vp
, &cmd
));
293 v_writeas(SCR
*sp
, VICMD
*vp
)
297 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
298 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
301 if (db_last(sp
, &cmd
.addr2
.lno
))
303 return (v_exec_ex(sp
, vp
, &cmd
));
308 * Find the event associated with a function.
310 * PUBLIC: int v_event __P((SCR *, VICMD *));
313 v_event(SCR
*sp
, VICMD
*vp
)
315 /* This array maps events to vi command functions. */
316 #define VIKEYDEF(a, b) { a, b, NULL, NULL }
317 static VIKEYS
const vievents
[] = {
318 #define V_C_SETTOP 0 /* VI_C_SETTOP */
319 VIKEYDEF(v_c_settop
, 0),
320 #define V_EDIT 1 /* VI_EDIT */
322 #define V_EDITOPT 2 /* VI_EDITOPT */
323 VIKEYDEF(v_editopt
, 0),
324 #define V_EDITSPLIT 3 /* VI_EDITSPLIT */
325 VIKEYDEF(v_editsplit
, 0),
326 #define V_EMARK 4 /* VI_MOUSE_MOVE */
327 VIKEYDEF(v_emark
, V_ABS_L
|V_MOVE
),
328 #define V_QUIT 5 /* VI_QUIT */
330 #define V_SEARCH 6 /* VI_SEARCH */
331 VIKEYDEF(v_esearch
, V_ABS_L
|V_MOVE
),
332 #define V_TAG 7 /* VI_TAG */
334 #define V_TAGAS 8 /* VI_TAGAS */
335 VIKEYDEF(v_tagas
, 0),
336 #define V_TAGSPLIT 9 /* VI_TAGSPLIT */
337 VIKEYDEF(v_tagsplit
, 0),
338 #define V_WQ 10 /* VI_WQ */
340 #define V_WRITE 11 /* VI_WRITE */
341 VIKEYDEF(v_write
, 0),
342 #define V_WRITEAS 12 /* VI_WRITEAS */
343 VIKEYDEF(v_writeas
, 0),
346 switch (vp
->ev
.e_ipcom
) {
348 vp
->kp
= &vikeys
['0'];
351 vp
->kp
= &vikeys
['G'];
354 vp
->kp
= &vikeys
['x'];
358 vp
->count
= vp
->ev
.e_lno
;
359 vp
->kp
= &vikeys
['\012'];
362 vp
->kp
= &vikeys
['$'];
365 vp
->kp
= &vikeys
['i'];
368 vp
->kp
= &vikeys
['\010'];
372 vp
->count
= vp
->ev
.e_lno
;
373 vp
->kp
= &vikeys
['\006'];
377 vp
->count
= vp
->ev
.e_lno
;
378 vp
->kp
= &vikeys
['\002'];
381 vp
->kp
= &vikeys
['\040'];
384 vp
->kp
= &vievents
[V_SEARCH
];
387 vp
->kp
= &vievents
[V_C_SETTOP
];
392 vp
->kp
= &vikeys
['G'];
396 vp
->count
= vp
->ev
.e_lno
;
397 vp
->kp
= &vikeys
['\020'];
400 vp
->kp
= &vievents
[V_EDIT
];
403 vp
->kp
= &vievents
[V_EDITOPT
];
406 vp
->kp
= &vievents
[V_EDITSPLIT
];
409 vp
->kp
= &vievents
[V_EMARK
];
412 v_sel_end(sp
, &vp
->ev
);
413 /* XXX RETURN IGNORE */
416 v_sel_start(sp
, &vp
->ev
);
417 /* XXX RETURN IGNORE */
420 vp
->kp
= &vievents
[V_QUIT
];
423 vp
->kp
= &vievents
[V_TAG
];
426 vp
->kp
= &vievents
[V_TAGAS
];
429 vp
->kp
= &vievents
[V_TAGSPLIT
];
432 vp
->kp
= &vikeys
['u'];
435 vp
->kp
= &vievents
[V_WQ
];
438 vp
->kp
= &vievents
[V_WRITE
];
441 vp
->kp
= &vievents
[V_WRITEAS
];