3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid
[] = "$Id: v_event.c,v 8.19 2001/06/09 18:26:31 skimo Exp $ (Berkeley) $Date: 2001/06/09 18:26:31 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
18 #include <bitstring.h>
27 #include "../common/common.h"
28 #include "../ipc/ip.h"
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
))
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));
87 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
88 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
89 return (v_exec_ex(sp
, vp
, &cmd
));
94 * Set an option value.
106 INT2CHAR(sp
, vp
->ev
.e_str1
, STRLEN(vp
->ev
.e_str1
), np
, nlen
);
108 INT2CHAR(sp
, vp
->ev
.e_str2
, STRLEN(vp
->ev
.e_str2
), np
, nlen
);
110 rval
= api_opts_set(sp
, p1
, p2
, vp
->ev
.e_val1
, vp
->ev
.e_val1
);
111 if (sp
->gp
->scr_reply
!= NULL
)
112 (void)sp
->gp
->scr_reply(sp
, rval
, NULL
);
120 * Edit in a split screen.
129 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
130 F_SET(&cmd
, E_NEWSCREEN
);
131 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
132 return (v_exec_ex(sp
, vp
, &cmd
));
149 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
150 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
151 return (v_exec_ex(sp
, vp
, &cmd
));
156 * Tag on the supplied string.
165 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
166 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
167 return (v_exec_ex(sp
, vp
, &cmd
));
172 * Tag in a split screen.
184 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
185 F_SET(&cmd
, E_NEWSCREEN
);
186 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
187 return (v_exec_ex(sp
, vp
, &cmd
));
201 ex_cinit(sp
, &cmd
, C_QUIT
, 0, OOBLNO
, OOBLNO
, 0);
202 return (v_exec_ex(sp
, vp
, &cmd
));
207 * Repaint selected lines from the screen.
209 * PUBLIC: int v_erepaint __P((SCR *, EVENT *));
218 for (; evp
->e_flno
<= evp
->e_tlno
; ++evp
->e_flno
) {
219 smp
= HMAP
+ evp
->e_flno
- 1;
221 if (vs_line(sp
, smp
, NULL
, NULL
))
239 smp
= HMAP
+ evp
->e_lno
;
246 vip
->sel
.lno
= smp
->lno
;
248 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
264 smp
= HMAP
+ evp
->e_lno
;
271 vip
->sel
.lno
= smp
->lno
;
273 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
279 * Write and quit command.
288 ex_cinit(sp
, &cmd
, C_WQ
, 0, OOBLNO
, OOBLNO
, 0);
291 if (db_last(sp
, &cmd
.addr2
.lno
))
293 return (v_exec_ex(sp
, vp
, &cmd
));
307 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
310 if (db_last(sp
, &cmd
.addr2
.lno
))
312 return (v_exec_ex(sp
, vp
, &cmd
));
326 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
327 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
330 if (db_last(sp
, &cmd
.addr2
.lno
))
332 return (v_exec_ex(sp
, vp
, &cmd
));
337 * Find the event associated with a function.
339 * PUBLIC: int v_event __P((SCR *, VICMD *));
346 /* This array maps events to vi command functions. */
347 static VIKEYS
const vievents
[] = {
348 #define V_C_SETTOP 0 /* VI_C_SETTOP */
350 #define V_EDIT 1 /* VI_EDIT */
352 #define V_EDITOPT 2 /* VI_EDITOPT */
354 #define V_EDITSPLIT 3 /* VI_EDITSPLIT */
356 #define V_EMARK 4 /* VI_MOUSE_MOVE */
357 {v_emark
, V_ABS_L
|V_MOVE
},
358 #define V_QUIT 5 /* VI_QUIT */
360 #define V_SEARCH 6 /* VI_SEARCH */
361 {v_esearch
, V_ABS_L
|V_MOVE
},
362 #define V_TAG 7 /* VI_TAG */
364 #define V_TAGAS 8 /* VI_TAGAS */
366 #define V_TAGSPLIT 9 /* VI_TAGSPLIT */
368 #define V_WQ 10 /* VI_WQ */
370 #define V_WRITE 11 /* VI_WRITE */
372 #define V_WRITEAS 12 /* VI_WRITEAS */
376 switch (vp
->ev
.e_ipcom
) {
378 vp
->kp
= &vikeys
['0'];
381 vp
->kp
= &vikeys
['G'];
384 vp
->kp
= &vikeys
['x'];
388 vp
->count
= vp
->ev
.e_lno
;
389 vp
->kp
= &vikeys
['\012'];
392 vp
->kp
= &vikeys
['$'];
395 vp
->kp
= &vikeys
['i'];
398 vp
->kp
= &vikeys
['\010'];
402 vp
->count
= vp
->ev
.e_lno
;
403 vp
->kp
= &vikeys
['\006'];
407 vp
->count
= vp
->ev
.e_lno
;
408 vp
->kp
= &vikeys
['\002'];
411 vp
->kp
= &vikeys
['\040'];
414 vp
->kp
= &vievents
[V_SEARCH
];
417 vp
->kp
= &vievents
[V_C_SETTOP
];
422 vp
->kp
= &vikeys
['G'];
426 vp
->count
= vp
->ev
.e_lno
;
427 vp
->kp
= &vikeys
['\020'];
430 vp
->kp
= &vievents
[V_EDIT
];
433 vp
->kp
= &vievents
[V_EDITOPT
];
436 vp
->kp
= &vievents
[V_EDITSPLIT
];
439 vp
->kp
= &vievents
[V_EMARK
];
442 v_sel_end(sp
, &vp
->ev
);
443 /* XXX RETURN IGNORE */
446 v_sel_start(sp
, &vp
->ev
);
447 /* XXX RETURN IGNORE */
450 vp
->kp
= &vievents
[V_QUIT
];
453 vp
->kp
= &vievents
[V_TAG
];
456 vp
->kp
= &vievents
[V_TAGAS
];
459 vp
->kp
= &vievents
[V_TAGSPLIT
];
462 vp
->kp
= &vikeys
['u'];
465 vp
->kp
= &vievents
[V_WQ
];
468 vp
->kp
= &vievents
[V_WRITE
];
471 vp
->kp
= &vievents
[V_WRITEAS
];