1 /* $NetBSD: v_event.c,v 1.2 2008/12/05 22:51:43 christos Exp $ */
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 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";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
29 #include "../common/common.h"
30 #include "../ipc/ip.h"
38 v_c_settop(SCR
*sp
, VICMD
*vp
)
41 size_t x
= 0, y
= LASTLINE(sp
); /* Future: change to -1 to not
47 * We want to scroll the screen, without changing the cursor position.
48 * So, we fill the screen map and then flush it to the screen. Then,
49 * set the VIP_S_REFRESH flag so the main vi loop doesn't update the
50 * screen. When the next real command happens, the refresh code will
51 * notice that the screen map is way wrong and fix it.
54 * There may be a serious performance problem here -- we're doing no
55 * optimization whatsoever, which means that we're copying the entire
56 * screen out to the X11 screen code on each change.
58 if (vs_sm_fill(sp
, vp
->ev
.e_lno
, P_TOP
))
60 for (smp
= HMAP
; smp
<= TMAP
; ++smp
) {
62 if (vs_line(sp
, smp
, &ty
, &tx
))
64 if (ty
!= (size_t)-1) {
69 (void)sp
->gp
->scr_move(sp
, y
, x
);
71 F_SET(VIP(sp
), VIP_S_REFRESH
);
73 return (sp
->gp
->scr_refresh(sp
, 0));
81 v_edit(SCR
*sp
, VICMD
*vp
)
85 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
86 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
87 return (v_exec_ex(sp
, vp
, &cmd
));
92 * Set an option value.
95 v_editopt(SCR
*sp
, VICMD
*vp
)
102 INT2CHAR(sp
, vp
->ev
.e_str2
, STRLEN(vp
->ev
.e_str2
)+1, np
, nlen
);
104 rval
= api_opts_set(sp
, vp
->ev
.e_str1
, p2
,
105 vp
->ev
.e_val1
, vp
->ev
.e_val1
);
106 if (sp
->gp
->scr_reply
!= NULL
)
107 (void)sp
->gp
->scr_reply(sp
, rval
, NULL
);
114 * Edit in a split screen.
117 v_editsplit(SCR
*sp
, VICMD
*vp
)
121 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
122 F_SET(&cmd
, E_NEWSCREEN
);
123 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
124 return (v_exec_ex(sp
, vp
, &cmd
));
132 v_tag(SCR
*sp
, VICMD
*vp
)
139 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
140 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
141 return (v_exec_ex(sp
, vp
, &cmd
));
146 * Tag on the supplied string.
149 v_tagas(SCR
*sp
, VICMD
*vp
)
153 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
154 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
155 return (v_exec_ex(sp
, vp
, &cmd
));
160 * Tag in a split screen.
163 v_tagsplit(SCR
*sp
, VICMD
*vp
)
170 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
171 F_SET(&cmd
, E_NEWSCREEN
);
172 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
173 return (v_exec_ex(sp
, vp
, &cmd
));
181 v_quit(SCR
*sp
, VICMD
*vp
)
185 ex_cinit(sp
, &cmd
, C_QUIT
, 0, OOBLNO
, OOBLNO
, 0);
186 return (v_exec_ex(sp
, vp
, &cmd
));
191 * Repaint selected lines from the screen.
193 * PUBLIC: int v_erepaint __P((SCR *, EVENT *));
196 v_erepaint(SCR
*sp
, EVENT
*evp
)
200 for (; evp
->e_flno
<= evp
->e_tlno
; ++evp
->e_flno
) {
201 smp
= HMAP
+ evp
->e_flno
- 1;
203 if (vs_line(sp
, smp
, NULL
, NULL
))
214 v_sel_end(SCR
*sp
, EVENT
*evp
)
219 smp
= HMAP
+ evp
->e_lno
;
226 vip
->sel
.lno
= smp
->lno
;
228 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
237 v_sel_start(SCR
*sp
, EVENT
*evp
)
242 smp
= HMAP
+ evp
->e_lno
;
249 vip
->sel
.lno
= smp
->lno
;
251 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
257 * Write and quit command.
260 v_wq(SCR
*sp
, VICMD
*vp
)
264 ex_cinit(sp
, &cmd
, C_WQ
, 0, OOBLNO
, OOBLNO
, 0);
267 if (db_last(sp
, &cmd
.addr2
.lno
))
269 return (v_exec_ex(sp
, vp
, &cmd
));
277 v_write(SCR
*sp
, VICMD
*vp
)
281 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
284 if (db_last(sp
, &cmd
.addr2
.lno
))
286 return (v_exec_ex(sp
, vp
, &cmd
));
294 v_writeas(SCR
*sp
, VICMD
*vp
)
298 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
299 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
302 if (db_last(sp
, &cmd
.addr2
.lno
))
304 return (v_exec_ex(sp
, vp
, &cmd
));
309 * Find the event associated with a function.
311 * PUBLIC: int v_event __P((SCR *, VICMD *));
314 v_event(SCR
*sp
, VICMD
*vp
)
316 /* This array maps events to vi command functions. */
317 #define VIKEYDEF(a, b) { a, b, NULL, NULL }
318 static VIKEYS
const vievents
[] = {
319 #define V_C_SETTOP 0 /* VI_C_SETTOP */
320 VIKEYDEF(v_c_settop
, 0),
321 #define V_EDIT 1 /* VI_EDIT */
323 #define V_EDITOPT 2 /* VI_EDITOPT */
324 VIKEYDEF(v_editopt
, 0),
325 #define V_EDITSPLIT 3 /* VI_EDITSPLIT */
326 VIKEYDEF(v_editsplit
, 0),
327 #define V_EMARK 4 /* VI_MOUSE_MOVE */
328 VIKEYDEF(v_emark
, V_ABS_L
|V_MOVE
),
329 #define V_QUIT 5 /* VI_QUIT */
331 #define V_SEARCH 6 /* VI_SEARCH */
332 VIKEYDEF(v_esearch
, V_ABS_L
|V_MOVE
),
333 #define V_TAG 7 /* VI_TAG */
335 #define V_TAGAS 8 /* VI_TAGAS */
336 VIKEYDEF(v_tagas
, 0),
337 #define V_TAGSPLIT 9 /* VI_TAGSPLIT */
338 VIKEYDEF(v_tagsplit
, 0),
339 #define V_WQ 10 /* VI_WQ */
341 #define V_WRITE 11 /* VI_WRITE */
342 VIKEYDEF(v_write
, 0),
343 #define V_WRITEAS 12 /* VI_WRITEAS */
344 VIKEYDEF(v_writeas
, 0),
347 switch (vp
->ev
.e_ipcom
) {
349 vp
->kp
= &vikeys
['0'];
352 vp
->kp
= &vikeys
['G'];
355 vp
->kp
= &vikeys
['x'];
359 vp
->count
= vp
->ev
.e_lno
;
360 vp
->kp
= &vikeys
['\012'];
363 vp
->kp
= &vikeys
['$'];
366 vp
->kp
= &vikeys
['i'];
369 vp
->kp
= &vikeys
['\010'];
373 vp
->count
= vp
->ev
.e_lno
;
374 vp
->kp
= &vikeys
['\006'];
378 vp
->count
= vp
->ev
.e_lno
;
379 vp
->kp
= &vikeys
['\002'];
382 vp
->kp
= &vikeys
['\040'];
385 vp
->kp
= &vievents
[V_SEARCH
];
388 vp
->kp
= &vievents
[V_C_SETTOP
];
393 vp
->kp
= &vikeys
['G'];
397 vp
->count
= vp
->ev
.e_lno
;
398 vp
->kp
= &vikeys
['\020'];
401 vp
->kp
= &vievents
[V_EDIT
];
404 vp
->kp
= &vievents
[V_EDITOPT
];
407 vp
->kp
= &vievents
[V_EDITSPLIT
];
410 vp
->kp
= &vievents
[V_EMARK
];
413 v_sel_end(sp
, &vp
->ev
);
414 /* XXX RETURN IGNORE */
417 v_sel_start(sp
, &vp
->ev
);
418 /* XXX RETURN IGNORE */
421 vp
->kp
= &vievents
[V_QUIT
];
424 vp
->kp
= &vievents
[V_TAG
];
427 vp
->kp
= &vievents
[V_TAGAS
];
430 vp
->kp
= &vievents
[V_TAGSPLIT
];
433 vp
->kp
= &vikeys
['u'];
436 vp
->kp
= &vievents
[V_WQ
];
439 vp
->kp
= &vievents
[V_WRITE
];
442 vp
->kp
= &vievents
[V_WRITEAS
];