3 * Window management. Some of the functions are internal, and some are
4 * attached to keys that the user actually types.
13 * Reposition dot in the current window to line "n". If the argument is
14 * positive, it is that line. If it is negative it is that line from the
15 * bottom. If it is 0 the window is centered (this is what the standard
16 * redisplay code does). With no argument it defaults to 1. Bound to M-!.
17 * Because of the default, it works like in Gosling.
24 curwp
->w_flag
|= WFFORCE
;
29 * Refresh the screen. With no argument, it just does the refresh. With an
30 * argument it recenters "." in the current window. Bound to "C-L".
40 curwp
->w_force
= 0; /* Center dot. */
41 curwp
->w_flag
|= WFFORCE
;
48 * The command make the next window (next => down the screen) the current
49 * window. There are no real errors, although the command does nothing if
50 * there is only 1 window on the screen. Bound to "C-X C-N".
58 if ((wp
= curwp
->w_wndp
) == NULL
)
67 * This command makes the previous window (previous => up the screen) the
68 * current window. There arn't any errors, although the command does not do a
69 * lot if there is 1 window.
84 while (wp1
->w_wndp
!= wp2
)
93 * This command moves the current window down by "arg" lines. Recompute the
94 * top line in the window. The move up and move down code is almost completely
95 * the same; most of the work has to do with reframing the window, and picking
96 * a new dot. We share the code by having "move down" just be an interface to
97 * "move up". Magic. Bound to "C-X C-N".
103 return (mvupwind(f
, -n
));
107 * Move the current window up by "arg" lines. Recompute the new top line of
108 * the window. Look to see if "." is still on the screen. If it is, you win.
109 * If it isn't, then move "." to center it in the new framing of the window
110 * (this command does not really move "."; it moves the frame). Bound to
124 while (n
++ && lp
!=curbp
->b_linep
)
129 while (n
-- && lback(lp
)!=curbp
->b_linep
)
134 curwp
->w_flag
|= WFHARD
; /* Mode line is OK. */
136 for (i
= 0; i
< curwp
->w_ntrows
; ++i
)
138 if (lp
== curwp
->w_dotp
)
140 if (lp
== curbp
->b_linep
)
146 i
= curwp
->w_ntrows
/2;
148 while (i
-- && lp
!= curbp
->b_linep
)
157 * This command makes the current window the only window on the screen. Bound
158 * to "C-X 1". Try to set the framing so that "." does not have to move on the
159 * display. Some care has to be taken to keep the values of dot and mark in
160 * the buffer structures right if the distruction of a window makes a buffer
161 * become undisplayed.
171 while (wheadp
!= curwp
) {
174 if (--wp
->w_bufp
->b_nwnd
== 0) {
175 wp
->w_bufp
->b_dotp
= wp
->w_dotp
;
176 wp
->w_bufp
->b_doto
= wp
->w_doto
;
177 wp
->w_bufp
->b_markp
= wp
->w_markp
;
178 wp
->w_bufp
->b_marko
= wp
->w_marko
;
182 while (curwp
->w_wndp
!= NULL
) {
184 curwp
->w_wndp
= wp
->w_wndp
;
185 if (--wp
->w_bufp
->b_nwnd
== 0) {
186 wp
->w_bufp
->b_dotp
= wp
->w_dotp
;
187 wp
->w_bufp
->b_doto
= wp
->w_doto
;
188 wp
->w_bufp
->b_markp
= wp
->w_markp
;
189 wp
->w_bufp
->b_marko
= wp
->w_marko
;
195 while (i
!=0 && lback(lp
)!=curbp
->b_linep
) {
200 curwp
->w_ntrows
= term
.t_nrow
-1;
202 curwp
->w_flag
|= WFMODE
|WFHARD
;
207 * Split the current window. A window smaller than 3 lines cannot be split.
208 * The only other error that is possible is a "malloc" failure allocating the
209 * structure for the new window. Bound to "C-X 2".
220 register WINDOW
*wp1
;
221 register WINDOW
*wp2
;
223 if (curwp
->w_ntrows
< 3) {
224 mlwrite("Cannot split a %d line window", curwp
->w_ntrows
);
227 if ((wp
= (WINDOW
*) malloc(sizeof(WINDOW
))) == NULL
) {
228 mlwrite("Cannot allocate WINDOW block");
231 ++curbp
->b_nwnd
; /* Displayed twice. */
233 wp
->w_dotp
= curwp
->w_dotp
;
234 wp
->w_doto
= curwp
->w_doto
;
235 wp
->w_markp
= curwp
->w_markp
;
236 wp
->w_marko
= curwp
->w_marko
;
239 ntru
= (curwp
->w_ntrows
-1) / 2; /* Upper size */
240 ntrl
= (curwp
->w_ntrows
-1) - ntru
; /* Lower size */
243 while (lp
!= curwp
->w_dotp
) {
248 if (ntrd
<= ntru
) { /* Old is upper window. */
249 if (ntrd
== ntru
) /* Hit mode line. */
251 curwp
->w_ntrows
= ntru
;
252 wp
->w_wndp
= curwp
->w_wndp
;
254 wp
->w_toprow
= curwp
->w_toprow
+ntru
+1;
256 } else { /* Old is lower window */
259 while (wp2
!= curwp
) {
268 wp
->w_toprow
= curwp
->w_toprow
;
270 ++ntru
; /* Mode line. */
271 curwp
->w_toprow
+= ntru
;
272 curwp
->w_ntrows
= ntrl
;
276 curwp
->w_linep
= lp
; /* Adjust the top lines */
277 wp
->w_linep
= lp
; /* if necessary. */
278 curwp
->w_flag
|= WFMODE
|WFHARD
;
279 wp
->w_flag
|= WFMODE
|WFHARD
;
284 * Enlarge the current window. Find the window that loses space. Make sure it
285 * is big enough. If so, hack the window descriptions, and ask redisplay to do
286 * all the hard work. You don't just set "force reframe" because dot would
287 * move. Bound to "C-X Z".
289 int enlargewind(f
, n
)
293 register WINDOW
*adjwp
;
298 return (shrinkwind(f
, -n
));
299 if (wheadp
->w_wndp
== NULL
) {
300 mlwrite("Only one window");
303 if ((adjwp
=curwp
->w_wndp
) == NULL
) {
305 while (adjwp
->w_wndp
!= curwp
)
306 adjwp
= adjwp
->w_wndp
;
308 if (adjwp
->w_ntrows
<= n
) {
309 mlwrite("Impossible change");
312 if (curwp
->w_wndp
== adjwp
) { /* Shrink below. */
314 for (i
=0; i
<n
&& lp
!=adjwp
->w_bufp
->b_linep
; ++i
)
317 adjwp
->w_toprow
+= n
;
318 } else { /* Shrink above. */
320 for (i
=0; i
<n
&& lback(lp
)!=curbp
->b_linep
; ++i
)
323 curwp
->w_toprow
-= n
;
325 curwp
->w_ntrows
+= n
;
326 adjwp
->w_ntrows
-= n
;
327 curwp
->w_flag
|= WFMODE
|WFHARD
;
328 adjwp
->w_flag
|= WFMODE
|WFHARD
;
333 * Shrink the current window. Find the window that gains space. Hack at the
334 * window descriptions. Ask the redisplay to do all the hard work. Bound to
341 register WINDOW
*adjwp
;
346 return (enlargewind(f
, -n
));
347 if (wheadp
->w_wndp
== NULL
) {
348 mlwrite("Only one window");
351 if ((adjwp
=curwp
->w_wndp
) == NULL
) {
353 while (adjwp
->w_wndp
!= curwp
)
354 adjwp
= adjwp
->w_wndp
;
356 if (curwp
->w_ntrows
<= n
) {
357 mlwrite("Impossible change");
360 if (curwp
->w_wndp
== adjwp
) { /* Grow below. */
362 for (i
=0; i
<n
&& lback(lp
)!=adjwp
->w_bufp
->b_linep
; ++i
)
365 adjwp
->w_toprow
-= n
;
366 } else { /* Grow above. */
368 for (i
=0; i
<n
&& lp
!=curbp
->b_linep
; ++i
)
371 curwp
->w_toprow
+= n
;
373 curwp
->w_ntrows
-= n
;
374 adjwp
->w_ntrows
+= n
;
375 curwp
->w_flag
|= WFMODE
|WFHARD
;
376 adjwp
->w_flag
|= WFMODE
|WFHARD
;
381 * Pick a window for a pop-up. Split the screen if there is only one window.
382 * Pick the uppermost window that isn't the current window. An LRU algorithm
383 * might be better. Return a pointer, or NULL on error.
390 if (wheadp
->w_wndp
== NULL
/* Only 1 window */
391 && splitwind(FALSE
, 0) == FALSE
) /* and it won't split */
393 wp
= wheadp
; /* Find window to use */
394 while (wp
!=NULL
&& wp
==curwp
)