2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: v_scroll.c,v 8.8 1993/12/16 12:11:56 bostic Exp $ (Berkeley) $Date: 1993/12/16 12:11:56 $";
12 #include <sys/types.h>
21 * The historic vi had a problem in that all movements were by physical
22 * lines, not by logical, or screen lines. Arguments can be made that this
23 * is the right thing to do. For example, single line movements, such as
24 * 'j' or 'k', should probably work on physical lines. Commands like "dj",
25 * or "j.", where '.' is a change command, make more sense for physical lines
26 * than they do for logical lines.
28 * These arguments, however, don't apply to scrolling commands like ^D and
29 * ^F -- if the window is fairly small, using physical lines can result in
30 * a half-page scroll repainting the entire screen, which is not what the
31 * user wanted. Second, if the line is larger than the screen, using physical
32 * lines can make it impossible to display parts of the line -- there aren't
33 * any commands that don't display the beginning of the line in historic vi,
34 * and if both the beginning and end of the line can't be on the screen at
35 * the same time, you lose. This is even worse in the case of the H, L, and
36 * M commands -- for large lines, they may all refer to the same line and
37 * will result in no movement at all.
39 * This implementation does the scrolling (^B, ^D, ^F, ^U, ^Y, ^E), and the
40 * cursor positioning commands (H, L, M) commands using logical lines, not
43 * Another issue is that page and half-page scrolling commands historically
44 * moved to the first non-blank character in the new line. If the line is
45 * approximately the same size as the screen, this loses because the cursor
46 * before and after a ^D, may refer to the same location on the screen. In
47 * this implementation, scrolling commands set the cursor to the first non-
48 * blank character if the line changes because of the scroll. Otherwise,
49 * the cursor is left alone.
54 * Go to first non-blank character of the line count, the last line
55 * of the file by default.
58 v_lgoto(sp
, ep
, vp
, fm
, tm
, rp
)
66 if (file_lline(sp
, ep
, &last
))
68 if (F_ISSET(vp
, VC_C1SET
)) {
69 if (last
< vp
->count
) {
75 rp
->lno
= last
? last
: 1;
81 * Move to the first non-blank character of the logical line
82 * count from the top of the screen, 1 by default.
85 v_home(sp
, ep
, vp
, fm
, tm
, rp
)
91 return (sp
->s_position(sp
, ep
, rp
,
92 F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 0, P_TOP
));
97 * Move to the first non-blank character of the logical line
98 * in the middle of the screen.
101 v_middle(sp
, ep
, vp
, fm
, tm
, rp
)
108 * Yielding to none in our quest for compatibility with every
109 * historical blemish of vi, no matter how strange it might be,
110 * we permit the user to enter a count and then ignore it.
112 return (sp
->s_position(sp
, ep
, rp
, 0, P_MIDDLE
));
116 * v_bottom -- [count]L
117 * Move to the first non-blank character of the logical line
118 * count from the bottom of the screen, 1 by default.
121 v_bottom(sp
, ep
, vp
, fm
, tm
, rp
)
127 return (sp
->s_position(sp
, ep
,
128 rp
, F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 0, P_BOTTOM
));
132 * v_up -- [count]^P, [count]k, [count]-
136 v_up(sp
, ep
, vp
, fm
, tm
, rp
)
144 lno
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1;
146 if (fm
->lno
<= lno
) {
150 rp
->lno
= fm
->lno
- lno
;
156 * In a script window, send the line to the shell.
157 * In a regular window, move down by lines.
160 v_cr(sp
, ep
, vp
, fm
, tm
, rp
)
167 * If it's a script window, exec the line,
168 * otherwise it's the same as v_down().
170 return (F_ISSET(sp
, S_SCRIPT
) ?
171 sscr_exec(sp
, ep
, fm
->lno
) : v_down(sp
, ep
, vp
, fm
, tm
, rp
));
175 * v_down -- [count]^J, [count]^N, [count]j, [count]^M, [count]+
176 * Move down by lines.
179 v_down(sp
, ep
, vp
, fm
, tm
, rp
)
187 lno
= fm
->lno
+ (F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1);
189 if (file_gline(sp
, ep
, lno
, NULL
) == NULL
) {
198 * v_hpageup -- [count]^U
199 * Page up half screens.
202 v_hpageup(sp
, ep
, vp
, fm
, tm
, rp
)
209 * Half screens always succeed unless already at SOF. Half screens
210 * set the scroll value, even if the command ultimately failed, in
211 * historic vi. It's probably a don't care.
213 if (F_ISSET(vp
, VC_C1SET
))
214 O_VAL(sp
, O_SCROLL
) = vp
->count
;
216 vp
->count
= O_VAL(sp
, O_SCROLL
);
218 return (sp
->s_down(sp
, ep
, rp
, (recno_t
)O_VAL(sp
, O_SCROLL
), 1));
222 * v_hpagedown -- [count]^D
223 * Page down half screens.
226 v_hpagedown(sp
, ep
, vp
, fm
, tm
, rp
)
233 * Half screens always succeed unless already at EOF. Half screens
234 * set the scroll value, even if the command ultimately failed, in
235 * historic vi. It's probably a don't care.
237 if (F_ISSET(vp
, VC_C1SET
))
238 O_VAL(sp
, O_SCROLL
) = vp
->count
;
240 vp
->count
= O_VAL(sp
, O_SCROLL
);
242 return (sp
->s_up(sp
, ep
, rp
, (recno_t
)O_VAL(sp
, O_SCROLL
), 1));
246 * v_pageup -- [count]^B
247 * Page up full screens.
250 * Historic vi did not move to the SOF if the screen couldn't move, i.e.
251 * if SOF was already displayed on the screen. This implementation does
252 * move to SOF in that case, making ^B more like the the historic ^U.
255 v_pageup(sp
, ep
, vp
, fm
, tm
, rp
)
263 /* Calculation from POSIX 1003.2/D8. */
264 count
= (F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1) * (sp
->t_rows
- 1);
266 return (sp
->s_down(sp
, ep
, rp
, count
, 1));
270 * v_pagedown -- [count]^F
271 * Page down full screens.
273 * Historic vi did not move to the EOF if the screen couldn't move, i.e.
274 * if EOF was already displayed on the screen. This implementation does
275 * move to EOF in that case, making ^F more like the the historic ^D.
278 v_pagedown(sp
, ep
, vp
, fm
, tm
, rp
)
286 /* Calculation from POSIX 1003.2/D8. */
287 count
= (F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1) * (sp
->t_rows
- 1);
289 return (sp
->s_up(sp
, ep
, rp
, count
, 1));
293 * v_lineup -- [count]^Y
297 v_lineup(sp
, ep
, vp
, fm
, tm
, rp
)
304 * The cursor moves down, staying with its original line, unless it
305 * reaches the bottom of the screen.
307 return (sp
->s_down(sp
, ep
,
308 rp
, F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1, 0));
312 * v_linedown -- [count]^E
313 * Page down by lines.
316 v_linedown(sp
, ep
, vp
, fm
, tm
, rp
)
323 * The cursor moves up, staying with its original line, unless it
324 * reaches the top of the screen.
326 return (sp
->s_up(sp
, ep
,
327 rp
, F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1, 0));