2013-05-18 02:43:13 -04:00
|
|
|
/* window.c -- inplements window.h */
|
|
|
|
#include "window.h"
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
/* Window management. Some of the functions are internal, and some are
|
|
|
|
attached to keys that the user actually types.
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
|
|
|
|
2017-05-27 04:07:56 -04:00
|
|
|
#include <assert.h>
|
2010-11-14 21:10:03 -05:00
|
|
|
|
2013-05-18 20:13:48 -04:00
|
|
|
#include "basic.h"
|
2013-09-20 06:10:30 -04:00
|
|
|
#include "buffer.h"
|
2021-08-18 04:54:35 -04:00
|
|
|
#include "defines.h"
|
2021-08-11 05:02:19 -04:00
|
|
|
#include "display.h" /* upmode() */
|
2013-06-03 23:52:28 -04:00
|
|
|
#include "execute.h"
|
2010-11-14 21:10:03 -05:00
|
|
|
#include "line.h"
|
2021-08-11 05:02:19 -04:00
|
|
|
#include "mlout.h"
|
2013-09-25 09:45:05 -04:00
|
|
|
#include "terminal.h"
|
2010-12-15 20:34:57 -05:00
|
|
|
#include "wrapper.h"
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
window_p curwp ; /* Current window */
|
|
|
|
window_p wheadp ; /* Head of list of windows */
|
2013-09-27 02:16:29 -04:00
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
static window_p savwindow = NULL ; /* saved window pointer */
|
2013-09-27 02:16:29 -04:00
|
|
|
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
/* Reposition dot in the current window to line "n". If the argument is
|
|
|
|
positive, it is that line. If it is negative it is that line from the
|
|
|
|
bottom. If it is 0 the window is centered (this is what the standard
|
|
|
|
redisplay code does). With no argument it defaults to 0. Bound to M-!.
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
TBINDABLE( reposition) {
|
|
|
|
curwp->w_force = (f == FALSE) ? 0 : n ; /* default to 0 to center screen */
|
|
|
|
curwp->w_flag |= WFFORCE ;
|
|
|
|
return TRUE ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Refresh the screen. With no argument, it just does the refresh. With
|
|
|
|
an argument it recenters "." in the current window. Bound to "C-L".
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
TBINDABLE( redraw) {
|
|
|
|
if( f == FALSE)
|
|
|
|
sgarbf = TRUE ;
|
2005-09-30 18:26:09 -04:00
|
|
|
else {
|
2021-08-11 05:02:19 -04:00
|
|
|
curwp->w_force = 0 ; /* Center dot. */
|
|
|
|
curwp->w_flag |= WFFORCE ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
return TRUE ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* The command make the next window (next => down the screen) the current
|
|
|
|
window. There are no real errors, although the command does nothing if
|
|
|
|
there is only 1 window on the screen. Bound to "C-X C-N".
|
|
|
|
|
|
|
|
with an argument this command finds the <n>th window from the top
|
|
|
|
|
|
|
|
int f, n; default flag and numeric argument
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( nextwind) {
|
|
|
|
window_p wp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int nwindows; /* total number of windows */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
if (f) {
|
|
|
|
|
|
|
|
/* first count the # of windows */
|
|
|
|
wp = wheadp;
|
|
|
|
nwindows = 1;
|
|
|
|
while (wp->w_wndp != NULL) {
|
|
|
|
nwindows++;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the argument is negative, it is the nth window
|
2005-09-30 18:26:09 -04:00
|
|
|
from the bottom of the screen */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (n < 0)
|
|
|
|
n = nwindows + n + 1;
|
|
|
|
|
|
|
|
/* if an argument, give them that window from the top */
|
|
|
|
if (n > 0 && n <= nwindows) {
|
|
|
|
wp = wheadp;
|
|
|
|
while (--n)
|
|
|
|
wp = wp->w_wndp;
|
2021-08-11 05:02:19 -04:00
|
|
|
} else
|
|
|
|
return mloutfail( "Window number out of range") ;
|
2005-09-30 18:26:09 -04:00
|
|
|
} else if ((wp = curwp->w_wndp) == NULL)
|
|
|
|
wp = wheadp;
|
2005-05-31 11:50:56 -04:00
|
|
|
curwp = wp;
|
|
|
|
curbp = wp->w_bufp;
|
|
|
|
cknewwindow();
|
|
|
|
upmode();
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* This command makes the previous window (previous => up the screen) the
|
|
|
|
current window. There arn't any errors, although the command does not
|
|
|
|
do a lot if there is 1 window.
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( prevwind) {
|
|
|
|
window_p wp1;
|
|
|
|
window_p wp2;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if we have an argument, we mean the nth window from the bottom */
|
|
|
|
if (f)
|
2010-08-29 06:03:55 -04:00
|
|
|
return nextwind(f, -n);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
wp1 = wheadp;
|
|
|
|
wp2 = curwp;
|
|
|
|
|
|
|
|
if (wp1 == wp2)
|
|
|
|
wp2 = NULL;
|
|
|
|
|
|
|
|
while (wp1->w_wndp != wp2)
|
|
|
|
wp1 = wp1->w_wndp;
|
|
|
|
|
|
|
|
curwp = wp1;
|
|
|
|
curbp = wp1->w_bufp;
|
2005-09-30 18:26:09 -04:00
|
|
|
cknewwindow();
|
2005-05-31 11:50:56 -04:00
|
|
|
upmode();
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* This command moves the current window down by "arg" lines. Recompute the
|
2005-05-31 11:50:56 -04:00
|
|
|
* top line in the window. The move up and move down code is almost completely
|
|
|
|
* the same; most of the work has to do with reframing the window, and picking
|
|
|
|
* a new dot. We share the code by having "move down" just be an interface to
|
|
|
|
* "move up". Magic. Bound to "C-X C-N".
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( mvdnwind) {
|
|
|
|
return mvupwind( f, -n) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Move the current window up by "arg" lines. Recompute the new top line of
|
2005-05-31 11:50:56 -04:00
|
|
|
* the window. Look to see if "." is still on the screen. If it is, you win.
|
|
|
|
* If it isn't, then move "." to center it in the new framing of the window
|
|
|
|
* (this command does not really move "."; it moves the frame). Bound to
|
|
|
|
* "C-X C-P".
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( mvupwind) {
|
|
|
|
line_p lp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
while (n++ && lp != curbp->b_linep)
|
|
|
|
lp = lforw(lp);
|
|
|
|
} else {
|
|
|
|
while (n-- && lback(lp) != curbp->b_linep)
|
|
|
|
lp = lback(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
curwp->w_linep = lp;
|
|
|
|
curwp->w_flag |= WFHARD; /* Mode line is OK. */
|
|
|
|
|
|
|
|
for (i = 0; i < curwp->w_ntrows; ++i) {
|
|
|
|
if (lp == curwp->w_dotp)
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (lp == curbp->b_linep)
|
|
|
|
break;
|
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
i = curwp->w_ntrows / 2;
|
|
|
|
|
|
|
|
while (i-- && lp != curbp->b_linep)
|
|
|
|
lp = lforw(lp);
|
|
|
|
|
|
|
|
curwp->w_dotp = lp;
|
|
|
|
curwp->w_doto = 0;
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* This command makes the current window the only window on the screen. Bound
|
2005-05-31 11:50:56 -04:00
|
|
|
* to "C-X 1". Try to set the framing so that "." does not have to move on the
|
|
|
|
* display. Some care has to be taken to keep the values of dot and mark in
|
|
|
|
* the buffer structures right if the distruction of a window makes a buffer
|
|
|
|
* become undisplayed.
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( onlywind) {
|
|
|
|
window_p wp;
|
|
|
|
line_p lp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
while (wheadp != curwp) {
|
|
|
|
wp = wheadp;
|
|
|
|
wheadp = wp->w_wndp;
|
|
|
|
if (--wp->w_bufp->b_nwnd == 0) {
|
|
|
|
wp->w_bufp->b_dotp = wp->w_dotp;
|
|
|
|
wp->w_bufp->b_doto = wp->w_doto;
|
|
|
|
wp->w_bufp->b_markp = wp->w_markp;
|
|
|
|
wp->w_bufp->b_marko = wp->w_marko;
|
|
|
|
}
|
|
|
|
free((char *) wp);
|
|
|
|
}
|
|
|
|
while (curwp->w_wndp != NULL) {
|
|
|
|
wp = curwp->w_wndp;
|
|
|
|
curwp->w_wndp = wp->w_wndp;
|
|
|
|
if (--wp->w_bufp->b_nwnd == 0) {
|
|
|
|
wp->w_bufp->b_dotp = wp->w_dotp;
|
|
|
|
wp->w_bufp->b_doto = wp->w_doto;
|
|
|
|
wp->w_bufp->b_markp = wp->w_markp;
|
|
|
|
wp->w_bufp->b_marko = wp->w_marko;
|
|
|
|
}
|
|
|
|
free((char *) wp);
|
|
|
|
}
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
i = curwp->w_toprow;
|
|
|
|
while (i != 0 && lback(lp) != curbp->b_linep) {
|
|
|
|
--i;
|
|
|
|
lp = lback(lp);
|
|
|
|
}
|
|
|
|
curwp->w_toprow = 0;
|
|
|
|
curwp->w_ntrows = term.t_nrow - 1;
|
|
|
|
curwp->w_linep = lp;
|
|
|
|
curwp->w_flag |= WFMODE | WFHARD;
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Delete the current window, placing its space in the window above,
|
2005-05-31 11:50:56 -04:00
|
|
|
* or, if it is the top window, the window below. Bound to C-X 0.
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* int f, n; arguments are ignored for this command
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( delwind) {
|
|
|
|
window_p wp; /* window to recieve deleted space */
|
|
|
|
window_p lwp; /* ptr window before curwp */
|
2010-02-27 05:38:22 -05:00
|
|
|
int target; /* target line to search for */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if there is only one window, don't delete it */
|
2021-08-11 05:02:19 -04:00
|
|
|
if( wheadp->w_wndp == NULL)
|
|
|
|
return mloutfail( "Can not delete this window") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* find window before curwp in linked list */
|
|
|
|
wp = wheadp;
|
|
|
|
lwp = NULL;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp == curwp)
|
|
|
|
break;
|
|
|
|
lwp = wp;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find recieving window and give up our space */
|
|
|
|
wp = wheadp;
|
|
|
|
if (curwp->w_toprow == 0) {
|
|
|
|
/* find the next window down */
|
|
|
|
target = curwp->w_ntrows + 1;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_toprow == target)
|
|
|
|
break;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
if (wp == NULL)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_toprow = 0;
|
|
|
|
wp->w_ntrows += target;
|
|
|
|
} else {
|
|
|
|
/* find the next window up */
|
|
|
|
target = curwp->w_toprow - 1;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if ((wp->w_toprow + wp->w_ntrows) == target)
|
|
|
|
break;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
if (wp == NULL)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_ntrows += 1 + curwp->w_ntrows;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get rid of the current window */
|
|
|
|
if (--curwp->w_bufp->b_nwnd == 0) {
|
|
|
|
curwp->w_bufp->b_dotp = curwp->w_dotp;
|
|
|
|
curwp->w_bufp->b_doto = curwp->w_doto;
|
|
|
|
curwp->w_bufp->b_markp = curwp->w_markp;
|
|
|
|
curwp->w_bufp->b_marko = curwp->w_marko;
|
|
|
|
}
|
|
|
|
if (lwp == NULL)
|
|
|
|
wheadp = curwp->w_wndp;
|
|
|
|
else
|
|
|
|
lwp->w_wndp = curwp->w_wndp;
|
2005-09-30 18:26:09 -04:00
|
|
|
free((char *) curwp);
|
2005-05-31 11:50:56 -04:00
|
|
|
curwp = wp;
|
|
|
|
wp->w_flag |= WFHARD;
|
|
|
|
curbp = wp->w_bufp;
|
2005-09-30 18:26:09 -04:00
|
|
|
cknewwindow();
|
2005-05-31 11:50:56 -04:00
|
|
|
upmode();
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Split the current window. A window smaller than 3 lines cannot be
|
2005-09-30 19:34:11 -04:00
|
|
|
* split. An argument of 1 forces the cursor into the upper window, an
|
|
|
|
* argument of two forces the cursor to the lower window. The only
|
|
|
|
* other error that is possible is a "malloc" failure allocating the
|
|
|
|
* structure for the new window. Bound to "C-X 2".
|
|
|
|
*
|
|
|
|
* int f, n; default flag and numeric argument
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( splitwind) {
|
|
|
|
window_p wp;
|
|
|
|
line_p lp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int ntru;
|
|
|
|
int ntrl;
|
|
|
|
int ntrd;
|
2021-08-11 05:02:19 -04:00
|
|
|
window_p wp1;
|
|
|
|
window_p wp2;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
if( curwp->w_ntrows < 3) {
|
|
|
|
mloutfmt( "Cannot split a %d line window", curwp->w_ntrows) ;
|
|
|
|
return FALSE ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
wp = xmalloc( sizeof *wp) ;
|
2005-09-30 18:26:09 -04:00
|
|
|
++curbp->b_nwnd; /* Displayed twice. */
|
|
|
|
wp->w_bufp = curbp;
|
|
|
|
wp->w_dotp = curwp->w_dotp;
|
|
|
|
wp->w_doto = curwp->w_doto;
|
|
|
|
wp->w_markp = curwp->w_markp;
|
|
|
|
wp->w_marko = curwp->w_marko;
|
|
|
|
wp->w_flag = 0;
|
|
|
|
wp->w_force = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
|
|
|
/* set the colors of the new window */
|
|
|
|
wp->w_fcolor = gfcolor;
|
|
|
|
wp->w_bcolor = gbcolor;
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
ntru = (curwp->w_ntrows - 1) / 2; /* Upper size */
|
|
|
|
ntrl = (curwp->w_ntrows - 1) - ntru; /* Lower size */
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
ntrd = 0;
|
|
|
|
while (lp != curwp->w_dotp) {
|
|
|
|
++ntrd;
|
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
if (((f == FALSE) && (ntrd <= ntru)) || ((f == TRUE) && (n == 1))) {
|
|
|
|
/* Old is upper window. */
|
|
|
|
if (ntrd == ntru) /* Hit mode line. */
|
|
|
|
lp = lforw(lp);
|
|
|
|
curwp->w_ntrows = ntru;
|
|
|
|
wp->w_wndp = curwp->w_wndp;
|
|
|
|
curwp->w_wndp = wp;
|
|
|
|
wp->w_toprow = curwp->w_toprow + ntru + 1;
|
|
|
|
wp->w_ntrows = ntrl;
|
|
|
|
} else { /* Old is lower window */
|
|
|
|
wp1 = NULL;
|
|
|
|
wp2 = wheadp;
|
|
|
|
while (wp2 != curwp) {
|
|
|
|
wp1 = wp2;
|
|
|
|
wp2 = wp2->w_wndp;
|
|
|
|
}
|
|
|
|
if (wp1 == NULL)
|
|
|
|
wheadp = wp;
|
|
|
|
else
|
|
|
|
wp1->w_wndp = wp;
|
|
|
|
wp->w_wndp = curwp;
|
|
|
|
wp->w_toprow = curwp->w_toprow;
|
|
|
|
wp->w_ntrows = ntru;
|
|
|
|
++ntru; /* Mode line. */
|
|
|
|
curwp->w_toprow += ntru;
|
|
|
|
curwp->w_ntrows = ntrl;
|
|
|
|
while (ntru--)
|
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
curwp->w_linep = lp; /* Adjust the top lines */
|
|
|
|
wp->w_linep = lp; /* if necessary. */
|
|
|
|
curwp->w_flag |= WFMODE | WFHARD;
|
|
|
|
wp->w_flag |= WFMODE | WFHARD;
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Enlarge the current window. Find the window that loses space. Make sure it
|
2005-05-31 11:50:56 -04:00
|
|
|
* is big enough. If so, hack the window descriptions, and ask redisplay to do
|
|
|
|
* all the hard work. You don't just set "force reframe" because dot would
|
|
|
|
* move. Bound to "C-X Z".
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( enlargewind) {
|
|
|
|
window_p adjwp;
|
|
|
|
line_p lp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
if (n < 0)
|
2010-08-29 06:03:55 -04:00
|
|
|
return shrinkwind(f, -n);
|
2021-08-11 05:02:19 -04:00
|
|
|
if( wheadp->w_wndp == NULL)
|
|
|
|
return mloutfail( "Only one window") ;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((adjwp = curwp->w_wndp) == NULL) {
|
|
|
|
adjwp = wheadp;
|
|
|
|
while (adjwp->w_wndp != curwp)
|
|
|
|
adjwp = adjwp->w_wndp;
|
|
|
|
}
|
2021-08-11 05:02:19 -04:00
|
|
|
if( adjwp->w_ntrows <= n)
|
|
|
|
return mloutfail( "Impossible change") ;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curwp->w_wndp == adjwp) { /* Shrink below. */
|
|
|
|
lp = adjwp->w_linep;
|
|
|
|
for (i = 0; i < n && lp != adjwp->w_bufp->b_linep; ++i)
|
|
|
|
lp = lforw(lp);
|
|
|
|
adjwp->w_linep = lp;
|
|
|
|
adjwp->w_toprow += n;
|
|
|
|
} else { /* Shrink above. */
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
for (i = 0; i < n && lback(lp) != curbp->b_linep; ++i)
|
|
|
|
lp = lback(lp);
|
|
|
|
curwp->w_linep = lp;
|
|
|
|
curwp->w_toprow -= n;
|
|
|
|
}
|
|
|
|
curwp->w_ntrows += n;
|
|
|
|
adjwp->w_ntrows -= n;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
curwp->w_flag |= WFMODE | WFHARD | WFINS;
|
|
|
|
adjwp->w_flag |= WFMODE | WFHARD | WFKILLS;
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
curwp->w_flag |= WFMODE | WFHARD;
|
|
|
|
adjwp->w_flag |= WFMODE | WFHARD;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Shrink the current window. Find the window that gains space. Hack at the
|
2005-05-31 11:50:56 -04:00
|
|
|
* window descriptions. Ask the redisplay to do all the hard work. Bound to
|
|
|
|
* "C-X C-Z".
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( shrinkwind) {
|
|
|
|
window_p adjwp;
|
|
|
|
line_p lp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
if (n < 0)
|
2010-08-29 06:03:55 -04:00
|
|
|
return enlargewind(f, -n);
|
2021-08-11 05:02:19 -04:00
|
|
|
if( wheadp->w_wndp == NULL)
|
|
|
|
return mloutfail( "Only one window") ;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((adjwp = curwp->w_wndp) == NULL) {
|
|
|
|
adjwp = wheadp;
|
|
|
|
while (adjwp->w_wndp != curwp)
|
|
|
|
adjwp = adjwp->w_wndp;
|
|
|
|
}
|
2021-08-11 05:02:19 -04:00
|
|
|
if( curwp->w_ntrows <= n)
|
|
|
|
return mloutfail( "Impossible change") ;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curwp->w_wndp == adjwp) { /* Grow below. */
|
|
|
|
lp = adjwp->w_linep;
|
|
|
|
for (i = 0; i < n && lback(lp) != adjwp->w_bufp->b_linep;
|
|
|
|
++i)
|
|
|
|
lp = lback(lp);
|
|
|
|
adjwp->w_linep = lp;
|
|
|
|
adjwp->w_toprow -= n;
|
|
|
|
} else { /* Grow above. */
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
for (i = 0; i < n && lp != curbp->b_linep; ++i)
|
|
|
|
lp = lforw(lp);
|
|
|
|
curwp->w_linep = lp;
|
|
|
|
curwp->w_toprow += n;
|
|
|
|
}
|
|
|
|
curwp->w_ntrows -= n;
|
|
|
|
adjwp->w_ntrows += n;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
curwp->w_flag |= WFMODE | WFHARD | WFKILLS;
|
|
|
|
adjwp->w_flag |= WFMODE | WFHARD | WFINS;
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
curwp->w_flag |= WFMODE | WFHARD;
|
|
|
|
adjwp->w_flag |= WFMODE | WFHARD;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Resize the current window to the requested size
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* int f, n; default flag and numeric argument
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( resize) {
|
2005-09-30 18:26:09 -04:00
|
|
|
int clines; /* current # of lines in window */
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* must have a non-default argument, else ignore call */
|
|
|
|
if (f == FALSE)
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* find out what to do */
|
|
|
|
clines = curwp->w_ntrows;
|
|
|
|
|
|
|
|
/* already the right size? */
|
|
|
|
if (clines == n)
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2010-08-29 06:03:55 -04:00
|
|
|
return enlargewind(TRUE, n - clines);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* Pick a window for a pop-up. Split the screen if there is only one window.
|
2005-05-31 11:50:56 -04:00
|
|
|
* Pick the uppermost window that isn't the current window. An LRU algorithm
|
|
|
|
* might be better. Return a pointer, or NULL on error.
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
window_p wpopup(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2021-08-11 05:02:19 -04:00
|
|
|
window_p wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (wheadp->w_wndp == NULL /* Only 1 window */
|
|
|
|
&& splitwind(FALSE, 0) == FALSE) /* and it won't split */
|
2010-08-29 06:03:55 -04:00
|
|
|
return NULL;
|
2005-09-30 18:26:09 -04:00
|
|
|
wp = wheadp; /* Find window to use */
|
|
|
|
while (wp != NULL && wp == curwp)
|
|
|
|
wp = wp->w_wndp;
|
2010-08-29 06:03:55 -04:00
|
|
|
return wp;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* scroll the next window up (back) a page */
|
|
|
|
BINDABLE( scrnextup) {
|
2005-05-31 11:50:56 -04:00
|
|
|
nextwind(FALSE, 1);
|
|
|
|
backpage(f, n);
|
|
|
|
prevwind(FALSE, 1);
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* scroll the next window down (forward) a page */
|
|
|
|
BINDABLE( scrnextdw) {
|
2005-05-31 11:50:56 -04:00
|
|
|
nextwind(FALSE, 1);
|
|
|
|
forwpage(f, n);
|
|
|
|
prevwind(FALSE, 1);
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* save ptr to current window */
|
|
|
|
BINDABLE( savewnd) {
|
|
|
|
savwindow = curwp ;
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
/* restore the saved screen */
|
|
|
|
BINDABLE( restwnd) {
|
|
|
|
/* check the saved window still exists */
|
|
|
|
for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
|
|
|
|
if( wp == savwindow) {
|
|
|
|
curwp = wp ;
|
|
|
|
curbp = wp->w_bufp ;
|
|
|
|
upmode() ;
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
return mloutfail( "(No such window exists)") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* resize the screen, re-writing the screen
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* int f; default flag
|
|
|
|
* int n; numeric argument
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( newsize) {
|
|
|
|
window_p wp; /* current window being examined */
|
|
|
|
window_p nextwp; /* next window to scan */
|
|
|
|
window_p lastwp; /* last window scanned */
|
2005-09-30 18:26:09 -04:00
|
|
|
int lastline; /* screen line of last line of current window */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if the command defaults, assume the largest */
|
|
|
|
if (f == FALSE)
|
2015-01-02 04:50:31 -05:00
|
|
|
n = term.t_mrow ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* make sure it's in range */
|
2021-08-11 05:02:19 -04:00
|
|
|
if( n < 3 || n > term.t_mrow)
|
|
|
|
return mloutfail( "%%Screen size out of range") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
if (term.t_nrow == n - 1)
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
else if (term.t_nrow < n - 1) {
|
|
|
|
|
|
|
|
/* go to the last window */
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp->w_wndp != NULL)
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
|
|
|
|
/* and enlarge it as needed */
|
|
|
|
wp->w_ntrows = n - wp->w_toprow - 2;
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_flag |= WFHARD | WFMODE;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* rebuild the window structure */
|
2017-05-27 04:07:56 -04:00
|
|
|
assert( wheadp->w_toprow == 0) ; /* proves coverity wrong */
|
2005-05-31 11:50:56 -04:00
|
|
|
nextwp = wheadp;
|
|
|
|
wp = NULL;
|
|
|
|
lastwp = NULL;
|
|
|
|
while (nextwp != NULL) {
|
|
|
|
wp = nextwp;
|
|
|
|
nextwp = wp->w_wndp;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* get rid of it if it is too low */
|
|
|
|
if (wp->w_toprow > n - 2) {
|
|
|
|
|
|
|
|
/* save the point/mark if needed */
|
|
|
|
if (--wp->w_bufp->b_nwnd == 0) {
|
|
|
|
wp->w_bufp->b_dotp = wp->w_dotp;
|
|
|
|
wp->w_bufp->b_doto = wp->w_doto;
|
|
|
|
wp->w_bufp->b_markp = wp->w_markp;
|
|
|
|
wp->w_bufp->b_marko = wp->w_marko;
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* update curwp and lastwp if needed */
|
|
|
|
if (wp == curwp)
|
|
|
|
curwp = wheadp;
|
2005-09-30 18:26:09 -04:00
|
|
|
curbp = curwp->w_bufp;
|
2005-05-31 11:50:56 -04:00
|
|
|
if (lastwp != NULL)
|
|
|
|
lastwp->w_wndp = NULL;
|
|
|
|
|
|
|
|
/* free the structure */
|
2005-09-30 18:26:09 -04:00
|
|
|
free((char *) wp);
|
2005-05-31 11:50:56 -04:00
|
|
|
wp = NULL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* need to change this window size? */
|
|
|
|
lastline = wp->w_toprow + wp->w_ntrows - 1;
|
|
|
|
if (lastline >= n - 2) {
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_ntrows =
|
|
|
|
n - wp->w_toprow - 2;
|
|
|
|
wp->w_flag |= WFHARD | WFMODE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastwp = wp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* screen is garbage */
|
|
|
|
term.t_nrow = n - 1;
|
|
|
|
sgarbf = TRUE;
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* resize the screen, re-writing the screen
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* int f; default flag
|
|
|
|
* int n; numeric argument
|
|
|
|
*/
|
2021-08-11 05:02:19 -04:00
|
|
|
BINDABLE( newwidth) {
|
|
|
|
window_p wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if the command defaults, assume the largest */
|
|
|
|
if (f == FALSE)
|
|
|
|
n = term.t_mcol;
|
|
|
|
|
|
|
|
/* make sure it's in range */
|
2021-08-11 05:02:19 -04:00
|
|
|
if (n < 10 || n > term.t_mcol)
|
|
|
|
return mloutfail( "%%Screen width out of range") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* otherwise, just re-width it (no big deal) */
|
|
|
|
term.t_ncol = n;
|
|
|
|
term.t_margin = n / 10;
|
|
|
|
term.t_scrsiz = n - (term.t_margin * 2);
|
|
|
|
|
|
|
|
/* florce all windows to redraw */
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp) {
|
|
|
|
wp->w_flag |= WFHARD | WFMOVE | WFMODE;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
sgarbf = TRUE;
|
|
|
|
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
int getwpos(void)
|
2005-09-30 18:26:09 -04:00
|
|
|
{ /* get screen offset of current line in current window */
|
2010-02-27 05:38:22 -05:00
|
|
|
int sline; /* screen line from top of window */
|
2021-08-11 05:02:19 -04:00
|
|
|
line_p lp; /* scannile line pointer */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* search down the line we want */
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
sline = 1;
|
|
|
|
while (lp != curwp->w_dotp) {
|
|
|
|
++sline;
|
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and return the value */
|
2010-08-29 06:03:55 -04:00
|
|
|
return sline;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
void cknewwindow(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
execute(META | SPEC | 'X', FALSE, 1);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2021-08-11 05:02:19 -04:00
|
|
|
|
|
|
|
/* end of window.c */
|