screen.c
资源名称:vim53src.zip [点击查看]
上传用户:gddssl
上传日期:2007-01-06
资源大小:1003k
文件大小:133k
源码类别:
编辑器/阅读器
开发平台:
DOS
- /*
- * If the cursor is below the bottom of the window, scroll the window
- * to put the cursor on the window. If the cursor is less than a
- * windowheight down compute the number of lines at the top which have
- * the same or more rows than the rows of the lines below the bottom.
- * When w_botline is invalid, recompute it first, to avoid a redraw later.
- * If w_botline was approximated, we might need a redraw later in a few
- * cases, but we don't want to spend (a lot of) time recomputing w_botline
- * for every small change.
- */
- else
- {
- if (!(curwin->w_valid & VALID_BOTLINE_AP))
- validate_botline();
- if ((long)curwin->w_cursor.lnum >= (long)curwin->w_botline - p_so &&
- curwin->w_botline <= curbuf->b_ml.ml_line_count)
- {
- line_count = curwin->w_cursor.lnum - curwin->w_botline + 1 + p_so;
- if (line_count <= curwin->w_height + 1)
- scroll_cursor_bot((int)p_sj, FALSE);
- else
- scroll_cursor_halfway(FALSE);
- }
- }
- /*
- * Need to redraw when topline changed.
- */
- if (curwin->w_topline != old_topline)
- {
- if (curwin->w_skipcol)
- {
- curwin->w_skipcol = 0;
- redraw_later(NOT_VALID);
- }
- else
- redraw_later(VALID);
- }
- }
- void
- update_curswant()
- {
- if (curwin->w_set_curswant)
- {
- validate_virtcol();
- curwin->w_curswant = curwin->w_virtcol;
- curwin->w_set_curswant = FALSE;
- }
- }
- void
- windgoto(row, col)
- int row;
- int col;
- {
- char_u *p;
- int i;
- int plan;
- int cost;
- int wouldbe_col;
- int noinvcurs;
- char_u *bs;
- int goto_cost;
- int attr;
- #define GOTO_COST 7 /* asssume a term_windgoto() takes about 7 chars */
- #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */
- #define PLAN_LE 1
- #define PLAN_CR 2
- #define PLAN_NL 3
- #define PLAN_WRITE 4
- /* Can't use LinePointers[] unless initialized */
- if (NextScreen == NULL)
- return;
- if (row < 0) /* window without text lines? */
- row = 0;
- if (col != screen_cur_col || row != screen_cur_row)
- {
- /* check if no cursor movement is allowed in highlight mode */
- if (screen_attr && *T_MS == NUL)
- noinvcurs = HIGHL_COST;
- else
- noinvcurs = 0;
- goto_cost = GOTO_COST + noinvcurs;
- /*
- * Plan how to do the positioning:
- * 1. Use CR to move it to column 0, same row.
- * 2. Use T_LE to move it a few columns to the left.
- * 3. Use NL to move a few lines down, column 0.
- * 4. Move a few columns to the right with T_ND or by writing chars.
- *
- * Don't do this if the cursor went beyond the last column, the cursor
- * position is unknown then (some terminals wrap, some don't )
- *
- * First check if the highlighting attibutes allow us to write
- * characters to move the cursor to the right.
- */
- if (row >= screen_cur_row && screen_cur_col < Columns)
- {
- /*
- * If the cursor is in the same row, bigger col, we can use CR
- * or T_LE.
- */
- bs = NULL; /* init for GCC */
- attr = screen_attr;
- if (row == screen_cur_row && col < screen_cur_col)
- {
- /* "le" is preferred over "bc", because "bc" is obsolete */
- if (*T_LE)
- bs = T_LE; /* "cursor left" */
- else
- bs = T_BC; /* "backspace character (old) */
- if (*bs)
- cost = (screen_cur_col - col) * STRLEN(bs);
- else
- cost = 999;
- if (col + 1 < cost) /* using CR is less characters */
- {
- plan = PLAN_CR;
- wouldbe_col = 0;
- cost = 1; /* CR is just one character */
- }
- else
- {
- plan = PLAN_LE;
- wouldbe_col = col;
- }
- if (noinvcurs) /* will stop highlighting */
- {
- cost += noinvcurs;
- attr = 0;
- }
- }
- /*
- * If the cursor is above where we want to be, we can use CR LF.
- */
- else if (row > screen_cur_row)
- {
- plan = PLAN_NL;
- wouldbe_col = 0;
- cost = (row - screen_cur_row) * 2; /* CR LF */
- if (noinvcurs) /* will stop highlighting */
- {
- cost += noinvcurs;
- attr = 0;
- }
- }
- /*
- * If the cursor is in the same row, smaller col, just use write.
- */
- else
- {
- plan = PLAN_WRITE;
- wouldbe_col = screen_cur_col;
- cost = 0;
- }
- /*
- * Check if any characters that need to be written have the
- * correct attributes.
- */
- i = col - wouldbe_col;
- if (i > 0)
- cost += i;
- if (cost < goto_cost && i > 0)
- {
- /*
- * Check if the attributes are correct without additionally
- * stopping highlighting.
- */
- p = LinePointers[row] + wouldbe_col + Columns;
- while (i && *p++ == attr)
- --i;
- if (i)
- {
- /*
- * Try if it works when highlighting is stopped here.
- */
- if (*--p == 0)
- {
- cost += noinvcurs;
- while (i && *p++ == 0)
- --i;
- }
- if (i)
- cost = 999; /* different attributes, don't do it */
- }
- }
- /*
- * We can do it without term_windgoto()!
- */
- if (cost < goto_cost)
- {
- if (plan == PLAN_LE)
- {
- if (noinvcurs)
- screen_stop_highlight();
- while (screen_cur_col > col)
- {
- out_str(bs);
- --screen_cur_col;
- }
- }
- else if (plan == PLAN_CR)
- {
- if (noinvcurs)
- screen_stop_highlight();
- out_char('r');
- screen_cur_col = 0;
- }
- else if (plan == PLAN_NL)
- {
- if (noinvcurs)
- screen_stop_highlight();
- while (screen_cur_row < row)
- {
- out_char('n');
- ++screen_cur_row;
- }
- screen_cur_col = 0;
- }
- i = col - screen_cur_col;
- if (i > 0)
- {
- /*
- * Use cursor-right if it's one character only. Avoids
- * removing a line of pixels from the last bold char, when
- * using the bold trick in the GUI.
- */
- if (T_ND[0] != NUL && T_ND[1] == NUL)
- {
- while (i--)
- out_char(*T_ND);
- }
- else
- {
- p = LinePointers[row] + screen_cur_col;
- while (i--)
- {
- if (*(p + Columns) != screen_attr)
- screen_stop_highlight();
- out_char(*p++);
- }
- }
- }
- }
- }
- else
- cost = 999;
- if (cost >= goto_cost)
- {
- if (noinvcurs)
- screen_stop_highlight();
- if (row == screen_cur_row && (col > screen_cur_col) &&
- *T_CRI != NUL)
- term_cursor_right(col - screen_cur_col);
- else
- term_windgoto(row, col);
- }
- screen_cur_row = row;
- screen_cur_col = col;
- }
- }
- /*
- * Set cursor to current position.
- */
- void
- setcursor()
- {
- if (redrawing())
- {
- validate_cursor();
- windgoto(curwin->w_winpos + curwin->w_wrow,
- #ifdef RIGHTLEFT
- curwin->w_p_rl ? ((int)Columns - 1 - curwin->w_wcol) :
- #endif
- curwin->w_wcol);
- }
- }
- /*
- * Recompute topline to put the cursor at the top of the window.
- * Scroll at least "min_scroll" lines.
- * If "always" is TRUE, always set topline (for "zt").
- */
- void
- scroll_cursor_top(min_scroll, always)
- int min_scroll;
- int always;
- {
- int scrolled = 0;
- int extra = 0;
- int used;
- int i;
- int sline; /* screen line for cursor */
- int old_topline = curwin->w_topline;
- /*
- * Decrease topline until:
- * - it has become 1
- * - (part of) the cursor line is moved off the screen or
- * - moved at least 'scrolljump' lines and
- * - at least 'scrolloff' lines above and below the cursor
- */
- validate_cheight();
- used = curwin->w_cline_height;
- for (sline = 1; sline < curwin->w_cursor.lnum; ++sline)
- {
- i = plines(curwin->w_cursor.lnum - sline);
- used += i;
- extra += i;
- if (extra <= p_so &&
- curwin->w_cursor.lnum + sline < curbuf->b_ml.ml_line_count)
- used += plines(curwin->w_cursor.lnum + sline);
- if (used > curwin->w_height)
- break;
- if (curwin->w_cursor.lnum - sline < curwin->w_topline)
- scrolled += i;
- /*
- * If scrolling is needed, scroll at least 'sj' lines.
- */
- if ((curwin->w_cursor.lnum - (sline - 1) >= curwin->w_topline ||
- scrolled >= min_scroll) && extra > p_so)
- break;
- }
- /*
- * If we don't have enough space, put cursor in the middle.
- * This makes sure we get the same position when using "k" and "j"
- * in a small window.
- */
- if (used > curwin->w_height)
- scroll_cursor_halfway(FALSE);
- else
- {
- /*
- * If "always" is FALSE, only adjust topline to a lower value, higher
- * value may happen with wrapping lines
- */
- if (curwin->w_cursor.lnum - (sline - 1) < curwin->w_topline || always)
- curwin->w_topline = curwin->w_cursor.lnum - (sline - 1);
- if (curwin->w_topline > curwin->w_cursor.lnum)
- curwin->w_topline = curwin->w_cursor.lnum;
- if (curwin->w_topline != old_topline)
- curwin->w_valid &=
- ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
- }
- }
- /*
- * Recompute topline to put the cursor at the bottom of the window.
- * Scroll at least "min_scroll" lines.
- * If "set_topbot" is TRUE, set topline and botline first (for "zb").
- * This is messy stuff!!!
- */
- void
- scroll_cursor_bot(min_scroll, set_topbot)
- int min_scroll;
- int set_topbot;
- {
- int used;
- int scrolled = 0;
- int extra = 0;
- int sline; /* screen line for cursor from bottom */
- int i;
- linenr_t lnum;
- linenr_t line_count;
- linenr_t old_topline = curwin->w_topline;
- linenr_t old_botline = curwin->w_botline;
- linenr_t old_valid = curwin->w_valid;
- int old_empty_rows = curwin->w_empty_rows;
- linenr_t cln; /* Cursor Line Number */
- cln = curwin->w_cursor.lnum;
- if (set_topbot)
- {
- used = 0;
- curwin->w_botline = cln + 1;
- for (curwin->w_topline = curwin->w_botline;
- curwin->w_topline != 1;
- --curwin->w_topline)
- {
- i = plines(curwin->w_topline - 1);
- if (used + i > curwin->w_height)
- break;
- used += i;
- }
- curwin->w_empty_rows = curwin->w_height - used;
- curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
- if (curwin->w_topline != old_topline)
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
- }
- else
- validate_botline();
- validate_cheight();
- used = curwin->w_cline_height;
- if (cln >= curwin->w_botline)
- {
- scrolled = used;
- if (cln == curwin->w_botline)
- scrolled -= curwin->w_empty_rows;
- }
- /*
- * Stop counting lines to scroll when
- * - hitting start of the file
- * - scrolled nothing or at least 'sj' lines
- * - at least 'so' lines below the cursor
- * - lines between botline and cursor have been counted
- */
- for (sline = 1; sline < cln; ++sline)
- {
- if ((((scrolled <= 0 || scrolled >= min_scroll) && extra >= p_so) ||
- cln + sline > curbuf->b_ml.ml_line_count) &&
- cln - sline < curwin->w_botline)
- break;
- i = plines(cln - sline);
- used += i;
- if (used > curwin->w_height)
- break;
- if (cln - sline >= curwin->w_botline)
- {
- scrolled += i;
- if (cln - sline == curwin->w_botline)
- scrolled -= curwin->w_empty_rows;
- }
- if (cln + sline <= curbuf->b_ml.ml_line_count)
- {
- i = plines(cln + sline);
- used += i;
- if (used > curwin->w_height)
- break;
- if (extra < p_so || scrolled < min_scroll)
- {
- extra += i;
- if (cln + sline >= curwin->w_botline)
- {
- scrolled += i;
- if (cln + sline == curwin->w_botline)
- scrolled -= curwin->w_empty_rows;
- }
- }
- }
- }
- /* curwin->w_empty_rows is larger, no need to scroll */
- if (scrolled <= 0)
- line_count = 0;
- /* more than a screenfull, don't scroll but redraw */
- else if (used > curwin->w_height)
- line_count = used;
- /* scroll minimal number of lines */
- else
- {
- for (i = 0, lnum = curwin->w_topline;
- i < scrolled && lnum < curwin->w_botline; ++lnum)
- i += plines(lnum);
- if (i >= scrolled) /* it's possible to scroll */
- line_count = lnum - curwin->w_topline;
- else /* below curwin->w_botline, don't scroll */
- line_count = 9999;
- }
- /*
- * Scroll up if the cursor is off the bottom of the screen a bit.
- * Otherwise put it at 1/2 of the screen.
- */
- if (line_count >= curwin->w_height && line_count > min_scroll)
- scroll_cursor_halfway(FALSE);
- else
- scrollup(line_count);
- /*
- * If topline didn't change we need to restore w_botline and w_empty_rows
- * (we changed them).
- * If topline did change, update_screen() will set botline.
- */
- if (curwin->w_topline == old_topline && set_topbot)
- {
- curwin->w_botline = old_botline;
- curwin->w_empty_rows = old_empty_rows;
- curwin->w_valid = old_valid;
- }
- }
- /*
- * Recompute topline to put the cursor halfway the window
- * If "atend" is TRUE, also put it halfway at the end of the file.
- */
- void
- scroll_cursor_halfway(atend)
- int atend;
- {
- int above = 0;
- linenr_t topline;
- int below = 0;
- linenr_t botline;
- int used;
- int i;
- linenr_t cln; /* Cursor Line Number */
- topline = botline = cln = curwin->w_cursor.lnum;
- used = plines(cln);
- while (topline > 1)
- {
- if (below <= above) /* add a line below the cursor */
- {
- if (botline + 1 <= curbuf->b_ml.ml_line_count)
- {
- i = plines(botline + 1);
- used += i;
- if (used > curwin->w_height)
- break;
- below += i;
- ++botline;
- }
- else
- {
- ++below; /* count a "~" line */
- if (atend)
- ++used;
- }
- }
- if (below > above) /* add a line above the cursor */
- {
- i = plines(topline - 1);
- used += i;
- if (used > curwin->w_height)
- break;
- above += i;
- --topline;
- }
- }
- curwin->w_topline = topline;
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
- }
- /*
- * Correct the cursor position so that it is in a part of the screen at least
- * 'so' lines from the top and bottom, if possible.
- * If not possible, put it at the same position as scroll_cursor_halfway().
- * When called topline must be valid!
- */
- void
- cursor_correct()
- {
- int above = 0; /* screen lines above topline */
- linenr_t topline;
- int below = 0; /* screen lines below botline */
- linenr_t botline;
- int above_wanted, below_wanted;
- linenr_t cln; /* Cursor Line Number */
- int max_off;
- /*
- * How many lines we would like to have above/below the cursor depends on
- * whether the first/last line of the file is on screen.
- */
- above_wanted = p_so;
- below_wanted = p_so;
- if (curwin->w_topline == 1)
- {
- above_wanted = 0;
- max_off = curwin->w_height / 2;
- if (below_wanted > max_off)
- below_wanted = max_off;
- }
- validate_botline();
- if (curwin->w_botline == curbuf->b_ml.ml_line_count + 1)
- {
- below_wanted = 0;
- max_off = (curwin->w_height - 1) / 2;
- if (above_wanted > max_off)
- above_wanted = max_off;
- }
- /*
- * If there are sufficient file-lines above and below the cursor, we can
- * return now.
- */
- cln = curwin->w_cursor.lnum;
- if (cln >= curwin->w_topline + above_wanted &&
- cln < curwin->w_botline - below_wanted)
- return;
- /*
- * Narrow down the area where the cursor can be put by taking lines from
- * the top and the bottom until:
- * - the desired context lines are found
- * - the lines from the top is past the lines from the bottom
- */
- topline = curwin->w_topline;
- botline = curwin->w_botline - 1;
- while ((above < above_wanted || below < below_wanted) && topline < botline)
- {
- if (below < below_wanted && (below <= above || above >= above_wanted))
- {
- below += plines(botline);
- --botline;
- }
- if (above < above_wanted && (above < below || below >= below_wanted))
- {
- above += plines(topline);
- ++topline;
- }
- }
- if (topline == botline || botline == 0)
- curwin->w_cursor.lnum = topline;
- else if (topline > botline)
- curwin->w_cursor.lnum = botline;
- else
- {
- if (cln < topline && curwin->w_topline > 1)
- {
- curwin->w_cursor.lnum = topline;
- curwin->w_valid &=
- ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW);
- }
- if (cln > botline && curwin->w_botline <= curbuf->b_ml.ml_line_count)
- {
- curwin->w_cursor.lnum = botline;
- curwin->w_valid &=
- ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW);
- }
- }
- }
- /*
- * Check if the cursor has moved. Set the w_valid flag accordingly.
- */
- static void
- check_cursor_moved(wp)
- WIN *wp;
- {
- if (wp->w_cursor.lnum != wp->w_valid_cursor.lnum)
- {
- wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL
- |VALID_CHEIGHT|VALID_CROW);
- wp->w_valid_cursor = wp->w_cursor;
- wp->w_valid_leftcol = wp->w_leftcol;
- }
- else if (wp->w_cursor.col != wp->w_valid_cursor.col
- || wp->w_leftcol != wp->w_valid_leftcol)
- {
- wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
- wp->w_valid_cursor.col = wp->w_cursor.col;
- wp->w_valid_leftcol = wp->w_leftcol;
- }
- }
- /*
- * Call this function when the length of the cursor line (in screen
- * characters) has changed, and the change is before the cursor.
- * Need to take care of w_botline separately!
- */
- void
- changed_cline_bef_curs()
- {
- curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CHEIGHT);
- }
- /*
- * Call this function when the length of the cursor line (in screen
- * characters) has changed, and the position of the cursor doesn't change.
- * Need to take care of w_botline separately!
- */
- void
- changed_cline_aft_curs()
- {
- curwin->w_valid &= ~VALID_CHEIGHT;
- }
- /*
- * Call this function when the length of a line (in screen characters) above
- * the cursor have changed.
- * Need to take care of w_botline separately!
- */
- void
- changed_line_abv_curs()
- {
- curwin->w_valid &=
- ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW|VALID_CHEIGHT);
- }
- /*
- * Set wp->w_topline to a certain number.
- */
- void
- set_topline(wp, lnum)
- WIN *wp;
- linenr_t lnum;
- {
- /* Approximate the value of w_botline */
- wp->w_botline += lnum - wp->w_topline;
- wp->w_topline = lnum;
- wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
- }
- /*
- * Make sure the value of curwin->w_botline is valid.
- */
- void
- validate_botline()
- {
- if (!(curwin->w_valid & VALID_BOTLINE))
- comp_botline();
- }
- /*
- * Mark curwin->w_botline as invalid (because of some change in the buffer).
- */
- void
- invalidate_botline()
- {
- curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
- }
- void
- invalidate_botline_win(wp)
- WIN *wp;
- {
- wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
- }
- /*
- * Mark curwin->w_botline as approximated (because of some small change in the
- * buffer).
- */
- void
- approximate_botline()
- {
- curwin->w_valid &= ~VALID_BOTLINE;
- }
- /*
- * Return TRUE if curwin->w_botline is valid.
- */
- int
- botline_valid()
- {
- return (curwin->w_valid & VALID_BOTLINE);
- }
- /*
- * Return TRUE if curwin->w_botline is valid or approximated.
- */
- int
- botline_approximated()
- {
- return (curwin->w_valid & VALID_BOTLINE_AP);
- }
- /*
- * Return TRUE if curwin->w_wrow and curwin->w_wcol are valid.
- */
- int
- cursor_valid()
- {
- check_cursor_moved(curwin);
- return ((curwin->w_valid & (VALID_WROW|VALID_WCOL)) ==
- (VALID_WROW|VALID_WCOL));
- }
- /*
- * Validate cursor position. Makes sure w_wrow and w_wcol are valid.
- * w_topline must be valid, you may need to call update_topline() first!
- */
- void
- validate_cursor()
- {
- check_cursor_moved(curwin);
- if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW))
- curs_columns(TRUE);
- }
- /*
- * validate w_cline_row.
- */
- void
- validate_cline_row()
- {
- /*
- * First make sure that w_topline is valid (after moving the cursor).
- */
- update_topline();
- check_cursor_moved(curwin);
- if (!(curwin->w_valid & VALID_CROW))
- curs_rows(FALSE);
- }
- /*
- * Check if w_cline_row and w_cline_height are valid, or can be made valid.
- * Can be called when topline and botline have not been updated.
- * Used to decide to redraw or keep the window update.
- *
- * Return OK if w_cline_row is valid.
- */
- int
- may_validate_crow()
- {
- if (curwin->w_cursor.lnum < curwin->w_topline ||
- curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count ||
- !(curwin->w_valid & (VALID_BOTLINE|VALID_BOTLINE_AP)) ||
- curwin->w_cursor.lnum >= curwin->w_botline)
- return FAIL;
- check_cursor_moved(curwin);
- if ((curwin->w_valid & (VALID_CROW|VALID_CHEIGHT)) !=
- (VALID_CROW|VALID_CHEIGHT))
- curs_rows(TRUE);
- return OK;
- }
- /*
- * Compute curwin->w_cline_row and curwin->w_cline_height.
- * Must only be called when w_topine is valid!
- *
- * Returns OK when cursor is in the window, FAIL when it isn't.
- */
- static void
- curs_rows(do_botline)
- int do_botline; /* also compute w_botline */
- {
- linenr_t lnum;
- int i;
- int lsize_invalid;
- /* Check if curwin->w_lsize[] is invalid */
- lsize_invalid = (!redrawing() || curwin->w_lsize_valid == 0 ||
- curwin->w_lsize_lnum[0] != curwin->w_topline);
- i = 0;
- curwin->w_cline_row = 0;
- for (lnum = curwin->w_topline; lnum < curwin->w_cursor.lnum; ++lnum)
- if (lsize_invalid)
- curwin->w_cline_row += plines(lnum);
- else
- curwin->w_cline_row += curwin->w_lsize[i++];
- check_cursor_moved(curwin);
- if (!(curwin->w_valid & VALID_CHEIGHT))
- {
- if (lsize_invalid)
- curwin->w_cline_height = plines(lnum);
- /* Check for a line that is too long to fit on the last screen line. */
- else if (i > curwin->w_lsize_valid)
- curwin->w_cline_height = 0;
- else
- curwin->w_cline_height = curwin->w_lsize[i];
- }
- curwin->w_valid |= VALID_CROW|VALID_CHEIGHT;
- /* validate botline too, if update_screen doesn't do it */
- if (do_botline && lsize_invalid)
- validate_botline();
- }
- /*
- * Validate curwin->w_virtcol only.
- */
- void
- validate_virtcol()
- {
- validate_virtcol_win(curwin);
- }
- /*
- * Validate wp->w_virtcol only.
- */
- static void
- validate_virtcol_win(wp)
- WIN *wp;
- {
- check_cursor_moved(wp);
- if (!(wp->w_valid & VALID_VIRTCOL))
- {
- getvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
- wp->w_valid |= VALID_VIRTCOL;
- }
- }
- /*
- * Validate curwin->w_cline_height only.
- */
- void
- validate_cheight()
- {
- check_cursor_moved(curwin);
- if (!(curwin->w_valid & VALID_CHEIGHT))
- {
- curwin->w_cline_height = plines(curwin->w_cursor.lnum);
- curwin->w_valid |= VALID_CHEIGHT;
- }
- }
- /*
- * validate w_wcol and w_virtcol only. Only for when 'wrap' on!
- */
- void
- validate_cursor_col()
- {
- validate_virtcol();
- if (!(curwin->w_valid & VALID_WCOL))
- {
- curwin->w_wcol = curwin->w_virtcol;
- if (curwin->w_p_nu)
- curwin->w_wcol += 8;
- /* long line wrapping, adjust curwin->w_wrow */
- if (curwin->w_p_wrap && curwin->w_wcol >= Columns)
- curwin->w_wcol = curwin->w_wcol % Columns;
- curwin->w_valid |= VALID_WCOL;
- }
- }
- /*
- * compute curwin->w_wcol and curwin->w_virtcol.
- * Also updates curwin->w_wrow and curwin->w_cline_row.
- */
- void
- curs_columns(scroll)
- int scroll; /* when TRUE, may scroll horizontally */
- {
- int diff;
- int extra;
- int new_leftcol;
- colnr_t startcol;
- colnr_t endcol;
- colnr_t prev_skipcol;
- /*
- * First make sure that w_topline is valid (after moving the cursor).
- */
- update_topline();
- /*
- * Next make sure that w_cline_row is valid.
- */
- if (!(curwin->w_valid & VALID_CROW))
- curs_rows(FALSE);
- /*
- * Compute the number of virtual columns.
- */
- getvcol(curwin, &curwin->w_cursor,
- &startcol, &(curwin->w_virtcol), &endcol);
- /* remove '$' from change command when cursor moves onto it */
- if (startcol > dollar_vcol)
- dollar_vcol = 0;
- curwin->w_wcol = curwin->w_virtcol;
- if (curwin->w_p_nu)
- {
- curwin->w_wcol += 8;
- endcol += 8;
- }
- /*
- * Now compute w_wrow, counting screen lines from w_cline_row.
- */
- curwin->w_wrow = curwin->w_cline_row;
- if (curwin->w_p_wrap) /* long line wrapping, adjust curwin->w_wrow */
- {
- while (curwin->w_wcol >= Columns)
- {
- curwin->w_wcol -= Columns;
- curwin->w_wrow++;
- }
- }
- else if (scroll) /* no line wrapping, compute curwin->w_leftcol if
- * scrolling is on. If scrolling is off,
- * curwin->w_leftcol is assumed to be 0 */
- {
- /* If Cursor is left of the screen, scroll rightwards */
- /* If Cursor is right of the screen, scroll leftwards */
- if ((extra = (int)startcol - (int)curwin->w_leftcol) < 0 ||
- (extra = (int)endcol - (int)(curwin->w_leftcol + Columns) + 1) > 0)
- {
- if (extra < 0)
- diff = -extra;
- else
- diff = extra;
- /* far off, put cursor in middle of window */
- if (p_ss == 0 || diff >= Columns / 2)
- new_leftcol = curwin->w_wcol - Columns / 2;
- else
- {
- if (diff < p_ss)
- diff = p_ss;
- if (extra < 0)
- new_leftcol = curwin->w_leftcol - diff;
- else
- new_leftcol = curwin->w_leftcol + diff;
- }
- if (new_leftcol < 0)
- curwin->w_leftcol = 0;
- else
- curwin->w_leftcol = new_leftcol;
- /* screen has to be redrawn with new curwin->w_leftcol */
- redraw_later(NOT_VALID);
- }
- curwin->w_wcol -= curwin->w_leftcol;
- }
- else if (curwin->w_wcol > (int)curwin->w_leftcol)
- curwin->w_wcol -= curwin->w_leftcol;
- else
- curwin->w_wcol = 0;
- prev_skipcol = curwin->w_skipcol;
- if ((curwin->w_wrow > curwin->w_height - 1 || prev_skipcol)
- && curwin->w_height
- && curwin->w_cursor.lnum == curwin->w_topline)
- {
- /* Cursor past end of screen. Happens with a single line that does
- * not fit on screen. Find a skipcol to show the text around the
- * cursor. Avoid scrolling all the time. */
- if (curwin->w_skipcol > curwin->w_virtcol)
- {
- extra = (curwin->w_skipcol - curwin->w_virtcol + Columns - 1)
- / Columns;
- win_ins_lines(curwin, 0, extra, FALSE, FALSE);
- curwin->w_skipcol -= extra * Columns;
- }
- else if (curwin->w_wrow > curwin->w_height - 1)
- {
- endcol = (curwin->w_wrow - curwin->w_height + 1) * Columns;
- if (endcol > curwin->w_skipcol)
- {
- win_del_lines(curwin, 0,
- (endcol - prev_skipcol) / (int)Columns, FALSE, FALSE);
- curwin->w_skipcol = endcol;
- }
- }
- curwin->w_wrow -= curwin->w_skipcol / Columns;
- }
- else
- curwin->w_skipcol = 0;
- if (prev_skipcol != curwin->w_skipcol)
- redraw_later(NOT_VALID);
- curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
- }
- /*
- * Scroll up 'line_count' lines.
- */
- void
- scrolldown(line_count)
- long line_count;
- {
- long done = 0; /* total # of physical lines done */
- int wrow;
- int moved = FALSE;
- validate_cursor(); /* w_wrow needs to be valid */
- while (line_count--)
- {
- if (curwin->w_topline == 1)
- break;
- done += plines(--curwin->w_topline);
- --curwin->w_botline; /* approximate w_botline */
- curwin->w_valid &= ~VALID_BOTLINE;
- }
- curwin->w_wrow += done; /* keep w_wrow updated */
- curwin->w_cline_row += done; /* keep w_cline_row updated */
- /*
- * Compute the row number of the last row of the cursor line
- * and move it onto the screen.
- */
- wrow = curwin->w_wrow;
- if (curwin->w_p_wrap)
- {
- validate_virtcol();
- validate_cheight();
- wrow += curwin->w_cline_height - 1 - curwin->w_virtcol / Columns;
- }
- while (wrow >= curwin->w_height && curwin->w_cursor.lnum > 1)
- {
- wrow -= plines(curwin->w_cursor.lnum--);
- curwin->w_valid &=
- ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
- moved = TRUE;
- }
- if (moved)
- coladvance(curwin->w_curswant);
- }
- void
- scrollup(line_count)
- long line_count;
- {
- curwin->w_topline += line_count;
- curwin->w_botline += line_count; /* approximate w_botline */
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
- if (curwin->w_topline > curbuf->b_ml.ml_line_count)
- curwin->w_topline = curbuf->b_ml.ml_line_count;
- if (curwin->w_cursor.lnum < curwin->w_topline)
- {
- curwin->w_cursor.lnum = curwin->w_topline;
- curwin->w_valid &=
- ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
- coladvance(curwin->w_curswant);
- }
- }
- /*
- * Scroll the screen one line down, but don't do it if it would move the
- * cursor off the screen.
- */
- void
- scrolldown_clamp()
- {
- int end_row;
- if (curwin->w_topline == 1)
- return;
- validate_cursor(); /* w_wrow needs to be valid */
- /*
- * Compute the row number of the last row of the cursor line
- * and make sure it doesn't go off the screen. Make sure the cursor
- * doesn't go past 'scrolloff' lines from the screen end.
- */
- end_row = curwin->w_wrow + plines(curwin->w_topline - 1);
- if (curwin->w_p_wrap)
- {
- validate_cheight();
- validate_virtcol();
- end_row += curwin->w_cline_height - 1 - curwin->w_virtcol / Columns;
- }
- if (end_row < curwin->w_height - p_so)
- {
- --curwin->w_topline;
- --curwin->w_botline; /* approximate w_botline */
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
- }
- }
- /*
- * Scroll the screen one line up, but don't do it if it would move the cursor
- * off the screen.
- */
- void
- scrollup_clamp()
- {
- int start_row;
- if (curwin->w_topline == curbuf->b_ml.ml_line_count)
- return;
- validate_cursor(); /* w_wrow needs to be valid */
- /*
- * Compute the row number of the first row of the cursor line
- * and make sure it doesn't go off the screen. Make sure the cursor
- * doesn't go before 'scrolloff' lines from the screen start.
- */
- start_row = curwin->w_wrow - plines(curwin->w_topline);
- if (curwin->w_p_wrap)
- {
- validate_virtcol();
- start_row -= curwin->w_virtcol / Columns;
- }
- if (start_row >= p_so)
- {
- ++curwin->w_topline;
- ++curwin->w_botline; /* approximate w_botline */
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
- }
- }
- /*
- * insert 'line_count' lines at 'row' in window 'wp'
- * if 'invalid' is TRUE the wp->w_lsize_lnum[] is invalidated.
- * if 'mayclear' is TRUE the screen will be cleared if it is faster than
- * scrolling.
- * Returns FAIL if the lines are not inserted, OK for success.
- */
- int
- win_ins_lines(wp, row, line_count, invalid, mayclear)
- WIN *wp;
- int row;
- int line_count;
- int invalid;
- int mayclear;
- {
- int did_delete;
- int nextrow;
- int lastrow;
- int retval;
- if (invalid)
- wp->w_lsize_valid = 0;
- if (!redrawing() || line_count <= 0 || wp->w_height < 5)
- return FAIL;
- if (line_count > wp->w_height - row)
- line_count = wp->w_height - row;
- if (mayclear && Rows - line_count < 5) /* only a few lines left: redraw is faster */
- {
- screenclear(); /* will set wp->w_lsize_valid to 0 */
- return FAIL;
- }
- /*
- * Delete all remaining lines
- */
- if (row + line_count >= wp->w_height)
- {
- screen_fill(wp->w_winpos + row, wp->w_winpos + wp->w_height,
- 0, (int)Columns, ' ', ' ', 0);
- return OK;
- }
- /*
- * when scrolling, the message on the command line should be cleared,
- * otherwise it will stay there forever.
- */
- clear_cmdline = TRUE;
- /*
- * if the terminal can set a scroll region, use that
- */
- if (scroll_region)
- {
- scroll_region_set(wp, row);
- retval = screen_ins_lines(wp->w_winpos + row, 0, line_count,
- wp->w_height - row);
- scroll_region_reset();
- return retval;
- }
- if (wp->w_next && p_tf) /* don't delete/insert on fast terminal */
- return FAIL;
- /*
- * If there is a next window or a status line, we first try to delete the
- * lines at the bottom to avoid messing what is after the window.
- * If this fails and there are following windows, don't do anything to avoid
- * messing up those windows, better just redraw.
- */
- did_delete = FALSE;
- if (wp->w_next || wp->w_status_height)
- {
- if (screen_del_lines(0, wp->w_winpos + wp->w_height - line_count,
- line_count, (int)Rows, FALSE) == OK)
- did_delete = TRUE;
- else if (wp->w_next)
- return FAIL;
- }
- /*
- * if no lines deleted, blank the lines that will end up below the window
- */
- if (!did_delete)
- {
- wp->w_redr_status = TRUE;
- redraw_cmdline = TRUE;
- nextrow = wp->w_winpos + wp->w_height + wp->w_status_height;
- lastrow = nextrow + line_count;
- if (lastrow > Rows)
- lastrow = Rows;
- screen_fill(nextrow - line_count, lastrow - line_count,
- 0, (int)Columns, ' ', ' ', 0);
- }
- if (screen_ins_lines(0, wp->w_winpos + row, line_count, (int)Rows) == FAIL)
- {
- /* deletion will have messed up other windows */
- if (did_delete)
- {
- wp->w_redr_status = TRUE;
- win_rest_invalid(wp->w_next);
- }
- return FAIL;
- }
- return OK;
- }
- /*
- * delete 'line_count' lines at 'row' in window 'wp'
- * If 'invalid' is TRUE curwin->w_lsize_lnum[] is invalidated.
- * If 'mayclear' is TRUE the screen will be cleared if it is faster than
- * scrolling
- * Return OK for success, FAIL if the lines are not deleted.
- */
- int
- win_del_lines(wp, row, line_count, invalid, mayclear)
- WIN *wp;
- int row;
- int line_count;
- int invalid;
- int mayclear;
- {
- int retval;
- if (invalid)
- wp->w_lsize_valid = 0;
- if (!redrawing() || line_count <= 0)
- return FAIL;
- if (line_count > wp->w_height - row)
- line_count = wp->w_height - row;
- /* only a few lines left: redraw is faster */
- if (mayclear && Rows - line_count < 5)
- {
- screenclear(); /* will set wp->w_lsize_valid to 0 */
- return FAIL;
- }
- /*
- * Delete all remaining lines
- */
- if (row + line_count >= wp->w_height)
- {
- screen_fill(wp->w_winpos + row, wp->w_winpos + wp->w_height,
- 0, (int)Columns, ' ', ' ', 0);
- return OK;
- }
- /*
- * when scrolling, the message on the command line should be cleared,
- * otherwise it will stay there forever.
- */
- clear_cmdline = TRUE;
- /*
- * if the terminal can set a scroll region, use that
- */
- if (scroll_region)
- {
- scroll_region_set(wp, row);
- retval = screen_del_lines(wp->w_winpos + row, 0, line_count,
- wp->w_height - row, FALSE);
- scroll_region_reset();
- return retval;
- }
- if (wp->w_next && p_tf) /* don't delete/insert on fast terminal */
- return FAIL;
- if (screen_del_lines(0, wp->w_winpos + row, line_count,
- (int)Rows, FALSE) == FAIL)
- return FAIL;
- /*
- * If there are windows or status lines below, try to put them at the
- * correct place. If we can't do that, they have to be redrawn.
- */
- if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1)
- {
- if (screen_ins_lines(0, wp->w_winpos + wp->w_height - line_count,
- line_count, (int)Rows) == FAIL)
- {
- wp->w_redr_status = TRUE;
- win_rest_invalid(wp->w_next);
- }
- }
- /*
- * If this is the last window and there is no status line, redraw the
- * command line later.
- */
- else
- redraw_cmdline = TRUE;
- return OK;
- }
- /*
- * window 'wp' and everything after it is messed up, mark it for redraw
- */
- void
- win_rest_invalid(wp)
- WIN *wp;
- {
- while (wp)
- {
- wp->w_lsize_valid = 0;
- wp->w_redr_type = NOT_VALID;
- wp->w_redr_status = TRUE;
- wp = wp->w_next;
- }
- redraw_cmdline = TRUE;
- }
- /*
- * The rest of the routines in this file perform screen manipulations. The
- * given operation is performed physically on the screen. The corresponding
- * change is also made to the internal screen image. In this way, the editor
- * anticipates the effect of editing changes on the appearance of the screen.
- * That way, when we call screenupdate a complete redraw isn't usually
- * necessary. Another advantage is that we can keep adding code to anticipate
- * screen changes, and in the meantime, everything still works.
- */
- /*
- * types for inserting or deleting lines
- */
- #define USE_T_CAL 1
- #define USE_T_CDL 2
- #define USE_T_AL 3
- #define USE_T_CE 4
- #define USE_T_DL 5
- #define USE_T_SR 6
- #define USE_NL 7
- #define USE_T_CD 8
- /*
- * insert lines on the screen and update NextScreen
- * 'end' is the line after the scrolled part. Normally it is Rows.
- * When scrolling region used 'off' is the offset from the top for the region.
- * 'row' and 'end' are relative to the start of the region.
- *
- * return FAIL for failure, OK for success.
- */
- static int
- screen_ins_lines(off, row, line_count, end)
- int off;
- int row;
- int line_count;
- int end;
- {
- int i;
- int j;
- char_u *temp;
- int cursor_row;
- int type;
- int result_empty;
- /*
- * FAIL if
- * - there is no valid screen
- * - the screen has to be redrawn completely
- * - the line count is less than one
- * - the line count is more than 'ttyscroll'
- */
- if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll)
- return FAIL;
- /*
- * There are seven ways to insert lines:
- * 1. Use T_CD (clear to end of display) if it exists and the result of
- * the insert is just empty lines
- * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not
- * present or line_count > 1. It looks better if we do all the inserts
- * at once.
- * 3. Use T_CDL (delete multiple lines) if it exists and the result of the
- * insert is just empty lines and T_CE is not present or line_count >
- * 1.
- * 4. Use T_AL (insert line) if it exists.
- * 5. Use T_CE (erase line) if it exists and the result of the insert is
- * just empty lines.
- * 6. Use T_DL (delete line) if it exists and the result of the insert is
- * just empty lines.
- * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and
- * the 'da' flag is not set or we have clear line capability.
- *
- * Careful: In a hpterm scroll reverse doesn't work as expected, it moves
- * the scrollbar for the window. It does have insert line, use that if it
- * exists.
- */
- result_empty = (row + line_count >= end);
- if (*T_CD != NUL && result_empty)
- type = USE_T_CD;
- else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL))
- type = USE_T_CAL;
- else if (*T_CDL != NUL && result_empty && (line_count > 1 || *T_CE == NUL))
- type = USE_T_CDL;
- else if (*T_AL != NUL)
- type = USE_T_AL;
- else if (*T_CE != NUL && result_empty)
- type = USE_T_CE;
- else if (*T_DL != NUL && result_empty)
- type = USE_T_DL;
- else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || *T_CE))
- type = USE_T_SR;
- else
- return FAIL;
- /*
- * For clearing the lines screen_del_lines is used. This will also take
- * care of t_db if necessary.
- */
- if (type == USE_T_CD || type == USE_T_CDL ||
- type == USE_T_CE || type == USE_T_DL)
- return screen_del_lines(off, row, line_count, end, FALSE);
- /*
- * If text is retained below the screen, first clear or delete as many
- * lines at the bottom of the window as are about to be inserted so that
- * the deleted lines won't later surface during a screen_del_lines.
- */
- if (*T_DB)
- screen_del_lines(off, end - line_count, line_count, end, FALSE);
- #ifdef USE_GUI_BEOS
- vim_lock_screen();
- #endif
- if (*T_CCS != NUL) /* cursor relative to region */
- cursor_row = row;
- else
- cursor_row = row + off;
- /*
- * Shift LinePointers line_count down to reflect the inserted lines.
- * Clear the inserted lines in NextScreen.
- */
- row += off;
- end += off;
- for (i = 0; i < line_count; ++i)
- {
- j = end - 1 - i;
- temp = LinePointers[j];
- while ((j -= line_count) >= row)
- LinePointers[j + line_count] = LinePointers[j];
- LinePointers[j + line_count] = temp;
- lineclear(temp);
- }
- #ifdef USE_GUI_BEOS
- vim_unlock_screen();
- #endif
- screen_stop_highlight();
- windgoto(cursor_row, 0);
- if (type == USE_T_CAL)
- {
- term_append_lines(line_count);
- screen_start(); /* don't know where cursor is now */
- }
- else
- {
- for (i = 0; i < line_count; i++)
- {
- if (type == USE_T_AL)
- {
- if (i && cursor_row != 0)
- windgoto(cursor_row, 0);
- out_str(T_AL);
- }
- else /* type == USE_T_SR */
- out_str(T_SR);
- screen_start(); /* don't know where cursor is now */
- }
- }
- /*
- * With scroll-reverse and 'da' flag set we need to clear the lines that
- * have been scrolled down into the region.
- */
- if (type == USE_T_SR && *T_DA)
- {
- for (i = 0; i < line_count; ++i)
- {
- windgoto(off + i, 0);
- out_str(T_CE);
- screen_start(); /* don't know where cursor is now */
- }
- }
- #ifdef USE_GUI
- if (gui.in_use)
- out_flush(); /* always flush after a scroll */
- #endif
- return OK;
- }
- /*
- * delete lines on the screen and update NextScreen
- * 'end' is the line after the scrolled part. Normally it is Rows.
- * When scrolling region used 'off' is the offset from the top for the region.
- * 'row' and 'end' are relative to the start of the region.
- *
- * Return OK for success, FAIL if the lines are not deleted.
- */
- int
- screen_del_lines(off, row, line_count, end, force)
- int off;
- int row;
- int line_count;
- int end;
- int force; /* even when line_count > p_ttyscroll */
- {
- int j;
- int i;
- char_u *temp;
- int cursor_row;
- int cursor_end;
- int result_empty; /* result is empty until end of region */
- int can_delete; /* deleting line codes can be used */
- int type;
- /*
- * FAIL if
- * - there is no valid screen
- * - the screen has to be redrawn completely
- * - the line count is less than one
- * - the line count is more than 'ttyscroll'
- */
- if (!screen_valid(TRUE) || line_count <= 0 ||
- (!force && line_count > p_ttyscroll))
- return FAIL;
- /*
- * Check if the rest of the current region will become empty.
- */
- result_empty = row + line_count >= end;
- /*
- * We can delete lines only when 'db' flag not set or when 'ce' option
- * available.
- */
- can_delete = (*T_DB == NUL || *T_CE);
- /*
- * There are four ways to delete lines:
- * 1. Use T_CD if it exists and the result is empty.
- * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist.
- * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or
- * none of the other ways work.
- * 4. Use T_CE (erase line) if the result is empty.
- * 5. Use T_DL (delete line) if it exists.
- */
- if (*T_CD != NUL && result_empty)
- type = USE_T_CD;
- #if defined(__BEOS__) && defined(BEOS_DR8)
- /*
- * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in
- * its internal termcap... this works okay for tests which test *T_DB !=
- * NUL. It has the disadvantage that the user cannot use any :set t_*
- * command to get T_DB (back) to empty_option, only :set term=... will do
- * the trick...
- * Anyway, this hack will hopefully go away with the next OS release.
- * (Olaf Seibert)
- */
- else if (row == 0 && T_DB == empty_option
- && (line_count == 1 || *T_CDL == NUL))
- #else
- else if (row == 0 && (
- #ifndef AMIGA
- /* On the Amiga, somehow 'n' on the last line doesn't always scroll
- * up, so use delete-line command */
- line_count == 1 ||
- #endif
- *T_CDL == NUL))
- #endif
- type = USE_NL;
- else if (*T_CDL != NUL && line_count > 1 && can_delete)
- type = USE_T_CDL;
- else if (*T_CE != NUL && result_empty)
- type = USE_T_CE;
- else if (*T_DL != NUL && can_delete)
- type = USE_T_DL;
- else if (*T_CDL != NUL && can_delete)
- type = USE_T_CDL;
- else
- return FAIL;
- #ifdef USE_GUI_BEOS
- vim_lock_screen();
- #endif
- if (*T_CCS != NUL) /* cursor relative to region */
- {
- cursor_row = row;
- cursor_end = end;
- }
- else
- {
- cursor_row = row + off;
- cursor_end = end + off;
- }
- /*
- * Now shift LinePointers line_count up to reflect the deleted lines.
- * Clear the inserted lines in NextScreen.
- */
- row += off;
- end += off;
- for (i = 0; i < line_count; ++i)
- {
- j = row + i;
- temp = LinePointers[j];
- while ((j += line_count) <= end - 1)
- LinePointers[j - line_count] = LinePointers[j];
- LinePointers[j - line_count] = temp;
- lineclear(temp);
- }
- #ifdef USE_GUI_BEOS
- vim_unlock_screen();
- #endif
- /* delete the lines */
- screen_stop_highlight();
- if (type == USE_T_CD)
- {
- windgoto(cursor_row, 0);
- out_str(T_CD);
- screen_start(); /* don't know where cursor is now */
- }
- else if (type == USE_T_CDL)
- {
- windgoto(cursor_row, 0);
- term_delete_lines(line_count);
- screen_start(); /* don't know where cursor is now */
- }
- /*
- * Deleting lines at top of the screen or scroll region: Just scroll
- * the whole screen (scroll region) up by outputting newlines on the
- * last line.
- */
- else if (type == USE_NL)
- {
- windgoto(cursor_end - 1, 0);
- for (i = line_count; --i >= 0; )
- out_char('n'); /* cursor will remain on same line */
- }
- else
- {
- for (i = line_count; --i >= 0; )
- {
- if (type == USE_T_DL)
- {
- windgoto(cursor_row, 0);
- out_str(T_DL); /* delete a line */
- }
- else /* type == USE_T_CE */
- {
- windgoto(cursor_row + i, 0);
- out_str(T_CE); /* erase a line */
- }
- screen_start(); /* don't know where cursor is now */
- }
- }
- /*
- * If the 'db' flag is set, we need to clear the lines that have been
- * scrolled up at the bottom of the region.
- */
- if (*T_DB && (type == USE_T_DL || type == USE_T_CDL))
- {
- for (i = line_count; i > 0; --i)
- {
- windgoto(cursor_end - i, 0);
- out_str(T_CE); /* erase a line */
- screen_start(); /* don't know where cursor is now */
- }
- }
- #ifdef USE_GUI
- if (gui.in_use)
- out_flush(); /* always flush after a scroll */
- #endif
- return OK;
- }
- /*
- * show the current mode and ruler
- *
- * If clear_cmdline is TRUE, clear the rest of the cmdline.
- * If clear_cmdline is FALSE there may be a message there that needs to be
- * cleared only if a mode is shown.
- * Return the length of the message (0 if no message).
- */
- int
- showmode()
- {
- int need_clear;
- int length = 0;
- int do_mode;
- int attr;
- #ifdef INSERT_EXPAND
- int sub_attr;
- #endif
- do_mode = (p_smd && ((State & INSERT) || restart_edit || VIsual_active));
- if (do_mode || Recording)
- {
- /*
- * Don't show mode right now, when not redrawing or inside a mapping.
- * Call char_avail() only when we are going to show something, because
- * it takes a bit of time.
- */
- if (!redrawing() || (char_avail() && !KeyTyped))
- {
- redraw_cmdline = TRUE; /* show mode later */
- return 0;
- }
- /* wait a bit before overwriting an important message */
- check_for_delay(FALSE);
- /* if the cmdline is more than one line high, erase top lines */
- need_clear = clear_cmdline;
- if (clear_cmdline && cmdline_row < Rows - 1)
- msg_clr_cmdline(); /* will reset clear_cmdline */
- /* Position on the last line in the window, column 0 */
- msg_col = 0;
- msg_row = Rows - 1;
- cursor_off();
- attr = hl_attr(HLF_CM); /* Highlight mode */
- if (do_mode)
- {
- MSG_PUTS_ATTR("--", attr);
- #ifdef INSERT_EXPAND
- if (edit_submode != NULL) /* CTRL-X in Insert mode */
- {
- msg_puts_attr(edit_submode, attr);
- if (edit_submode_extra != NULL)
- {
- MSG_PUTS_ATTR(" ", attr); /* add a space in between */
- if ((int)edit_submode_highl < (int)HLF_COUNT)
- sub_attr = hl_attr(edit_submode_highl);
- else
- sub_attr = attr;
- msg_puts_attr(edit_submode_extra, sub_attr);
- }
- }
- else
- #endif
- {
- if (State == INSERT)
- {
- #ifdef RIGHTLEFT
- if (p_ri)
- MSG_PUTS_ATTR(" REVERSE", attr);
- #endif
- MSG_PUTS_ATTR(" INSERT", attr);
- }
- else if (State == REPLACE)
- MSG_PUTS_ATTR(" REPLACE", attr);
- else if (restart_edit == 'I')
- MSG_PUTS_ATTR(" (insert)", attr);
- else if (restart_edit == 'R')
- MSG_PUTS_ATTR(" (replace)", attr);
- #ifdef RIGHTLEFT
- if (p_hkmap)
- MSG_PUTS_ATTR(" Hebrew", attr);
- # ifdef FKMAP
- if (p_fkmap)
- MSG_PUTS_ATTR(farsi_text_5, attr);
- # endif
- #endif
- if ((State & INSERT) && p_paste)
- MSG_PUTS_ATTR(" (paste)", attr);
- if (VIsual_active)
- {
- if (VIsual_select)
- MSG_PUTS_ATTR(" SELECT", attr);
- else
- MSG_PUTS_ATTR(" VISUAL", attr);
- if (VIsual_mode == Ctrl('V'))
- MSG_PUTS_ATTR(" BLOCK", attr);
- else if (VIsual_mode == 'V')
- MSG_PUTS_ATTR(" LINE", attr);
- }
- }
- MSG_PUTS_ATTR(" --", attr);
- need_clear = TRUE;
- }
- if (Recording)
- {
- MSG_PUTS_ATTR("recording", attr);
- need_clear = TRUE;
- }
- if (need_clear || clear_cmdline)
- msg_clr_eos();
- msg_didout = FALSE; /* overwrite this message */
- length = msg_col;
- msg_col = 0;
- }
- else if (clear_cmdline) /* just clear anything */
- msg_clr_cmdline(); /* will reset clear_cmdline */
- win_redr_ruler(lastwin, TRUE);
- redraw_cmdline = FALSE;
- clear_cmdline = FALSE;
- return length;
- }
- /*
- * delete mode message
- */
- void
- unshowmode(force)
- int force;
- {
- /*
- * Don't delete it right now, when not redrawing or insided a mapping.
- */
- if (!redrawing() || (!force && char_avail() && !KeyTyped))
- redraw_cmdline = TRUE; /* delete mode later */
- else if (Recording)
- MSG("recording");
- else
- MSG("");
- }
- static int
- highlight_status(attr, is_curwin)
- int *attr;
- int is_curwin;
- {
- if (is_curwin)
- *attr = hl_attr(HLF_S);
- else
- *attr = hl_attr(HLF_SNC);
- /* Use a space when there is highlighting, and highlighting of current
- * window differs, or this is not the current window */
- if (*attr && (hl_attr(HLF_S) != hl_attr(HLF_SNC)
- || !is_curwin || firstwin == lastwin))
- return ' ';
- if (is_curwin)
- return '^';
- return '=';
- }
- /*
- * If ruler option is set: show current cursor position.
- * If always is FALSE, only print if position has changed.
- */
- void
- showruler(always)
- int always;
- {
- win_redr_ruler(curwin, always);
- }
- static void
- win_redr_ruler(wp, always)
- WIN *wp;
- int always;
- {
- char_u buffer[30];
- int row;
- int fillchar;
- int attr;
- int empty_line = FALSE;
- colnr_t virtcol;
- /* If 'ruler' off or redrawing disabled, don't do anything */
- if (!p_ru || (!always && !redrawing()))
- return;
- /*
- * Check if cursor.lnum is valid, since win_redr_ruler() may be called
- * after deleting lines, before cursor.lnum is corrected.
- */
- if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
- return;
- /*
- * Check if the line is empty (will show "0-1").
- */
- if (*ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL)
- empty_line = TRUE;
- /*
- * Only draw the ruler when something changed.
- */
- validate_virtcol_win(wp);
- if ( redraw_cmdline
- || always
- || wp->w_cursor.lnum != wp->w_ru_cursor.lnum
- || wp->w_cursor.col != wp->w_ru_cursor.col
- || wp->w_virtcol != wp->w_ru_virtcol
- || empty_line != wp->w_ru_empty)
- {
- cursor_off();
- if (wp->w_status_height)
- {
- row = wp->w_winpos + wp->w_height;
- fillchar = highlight_status(&attr, wp == curwin);
- }
- else
- {
- row = Rows - 1;
- fillchar = ' ';
- attr = 0;
- }
- /* In list mode virtcol needs to be recomputed */
- virtcol = wp->w_virtcol;
- if (wp->w_p_list && lcs_tab1 == NUL)
- {
- wp->w_p_list = FALSE;
- getvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
- wp->w_p_list = TRUE;
- }
- /*
- * Some sprintfs return the length, some return a pointer.
- * To avoid portability problems we use strlen() here.
- */
- sprintf((char *)buffer, "%ld,",
- (wp->w_buffer->b_ml.ml_flags & ML_EMPTY)
- ? 0L
- : (long)(wp->w_cursor.lnum));
- col_print(buffer + STRLEN(buffer),
- !(State & INSERT) && empty_line
- ? 0
- : (int)wp->w_cursor.col + 1,
- (int)virtcol + 1);
- screen_puts(buffer, row, ru_col, attr);
- screen_fill(row, row + 1, ru_col + (int)STRLEN(buffer),
- (int)Columns, fillchar, fillchar, attr);
- wp->w_ru_cursor = wp->w_cursor;
- wp->w_ru_virtcol = wp->w_virtcol;
- wp->w_ru_empty = empty_line;
- }
- }
- /*
- * Check if there should be a delay. Used before clearing or redrawing the
- * screen or the command line.
- */
- void
- check_for_delay(check_msg_scroll)
- int check_msg_scroll;
- {
- if (emsg_on_display || (check_msg_scroll && msg_scroll))
- {
- out_flush();
- ui_delay(1000L, TRUE);
- emsg_on_display = FALSE;
- if (check_msg_scroll)
- msg_scroll = FALSE;
- }
- }
- /*
- * screen_valid - allocate screen buffers if size changed
- * If "clear" is TRUE: clear screen if it has been resized.
- * Returns TRUE if there is a valid screen to write to.
- * Returns FALSE when starting up and screen not initialized yet.
- */
- int
- screen_valid(clear)
- int clear;
- {
- screenalloc(clear); /* allocate screen buffers if size changed */
- return (NextScreen != NULL);
- }
- #ifdef USE_MOUSE
- /*
- * Move the cursor to the specified row and column on the screen.
- * Change current window if neccesary. Returns an integer with the
- * CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
- *
- * If flags has MOUSE_FOCUS, then the current window will not be changed, and
- * if the mouse is outside the window then the text will scroll, or if the
- * mouse was previously on a status line, then the status line may be dragged.
- *
- * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
- * cursor is moved unless the cursor was on a status line. Ignoring the
- * CURSOR_MOVED bit, this function returns one of IN_UNKNOWN, IN_BUFFER, or
- * IN_STATUS_LINE depending on where the cursor was clicked.
- *
- * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
- * the mouse is on the status line of the same window.
- *
- * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
- * the last call.
- *
- * If flags has MOUSE_SETPOS, nothing is done, only the current position is
- * remembered.
- */
- int
- jump_to_mouse(flags, inclusive)
- int flags;
- int *inclusive; /* used for inclusive operator, can be NULL */
- {
- static int on_status_line = 0; /* #lines below bottom of window */
- static int prev_row = -1;
- static int prev_col = -1;
- WIN *wp, *old_curwin;
- FPOS old_cursor;
- int count;
- int first;
- int row = mouse_row;
- int col = mouse_col;
- mouse_past_bottom = FALSE;
- mouse_past_eol = FALSE;
- if ((flags & MOUSE_DID_MOVE) && prev_row == mouse_row
- && prev_col == mouse_col)
- {
- retnomove:
- /* before moving the cursor for a left click wich is NOT in a status
- * line, stop Visual mode */
- if (on_status_line)
- return IN_STATUS_LINE;
- if (flags & MOUSE_MAY_STOP_VIS)
- {
- end_visual_mode();
- update_curbuf(NOT_VALID); /* delete the inversion */
- }
- return IN_BUFFER;
- }
- prev_row = mouse_row;
- prev_col = mouse_col;
- if ((flags & MOUSE_SETPOS))
- goto retnomove; /* ugly goto... */
- old_curwin = curwin;
- old_cursor = curwin->w_cursor;
- if (!(flags & MOUSE_FOCUS))
- {
- if (row < 0 || col < 0) /* check if it makes sense */
- return IN_UNKNOWN;
- /* find the window where the row is in */
- for (wp = firstwin; wp->w_next; wp = wp->w_next)
- if (row < wp->w_next->w_winpos)
- break;
- /*
- * winpos and height may change in win_enter()!
- */
- row -= wp->w_winpos;
- if (row >= wp->w_height) /* In (or below) status line */
- on_status_line = row - wp->w_height + 1;
- else
- on_status_line = 0;
- /* Before jumping to another buffer, or moving the cursor for a left
- * click, stop Visual mode. */
- if (VIsual_active
- && (wp->w_buffer != curwin->w_buffer
- || (!on_status_line && (flags & MOUSE_MAY_STOP_VIS))))
- {
- end_visual_mode();
- update_curbuf(NOT_VALID); /* delete the inversion */
- }
- win_enter(wp, TRUE); /* can make wp invalid! */
- if (on_status_line) /* In (or below) status line */
- {
- /* Don't use start_arrow() if we're in the same window */
- if (curwin == old_curwin)
- return IN_STATUS_LINE;
- else
- return IN_STATUS_LINE | CURSOR_MOVED;
- }
- curwin->w_cursor.lnum = curwin->w_topline;
- #ifdef USE_GUI
- /* remember topline, needed for double click */
- gui_prev_topline = curwin->w_topline;
- #endif
- }
- else if (on_status_line)
- {
- /* Drag the status line */
- count = row - curwin->w_winpos - curwin->w_height + 1 - on_status_line;
- win_drag_status_line(count);
- return IN_STATUS_LINE; /* Cursor didn't move */
- }
- else /* keep_window_focus must be TRUE */
- {
- /* before moving the cursor for a left click, stop Visual mode */
- if (flags & MOUSE_MAY_STOP_VIS)
- {
- end_visual_mode();
- update_curbuf(NOT_VALID); /* delete the inversion */
- }
- row -= curwin->w_winpos;
- /*
- * When clicking beyond the end of the window, scroll the screen.
- * Scroll by however many rows outside the window we are.
- */
- if (row < 0)
- {
- count = 0;
- for (first = TRUE; curwin->w_topline > 1; --curwin->w_topline)
- {
- count += plines(curwin->w_topline - 1);
- if (!first && count > -row)
- break;
- first = FALSE;
- }
- curwin->w_valid &=
- ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
- redraw_later(VALID);
- row = 0;
- }
- else if (row >= curwin->w_height)
- {
- count = 0;
- for (first = TRUE; curwin->w_topline < curbuf->b_ml.ml_line_count;
- ++curwin->w_topline)
- {
- count += plines(curwin->w_topline);
- if (!first && count > row - curwin->w_height + 1)
- break;
- first = FALSE;
- }
- redraw_later(VALID);
- curwin->w_valid &=
- ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
- row = curwin->w_height - 1;
- }
- curwin->w_cursor.lnum = curwin->w_topline;
- }
- #ifdef RIGHTLEFT
- if (curwin->w_p_rl)
- col = Columns - 1 - col;
- #endif
- if (curwin->w_p_wrap) /* lines wrap */
- {
- while (row)
- {
- count = plines(curwin->w_cursor.lnum);
- if (count > row)
- {
- col += row * Columns;
- break;
- }
- if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)
- {
- mouse_past_bottom = TRUE;
- break;
- }
- row -= count;
- ++curwin->w_cursor.lnum;
- }
- }
- else /* lines don't wrap */
- {
- curwin->w_cursor.lnum += row;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
- {
- curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- mouse_past_bottom = TRUE;
- }
- col += curwin->w_leftcol;
- }
- if (curwin->w_p_nu) /* skip number in front of the line */
- if ((col -= 8) < 0)
- col = 0;
- /* Start Visual mode before coladvance(), for when 'sel' != "old" */
- if ((flags & MOUSE_MAY_VIS) && !VIsual_active)
- {
- check_visual_highlight();
- VIsual = old_cursor;
- VIsual_active = TRUE;
- VIsual_reselect = TRUE;
- /* if 'selectmode' contains "mouse", start Select mode */
- may_start_select('o');
- setmouse();
- if (p_smd)
- redraw_cmdline = TRUE; /* show visual mode later */
- }
- curwin->w_curswant = col;
- curwin->w_set_curswant = FALSE; /* May still have been TRUE */
- if (coladvance(col) == FAIL) /* Mouse click beyond end of line */
- {
- if (inclusive != NULL)
- *inclusive = TRUE;
- mouse_past_eol = TRUE;
- }
- else if (inclusive != NULL)
- *inclusive = FALSE;
- if (curwin == old_curwin && curwin->w_cursor.lnum == old_cursor.lnum &&
- curwin->w_cursor.col == old_cursor.col)
- return IN_BUFFER; /* Cursor has not moved */
- return IN_BUFFER | CURSOR_MOVED; /* Cursor has moved */
- }
- #endif /* USE_MOUSE */
- /*
- * Return TRUE if redrawing should currently be done.
- */
- int
- redrawing()
- {
- return (!RedrawingDisabled && !(p_lz && char_avail() && !KeyTyped));
- }
- /*
- * Return TRUE if printing messages should currently be done.
- */
- int
- messaging()
- {
- return (!(p_lz && char_avail() && !KeyTyped));
- }
- /*
- * move screen 'count' pages up or down and update screen
- *
- * return FAIL for failure, OK otherwise
- */
- int
- onepage(dir, count)
- int dir;
- long count;
- {
- linenr_t lp;
- long n;
- int off;
- int retval = OK;
- if (curbuf->b_ml.ml_line_count == 1) /* nothing to do */
- {
- beep_flush();
- return FAIL;
- }
- for ( ; count > 0; --count)
- {
- validate_botline();
- /*
- * It's an error to move a page up when the first line is already on
- * the screen. It's an error to move a page down when the last line
- * is on the screen and the topline is 'scrolloff' lines from the
- * last line.
- */
- if (dir == FORWARD
- ? ((curwin->w_topline >= curbuf->b_ml.ml_line_count - p_so) &&
- curwin->w_botline > curbuf->b_ml.ml_line_count)
- : (curwin->w_topline == 1))
- {
- beep_flush();
- retval = FAIL;
- break;
- }
- if (dir == FORWARD)
- {
- /* at end of file */
- if (curwin->w_botline > curbuf->b_ml.ml_line_count)
- {
- curwin->w_topline = curbuf->b_ml.ml_line_count;
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
- }
- else
- {
- /*
- * When there are three or less lines on the screen, move them
- * all to above the screen.
- */
- if (curwin->w_botline - curwin->w_topline <= 3)
- off = 0;
- /*
- * Make sure at least w_botline gets onto the screen, also
- * when 'scrolloff' is non-zero and with very long lines.
- */
- else if (plines(curwin->w_botline) +
- plines(curwin->w_botline - 1) +
- plines(curwin->w_botline - 2) >= curwin->w_height - 2)
- off = 0;
- else
- off = 2;
- curwin->w_topline = curwin->w_botline - off;
- curwin->w_cursor.lnum = curwin->w_topline;
- curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|
- VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
- }
- }
- else /* dir == BACKWARDS */
- {
- lp = curwin->w_topline;
- /*
- * If the first two lines on the screen are not too big, we keep
- * them on the screen.
- */
- if ((n = plines(lp)) > curwin->w_height / 2)
- --lp;
- else if (lp < curbuf->b_ml.ml_line_count &&
- n + plines(lp + 1) < curwin->w_height / 2)
- ++lp;
- curwin->w_cursor.lnum = lp;
- n = 0;
- while (n <= curwin->w_height && lp >= 1)
- {
- n += plines(lp);
- --lp;
- }
- if (n <= curwin->w_height) /* at begin of file */
- {
- curwin->w_topline = 1;
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
- }
- else if (lp >= curwin->w_topline - 2) /* very long lines */
- {
- --curwin->w_topline;
- comp_botline();
- curwin->w_cursor.lnum = curwin->w_botline - 1;
- curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|
- VALID_WROW|VALID_CROW);
- }
- else
- {
- curwin->w_topline = lp + 2;
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
- }
- }
- }
- cursor_correct();
- beginline(BL_SOL | BL_FIX);
- curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL);
- /*
- * Avoid the screen jumping up and down when 'scrolloff' is non-zero.
- */
- if (dir == FORWARD && curwin->w_cursor.lnum < curwin->w_topline + p_so)
- scroll_cursor_top(1, FALSE);
- update_screen(VALID);
- return retval;
- }
- /* #define KEEP_SCREEN_LINE */
- void
- halfpage(flag, Prenum)
- int flag;
- linenr_t Prenum;
- {
- long scrolled = 0;
- int i;
- int n;
- int room;
- if (Prenum)
- curwin->w_p_scroll = (Prenum > curwin->w_height) ?
- curwin->w_height : Prenum;
- n = (curwin->w_p_scroll <= curwin->w_height) ?
- curwin->w_p_scroll : curwin->w_height;
- validate_botline();
- room = curwin->w_empty_rows;
- if (flag) /* scroll down */
- {
- while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count)
- {
- i = plines(curwin->w_topline);
- n -= i;
- if (n < 0 && scrolled)
- break;
- ++curwin->w_topline;
- curwin->w_valid &= ~(VALID_CROW|VALID_WROW);
- scrolled += i;
- /*
- * Correct w_botline for changed w_topline.
- */
- room += i;
- do
- {
- i = plines(curwin->w_botline);
- if (i > room)
- break;
- ++curwin->w_botline;
- room -= i;
- } while (curwin->w_botline <= curbuf->b_ml.ml_line_count);
- #ifndef KEEP_SCREEN_LINE
- if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
- {
- ++curwin->w_cursor.lnum;
- curwin->w_valid &= ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL);
- }
- #endif
- }
- #ifndef KEEP_SCREEN_LINE
- /*
- * When hit bottom of the file: move cursor down.
- */
- if (n > 0)
- {
- curwin->w_cursor.lnum += n;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
- curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- }
- #else
- /* try to put the cursor in the same screen line */
- while ((curwin->w_cursor.lnum < curwin->w_topline || scrolled > 0)
- && curwin->w_cursor.lnum < curwin->w_botline - 1)
- {
- scrolled -= plines(curwin->w_cursor.lnum);
- if (scrolled < 0 && curwin->w_cursor.lnum >= curwin->w_topline)
- break;
- ++curwin->w_cursor.lnum;
- }
- #endif
- }
- else /* scroll up */
- {
- while (n > 0 && curwin->w_topline > 1)
- {
- i = plines(curwin->w_topline - 1);
- n -= i;
- if (n < 0 && scrolled)
- break;
- scrolled += i;
- --curwin->w_topline;
- curwin->w_valid &= ~(VALID_CROW|VALID_WROW|
- VALID_BOTLINE|VALID_BOTLINE_AP);
- #ifndef KEEP_SCREEN_LINE
- if (curwin->w_cursor.lnum > 1)
- {
- --curwin->w_cursor.lnum;
- curwin->w_valid &= ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL);
- }
- #endif
- }
- #ifndef KEEP_SCREEN_LINE
- /*
- * When hit top of the file: move cursor up.
- */
- if (n > 0)
- {
- if (curwin->w_cursor.lnum > (linenr_t)n)
- curwin->w_cursor.lnum -= n;
- else
- curwin->w_cursor.lnum = 1;
- }
- #else
- /* try to put the cursor in the same screen line */
- scrolled += n; /* move cursor when topline is 1 */
- while (curwin->w_cursor.lnum > curwin->w_topline &&
- (scrolled > 0 || curwin->w_cursor.lnum >= curwin->w_botline))
- {
- scrolled -= plines(curwin->w_cursor.lnum - 1);
- if (scrolled < 0 && curwin->w_cursor.lnum < curwin->w_botline)
- break;
- --curwin->w_cursor.lnum;
- }
- #endif
- }
- cursor_correct();
- beginline(BL_SOL | BL_FIX);
- update_screen(VALID);
- }
- /*
- * Give an introductory message about Vim.
- * Only used when starting Vim on an empty file, without a file name.
- * Or with the ":intro" command (for Sven :-).
- */
- static void
- intro_message()
- {
- int i;
- int row;
- int col;
- static char *(lines[]) =
- {
- "VIM - Vi IMproved",
- "",
- "version ",
- "by Bram Moolenaar et al.",
- "",
- "Vim is freely distributable",
- "type :help uganda<Enter> if you like Vim ",
- "",
- "type :q<Enter> to exit ",
- "type :help<Enter> or <F1> for on-line help",
- "type :help version5<Enter> for version info",
- NULL,
- "",
- "Running in Vi compatible mode",
- "type :set nocp<Enter> for Vim defaults",
- "type :help cp-default<Enter> for info on this",
- };
- row = ((int)Rows - (int)(sizeof(lines) / sizeof(char *))) / 2;
- if (!p_cp)
- row += 2;
- #if defined(WIN32) && !defined(USE_GUI_WIN32)
- if (mch_windows95())
- row -= 2;
- #endif
- #if defined(__BEOS__) && defined(__INTEL__)
- row -= 2;
- #endif
- if (row > 2 && Columns >= 50)
- {
- for (i = 0; i < (int)(sizeof(lines) / sizeof(char *)); ++i)
- {
- if (lines[i] == NULL)
- {
- if (!p_cp)
- break;
- continue;
- }
- col = strlen(lines[i]);
- if (i == 2)
- col += strlen(mediumVersion);
- col = (Columns - col) / 2;
- if (col < 0)
- col = 0;
- screen_puts((char_u *)lines[i], row, col, 0);
- if (i == 2)
- screen_puts((char_u *)mediumVersion, row, col + 8, 0);
- ++row;
- }
- #if defined(WIN32) && !defined(USE_GUI_WIN32)
- if (mch_windows95())
- {
- screen_puts((char_u *)"WARNING: Windows 95 detected", row + 1, col + 8, hl_attr(HLF_E));
- screen_puts((char_u *)"type :help windows95<Enter> for info on this", row + 2, col, 0);
- }
- #endif
- #if defined(__BEOS__) && defined(__INTEL__)
- screen_puts((char_u *)" WARNING: Intel CPU detected. ", row + 1, col + 4, hl_attr(HLF_E));
- screen_puts((char_u *)" PPC has a much better architecture. ", row + 2, col + 4, hl_attr(HLF_E));
- #endif
- }
- }
- /*
- * ":intro" command: clear screen, display intro screen and wait for return.
- */
- void
- do_intro()
- {
- screenclear();
- intro_message();
- wait_return(TRUE);
- }