Initial revision
[nvi.git] / vi / v_z.c
blob5487dc333445ee3e474b8d563c7b87dab75f7c1b
1 /* move4.c */
3 /* Author:
4 * Steve Kirkendall
5 * 14407 SW Teal Blvd. #C
6 * Beaverton, OR 97005
7 * kirkenda@cs.pdx.edu
8 */
11 /* This file contains movement functions which are screen-relative */
13 #include "config.h"
14 #include "vi.h"
16 /* This moves the cursor to a particular row on the screen */
17 /*ARGSUSED*/
18 MARK m_row(m, cnt, key)
19 MARK m; /* the cursor position */
20 long cnt; /* the row we'll move to */
21 int key; /* the keystroke of this move - H/L/M */
23 DEFAULT(1);
25 /* calculate destination line based on key */
26 cnt--;
27 switch (key)
29 case 'H':
30 cnt = topline + cnt;
31 break;
33 case 'M':
34 cnt = topline + (LINES - 1) / 2;
35 break;
37 case 'L':
38 cnt = botline - cnt;
39 break;
42 /* return the mark of the destination line */
43 return MARK_AT_LINE(cnt);
47 /* This function repositions the current line to show on a given row */
48 /*ARGSUSED*/
49 MARK m_z(m, cnt, key)
50 MARK m; /* the cursor */
51 long cnt; /* the line number we're repositioning */
52 int key; /* key struck after the z */
54 long newtop;
55 int i;
57 /* Which line are we talking about? */
58 if (cnt < 0 || cnt > nlines)
60 return MARK_UNSET;
62 if (cnt)
64 m = MARK_AT_LINE(cnt);
65 newtop = cnt;
67 else
69 newtop = markline(m);
72 /* allow a "window size" number to be entered */
73 for (i = 0; key >= '0' && key <= '9'; key = getkey(0))
75 i = i * 10 + key - '0';
77 #ifndef CRUNCH
78 if (i > 0 && i <= LINES - 1)
80 *o_window = i;
82 #endif
84 /* figure out which line will have to be at the top of the screen */
85 switch (key)
87 case '\n':
88 #if OSK
89 case '\l':
90 #else
91 case '\r':
92 #endif
93 case '+':
94 break;
96 case '.':
97 case 'z':
98 newtop -= LINES / 2;
99 break;
101 case '-':
102 newtop -= LINES - 1;
103 break;
105 default:
106 return MARK_UNSET;
109 /* make the new topline take effect */
110 if (newtop >= 1)
112 topline = newtop;
114 else
116 topline = 1L;
118 redrawrange(0L, INFINITY, INFINITY);
120 /* The cursor doesn't move */
121 return m;
125 /* This function scrolls the screen. It does this by calling redraw() with
126 * an off-screen line as the argument. It will move the cursor if necessary
127 * so that the cursor is on the new screen.
129 /*ARGSUSED*/
130 MARK m_scroll(m, cnt, key)
131 MARK m; /* the cursor position */
132 long cnt; /* for some keys: the number of lines to scroll */
133 int key; /* keystroke that causes this movement */
135 MARK tmp; /* a temporary mark, used as arg to redraw() */
137 /* adjust cnt, and maybe *o_scroll, depending of key */
138 switch (key)
140 case ctrl('F'):
141 case ctrl('B'):
142 DEFAULT(1);
143 redrawrange(0, INFINITY, INFINITY);
144 cnt = cnt * (LINES - 1) - 1; /* keeps one old line on screen */
145 break;
147 case ctrl('E'):
148 case ctrl('Y'):
149 DEFAULT(1);
150 break;
152 case ctrl('U'):
153 case ctrl('D'):
154 if (cnt == 0) /* default */
156 cnt = *o_scroll;
158 else
160 if (cnt > LINES - 1)
162 cnt = LINES - 1;
164 *o_scroll = cnt;
166 break;
169 /* scroll up or down, depending on key */
170 switch (key)
172 case ctrl('B'):
173 case ctrl('Y'):
174 case ctrl('U'):
175 cnt = topline - cnt;
176 if (cnt < 1L)
178 cnt = 1L;
179 m = MARK_FIRST;
181 tmp = MARK_AT_LINE(cnt) + markidx(m);
182 redraw(tmp, FALSE);
183 if (markline(m) > botline)
185 m = MARK_AT_LINE(botline);
187 break;
189 case ctrl('F'):
190 case ctrl('E'):
191 case ctrl('D'):
192 cnt = botline + cnt;
193 if (cnt > nlines)
195 cnt = nlines;
196 m = MARK_LAST;
198 tmp = MARK_AT_LINE(cnt) + markidx(m);
199 redraw(tmp, FALSE);
200 if (markline(m) < topline)
202 m = MARK_AT_LINE(topline);
204 break;
207 /* arrange for ctrl-B and ctrl-F to redraw the smart line */
208 if (key == ctrl('B') || key == ctrl('F'))
210 changes++;
212 /* also, erase the statusline. This happens naturally for
213 * the scrolling commands, but the paging commands need to
214 * explicitly clear the statusline.
216 msg("");
219 return m;