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.21 2001/06/25 15:19:31 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19: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"
36 v_c_settop(SCR
*sp
, VICMD
*vp
)
39 size_t x
= 0, y
= LASTLINE(sp
); /* Future: change to -1 to not
45 * We want to scroll the screen, without changing the cursor position.
46 * So, we fill the screen map and then flush it to the screen. Then,
47 * set the VIP_S_REFRESH flag so the main vi loop doesn't update the
48 * screen. When the next real command happens, the refresh code will
49 * notice that the screen map is way wrong and fix it.
52 * There may be a serious performance problem here -- we're doing no
53 * optimization whatsoever, which means that we're copying the entire
54 * screen out to the X11 screen code on each change.
56 if (vs_sm_fill(sp
, vp
->ev
.e_lno
, P_TOP
))
58 for (smp
= HMAP
; smp
<= TMAP
; ++smp
) {
60 if (vs_line(sp
, smp
, &ty
, &tx
))
67 (void)sp
->gp
->scr_move(sp
, y
, x
);
69 F_SET(VIP(sp
), VIP_S_REFRESH
);
71 return (sp
->gp
->scr_refresh(sp
, 0));
79 v_edit(SCR
*sp
, VICMD
*vp
)
83 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
84 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
85 return (v_exec_ex(sp
, vp
, &cmd
));
90 * Set an option value.
93 v_editopt(SCR
*sp
, VICMD
*vp
)
100 INT2CHAR(sp
, vp
->ev
.e_str2
, STRLEN(vp
->ev
.e_str2
)+1, np
, nlen
);
102 rval
= api_opts_set(sp
, vp
->ev
.e_str1
, p2
,
103 vp
->ev
.e_val1
, vp
->ev
.e_val1
);
104 if (sp
->gp
->scr_reply
!= NULL
)
105 (void)sp
->gp
->scr_reply(sp
, rval
, NULL
);
112 * Edit in a split screen.
115 v_editsplit(SCR
*sp
, VICMD
*vp
)
119 ex_cinit(sp
, &cmd
, C_EDIT
, 0, OOBLNO
, OOBLNO
, 0);
120 F_SET(&cmd
, E_NEWSCREEN
);
121 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
122 return (v_exec_ex(sp
, vp
, &cmd
));
130 v_tag(SCR
*sp
, VICMD
*vp
)
137 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
138 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
139 return (v_exec_ex(sp
, vp
, &cmd
));
144 * Tag on the supplied string.
147 v_tagas(SCR
*sp
, VICMD
*vp
)
151 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
152 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
153 return (v_exec_ex(sp
, vp
, &cmd
));
158 * Tag in a split screen.
161 v_tagsplit(SCR
*sp
, VICMD
*vp
)
168 ex_cinit(sp
, &cmd
, C_TAG
, 0, OOBLNO
, OOBLNO
, 0);
169 F_SET(&cmd
, E_NEWSCREEN
);
170 argv_exp0(sp
, &cmd
, VIP(sp
)->keyw
, STRLEN(VIP(sp
)->keyw
));
171 return (v_exec_ex(sp
, vp
, &cmd
));
179 v_quit(SCR
*sp
, VICMD
*vp
)
183 ex_cinit(sp
, &cmd
, C_QUIT
, 0, OOBLNO
, OOBLNO
, 0);
184 return (v_exec_ex(sp
, vp
, &cmd
));
189 * Repaint selected lines from the screen.
191 * PUBLIC: int v_erepaint __P((SCR *, EVENT *));
194 v_erepaint(SCR
*sp
, EVENT
*evp
)
198 for (; evp
->e_flno
<= evp
->e_tlno
; ++evp
->e_flno
) {
199 smp
= HMAP
+ evp
->e_flno
- 1;
201 if (vs_line(sp
, smp
, NULL
, NULL
))
212 v_sel_end(SCR
*sp
, EVENT
*evp
)
217 smp
= HMAP
+ evp
->e_lno
;
224 vip
->sel
.lno
= smp
->lno
;
226 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
235 v_sel_start(SCR
*sp
, EVENT
*evp
)
240 smp
= HMAP
+ evp
->e_lno
;
247 vip
->sel
.lno
= smp
->lno
;
249 vs_colpos(sp
, smp
->lno
, evp
->e_cno
+ (smp
->soff
- 1) * sp
->cols
);
255 * Write and quit command.
258 v_wq(SCR
*sp
, VICMD
*vp
)
262 ex_cinit(sp
, &cmd
, C_WQ
, 0, OOBLNO
, OOBLNO
, 0);
265 if (db_last(sp
, &cmd
.addr2
.lno
))
267 return (v_exec_ex(sp
, vp
, &cmd
));
275 v_write(SCR
*sp
, VICMD
*vp
)
279 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
282 if (db_last(sp
, &cmd
.addr2
.lno
))
284 return (v_exec_ex(sp
, vp
, &cmd
));
292 v_writeas(SCR
*sp
, VICMD
*vp
)
296 ex_cinit(sp
, &cmd
, C_WRITE
, 0, OOBLNO
, OOBLNO
, 0);
297 argv_exp0(sp
, &cmd
, vp
->ev
.e_csp
, vp
->ev
.e_len
);
300 if (db_last(sp
, &cmd
.addr2
.lno
))
302 return (v_exec_ex(sp
, vp
, &cmd
));
307 * Find the event associated with a function.
309 * PUBLIC: int v_event __P((SCR *, VICMD *));
312 v_event(SCR
*sp
, VICMD
*vp
)
314 /* This array maps events to vi command functions. */
315 static VIKEYS
const vievents
[] = {
316 #define V_C_SETTOP 0 /* VI_C_SETTOP */
318 #define V_EDIT 1 /* VI_EDIT */
320 #define V_EDITOPT 2 /* VI_EDITOPT */
322 #define V_EDITSPLIT 3 /* VI_EDITSPLIT */
324 #define V_EMARK 4 /* VI_MOUSE_MOVE */
325 {v_emark
, V_ABS_L
|V_MOVE
},
326 #define V_QUIT 5 /* VI_QUIT */
328 #define V_SEARCH 6 /* VI_SEARCH */
329 {v_esearch
, V_ABS_L
|V_MOVE
},
330 #define V_TAG 7 /* VI_TAG */
332 #define V_TAGAS 8 /* VI_TAGAS */
334 #define V_TAGSPLIT 9 /* VI_TAGSPLIT */
336 #define V_WQ 10 /* VI_WQ */
338 #define V_WRITE 11 /* VI_WRITE */
340 #define V_WRITEAS 12 /* VI_WRITEAS */
344 switch (vp
->ev
.e_ipcom
) {
346 vp
->kp
= &vikeys
['0'];
349 vp
->kp
= &vikeys
['G'];
352 vp
->kp
= &vikeys
['x'];
356 vp
->count
= vp
->ev
.e_lno
;
357 vp
->kp
= &vikeys
['\012'];
360 vp
->kp
= &vikeys
['$'];
363 vp
->kp
= &vikeys
['i'];
366 vp
->kp
= &vikeys
['\010'];
370 vp
->count
= vp
->ev
.e_lno
;
371 vp
->kp
= &vikeys
['\006'];
375 vp
->count
= vp
->ev
.e_lno
;
376 vp
->kp
= &vikeys
['\002'];
379 vp
->kp
= &vikeys
['\040'];
382 vp
->kp
= &vievents
[V_SEARCH
];
385 vp
->kp
= &vievents
[V_C_SETTOP
];
390 vp
->kp
= &vikeys
['G'];
394 vp
->count
= vp
->ev
.e_lno
;
395 vp
->kp
= &vikeys
['\020'];
398 vp
->kp
= &vievents
[V_EDIT
];
401 vp
->kp
= &vievents
[V_EDITOPT
];
404 vp
->kp
= &vievents
[V_EDITSPLIT
];
407 vp
->kp
= &vievents
[V_EMARK
];
410 v_sel_end(sp
, &vp
->ev
);
411 /* XXX RETURN IGNORE */
414 v_sel_start(sp
, &vp
->ev
);
415 /* XXX RETURN IGNORE */
418 vp
->kp
= &vievents
[V_QUIT
];
421 vp
->kp
= &vievents
[V_TAG
];
424 vp
->kp
= &vievents
[V_TAGAS
];
427 vp
->kp
= &vievents
[V_TAGSPLIT
];
430 vp
->kp
= &vikeys
['u'];
433 vp
->kp
= &vievents
[V_WQ
];
436 vp
->kp
= &vievents
[V_WRITE
];
439 vp
->kp
= &vievents
[V_WRITEAS
];