1 /* vi:set ts=8 sts=4 sw=4: 2 * 3 * VIM - Vi IMproved by Bram Moolenaar 4 * 5 * Do ":help uganda" in Vim to read copying and usage conditions. 6 * Do ":help credits" in Vim to see a list of people who contributed. 7 * See README.txt for an overview of the Vim source code. 8 */ 9 10 /* 11 * screen.c: code for displaying on the screen 12 * 13 * Output to the screen (console, terminal emulator or GUI window) is minimized 14 * by remembering what is already on the screen, and only updating the parts 15 * that changed. 16 * 17 * ScreenLines[off] Contains a copy of the whole screen, as it is currently 18 * displayed (excluding text written by external commands). 19 * ScreenAttrs[off] Contains the associated attributes. 20 * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] 21 * for each line. 22 * LineWraps[row] Flag for each line whether it wraps to the next line. 23 * 24 * For double-byte characters, two consecutive bytes in ScreenLines[] can form 25 * one character which occupies two display cells. 26 * For UTF-8 a multi-byte character is converted to Unicode and stored in 27 * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII 28 * character without composing chars ScreenLinesUC[] will be 0. When the 29 * character occupies two display cells the next byte in ScreenLines[] is 0. 30 * ScreenLinesC1[] and ScreenLinesC2[] contain up to two composing characters 31 * (drawn on top of the first character). They are 0 when not used. 32 * ScreenLines2[] is only used for euc-jp to store the second byte if the 33 * first byte is 0x8e (single-width character). 34 * 35 * The screen_*() functions write to the screen and handle updating 36 * ScreenLines[]. 37 * 38 * update_screen() is the function that updates all windows and status lines. 39 * It is called form the main loop when must_redraw is non-zero. It may be 40 * called from other places when an immediated screen update is needed. 41 * 42 * The part of the buffer that is displayed in a window is set with: 43 * - w_topline (first buffer line in window) 44 * - w_topfill (filler line above the first line) 45 * - w_leftcol (leftmost window cell in window), 46 * - w_skipcol (skipped window cells of first line) 47 * 48 * Commands that only move the cursor around in a window, do not need to take 49 * action to update the display. The main loop will check if w_topline is 50 * valid and update it (scroll the window) when needed. 51 * 52 * Commands that scroll a window change w_topline and must call 53 * check_cursor() to move the cursor into the visible part of the window, and 54 * call redraw_later(VALID) to have the window displayed by update_screen() 55 * later. 56 * 57 * Commands that change text in the buffer must call changed_bytes() or 58 * changed_lines() to mark the area that changed and will require updating 59 * later. The main loop will call update_screen(), which will update each 60 * window that shows the changed buffer. This assumes text above the change 61 * can remain displayed as it is. Text after the change may need updating for 62 * scrolling, folding and syntax highlighting. 63 * 64 * Commands that change how a window is displayed (e.g., setting 'list') or 65 * invalidate the contents of a window in another way (e.g., change fold 66 * settings), must call redraw_later(NOT_VALID) to have the whole window 67 * redisplayed by update_screen() later. 68 * 69 * Commands that change how a buffer is displayed (e.g., setting 'tabstop') 70 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the 71 * buffer redisplayed by update_screen() later. 72 * 73 * Commands that move the window position must call redraw_later(NOT_VALID). 74 * TODO: should minimize redrawing by scrolling when possible. 75 * 76 * Commands that change everything (e.g., resizing the screen) must call 77 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). 78 * 79 * Things that are handled indirectly: 80 * - When messages scroll the screen up, msg_scrolled will be set and 81 * update_screen() called to redraw. 82 */ 83 84 #include "vim.h" 85 86 /* 87 * The attributes that are actually active for writing to the screen. 88 */ 89 static int screen_attr = 0; 90 91 /* 92 * Positioning the cursor is reduced by remembering the last position. 93 * Mostly used by windgoto() and screen_char(). 94 */ 95 static int screen_cur_row, screen_cur_col; /* last known cursor position */ 96 97 #ifdef FEAT_SEARCH_EXTRA 98 /* 99 * Struct used for highlighting 'hlsearch' matches for the last use search 100 * pattern or a ":match" item. 101 * For 'hlsearch' there is one pattern for all windows. For ":match" there is 102 * a different pattern for each window. 103 */ 104 typedef struct 105 { 106 regmmatch_T rm; /* points to the regexp program; contains last found 107 match (may continue in next line) */ 108 buf_T *buf; /* the buffer to search for a match */ 109 linenr_T lnum; /* the line to search for a match */ 110 int attr; /* attributes to be used for a match */ 111 int attr_cur; /* attributes currently active in win_line() */ 112 linenr_T first_lnum; /* first lnum to search for multi-line pat */ 113 char_u *startp; /* in win_line() points to char where HL starts */ 114 char_u *endp; /* in win_line() points to char where HL ends */ 115 } match_T; 116 117 static match_T search_hl; /* used for 'hlsearch' highlight matching */ 118 static match_T match_hl; /* used for ":match" highlight matching */ 119 #endif 120 121 #ifdef FEAT_FOLDING 122 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ 123 #endif 124 125 /* 126 * Buffer for one screen line (characters and attributes). 127 */ 128 static schar_T *current_ScreenLine; 129 130 static void win_update __ARGS((win_T *wp)); 131 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, enum hlf_value hl)); 132 #ifdef FEAT_FOLDING 133 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); 134 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); 135 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); 136 #endif 137 static int win_line __ARGS((win_T *, linenr_T, int, int)); 138 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); 139 #ifdef FEAT_RIGHTLEFT 140 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); 141 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) 142 #else 143 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); 144 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) 145 #endif 146 #ifdef FEAT_RIGHTLEFT 147 static void rl_mirror __ARGS((char_u *str)); 148 #endif 149 #ifdef FEAT_VERTSPLIT 150 static void draw_vsep_win __ARGS((win_T *wp, int row)); 151 #endif 152 #ifdef FEAT_SEARCH_EXTRA 153 static void start_search_hl __ARGS((void)); 154 static void end_search_hl __ARGS((void)); 155 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); 156 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); 157 #endif 158 static void screen_start_highlight __ARGS((int attr)); 159 static void screen_char __ARGS((unsigned off, int row, int col)); 160 #ifdef FEAT_MBYTE 161 static void screen_char_2 __ARGS((unsigned off, int row, int col)); 162 #endif 163 static void screenclear2 __ARGS((void)); 164 static void lineclear __ARGS((unsigned off, int width)); 165 static void lineinvalid __ARGS((unsigned off, int width)); 166 #ifdef FEAT_VERTSPLIT 167 static void linecopy __ARGS((int to, int from, win_T *wp)); 168 static void redraw_block __ARGS((int row, int end, win_T *wp)); 169 #endif 170 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); 171 static void win_rest_invalid __ARGS((win_T *wp)); 172 static int screen_ins_lines __ARGS((int, int, int, int, win_T *wp)); 173 static void msg_pos_mode __ARGS((void)); 174 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) 175 static int fillchar_status __ARGS((int *attr, int is_curwin)); 176 #endif 177 #ifdef FEAT_VERTSPLIT 178 static int fillchar_vsep __ARGS((int *attr)); 179 #endif 180 #ifdef FEAT_STL_OPT 181 static void win_redr_custom __ARGS((win_T *wp, int Ruler)); 182 #endif 183 #ifdef FEAT_CMDL_INFO 184 static void win_redr_ruler __ARGS((win_T *wp, int always)); 185 #endif 186 187 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) 188 /* Ugly global: overrule attribute used by screen_char() */ 189 static int screen_char_attr = 0; 190 #endif 191 192 /* 193 * Redraw the current window later, with update_screen(type). 194 * Set must_redraw only if not already set to a higher value. 195 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. 196 */ 197 void 198 redraw_later(type) 199 int type; 200 { 201 redraw_win_later(curwin, type); 202 } 203 204 void 205 redraw_win_later(wp, type) 206 win_T *wp; 207 int type; 208 { 209 if (wp->w_redr_type < type) 210 { 211 wp->w_redr_type = type; 212 if (type >= NOT_VALID) 213 wp->w_lines_valid = 0; 214 if (must_redraw < type) /* must_redraw is the maximum of all windows */ 215 must_redraw = type; 216 } 217 } 218 219 /* 220 * Force a complete redraw later. Also resets the highlighting. To be used 221 * after executing a shell command that messes up the screen. 222 */ 223 void 224 redraw_later_clear() 225 { 226 redraw_all_later(CLEAR); 227 screen_attr = HL_BOLD | HL_UNDERLINE; 228 } 229 230 /* 231 * Mark all windows to be redrawn later. 232 */ 233 void 234 redraw_all_later(type) 235 int type; 236 { 237 win_T *wp; 238 239 FOR_ALL_WINDOWS(wp) 240 { 241 redraw_win_later(wp, type); 242 } 243 } 244 245 /* 246 * Mark all windows that are editing the current buffer to be udpated later. 247 */ 248 void 249 redraw_curbuf_later(type) 250 int type; 251 { 252 redraw_buf_later(curbuf, type); 253 } 254 255 void 256 redraw_buf_later(buf, type) 257 buf_T *buf; 258 int type; 259 { 260 win_T *wp; 261 262 FOR_ALL_WINDOWS(wp) 263 { 264 if (wp->w_buffer == buf) 265 redraw_win_later(wp, type); 266 } 267 } 268 269 /* 270 * Changed something in the current window, at buffer line "lnum", that 271 * requires that line and possibly other lines to be redrawn. 272 * Used when entering/leaving Insert mode with the cursor on a folded line. 273 * Used to remove the "$" from a change command. 274 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot 275 * may become invalid and the whole window will have to be redrawn. 276 */ 277 /*ARGSUSED*/ 278 void 279 redrawWinline(lnum, invalid) 280 linenr_T lnum; 281 int invalid; /* window line height is invalid now */ 282 { 283 #ifdef FEAT_FOLDING 284 int i; 285 #endif 286 287 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) 288 curwin->w_redraw_top = lnum; 289 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) 290 curwin->w_redraw_bot = lnum; 291 redraw_later(VALID); 292 293 #ifdef FEAT_FOLDING 294 if (invalid) 295 { 296 /* A w_lines[] entry for this lnum has become invalid. */ 297 i = find_wl_entry(curwin, lnum); 298 if (i >= 0) 299 curwin->w_lines[i].wl_valid = FALSE; 300 } 301 #endif 302 } 303 304 /* 305 * update all windows that are editing the current buffer 306 */ 307 void 308 update_curbuf(type) 309 int type; 310 { 311 redraw_curbuf_later(type); 312 update_screen(type); 313 } 314 315 /* 316 * update_screen() 317 * 318 * Based on the current value of curwin->w_topline, transfer a screenfull 319 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. 320 */ 321 void 322 update_screen(type) 323 int type; 324 { 325 win_T *wp; 326 static int did_intro = FALSE; 327 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) 328 int did_one; 329 #endif 330 331 if (!screen_valid(TRUE)) 332 return; 333 334 if (must_redraw) 335 { 336 if (type < must_redraw) /* use maximal type */ 337 type = must_redraw; 338 must_redraw = 0; 339 } 340 341 /* Need to update w_lines[]. */ 342 if (curwin->w_lines_valid == 0 && type < NOT_VALID) 343 type = NOT_VALID; 344 345 if (!redrawing()) 346 { 347 redraw_later(type); /* remember type for next time */ 348 must_redraw = type; 349 if (type > INVERTED_ALL) 350 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ 351 return; 352 } 353 354 updating_screen = TRUE; 355 #ifdef FEAT_SYN_HL 356 ++display_tick; /* let syntax code know we're in a next round of 357 * display updating */ 358 #endif 359 360 /* 361 * if the screen was scrolled up when displaying a message, scroll it down 362 */ 363 if (msg_scrolled) 364 { 365 clear_cmdline = TRUE; 366 if (msg_scrolled > Rows - 5) /* clearing is faster */ 367 type = CLEAR; 368 else if (type != CLEAR) 369 { 370 check_for_delay(FALSE); 371 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) 372 type = CLEAR; 373 FOR_ALL_WINDOWS(wp) 374 { 375 if (W_WINROW(wp) < msg_scrolled) 376 { 377 if (W_WINROW(wp) + wp->w_height > msg_scrolled 378 && wp->w_redr_type < REDRAW_TOP 379 && wp->w_lines_valid > 0 380 && wp->w_topline == wp->w_lines[0].wl_lnum) 381 { 382 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); 383 wp->w_redr_type = REDRAW_TOP; 384 } 385 else 386 { 387 wp->w_redr_type = NOT_VALID; 388 #ifdef FEAT_WINDOWS 389 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) 390 <= msg_scrolled) 391 wp->w_redr_status = TRUE; 392 #endif 393 } 394 } 395 } 396 redraw_cmdline = TRUE; 397 } 398 msg_scrolled = 0; 399 need_wait_return = FALSE; 400 } 401 402 /* reset cmdline_row now (may have been changed temporarily) */ 403 compute_cmdrow(); 404 405 /* Check for changed highlighting */ 406 if (need_highlight_changed) 407 highlight_changed(); 408 409 if (type == CLEAR) /* first clear screen */ 410 { 411 screenclear(); /* will reset clear_cmdline */ 412 type = NOT_VALID; 413 } 414 415 if (clear_cmdline) /* going to clear cmdline (done below) */ 416 check_for_delay(FALSE); 417 418 #ifdef FEAT_LINEBREAK 419 /* Force redraw when width of 'number' column changes. */ 420 if (curwin->w_redr_type < NOT_VALID 421 && curwin->w_nrwidth != number_width(curwin)) 422 curwin->w_redr_type = NOT_VALID; 423 #endif 424 425 /* 426 * Only start redrawing if there is really something to do. 427 */ 428 if (type == INVERTED) 429 update_curswant(); 430 if (curwin->w_redr_type < type 431 && !((type == VALID 432 && curwin->w_lines[0].wl_valid 433 #ifdef FEAT_DIFF 434 && curwin->w_topfill == curwin->w_old_topfill 435 && curwin->w_botfill == curwin->w_old_botfill 436 #endif 437 && curwin->w_topline == curwin->w_lines[0].wl_lnum) 438 #ifdef FEAT_VISUAL 439 || (type == INVERTED 440 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum 441 && curwin->w_old_visual_mode == VIsual_mode 442 && (curwin->w_valid & VALID_VIRTCOL) 443 && curwin->w_old_curswant == curwin->w_curswant) 444 #endif 445 )) 446 curwin->w_redr_type = type; 447 448 #ifdef FEAT_SYN_HL 449 /* 450 * Correct stored syntax highlighting info for changes in each displayed 451 * buffer. Each buffer must only be done once. 452 */ 453 FOR_ALL_WINDOWS(wp) 454 { 455 if (wp->w_buffer->b_mod_set) 456 { 457 # ifdef FEAT_WINDOWS 458 win_T *wwp; 459 460 /* Check if we already did this buffer. */ 461 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) 462 if (wwp->w_buffer == wp->w_buffer) 463 break; 464 # endif 465 if ( 466 # ifdef FEAT_WINDOWS 467 wwp == wp && 468 # endif 469 syntax_present(wp->w_buffer)) 470 syn_stack_apply_changes(wp->w_buffer); 471 } 472 } 473 #endif 474 475 /* 476 * Go from top to bottom through the windows, redrawing the ones that need 477 * it. 478 */ 479 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) 480 did_one = FALSE; 481 #endif 482 #ifdef FEAT_SEARCH_EXTRA 483 search_hl.rm.regprog = NULL; 484 #endif 485 FOR_ALL_WINDOWS(wp) 486 { 487 if (wp->w_redr_type != 0) 488 { 489 cursor_off(); 490 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) 491 if (!did_one) 492 { 493 did_one = TRUE; 494 # ifdef FEAT_SEARCH_EXTRA 495 start_search_hl(); 496 # endif 497 # ifdef FEAT_CLIPBOARD 498 /* When Visual area changed, may have to update selection. */ 499 if (clip_star.available && clip_isautosel()) 500 clip_update_selection(); 501 # endif 502 #ifdef FEAT_GUI 503 /* Remove the cursor before starting to do anything, because 504 * scrolling may make it difficult to redraw the text under 505 * it. */ 506 if (gui.in_use) 507 gui_undraw_cursor(); 508 #endif 509 } 510 #endif 511 win_update(wp); 512 } 513 514 #ifdef FEAT_WINDOWS 515 /* redraw status line after the window to minimize cursor movement */ 516 if (wp->w_redr_status) 517 { 518 cursor_off(); 519 win_redr_status(wp); 520 } 521 #endif 522 } 523 #if defined(FEAT_SEARCH_EXTRA) 524 end_search_hl(); 525 #endif 526 527 #ifdef FEAT_WINDOWS 528 /* Reset b_mod_set flags. Going through all windows is probably faster 529 * than going through all buffers (there could be many buffers). */ 530 for (wp = firstwin; wp != NULL; wp = wp->w_next) 531 wp->w_buffer->b_mod_set = FALSE; 532 #else 533 curbuf->b_mod_set = FALSE; 534 #endif 535 536 updating_screen = FALSE; 537 #ifdef FEAT_GUI 538 gui_may_resize_shell(); 539 #endif 540 541 /* Clear or redraw the command line. Done last, because scrolling may 542 * mess up the command line. */ 543 if (clear_cmdline || redraw_cmdline) 544 showmode(); 545 546 /* May put up an introductory message when not editing a file */ 547 if (!did_intro && bufempty() 548 && curbuf->b_fname == NULL 549 #ifdef FEAT_WINDOWS 550 && firstwin->w_next == NULL 551 #endif 552 && vim_strchr(p_shm, SHM_INTRO) == NULL) 553 intro_message(FALSE); 554 did_intro = TRUE; 555 556 #ifdef FEAT_GUI 557 /* Redraw the cursor and update the scrollbars when all screen updating is 558 * done. */ 559 if (gui.in_use) 560 { 561 out_flush(); /* required before updating the cursor */ 562 if (did_one) 563 gui_update_cursor(FALSE, FALSE); 564 gui_update_scrollbars(FALSE); 565 } 566 #endif 567 } 568 569 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) 570 static void update_prepare __ARGS((void)); 571 static void update_finish __ARGS((void)); 572 573 /* 574 * Prepare for updating one or more windows. 575 */ 576 static void 577 update_prepare() 578 { 579 cursor_off(); 580 updating_screen = TRUE; 581 #ifdef FEAT_GUI 582 /* Remove the cursor before starting to do anything, because scrolling may 583 * make it difficult to redraw the text under it. */ 584 if (gui.in_use) 585 gui_undraw_cursor(); 586 #endif 587 #ifdef FEAT_SEARCH_EXTRA 588 start_search_hl(); 589 #endif 590 } 591 592 /* 593 * Finish updating one or more windows. 594 */ 595 static void 596 update_finish() 597 { 598 if (redraw_cmdline) 599 showmode(); 600 601 # ifdef FEAT_SEARCH_EXTRA 602 end_search_hl(); 603 # endif 604 605 updating_screen = FALSE; 606 607 # ifdef FEAT_GUI 608 gui_may_resize_shell(); 609 610 /* Redraw the cursor and update the scrollbars when all screen updating is 611 * done. */ 612 if (gui.in_use) 613 { 614 out_flush(); /* required before updating the cursor */ 615 gui_update_cursor(FALSE, FALSE); 616 gui_update_scrollbars(FALSE); 617 } 618 # endif 619 } 620 #endif 621 622 #if defined(FEAT_SIGNS) || defined(PROTO) 623 void 624 update_debug_sign(buf, lnum) 625 buf_T *buf; 626 linenr_T lnum; 627 { 628 win_T *wp; 629 int doit = FALSE; 630 631 # ifdef FEAT_FOLDING 632 win_foldinfo.fi_level = 0; 633 # endif 634 635 /* update/delete a specific mark */ 636 FOR_ALL_WINDOWS(wp) 637 { 638 if (buf != NULL && lnum > 0) 639 { 640 if (wp->w_buffer == buf && lnum >= wp->w_topline 641 && lnum < wp->w_botline) 642 { 643 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) 644 wp->w_redraw_top = lnum; 645 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) 646 wp->w_redraw_bot = lnum; 647 redraw_win_later(wp, VALID); 648 } 649 } 650 else 651 redraw_win_later(wp, VALID); 652 if (wp->w_redr_type != 0) 653 doit = TRUE; 654 } 655 656 if (!doit) 657 return; 658 659 /* update all windows that need updating */ 660 update_prepare(); 661 662 # ifdef FEAT_WINDOWS 663 for (wp = firstwin; wp; wp = wp->w_next) 664 { 665 if (wp->w_redr_type != 0) 666 win_update(wp); 667 if (wp->w_redr_status) 668 win_redr_status(wp); 669 } 670 # else 671 if (curwin->w_redr_type != 0) 672 win_update(curwin); 673 # endif 674 675 update_finish(); 676 } 677 #endif 678 679 680 #if defined(FEAT_GUI) || defined(PROTO) 681 /* 682 * Update a single window, its status line and maybe the command line msg. 683 * Used for the GUI scrollbar. 684 */ 685 void 686 updateWindow(wp) 687 win_T *wp; 688 { 689 update_prepare(); 690 691 #ifdef FEAT_CLIPBOARD 692 /* When Visual area changed, may have to update selection. */ 693 if (clip_star.available && clip_isautosel()) 694 clip_update_selection(); 695 #endif 696 win_update(wp); 697 #ifdef FEAT_WINDOWS 698 if (wp->w_redr_status 699 # ifdef FEAT_CMDL_INFO 700 || p_ru 701 # endif 702 # ifdef FEAT_STL_OPT 703 || *p_stl 704 # endif 705 ) 706 win_redr_status(wp); 707 #endif 708 709 update_finish(); 710 } 711 #endif 712 713 /* 714 * Update a single window. 715 * 716 * This may cause the windows below it also to be redrawn (when clearing the 717 * screen or scrolling lines). 718 * 719 * How the window is redrawn depends on wp->w_redr_type. Each type also 720 * implies the one below it. 721 * NOT_VALID redraw the whole window 722 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID 723 * INVERTED redraw the changed part of the Visual area 724 * INVERTED_ALL redraw the whole Visual area 725 * VALID 1. scroll up/down to adjust for a changed w_topline 726 * 2. update lines at the top when scrolled down 727 * 3. redraw changed text: 728 * - if wp->w_buffer->b_mod_set set, udpate lines between 729 * b_mod_top and b_mod_bot. 730 * - if wp->w_redraw_top non-zero, redraw lines between 731 * wp->w_redraw_top and wp->w_redr_bot. 732 * - continue redrawing when syntax status is invalid. 733 * 4. if scrolled up, update lines at the bottom. 734 * This results in three areas that may need updating: 735 * top: from first row to top_end (when scrolled down) 736 * mid: from mid_start to mid_end (update inversion or changed text) 737 * bot: from bot_start to last row (when scrolled up) 738 */ 739 static void 740 win_update(wp) 741 win_T *wp; 742 { 743 buf_T *buf = wp->w_buffer; 744 int type; 745 int top_end = 0; /* Below last row of the top area that needs 746 updating. 0 when no top area updating. */ 747 int mid_start = 999;/* first row of the mid area that needs 748 updating. 999 when no mid area updating. */ 749 int mid_end = 0; /* Below last row of the mid area that needs 750 updating. 0 when no mid area updating. */ 751 int bot_start = 999;/* first row of the bot area that needs 752 updating. 999 when no bot area updating */ 753 #ifdef FEAT_VISUAL 754 int scrolled_down = FALSE; /* TRUE when scrolled down when 755 w_topline got smaller a bit */ 756 #endif 757 #ifdef FEAT_SEARCH_EXTRA 758 int top_to_mod = FALSE; /* redraw above mod_top */ 759 #endif 760 761 int row; /* current window row to display */ 762 linenr_T lnum; /* current buffer lnum to display */ 763 int idx; /* current index in w_lines[] */ 764 int srow; /* starting row of the current line */ 765 766 int eof = FALSE; /* if TRUE, we hit the end of the file */ 767 int didline = FALSE; /* if TRUE, we finished the last line */ 768 int i; 769 long j; 770 static int recursive = FALSE; /* being called recursively */ 771 int old_botline = wp->w_botline; 772 #ifdef FEAT_FOLDING 773 long fold_count; 774 #endif 775 #ifdef FEAT_SYN_HL 776 /* remember what happened to the previous line, to know if 777 * check_visual_highlight() can be used */ 778 #define DID_NONE 1 /* didn't update a line */ 779 #define DID_LINE 2 /* updated a normal line */ 780 #define DID_FOLD 3 /* updated a folded line */ 781 int did_update = DID_NONE; 782 linenr_T syntax_last_parsed = 0; /* last parsed text line */ 783 #endif 784 linenr_T mod_top = 0; 785 linenr_T mod_bot = 0; 786 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) 787 int save_got_int; 788 #endif 789 790 type = wp->w_redr_type; 791 792 if (type == NOT_VALID) 793 { 794 #ifdef FEAT_WINDOWS 795 wp->w_redr_status = TRUE; 796 #endif 797 wp->w_lines_valid = 0; 798 } 799 800 /* Window is zero-height: nothing to draw. */ 801 if (wp->w_height == 0) 802 { 803 wp->w_redr_type = 0; 804 return; 805 } 806 807 #ifdef FEAT_VERTSPLIT 808 /* Window is zero-width: Only need to draw the separator. */ 809 if (wp->w_width == 0) 810 { 811 /* draw the vertical separator right of this window */ 812 draw_vsep_win(wp, 0); 813 wp->w_redr_type = 0; 814 return; 815 } 816 #endif 817 818 #ifdef FEAT_SEARCH_EXTRA 819 /* Setup for ":match" highlighting. Disable any previous match */ 820 match_hl.rm = wp->w_match; 821 if (wp->w_match_id == 0) 822 match_hl.attr = 0; 823 else 824 match_hl.attr = syn_id2attr(wp->w_match_id); 825 match_hl.buf = buf; 826 match_hl.lnum = 0; 827 search_hl.buf = buf; 828 search_hl.lnum = 0; 829 search_hl.first_lnum = 0; 830 #endif 831 832 #ifdef FEAT_LINEBREAK 833 /* Force redraw when width of 'number' column changes. */ 834 i = number_width(curwin); 835 if (curwin->w_nrwidth != i) 836 { 837 type = NOT_VALID; 838 curwin->w_nrwidth = i; 839 } 840 else 841 #endif 842 843 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) 844 { 845 /* 846 * When there are both inserted/deleted lines and specific lines to be 847 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw 848 * everything (only happens when redrawing is off for while). 849 */ 850 type = NOT_VALID; 851 } 852 else 853 { 854 /* 855 * Set mod_top to the first line that needs displaying because of 856 * changes. Set mod_bot to the first line after the changes. 857 */ 858 mod_top = wp->w_redraw_top; 859 if (wp->w_redraw_bot != 0) 860 mod_bot = wp->w_redraw_bot + 1; 861 else 862 mod_bot = 0; 863 wp->w_redraw_top = 0; /* reset for next time */ 864 wp->w_redraw_bot = 0; 865 if (buf->b_mod_set) 866 { 867 if (mod_top == 0 || mod_top > buf->b_mod_top) 868 { 869 mod_top = buf->b_mod_top; 870 #ifdef FEAT_SYN_HL 871 /* Need to redraw lines above the change that may be included 872 * in a pattern match. */ 873 if (syntax_present(buf)) 874 { 875 mod_top -= buf->b_syn_sync_linebreaks; 876 if (mod_top < 1) 877 mod_top = 1; 878 } 879 #endif 880 } 881 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) 882 mod_bot = buf->b_mod_bot; 883 884 #ifdef FEAT_SEARCH_EXTRA 885 /* When 'hlsearch' is on and using a multi-line search pattern, a 886 * change in one line may make the Search highlighting in a 887 * previous line invalid. Simple solution: redraw all visible 888 * lines above the change. 889 * Same for a ":match" pattern. 890 */ 891 if ((search_hl.rm.regprog != NULL 892 && re_multiline(search_hl.rm.regprog)) 893 || (match_hl.rm.regprog != NULL 894 && re_multiline(match_hl.rm.regprog))) 895 top_to_mod = TRUE; 896 #endif 897 } 898 #ifdef FEAT_FOLDING 899 if (mod_top != 0 && hasAnyFolding(wp)) 900 { 901 linenr_T lnumt, lnumb; 902 903 /* 904 * A change in a line can cause lines above it to become folded or 905 * unfolded. Find the top most buffer line that may be affected. 906 * If the line was previously folded and displayed, get the first 907 * line of that fold. If the line is folded now, get the first 908 * folded line. Use the minimum of these two. 909 */ 910 911 /* Find last valid w_lines[] entry above mod_top. Set lnumt to 912 * the line below it. If there is no valid entry, use w_topline. 913 * Find the first valid w_lines[] entry below mod_bot. Set lnumb 914 * to this line. If there is no valid entry, use MAXLNUM. */ 915 lnumt = wp->w_topline; 916 lnumb = MAXLNUM; 917 for (i = 0; i < wp->w_lines_valid; ++i) 918 if (wp->w_lines[i].wl_valid) 919 { 920 if (wp->w_lines[i].wl_lastlnum < mod_top) 921 lnumt = wp->w_lines[i].wl_lastlnum + 1; 922 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) 923 { 924 lnumb = wp->w_lines[i].wl_lnum; 925 /* When there is a fold column it might need updating 926 * in the next line ("J" just above an open fold). */ 927 if (wp->w_p_fdc > 0) 928 ++lnumb; 929 } 930 } 931 932 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); 933 if (mod_top > lnumt) 934 mod_top = lnumt; 935 936 /* Now do the same for the bottom line (one above mod_bot). */ 937 --mod_bot; 938 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); 939 ++mod_bot; 940 if (mod_bot < lnumb) 941 mod_bot = lnumb; 942 } 943 #endif 944 945 /* When a change starts above w_topline and the end is below 946 * w_topline, start redrawing at w_topline. 947 * If the end of the change is above w_topline: do like no changes was 948 * maded, but redraw the first line to find changes in syntax. */ 949 if (mod_top != 0 && mod_top < wp->w_topline) 950 { 951 if (mod_bot > wp->w_topline) 952 mod_top = wp->w_topline; 953 #ifdef FEAT_SYN_HL 954 else if (syntax_present(buf)) 955 top_end = 1; 956 #endif 957 } 958 } 959 960 /* 961 * When only displaying the lines at the top, set top_end. Used when 962 * window has scrolled down for msg_scrolled. 963 */ 964 if (type == REDRAW_TOP) 965 { 966 j = 0; 967 for (i = 0; i < wp->w_lines_valid; ++i) 968 { 969 j += wp->w_lines[i].wl_size; 970 if (j >= wp->w_upd_rows) 971 { 972 top_end = j; 973 break; 974 } 975 } 976 if (top_end == 0) 977 /* not found (cannot happen?): redraw everything */ 978 type = NOT_VALID; 979 else 980 /* top area defined, the rest is VALID */ 981 type = VALID; 982 } 983 984 /* 985 * If there are no changes on the screen that require a complete redraw, 986 * handle three cases: 987 * 1: we are off the top of the screen by a few lines: scroll down 988 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up 989 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in 990 * w_lines[] that needs updating. 991 */ 992 if ((type == VALID || type == INVERTED || type == INVERTED_ALL) 993 #ifdef FEAT_DIFF 994 && !wp->w_botfill && !wp->w_old_botfill 995 #endif 996 ) 997 { 998 if (mod_top != 0 && wp->w_topline == mod_top) 999 { 1000 /* 1001 * w_topline is the first changed line, the scrolling will be done 1002 * further down. 1003 */ 1004 } 1005 else if (wp->w_lines[0].wl_valid 1006 && (wp->w_topline < wp->w_lines[0].wl_lnum 1007 #ifdef FEAT_DIFF 1008 || (wp->w_topline == wp->w_lines[0].wl_lnum 1009 && wp->w_topfill > wp->w_old_topfill) 1010 #endif 1011 )) 1012 { 1013 /* 1014 * New topline is above old topline: May scroll down. 1015 */ 1016 #ifdef FEAT_FOLDING 1017 if (hasAnyFolding(wp)) 1018 { 1019 linenr_T ln; 1020 1021 /* count the number of lines we are off, counting a sequence 1022 * of folded lines as one */ 1023 j = 0; 1024 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) 1025 { 1026 ++j; 1027 if (j >= wp->w_height - 2) 1028 break; 1029 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); 1030 } 1031 } 1032 else 1033 #endif 1034 j = wp->w_lines[0].wl_lnum - wp->w_topline; 1035 if (j < wp->w_height - 2) /* not too far off */ 1036 { 1037 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); 1038 #ifdef FEAT_DIFF 1039 /* insert extra lines for previously invisible filler lines */ 1040 if (wp->w_lines[0].wl_lnum != wp->w_topline) 1041 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) 1042 - wp->w_old_topfill; 1043 #endif 1044 if (i < wp->w_height - 2) /* less than a screen off */ 1045 { 1046 /* 1047 * Try to insert the correct number of lines. 1048 * If not the last window, delete the lines at the bottom. 1049 * win_ins_lines may fail when the terminal can't do it. 1050 */ 1051 if (i > 0) 1052 check_for_delay(FALSE); 1053 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) 1054 { 1055 if (wp->w_lines_valid != 0) 1056 { 1057 /* Need to update rows that are new, stop at the 1058 * first one that scrolled down. */ 1059 top_end = i; 1060 #ifdef FEAT_VISUAL 1061 scrolled_down = TRUE; 1062 #endif 1063 1064 /* Move the entries that were scrolled, disable 1065 * the entries for the lines to be redrawn. */ 1066 if ((wp->w_lines_valid += j) > wp->w_height) 1067 wp->w_lines_valid = wp->w_height; 1068 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) 1069 wp->w_lines[idx] = wp->w_lines[idx - j]; 1070 while (idx >= 0) 1071 wp->w_lines[idx--].wl_valid = FALSE; 1072 } 1073 } 1074 else 1075 mid_start = 0; /* redraw all lines */ 1076 } 1077 else 1078 mid_start = 0; /* redraw all lines */ 1079 } 1080 else 1081 mid_start = 0; /* redraw all lines */ 1082 } 1083 else 1084 { 1085 /* 1086 * New topline is at or below old topline: May scroll up. 1087 * When topline didn't change, find first entry in w_lines[] that 1088 * needs updating. 1089 */ 1090 1091 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ 1092 j = -1; 1093 row = 0; 1094 for (i = 0; i < wp->w_lines_valid; i++) 1095 { 1096 if (wp->w_lines[i].wl_valid 1097 && wp->w_lines[i].wl_lnum == wp->w_topline) 1098 { 1099 j = i; 1100 break; 1101 } 1102 row += wp->w_lines[i].wl_size; 1103 } 1104 if (j == -1) 1105 { 1106 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all 1107 * lines */ 1108 mid_start = 0; 1109 } 1110 else 1111 { 1112 /* 1113 * Try to delete the correct number of lines. 1114 * wp->w_topline is at wp->w_lines[i].wl_lnum. 1115 */ 1116 #ifdef FEAT_DIFF 1117 /* If the topline didn't change, delete old filler lines, 1118 * otherwise delete filler lines of the new topline... */ 1119 if (wp->w_lines[0].wl_lnum == wp->w_topline) 1120 row += wp->w_old_topfill; 1121 else 1122 row += diff_check_fill(wp, wp->w_topline); 1123 /* ... but don't delete new filler lines. */ 1124 row -= wp->w_topfill; 1125 #endif 1126 if (row > 0) 1127 { 1128 check_for_delay(FALSE); 1129 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) 1130 bot_start = wp->w_height - row; 1131 else 1132 mid_start = 0; /* redraw all lines */ 1133 } 1134 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) 1135 { 1136 /* 1137 * Skip the lines (below the deleted lines) that are still 1138 * valid and don't need redrawing. Copy their info 1139 * upwards, to compensate for the deleted lines. Set 1140 * bot_start to the first row that needs redrawing. 1141 */ 1142 bot_start = 0; 1143 idx = 0; 1144 for (;;) 1145 { 1146 wp->w_lines[idx] = wp->w_lines[j]; 1147 /* stop at line that didn't fit, unless it is still 1148 * valid (no lines deleted) */ 1149 if (row > 0 && bot_start + row 1150 + (int)wp->w_lines[j].wl_size > wp->w_height) 1151 { 1152 wp->w_lines_valid = idx + 1; 1153 break; 1154 } 1155 bot_start += wp->w_lines[idx++].wl_size; 1156 1157 /* stop at the last valid entry in w_lines[].wl_size */ 1158 if (++j >= wp->w_lines_valid) 1159 { 1160 wp->w_lines_valid = idx; 1161 break; 1162 } 1163 } 1164 #ifdef FEAT_DIFF 1165 /* Correct the first entry for filler lines at the top 1166 * when it won't get updated below. */ 1167 if (wp->w_p_diff && bot_start > 0) 1168 wp->w_lines[0].wl_size = 1169 plines_win_nofill(wp, wp->w_topline, TRUE) 1170 + wp->w_topfill; 1171 #endif 1172 } 1173 } 1174 } 1175 1176 /* When starting redraw in the first line, redraw all lines. When 1177 * there is only one window it's probably faster to clear the screen 1178 * first. */ 1179 if (mid_start == 0) 1180 { 1181 mid_end = wp->w_height; 1182 if (lastwin == firstwin) 1183 screenclear(); 1184 } 1185 } 1186 else 1187 { 1188 /* Not VALID or INVERTED: redraw all lines. */ 1189 mid_start = 0; 1190 mid_end = wp->w_height; 1191 } 1192 1193 #ifdef FEAT_VISUAL 1194 /* check if we are updating or removing the inverted part */ 1195 if ((VIsual_active && buf == curwin->w_buffer) 1196 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) 1197 { 1198 linenr_T from, to; 1199 1200 if (VIsual_active) 1201 { 1202 if (VIsual_active 1203 && (VIsual_mode != wp->w_old_visual_mode 1204 || type == INVERTED_ALL)) 1205 { 1206 /* 1207 * If the type of Visual selection changed, redraw the whole 1208 * selection. Also when the ownership of the X selection is 1209 * gained or lost. 1210 */ 1211 if (curwin->w_cursor.lnum < VIsual.lnum) 1212 { 1213 from = curwin->w_cursor.lnum; 1214 to = VIsual.lnum; 1215 } 1216 else 1217 { 1218 from = VIsual.lnum; 1219 to = curwin->w_cursor.lnum; 1220 } 1221 /* redraw more when the cursor moved as well */ 1222 if (wp->w_old_cursor_lnum < from) 1223 from = wp->w_old_cursor_lnum; 1224 if (wp->w_old_cursor_lnum > to) 1225 to = wp->w_old_cursor_lnum; 1226 if (wp->w_old_visual_lnum < from) 1227 from = wp->w_old_visual_lnum; 1228 if (wp->w_old_visual_lnum > to) 1229 to = wp->w_old_visual_lnum; 1230 } 1231 else 1232 { 1233 /* 1234 * Find the line numbers that need to be updated: The lines 1235 * between the old cursor position and the current cursor 1236 * position. Also check if the Visual position changed. 1237 */ 1238 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) 1239 { 1240 from = curwin->w_cursor.lnum; 1241 to = wp->w_old_cursor_lnum; 1242 } 1243 else 1244 { 1245 from = wp->w_old_cursor_lnum; 1246 to = curwin->w_cursor.lnum; 1247 if (from == 0) /* Visual mode just started */ 1248 from = to; 1249 } 1250 1251 if (VIsual.lnum != wp->w_old_visual_lnum) 1252 { 1253 if (wp->w_old_visual_lnum < from 1254 && wp->w_old_visual_lnum != 0) 1255 from = wp->w_old_visual_lnum; 1256 if (wp->w_old_visual_lnum > to) 1257 to = wp->w_old_visual_lnum; 1258 if (VIsual.lnum < from) 1259 from = VIsual.lnum; 1260 if (VIsual.lnum > to) 1261 to = VIsual.lnum; 1262 } 1263 } 1264 1265 /* 1266 * If in block mode and changed column or curwin->w_curswant: 1267 * update all lines. 1268 * First compute the actual start and end column. 1269 */ 1270 if (VIsual_mode == Ctrl_V) 1271 { 1272 colnr_T fromc, toc; 1273 1274 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); 1275 ++toc; 1276 if (curwin->w_curswant == MAXCOL) 1277 toc = MAXCOL; 1278 1279 if (fromc != wp->w_old_cursor_fcol 1280 || toc != wp->w_old_cursor_lcol) 1281 { 1282 if (from > VIsual.lnum) 1283 from = VIsual.lnum; 1284 if (to < VIsual.lnum) 1285 to = VIsual.lnum; 1286 } 1287 wp->w_old_cursor_fcol = fromc; 1288 wp->w_old_cursor_lcol = toc; 1289 } 1290 } 1291 else 1292 { 1293 /* Use the line numbers of the old Visual area. */ 1294 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) 1295 { 1296 from = wp->w_old_cursor_lnum; 1297 to = wp->w_old_visual_lnum; 1298 } 1299 else 1300 { 1301 from = wp->w_old_visual_lnum; 1302 to = wp->w_old_cursor_lnum; 1303 } 1304 } 1305 1306 /* 1307 * There is no need to update lines above the top of the window. 1308 */ 1309 if (from < wp->w_topline) 1310 from = wp->w_topline; 1311 1312 /* 1313 * If we know the value of w_botline, use it to restrict the update to 1314 * the lines that are visible in the window. 1315 */ 1316 if (wp->w_valid & VALID_BOTLINE) 1317 { 1318 if (from >= wp->w_botline) 1319 from = wp->w_botline - 1; 1320 if (to >= wp->w_botline) 1321 to = wp->w_botline - 1; 1322 } 1323 1324 /* 1325 * Find the minimal part to be updated. 1326 * Watch out for scrolling that made entries in w_lines[] invalid. 1327 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets 1328 * top_end; need to redraw from top_end to the "to" line. 1329 * A middle mouse click with a Visual selection may change the text 1330 * above the Visual area and reset wl_valid, do count these for 1331 * mid_end (in srow). 1332 */ 1333 if (mid_start > 0) 1334 { 1335 lnum = wp->w_topline; 1336 idx = 0; 1337 srow = 0; 1338 if (scrolled_down) 1339 mid_start = top_end; 1340 else 1341 mid_start = 0; 1342 while (lnum < from && idx < wp->w_lines_valid) /* find start */ 1343 { 1344 if (wp->w_lines[idx].wl_valid) 1345 mid_start += wp->w_lines[idx].wl_size; 1346 else if (!scrolled_down) 1347 srow += wp->w_lines[idx].wl_size; 1348 ++idx; 1349 # ifdef FEAT_FOLDING 1350 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) 1351 lnum = wp->w_lines[idx].wl_lnum; 1352 else 1353 # endif 1354 ++lnum; 1355 } 1356 srow += mid_start; 1357 mid_end = wp->w_height; 1358 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ 1359 { 1360 if (wp->w_lines[idx].wl_valid 1361 && wp->w_lines[idx].wl_lnum >= to + 1) 1362 { 1363 /* Only update until first row of this line */ 1364 mid_end = srow; 1365 break; 1366 } 1367 srow += wp->w_lines[idx].wl_size; 1368 } 1369 } 1370 } 1371 1372 if (VIsual_active && buf == curwin->w_buffer) 1373 { 1374 wp->w_old_visual_mode = VIsual_mode; 1375 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; 1376 wp->w_old_visual_lnum = VIsual.lnum; 1377 wp->w_old_curswant = curwin->w_curswant; 1378 } 1379 else 1380 { 1381 wp->w_old_visual_mode = 0; 1382 wp->w_old_cursor_lnum = 0; 1383 wp->w_old_visual_lnum = 0; 1384 } 1385 #endif /* FEAT_VISUAL */ 1386 1387 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) 1388 /* reset got_int, otherwise regexp won't work */ 1389 save_got_int = got_int; 1390 got_int = 0; 1391 #endif 1392 #ifdef FEAT_FOLDING 1393 win_foldinfo.fi_level = 0; 1394 #endif 1395 1396 /* 1397 * Update all the window rows. 1398 */ 1399 idx = 0; /* first entry in w_lines[].wl_size */ 1400 row = 0; 1401 srow = 0; 1402 lnum = wp->w_topline; /* first line shown in window */ 1403 for (;;) 1404 { 1405 /* stop updating when reached the end of the window (check for _past_ 1406 * the end of the window is at the end of the loop) */ 1407 if (row == wp->w_height) 1408 { 1409 didline = TRUE; 1410 break; 1411 } 1412 1413 /* stop updating when hit the end of the file */ 1414 if (lnum > buf->b_ml.ml_line_count) 1415 { 1416 eof = TRUE; 1417 break; 1418 } 1419 1420 /* Remember the starting row of the line that is going to be dealt 1421 * with. It is used further down when the line doesn't fit. */ 1422 srow = row; 1423 1424 /* 1425 * Update a line when it is in an area that needs updating, when it 1426 * has changes or w_lines[idx] is invalid. 1427 * bot_start may be halfway a wrapped line after using 1428 * win_del_lines(), check if the current line includes it. 1429 * When syntax folding is being used, the saved syntax states will 1430 * already have been updated, we can't see where the syntax state is 1431 * the same again, just update until the end of the window. 1432 */ 1433 if (row < top_end 1434 || (row >= mid_start && row < mid_end) 1435 #ifdef FEAT_SEARCH_EXTRA 1436 || top_to_mod 1437 #endif 1438 || idx >= wp->w_lines_valid 1439 || (row + wp->w_lines[idx].wl_size > bot_start) 1440 || (mod_top != 0 1441 && (lnum == mod_top 1442 || (lnum >= mod_top 1443 && (lnum < mod_bot 1444 #ifdef FEAT_SYN_HL 1445 || did_update == DID_FOLD 1446 || (did_update == DID_LINE 1447 && syntax_present(buf) 1448 && ( 1449 # ifdef FEAT_FOLDING 1450 (foldmethodIsSyntax(wp) 1451 && hasAnyFolding(wp)) || 1452 # endif 1453 syntax_check_changed(lnum))) 1454 #endif 1455 ))))) 1456 { 1457 #ifdef FEAT_SEARCH_EXTRA 1458 if (lnum == mod_top) 1459 top_to_mod = FALSE; 1460 #endif 1461 1462 /* 1463 * When at start of changed lines: May scroll following lines 1464 * up or down to minimize redrawing. 1465 * Don't do this when the change continues until the end. 1466 * Don't scroll when dollar_vcol is non-zero, keep the "$". 1467 */ 1468 if (lnum == mod_top 1469 && mod_bot != MAXLNUM 1470 && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) 1471 { 1472 int old_rows = 0; 1473 int new_rows = 0; 1474 int xtra_rows; 1475 linenr_T l; 1476 1477 /* Count the old number of window rows, using w_lines[], which 1478 * should still contain the sizes for the lines as they are 1479 * currently displayed. */ 1480 for (i = idx; i < wp->w_lines_valid; ++i) 1481 { 1482 /* Only valid lines have a meaningful wl_lnum. Invalid 1483 * lines are part of the changed area. */ 1484 if (wp->w_lines[i].wl_valid 1485 && wp->w_lines[i].wl_lnum == mod_bot) 1486 break; 1487 old_rows += wp->w_lines[i].wl_size; 1488 #ifdef FEAT_FOLDING 1489 if (wp->w_lines[i].wl_valid 1490 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) 1491 { 1492 /* Must have found the last valid entry above mod_bot. 1493 * Add following invalid entries. */ 1494 ++i; 1495 while (i < wp->w_lines_valid 1496 && !wp->w_lines[i].wl_valid) 1497 old_rows += wp->w_lines[i++].wl_size; 1498 break; 1499 } 1500 #endif 1501 } 1502 1503 if (i >= wp->w_lines_valid) 1504 { 1505 /* We can't find a valid line below the changed lines, 1506 * need to redraw until the end of the window. 1507 * Inserting/deleting lines has no use. */ 1508 bot_start = 0; 1509 } 1510 else 1511 { 1512 /* Able to count old number of rows: Count new window 1513 * rows, and may insert/delete lines */ 1514 j = idx; 1515 for (l = lnum; l < mod_bot; ++l) 1516 { 1517 #ifdef FEAT_FOLDING 1518 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) 1519 ++new_rows; 1520 else 1521 #endif 1522 #ifdef FEAT_DIFF 1523 if (l == wp->w_topline) 1524 new_rows += plines_win_nofill(wp, l, TRUE) 1525 + wp->w_topfill; 1526 else 1527 #endif 1528 new_rows += plines_win(wp, l, TRUE); 1529 ++j; 1530 if (new_rows > wp->w_height - row - 2) 1531 { 1532 /* it's getting too much, must redraw the rest */ 1533 new_rows = 9999; 1534 break; 1535 } 1536 } 1537 xtra_rows = new_rows - old_rows; 1538 if (xtra_rows < 0) 1539 { 1540 /* May scroll text up. If there is not enough 1541 * remaining text or scrolling fails, must redraw the 1542 * rest. If scrolling works, must redraw the text 1543 * below the scrolled text. */ 1544 if (row - xtra_rows >= wp->w_height - 2) 1545 mod_bot = MAXLNUM; 1546 else 1547 { 1548 check_for_delay(FALSE); 1549 if (win_del_lines(wp, row, 1550 -xtra_rows, FALSE, FALSE) == FAIL) 1551 mod_bot = MAXLNUM; 1552 else 1553 bot_start = wp->w_height + xtra_rows; 1554 } 1555 } 1556 else if (xtra_rows > 0) 1557 { 1558 /* May scroll text down. If there is not enough 1559 * remaining text of scrolling fails, must redraw the 1560 * rest. */ 1561 if (row + xtra_rows >= wp->w_height - 2) 1562 mod_bot = MAXLNUM; 1563 else 1564 { 1565 check_for_delay(FALSE); 1566 if (win_ins_lines(wp, row + old_rows, 1567 xtra_rows, FALSE, FALSE) == FAIL) 1568 mod_bot = MAXLNUM; 1569 else if (top_end > row + old_rows) 1570 /* Scrolled the part at the top that requires 1571 * updating down. */ 1572 top_end += xtra_rows; 1573 } 1574 } 1575 1576 /* When not updating the rest, may need to move w_lines[] 1577 * entries. */ 1578 if (mod_bot != MAXLNUM && i != j) 1579 { 1580 if (j < i) 1581 { 1582 int x = row + new_rows; 1583 1584 /* move entries in w_lines[] upwards */ 1585 for (;;) 1586 { 1587 /* stop at last valid entry in w_lines[] */ 1588 if (i >= wp->w_lines_valid) 1589 { 1590 wp->w_lines_valid = j; 1591 break; 1592 } 1593 wp->w_lines[j] = wp->w_lines[i]; 1594 /* stop at a line that won't fit */ 1595 if (x + (int)wp->w_lines[j].wl_size 1596 > wp->w_height) 1597 { 1598 wp->w_lines_valid = j + 1; 1599 break; 1600 } 1601 x += wp->w_lines[j++].wl_size; 1602 ++i; 1603 } 1604 if (bot_start > x) 1605 bot_start = x; 1606 } 1607 else /* j > i */ 1608 { 1609 /* move entries in w_lines[] downwards */ 1610 j -= i; 1611 wp->w_lines_valid += j; 1612 if (wp->w_lines_valid > wp->w_height) 1613 wp->w_lines_valid = wp->w_height; 1614 for (i = wp->w_lines_valid; i - j >= idx; --i) 1615 wp->w_lines[i] = wp->w_lines[i - j]; 1616 1617 /* The w_lines[] entries for inserted lines are 1618 * now invalid, but wl_size may be used above. 1619 * Reset to zero. */ 1620 while (i >= idx) 1621 { 1622 wp->w_lines[i].wl_size = 0; 1623 wp->w_lines[i--].wl_valid = FALSE; 1624 } 1625 } 1626 } 1627 } 1628 1629 /* When inserting or deleting lines and 'number' is set: 1630 * Redraw all lines below the change to update the line 1631 * numbers. */ 1632 if (buf->b_mod_xlines != 0 && wp->w_p_nu) 1633 bot_start = 0; 1634 } 1635 1636 #ifdef FEAT_FOLDING 1637 /* 1638 * When lines are folded, display one line for all of them. 1639 * Otherwise, display normally (can be several display lines when 1640 * 'wrap' is on). 1641 */ 1642 fold_count = foldedCount(wp, lnum, &win_foldinfo); 1643 if (fold_count != 0) 1644 { 1645 fold_line(wp, fold_count, &win_foldinfo, lnum, row); 1646 ++row; 1647 --fold_count; 1648 wp->w_lines[idx].wl_folded = TRUE; 1649 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; 1650 # ifdef FEAT_SYN_HL 1651 did_update = DID_FOLD; 1652 # endif 1653 } 1654 else 1655 #endif 1656 if (idx < wp->w_lines_valid 1657 && wp->w_lines[idx].wl_valid 1658 && wp->w_lines[idx].wl_lnum == lnum 1659 && lnum > wp->w_topline 1660 && !(dy_flags & DY_LASTLINE) 1661 && srow + wp->w_lines[idx].wl_size > wp->w_height 1662 #ifdef FEAT_DIFF 1663 && diff_check_fill(wp, lnum) == 0 1664 #endif 1665 ) 1666 { 1667 /* This line is not going to fit. Don't draw anything here, 1668 * will draw "@ " lines below. */ 1669 row = wp->w_height + 1; 1670 } 1671 else 1672 { 1673 #ifdef FEAT_SEARCH_EXTRA 1674 prepare_search_hl(wp, lnum); 1675 #endif 1676 #ifdef FEAT_SYN_HL 1677 /* Let the syntax stuff know we skipped a few lines. */ 1678 if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum 1679 && syntax_present(buf)) 1680 syntax_end_parsing(syntax_last_parsed + 1); 1681 #endif 1682 1683 /* 1684 * Display one line. 1685 */ 1686 row = win_line(wp, lnum, srow, wp->w_height); 1687 1688 #ifdef FEAT_FOLDING 1689 wp->w_lines[idx].wl_folded = FALSE; 1690 wp->w_lines[idx].wl_lastlnum = lnum; 1691 #endif 1692 #ifdef FEAT_SYN_HL 1693 did_update = DID_LINE; 1694 syntax_last_parsed = lnum; 1695 #endif 1696 } 1697 1698 wp->w_lines[idx].wl_lnum = lnum; 1699 wp->w_lines[idx].wl_valid = TRUE; 1700 if (row > wp->w_height) /* past end of screen */ 1701 { 1702 /* we may need the size of that too long line later on */ 1703 if (dollar_vcol == 0) 1704 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); 1705 ++idx; 1706 break; 1707 } 1708 if (dollar_vcol == 0) 1709 wp->w_lines[idx].wl_size = row - srow; 1710 ++idx; 1711 #ifdef FEAT_FOLDING 1712 lnum += fold_count + 1; 1713 #else 1714 ++lnum; 1715 #endif 1716 } 1717 else 1718 { 1719 /* This line does not need updating, advance to the next one */ 1720 row += wp->w_lines[idx++].wl_size; 1721 if (row > wp->w_height) /* past end of screen */ 1722 break; 1723 #ifdef FEAT_FOLDING 1724 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; 1725 #else 1726 ++lnum; 1727 #endif 1728 #ifdef FEAT_SYN_HL 1729 did_update = DID_NONE; 1730 #endif 1731 } 1732 1733 if (lnum > buf->b_ml.ml_line_count) 1734 { 1735 eof = TRUE; 1736 break; 1737 } 1738 } 1739 /* 1740 * End of loop over all window lines. 1741 */ 1742 1743 1744 if (idx > wp->w_lines_valid) 1745 wp->w_lines_valid = idx; 1746 1747 #ifdef FEAT_SYN_HL 1748 /* 1749 * Let the syntax stuff know we stop parsing here. 1750 */ 1751 if (syntax_last_parsed != 0 && syntax_present(buf)) 1752 syntax_end_parsing(syntax_last_parsed + 1); 1753 #endif 1754 1755 /* 1756 * If we didn't hit the end of the file, and we didn't finish the last 1757 * line we were working on, then the line didn't fit. 1758 */ 1759 wp->w_empty_rows = 0; 1760 #ifdef FEAT_DIFF 1761 wp->w_filler_rows = 0; 1762 #endif 1763 if (!eof && !didline) 1764 { 1765 if (lnum == wp->w_topline) 1766 { 1767 /* 1768 * Single line that does not fit! 1769 * Don't overwrite it, it can be edited. 1770 */ 1771 wp->w_botline = lnum + 1; 1772 } 1773 #ifdef FEAT_DIFF 1774 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) 1775 { 1776 /* Window ends in filler lines. */ 1777 wp->w_botline = lnum; 1778 wp->w_filler_rows = wp->w_height - srow; 1779 } 1780 #endif 1781 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ 1782 { 1783 /* 1784 * Last line isn't finished: Display "@@@" at the end. 1785 */ 1786 screen_fill(W_WINROW(wp) + wp->w_height - 1, 1787 W_WINROW(wp) + wp->w_height, 1788 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), 1789 '@', '@', hl_attr(HLF_AT)); 1790 set_empty_rows(wp, srow); 1791 wp->w_botline = lnum; 1792 } 1793 else 1794 { 1795 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); 1796 wp->w_botline = lnum; 1797 } 1798 } 1799 else 1800 { 1801 #ifdef FEAT_VERTSPLIT 1802 draw_vsep_win(wp, row); 1803 #endif 1804 if (eof) /* we hit the end of the file */ 1805 { 1806 wp->w_botline = buf->b_ml.ml_line_count + 1; 1807 #ifdef FEAT_DIFF 1808 j = diff_check_fill(wp, wp->w_botline); 1809 if (j > 0 && !wp->w_botfill) 1810 { 1811 /* 1812 * Display filler lines at the end of the file 1813 */ 1814 if (char2cells(fill_diff) > 1) 1815 i = '-'; 1816 else 1817 i = fill_diff; 1818 if (row + j > wp->w_height) 1819 j = wp->w_height - row; 1820 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); 1821 row += j; 1822 } 1823 #endif 1824 } 1825 else if (dollar_vcol == 0) 1826 wp->w_botline = lnum; 1827 1828 /* make sure the rest of the screen is blank */ 1829 /* put '~'s on rows that aren't part of the file. */ 1830 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); 1831 } 1832 1833 /* Reset the type of redrawing required, the window has been updated. */ 1834 wp->w_redr_type = 0; 1835 #ifdef FEAT_DIFF 1836 wp->w_old_topfill = wp->w_topfill; 1837 wp->w_old_botfill = wp->w_botfill; 1838 #endif 1839 1840 if (dollar_vcol == 0) 1841 { 1842 /* 1843 * There is a trick with w_botline. If we invalidate it on each 1844 * change that might modify it, this will cause a lot of expensive 1845 * calls to plines() in update_topline() each time. Therefore the 1846 * value of w_botline is often approximated, and this value is used to 1847 * compute the value of w_topline. If the value of w_botline was 1848 * wrong, check that the value of w_topline is correct (cursor is on 1849 * the visible part of the text). If it's not, we need to redraw 1850 * again. Mostly this just means scrolling up a few lines, so it 1851 * doesn't look too bad. Only do this for the current window (where 1852 * changes are relevant). 1853 */ 1854 wp->w_valid |= VALID_BOTLINE; 1855 if (wp == curwin && wp->w_botline != old_botline && !recursive) 1856 { 1857 recursive = TRUE; 1858 curwin->w_valid &= ~VALID_TOPLINE; 1859 update_topline(); /* may invalidate w_botline again */ 1860 if (must_redraw != 0) 1861 { 1862 /* Don't update for changes in buffer again. */ 1863 i = curbuf->b_mod_set; 1864 curbuf->b_mod_set = FALSE; 1865 win_update(curwin); 1866 must_redraw = 0; 1867 curbuf->b_mod_set = i; 1868 } 1869 recursive = FALSE; 1870 } 1871 } 1872 1873 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) 1874 /* restore got_int, unless CTRL-C was hit while redrawing */ 1875 if (!got_int) 1876 got_int = save_got_int; 1877 #endif 1878 } 1879 1880 #ifdef FEAT_SIGNS 1881 static int draw_signcolumn __ARGS((win_T *wp)); 1882 1883 /* 1884 * Return TRUE when window "wp" has a column to draw signs in. 1885 */ 1886 static int 1887 draw_signcolumn(wp) 1888 win_T *wp; 1889 { 1890 return (wp->w_buffer->b_signlist != NULL 1891 # ifdef FEAT_NETBEANS_INTG 1892 || usingNetbeans 1893 # endif 1894 ); 1895 } 1896 #endif 1897 1898 /* 1899 * Clear the rest of the window and mark the unused lines with "c1". use "c2" 1900 * as the filler character. 1901 */ 1902 static void 1903 win_draw_end(wp, c1, c2, row, endrow, hl) 1904 win_T *wp; 1905 int c1; 1906 int c2; 1907 int row; 1908 int endrow; 1909 enum hlf_value hl; 1910 { 1911 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) 1912 int n = 0; 1913 # define FDC_OFF n 1914 #else 1915 # define FDC_OFF 0 1916 #endif 1917 1918 #ifdef FEAT_RIGHTLEFT 1919 if (wp->w_p_rl) 1920 { 1921 /* No check for cmdline window: should never be right-left. */ 1922 # ifdef FEAT_FOLDING 1923 n = wp->w_p_fdc; 1924 1925 if (n > 0) 1926 { 1927 /* draw the fold column at the right */ 1928 if (n > wp->w_width) 1929 n = wp->w_width; 1930 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 1931 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), 1932 ' ', ' ', hl_attr(HLF_FC)); 1933 } 1934 # endif 1935 # ifdef FEAT_SIGNS 1936 if (draw_signcolumn(wp)) 1937 { 1938 int nn = n + 2; 1939 1940 /* draw the sign column left of the fold column */ 1941 if (nn > wp->w_width) 1942 nn = wp->w_width; 1943 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 1944 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, 1945 ' ', ' ', hl_attr(HLF_SC)); 1946 n = nn; 1947 } 1948 # endif 1949 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 1950 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, 1951 c2, c2, hl_attr(hl)); 1952 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 1953 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, 1954 c1, c2, hl_attr(hl)); 1955 } 1956 else 1957 #endif 1958 { 1959 #ifdef FEAT_CMDWIN 1960 if (cmdwin_type != 0 && wp == curwin) 1961 { 1962 /* draw the cmdline character in the leftmost column */ 1963 n = 1; 1964 if (n > wp->w_width) 1965 n = wp->w_width; 1966 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 1967 W_WINCOL(wp), (int)W_WINCOL(wp) + n, 1968 cmdwin_type, ' ', hl_attr(HLF_AT)); 1969 } 1970 #endif 1971 #ifdef FEAT_FOLDING 1972 if (wp->w_p_fdc > 0) 1973 { 1974 int nn = n + wp->w_p_fdc; 1975 1976 /* draw the fold column at the left */ 1977 if (nn > W_WIDTH(wp)) 1978 nn = W_WIDTH(wp); 1979 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 1980 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, 1981 ' ', ' ', hl_attr(HLF_FC)); 1982 n = nn; 1983 } 1984 #endif 1985 #ifdef FEAT_SIGNS 1986 if (draw_signcolumn(wp)) 1987 { 1988 int nn = n + 2; 1989 1990 /* draw the sign column after the fold column */ 1991 if (nn > W_WIDTH(wp)) 1992 nn = W_WIDTH(wp); 1993 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 1994 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, 1995 ' ', ' ', hl_attr(HLF_SC)); 1996 n = nn; 1997 } 1998 #endif 1999 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, 2000 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), 2001 c1, c2, hl_attr(hl)); 2002 } 2003 set_empty_rows(wp, row); 2004 } 2005 2006 #ifdef FEAT_FOLDING 2007 /* 2008 * Display one folded line. 2009 */ 2010 static void 2011 fold_line(wp, fold_count, foldinfo, lnum, row) 2012 win_T *wp; 2013 long fold_count; 2014 foldinfo_T *foldinfo; 2015 linenr_T lnum; 2016 int row; 2017 { 2018 char_u buf[51]; 2019 pos_T *top, *bot; 2020 linenr_T lnume = lnum + fold_count - 1; 2021 int len; 2022 char_u *p; 2023 char_u *text = NULL; 2024 int fdc; 2025 int level; 2026 int col; 2027 int txtcol; 2028 int off = (int)(current_ScreenLine - ScreenLines); 2029 2030 /* Build the fold line: 2031 * 1. Add the cmdwin_type for the command-line window 2032 * 2. Add the 'foldcolumn' 2033 * 3. Add the 'number' column 2034 * 4. Compose the text 2035 * 5. Add the text 2036 * 6. set highlighting for the Visual area an other text 2037 */ 2038 col = 0; 2039 2040 /* 2041 * 1. Add the cmdwin_type for the command-line window 2042 * Ignores 'rightleft', this window is never right-left. 2043 */ 2044 #ifdef FEAT_CMDWIN 2045 if (cmdwin_type != 0 && wp == curwin) 2046 { 2047 ScreenLines[off] = cmdwin_type; 2048 ScreenAttrs[off] = hl_attr(HLF_AT); 2049 #ifdef FEAT_MBYTE 2050 if (enc_utf8) 2051 ScreenLinesUC[off] = 0; 2052 #endif 2053 ++col; 2054 } 2055 #endif 2056 2057 /* 2058 * 2. Add the 'foldcolumn' 2059 */ 2060 fdc = wp->w_p_fdc; 2061 if (fdc > W_WIDTH(wp) - col) 2062 fdc = W_WIDTH(wp) - col; 2063 if (fdc > 0) 2064 { 2065 fill_foldcolumn(buf, wp, TRUE, lnum); 2066 #ifdef FEAT_RIGHTLEFT 2067 if (wp->w_p_rl) 2068 { 2069 int i; 2070 2071 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, 2072 hl_attr(HLF_FC)); 2073 /* reverse the fold column */ 2074 for (i = 0; i < fdc; ++i) 2075 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; 2076 } 2077 else 2078 #endif 2079 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); 2080 col += fdc; 2081 } 2082 2083 #ifdef FEAT_RIGHTLEFT 2084 # define RL_MEMSET(p, v, l) vim_memset(ScreenAttrs + off + (wp->w_p_rl ? (W_WIDTH(wp) - (p) - (l)) : (p)), v, l) 2085 #else 2086 # define RL_MEMSET(p, v, l) vim_memset(ScreenAttrs + off + p, v, l) 2087 #endif 2088 2089 /* Set all attributes of the 'number' column and the text */ 2090 RL_MEMSET(col, hl_attr(HLF_FL), (size_t)(W_WIDTH(wp) - col)); 2091 2092 #ifdef FEAT_SIGNS 2093 /* If signs are being displayed, add two spaces. */ 2094 if (draw_signcolumn(wp)) 2095 { 2096 len = W_WIDTH(wp) - col; 2097 if (len > 0) 2098 { 2099 if (len > 2) 2100 len = 2; 2101 # ifdef FEAT_RIGHTLEFT 2102 if (wp->w_p_rl) 2103 /* the line number isn't reversed */ 2104 copy_text_attr(off + W_WIDTH(wp) - len - col, 2105 (char_u *)" ", len, hl_attr(HLF_FL)); 2106 else 2107 # endif 2108 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); 2109 col += len; 2110 } 2111 } 2112 #endif 2113 2114 /* 2115 * 3. Add the 'number' column 2116 */ 2117 if (wp->w_p_nu) 2118 { 2119 len = W_WIDTH(wp) - col; 2120 if (len > 0) 2121 { 2122 int w = number_width(wp); 2123 2124 if (len > w + 1) 2125 len = w + 1; 2126 sprintf((char *)buf, "%*ld ", w, (long)lnum); 2127 #ifdef FEAT_RIGHTLEFT 2128 if (wp->w_p_rl) 2129 /* the line number isn't reversed */ 2130 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, 2131 hl_attr(HLF_FL)); 2132 else 2133 #endif 2134 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); 2135 col += len; 2136 } 2137 } 2138 2139 /* 2140 * 4. Compose the folded-line string with 'foldtext', if set. 2141 */ 2142 #ifdef FEAT_EVAL 2143 if (*wp->w_p_fdt != NUL) 2144 { 2145 char_u dashes[51]; 2146 win_T *save_curwin; 2147 2148 /* Set "v:foldstart" and "v:foldend". */ 2149 set_vim_var_nr(VV_FOLDSTART, lnum); 2150 set_vim_var_nr(VV_FOLDEND, lnume); 2151 2152 /* Set "v:folddashes" to a string of "level" dashes. */ 2153 /* Set "v:foldlevel" to "level". */ 2154 level = foldinfo->fi_level; 2155 if (level > 50) 2156 level = 50; 2157 vim_memset(dashes, '-', (size_t)level); 2158 dashes[level] = NUL; 2159 set_vim_var_string(VV_FOLDDASHES, dashes, -1); 2160 set_vim_var_nr(VV_FOLDLEVEL, (long)level); 2161 save_curwin = curwin; 2162 curwin = wp; 2163 curbuf = wp->w_buffer; 2164 2165 ++emsg_off; 2166 text = eval_to_string_safe(wp->w_p_fdt, NULL); 2167 --emsg_off; 2168 2169 curwin = save_curwin; 2170 curbuf = curwin->w_buffer; 2171 set_vim_var_string(VV_FOLDDASHES, NULL, -1); 2172 2173 if (text != NULL) 2174 { 2175 /* Replace unprintable characters, if there are any. But 2176 * replace a TAB with a space. */ 2177 for (p = text; *p != NUL; ++p) 2178 { 2179 #ifdef FEAT_MBYTE 2180 if (has_mbyte && (len = (*mb_ptr2len_check)(p)) > 1) 2181 { 2182 if (!vim_isprintc((*mb_ptr2char)(p))) 2183 break; 2184 p += len - 1; 2185 } 2186 else 2187 #endif 2188 if (*p == TAB) 2189 *p = ' '; 2190 else if (ptr2cells(p) > 1) 2191 break; 2192 } 2193 if (*p != NUL) 2194 { 2195 p = transstr(text); 2196 vim_free(text); 2197 text = p; 2198 } 2199 } 2200 } 2201 if (text == NULL) 2202 #endif 2203 { 2204 sprintf((char *)buf, _("+--%3ld lines folded "), fold_count); 2205 text = buf; 2206 } 2207 2208 txtcol = col; /* remember where text starts */ 2209 2210 /* 2211 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". 2212 * Right-left text is put in columns 0 - number-col, normal text is put 2213 * in columns number-col - window-width. 2214 */ 2215 #ifdef FEAT_MBYTE 2216 if (has_mbyte) 2217 { 2218 int cells; 2219 int u8c, u8c_c1, u8c_c2; 2220 int idx; 2221 int c_len; 2222 # ifdef FEAT_ARABIC 2223 int prev_c = 0; /* previous Arabic character */ 2224 int prev_c1 = 0; /* first composing char for prev_c */ 2225 # endif 2226 2227 # ifdef FEAT_RIGHTLEFT 2228 if (wp->w_p_rl) 2229 idx = off; 2230 else 2231 # endif 2232 idx = off + col; 2233 2234 /* Store multibyte characters in ScreenLines[] et al. correctly. */ 2235 for (p = text; *p != NUL; ) 2236 { 2237 cells = (*mb_ptr2cells)(p); 2238 c_len = (*mb_ptr2len_check)(p); 2239 if (col + cells > W_WIDTH(wp) 2240 # ifdef FEAT_RIGHTLEFT 2241 - (wp->w_p_rl ? col : 0) 2242 # endif 2243 ) 2244 break; 2245 ScreenLines[idx] = *p; 2246 if (enc_utf8) 2247 { 2248 u8c = utfc_ptr2char(p, &u8c_c1, &u8c_c2); 2249 if (*p < 0x80 && u8c_c1 == 0 && u8c_c2 == 0) 2250 { 2251 ScreenLinesUC[idx] = 0; 2252 #ifdef FEAT_ARABIC 2253 prev_c = u8c; 2254 #endif 2255 } 2256 else 2257 { 2258 #ifdef FEAT_ARABIC 2259 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) 2260 { 2261 /* Do Arabic shaping. */ 2262 int pc, pc1, nc, dummy; 2263 int firstbyte = *p; 2264 2265 /* The idea of what is the previous and next 2266 * character depends on 'rightleft'. */ 2267 if (wp->w_p_rl) 2268 { 2269 pc = prev_c; 2270 pc1 = prev_c1; 2271 nc = utf_ptr2char(p + c_len); 2272 prev_c1 = u8c_c1; 2273 } 2274 else 2275 { 2276 pc = utfc_ptr2char(p + c_len, &pc1, &dummy); 2277 nc = prev_c; 2278 } 2279 prev_c = u8c; 2280 2281 u8c = arabic_shape(u8c, &firstbyte, &u8c_c1, 2282 pc, pc1, nc); 2283 ScreenLines[idx] = firstbyte; 2284 } 2285 else 2286 prev_c = u8c; 2287 #endif 2288 /* Non-BMP character: display as ? or fullwidth ?. */ 2289 if (u8c >= 0x10000) 2290 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; 2291 else 2292 ScreenLinesUC[idx] = u8c; 2293 ScreenLinesC1[idx] = u8c_c1; 2294 ScreenLinesC2[idx] = u8c_c2; 2295 } 2296 if (cells > 1) 2297 ScreenLines[idx + 1] = 0; 2298 } 2299 else if (cells > 1) /* double-byte character */ 2300 { 2301 if (enc_dbcs == DBCS_JPNU && *p == 0x8e) 2302 ScreenLines2[idx] = p[1]; 2303 else 2304 ScreenLines[idx + 1] = p[1]; 2305 } 2306 col += cells; 2307 idx += cells; 2308 p += c_len; 2309 } 2310 } 2311 else 2312 #endif 2313 { 2314 len = (int)STRLEN(text); 2315 if (len > W_WIDTH(wp) - col) 2316 len = W_WIDTH(wp) - col; 2317 if (len > 0) 2318 { 2319 #ifdef FEAT_RIGHTLEFT 2320 if (wp->w_p_rl) 2321 STRNCPY(current_ScreenLine, text, len); 2322 else 2323 #endif 2324 STRNCPY(current_ScreenLine + col, text, len); 2325 col += len; 2326 } 2327 } 2328 2329 /* Fill the rest of the line with the fold filler */ 2330 #ifdef FEAT_RIGHTLEFT 2331 if (wp->w_p_rl) 2332 col -= txtcol; 2333 #endif 2334 while (col < W_WIDTH(wp) 2335 #ifdef FEAT_RIGHTLEFT 2336 - (wp->w_p_rl ? txtcol : 0) 2337 #endif 2338 ) 2339 { 2340 #ifdef FEAT_MBYTE 2341 if (enc_utf8) 2342 { 2343 if (fill_fold >= 0x80) 2344 { 2345 ScreenLinesUC[off + col] = fill_fold; 2346 ScreenLinesC1[off + col] = 0; 2347 ScreenLinesC2[off + col] = 0; 2348 } 2349 else 2350 ScreenLinesUC[off + col] = 0; 2351 } 2352 #endif 2353 ScreenLines[off + col++] = fill_fold; 2354 } 2355 2356 if (text != buf) 2357 vim_free(text); 2358 2359 /* 2360 * 6. set highlighting for the Visual area an other text. 2361 * If all folded lines are in the Visual area, highlight the line. 2362 */ 2363 #ifdef FEAT_VISUAL 2364 if (VIsual_active && wp->w_buffer == curwin->w_buffer) 2365 { 2366 if (ltoreq(curwin->w_cursor, VIsual)) 2367 { 2368 /* Visual is after curwin->w_cursor */ 2369 top = &curwin->w_cursor; 2370 bot = &VIsual; 2371 } 2372 else 2373 { 2374 /* Visual is before curwin->w_cursor */ 2375 top = &VIsual; 2376 bot = &curwin->w_cursor; 2377 } 2378 if (lnum >= top->lnum 2379 && lnume <= bot->lnum 2380 && (VIsual_mode != 'v' 2381 || ((lnum > top->lnum 2382 || (lnum == top->lnum 2383 && top->col == 0)) 2384 && (lnume < bot->lnum 2385 || (lnume == bot->lnum 2386 && (bot->col - (*p_sel == 'e')) 2387 >= STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) 2388 { 2389 if (VIsual_mode == Ctrl_V) 2390 { 2391 /* Visual block mode: highlight the chars part of the block */ 2392 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) 2393 { 2394 if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) 2395 len = wp->w_old_cursor_lcol; 2396 else 2397 len = W_WIDTH(wp) - txtcol; 2398 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), 2399 (size_t)(len - wp->w_old_cursor_fcol)); 2400 } 2401 } 2402 else 2403 /* Set all attributes of the text */ 2404 RL_MEMSET(txtcol, hl_attr(HLF_V), 2405 (size_t)(W_WIDTH(wp) - txtcol)); 2406 } 2407 } 2408 #endif 2409 2410 2411 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), 2412 (int)W_WIDTH(wp), FALSE); 2413 2414 /* 2415 * Update w_cline_height and w_cline_folded if the cursor line was 2416 * updated (saves a call to plines() later). 2417 */ 2418 if (wp == curwin 2419 && lnum <= curwin->w_cursor.lnum 2420 && lnume >= curwin->w_cursor.lnum) 2421 { 2422 curwin->w_cline_row = row; 2423 curwin->w_cline_height = 1; 2424 curwin->w_cline_folded = TRUE; 2425 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); 2426 } 2427 } 2428 2429 /* 2430 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". 2431 */ 2432 static void 2433 copy_text_attr(off, buf, len, attr) 2434 int off; 2435 char_u *buf; 2436 int len; 2437 int attr; 2438 { 2439 mch_memmove(ScreenLines + off, buf, (size_t)len); 2440 # ifdef FEAT_MBYTE 2441 if (enc_utf8) 2442 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); 2443 # endif 2444 vim_memset(ScreenAttrs + off, attr, (size_t)len); 2445 } 2446 2447 /* 2448 * Fill the foldcolumn at "p" for window "wp". 2449 */ 2450 static void 2451 fill_foldcolumn(p, wp, closed, lnum) 2452 char_u *p; 2453 win_T *wp; 2454 int closed; /* TRUE of FALSE */ 2455 linenr_T lnum; /* current line number */ 2456 { 2457 int i = 0; 2458 int level; 2459 int first_level; 2460 2461 /* Init to all spaces. */ 2462 copy_spaces(p, (size_t)wp->w_p_fdc); 2463 2464 level = win_foldinfo.fi_level; 2465 if (level > 0) 2466 { 2467 /* If the column is too narrow, we start at the lowest level that 2468 * fits and use numbers to indicated the depth. */ 2469 first_level = level - wp->w_p_fdc - closed + 2; 2470 if (first_level < 1) 2471 first_level = 1; 2472 2473 for (i = 0; i + 1 < wp->w_p_fdc; ++i) 2474 { 2475 if (win_foldinfo.fi_lnum == lnum 2476 && first_level + i >= win_foldinfo.fi_low_level) 2477 p[i] = '-'; 2478 else if (first_level == 1) 2479 p[i] = '|'; 2480 else if (first_level + i <= 9) 2481 p[i] = '0' + first_level + i; 2482 else 2483 p[i] = '>'; 2484 if (first_level + i == level) 2485 break; 2486 } 2487 } 2488 if (closed) 2489 p[i] = '+'; 2490 } 2491 #endif /* FEAT_FOLDING */ 2492 2493 /* 2494 * Display line "lnum" of window 'wp' on the screen. 2495 * Start at row "startrow", stop when "endrow" is reached. 2496 * wp->w_virtcol needs to be valid. 2497 * 2498 * Return the number of last row the line occupies. 2499 */ 2500 static int 2501 win_line(wp, lnum, startrow, endrow) 2502 win_T *wp; 2503 linenr_T lnum; 2504 int startrow; 2505 int endrow; 2506 { 2507 int col; /* visual column on screen */ 2508 unsigned off; /* offset in ScreenLines/ScreenAttrs */ 2509 int c = 0; /* init for GCC */ 2510 long vcol = 0; /* virtual column (for tabs) */ 2511 long vcol_prev = -1; /* "vcol" of previous character */ 2512 char_u *line; /* current line */ 2513 char_u *ptr; /* current position in "line" */ 2514 int row; /* row in the window, excl w_winrow */ 2515 int screen_row; /* row on the screen, incl w_winrow */ 2516 2517 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ 2518 int n_extra = 0; /* number of extra chars */ 2519 char_u *p_extra = NULL; /* string of extra chars */ 2520 int c_extra = NUL; /* extra chars, all the same */ 2521 int extra_attr = 0; /* attributes when n_extra != 0 */ 2522 static char_u *at_end_str = (char_u *)""; /* used for p_extra when 2523 displaying lcs_eol at end-of-line */ 2524 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ 2525 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ 2526 2527 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ 2528 int saved_n_extra = 0; 2529 char_u *saved_p_extra = NULL; 2530 int saved_c_extra = 0; 2531 int saved_char_attr = 0; 2532 2533 int n_attr = 0; /* chars with special attr */ 2534 int saved_attr2 = 0; /* char_attr saved for n_attr */ 2535 int n_attr3 = 0; /* chars with overruling special attr */ 2536 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ 2537 2538 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ 2539 2540 int fromcol, tocol; /* start/end of inverting */ 2541 int fromcol_prev = -2; /* start of inverting after cursor */ 2542 int noinvcur = FALSE; /* don't invert the cursor */ 2543 #ifdef FEAT_VISUAL 2544 pos_T *top, *bot; 2545 #endif 2546 pos_T pos; 2547 long v; 2548 2549 int char_attr = 0; /* attributes for next character */ 2550 int area_highlighting = FALSE; /* Visual or incsearch highlighting 2551 in this line */ 2552 int attr = 0; /* attributes for area highlighting */ 2553 int area_attr = 0; /* attributes desired by highlighting */ 2554 int search_attr = 0; /* attributes desired by 'hlsearch' */ 2555 #ifdef FEAT_SYN_HL 2556 int syntax_attr = 0; /* attributes desired by syntax */ 2557 int has_syntax = FALSE; /* this buffer has syntax highl. */ 2558 int save_did_emsg; 2559 #endif 2560 int extra_check; /* has syntax or linebreak */ 2561 #ifdef FEAT_MBYTE 2562 int multi_attr = 0; /* attributes desired by multibyte */ 2563 int mb_l = 1; /* multi-byte byte length */ 2564 int mb_c = 0; /* decoded multi-byte character */ 2565 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ 2566 int u8c_c1 = 0; /* first composing UTF-8 char */ 2567 int u8c_c2 = 0; /* second composing UTF-8 char */ 2568 #endif 2569 #ifdef FEAT_DIFF 2570 int filler_lines; /* nr of filler lines to be drawn */ 2571 int filler_todo; /* nr of filler lines still to do + 1 */ 2572 enum hlf_value diff_hlf = (enum hlf_value)0; /* type of diff highlighting */ 2573 int change_start = MAXCOL; /* first col of changed area */ 2574 int change_end = -1; /* last col of changed area */ 2575 #endif 2576 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ 2577 #ifdef FEAT_LINEBREAK 2578 int need_showbreak = FALSE; 2579 #endif 2580 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) 2581 # define LINE_ATTR 2582 int line_attr = 0; /* atrribute for the whole line */ 2583 #endif 2584 #ifdef FEAT_SEARCH_EXTRA 2585 match_T *shl; /* points to search_hl or match_hl */ 2586 #endif 2587 #ifdef FEAT_ARABIC 2588 int prev_c = 0; /* previous Arabic character */ 2589 int prev_c1 = 0; /* first composing char for prev_c */ 2590 #endif 2591 2592 /* draw_state: items that are drawn in sequence: */ 2593 #define WL_START 0 /* nothing done yet */ 2594 #ifdef FEAT_CMDWIN 2595 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ 2596 #else 2597 # define WL_CMDLINE WL_START 2598 #endif 2599 #ifdef FEAT_FOLDING 2600 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ 2601 #else 2602 # define WL_FOLD WL_CMDLINE 2603 #endif 2604 #ifdef FEAT_SIGNS 2605 # define WL_SIGN WL_FOLD + 1 /* column for signs */ 2606 #else 2607 # define WL_SIGN WL_FOLD /* column for signs */ 2608 #endif 2609 #define WL_NR WL_SIGN + 1 /* line number */ 2610 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) 2611 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ 2612 #else 2613 # define WL_SBR WL_NR 2614 #endif 2615 #define WL_LINE WL_SBR + 1 /* text in the line */ 2616 int draw_state = WL_START; /* what to draw next */ 2617 #if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)) 2618 int feedback_col = 0; 2619 int feedback_old_attr = -1; 2620 #endif 2621 2622 2623 if (startrow > endrow) /* past the end already! */ 2624 return startrow; 2625 2626 row = startrow; 2627 screen_row = row + W_WINROW(wp); 2628 2629 /* 2630 * To speed up the loop below, set extra_check when there is linebreak, 2631 * trailing white space and/or syntax processing to be done. 2632 */ 2633 #ifdef FEAT_LINEBREAK 2634 extra_check = wp->w_p_lbr; 2635 #else 2636 extra_check = 0; 2637 #endif 2638 #ifdef FEAT_SYN_HL 2639 if (syntax_present(wp->w_buffer)) 2640 { 2641 /* Prepare for syntax highlighting in this line. When there is an 2642 * error, stop syntax highlighting. */ 2643 save_did_emsg = did_emsg; 2644 did_emsg = FALSE; 2645 syntax_start(wp, lnum); 2646 if (did_emsg) 2647 syntax_clear(wp->w_buffer); 2648 else 2649 { 2650 did_emsg = save_did_emsg; 2651 has_syntax = TRUE; 2652 extra_check = TRUE; 2653 } 2654 } 2655 #endif 2656 2657 /* 2658 * handle visual active in this window 2659 */ 2660 fromcol = -10; 2661 tocol = MAXCOL; 2662 #ifdef FEAT_VISUAL 2663 if (VIsual_active && wp->w_buffer == curwin->w_buffer) 2664 { 2665 /* Visual is after curwin->w_cursor */ 2666 if (ltoreq(curwin->w_cursor, VIsual)) 2667 { 2668 top = &curwin->w_cursor; 2669 bot = &VIsual; 2670 } 2671 else /* Visual is before curwin->w_cursor */ 2672 { 2673 top = &VIsual; 2674 bot = &curwin->w_cursor; 2675 } 2676 if (VIsual_mode == Ctrl_V) /* block mode */ 2677 { 2678 if (lnum >= top->lnum && lnum <= bot->lnum) 2679 { 2680 fromcol = wp->w_old_cursor_fcol; 2681 tocol = wp->w_old_cursor_lcol; 2682 } 2683 } 2684 else /* non-block mode */ 2685 { 2686 if (lnum > top->lnum && lnum <= bot->lnum) 2687 fromcol = 0; 2688 else if (lnum == top->lnum) 2689 { 2690 if (VIsual_mode == 'V') /* linewise */ 2691 fromcol = 0; 2692 else 2693 { 2694 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); 2695 if (gchar_pos(top) == NUL) 2696 tocol = fromcol + 1; 2697 } 2698 } 2699 if (VIsual_mode != 'V' && lnum == bot->lnum) 2700 { 2701 if (*p_sel == 'e' && bot->col == 0 2702 #ifdef FEAT_VIRTUALEDIT 2703 && bot->coladd == 0 2704 #endif 2705 ) 2706 { 2707 fromcol = -10; 2708 tocol = MAXCOL; 2709 } 2710 else 2711 { 2712 pos = *bot; 2713 if (*p_sel == 'e') 2714 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); 2715 else 2716 { 2717 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); 2718 ++tocol; 2719 } 2720 } 2721 } 2722 } 2723 2724 #ifndef MSDOS 2725 /* Check if the character under the cursor should not be inverted */ 2726 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin 2727 # ifdef FEAT_GUI 2728 && !gui.in_use 2729 # endif 2730 ) 2731 noinvcur = TRUE; 2732 #endif 2733 2734 /* if inverting in this line set area_highlighting */ 2735 if (fromcol >= 0) 2736 { 2737 area_highlighting = TRUE; 2738 attr = hl_attr(HLF_V); 2739 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) 2740 if (clip_star.available && !clip_star.owned && clip_isautosel()) 2741 attr = hl_attr(HLF_VNC); 2742 #endif 2743 } 2744 } 2745 2746 /* 2747 * handle 'insearch' and ":s///c" highlighting 2748 */ 2749 else 2750 #endif /* FEAT_VISUAL */ 2751 if (highlight_match 2752 && wp == curwin 2753 && lnum >= curwin->w_cursor.lnum 2754 && lnum <= curwin->w_cursor.lnum + search_match_lines) 2755 { 2756 if (lnum == curwin->w_cursor.lnum) 2757 getvcol(curwin, &(curwin->w_cursor), 2758 (colnr_T *)&fromcol, NULL, NULL); 2759 else 2760 fromcol = 0; 2761 if (lnum == curwin->w_cursor.lnum + search_match_lines) 2762 { 2763 pos.lnum = lnum; 2764 pos.col = search_match_endcol; 2765 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); 2766 } 2767 else 2768 tocol = MAXCOL; 2769 if (fromcol == tocol) /* do at least one character */ 2770 tocol = fromcol + 1; /* happens when past end of line */ 2771 area_highlighting = TRUE; 2772 attr = hl_attr(HLF_I); 2773 } 2774 2775 #ifdef FEAT_DIFF 2776 filler_lines = diff_check(wp, lnum); 2777 if (filler_lines < 0) 2778 { 2779 if (filler_lines == -1) 2780 { 2781 if (diff_find_change(wp, lnum, &change_start, &change_end)) 2782 diff_hlf = HLF_ADD; /* added line */ 2783 else if (change_start == 0) 2784 diff_hlf = HLF_TXD; /* changed text */ 2785 else 2786 diff_hlf = HLF_CHD; /* changed line */ 2787 } 2788 else 2789 diff_hlf = HLF_ADD; /* added line */ 2790 filler_lines = 0; 2791 area_highlighting = TRUE; 2792 } 2793 if (lnum == wp->w_topline) 2794 filler_lines = wp->w_topfill; 2795 filler_todo = filler_lines; 2796 #endif 2797 2798 #ifdef LINE_ATTR 2799 # ifdef FEAT_SIGNS 2800 /* If this line has a sign with line highlighting set line_attr. */ 2801 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); 2802 if (v != 0) 2803 line_attr = sign_get_attr((int)v, TRUE); 2804 # endif 2805 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) 2806 /* Highlight the current line in the quickfix window. */ 2807 if (bt_quickfix(wp->w_buffer) && qf_current_entry() == lnum) 2808 line_attr = hl_attr(HLF_L); 2809 # endif 2810 if (line_attr != 0) 2811 area_highlighting = TRUE; 2812 #endif 2813 2814 line = ml_get_buf(wp->w_buffer, lnum, FALSE); 2815 ptr = line; 2816 2817 /* find start of trailing whitespace */ 2818 if (wp->w_p_list && lcs_trail) 2819 { 2820 trailcol = (colnr_T)STRLEN(ptr); 2821 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) 2822 --trailcol; 2823 trailcol += (colnr_T) (ptr - line); 2824 extra_check = TRUE; 2825 } 2826 2827 /* 2828 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the 2829 * first character to be displayed. 2830 */ 2831 if (wp->w_p_wrap) 2832 v = wp->w_skipcol; 2833 else 2834 v = wp->w_leftcol; 2835 if (v > 0) 2836 { 2837 #ifdef FEAT_MBYTE 2838 char_u *prev_ptr = ptr; 2839 #endif 2840 while (vcol < v && *ptr != NUL) 2841 { 2842 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); 2843 vcol += c; 2844 #ifdef FEAT_MBYTE 2845 prev_ptr = ptr; 2846 if (has_mbyte) 2847 ptr += (*mb_ptr2len_check)(ptr); 2848 else 2849 #endif 2850 ++ptr; 2851 } 2852 2853 #ifdef FEAT_VIRTUALEDIT 2854 /* When 'virtualedit' is set the end of the line may be before the 2855 * start of the displayed part. */ 2856 if (vcol < v && *ptr == NUL && virtual_active()) 2857 vcol = v; 2858 #endif 2859 2860 /* Handle a character that's not completely on the screen: Put ptr at 2861 * that character but skip the first few screen characters. */ 2862 if (vcol > v) 2863 { 2864 vcol -= c; 2865 #ifdef FEAT_MBYTE 2866 ptr = prev_ptr; 2867 #else 2868 --ptr; 2869 #endif 2870 n_skip = v - vcol; 2871 } 2872 2873 /* 2874 * Adjust for when the inverted text is before the screen, 2875 * and when the start of the inverted text is before the screen. 2876 */ 2877 if (tocol <= vcol) 2878 fromcol = 0; 2879 else if (fromcol >= 0 && fromcol < vcol) 2880 fromcol = vcol; 2881 2882 #ifdef FEAT_LINEBREAK 2883 /* When w_skipcol is non-zero, first line needs 'showbreak' */ 2884 if (wp->w_p_wrap) 2885 need_showbreak = TRUE; 2886 #endif 2887 } 2888 2889 /* 2890 * Correct highlighting for cursor that can't be disabled. 2891 * Avoids having to check this for each character. 2892 */ 2893 if (fromcol >= 0) 2894 { 2895 if (noinvcur) 2896 { 2897 if ((colnr_T)fromcol == wp->w_virtcol) 2898 { 2899 /* highlighting starts at cursor, let it start just after the 2900 * cursor */ 2901 fromcol_prev = fromcol; 2902 fromcol = -1; 2903 } 2904 else if ((colnr_T)fromcol < wp->w_virtcol) 2905 /* restart highlighting after the cursor */ 2906 fromcol_prev = wp->w_virtcol; 2907 } 2908 if (fromcol >= tocol) 2909 fromcol = -1; 2910 } 2911 2912 #ifdef FEAT_SEARCH_EXTRA 2913 /* 2914 * Handle highlighting the last used search pattern. 2915 * Do this for both search_hl and match_hl. 2916 */ 2917 shl = &search_hl; 2918 for (;;) 2919 { 2920 shl->startp = NULL; 2921 shl->endp = NULL; 2922 shl->attr_cur = 0; 2923 if (shl->rm.regprog != NULL) 2924 { 2925 v = (long)(ptr - line); 2926 next_search_hl(wp, shl, lnum, (colnr_T)v); 2927 2928 /* Need to get the line again, a multi-line regexp may have made it 2929 * invalid. */ 2930 line = ml_get_buf(wp->w_buffer, lnum, FALSE); 2931 ptr = line + v; 2932 2933 if (shl->lnum != 0 && shl->lnum <= lnum) 2934 { 2935 if (shl->lnum == lnum) 2936 shl->startp = line + shl->rm.startpos[0].col; 2937 else 2938 shl->startp = line; 2939 if (lnum == shl->lnum + shl->rm.endpos[0].lnum 2940 - shl->rm.startpos[0].lnum) 2941 shl->endp = line + shl->rm.endpos[0].col; 2942 else 2943 shl->endp = line + MAXCOL; 2944 /* Highlight one character for an empty match. */ 2945 if (shl->startp == shl->endp) 2946 { 2947 #ifdef FEAT_MBYTE 2948 if (has_mbyte && *shl->endp != NUL) 2949 shl->endp += (*mb_ptr2len_check)(shl->endp); 2950 else 2951 #endif 2952 ++shl->endp; 2953 } 2954 if (shl->startp < ptr) /* match at leftcol */ 2955 { 2956 shl->attr_cur = shl->attr; 2957 search_attr = shl->attr; 2958 } 2959 area_highlighting = TRUE; 2960 } 2961 } 2962 if (shl == &match_hl) 2963 break; 2964 shl = &match_hl; 2965 } 2966 #endif 2967 2968 off = (unsigned) (current_ScreenLine - ScreenLines); 2969 col = 0; 2970 #ifdef FEAT_RIGHTLEFT 2971 if (wp->w_p_rl) 2972 { 2973 /* Rightleft window: process the text in the normal direction, but put 2974 * it in current_ScreenLine[] from right to left. Start at the 2975 * rightmost column of the window. */ 2976 col = W_WIDTH(wp) - 1; 2977 off += col; 2978 } 2979 #endif 2980 2981 /* 2982 * Repeat for the whole displayed line. 2983 */ 2984 for (;;) 2985 { 2986 /* Skip this quickly when working on the text. */ 2987 if (draw_state != WL_LINE) 2988 { 2989 #ifdef FEAT_CMDWIN 2990 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) 2991 { 2992 draw_state = WL_CMDLINE; 2993 if (cmdwin_type != 0 && wp == curwin) 2994 { 2995 /* Draw the cmdline character. */ 2996 *extra = cmdwin_type; 2997 n_extra = 1; 2998 p_extra = extra; 2999 c_extra = NUL; 3000 char_attr = hl_attr(HLF_AT); 3001 } 3002 } 3003 #endif 3004 3005 #ifdef FEAT_FOLDING 3006 if (draw_state == WL_FOLD - 1 && n_extra == 0) 3007 { 3008 draw_state = WL_FOLD; 3009 if (wp->w_p_fdc > 0) 3010 { 3011 /* Draw the 'foldcolumn'. */ 3012 fill_foldcolumn(extra, wp, FALSE, lnum); 3013 n_extra = wp->w_p_fdc; 3014 p_extra = extra; 3015 c_extra = NUL; 3016 char_attr = hl_attr(HLF_FC); 3017 } 3018 } 3019 #endif 3020 3021 #ifdef FEAT_SIGNS 3022 if (draw_state == WL_SIGN - 1 && n_extra == 0) 3023 { 3024 draw_state = WL_SIGN; 3025 /* Show the sign column when there are any signs in this 3026 * buffer or when using Netbeans. */ 3027 if (draw_signcolumn(wp) 3028 # ifdef FEAT_DIFF 3029 && filler_todo <= 0 3030 # endif 3031 ) 3032 { 3033 int_u text_sign; 3034 # ifdef FEAT_SIGN_ICONS 3035 int_u icon_sign; 3036 # endif 3037 3038 /* Draw two cells with the sign value or blank. */ 3039 c_extra = ' '; 3040 char_attr = hl_attr(HLF_SC); 3041 n_extra = 2; 3042 3043 if (row == startrow) 3044 { 3045 text_sign = buf_getsigntype(wp->w_buffer, lnum, 3046 SIGN_TEXT); 3047 # ifdef FEAT_SIGN_ICONS 3048 icon_sign = buf_getsigntype(wp->w_buffer, lnum, 3049 SIGN_ICON); 3050 if (gui.in_use && icon_sign != 0) 3051 { 3052 /* Use the image in this position. */ 3053 c_extra = SIGN_BYTE; 3054 # ifdef FEAT_NETBEANS_INTG 3055 if (buf_signcount(wp->w_buffer, lnum) > 1) 3056 c_extra = MULTISIGN_BYTE; 3057 # endif 3058 char_attr = icon_sign; 3059 } 3060 else 3061 # endif 3062 if (text_sign != 0) 3063 { 3064 p_extra = sign_get_text(text_sign); 3065 if (p_extra != NULL) 3066 { 3067 c_extra = NUL; 3068 n_extra = STRLEN(p_extra); 3069 } 3070 char_attr = sign_get_attr(text_sign, FALSE); 3071 } 3072 } 3073 } 3074 } 3075 #endif 3076 3077 if (draw_state == WL_NR - 1 && n_extra == 0) 3078 { 3079 draw_state = WL_NR; 3080 /* Display the line number. After the first fill with blanks 3081 * when the 'n' flag isn't in 'cpo' */ 3082 if (wp->w_p_nu 3083 && (row == startrow 3084 #ifdef FEAT_DIFF 3085 + filler_lines 3086 #endif 3087 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) 3088 { 3089 /* Draw the line number (empty space after wrapping). */ 3090 if (row == startrow 3091 #ifdef FEAT_DIFF 3092 + filler_lines 3093 #endif 3094 ) 3095 { 3096 sprintf((char *)extra, "%*ld ", 3097 number_width(wp), (long)lnum); 3098 if (wp->w_skipcol > 0) 3099 for (p_extra = extra; *p_extra == ' '; ++p_extra) 3100 *p_extra = '-'; 3101 #ifdef FEAT_RIGHTLEFT 3102 if (wp->w_p_rl) /* reverse line numbers */ 3103 rl_mirror(extra); 3104 #endif 3105 p_extra = extra; 3106 c_extra = NUL; 3107 } 3108 else 3109 c_extra = ' '; 3110 n_extra = number_width(wp) + 1; 3111 char_attr = hl_attr(HLF_N); 3112 } 3113 } 3114 3115 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) 3116 if (draw_state == WL_SBR - 1 && n_extra == 0) 3117 { 3118 draw_state = WL_SBR; 3119 # ifdef FEAT_DIFF 3120 if (filler_todo > 0) 3121 { 3122 /* Draw "deleted" diff line(s). */ 3123 if (char2cells(fill_diff) > 1) 3124 c_extra = '-'; 3125 else 3126 c_extra = fill_diff; 3127 # ifdef FEAT_RIGHTLEFT 3128 if (wp->w_p_rl) 3129 n_extra = col + 1; 3130 else 3131 # endif 3132 n_extra = W_WIDTH(wp) - col; 3133 char_attr = hl_attr(HLF_DED); 3134 } 3135 # endif 3136 # ifdef FEAT_LINEBREAK 3137 if (*p_sbr != NUL && need_showbreak) 3138 { 3139 /* Draw 'showbreak' at the start of each broken line. */ 3140 p_extra = p_sbr; 3141 c_extra = NUL; 3142 n_extra = (int)STRLEN(p_sbr); 3143 char_attr = hl_attr(HLF_AT); 3144 need_showbreak = FALSE; 3145 /* Correct end of highlighted area for 'showbreak', 3146 * required when 'linebreak' is also set. */ 3147 if (tocol == vcol) 3148 tocol += n_extra; 3149 } 3150 # endif 3151 } 3152 #endif 3153 3154 if (draw_state == WL_LINE - 1 && n_extra == 0) 3155 { 3156 draw_state = WL_LINE; 3157 if (saved_n_extra) 3158 { 3159 /* Continue item from end of wrapped line. */ 3160 n_extra = saved_n_extra; 3161 c_extra = saved_c_extra; 3162 p_extra = saved_p_extra; 3163 char_attr = saved_char_attr; 3164 } 3165 else 3166 char_attr = 0; 3167 } 3168 } 3169 3170 /* When still displaying '$' of change command, stop at cursor */ 3171 if (dollar_vcol != 0 && wp == curwin && vcol >= (long)wp->w_virtcol 3172 #ifdef FEAT_DIFF 3173 && filler_todo <= 0 3174 #endif 3175 ) 3176 { 3177 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), 3178 wp->w_p_rl); 3179 /* Pretend we have finished updating the window. */ 3180 row = wp->w_height; 3181 break; 3182 } 3183 3184 if (draw_state == WL_LINE && area_highlighting) 3185 { 3186 /* handle Visual or match highlighting in this line */ 3187 if (vcol == fromcol 3188 #ifdef FEAT_MBYTE 3189 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 3190 && (*mb_ptr2cells)(ptr) > 1) 3191 #endif 3192 || ((int)vcol_prev == fromcol_prev 3193 && vcol < tocol)) 3194 area_attr = attr; /* start highlighting */ 3195 else if (area_attr != 0 3196 && (vcol == tocol 3197 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) 3198 #ifdef LINE_ATTR 3199 area_attr = line_attr; /* stop highlighting */ 3200 else if (line_attr && ((fromcol == -10 && tocol == MAXCOL) 3201 || (vcol < fromcol || vcol > tocol))) 3202 area_attr = line_attr; 3203 #else 3204 area_attr = 0; /* stop highlighting */ 3205 #endif 3206 3207 #ifdef FEAT_SEARCH_EXTRA 3208 if (!n_extra) 3209 { 3210 /* 3211 * Check for start/end of search pattern match. 3212 * After end, check for start/end of next match. 3213 * When another match, have to check for start again. 3214 * Watch out for matching an empty string! 3215 * Do this first for search_hl, then for match_hl, so that 3216 * ":match" overrules 'hlsearch'. 3217 */ 3218 shl = &search_hl; 3219 for (;;) 3220 { 3221 while (shl->rm.regprog != NULL) 3222 { 3223 if (shl->startp != NULL 3224 && ptr >= shl->startp 3225 && ptr < shl->endp) 3226 { 3227 shl->attr_cur = shl->attr; 3228 } 3229 else if (ptr == shl->endp) 3230 { 3231 shl->attr_cur = 0; 3232 3233 v = (long)(ptr - line); 3234 next_search_hl(wp, shl, lnum, (colnr_T)v); 3235 3236 /* Need to get the line again, a multi-line regexp 3237 * may have made it invalid. */ 3238 line = ml_get_buf(wp->w_buffer, lnum, FALSE); 3239 ptr = line + v; 3240 3241 if (shl->lnum == lnum) 3242 { 3243 shl->startp = line + shl->rm.startpos[0].col; 3244 if (shl->rm.endpos[0].lnum == 0) 3245 shl->endp = line + shl->rm.endpos[0].col; 3246 else 3247 shl->endp = line + MAXCOL; 3248 3249 if (shl->startp == shl->endp) 3250 { 3251 /* highlight empty match, try again after 3252 * it */ 3253 #ifdef FEAT_MBYTE 3254 if (has_mbyte) 3255 shl->endp += 3256 (*mb_ptr2len_check)(shl->endp); 3257 else 3258 #endif 3259 ++shl->endp; 3260 } 3261 3262 /* Loop to check if the match starts at the 3263 * current position */ 3264 continue; 3265 } 3266 } 3267 break; 3268 } 3269 if (shl == &match_hl) 3270 break; 3271 shl = &match_hl; 3272 } 3273 /* ":match" highlighting overrules 'hlsearch' */ 3274 if (match_hl.attr_cur != 0) 3275 search_attr = match_hl.attr_cur; 3276 else 3277 search_attr = search_hl.attr_cur; 3278 } 3279 #endif 3280 3281 if (area_attr != 0) 3282 char_attr = area_attr; 3283 #ifdef FEAT_SYN_HL 3284 else if (search_attr == 0 && has_syntax) 3285 char_attr = syntax_attr; 3286 #endif 3287 else 3288 char_attr = search_attr; 3289 3290 #ifdef FEAT_DIFF 3291 if (diff_hlf != (enum hlf_value)0 && n_extra == 0) 3292 { 3293 if (diff_hlf == HLF_CHD && ptr - line >= change_start) 3294 diff_hlf = HLF_TXD; /* changed text */ 3295 if (diff_hlf == HLF_TXD && ptr - line > change_end) 3296 diff_hlf = HLF_CHD; /* changed line */ 3297 if (attr == 0 || area_attr != attr) 3298 area_attr = hl_attr(diff_hlf); 3299 if (attr == 0 || char_attr != attr) 3300 { 3301 if (search_attr != 0) 3302 char_attr = search_attr; 3303 else 3304 char_attr = hl_attr(diff_hlf); 3305 } 3306 } 3307 #endif 3308 } 3309 3310 /* 3311 * Get the next character to put on the screen. 3312 */ 3313 /* 3314 * The 'extra' array contains the extra stuff that is inserted to 3315 * represent special characters (non-printable stuff). When all 3316 * characters are the same, c_extra is used. 3317 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". 3318 */ 3319 if (n_extra > 0) 3320 { 3321 if (c_extra != NUL) 3322 { 3323 c = c_extra; 3324 #ifdef FEAT_MBYTE 3325 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ 3326 if (enc_utf8 && (*mb_char2len)(c) > 1) 3327 { 3328 mb_utf8 = TRUE; 3329 u8c_c1 = u8c_c2 = 0; 3330 } 3331 else 3332 mb_utf8 = FALSE; 3333 #endif 3334 } 3335 else 3336 { 3337 c = *p_extra; 3338 #ifdef FEAT_MBYTE 3339 if (has_mbyte) 3340 { 3341 mb_c = c; 3342 if (enc_utf8) 3343 { 3344 /* If the UTF-8 character is more than one byte: 3345 * Decode it into "mb_c". */ 3346 mb_l = (*mb_ptr2len_check)(p_extra); 3347 mb_utf8 = FALSE; 3348 if (mb_l > n_extra) 3349 mb_l = 1; 3350 else if (mb_l > 1) 3351 { 3352 mb_c = utfc_ptr2char(p_extra, &u8c_c1, &u8c_c2); 3353 mb_utf8 = TRUE; 3354 } 3355 } 3356 else 3357 { 3358 /* if this is a DBCS character, put it in "mb_c" */ 3359 mb_l = MB_BYTE2LEN(c); 3360 if (mb_l >= n_extra) 3361 mb_l = 1; 3362 else if (mb_l > 1) 3363 mb_c = (c << 8) + p_extra[1]; 3364 } 3365 /* If a double-width char doesn't fit display a '>' in the 3366 * last column. */ 3367 if ( 3368 # ifdef FEAT_RIGHTLEFT 3369 wp->w_p_rl ? (col <= 0) : 3370 # endif 3371 (col >= W_WIDTH(wp) - 1) 3372 && (*mb_char2cells)(mb_c) == 2) 3373 { 3374 c = '>'; 3375 mb_c = c; 3376 mb_l = 1; 3377 mb_utf8 = FALSE; 3378 multi_attr = hl_attr(HLF_AT); 3379 /* put the pointer back to output the double-width 3380 * character at the start of the next line. */ 3381 ++n_extra; 3382 --p_extra; 3383 } 3384 else 3385 { 3386 n_extra -= mb_l - 1; 3387 p_extra += mb_l - 1; 3388 } 3389 } 3390 #endif 3391 ++p_extra; 3392 } 3393 --n_extra; 3394 } 3395 else 3396 { 3397 /* 3398 * Get a character from the line itself. 3399 */ 3400 c = *ptr; 3401 #ifdef FEAT_MBYTE 3402 if (has_mbyte) 3403 { 3404 mb_c = c; 3405 if (enc_utf8) 3406 { 3407 /* If the UTF-8 character is more than one byte: Decode it 3408 * into "mb_c". */ 3409 mb_l = (*mb_ptr2len_check)(ptr); 3410 mb_utf8 = FALSE; 3411 if (mb_l > 1) 3412 { 3413 mb_c = utfc_ptr2char(ptr, &u8c_c1, &u8c_c2); 3414 /* Overlong encoded ASCII or ASCII with composing char 3415 * is displayed normally, except a NUL. */ 3416 if (mb_c < 0x80) 3417 c = mb_c; 3418 mb_utf8 = TRUE; 3419 } 3420 3421 if ((mb_l == 1 && c >= 0x80) 3422 || (mb_l >= 1 && mb_c == 0) 3423 || (mb_l > 1 && (!vim_isprintc(mb_c) 3424 || mb_c >= 0x10000))) 3425 { 3426 /* 3427 * Illegal UTF-8 byte: display as <xx>. 3428 * Non-BMP character : display as ? or fullwidth ?. 3429 */ 3430 if (mb_c < 0x10000) 3431 { 3432 transchar_hex(extra, mb_c); 3433 #ifdef FEAT_RIGHTLEFT 3434 if (wp->w_p_rl) /* reverse */ 3435 rl_mirror(extra); 3436 #endif 3437 } 3438 else if (utf_char2cells(mb_c) != 2) 3439 STRCPY(extra, "?"); 3440 else 3441 /* 0xff1f in UTF-8: full-width '?' */ 3442 STRCPY(extra, "\357\274\237"); 3443 3444 p_extra = extra; 3445 c = *p_extra; 3446 mb_c = mb_ptr2char_adv(&p_extra); 3447 mb_utf8 = (c >= 0x80); 3448 n_extra = (int)STRLEN(p_extra); 3449 c_extra = NUL; 3450 if (area_attr == 0 && search_attr == 0) 3451 { 3452 n_attr = n_extra + 1; 3453 extra_attr = hl_attr(HLF_8); 3454 saved_attr2 = char_attr; /* save current attr */ 3455 } 3456 } 3457 else if (mb_l == 0) /* at the NUL at end-of-line */ 3458 mb_l = 1; 3459 #ifdef FEAT_ARABIC 3460 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) 3461 { 3462 /* Do Arabic shaping. */ 3463 int pc, pc1, nc, dummy; 3464 3465 /* The idea of what is the previous and next 3466 * character depends on 'rightleft'. */ 3467 if (wp->w_p_rl) 3468 { 3469 pc = prev_c; 3470 pc1 = prev_c1; 3471 nc = utf_ptr2char(ptr + mb_l); 3472 prev_c1 = u8c_c1; 3473 } 3474 else 3475 { 3476 pc = utfc_ptr2char(ptr + mb_l, &pc1, &dummy); 3477 nc = prev_c; 3478 } 3479 prev_c = mb_c; 3480 3481 mb_c = arabic_shape(mb_c, &c, &u8c_c1, pc, pc1, nc); 3482 } 3483 else 3484 prev_c = mb_c; 3485 #endif 3486 } 3487 else /* enc_dbcs */ 3488 { 3489 mb_l = MB_BYTE2LEN(c); 3490 if (mb_l == 0) /* at the NUL at end-of-line */ 3491 mb_l = 1; 3492 else if (mb_l > 1) 3493 { 3494 /* We assume a second byte below 32 is illegal. 3495 * Hopefully this is OK for all double-byte encodings! 3496 */ 3497 if (ptr[1] >= 32) 3498 mb_c = (c << 8) + ptr[1]; 3499 else 3500 { 3501 if (ptr[1] == NUL) 3502 { 3503 /* head byte at end of line */ 3504 mb_l = 1; 3505 transchar_nonprint(extra, c); 3506 } 3507 else 3508 { 3509 /* illegal tail byte */ 3510 mb_l = 2; 3511 STRCPY(extra, "XX"); 3512 } 3513 p_extra = extra; 3514 n_extra = (int)STRLEN(extra) - 1; 3515 c_extra = NUL; 3516 c = *p_extra++; 3517 if (area_attr == 0 && search_attr == 0) 3518 { 3519 n_attr = n_extra + 1; 3520 extra_attr = hl_attr(HLF_8); 3521 saved_attr2 = char_attr; /* save current attr */ 3522 } 3523 mb_c = c; 3524 } 3525 } 3526 } 3527 /* If a double-width char doesn't fit display a '>' in the 3528 * last column; the character is displayed at the start of the 3529 * next line. */ 3530 if (( 3531 # ifdef FEAT_RIGHTLEFT 3532 wp->w_p_rl ? (col <= 0) : 3533 # endif 3534 (col >= W_WIDTH(wp) - 1)) 3535 && (*mb_char2cells)(mb_c) == 2) 3536 { 3537 c = '>'; 3538 mb_c = c; 3539 mb_utf8 = FALSE; 3540 mb_l = 1; 3541 multi_attr = hl_attr(HLF_AT); 3542 /* Put pointer back so that the character will be 3543 * displayed at the start of the next line. */ 3544 --ptr; 3545 } 3546 else if (*ptr != NUL) 3547 ptr += mb_l - 1; 3548 3549 /* If a double-width char doesn't fit at the left side display 3550 * a '<' in the first column. */ 3551 if (n_skip > 0 && mb_l > 1) 3552 { 3553 extra[0] = '<'; 3554 p_extra = extra; 3555 n_extra = 1; 3556 c_extra = NUL; 3557 c = ' '; 3558 if (area_attr == 0 && search_attr == 0) 3559 { 3560 n_attr = n_extra + 1; 3561 extra_attr = hl_attr(HLF_AT); 3562 saved_attr2 = char_attr; /* save current attr */ 3563 } 3564 mb_c = c; 3565 mb_utf8 = FALSE; 3566 mb_l = 1; 3567 } 3568 3569 } 3570 #endif 3571 ++ptr; 3572 3573 /* 'list' : change char 160 to lcs_nbsp. */ 3574 if (wp->w_p_list && c == 160 && lcs_nbsp) 3575 { 3576 c = lcs_nbsp; 3577 if (area_attr == 0 && search_attr == 0) 3578 { 3579 n_attr = 1; 3580 extra_attr = hl_attr(HLF_8); 3581 saved_attr2 = char_attr; /* save current attr */ 3582 } 3583 #ifdef FEAT_MBYTE 3584 mb_c = c; 3585 if (enc_utf8 && (*mb_char2len)(c) > 1) 3586 { 3587 mb_utf8 = TRUE; 3588 u8c_c1 = u8c_c2 = 0; 3589 } 3590 else 3591 mb_utf8 = FALSE; 3592 #endif 3593 } 3594 3595 if (extra_check) 3596 { 3597 #ifdef FEAT_SYN_HL 3598 /* Get syntax attribute, unless still at the start of the line 3599 * (double-wide char that doesn't fit). */ 3600 if (has_syntax && (v = (long)(ptr - line)) > 0) 3601 { 3602 /* Get the syntax attribute for the character. If there 3603 * is an error, disable syntax highlighting. */ 3604 save_did_emsg = did_emsg; 3605 did_emsg = FALSE; 3606 3607 syntax_attr = get_syntax_attr((colnr_T)v - 1); 3608 3609 if (did_emsg) 3610 syntax_clear(wp->w_buffer); 3611 else 3612 did_emsg = save_did_emsg; 3613 3614 /* Need to get the line again, a multi-line regexp may 3615 * have made it invalid. */ 3616 line = ml_get_buf(wp->w_buffer, lnum, FALSE); 3617 ptr = line + v; 3618 3619 if (area_attr == 0 && search_attr == 0) 3620 char_attr = syntax_attr; 3621 } 3622 #endif 3623 #ifdef FEAT_LINEBREAK 3624 /* 3625 * Found last space before word: check for line break 3626 */ 3627 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) 3628 && !wp->w_p_list) 3629 { 3630 n_extra = win_lbr_chartabsize(wp, ptr - ( 3631 # ifdef FEAT_MBYTE 3632 has_mbyte ? mb_l : 3633 # endif 3634 1), (colnr_T)vcol, NULL) - 1; 3635 c_extra = ' '; 3636 if (vim_iswhite(c)) 3637 c = ' '; 3638 } 3639 #endif 3640 3641 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') 3642 { 3643 c = lcs_trail; 3644 if (area_attr == 0 && search_attr == 0) 3645 { 3646 n_attr = 1; 3647 extra_attr = hl_attr(HLF_8); 3648 saved_attr2 = char_attr; /* save current attr */ 3649 } 3650 #ifdef FEAT_MBYTE 3651 mb_c = c; 3652 if (enc_utf8 && (*mb_char2len)(c) > 1) 3653 { 3654 mb_utf8 = TRUE; 3655 u8c_c1 = u8c_c2 = 0; 3656 } 3657 else 3658 mb_utf8 = FALSE; 3659 #endif 3660 } 3661 } 3662 3663 /* 3664 * Handling of non-printable characters. 3665 */ 3666 if (!(chartab[c] & CT_PRINT_CHAR)) 3667 { 3668 /* 3669 * when getting a character from the file, we may have to 3670 * turn it into something else on the way to putting it 3671 * into "ScreenLines". 3672 */ 3673 if (c == TAB && (!wp->w_p_list || lcs_tab1)) 3674 { 3675 /* tab amount depends on current column */ 3676 n_extra = (int)wp->w_buffer->b_p_ts 3677 - vcol % (int)wp->w_buffer->b_p_ts - 1; 3678 #ifdef FEAT_MBYTE 3679 mb_utf8 = FALSE; /* don't draw as UTF-8 */ 3680 #endif 3681 if (wp->w_p_list) 3682 { 3683 c = lcs_tab1; 3684 c_extra = lcs_tab2; 3685 n_attr = n_extra + 1; 3686 extra_attr = hl_attr(HLF_8); 3687 saved_attr2 = char_attr; /* save current attr */ 3688 #ifdef FEAT_MBYTE 3689 mb_c = c; 3690 if (enc_utf8 && (*mb_char2len)(c) > 1) 3691 { 3692 mb_utf8 = TRUE; 3693 u8c_c1 = u8c_c2 = 0; 3694 } 3695 #endif 3696 } 3697 else 3698 { 3699 c_extra = ' '; 3700 c = ' '; 3701 } 3702 } 3703 else if (c == NUL && wp->w_p_list && lcs_eol_one > 0) 3704 { 3705 #if defined(FEAT_DIFF) || defined(LINE_ATTR) 3706 /* For a diff line the highlighting continues after the 3707 * "$". */ 3708 if ( 3709 # ifdef FEAT_DIFF 3710 diff_hlf == (enum hlf_value)0 3711 # ifdef LINE_ATTR 3712 && 3713 # endif 3714 # endif 3715 # ifdef LINE_ATTR 3716 line_attr == 0 3717 # endif 3718 ) 3719 #endif 3720 { 3721 #ifdef FEAT_VIRTUALEDIT 3722 /* In virtualedit, visual selections may extend 3723 * beyond end of line. */ 3724 if (area_highlighting && virtual_active() 3725 && tocol != MAXCOL && vcol < tocol) 3726 n_extra = 0; 3727 else 3728 #endif 3729 { 3730 p_extra = at_end_str; 3731 n_extra = 1; 3732 c_extra = NUL; 3733 } 3734 } 3735 c = lcs_eol; 3736 lcs_eol_one = -1; 3737 --ptr; /* put it back at the NUL */ 3738 if (area_attr == 0 && search_attr == 0) 3739 { 3740 extra_attr = hl_attr(HLF_AT); 3741 n_attr = 1; 3742 } 3743 #ifdef FEAT_MBYTE 3744 mb_c = c; 3745 if (enc_utf8 && (*mb_char2len)(c) > 1) 3746 { 3747 mb_utf8 = TRUE; 3748 u8c_c1 = u8c_c2 = 0; 3749 } 3750 else 3751 mb_utf8 = FALSE; /* don't draw as UTF-8 */ 3752 #endif 3753 } 3754 else if (c != NUL) 3755 { 3756 p_extra = transchar(c); 3757 #ifdef FEAT_RIGHTLEFT 3758 if ((dy_flags & DY_UHEX) && wp->w_p_rl) 3759 rl_mirror(p_extra); /* reverse "<12>" */ 3760 #endif 3761 n_extra = byte2cells(c) - 1; 3762 c_extra = NUL; 3763 c = *p_extra++; 3764 if (area_attr == 0 && search_attr == 0) 3765 { 3766 n_attr = n_extra + 1; 3767 extra_attr = hl_attr(HLF_8); 3768 saved_attr2 = char_attr; /* save current attr */ 3769 } 3770 #ifdef FEAT_MBYTE 3771 mb_utf8 = FALSE; /* don't draw as UTF-8 */ 3772 #endif 3773 } 3774 #ifdef FEAT_VIRTUALEDIT 3775 else if (VIsual_active 3776 && (VIsual_mode == Ctrl_V 3777 || VIsual_mode == 'v') 3778 && virtual_active() 3779 && tocol != MAXCOL 3780 && vcol < tocol 3781 && ( 3782 # ifdef FEAT_RIGHTLEFT 3783 wp->w_p_rl ? (col >= 0) : 3784 # endif 3785 (col < W_WIDTH(wp)))) 3786 { 3787 c = ' '; 3788 --ptr; /* put it back at the NUL */ 3789 } 3790 #endif 3791 #if defined(FEAT_DIFF) || defined(LINE_ATTR) 3792 else if (( 3793 # ifdef FEAT_DIFF 3794 diff_hlf != (enum hlf_value)0 3795 # ifdef LINE_ATTR 3796 || 3797 # endif 3798 # endif 3799 # ifdef LINE_ATTR 3800 line_attr != 0 3801 # endif 3802 ) && ( 3803 # ifdef FEAT_RIGHTLEFT 3804 wp->w_p_rl ? (col >= 0) : 3805 # endif 3806 (col < W_WIDTH(wp)))) 3807 { 3808 /* Highlight until the right side of the window */ 3809 c = ' '; 3810 --ptr; /* put it back at the NUL */ 3811 # ifdef FEAT_DIFF 3812 if (diff_hlf == HLF_TXD) 3813 { 3814 diff_hlf = HLF_CHD; 3815 if (attr == 0 || char_attr != attr) 3816 char_attr = hl_attr(diff_hlf); 3817 } 3818 # endif 3819 } 3820 #endif 3821 } 3822 } 3823 3824 /* Don't override visual selection highlighting. */ 3825 if (n_attr > 0 3826 && draw_state == WL_LINE 3827 && (area_attr == 0 || char_attr != area_attr) 3828 && (search_attr == 0 || char_attr != search_attr)) 3829 char_attr = extra_attr; 3830 3831 #if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)) 3832 /* XIM don't send preedit_start and preedit_end, but they send 3833 * preedit_changed and commit. Thus Vim can't set "im_is_active", use 3834 * im_is_preediting() here. */ 3835 if (xic != NULL 3836 && lnum == curwin->w_cursor.lnum 3837 && (State & INSERT) 3838 && !p_imdisable 3839 && im_is_preediting() 3840 && draw_state == WL_LINE) 3841 { 3842 colnr_T tcol; 3843 3844 if (preedit_end_col == MAXCOL) 3845 getvcol(curwin, &(curwin->w_cursor), &tcol, NULL, NULL); 3846 else 3847 tcol = preedit_end_col; 3848 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) 3849 { 3850 if (feedback_old_attr < 0) 3851 { 3852 feedback_col = 0; 3853 feedback_old_attr = char_attr; 3854 } 3855 char_attr = im_get_feedback_attr(feedback_col); 3856 if (char_attr < 0) 3857 char_attr = feedback_old_attr; 3858 feedback_col++; 3859 } 3860 else if (feedback_old_attr >= 0) 3861 { 3862 char_attr = feedback_old_attr; 3863 feedback_old_attr = -1; 3864 feedback_col = 0; 3865 } 3866 } 3867 #endif 3868 /* 3869 * Handle the case where we are in column 0 but not on the first 3870 * character of the line and the user wants us to show us a 3871 * special character (via 'listchars' option "precedes:<char>". 3872 */ 3873 if (lcs_prec_todo != NUL 3874 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) 3875 #ifdef FEAT_DIFF 3876 && filler_todo <= 0 3877 #endif 3878 && draw_state > WL_NR 3879 && c != NUL) 3880 { 3881 c = lcs_prec; 3882 lcs_prec_todo = NUL; 3883 #ifdef FEAT_MBYTE 3884 mb_c = c; 3885 if (enc_utf8 && (*mb_char2len)(c) > 1) 3886 { 3887 mb_utf8 = TRUE; 3888 u8c_c1 = u8c_c2 = 0; 3889 } 3890 else 3891 mb_utf8 = FALSE; /* don't draw as UTF-8 */ 3892 #endif 3893 if ((area_attr == 0 || char_attr != area_attr) 3894 && (search_attr == 0 || char_attr != search_attr)) 3895 { 3896 saved_attr3 = char_attr; /* save current attr */ 3897 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ 3898 n_attr3 = 1; 3899 } 3900 } 3901 3902 /* 3903 * At end of the text line. 3904 */ 3905 if (c == NUL) 3906 { 3907 /* invert at least one char, used for Visual and empty line or 3908 * highlight match at end of line. If it's beyond the last 3909 * char on the screen, just overwrite that one (tricky!) Not 3910 * needed when a '$' was displayed for 'list'. */ 3911 if (lcs_eol == lcs_eol_one 3912 && ((area_attr != 0 && vcol == fromcol) 3913 #ifdef FEAT_SEARCH_EXTRA 3914 /* highlight 'hlsearch' match at end of line */ 3915 || ptr - 1 == search_hl.startp 3916 || ptr - 1 == match_hl.startp 3917 #endif 3918 )) 3919 { 3920 int n = 0; 3921 3922 #ifdef FEAT_RIGHTLEFT 3923 if (wp->w_p_rl) 3924 { 3925 if (col < 0) 3926 n = 1; 3927 } 3928 else 3929 #endif 3930 { 3931 if (col >= W_WIDTH(wp)) 3932 n = -1; 3933 } 3934 if (n != 0) 3935 { 3936 /* At the window boundary, highlight the last character 3937 * instead (better than nothing). */ 3938 off += n; 3939 col += n; 3940 } 3941 else 3942 { 3943 /* Add a blank character to highlight. */ 3944 ScreenLines[off] = ' '; 3945 #ifdef FEAT_MBYTE 3946 if (enc_utf8) 3947 ScreenLinesUC[off] = 0; 3948 #endif 3949 } 3950 #ifdef FEAT_SEARCH_EXTRA 3951 if (area_attr == 0) 3952 { 3953 if (ptr - 1 == match_hl.startp) 3954 char_attr = match_hl.attr; 3955 else 3956 char_attr = search_hl.attr; 3957 } 3958 #endif 3959 ScreenAttrs[off] = char_attr; 3960 #ifdef FEAT_RIGHTLEFT 3961 if (wp->w_p_rl) 3962 --col; 3963 else 3964 #endif 3965 ++col; 3966 } 3967 3968 SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), 3969 wp->w_p_rl); 3970 row++; 3971 3972 /* 3973 * Update w_cline_height and w_cline_folded if the cursor line was 3974 * updated (saves a call to plines() later). 3975 */ 3976 if (wp == curwin && lnum == curwin->w_cursor.lnum) 3977 { 3978 curwin->w_cline_row = startrow; 3979 curwin->w_cline_height = row - startrow; 3980 #ifdef FEAT_FOLDING 3981 curwin->w_cline_folded = FALSE; 3982 #endif 3983 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); 3984 } 3985 3986 break; 3987 } 3988 3989 /* line continues beyond line end */ 3990 if (lcs_ext 3991 && !wp->w_p_wrap 3992 #ifdef FEAT_DIFF 3993 && filler_todo <= 0 3994 #endif 3995 && ( 3996 #ifdef FEAT_RIGHTLEFT 3997 wp->w_p_rl ? col == 0 : 3998 #endif 3999 col == W_WIDTH(wp) - 1) 4000 && (*ptr != NUL 4001 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) 4002 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) 4003 { 4004 c = lcs_ext; 4005 char_attr = hl_attr(HLF_AT); 4006 #ifdef FEAT_MBYTE 4007 mb_c = c; 4008 if (enc_utf8 && (*mb_char2len)(c) > 1) 4009 { 4010 mb_utf8 = TRUE; 4011 u8c_c1 = u8c_c2 = 0; 4012 } 4013 else 4014 mb_utf8 = FALSE; 4015 #endif 4016 } 4017 4018 /* 4019 * Store character to be displayed. 4020 * Skip characters that are left of the screen for 'nowrap'. 4021 */ 4022 vcol_prev = vcol; 4023 if (draw_state < WL_LINE || n_skip <= 0) 4024 { 4025 /* 4026 * Store the character. 4027 */ 4028 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) 4029 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) 4030 { 4031 /* A double-wide character is: put first halve in left cell. */ 4032 --off; 4033 --col; 4034 } 4035 #endif 4036 ScreenLines[off] = c; 4037 #ifdef FEAT_MBYTE 4038 if (enc_dbcs == DBCS_JPNU) 4039 ScreenLines2[off] = mb_c & 0xff; 4040 else if (enc_utf8) 4041 { 4042 if (mb_utf8) 4043 { 4044 ScreenLinesUC[off] = mb_c; 4045 ScreenLinesC1[off] = u8c_c1; 4046 ScreenLinesC2[off] = u8c_c2; 4047 } 4048 else 4049 ScreenLinesUC[off] = 0; 4050 } 4051 if (multi_attr) 4052 { 4053 ScreenAttrs[off] = multi_attr; 4054 multi_attr = 0; 4055 } 4056 else 4057 #endif 4058 ScreenAttrs[off] = char_attr; 4059 4060 #ifdef FEAT_MBYTE 4061 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) 4062 { 4063 /* Need to fill two screen columns. */ 4064 ++off; 4065 ++col; 4066 if (enc_utf8) 4067 /* UTF-8: Put a 0 in the second screen char. */ 4068 ScreenLines[off] = 0; 4069 else 4070 /* DBCS: Put second byte in the second screen char. */ 4071 ScreenLines[off] = mb_c & 0xff; 4072 ++vcol; 4073 /* When "tocol" is halfway a character, set it to the end of 4074 * the character, otherwise highlighting won't stop. */ 4075 if (tocol == vcol) 4076 ++tocol; 4077 #ifdef FEAT_RIGHTLEFT 4078 if (wp->w_p_rl) 4079 { 4080 /* now it's time to backup one cell */ 4081 --off; 4082 --col; 4083 } 4084 #endif 4085 } 4086 #endif 4087 #ifdef FEAT_RIGHTLEFT 4088 if (wp->w_p_rl) 4089 { 4090 --off; 4091 --col; 4092 } 4093 else 4094 #endif 4095 { 4096 ++off; 4097 ++col; 4098 } 4099 } 4100 else 4101 --n_skip; 4102 4103 /* Only advance the "vcol" when after the 'number' column. */ 4104 if (draw_state >= WL_SBR 4105 #ifdef FEAT_DIFF 4106 && filler_todo <= 0 4107 #endif 4108 ) 4109 ++vcol; 4110 4111 /* restore attributes after "predeces" in 'listchars' */ 4112 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) 4113 char_attr = saved_attr3; 4114 4115 /* restore attributes after last 'listchars' or 'number' char */ 4116 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) 4117 char_attr = saved_attr2; 4118 4119 /* 4120 * At end of screen line and there is more to come: Display the line 4121 * so far. If there is no more to display it is catched above. 4122 */ 4123 if (( 4124 #ifdef FEAT_RIGHTLEFT 4125 wp->w_p_rl ? (col < 0) : 4126 #endif 4127 (col >= W_WIDTH(wp))) 4128 && (*ptr != NUL 4129 #ifdef FEAT_DIFF 4130 || filler_todo > 0 4131 #endif 4132 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) 4133 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) 4134 ) 4135 { 4136 SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), 4137 wp->w_p_rl); 4138 ++row; 4139 ++screen_row; 4140 4141 /* When not wrapping and finished diff lines, or when displayed 4142 * '$' and highlighting until last column, break here. */ 4143 if ((!wp->w_p_wrap 4144 #ifdef FEAT_DIFF 4145 && filler_todo <= 0 4146 #endif 4147 ) || lcs_eol_one == -1) 4148 break; 4149 4150 /* When the window is too narrow draw all "@" lines. */ 4151 if (draw_state != WL_LINE 4152 #ifdef FEAT_DIFF 4153 && filler_todo <= 0 4154 #endif 4155 ) 4156 { 4157 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); 4158 #ifdef FEAT_VERTSPLIT 4159 draw_vsep_win(wp, row); 4160 #endif 4161 row = endrow; 4162 } 4163 4164 /* When line got too long for screen break here. */ 4165 if (row == endrow) 4166 { 4167 ++row; 4168 break; 4169 } 4170 4171 if (screen_cur_row == screen_row - 1 4172 #ifdef FEAT_DIFF 4173 && filler_todo <= 0 4174 #endif 4175 && W_WIDTH(wp) == Columns) 4176 { 4177 /* Remember that the line wraps, used for modeless copy. */ 4178 LineWraps[screen_row - 1] = TRUE; 4179 4180 /* 4181 * Special trick to make copy/paste of wrapped lines work with 4182 * xterm/screen: write an extra character beyond the end of 4183 * the line. This will work with all terminal types 4184 * (regardless of the xn,am settings). 4185 * Only do this on a fast tty. 4186 * Only do this if the cursor is on the current line 4187 * (something has been written in it). 4188 * Don't do this for the GUI. 4189 * Don't do this for double-width characters. 4190 * Don't do this for a window not at the right screen border. 4191 */ 4192 if (p_tf 4193 #ifdef FEAT_GUI 4194 && !gui.in_use 4195 #endif 4196 #ifdef FEAT_MBYTE 4197 && !(has_mbyte 4198 && ((*mb_off2cells)(LineOffset[screen_row]) == 2 4199 || (*mb_off2cells)(LineOffset[screen_row - 1] 4200 + (int)Columns - 2) == 2)) 4201 #endif 4202 ) 4203 { 4204 /* First make sure we are at the end of the screen line, 4205 * then output the same character again to let the 4206 * terminal know about the wrap. If the terminal doesn't 4207 * auto-wrap, we overwrite the character. */ 4208 if (screen_cur_col != W_WIDTH(wp)) 4209 screen_char(LineOffset[screen_row - 1] 4210 + (unsigned)Columns - 1, 4211 screen_row - 1, (int)(Columns - 1)); 4212 4213 #ifdef FEAT_MBYTE 4214 /* When there is a multi-byte character, just output a 4215 * space to keep it simple. */ 4216 if (has_mbyte && mb_off2cells(LineOffset[screen_row - 1] 4217 + (unsigned)Columns - 1) != 1) 4218 out_char(' '); 4219 else 4220 #endif 4221 out_char(ScreenLines[LineOffset[screen_row - 1] 4222 + (Columns - 1)]); 4223 /* force a redraw of the first char on the next line */ 4224 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; 4225 screen_start(); /* don't know where cursor is now */ 4226 } 4227 } 4228 4229 col = 0; 4230 off = (unsigned)(current_ScreenLine - ScreenLines); 4231 #ifdef FEAT_RIGHTLEFT 4232 if (wp->w_p_rl) 4233 { 4234 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ 4235 off += col; 4236 } 4237 #endif 4238 4239 /* reset the drawing state for the start of a wrapped line */ 4240 draw_state = WL_START; 4241 saved_n_extra = n_extra; 4242 saved_p_extra = p_extra; 4243 saved_c_extra = c_extra; 4244 saved_char_attr = char_attr; 4245 n_extra = 0; 4246 lcs_prec_todo = lcs_prec; 4247 #ifdef FEAT_LINEBREAK 4248 # ifdef FEAT_DIFF 4249 if (filler_todo <= 0) 4250 # endif 4251 need_showbreak = TRUE; 4252 #endif 4253 #ifdef FEAT_DIFF 4254 --filler_todo; 4255 /* When the filler lines are actually below the last line of the 4256 * file, don't draw the line itself, break here. */ 4257 if (filler_todo == 0 && wp->w_botfill) 4258 break; 4259 #endif 4260 } 4261 4262 } /* for every character in the line */ 4263 4264 return row; 4265 } 4266 4267 /* 4268 * Check whether the given character needs redrawing: 4269 * - the (first byte of the) character is different 4270 * - the attributes are different 4271 * - the character is multi-byte and the next byte is different 4272 */ 4273 static int 4274 char_needs_redraw(off_from, off_to, cols) 4275 int off_from; 4276 int off_to; 4277 int cols; 4278 { 4279 if (cols > 0 4280 && ((ScreenLines[off_from] != ScreenLines[off_to] 4281 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) 4282 4283 #ifdef FEAT_MBYTE 4284 || (enc_dbcs != 0 4285 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 4286 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e 4287 ? ScreenLines2[off_from] != ScreenLines2[off_to] 4288 : (cols > 1 && ScreenLines[off_from + 1] 4289 != ScreenLines[off_to + 1]))) 4290 || (enc_utf8 4291 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] 4292 || (ScreenLinesUC[off_from] != 0 4293 && (ScreenLinesC1[off_from] 4294 != ScreenLinesC1[off_to] 4295 || ScreenLinesC2[off_from] 4296 != ScreenLinesC2[off_to])))) 4297 #endif 4298 )) 4299 return TRUE; 4300 return FALSE; 4301 } 4302 4303 /* 4304 * Move one "cooked" screen line to the screen, but only the characters that 4305 * have actually changed. Handle insert/delete character. 4306 * "coloff" gives the first column on the screen for this line. 4307 * "endcol" gives the columns where valid characters are. 4308 * "clear_width" is the width of the window. It's > 0 if the rest of the line 4309 * needs to be cleared, negative otherwise. 4310 * "rlflag" is TRUE in a rightleft window: 4311 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" 4312 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" 4313 */ 4314 static void 4315 screen_line(row, coloff, endcol, clear_width 4316 #ifdef FEAT_RIGHTLEFT 4317 , rlflag 4318 #endif 4319 ) 4320 int row; 4321 int coloff; 4322 int endcol; 4323 int clear_width; 4324 #ifdef FEAT_RIGHTLEFT 4325 int rlflag; 4326 #endif 4327 { 4328 unsigned off_from; 4329 unsigned off_to; 4330 int col = 0; 4331 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) 4332 int hl; 4333 #endif 4334 int force = FALSE; /* force update rest of the line */ 4335 int redraw_this /* bool: does character need redraw? */ 4336 #ifdef FEAT_GUI 4337 = TRUE /* For GUI when while-loop empty */ 4338 #endif 4339 ; 4340 int redraw_next; /* redraw_this for next character */ 4341 #ifdef FEAT_MBYTE 4342 int clear_next = FALSE; 4343 int char_cells; /* 1: normal char */ 4344 /* 2: occupies two display cells */ 4345 # define CHAR_CELLS char_cells 4346 #else 4347 # define CHAR_CELLS 1 4348 #endif 4349 4350 # ifdef FEAT_CLIPBOARD 4351 clip_may_clear_selection(row, row); 4352 # endif 4353 4354 off_from = (unsigned)(current_ScreenLine - ScreenLines); 4355 off_to = LineOffset[row] + coloff; 4356 4357 #ifdef FEAT_RIGHTLEFT 4358 if (rlflag) 4359 { 4360 /* Clear rest first, because it's left of the text. */ 4361 if (clear_width > 0) 4362 { 4363 while (col <= endcol && ScreenLines[off_to] == ' ' 4364 && ScreenAttrs[off_to] == 0 4365 # ifdef FEAT_MBYTE 4366 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) 4367 # endif 4368 ) 4369 { 4370 ++off_to; 4371 ++col; 4372 } 4373 if (col <= endcol) 4374 screen_fill(row, row + 1, col + coloff, 4375 endcol + coloff + 1, ' ', ' ', 0); 4376 } 4377 col = endcol + 1; 4378 off_to = LineOffset[row] + col + coloff; 4379 off_from += col; 4380 endcol = (clear_width > 0 ? clear_width : -clear_width); 4381 } 4382 #endif /* FEAT_RIGHTLEFT */ 4383 4384 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); 4385 4386 while (col < endcol) 4387 { 4388 #ifdef FEAT_MBYTE 4389 if (has_mbyte && (col + 1 < endcol)) 4390 char_cells = (*mb_off2cells)(off_from); 4391 else 4392 char_cells = 1; 4393 #endif 4394 4395 redraw_this = redraw_next; 4396 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, 4397 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); 4398 4399 #ifdef FEAT_GUI 4400 /* If the next character was bold, then redraw the current character to 4401 * remove any pixels that might have spilt over into us. This only 4402 * happens in the GUI. 4403 */ 4404 if (redraw_next && gui.in_use) 4405 { 4406 hl = ScreenAttrs[off_to + CHAR_CELLS]; 4407 if (hl > HL_ALL || (hl & HL_BOLD)) 4408 redraw_this = TRUE; 4409 } 4410 #endif 4411 4412 if (redraw_this) 4413 { 4414 /* 4415 * Special handling when 'xs' termcap flag set (hpterm): 4416 * Attributes for characters are stored at the position where the 4417 * cursor is when writing the highlighting code. The 4418 * start-highlighting code must be written with the cursor on the 4419 * first highlighted character. The stop-highlighting code must 4420 * be written with the cursor just after the last highlighted 4421 * character. 4422 * Overwriting a character doesn't remove it's highlighting. Need 4423 * to clear the rest of the line, and force redrawing it 4424 * completely. 4425 */ 4426 if ( p_wiv 4427 && !force 4428 #ifdef FEAT_GUI 4429 && !gui.in_use 4430 #endif 4431 && ScreenAttrs[off_to] != 0 4432 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) 4433 { 4434 /* 4435 * Need to remove highlighting attributes here. 4436 */ 4437 windgoto(row, col + coloff); 4438 out_str(T_CE); /* clear rest of this screen line */ 4439 screen_start(); /* don't know where cursor is now */ 4440 force = TRUE; /* force redraw of rest of the line */ 4441 redraw_next = TRUE; /* or else next char would miss out */ 4442 4443 /* 4444 * If the previous character was highlighted, need to stop 4445 * highlighting at this character. 4446 */ 4447 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) 4448 { 4449 screen_attr = ScreenAttrs[off_to - 1]; 4450 term_windgoto(row, col + coloff); 4451 screen_stop_highlight(); 4452 } 4453 else 4454 screen_attr = 0; /* highlighting has stopped */ 4455 } 4456 #ifdef FEAT_MBYTE 4457 if (enc_dbcs != 0) 4458 { 4459 /* Check if overwriting a double-byte with a single-byte or 4460 * the other way around requires another character to be 4461 * redrawn. For UTF-8 this isn't needed, because comparing 4462 * ScreenLinesUC[] is sufficient. */ 4463 if (char_cells == 1 4464 && col + 1 < endcol 4465 && (*mb_off2cells)(off_to) > 1) 4466 { 4467 /* Writing a single-cell character over a double-cell 4468 * character: need to redraw the next cell. */ 4469 ScreenLines[off_to + 1] = 0; 4470 redraw_next = TRUE; 4471 } 4472 else if (char_cells == 2 4473 && col + 2 < endcol 4474 && (*mb_off2cells)(off_to) == 1 4475 && (*mb_off2cells)(off_to + 1) > 1) 4476 { 4477 /* Writing the second half of a double-cell character over 4478 * a double-cell character: need to redraw the second 4479 * cell. */ 4480 ScreenLines[off_to + 2] = 0; 4481 redraw_next = TRUE; 4482 } 4483 4484 if (enc_dbcs == DBCS_JPNU) 4485 ScreenLines2[off_to] = ScreenLines2[off_from]; 4486 } 4487 /* When writing a single-width character over a double-width 4488 * character and at the end of the redrawn text, need to clear out 4489 * the right halve of the old character. 4490 * Also required when writing the right halve of a double-width 4491 * char over the left halve of an existing one. */ 4492 if (has_mbyte && col + char_cells == endcol 4493 && ((char_cells == 1 4494 && (*mb_off2cells)(off_to) > 1) 4495 || (char_cells == 2 4496 && (*mb_off2cells)(off_to) == 1 4497 && (*mb_off2cells)(off_to + 1) > 1))) 4498 clear_next = TRUE; 4499 #endif 4500 4501 ScreenLines[off_to] = ScreenLines[off_from]; 4502 #ifdef FEAT_MBYTE 4503 if (enc_utf8) 4504 { 4505 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; 4506 if (ScreenLinesUC[off_from] != 0) 4507 { 4508 ScreenLinesC1[off_to] = ScreenLinesC1[off_from]; 4509 ScreenLinesC2[off_to] = ScreenLinesC2[off_from]; 4510 } 4511 } 4512 if (char_cells == 2) 4513 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; 4514 #endif 4515 4516 #if defined(FEAT_GUI) || defined(UNIX) 4517 /* The bold trick makes a single row of pixels appear in the next 4518 * character. When a bold character is removed, the next 4519 * character should be redrawn too. This happens for our own GUI 4520 * and for some xterms. */ 4521 if ( 4522 # ifdef FEAT_GUI 4523 gui.in_use 4524 # endif 4525 # if defined(FEAT_GUI) && defined(UNIX) 4526 || 4527 # endif 4528 # ifdef UNIX 4529 term_is_xterm 4530 # endif 4531 ) 4532 { 4533 hl = ScreenAttrs[off_to]; 4534 if (hl > HL_ALL || (hl & HL_BOLD)) 4535 redraw_next = TRUE; 4536 } 4537 #endif 4538 ScreenAttrs[off_to] = ScreenAttrs[off_from]; 4539 #ifdef FEAT_MBYTE 4540 if (enc_dbcs != 0 && char_cells == 2) 4541 { 4542 /* just a hack: It makes two bytes of DBCS have same attr */ 4543 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; 4544 screen_char_2(off_to, row, col + coloff); 4545 } 4546 else 4547 #endif 4548 screen_char(off_to, row, col + coloff); 4549 } 4550 else if ( p_wiv 4551 #ifdef FEAT_GUI 4552 && !gui.in_use 4553 #endif 4554 && col + coloff > 0) 4555 { 4556 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) 4557 { 4558 /* 4559 * Don't output stop-highlight when moving the cursor, it will 4560 * stop the highlighting when it should continue. 4561 */ 4562 screen_attr = 0; 4563 } 4564 else if (screen_attr != 0) 4565 screen_stop_highlight(); 4566 } 4567 4568 off_to += CHAR_CELLS; 4569 off_from += CHAR_CELLS; 4570 col += CHAR_CELLS; 4571 } 4572 4573 #ifdef FEAT_MBYTE 4574 if (clear_next) 4575 { 4576 /* Clear the second half of a double-wide character of which the left 4577 * half was overwritten with a single-wide character. */ 4578 ScreenLines[off_to] = ' '; 4579 if (enc_utf8) 4580 ScreenLinesUC[off_to] = 0; 4581 screen_char(off_to, row, col + coloff); 4582 } 4583 #endif 4584 4585 if (clear_width > 0 4586 #ifdef FEAT_RIGHTLEFT 4587 && !rlflag 4588 #endif 4589 ) 4590 { 4591 #ifdef FEAT_GUI 4592 int startCol = col; 4593 #endif 4594 4595 /* blank out the rest of the line */ 4596 while (col < clear_width && ScreenLines[off_to] == ' ' 4597 && ScreenAttrs[off_to] == 0 4598 #ifdef FEAT_MBYTE 4599 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) 4600 #endif 4601 ) 4602 { 4603 ++off_to; 4604 ++col; 4605 } 4606 if (col < clear_width) 4607 { 4608 #ifdef FEAT_GUI 4609 /* 4610 * In the GUI, clearing the rest of the line may leave pixels 4611 * behind if the first character cleared was bold. Some bold 4612 * fonts spill over the left. In this case we redraw the previous 4613 * character too. If we didn't skip any blanks above, then we 4614 * only redraw if the character wasn't already redrawn anyway. 4615 */ 4616 if (gui.in_use && (col > startCol || !redraw_this) 4617 # ifdef FEAT_MBYTE 4618 && enc_dbcs == 0 4619 # endif 4620 ) 4621 { 4622 hl = ScreenAttrs[off_to]; 4623 if (hl > HL_ALL || (hl & HL_BOLD)) 4624 screen_char(off_to - 1, row, col + coloff - 1); 4625 } 4626 #endif 4627 screen_fill(row, row + 1, col + coloff, clear_width + coloff, 4628 ' ', ' ', 0); 4629 #ifdef FEAT_VERTSPLIT 4630 off_to += clear_width - col; 4631 col = clear_width; 4632 #endif 4633 } 4634 } 4635 4636 if (clear_width > 0) 4637 { 4638 #ifdef FEAT_VERTSPLIT 4639 /* For a window that's left of another, draw the separator char. */ 4640 if (col + coloff < Columns) 4641 { 4642 int c; 4643 4644 c = fillchar_vsep(&hl); 4645 if (ScreenLines[off_to] != c 4646 # ifdef FEAT_MBYTE 4647 || (enc_utf8 4648 && ScreenLinesUC[off_to] != (c >= 0x80 ? c : 0)) 4649 # endif 4650 || ScreenAttrs[off_to] != hl) 4651 { 4652 ScreenLines[off_to] = c; 4653 ScreenAttrs[off_to] = hl; 4654 # ifdef FEAT_MBYTE 4655 if (enc_utf8) 4656 { 4657 if (c >= 0x80) 4658 { 4659 ScreenLinesUC[off_to] = c; 4660 ScreenLinesC1[off_to] = 0; 4661 ScreenLinesC2[off_to] = 0; 4662 } 4663 else 4664 ScreenLinesUC[off_to] = 0; 4665 } 4666 # endif 4667 screen_char(off_to, row, col + coloff); 4668 } 4669 } 4670 else 4671 #endif 4672 LineWraps[row] = FALSE; 4673 } 4674 } 4675 4676 #ifdef FEAT_RIGHTLEFT 4677 /* 4678 * Mirror text "str" for right-lieft displaying. 4679 */ 4680 static void 4681 rl_mirror(str) 4682 char_u *str; 4683 { 4684 char_u *p1, *p2; 4685 int t; 4686 4687 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) 4688 { 4689 t = *p1; 4690 *p1 = *p2; 4691 *p2 = t; 4692 } 4693 } 4694 #endif 4695 4696 #if defined(FEAT_WINDOWS) || defined(PROTO) 4697 /* 4698 * mark all status lines for redraw; used after first :cd 4699 */ 4700 void 4701 status_redraw_all() 4702 { 4703 win_T *wp; 4704 4705 for (wp = firstwin; wp; wp = wp->w_next) 4706 if (wp->w_status_height) 4707 { 4708 wp->w_redr_status = TRUE; 4709 redraw_later(VALID); 4710 } 4711 } 4712 4713 /* 4714 * mark all status lines of the current buffer for redraw 4715 */ 4716 void 4717 status_redraw_curbuf() 4718 { 4719 win_T *wp; 4720 4721 for (wp = firstwin; wp; wp = wp->w_next) 4722 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) 4723 { 4724 wp->w_redr_status = TRUE; 4725 redraw_later(VALID); 4726 } 4727 } 4728 4729 /* 4730 * Redraw all status lines that need to be redrawn. 4731 */ 4732 void 4733 redraw_statuslines() 4734 { 4735 win_T *wp; 4736 4737 for (wp = firstwin; wp; wp = wp->w_next) 4738 if (wp->w_redr_status) 4739 win_redr_status(wp); 4740 } 4741 #endif 4742 4743 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) 4744 /* 4745 * Redraw all status lines at the bottom of frame "frp". 4746 */ 4747 void 4748 win_redraw_last_status(frp) 4749 frame_T *frp; 4750 { 4751 if (frp->fr_layout == FR_LEAF) 4752 frp->fr_win->w_redr_status = TRUE; 4753 else if (frp->fr_layout == FR_ROW) 4754 { 4755 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) 4756 win_redraw_last_status(frp); 4757 } 4758 else /* frp->fr_layout == FR_COL */ 4759 { 4760 frp = frp->fr_child; 4761 while (frp->fr_next != NULL) 4762 frp = frp->fr_next; 4763 win_redraw_last_status(frp); 4764 } 4765 } 4766 #endif 4767 4768 #ifdef FEAT_VERTSPLIT 4769 /* 4770 * Draw the verticap separator right of window "wp" starting with line "row". 4771 */ 4772 static void 4773 draw_vsep_win(wp, row) 4774 win_T *wp; 4775 int row; 4776 { 4777 int hl; 4778 int c; 4779 4780 if (wp->w_vsep_width) 4781 { 4782 /* draw the vertical separator right of this window */ 4783 c = fillchar_vsep(&hl); 4784 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, 4785 W_ENDCOL(wp), W_ENDCOL(wp) + 1, 4786 c, ' ', hl); 4787 } 4788 } 4789 #endif 4790 4791 #ifdef FEAT_WILDMENU 4792 static int status_match_len __ARGS((expand_T *xp, char_u *s)); 4793 4794 /* 4795 * Get the lenght of an item as it will be shown in the status line. 4796 */ 4797 static int 4798 status_match_len(xp, s) 4799 expand_T *xp; 4800 char_u *s; 4801 { 4802 int len = 0; 4803 4804 #ifdef FEAT_MENU 4805 int emenu = (xp->xp_context == EXPAND_MENUS 4806 || xp->xp_context == EXPAND_MENUNAMES); 4807 4808 /* Check for menu separators - replace with '|'. */ 4809 if (emenu && menu_is_separator(s)) 4810 return 1; 4811 #endif 4812 4813 while (*s != NUL) 4814 { 4815 /* Don't display backslashes used for escaping, they look ugly. */ 4816 if (rem_backslash(s) 4817 #ifdef FEAT_MENU 4818 || (emenu && (s[0] == '\\' && s[1] != NUL)) 4819 #endif 4820 ) 4821 ++s; 4822 #ifdef FEAT_MBYTE 4823 if (has_mbyte) 4824 { 4825 len += ptr2cells(s); 4826 s += (*mb_ptr2len_check)(s); 4827 } 4828 else 4829 #endif 4830 len += ptr2cells(s++); 4831 4832 } 4833 4834 return len; 4835 } 4836 4837 /* 4838 * Show wildchar matches in the status line. 4839 * Show at least the "match" item. 4840 * We start at item 'first_match' in the list and show all matches that fit. 4841 * 4842 * If inversion is possible we use it. Else '=' characters are used. 4843 */ 4844 void 4845 win_redr_status_matches(xp, num_matches, matches, match, showtail) 4846 expand_T *xp; 4847 int num_matches; 4848 char_u **matches; /* list of matches */ 4849 int match; 4850 int showtail; 4851 { 4852 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) 4853 int row; 4854 char_u *buf; 4855 int len; 4856 int clen; /* lenght in screen cells */ 4857 int fillchar; 4858 int attr; 4859 int i; 4860 int highlight = TRUE; 4861 char_u *selstart = NULL; 4862 int selstart_col = 0; 4863 char_u *selend = NULL; 4864 static int first_match = 0; 4865 int add_left = FALSE; 4866 char_u *s; 4867 #ifdef FEAT_MENU 4868 int emenu; 4869 #endif 4870 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) 4871 int l; 4872 #endif 4873 4874 if (matches == NULL) /* interrupted completion? */ 4875 return; 4876 4877 buf = alloc((unsigned)Columns + 1); 4878 if (buf == NULL) 4879 return; 4880 4881 if (match == -1) /* don't show match but original text */ 4882 { 4883 match = 0; 4884 highlight = FALSE; 4885 } 4886 /* count 1 for the ending ">" */ 4887 clen = status_match_len(xp, L_MATCH(match)) + 3; 4888 if (match == 0) 4889 first_match = 0; 4890 else if (match < first_match) 4891 { 4892 /* jumping left, as far as we can go */ 4893 first_match = match; 4894 add_left = TRUE; 4895 } 4896 else 4897 { 4898 /* check if match fits on the screen */ 4899 for (i = first_match; i < match; ++i) 4900 clen += status_match_len(xp, L_MATCH(i)) + 2; 4901 if (first_match > 0) 4902 clen += 2; 4903 /* jumping right, put match at the left */ 4904 if ((long)clen > Columns) 4905 { 4906 first_match = match; 4907 /* if showing the last match, we can add some on the left */ 4908 clen = 2; 4909 for (i = match; i < num_matches; ++i) 4910 { 4911 clen += status_match_len(xp, L_MATCH(i)) + 2; 4912 if ((long)clen >= Columns) 4913 break; 4914 } 4915 if (i == num_matches) 4916 add_left = TRUE; 4917 } 4918 } 4919 if (add_left) 4920 while (first_match > 0) 4921 { 4922 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; 4923 if ((long)clen >= Columns) 4924 break; 4925 --first_match; 4926 } 4927 4928 fillchar = fillchar_status(&attr, TRUE); 4929 4930 if (first_match == 0) 4931 { 4932 *buf = NUL; 4933 len = 0; 4934 } 4935 else 4936 { 4937 STRCPY(buf, "< "); 4938 len = 2; 4939 } 4940 clen = len; 4941 4942 i = first_match; 4943 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) 4944 { 4945 if (i == match) 4946 { 4947 selstart = buf + len; 4948 selstart_col = clen; 4949 } 4950 4951 s = L_MATCH(i); 4952 /* Check for menu separators - replace with '|' */ 4953 #ifdef FEAT_MENU 4954 emenu = (xp->xp_context == EXPAND_MENUS 4955 || xp->xp_context == EXPAND_MENUNAMES); 4956 if (emenu && menu_is_separator(s)) 4957 { 4958 STRCPY(buf + len, transchar('|')); 4959 l = (int)STRLEN(buf + len); 4960 len += l; 4961 clen += l; 4962 } 4963 else 4964 #endif 4965 for ( ; *s != NUL; ++s) 4966 { 4967 /* Don't display backslashes used for escaping, they look ugly. */ 4968 if (rem_backslash(s) 4969 #ifdef FEAT_MENU 4970 || (emenu 4971 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) 4972 #endif 4973 ) 4974 ++s; 4975 clen += ptr2cells(s); 4976 #ifdef FEAT_MBYTE 4977 if (has_mbyte && (l = (*mb_ptr2len_check)(s)) > 1) 4978 { 4979 STRNCPY(buf + len, s, l); 4980 s += l - 1; 4981 len += l; 4982 } 4983 else 4984 #endif 4985 { 4986 STRCPY(buf + len, transchar_byte(*s)); 4987 len += (int)STRLEN(buf + len); 4988 } 4989 } 4990 if (i == match) 4991 selend = buf + len; 4992 4993 *(buf + len++) = ' '; 4994 *(buf + len++) = ' '; 4995 clen += 2; 4996 if (++i == num_matches) 4997 break; 4998 } 4999 5000 if (i != num_matches) 5001 { 5002 *(buf + len++) = '>'; 5003 ++clen; 5004 } 5005 5006 buf[len] = NUL; 5007 5008 row = cmdline_row - 1; 5009 if (row >= 0) 5010 { 5011 if (wild_menu_showing == 0) 5012 { 5013 if (msg_scrolled > 0) 5014 { 5015 /* Put the wildmenu just above the command line. If there is 5016 * no room, scroll the screen one line up. */ 5017 if (cmdline_row == Rows - 1) 5018 { 5019 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); 5020 ++msg_scrolled; 5021 } 5022 else 5023 { 5024 ++cmdline_row; 5025 ++row; 5026 } 5027 wild_menu_showing = WM_SCROLLED; 5028 } 5029 else 5030 { 5031 /* Create status line if needed by setting 'laststatus' to 2. 5032 * Set 'winminheight' to zero to avoid that the window is 5033 * resized. */ 5034 if (lastwin->w_status_height == 0) 5035 { 5036 save_p_ls = p_ls; 5037 save_p_wmh = p_wmh; 5038 p_ls = 2; 5039 p_wmh = 0; 5040 last_status(FALSE); 5041 } 5042 wild_menu_showing = WM_SHOWN; 5043 } 5044 } 5045 5046 screen_puts(buf, row, 0, attr); 5047 if (selstart != NULL && highlight) 5048 { 5049 *selend = NUL; 5050 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); 5051 } 5052 5053 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); 5054 } 5055 5056 #ifdef FEAT_VERTSPLIT 5057 win_redraw_last_status(topframe); 5058 #else 5059 lastwin->w_redr_status = TRUE; 5060 #endif 5061 vim_free(buf); 5062 } 5063 #endif 5064 5065 #if defined(FEAT_WINDOWS) || defined(PROTO) 5066 /* 5067 * Redraw the status line of window wp. 5068 * 5069 * If inversion is possible we use it. Else '=' characters are used. 5070 */ 5071 void 5072 win_redr_status(wp) 5073 win_T *wp; 5074 { 5075 int row; 5076 char_u *p; 5077 int len; 5078 int fillchar; 5079 int attr; 5080 int this_ru_col; 5081 5082 wp->w_redr_status = FALSE; 5083 if (wp->w_status_height == 0) 5084 { 5085 /* no status line, can only be last window */ 5086 redraw_cmdline = TRUE; 5087 } 5088 else if (!redrawing()) 5089 { 5090 /* Don't redraw right now, do it later. */ 5091 wp->w_redr_status = TRUE; 5092 } 5093 #ifdef FEAT_STL_OPT 5094 else if (*p_stl) 5095 { 5096 /* redraw custom status line */ 5097 win_redr_custom(wp, FALSE); 5098 } 5099 #endif 5100 else 5101 { 5102 fillchar = fillchar_status(&attr, wp == curwin); 5103 5104 if (buf_spname(wp->w_buffer) != NULL) 5105 STRCPY(NameBuff, buf_spname(wp->w_buffer)); 5106 else 5107 home_replace(wp->w_buffer, wp->w_buffer->b_fname, NameBuff, 5108 MAXPATHL, TRUE); 5109 trans_characters(NameBuff, MAXPATHL); 5110 p = NameBuff; 5111 len = (int)STRLEN(p); 5112 5113 if (wp->w_buffer->b_help 5114 #ifdef FEAT_QUICKFIX 5115 || wp->w_p_pvw 5116 #endif 5117 || bufIsChanged(wp->w_buffer) 5118 || wp->w_buffer->b_p_ro) 5119 *(p + len++) = ' '; 5120 if (wp->w_buffer->b_help) 5121 { 5122 STRCPY(p + len, _("[help]")); 5123 len += (int)STRLEN(p + len); 5124 } 5125 #ifdef FEAT_QUICKFIX 5126 if (wp->w_p_pvw) 5127 { 5128 STRCPY(p + len, _("[Preview]")); 5129 len += (int)STRLEN(p + len); 5130 } 5131 #endif 5132 if (bufIsChanged(wp->w_buffer)) 5133 { 5134 STRCPY(p + len, "[+]"); 5135 len += 3; 5136 } 5137 if (wp->w_buffer->b_p_ro) 5138 { 5139 STRCPY(p + len, "[RO]"); 5140 len += 4; 5141 } 5142 5143 #ifndef FEAT_VERTSPLIT 5144 this_ru_col = ru_col; 5145 if (this_ru_col < (Columns + 1) / 2) 5146 this_ru_col = (Columns + 1) / 2; 5147 #else 5148 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); 5149 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) 5150 this_ru_col = (W_WIDTH(wp) + 1) / 2; 5151 if (this_ru_col <= 1) 5152 { 5153 p = (char_u *)"<"; /* No room for file name! */ 5154 len = 1; 5155 } 5156 else 5157 #endif 5158 #ifdef FEAT_MBYTE 5159 if (has_mbyte) 5160 { 5161 int clen = 0, i; 5162 5163 /* Count total number of display cells. */ 5164 for (i = 0; p[i] != NUL; i += (*mb_ptr2len_check)(p + i)) 5165 clen += (*mb_ptr2cells)(p + i); 5166 /* Find first character that will fit. 5167 * Going from start to end is much faster for DBCS. */ 5168 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; 5169 i += (*mb_ptr2len_check)(p + i)) 5170 clen -= (*mb_ptr2cells)(p + i); 5171 len = clen; 5172 if (i > 0) 5173 { 5174 p = p + i - 1; 5175 *p = '<'; 5176 ++len; 5177 } 5178 5179 } 5180 else 5181 #endif 5182 if (len > this_ru_col - 1) 5183 { 5184 p += len - (this_ru_col - 1); 5185 *p = '<'; 5186 len = this_ru_col - 1; 5187 } 5188 5189 row = W_WINROW(wp) + wp->w_height; 5190 screen_puts(p, row, W_WINCOL(wp), attr); 5191 screen_fill(row, row + 1, len + W_WINCOL(wp), 5192 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); 5193 5194 if (get_keymap_str(wp, NameBuff, MAXPATHL) 5195 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) 5196 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) 5197 - 1 + W_WINCOL(wp)), attr); 5198 5199 #ifdef FEAT_CMDL_INFO 5200 win_redr_ruler(wp, TRUE); 5201 #endif 5202 } 5203 5204 #ifdef FEAT_VERTSPLIT 5205 /* 5206 * May need to draw the character below the vertical separator. 5207 */ 5208 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) 5209 { 5210 if (stl_connected(wp)) 5211 fillchar = fillchar_status(&attr, wp == curwin); 5212 else 5213 fillchar = fillchar_vsep(&attr); 5214 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), 5215 attr); 5216 } 5217 #endif 5218 } 5219 5220 # ifdef FEAT_VERTSPLIT 5221 /* 5222 * Return TRUE if the status line of window "wp" is connected to the status 5223 * line of the window right of it. If not, then it's a vertical separator. 5224 * Only call if (wp->w_vsep_width != 0). 5225 */ 5226 int 5227 stl_connected(wp) 5228 win_T *wp; 5229 { 5230 frame_T *fr; 5231 5232 fr = wp->w_frame; 5233 while (fr->fr_parent != NULL) 5234 { 5235 if (fr->fr_parent->fr_layout == FR_COL) 5236 { 5237 if (fr->fr_next != NULL) 5238 break; 5239 } 5240 else 5241 { 5242 if (fr->fr_next != NULL) 5243 return TRUE; 5244 } 5245 fr = fr->fr_parent; 5246 } 5247 return FALSE; 5248 } 5249 # endif 5250 5251 #endif /* FEAT_WINDOWS */ 5252 5253 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) 5254 /* 5255 * Get the value to show for the language mappings, active 'keymap'. 5256 */ 5257 int 5258 get_keymap_str(wp, buf, len) 5259 win_T *wp; 5260 char_u *buf; /* buffer for the result */ 5261 int len; /* length of buffer */ 5262 { 5263 char_u *p; 5264 5265 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) 5266 return FALSE; 5267 5268 { 5269 #ifdef FEAT_EVAL 5270 buf_T *old_curbuf = curbuf; 5271 win_T *old_curwin = curwin; 5272 char_u *s; 5273 5274 curbuf = wp->w_buffer; 5275 curwin = wp; 5276 STRCPY(buf, "b:keymap_name"); /* must be writable */ 5277 ++emsg_skip; 5278 s = p = eval_to_string(buf, NULL); 5279 --emsg_skip; 5280 curbuf = old_curbuf; 5281 curwin = old_curwin; 5282 if (p == NULL || *p == NUL) 5283 #endif 5284 { 5285 #ifdef FEAT_KEYMAP 5286 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) 5287 p = wp->w_buffer->b_p_keymap; 5288 else 5289 #endif 5290 p = (char_u *)"lang"; 5291 } 5292 if ((int)(STRLEN(p) + 3) < len) 5293 sprintf((char *)buf, "<%s>", p); 5294 else 5295 buf[0] = NUL; 5296 #ifdef FEAT_EVAL 5297 vim_free(s); 5298 #endif 5299 } 5300 return buf[0] != NUL; 5301 } 5302 #endif 5303 5304 #if defined(FEAT_STL_OPT) || defined(PROTO) 5305 /* 5306 * Redraw the status line or ruler of window wp. 5307 */ 5308 static void 5309 win_redr_custom(wp, Ruler) 5310 win_T *wp; 5311 int Ruler; 5312 { 5313 int attr; 5314 int curattr; 5315 int row; 5316 int col = 0; 5317 int maxwidth; 5318 int width; 5319 int n; 5320 int len; 5321 int fillchar; 5322 char_u buf[MAXPATHL]; 5323 char_u *p; 5324 struct stl_hlrec hl[STL_MAX_ITEM]; 5325 5326 /* setup environment for the task at hand */ 5327 row = W_WINROW(wp) + wp->w_height; 5328 fillchar = fillchar_status(&attr, wp == curwin); 5329 maxwidth = W_WIDTH(wp); 5330 p = p_stl; 5331 if (Ruler) 5332 { 5333 p = p_ruf; 5334 /* advance past any leading group spec - implicit in ru_col */ 5335 if (*p == '%') 5336 { 5337 if (*++p == '-') 5338 p++; 5339 if (atoi((char *) p)) 5340 while (VIM_ISDIGIT(*p)) 5341 p++; 5342 if (*p++ != '(') 5343 p = p_ruf; 5344 } 5345 #ifdef FEAT_VERTSPLIT 5346 col = ru_col - (Columns - W_WIDTH(wp)); 5347 if (col < (W_WIDTH(wp) + 1) / 2) 5348 col = (W_WIDTH(wp) + 1) / 2; 5349 #else 5350 col = ru_col; 5351 if (col > (Columns + 1) / 2) 5352 col = (Columns + 1) / 2; 5353 #endif 5354 maxwidth = W_WIDTH(wp) - col; 5355 #ifdef FEAT_WINDOWS 5356 if (!wp->w_status_height) 5357 #endif 5358 { 5359 row = Rows - 1; 5360 --maxwidth; /* writing in last column may cause scrolling */ 5361 fillchar = ' '; 5362 attr = 0; 5363 } 5364 } 5365 if (maxwidth <= 0) 5366 return; 5367 #ifdef FEAT_VERTSPLIT 5368 col += W_WINCOL(wp); 5369 #endif 5370 5371 width = build_stl_str_hl(wp, buf, sizeof(buf), p, fillchar, maxwidth, hl); 5372 len = STRLEN(buf); 5373 5374 while (width < maxwidth && len < sizeof(buf) - 1) 5375 { 5376 #ifdef FEAT_MBYTE 5377 len += (*mb_char2bytes)(fillchar, buf + len); 5378 #else 5379 buf[len++] = fillchar; 5380 #endif 5381 ++width; 5382 } 5383 buf[len] = NUL; 5384 5385 curattr = attr; 5386 p = buf; 5387 for (n = 0; hl[n].start != NULL; n++) 5388 { 5389 len = (int)(hl[n].start - p); 5390 screen_puts_len(p, len, row, col, curattr); 5391 col += vim_strnsize(p, len); 5392 p = hl[n].start; 5393 5394 if (hl[n].userhl == 0) 5395 curattr = attr; 5396 #ifdef FEAT_WINDOWS 5397 else if (wp != curwin && wp->w_status_height != 0) 5398 curattr = highlight_stlnc[hl[n].userhl - 1]; 5399 #endif 5400 else 5401 curattr = highlight_user[hl[n].userhl - 1]; 5402 } 5403 screen_puts(p, row, col, curattr); 5404 } 5405 5406 #endif /* FEAT_STL_OPT */ 5407 5408 /* 5409 * Output a single character directly to the screen and update ScreenLines. 5410 */ 5411 void 5412 screen_putchar(c, row, col, attr) 5413 int c; 5414 int row, col; 5415 int attr; 5416 { 5417 #ifdef FEAT_MBYTE 5418 char_u buf[MB_MAXBYTES + 1]; 5419 5420 buf[(*mb_char2bytes)(c, buf)] = NUL; 5421 #else 5422 char_u buf[2]; 5423 5424 buf[0] = c; 5425 buf[1] = NUL; 5426 #endif 5427 screen_puts(buf, row, col, attr); 5428 } 5429 5430 /* 5431 * Get a single character directly from ScreenLines into "bytes[]". 5432 * Also return its attribute in *attrp; 5433 */ 5434 void 5435 screen_getbytes(row, col, bytes, attrp) 5436 int row, col; 5437 char_u *bytes; 5438 int *attrp; 5439 { 5440 unsigned off; 5441 5442 /* safety check */ 5443 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) 5444 { 5445 off = LineOffset[row] + col; 5446 *attrp = ScreenAttrs[off]; 5447 bytes[0] = ScreenLines[off]; 5448 bytes[1] = NUL; 5449 5450 #ifdef FEAT_MBYTE 5451 if (enc_utf8 && ScreenLinesUC[off] != 0) 5452 bytes[utfc_char2bytes(off, bytes)] = NUL; 5453 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) 5454 { 5455 bytes[0] = ScreenLines[off]; 5456 bytes[1] = ScreenLines2[off]; 5457 bytes[2] = NUL; 5458 } 5459 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) 5460 { 5461 bytes[1] = ScreenLines[off + 1]; 5462 bytes[2] = NUL; 5463 } 5464 #endif 5465 } 5466 } 5467 5468 /* 5469 * Put string '*text' on the screen at position 'row' and 'col', with 5470 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. 5471 * Note: only outputs within one row, message is truncated at screen boundary! 5472 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. 5473 */ 5474 void 5475 screen_puts(text, row, col, attr) 5476 char_u *text; 5477 int row; 5478 int col; 5479 int attr; 5480 { 5481 screen_puts_len(text, -1, row, col, attr); 5482 } 5483 5484 /* 5485 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to 5486 * a NUL. 5487 */ 5488 void 5489 screen_puts_len(text, len, row, col, attr) 5490 char_u *text; 5491 int len; 5492 int row; 5493 int col; 5494 int attr; 5495 { 5496 unsigned off; 5497 char_u *ptr = text; 5498 int c; 5499 #ifdef FEAT_MBYTE 5500 int mbyte_blen = 1; 5501 int mbyte_cells = 1; 5502 int u8c = 0; 5503 int u8c_c1 = 0; 5504 int u8c_c2 = 0; 5505 int clear_next_cell = FALSE; 5506 # ifdef FEAT_ARABIC 5507 int prev_c = 0; /* previous Arabic character */ 5508 int pc, nc, nc1, dummy; 5509 # endif 5510 #endif 5511 5512 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ 5513 return; 5514 5515 off = LineOffset[row] + col; 5516 while (*ptr != NUL && col < screen_Columns 5517 && (len < 0 || (int)(ptr - text) < len)) 5518 { 5519 c = *ptr; 5520 #ifdef FEAT_MBYTE 5521 /* check if this is the first byte of a multibyte */ 5522 if (has_mbyte) 5523 { 5524 if (enc_utf8 && len > 0) 5525 mbyte_blen = utfc_ptr2len_check_len(ptr, 5526 (int)((text + len) - ptr)); 5527 else 5528 mbyte_blen = (*mb_ptr2len_check)(ptr); 5529 if (enc_dbcs == DBCS_JPNU && c == 0x8e) 5530 mbyte_cells = 1; 5531 else if (enc_dbcs != 0) 5532 mbyte_cells = mbyte_blen; 5533 else /* enc_utf8 */ 5534 { 5535 if (len >= 0) 5536 u8c = utfc_ptr2char_len(ptr, &u8c_c1, &u8c_c2, 5537 (int)((text + len) - ptr)); 5538 else 5539 u8c = utfc_ptr2char(ptr, &u8c_c1, &u8c_c2); 5540 mbyte_cells = utf_char2cells(u8c); 5541 /* Non-BMP character: display as ? or fullwidth ?. */ 5542 if (u8c >= 0x10000) 5543 { 5544 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; 5545 if (attr == 0) 5546 attr = hl_attr(HLF_8); 5547 } 5548 # ifdef FEAT_ARABIC 5549 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) 5550 { 5551 /* Do Arabic shaping. */ 5552 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) 5553 { 5554 /* Past end of string to be displayed. */ 5555 nc = NUL; 5556 nc1 = NUL; 5557 } 5558 else 5559 nc = utfc_ptr2char(ptr + mbyte_blen, &nc1, &dummy); 5560 pc = prev_c; 5561 prev_c = u8c; 5562 u8c = arabic_shape(u8c, &c, &u8c_c1, nc, nc1, pc); 5563 } 5564 else 5565 prev_c = u8c; 5566 # endif 5567 } 5568 } 5569 #endif 5570 5571 if (ScreenLines[off] != c 5572 #ifdef FEAT_MBYTE 5573 || (mbyte_cells == 2 5574 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) 5575 || (enc_dbcs == DBCS_JPNU 5576 && c == 0x8e 5577 && ScreenLines2[off] != ptr[1]) 5578 || (enc_utf8 5579 && mbyte_blen > 1 5580 && (ScreenLinesUC[off] != u8c 5581 || ScreenLinesC1[off] != u8c_c1 5582 || ScreenLinesC2[off] != u8c_c2)) 5583 #endif 5584 || ScreenAttrs[off] != attr 5585 || exmode_active 5586 ) 5587 { 5588 #if defined(FEAT_GUI) || defined(UNIX) 5589 /* The bold trick makes a single row of pixels appear in the next 5590 * character. When a bold character is removed, the next 5591 * character should be redrawn too. This happens for our own GUI 5592 * and for some xterms. 5593 * Force the redraw by setting the attribute to a different value 5594 * than "attr", the contents of ScreenLines[] may be needed by 5595 * mb_off2cells() further on. 5596 * Don't do this for the last drawn character, because the next 5597 * character may not be redrawn. */ 5598 if ( 5599 # ifdef FEAT_GUI 5600 gui.in_use 5601 # endif 5602 # if defined(FEAT_GUI) && defined(UNIX) 5603 || 5604 # endif 5605 # ifdef UNIX 5606 term_is_xterm 5607 # endif 5608 ) 5609 { 5610 int n; 5611 5612 n = ScreenAttrs[off]; 5613 # ifdef FEAT_MBYTE 5614 if (col + mbyte_cells < screen_Columns 5615 && (n > HL_ALL || (n & HL_BOLD)) 5616 && (len < 0 ? ptr[mbyte_blen] != NUL 5617 : ptr + mbyte_blen < text + len)) 5618 ScreenAttrs[off + mbyte_cells] = attr + 1; 5619 # else 5620 if (col + 1 < screen_Columns 5621 && (n > HL_ALL || (n & HL_BOLD)) 5622 && (len < 0 ? ptr[1] != NUL : ptr + 1 < text + len)) 5623 ScreenLines[off + 1] = 0; 5624 # endif 5625 } 5626 #endif 5627 #ifdef FEAT_MBYTE 5628 /* When at the end of the text and overwriting a two-cell 5629 * character with a one-cell character, need to clear the next 5630 * cell. Also when overwriting the left halve of a two-cell char 5631 * with the right halve of a two-cell char. Do this only once 5632 * (mb_off2cells() may return 2 on the right halve). */ 5633 if (clear_next_cell) 5634 clear_next_cell = FALSE; 5635 else if (has_mbyte 5636 && (len < 0 ? ptr[mbyte_blen] == NUL 5637 : ptr + mbyte_blen >= text + len) 5638 && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) 5639 || (mbyte_cells == 2 5640 && (*mb_off2cells)(off) == 1 5641 && (*mb_off2cells)(off + 1) > 1))) 5642 clear_next_cell = TRUE; 5643 5644 /* Make sure we never leave a second byte of a double-byte behind, 5645 * it confuses mb_off2cells(). */ 5646 if (enc_dbcs 5647 && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) 5648 || (mbyte_cells == 2 5649 && (*mb_off2cells)(off) == 1 5650 && (*mb_off2cells)(off + 1) > 1))) 5651 ScreenLines[off + mbyte_blen] = 0; 5652 #endif 5653 ScreenLines[off] = c; 5654 ScreenAttrs[off] = attr; 5655 #ifdef FEAT_MBYTE 5656 if (enc_utf8) 5657 { 5658 if (c < 0x80 && u8c_c1 == 0 && u8c_c2 == 0) 5659 ScreenLinesUC[off] = 0; 5660 else 5661 { 5662 ScreenLinesUC[off] = u8c; 5663 ScreenLinesC1[off] = u8c_c1; 5664 ScreenLinesC2[off] = u8c_c2; 5665 } 5666 if (mbyte_cells == 2) 5667 { 5668 ScreenLines[off + 1] = 0; 5669 ScreenAttrs[off + 1] = attr; 5670 } 5671 screen_char(off, row, col); 5672 } 5673 else if (mbyte_cells == 2) 5674 { 5675 ScreenLines[off + 1] = ptr[1]; 5676 ScreenAttrs[off + 1] = attr; 5677 screen_char_2(off, row, col); 5678 } 5679 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) 5680 { 5681 ScreenLines2[off] = ptr[1]; 5682 screen_char(off, row, col); 5683 } 5684 else 5685 #endif 5686 screen_char(off, row, col); 5687 } 5688 #ifdef FEAT_MBYTE 5689 if (has_mbyte) 5690 { 5691 off += mbyte_cells; 5692 col += mbyte_cells; 5693 ptr += mbyte_blen; 5694 if (clear_next_cell) 5695 ptr = (char_u *)" "; 5696 } 5697 else 5698 #endif 5699 { 5700 ++off; 5701 ++col; 5702 ++ptr; 5703 } 5704 } 5705 } 5706 5707 #ifdef FEAT_SEARCH_EXTRA 5708 /* 5709 * Prepare for 'searchhl' highlighting. 5710 */ 5711 static void 5712 start_search_hl() 5713 { 5714 if (p_hls && !no_hlsearch) 5715 { 5716 last_pat_prog(&search_hl.rm); 5717 search_hl.attr = hl_attr(HLF_L); 5718 } 5719 } 5720 5721 /* 5722 * Clean up for 'searchhl' highlighting. 5723 */ 5724 static void 5725 end_search_hl() 5726 { 5727 if (search_hl.rm.regprog != NULL) 5728 { 5729 vim_free(search_hl.rm.regprog); 5730 search_hl.rm.regprog = NULL; 5731 } 5732 } 5733 5734 /* 5735 * Advance to the match in window "wp" line "lnum" or past it. 5736 */ 5737 static void 5738 prepare_search_hl(wp, lnum) 5739 win_T *wp; 5740 linenr_T lnum; 5741 { 5742 match_T *shl; /* points to search_hl or match_hl */ 5743 int n; 5744 5745 /* 5746 * When using a multi-line pattern, start searching at the top 5747 * of the window or just after a closed fold. 5748 * Do this both for search_hl and match_hl. 5749 */ 5750 shl = &search_hl; 5751 for (;;) 5752 { 5753 if (shl->rm.regprog != NULL 5754 && shl->lnum == 0 5755 && re_multiline(shl->rm.regprog)) 5756 { 5757 if (shl->first_lnum == 0) 5758 { 5759 # ifdef FEAT_FOLDING 5760 for (shl->first_lnum = lnum; 5761 shl->first_lnum > wp->w_topline; --shl->first_lnum) 5762 if (hasFoldingWin(wp, shl->first_lnum - 1, 5763 NULL, NULL, TRUE, NULL)) 5764 break; 5765 # else 5766 shl->first_lnum = wp->w_topline; 5767 # endif 5768 } 5769 n = 0; 5770 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) 5771 { 5772 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); 5773 if (shl->lnum != 0) 5774 { 5775 shl->first_lnum = shl->lnum 5776 + shl->rm.endpos[0].lnum 5777 - shl->rm.startpos[0].lnum; 5778 n = shl->rm.endpos[0].col; 5779 } 5780 else 5781 { 5782 ++shl->first_lnum; 5783 n = 0; 5784 } 5785 } 5786 } 5787 if (shl == &match_hl) 5788 break; 5789 shl = &match_hl; 5790 } 5791 } 5792 5793 /* 5794 * Search for a next 'searchl' or ":match" match. 5795 * Uses shl->buf. 5796 * Sets shl->lnum and shl->rm contents. 5797 * Note: Assumes a previous match is always before "lnum", unless 5798 * shl->lnum is zero. 5799 * Careful: Any pointers for buffer lines will become invalid. 5800 */ 5801 static void 5802 next_search_hl(win, shl, lnum, mincol) 5803 win_T *win; 5804 match_T *shl; /* points to search_hl or match_hl */ 5805 linenr_T lnum; 5806 colnr_T mincol; /* minimal column for a match */ 5807 { 5808 linenr_T l; 5809 colnr_T matchcol; 5810 long nmatched; 5811 5812 if (shl->lnum != 0) 5813 { 5814 /* Check for three situations: 5815 * 1. If the "lnum" is below a previous match, start a new search. 5816 * 2. If the previous match includes "mincol", use it. 5817 * 3. Continue after the previous match. 5818 */ 5819 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; 5820 if (lnum > l) 5821 shl->lnum = 0; 5822 else if (lnum < l || shl->rm.endpos[0].col > mincol) 5823 return; 5824 } 5825 5826 /* 5827 * Repeat searching for a match until one is found that includes "mincol" 5828 * or none is found in this line. 5829 */ 5830 called_emsg = FALSE; 5831 for (;;) 5832 { 5833 /* Three situations: 5834 * 1. No useful previous match: search from start of line. 5835 * 2. Not Vi compatible or empty match: continue at next character. 5836 * Break the loop if this is beyond the end of the line. 5837 * 3. Vi compatible searching: continue at end of previous match. 5838 */ 5839 if (shl->lnum == 0) 5840 matchcol = 0; 5841 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL 5842 || (shl->rm.endpos[0].lnum == 0 5843 && shl->rm.endpos[0].col == shl->rm.startpos[0].col)) 5844 { 5845 matchcol = shl->rm.startpos[0].col + 1; 5846 if (ml_get_buf(shl->buf, lnum, FALSE)[matchcol - 1] == NUL) 5847 { 5848 shl->lnum = 0; 5849 break; 5850 } 5851 } 5852 else 5853 matchcol = shl->rm.endpos[0].col; 5854 5855 shl->lnum = lnum; 5856 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol); 5857 if (called_emsg) 5858 { 5859 /* Error while handling regexp: stop using this regexp. */ 5860 vim_free(shl->rm.regprog); 5861 shl->rm.regprog = NULL; 5862 no_hlsearch = TRUE; 5863 break; 5864 } 5865 if (nmatched == 0) 5866 { 5867 shl->lnum = 0; /* no match found */ 5868 break; 5869 } 5870 if (shl->rm.startpos[0].lnum > 0 5871 || shl->rm.startpos[0].col >= mincol 5872 || nmatched > 1 5873 || shl->rm.endpos[0].col > mincol) 5874 { 5875 shl->lnum += shl->rm.startpos[0].lnum; 5876 break; /* useful match found */ 5877 } 5878 } 5879 } 5880 #endif 5881 5882 static void 5883 screen_start_highlight(attr) 5884 int attr; 5885 { 5886 attrentry_T *aep = NULL; 5887 5888 screen_attr = attr; 5889 if (full_screen 5890 #ifdef WIN3264 5891 && termcap_active 5892 #endif 5893 ) 5894 { 5895 #ifdef FEAT_GUI 5896 if (gui.in_use) 5897 { 5898 char buf[20]; 5899 5900 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); /* internal GUI code */ 5901 OUT_STR(buf); 5902 } 5903 else 5904 #endif 5905 { 5906 if (attr > HL_ALL) /* special HL attr. */ 5907 { 5908 if (t_colors > 1) 5909 aep = syn_cterm_attr2entry(attr); 5910 else 5911 aep = syn_term_attr2entry(attr); 5912 if (aep == NULL) /* did ":syntax clear" */ 5913 attr = 0; 5914 else 5915 attr = aep->ae_attr; 5916 } 5917 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ 5918 out_str(T_MD); 5919 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ 5920 out_str(T_SO); 5921 if ((attr & HL_UNDERLINE) && T_US != NULL) /* underline */ 5922 out_str(T_US); 5923 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ 5924 out_str(T_CZH); 5925 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ 5926 out_str(T_MR); 5927 5928 /* 5929 * Output the color or start string after bold etc., in case the 5930 * bold etc. override the color setting. 5931 */ 5932 if (aep != NULL) 5933 { 5934 if (t_colors > 1) 5935 { 5936 if (aep->ae_u.cterm.fg_color) 5937 term_fg_color(aep->ae_u.cterm.fg_color - 1); 5938 if (aep->ae_u.cterm.bg_color) 5939 term_bg_color(aep->ae_u.cterm.bg_color - 1); 5940 } 5941 else 5942 { 5943 if (aep->ae_u.term.start != NULL) 5944 out_str(aep->ae_u.term.start); 5945 } 5946 } 5947 } 5948 } 5949 } 5950 5951 void 5952 screen_stop_highlight() 5953 { 5954 int do_ME = FALSE; /* output T_ME code */ 5955 5956 if (screen_attr != 0 5957 #ifdef WIN3264 5958 && termcap_active 5959 #endif 5960 ) 5961 { 5962 #ifdef FEAT_GUI 5963 if (gui.in_use) 5964 { 5965 char buf[20]; 5966 5967 /* use internal GUI code */ 5968 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); 5969 OUT_STR(buf); 5970 } 5971 else 5972 #endif 5973 { 5974 if (screen_attr > HL_ALL) /* special HL attr. */ 5975 { 5976 attrentry_T *aep; 5977 5978 if (t_colors > 1) 5979 { 5980 /* 5981 * Assume that t_me restores the original colors! 5982 */ 5983 aep = syn_cterm_attr2entry(screen_attr); 5984 if (aep != NULL && (aep->ae_u.cterm.fg_color 5985 || aep->ae_u.cterm.bg_color)) 5986 do_ME = TRUE; 5987 } 5988 else 5989 { 5990 aep = syn_term_attr2entry(screen_attr); 5991 if (aep != NULL && aep->ae_u.term.stop != NULL) 5992 { 5993 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) 5994 do_ME = TRUE; 5995 else 5996 out_str(aep->ae_u.term.stop); 5997 } 5998 } 5999 if (aep == NULL) /* did ":syntax clear" */ 6000 screen_attr = 0; 6001 else 6002 screen_attr = aep->ae_attr; 6003 } 6004 6005 /* 6006 * Often all ending-codes are equal to T_ME. Avoid outputting the 6007 * same sequence several times. 6008 */ 6009 if (screen_attr & HL_STANDOUT) 6010 { 6011 if (STRCMP(T_SE, T_ME) == 0) 6012 do_ME = TRUE; 6013 else 6014 out_str(T_SE); 6015 } 6016 if (screen_attr & HL_UNDERLINE) 6017 { 6018 if (STRCMP(T_UE, T_ME) == 0) 6019 do_ME = TRUE; 6020 else 6021 out_str(T_UE); 6022 } 6023 if (screen_attr & HL_ITALIC) 6024 { 6025 if (STRCMP(T_CZR, T_ME) == 0) 6026 do_ME = TRUE; 6027 else 6028 out_str(T_CZR); 6029 } 6030 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) 6031 out_str(T_ME); 6032 6033 if (t_colors > 1) 6034 { 6035 /* set Normal cterm colors */ 6036 if (cterm_normal_fg_color != 0) 6037 term_fg_color(cterm_normal_fg_color - 1); 6038 if (cterm_normal_bg_color != 0) 6039 term_bg_color(cterm_normal_bg_color - 1); 6040 if (cterm_normal_fg_bold) 6041 out_str(T_MD); 6042 } 6043 } 6044 } 6045 screen_attr = 0; 6046 } 6047 6048 /* 6049 * Reset the colors for a cterm. Used when leaving Vim. 6050 * The machine specific code may override this again. 6051 */ 6052 void 6053 reset_cterm_colors() 6054 { 6055 if (t_colors > 1) 6056 { 6057 /* set Normal cterm colors */ 6058 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) 6059 { 6060 out_str(T_OP); 6061 screen_attr = -1; 6062 } 6063 if (cterm_normal_fg_bold) 6064 { 6065 out_str(T_ME); 6066 screen_attr = -1; 6067 } 6068 } 6069 } 6070 6071 /* 6072 * Put character ScreenLines["off"] on the screen at position "row" and "col", 6073 * using the attributes from ScreenAttrs["off"]. 6074 */ 6075 static void 6076 screen_char(off, row, col) 6077 unsigned off; 6078 int row; 6079 int col; 6080 { 6081 int attr; 6082 6083 /* Check for illegal values, just in case (could happen just after 6084 * resizing). */ 6085 if (row >= screen_Rows || col >= screen_Columns) 6086 return; 6087 6088 /* Outputting the last character on the screen may scrollup the screen. 6089 * Don't to it! Mark the character invalid (update it when scrolled up) */ 6090 if (row == screen_Rows - 1 && col == screen_Columns - 1 6091 #ifdef FEAT_RIGHTLEFT 6092 /* account for first command-line character in rightleft mode */ 6093 && !cmdmsg_rl 6094 #endif 6095 ) 6096 { 6097 ScreenAttrs[off] = (sattr_T)-1; 6098 return; 6099 } 6100 6101 /* 6102 * Stop highlighting first, so it's easier to move the cursor. 6103 */ 6104 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) 6105 if (screen_char_attr != 0) 6106 attr = screen_char_attr; 6107 else 6108 #endif 6109 attr = ScreenAttrs[off]; 6110 if (screen_attr != attr) 6111 screen_stop_highlight(); 6112 6113 windgoto(row, col); 6114 6115 if (screen_attr != attr) 6116 screen_start_highlight(attr); 6117 6118 #ifdef FEAT_MBYTE 6119 if (enc_utf8 && ScreenLinesUC[off] != 0) 6120 { 6121 char_u buf[MB_MAXBYTES + 1]; 6122 6123 /* Convert UTF-8 character to bytes and write it. */ 6124 6125 buf[utfc_char2bytes(off, buf)] = NUL; 6126 6127 out_str(buf); 6128 if (utf_char2cells(ScreenLinesUC[off]) > 1) 6129 ++screen_cur_col; 6130 } 6131 else 6132 #endif 6133 { 6134 #ifdef FEAT_MBYTE 6135 out_flush_check(); 6136 #endif 6137 out_char(ScreenLines[off]); 6138 #ifdef FEAT_MBYTE 6139 /* double-byte character in single-width cell */ 6140 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) 6141 out_char(ScreenLines2[off]); 6142 #endif 6143 } 6144 6145 screen_cur_col++; 6146 } 6147 6148 #ifdef FEAT_MBYTE 6149 6150 /* 6151 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] 6152 * on the screen at position 'row' and 'col'. 6153 * The attributes of the first byte is used for all. This is required to 6154 * output the two bytes of a double-byte character with nothing in between. 6155 */ 6156 static void 6157 screen_char_2(off, row, col) 6158 unsigned off; 6159 int row; 6160 int col; 6161 { 6162 /* Check for illegal values (could be wrong when screen was resized). */ 6163 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) 6164 return; 6165 6166 /* Outputting the last character on the screen may scrollup the screen. 6167 * Don't to it! Mark the character invalid (update it when scrolled up) */ 6168 if (row == screen_Rows - 1 && col >= screen_Columns - 2) 6169 { 6170 ScreenAttrs[off] = (sattr_T)-1; 6171 return; 6172 } 6173 6174 /* Output the first byte normally (positions the cursor), then write the 6175 * second byte directly. */ 6176 screen_char(off, row, col); 6177 out_char(ScreenLines[off + 1]); 6178 ++screen_cur_col; 6179 } 6180 #endif 6181 6182 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) 6183 /* 6184 * Draw a rectangle of the screen, inverted when "invert" is TRUE. 6185 * This uses the contents of ScreenLines[] and doesn't change it. 6186 */ 6187 void 6188 screen_draw_rectangle(row, col, height, width, invert) 6189 int row; 6190 int col; 6191 int height; 6192 int width; 6193 int invert; 6194 { 6195 int r, c; 6196 int off; 6197 6198 if (invert) 6199 screen_char_attr = HL_INVERSE; 6200 for (r = row; r < row + height; ++r) 6201 { 6202 off = LineOffset[r]; 6203 for (c = col; c < col + width; ++c) 6204 { 6205 #ifdef FEAT_MBYTE 6206 if (enc_dbcs != 0 && dbcs_off2cells(off + c) > 1) 6207 { 6208 screen_char_2(off + c, r, c); 6209 ++c; 6210 } 6211 else 6212 #endif 6213 { 6214 screen_char(off + c, r, c); 6215 #ifdef FEAT_MBYTE 6216 if (utf_off2cells(off + c) > 1) 6217 ++c; 6218 #endif 6219 } 6220 } 6221 } 6222 screen_char_attr = 0; 6223 } 6224 #endif 6225 6226 #ifdef FEAT_VERTSPLIT 6227 /* 6228 * Redraw the characters for a vertically split window. 6229 */ 6230 static void 6231 redraw_block(row, end, wp) 6232 int row; 6233 int end; 6234 win_T *wp; 6235 { 6236 int col; 6237 int width; 6238 6239 # ifdef FEAT_CLIPBOARD 6240 clip_may_clear_selection(row, end - 1); 6241 # endif 6242 6243 if (wp == NULL) 6244 { 6245 col = 0; 6246 width = Columns; 6247 } 6248 else 6249 { 6250 col = wp->w_wincol; 6251 width = wp->w_width; 6252 } 6253 screen_draw_rectangle(row, col, end - row, width, FALSE); 6254 } 6255 #endif 6256 6257 /* 6258 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' 6259 * with character 'c1' in first column followed by 'c2' in the other columns. 6260 * Use attributes 'attr'. 6261 */ 6262 void 6263 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) 6264 int start_row, end_row; 6265 int start_col, end_col; 6266 int c1, c2; 6267 int attr; 6268 { 6269 int row; 6270 int col; 6271 int off; 6272 int end_off; 6273 int did_delete; 6274 int c; 6275 int norm_term; 6276 #if defined(FEAT_GUI) || defined(UNIX) 6277 int force_next = FALSE; 6278 #endif 6279 6280 if (end_row > screen_Rows) /* safety check */ 6281 end_row = screen_Rows; 6282 if (end_col > screen_Columns) /* safety check */ 6283 end_col = screen_Columns; 6284 if (ScreenLines == NULL 6285 || start_row >= end_row 6286 || start_col >= end_col) /* nothing to do */ 6287 return; 6288 6289 /* it's a "normal" terminal when not in a GUI or cterm */ 6290 norm_term = ( 6291 #ifdef FEAT_GUI 6292 !gui.in_use && 6293 #endif 6294 t_colors <= 1); 6295 for (row = start_row; row < end_row; ++row) 6296 { 6297 /* 6298 * Try to use delete-line termcap code, when no attributes or in a 6299 * "normal" terminal, where a bold/italic space is just a 6300 * space. 6301 */ 6302 did_delete = FALSE; 6303 if (c2 == ' ' 6304 && end_col == Columns 6305 && can_clear(T_CE) 6306 && (attr == 0 6307 || (norm_term 6308 && attr <= HL_ALL 6309 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) 6310 { 6311 /* 6312 * check if we really need to clear something 6313 */ 6314 col = start_col; 6315 if (c1 != ' ') /* don't clear first char */ 6316 ++col; 6317 6318 off = LineOffset[row] + col; 6319 end_off = LineOffset[row] + end_col; 6320 6321 /* skip blanks (used often, keep it fast!) */ 6322 #ifdef FEAT_MBYTE 6323 if (enc_utf8) 6324 while (off < end_off && ScreenLines[off] == ' ' 6325 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) 6326 ++off; 6327 else 6328 #endif 6329 while (off < end_off && ScreenLines[off] == ' ' 6330 && ScreenAttrs[off] == 0) 6331 ++off; 6332 if (off < end_off) /* something to be cleared */ 6333 { 6334 col = off - LineOffset[row]; 6335 screen_stop_highlight(); 6336 term_windgoto(row, col);/* clear rest of this screen line */ 6337 out_str(T_CE); 6338 screen_start(); /* don't know where cursor is now */ 6339 col = end_col - col; 6340 while (col--) /* clear chars in ScreenLines */ 6341 { 6342 ScreenLines[off] = ' '; 6343 #ifdef FEAT_MBYTE 6344 if (enc_utf8) 6345 ScreenLinesUC[off] = 0; 6346 #endif 6347 ScreenAttrs[off] = 0; 6348 ++off; 6349 } 6350 } 6351 did_delete = TRUE; /* the chars are cleared now */ 6352 } 6353 6354 off = LineOffset[row] + start_col; 6355 c = c1; 6356 for (col = start_col; col < end_col; ++col) 6357 { 6358 if (ScreenLines[off] != c 6359 #ifdef FEAT_MBYTE 6360 || (enc_utf8 && ScreenLinesUC[off] != (c >= 0x80 ? c : 0)) 6361 #endif 6362 || ScreenAttrs[off] != attr 6363 #if defined(FEAT_GUI) || defined(UNIX) 6364 || force_next 6365 #endif 6366 ) 6367 { 6368 #if defined(FEAT_GUI) || defined(UNIX) 6369 /* The bold trick may make a single row of pixels appear in 6370 * the next character. When a bold character is removed, the 6371 * next character should be redrawn too. This happens for our 6372 * own GUI and for some xterms. */ 6373 if ( 6374 # ifdef FEAT_GUI 6375 gui.in_use 6376 # endif 6377 # if defined(FEAT_GUI) && defined(UNIX) 6378 || 6379 # endif 6380 # ifdef UNIX 6381 term_is_xterm 6382 # endif 6383 ) 6384 { 6385 if (ScreenLines[off] != ' ' 6386 && (ScreenAttrs[off] > HL_ALL 6387 || ScreenAttrs[off] & HL_BOLD)) 6388 force_next = TRUE; 6389 else 6390 force_next = FALSE; 6391 } 6392 #endif 6393 ScreenLines[off] = c; 6394 #ifdef FEAT_MBYTE 6395 if (enc_utf8) 6396 { 6397 if (c >= 0x80) 6398 { 6399 ScreenLinesUC[off] = c; 6400 ScreenLinesC1[off] = 0; 6401 ScreenLinesC2[off] = 0; 6402 } 6403 else 6404 ScreenLinesUC[off] = 0; 6405 } 6406 #endif 6407 ScreenAttrs[off] = attr; 6408 if (!did_delete || c != ' ') 6409 screen_char(off, row, col); 6410 } 6411 ++off; 6412 if (col == start_col) 6413 { 6414 if (did_delete) 6415 break; 6416 c = c2; 6417 } 6418 } 6419 if (end_col == Columns) 6420 LineWraps[row] = FALSE; 6421 if (row == Rows - 1) /* overwritten the command line */ 6422 { 6423 redraw_cmdline = TRUE; 6424 if (c1 == ' ' && c2 == ' ') 6425 clear_cmdline = FALSE; /* command line has been cleared */ 6426 } 6427 } 6428 } 6429 6430 /* 6431 * Check if there should be a delay. Used before clearing or redrawing the 6432 * screen or the command line. 6433 */ 6434 void 6435 check_for_delay(check_msg_scroll) 6436 int check_msg_scroll; 6437 { 6438 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) 6439 && !did_wait_return 6440 && emsg_silent == 0) 6441 { 6442 out_flush(); 6443 ui_delay(1000L, TRUE); 6444 emsg_on_display = FALSE; 6445 if (check_msg_scroll) 6446 msg_scroll = FALSE; 6447 } 6448 } 6449 6450 /* 6451 * screen_valid - allocate screen buffers if size changed 6452 * If "clear" is TRUE: clear screen if it has been resized. 6453 * Returns TRUE if there is a valid screen to write to. 6454 * Returns FALSE when starting up and screen not initialized yet. 6455 */ 6456 int 6457 screen_valid(clear) 6458 int clear; 6459 { 6460 screenalloc(clear); /* allocate screen buffers if size changed */ 6461 return (ScreenLines != NULL); 6462 } 6463 6464 /* 6465 * Resize the shell to Rows and Columns. 6466 * Allocate ScreenLines[] and associated items. 6467 * 6468 * There may be some time between setting Rows and Columns and (re)allocating 6469 * ScreenLines[]. This happens when starting up and when (manually) changing 6470 * the shell size. Always use screen_Rows and screen_Columns to access items 6471 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the 6472 * final size of the shell is needed. 6473 */ 6474 void 6475 screenalloc(clear) 6476 int clear; 6477 { 6478 int new_row, old_row; 6479 #ifdef FEAT_GUI 6480 int old_Rows; 6481 #endif 6482 win_T *wp; 6483 int outofmem = FALSE; 6484 int len; 6485 schar_T *new_ScreenLines; 6486 #ifdef FEAT_MBYTE 6487 u8char_T *new_ScreenLinesUC = NULL; 6488 u8char_T *new_ScreenLinesC1 = NULL; 6489 u8char_T *new_ScreenLinesC2 = NULL; 6490 schar_T *new_ScreenLines2 = NULL; 6491 #endif 6492 sattr_T *new_ScreenAttrs; 6493 unsigned *new_LineOffset; 6494 char_u *new_LineWraps; 6495 static int entered = FALSE; /* avoid recursiveness */ 6496 6497 /* 6498 * Allocation of the screen buffers is done only when the size changes and 6499 * when Rows and Columns have been set and we have started doing full 6500 * screen stuff. 6501 */ 6502 if ((ScreenLines != NULL 6503 && Rows == screen_Rows 6504 && Columns == screen_Columns 6505 #ifdef FEAT_MBYTE 6506 && enc_utf8 == (ScreenLinesUC != NULL) 6507 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) 6508 #endif 6509 ) 6510 || Rows == 0 6511 || Columns == 0 6512 || (!full_screen && ScreenLines == NULL)) 6513 return; 6514 6515 /* 6516 * It's possible that we produce an out-of-memory message below, which 6517 * will cause this function to be called again. To break the loop, just 6518 * return here. 6519 */ 6520 if (entered) 6521 return; 6522 entered = TRUE; 6523 6524 win_new_shellsize(); /* fit the windows in the new sized shell */ 6525 6526 #ifdef FEAT_GUI_BEOS 6527 vim_lock_screen(); /* be safe, put it here */ 6528 #endif 6529 6530 comp_col(); /* recompute columns for shown command and ruler */ 6531 6532 /* 6533 * We're changing the size of the screen. 6534 * - Allocate new arrays for ScreenLines and ScreenAttrs. 6535 * - Move lines from the old arrays into the new arrays, clear extra 6536 * lines (unless the screen is going to be cleared). 6537 * - Free the old arrays. 6538 * 6539 * If anything fails, make ScreenLines NULL, so we don't do anything! 6540 * Continuing with the old ScreenLines may result in a crash, because the 6541 * size is wrong. 6542 */ 6543 #ifdef FEAT_WINDOWS 6544 for (wp = firstwin; wp; wp = wp->w_next) 6545 win_free_lsize(wp); 6546 #else 6547 win_free_lsize(curwin); 6548 #endif 6549 6550 new_ScreenLines = (schar_T *)lalloc((long_u)( 6551 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); 6552 #ifdef FEAT_MBYTE 6553 if (enc_utf8) 6554 { 6555 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( 6556 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); 6557 new_ScreenLinesC1 = (u8char_T *)lalloc((long_u)( 6558 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); 6559 new_ScreenLinesC2 = (u8char_T *)lalloc((long_u)( 6560 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); 6561 } 6562 if (enc_dbcs == DBCS_JPNU) 6563 new_ScreenLines2 = (schar_T *)lalloc((long_u)( 6564 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); 6565 #endif 6566 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( 6567 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); 6568 new_LineOffset = (unsigned *)lalloc((long_u)( 6569 Rows * sizeof(unsigned)), FALSE); 6570 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); 6571 6572 FOR_ALL_WINDOWS(wp) 6573 { 6574 if (win_alloc_lines(wp) == FAIL) 6575 { 6576 outofmem = TRUE; 6577 #ifdef FEAT_WINDOWS 6578 break; 6579 #endif 6580 } 6581 } 6582 6583 if (new_ScreenLines == NULL 6584 #ifdef FEAT_MBYTE 6585 || (enc_utf8 && (new_ScreenLinesUC == NULL 6586 || new_ScreenLinesC1 == NULL || new_ScreenLinesC2 == NULL)) 6587 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) 6588 #endif 6589 || new_ScreenAttrs == NULL 6590 || new_LineOffset == NULL 6591 || new_LineWraps == NULL 6592 || outofmem) 6593 { 6594 do_outofmem_msg((long_u)((Rows + 1) * Columns)); /* guess the size */ 6595 vim_free(new_ScreenLines); 6596 new_ScreenLines = NULL; 6597 #ifdef FEAT_MBYTE 6598 vim_free(new_ScreenLinesUC); 6599 new_ScreenLinesUC = NULL; 6600 vim_free(new_ScreenLinesC1); 6601 new_ScreenLinesC1 = NULL; 6602 vim_free(new_ScreenLinesC2); 6603 new_ScreenLinesC2 = NULL; 6604 vim_free(new_ScreenLines2); 6605 new_ScreenLines2 = NULL; 6606 #endif 6607 vim_free(new_ScreenAttrs); 6608 new_ScreenAttrs = NULL; 6609 vim_free(new_LineOffset); 6610 new_LineOffset = NULL; 6611 vim_free(new_LineWraps); 6612 new_LineWraps = NULL; 6613 } 6614 else 6615 { 6616 for (new_row = 0; new_row < Rows; ++new_row) 6617 { 6618 new_LineOffset[new_row] = new_row * Columns; 6619 new_LineWraps[new_row] = FALSE; 6620 6621 /* 6622 * If the screen is not going to be cleared, copy as much as 6623 * possible from the old screen to the new one and clear the rest 6624 * (used when resizing the window at the "--more--" prompt or when 6625 * executing an external command, for the GUI). 6626 */ 6627 if (!clear) 6628 { 6629 (void)vim_memset(new_ScreenLines + new_row * Columns, 6630 ' ', (size_t)Columns * sizeof(schar_T)); 6631 #ifdef FEAT_MBYTE 6632 if (enc_utf8) 6633 { 6634 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, 6635 0, (size_t)Columns * sizeof(u8char_T)); 6636 (void)vim_memset(new_ScreenLinesC1 + new_row * Columns, 6637 0, (size_t)Columns * sizeof(u8char_T)); 6638 (void)vim_memset(new_ScreenLinesC2 + new_row * Columns, 6639 0, (size_t)Columns * sizeof(u8char_T)); 6640 } 6641 if (enc_dbcs == DBCS_JPNU) 6642 (void)vim_memset(new_ScreenLines2 + new_row * Columns, 6643 0, (size_t)Columns * sizeof(schar_T)); 6644 #endif 6645 (void)vim_memset(new_ScreenAttrs + new_row * Columns, 6646 0, (size_t)Columns * sizeof(sattr_T)); 6647 old_row = new_row + (screen_Rows - Rows); 6648 if (old_row >= 0) 6649 { 6650 if (screen_Columns < Columns) 6651 len = screen_Columns; 6652 else 6653 len = Columns; 6654 #ifdef FEAT_MBYTE 6655 /* When switching to utf-8 dont copy characters, they 6656 * may be invalid now. */ 6657 if (!(enc_utf8 && ScreenLinesUC == NULL)) 6658 #endif 6659 mch_memmove(new_ScreenLines + new_LineOffset[new_row], 6660 ScreenLines + LineOffset[old_row], 6661 (size_t)len * sizeof(schar_T)); 6662 #ifdef FEAT_MBYTE 6663 if (enc_utf8 && ScreenLinesUC != NULL) 6664 { 6665 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], 6666 ScreenLinesUC + LineOffset[old_row], 6667 (size_t)len * sizeof(u8char_T)); 6668 mch_memmove(new_ScreenLinesC1 + new_LineOffset[new_row], 6669 ScreenLinesC1 + LineOffset[old_row], 6670 (size_t)len * sizeof(u8char_T)); 6671 mch_memmove(new_ScreenLinesC2 + new_LineOffset[new_row], 6672 ScreenLinesC2 + LineOffset[old_row], 6673 (size_t)len * sizeof(u8char_T)); 6674 } 6675 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) 6676 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], 6677 ScreenLines2 + LineOffset[old_row], 6678 (size_t)len * sizeof(schar_T)); 6679 #endif 6680 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], 6681 ScreenAttrs + LineOffset[old_row], 6682 (size_t)len * sizeof(sattr_T)); 6683 } 6684 } 6685 } 6686 /* Use the last line of the screen for the current line. */ 6687 current_ScreenLine = new_ScreenLines + Rows * Columns; 6688 } 6689 6690 vim_free(ScreenLines); 6691 #ifdef FEAT_MBYTE 6692 vim_free(ScreenLinesUC); 6693 vim_free(ScreenLinesC1); 6694 vim_free(ScreenLinesC2); 6695 vim_free(ScreenLines2); 6696 #endif 6697 vim_free(ScreenAttrs); 6698 vim_free(LineOffset); 6699 vim_free(LineWraps); 6700 ScreenLines = new_ScreenLines; 6701 #ifdef FEAT_MBYTE 6702 ScreenLinesUC = new_ScreenLinesUC; 6703 ScreenLinesC1 = new_ScreenLinesC1; 6704 ScreenLinesC2 = new_ScreenLinesC2; 6705 ScreenLines2 = new_ScreenLines2; 6706 #endif 6707 ScreenAttrs = new_ScreenAttrs; 6708 LineOffset = new_LineOffset; 6709 LineWraps = new_LineWraps; 6710 6711 /* It's important that screen_Rows and screen_Columns reflect the actual 6712 * size of ScreenLines[]. Set them before calling anything. */ 6713 #ifdef FEAT_GUI 6714 old_Rows = screen_Rows; 6715 #endif 6716 screen_Rows = Rows; 6717 screen_Columns = Columns; 6718 6719 must_redraw = CLEAR; /* need to clear the screen later */ 6720 if (clear) 6721 screenclear2(); 6722 6723 #ifdef FEAT_GUI 6724 else if (gui.in_use 6725 && !gui.starting 6726 && ScreenLines != NULL 6727 && old_Rows != Rows) 6728 { 6729 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); 6730 /* 6731 * Adjust the position of the cursor, for when executing an external 6732 * command. 6733 */ 6734 if (msg_row >= Rows) /* Rows got smaller */ 6735 msg_row = Rows - 1; /* put cursor at last row */ 6736 else if (Rows > old_Rows) /* Rows got bigger */ 6737 msg_row += Rows - old_Rows; /* put cursor in same place */ 6738 if (msg_col >= Columns) /* Columns got smaller */ 6739 msg_col = Columns - 1; /* put cursor at last column */ 6740 } 6741 #endif 6742 6743 #ifdef FEAT_GUI_BEOS 6744 vim_unlock_screen(); 6745 #endif 6746 entered = FALSE; 6747 } 6748 6749 void 6750 screenclear() 6751 { 6752 check_for_delay(FALSE); 6753 screenalloc(FALSE); /* allocate screen buffers if size changed */ 6754 screenclear2(); /* clear the screen */ 6755 } 6756 6757 static void 6758 screenclear2() 6759 { 6760 int i; 6761 6762 if (starting == NO_SCREEN || ScreenLines == NULL 6763 #ifdef FEAT_GUI 6764 || (gui.in_use && gui.starting) 6765 #endif 6766 ) 6767 return; 6768 6769 #ifdef FEAT_GUI 6770 if (!gui.in_use) 6771 #endif 6772 screen_attr = -1; /* force setting the Normal colors */ 6773 screen_stop_highlight(); /* don't want highlighting here */ 6774 6775 #ifdef FEAT_CLIPBOARD 6776 /* disable selection without redrawing it */ 6777 clip_scroll_selection(9999); 6778 #endif 6779 6780 /* blank out ScreenLines */ 6781 for (i = 0; i < Rows; ++i) 6782 { 6783 lineclear(LineOffset[i], (int)Columns); 6784 LineWraps[i] = FALSE; 6785 } 6786 6787 if (can_clear(T_CL)) 6788 { 6789 out_str(T_CL); /* clear the display */ 6790 clear_cmdline = FALSE; 6791 } 6792 else 6793 { 6794 /* can't clear the screen, mark all chars with invalid attributes */ 6795 for (i = 0; i < Rows; ++i) 6796 lineinvalid(LineOffset[i], (int)Columns); 6797 clear_cmdline = TRUE; 6798 } 6799 6800 screen_cleared = TRUE; /* can use contents of ScreenLines now */ 6801 6802 win_rest_invalid(firstwin); 6803 redraw_cmdline = TRUE; 6804 if (must_redraw == CLEAR) /* no need to clear again */ 6805 must_redraw = NOT_VALID; 6806 compute_cmdrow(); 6807 msg_row = cmdline_row; /* put cursor on last line for messages */ 6808 msg_col = 0; 6809 screen_start(); /* don't know where cursor is now */ 6810 msg_scrolled = 0; /* can't scroll back */ 6811 msg_didany = FALSE; 6812 msg_didout = FALSE; 6813 } 6814 6815 /* 6816 * Clear one line in ScreenLines. 6817 */ 6818 static void 6819 lineclear(off, width) 6820 unsigned off; 6821 int width; 6822 { 6823 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); 6824 #ifdef FEAT_MBYTE 6825 if (enc_utf8) 6826 (void)vim_memset(ScreenLinesUC + off, 0, 6827 (size_t)width * sizeof(u8char_T)); 6828 #endif 6829 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); 6830 } 6831 6832 /* 6833 * Mark one line in ScreenLines invalid by setting the attributes to an 6834 * invalid value. 6835 */ 6836 static void 6837 lineinvalid(off, width) 6838 unsigned off; 6839 int width; 6840 { 6841 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); 6842 } 6843 6844 #ifdef FEAT_VERTSPLIT 6845 /* 6846 * Copy part of a Screenline for vertically split window "wp". 6847 */ 6848 static void 6849 linecopy(to, from, wp) 6850 int to; 6851 int from; 6852 win_T *wp; 6853 { 6854 unsigned off_to = LineOffset[to] + wp->w_wincol; 6855 unsigned off_from = LineOffset[from] + wp->w_wincol; 6856 6857 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, 6858 wp->w_width * sizeof(schar_T)); 6859 # ifdef FEAT_MBYTE 6860 if (enc_utf8) 6861 { 6862 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, 6863 wp->w_width * sizeof(u8char_T)); 6864 mch_memmove(ScreenLinesC1 + off_to, ScreenLinesC1 + off_from, 6865 wp->w_width * sizeof(u8char_T)); 6866 mch_memmove(ScreenLinesC2 + off_to, ScreenLinesC2 + off_from, 6867 wp->w_width * sizeof(u8char_T)); 6868 } 6869 if (enc_dbcs == DBCS_JPNU) 6870 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, 6871 wp->w_width * sizeof(schar_T)); 6872 # endif 6873 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, 6874 wp->w_width * sizeof(sattr_T)); 6875 } 6876 #endif 6877 6878 /* 6879 * Return TRUE if clearing with term string "p" would work. 6880 * It can't work when the string is empty or it won't set the right background. 6881 */ 6882 int 6883 can_clear(p) 6884 char_u *p; 6885 { 6886 return (*p != NUL && (t_colors <= 1 6887 #ifdef FEAT_GUI 6888 || gui.in_use 6889 #endif 6890 || cterm_normal_bg_color == 0 || *T_UT != NUL)); 6891 } 6892 6893 /* 6894 * Reset cursor position. Use whenever cursor was moved because of outputting 6895 * something directly to the screen (shell commands) or a terminal control 6896 * code. 6897 */ 6898 void 6899 screen_start() 6900 { 6901 screen_cur_row = screen_cur_col = 9999; 6902 } 6903 6904 /* 6905 * Note that the cursor has gone down to the next line, column 0. 6906 * Used for Ex mode. 6907 */ 6908 void 6909 screen_down() 6910 { 6911 screen_cur_col = 0; 6912 if (screen_cur_row < Rows - 1) 6913 ++screen_cur_row; 6914 } 6915 6916 /* 6917 * Move the cursor to position "row","col" in the screen. 6918 * This tries to find the most efficient way to move, minimizing the number of 6919 * characters sent to the terminal. 6920 */ 6921 void 6922 windgoto(row, col) 6923 int row; 6924 int col; 6925 { 6926 char_u *p; 6927 int i; 6928 int plan; 6929 int cost; 6930 int wouldbe_col; 6931 int noinvcurs; 6932 char_u *bs; 6933 int goto_cost; 6934 int attr; 6935 6936 #define GOTO_COST 7 /* asssume a term_windgoto() takes about 7 chars */ 6937 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ 6938 6939 #define PLAN_LE 1 6940 #define PLAN_CR 2 6941 #define PLAN_NL 3 6942 #define PLAN_WRITE 4 6943 /* Can't use ScreenLines unless initialized */ 6944 if (ScreenLines == NULL) 6945 return; 6946 6947 if (col != screen_cur_col || row != screen_cur_row) 6948 { 6949 /* Check for valid position. */ 6950 if (row < 0) /* window without text lines? */ 6951 row = 0; 6952 if (row >= screen_Rows) 6953 row = screen_Rows - 1; 6954 if (col >= screen_Columns) 6955 col = screen_Columns - 1; 6956 6957 /* check if no cursor movement is allowed in highlight mode */ 6958 if (screen_attr && *T_MS == NUL) 6959 noinvcurs = HIGHL_COST; 6960 else 6961 noinvcurs = 0; 6962 goto_cost = GOTO_COST + noinvcurs; 6963 6964 /* 6965 * Plan how to do the positioning: 6966 * 1. Use CR to move it to column 0, same row. 6967 * 2. Use T_LE to move it a few columns to the left. 6968 * 3. Use NL to move a few lines down, column 0. 6969 * 4. Move a few columns to the right with T_ND or by writing chars. 6970 * 6971 * Don't do this if the cursor went beyond the last column, the cursor 6972 * position is unknown then (some terminals wrap, some don't ) 6973 * 6974 * First check if the highlighting attibutes allow us to write 6975 * characters to move the cursor to the right. 6976 */ 6977 if (row >= screen_cur_row && screen_cur_col < Columns) 6978 { 6979 /* 6980 * If the cursor is in the same row, bigger col, we can use CR 6981 * or T_LE. 6982 */ 6983 bs = NULL; /* init for GCC */ 6984 attr = screen_attr; 6985 if (row == screen_cur_row && col < screen_cur_col) 6986 { 6987 /* "le" is preferred over "bc", because "bc" is obsolete */ 6988 if (*T_LE) 6989 bs = T_LE; /* "cursor left" */ 6990 else 6991 bs = T_BC; /* "backspace character (old) */ 6992 if (*bs) 6993 cost = (screen_cur_col - col) * (int)STRLEN(bs); 6994 else 6995 cost = 999; 6996 if (col + 1 < cost) /* using CR is less characters */ 6997 { 6998 plan = PLAN_CR; 6999 wouldbe_col = 0; 7000 cost = 1; /* CR is just one character */ 7001 } 7002 else 7003 { 7004 plan = PLAN_LE; 7005 wouldbe_col = col; 7006 } 7007 if (noinvcurs) /* will stop highlighting */ 7008 { 7009 cost += noinvcurs; 7010 attr = 0; 7011 } 7012 } 7013 7014 /* 7015 * If the cursor is above where we want to be, we can use CR LF. 7016 */ 7017 else if (row > screen_cur_row) 7018 { 7019 plan = PLAN_NL; 7020 wouldbe_col = 0; 7021 cost = (row - screen_cur_row) * 2; /* CR LF */ 7022 if (noinvcurs) /* will stop highlighting */ 7023 { 7024 cost += noinvcurs; 7025 attr = 0; 7026 } 7027 } 7028 7029 /* 7030 * If the cursor is in the same row, smaller col, just use write. 7031 */ 7032 else 7033 { 7034 plan = PLAN_WRITE; 7035 wouldbe_col = screen_cur_col; 7036 cost = 0; 7037 } 7038 7039 /* 7040 * Check if any characters that need to be written have the 7041 * correct attributes. Also avoid UTF-8 characters. 7042 */ 7043 i = col - wouldbe_col; 7044 if (i > 0) 7045 cost += i; 7046 if (cost < goto_cost && i > 0) 7047 { 7048 /* 7049 * Check if the attributes are correct without additionally 7050 * stopping highlighting. 7051 */ 7052 p = ScreenAttrs + LineOffset[row] + wouldbe_col; 7053 while (i && *p++ == attr) 7054 --i; 7055 if (i != 0) 7056 { 7057 /* 7058 * Try if it works when highlighting is stopped here. 7059 */ 7060 if (*--p == 0) 7061 { 7062 cost += noinvcurs; 7063 while (i && *p++ == 0) 7064 --i; 7065 } 7066 if (i != 0) 7067 cost = 999; /* different attributes, don't do it */ 7068 } 7069 #ifdef FEAT_MBYTE 7070 if (enc_utf8) 7071 { 7072 /* Don't use an UTF-8 char for positioning, it's slow. */ 7073 for (i = wouldbe_col; i < col; ++i) 7074 if (ScreenLinesUC[LineOffset[row] + i] != 0) 7075 { 7076 cost = 999; 7077 break; 7078 } 7079 } 7080 #endif 7081 } 7082 7083 /* 7084 * We can do it without term_windgoto()! 7085 */ 7086 if (cost < goto_cost) 7087 { 7088 if (plan == PLAN_LE) 7089 { 7090 if (noinvcurs) 7091 screen_stop_highlight(); 7092 while (screen_cur_col > col) 7093 { 7094 out_str(bs); 7095 --screen_cur_col; 7096 } 7097 } 7098 else if (plan == PLAN_CR) 7099 { 7100 if (noinvcurs) 7101 screen_stop_highlight(); 7102 out_char('\r'); 7103 screen_cur_col = 0; 7104 } 7105 else if (plan == PLAN_NL) 7106 { 7107 if (noinvcurs) 7108 screen_stop_highlight(); 7109 while (screen_cur_row < row) 7110 { 7111 out_char('\n'); 7112 ++screen_cur_row; 7113 } 7114 screen_cur_col = 0; 7115 } 7116 7117 i = col - screen_cur_col; 7118 if (i > 0) 7119 { 7120 /* 7121 * Use cursor-right if it's one character only. Avoids 7122 * removing a line of pixels from the last bold char, when 7123 * using the bold trick in the GUI. 7124 */ 7125 if (T_ND[0] != NUL && T_ND[1] == NUL) 7126 { 7127 while (i-- > 0) 7128 out_char(*T_ND); 7129 } 7130 else 7131 { 7132 int off; 7133 7134 off = LineOffset[row] + screen_cur_col; 7135 while (i-- > 0) 7136 { 7137 if (ScreenAttrs[off] != screen_attr) 7138 screen_stop_highlight(); 7139 #ifdef FEAT_MBYTE 7140 out_flush_check(); 7141 #endif 7142 out_char(ScreenLines[off]); 7143 #ifdef FEAT_MBYTE 7144 if (enc_dbcs == DBCS_JPNU 7145 && ScreenLines[off] == 0x8e) 7146 out_char(ScreenLines2[off]); 7147 #endif 7148 ++off; 7149 } 7150 } 7151 } 7152 } 7153 } 7154 else 7155 cost = 999; 7156 7157 if (cost >= goto_cost) 7158 { 7159 if (noinvcurs) 7160 screen_stop_highlight(); 7161 if (row == screen_cur_row && (col > screen_cur_col) && 7162 *T_CRI != NUL) 7163 term_cursor_right(col - screen_cur_col); 7164 else 7165 term_windgoto(row, col); 7166 } 7167 screen_cur_row = row; 7168 screen_cur_col = col; 7169 } 7170 } 7171 7172 /* 7173 * Set cursor to its position in the current window. 7174 */ 7175 void 7176 setcursor() 7177 { 7178 if (redrawing()) 7179 { 7180 validate_cursor(); 7181 windgoto(W_WINROW(curwin) + curwin->w_wrow, 7182 W_WINCOL(curwin) + ( 7183 #ifdef FEAT_RIGHTLEFT 7184 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( 7185 # ifdef FEAT_MBYTE 7186 has_mbyte ? (*mb_ptr2cells)(ml_get_cursor()) : 7187 # endif 7188 1)) : 7189 #endif 7190 curwin->w_wcol)); 7191 } 7192 } 7193 7194 7195 /* 7196 * insert 'line_count' lines at 'row' in window 'wp' 7197 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. 7198 * if 'mayclear' is TRUE the screen will be cleared if it is faster than 7199 * scrolling. 7200 * Returns FAIL if the lines are not inserted, OK for success. 7201 */ 7202 int 7203 win_ins_lines(wp, row, line_count, invalid, mayclear) 7204 win_T *wp; 7205 int row; 7206 int line_count; 7207 int invalid; 7208 int mayclear; 7209 { 7210 int did_delete; 7211 int nextrow; 7212 int lastrow; 7213 int retval; 7214 7215 if (invalid) 7216 wp->w_lines_valid = 0; 7217 7218 if (wp->w_height < 5) 7219 return FAIL; 7220 7221 if (line_count > wp->w_height - row) 7222 line_count = wp->w_height - row; 7223 7224 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); 7225 if (retval != MAYBE) 7226 return retval; 7227 7228 /* 7229 * If there is a next window or a status line, we first try to delete the 7230 * lines at the bottom to avoid messing what is after the window. 7231 * If this fails and there are following windows, don't do anything to avoid 7232 * messing up those windows, better just redraw. 7233 */ 7234 did_delete = FALSE; 7235 #ifdef FEAT_WINDOWS 7236 if (wp->w_next != NULL || wp->w_status_height) 7237 { 7238 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, 7239 line_count, (int)Rows, FALSE, NULL) == OK) 7240 did_delete = TRUE; 7241 else if (wp->w_next) 7242 return FAIL; 7243 } 7244 #endif 7245 /* 7246 * if no lines deleted, blank the lines that will end up below the window 7247 */ 7248 if (!did_delete) 7249 { 7250 #ifdef FEAT_WINDOWS 7251 wp->w_redr_status = TRUE; 7252 #endif 7253 redraw_cmdline = TRUE; 7254 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); 7255 lastrow = nextrow + line_count; 7256 if (lastrow > Rows) 7257 lastrow = Rows; 7258 screen_fill(nextrow - line_count, lastrow - line_count, 7259 W_WINCOL(wp), (int)W_ENDCOL(wp), 7260 ' ', ' ', 0); 7261 } 7262 7263 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) 7264 == FAIL) 7265 { 7266 /* deletion will have messed up other windows */ 7267 if (did_delete) 7268 { 7269 #ifdef FEAT_WINDOWS 7270 wp->w_redr_status = TRUE; 7271 #endif 7272 win_rest_invalid(W_NEXT(wp)); 7273 } 7274 return FAIL; 7275 } 7276 7277 return OK; 7278 } 7279 7280 /* 7281 * delete "line_count" window lines at "row" in window "wp" 7282 * If "invalid" is TRUE curwin->w_lines[] is invalidated. 7283 * If "mayclear" is TRUE the screen will be cleared if it is faster than 7284 * scrolling 7285 * Return OK for success, FAIL if the lines are not deleted. 7286 */ 7287 int 7288 win_del_lines(wp, row, line_count, invalid, mayclear) 7289 win_T *wp; 7290 int row; 7291 int line_count; 7292 int invalid; 7293 int mayclear; 7294 { 7295 int retval; 7296 7297 if (invalid) 7298 wp->w_lines_valid = 0; 7299 7300 if (line_count > wp->w_height - row) 7301 line_count = wp->w_height - row; 7302 7303 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); 7304 if (retval != MAYBE) 7305 return retval; 7306 7307 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, 7308 (int)Rows, FALSE, NULL) == FAIL) 7309 return FAIL; 7310 7311 #ifdef FEAT_WINDOWS 7312 /* 7313 * If there are windows or status lines below, try to put them at the 7314 * correct place. If we can't do that, they have to be redrawn. 7315 */ 7316 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) 7317 { 7318 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, 7319 line_count, (int)Rows, NULL) == FAIL) 7320 { 7321 wp->w_redr_status = TRUE; 7322 win_rest_invalid(wp->w_next); 7323 } 7324 } 7325 /* 7326 * If this is the last window and there is no status line, redraw the 7327 * command line later. 7328 */ 7329 else 7330 #endif 7331 redraw_cmdline = TRUE; 7332 return OK; 7333 } 7334 7335 /* 7336 * Common code for win_ins_lines() and win_del_lines(). 7337 * Returns OK or FAIL when the work has been done. 7338 * Returns MAYBE when not finished yet. 7339 */ 7340 static int 7341 win_do_lines(wp, row, line_count, mayclear, del) 7342 win_T *wp; 7343 int row; 7344 int line_count; 7345 int mayclear; 7346 int del; 7347 { 7348 int retval; 7349 7350 if (!redrawing() || line_count <= 0) 7351 return FAIL; 7352 7353 /* only a few lines left: redraw is faster */ 7354 if (mayclear && Rows - line_count < 5 7355 #ifdef FEAT_VERTSPLIT 7356 && wp->w_width == Columns 7357 #endif 7358 ) 7359 { 7360 screenclear(); /* will set wp->w_lines_valid to 0 */ 7361 return FAIL; 7362 } 7363 7364 /* 7365 * Delete all remaining lines 7366 */ 7367 if (row + line_count >= wp->w_height) 7368 { 7369 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, 7370 W_WINCOL(wp), (int)W_ENDCOL(wp), 7371 ' ', ' ', 0); 7372 return OK; 7373 } 7374 7375 /* 7376 * when scrolling, the message on the command line should be cleared, 7377 * otherwise it will stay there forever. 7378 */ 7379 clear_cmdline = TRUE; 7380 7381 /* 7382 * If the terminal can set a scroll region, use that. 7383 * Always do this in a vertically split window. This will redraw from 7384 * ScreenLines[] when t_CV isn't defined. That's faster than using 7385 * win_line(). 7386 * Don't use a scroll region when we are going to redraw the text, writing 7387 * a character in the lower right corner of the scroll region causes a 7388 * scroll-up in the DJGPP version. 7389 */ 7390 if (scroll_region 7391 #ifdef FEAT_VERTSPLIT 7392 || W_WIDTH(wp) != Columns 7393 #endif 7394 ) 7395 { 7396 #ifdef FEAT_VERTSPLIT 7397 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) 7398 #endif 7399 scroll_region_set(wp, row); 7400 if (del) 7401 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, 7402 wp->w_height - row, FALSE, wp); 7403 else 7404 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, 7405 wp->w_height - row, wp); 7406 #ifdef FEAT_VERTSPLIT 7407 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) 7408 #endif 7409 scroll_region_reset(); 7410 return retval; 7411 } 7412 7413 #ifdef FEAT_WINDOWS 7414 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ 7415 return FAIL; 7416 #endif 7417 7418 return MAYBE; 7419 } 7420 7421 /* 7422 * window 'wp' and everything after it is messed up, mark it for redraw 7423 */ 7424 static void 7425 win_rest_invalid(wp) 7426 win_T *wp; 7427 { 7428 #ifdef FEAT_WINDOWS 7429 while (wp != NULL) 7430 #else 7431 if (wp != NULL) 7432 #endif 7433 { 7434 redraw_win_later(wp, NOT_VALID); 7435 #ifdef FEAT_WINDOWS 7436 wp->w_redr_status = TRUE; 7437 wp = wp->w_next; 7438 #endif 7439 } 7440 redraw_cmdline = TRUE; 7441 } 7442 7443 /* 7444 * The rest of the routines in this file perform screen manipulations. The 7445 * given operation is performed physically on the screen. The corresponding 7446 * change is also made to the internal screen image. In this way, the editor 7447 * anticipates the effect of editing changes on the appearance of the screen. 7448 * That way, when we call screenupdate a complete redraw isn't usually 7449 * necessary. Another advantage is that we can keep adding code to anticipate 7450 * screen changes, and in the meantime, everything still works. 7451 */ 7452 7453 /* 7454 * types for inserting or deleting lines 7455 */ 7456 #define USE_T_CAL 1 7457 #define USE_T_CDL 2 7458 #define USE_T_AL 3 7459 #define USE_T_CE 4 7460 #define USE_T_DL 5 7461 #define USE_T_SR 6 7462 #define USE_NL 7 7463 #define USE_T_CD 8 7464 #define USE_REDRAW 9 7465 7466 /* 7467 * insert lines on the screen and update ScreenLines[] 7468 * 'end' is the line after the scrolled part. Normally it is Rows. 7469 * When scrolling region used 'off' is the offset from the top for the region. 7470 * 'row' and 'end' are relative to the start of the region. 7471 * 7472 * return FAIL for failure, OK for success. 7473 */ 7474 static int 7475 screen_ins_lines(off, row, line_count, end, wp) 7476 int off; 7477 int row; 7478 int line_count; 7479 int end; 7480 win_T *wp; /* NULL or window to use width from */ 7481 { 7482 int i; 7483 int j; 7484 unsigned temp; 7485 int cursor_row; 7486 int type; 7487 int result_empty; 7488 int can_ce = can_clear(T_CE); 7489 7490 /* 7491 * FAIL if 7492 * - there is no valid screen 7493 * - the screen has to be redrawn completely 7494 * - the line count is less than one 7495 * - the line count is more than 'ttyscroll' 7496 */ 7497 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) 7498 return FAIL; 7499 7500 /* 7501 * There are seven ways to insert lines: 7502 * 0. When in a vertically split window and t_CV isn't set, redraw the 7503 * characters from ScreenLines[]. 7504 * 1. Use T_CD (clear to end of display) if it exists and the result of 7505 * the insert is just empty lines 7506 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not 7507 * present or line_count > 1. It looks better if we do all the inserts 7508 * at once. 7509 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the 7510 * insert is just empty lines and T_CE is not present or line_count > 7511 * 1. 7512 * 4. Use T_AL (insert line) if it exists. 7513 * 5. Use T_CE (erase line) if it exists and the result of the insert is 7514 * just empty lines. 7515 * 6. Use T_DL (delete line) if it exists and the result of the insert is 7516 * just empty lines. 7517 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and 7518 * the 'da' flag is not set or we have clear line capability. 7519 * 8. redraw the characters from ScreenLines[]. 7520 * 7521 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves 7522 * the scrollbar for the window. It does have insert line, use that if it 7523 * exists. 7524 */ 7525 result_empty = (row + line_count >= end); 7526 #ifdef FEAT_VERTSPLIT 7527 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) 7528 type = USE_REDRAW; 7529 else 7530 #endif 7531 if (can_clear(T_CD) && result_empty) 7532 type = USE_T_CD; 7533 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) 7534 type = USE_T_CAL; 7535 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) 7536 type = USE_T_CDL; 7537 else if (*T_AL != NUL) 7538 type = USE_T_AL; 7539 else if (can_ce && result_empty) 7540 type = USE_T_CE; 7541 else if (*T_DL != NUL && result_empty) 7542 type = USE_T_DL; 7543 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) 7544 type = USE_T_SR; 7545 else 7546 return FAIL; 7547 7548 /* 7549 * For clearing the lines screen_del_lines() is used. This will also take 7550 * care of t_db if necessary. 7551 */ 7552 if (type == USE_T_CD || type == USE_T_CDL || 7553 type == USE_T_CE || type == USE_T_DL) 7554 return screen_del_lines(off, row, line_count, end, FALSE, wp); 7555 7556 /* 7557 * If text is retained below the screen, first clear or delete as many 7558 * lines at the bottom of the window as are about to be inserted so that 7559 * the deleted lines won't later surface during a screen_del_lines. 7560 */ 7561 if (*T_DB) 7562 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); 7563 7564 #ifdef FEAT_CLIPBOARD 7565 /* Remove a modeless selection when inserting lines halfway the screen 7566 * or not the full width of the screen. */ 7567 if (off + row > 0 7568 # ifdef FEAT_VERTSPLIT 7569 || (wp != NULL && wp->w_width != Columns) 7570 # endif 7571 ) 7572 clip_clear_selection(); 7573 else 7574 clip_scroll_selection(-line_count); 7575 #endif 7576 7577 #ifdef FEAT_GUI_BEOS 7578 vim_lock_screen(); 7579 #endif 7580 #ifdef FEAT_GUI 7581 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the 7582 * scrolling is actually carried out. */ 7583 gui_dont_update_cursor(); 7584 #endif 7585 7586 if (*T_CCS != NUL) /* cursor relative to region */ 7587 cursor_row = row; 7588 else 7589 cursor_row = row + off; 7590 7591 /* 7592 * Shift LineOffset[] line_count down to reflect the inserted lines. 7593 * Clear the inserted lines in ScreenLines[]. 7594 */ 7595 row += off; 7596 end += off; 7597 for (i = 0; i < line_count; ++i) 7598 { 7599 #ifdef FEAT_VERTSPLIT 7600 if (wp != NULL && wp->w_width != Columns) 7601 { 7602 /* need to copy part of a line */ 7603 j = end - 1 - i; 7604 while ((j -= line_count) >= row) 7605 linecopy(j + line_count, j, wp); 7606 j += line_count; 7607 if (can_clear((char_u *)" ")) 7608 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); 7609 else 7610 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); 7611 LineWraps[j] = FALSE; 7612 } 7613 else 7614 #endif 7615 { 7616 j = end - 1 - i; 7617 temp = LineOffset[j]; 7618 while ((j -= line_count) >= row) 7619 { 7620 LineOffset[j + line_count] = LineOffset[j]; 7621 LineWraps[j + line_count] = LineWraps[j]; 7622 } 7623 LineOffset[j + line_count] = temp; 7624 LineWraps[j + line_count] = FALSE; 7625 if (can_clear((char_u *)" ")) 7626 lineclear(temp, (int)Columns); 7627 else 7628 lineinvalid(temp, (int)Columns); 7629 } 7630 } 7631 #ifdef FEAT_GUI_BEOS 7632 vim_unlock_screen(); 7633 #endif 7634 7635 screen_stop_highlight(); 7636 windgoto(cursor_row, 0); 7637 7638 #ifdef FEAT_VERTSPLIT 7639 /* redraw the characters */ 7640 if (type == USE_REDRAW) 7641 redraw_block(row, end, wp); 7642 else 7643 #endif 7644 if (type == USE_T_CAL) 7645 { 7646 term_append_lines(line_count); 7647 screen_start(); /* don't know where cursor is now */ 7648 } 7649 else 7650 { 7651 for (i = 0; i < line_count; i++) 7652 { 7653 if (type == USE_T_AL) 7654 { 7655 if (i && cursor_row != 0) 7656 windgoto(cursor_row, 0); 7657 out_str(T_AL); 7658 } 7659 else /* type == USE_T_SR */ 7660 out_str(T_SR); 7661 screen_start(); /* don't know where cursor is now */ 7662 } 7663 } 7664 7665 /* 7666 * With scroll-reverse and 'da' flag set we need to clear the lines that 7667 * have been scrolled down into the region. 7668 */ 7669 if (type == USE_T_SR && *T_DA) 7670 { 7671 for (i = 0; i < line_count; ++i) 7672 { 7673 windgoto(off + i, 0); 7674 out_str(T_CE); 7675 screen_start(); /* don't know where cursor is now */ 7676 } 7677 } 7678 7679 #ifdef FEAT_GUI 7680 gui_can_update_cursor(); 7681 if (gui.in_use) 7682 out_flush(); /* always flush after a scroll */ 7683 #endif 7684 return OK; 7685 } 7686 7687 /* 7688 * delete lines on the screen and update ScreenLines[] 7689 * 'end' is the line after the scrolled part. Normally it is Rows. 7690 * When scrolling region used 'off' is the offset from the top for the region. 7691 * 'row' and 'end' are relative to the start of the region. 7692 * 7693 * Return OK for success, FAIL if the lines are not deleted. 7694 */ 7695 /*ARGSUSED*/ 7696 int 7697 screen_del_lines(off, row, line_count, end, force, wp) 7698 int off; 7699 int row; 7700 int line_count; 7701 int end; 7702 int force; /* even when line_count > p_ttyscroll */ 7703 win_T *wp; /* NULL or window to use width from */ 7704 { 7705 int j; 7706 int i; 7707 unsigned temp; 7708 int cursor_row; 7709 int cursor_end; 7710 int result_empty; /* result is empty until end of region */ 7711 int can_delete; /* deleting line codes can be used */ 7712 int type; 7713 7714 /* 7715 * FAIL if 7716 * - there is no valid screen 7717 * - the screen has to be redrawn completely 7718 * - the line count is less than one 7719 * - the line count is more than 'ttyscroll' 7720 */ 7721 if (!screen_valid(TRUE) || line_count <= 0 || 7722 (!force && line_count > p_ttyscroll)) 7723 return FAIL; 7724 7725 /* 7726 * Check if the rest of the current region will become empty. 7727 */ 7728 result_empty = row + line_count >= end; 7729 7730 /* 7731 * We can delete lines only when 'db' flag not set or when 'ce' option 7732 * available. 7733 */ 7734 can_delete = (*T_DB == NUL || can_clear(T_CE)); 7735 7736 /* 7737 * There are six ways to delete lines: 7738 * 0. When in a vertically split window and t_CV isn't set, redraw the 7739 * characters from ScreenLines[]. 7740 * 1. Use T_CD if it exists and the result is empty. 7741 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. 7742 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or 7743 * none of the other ways work. 7744 * 4. Use T_CE (erase line) if the result is empty. 7745 * 5. Use T_DL (delete line) if it exists. 7746 * 6. redraw the characters from ScreenLines[]. 7747 */ 7748 #ifdef FEAT_VERTSPLIT 7749 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) 7750 type = USE_REDRAW; 7751 else 7752 #endif 7753 if (can_clear(T_CD) && result_empty) 7754 type = USE_T_CD; 7755 #if defined(__BEOS__) && defined(BEOS_DR8) 7756 /* 7757 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in 7758 * its internal termcap... this works okay for tests which test *T_DB != 7759 * NUL. It has the disadvantage that the user cannot use any :set t_* 7760 * command to get T_DB (back) to empty_option, only :set term=... will do 7761 * the trick... 7762 * Anyway, this hack will hopefully go away with the next OS release. 7763 * (Olaf Seibert) 7764 */ 7765 else if (row == 0 && T_DB == empty_option 7766 && (line_count == 1 || *T_CDL == NUL)) 7767 #else 7768 else if (row == 0 && ( 7769 #ifndef AMIGA 7770 /* On the Amiga, somehow '\n' on the last line doesn't always scroll 7771 * up, so use delete-line command */ 7772 line_count == 1 || 7773 #endif 7774 *T_CDL == NUL)) 7775 #endif 7776 type = USE_NL; 7777 else if (*T_CDL != NUL && line_count > 1 && can_delete) 7778 type = USE_T_CDL; 7779 else if (can_clear(T_CE) && result_empty 7780 #ifdef FEAT_VERTSPLIT 7781 && (wp == NULL || wp->w_width == Columns) 7782 #endif 7783 ) 7784 type = USE_T_CE; 7785 else if (*T_DL != NUL && can_delete) 7786 type = USE_T_DL; 7787 else if (*T_CDL != NUL && can_delete) 7788 type = USE_T_CDL; 7789 else 7790 return FAIL; 7791 7792 #ifdef FEAT_CLIPBOARD 7793 /* Remove a modeless selection when deleting lines halfway the screen or 7794 * not the full width of the screen. */ 7795 if (off + row > 0 7796 # ifdef FEAT_VERTSPLIT 7797 || (wp != NULL && wp->w_width != Columns) 7798 # endif 7799 ) 7800 clip_clear_selection(); 7801 else 7802 clip_scroll_selection(line_count); 7803 #endif 7804 7805 #ifdef FEAT_GUI_BEOS 7806 vim_lock_screen(); 7807 #endif 7808 #ifdef FEAT_GUI 7809 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the 7810 * scrolling is actually carried out. */ 7811 gui_dont_update_cursor(); 7812 #endif 7813 7814 if (*T_CCS != NUL) /* cursor relative to region */ 7815 { 7816 cursor_row = row; 7817 cursor_end = end; 7818 } 7819 else 7820 { 7821 cursor_row = row + off; 7822 cursor_end = end + off; 7823 } 7824 7825 /* 7826 * Now shift LineOffset[] line_count up to reflect the deleted lines. 7827 * Clear the inserted lines in ScreenLines[]. 7828 */ 7829 row += off; 7830 end += off; 7831 for (i = 0; i < line_count; ++i) 7832 { 7833 #ifdef FEAT_VERTSPLIT 7834 if (wp != NULL && wp->w_width != Columns) 7835 { 7836 /* need to copy part of a line */ 7837 j = row + i; 7838 while ((j += line_count) <= end - 1) 7839 linecopy(j - line_count, j, wp); 7840 j -= line_count; 7841 if (can_clear((char_u *)" ")) 7842 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); 7843 else 7844 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); 7845 LineWraps[j] = FALSE; 7846 } 7847 else 7848 #endif 7849 { 7850 /* whole width, moving the line pointers is faster */ 7851 j = row + i; 7852 temp = LineOffset[j]; 7853 while ((j += line_count) <= end - 1) 7854 { 7855 LineOffset[j - line_count] = LineOffset[j]; 7856 LineWraps[j - line_count] = LineWraps[j]; 7857 } 7858 LineOffset[j - line_count] = temp; 7859 LineWraps[j - line_count] = FALSE; 7860 if (can_clear((char_u *)" ")) 7861 lineclear(temp, (int)Columns); 7862 else 7863 lineinvalid(temp, (int)Columns); 7864 } 7865 } 7866 #ifdef FEAT_GUI_BEOS 7867 vim_unlock_screen(); 7868 #endif 7869 7870 screen_stop_highlight(); 7871 7872 #ifdef FEAT_VERTSPLIT 7873 /* redraw the characters */ 7874 if (type == USE_REDRAW) 7875 redraw_block(row, end, wp); 7876 else 7877 #endif 7878 if (type == USE_T_CD) /* delete the lines */ 7879 { 7880 windgoto(cursor_row, 0); 7881 out_str(T_CD); 7882 screen_start(); /* don't know where cursor is now */ 7883 } 7884 else if (type == USE_T_CDL) 7885 { 7886 windgoto(cursor_row, 0); 7887 term_delete_lines(line_count); 7888 screen_start(); /* don't know where cursor is now */ 7889 } 7890 /* 7891 * Deleting lines at top of the screen or scroll region: Just scroll 7892 * the whole screen (scroll region) up by outputting newlines on the 7893 * last line. 7894 */ 7895 else if (type == USE_NL) 7896 { 7897 windgoto(cursor_end - 1, 0); 7898 for (i = line_count; --i >= 0; ) 7899 out_char('\n'); /* cursor will remain on same line */ 7900 } 7901 else 7902 { 7903 for (i = line_count; --i >= 0; ) 7904 { 7905 if (type == USE_T_DL) 7906 { 7907 windgoto(cursor_row, 0); 7908 out_str(T_DL); /* delete a line */ 7909 } 7910 else /* type == USE_T_CE */ 7911 { 7912 windgoto(cursor_row + i, 0); 7913 out_str(T_CE); /* erase a line */ 7914 } 7915 screen_start(); /* don't know where cursor is now */ 7916 } 7917 } 7918 7919 /* 7920 * If the 'db' flag is set, we need to clear the lines that have been 7921 * scrolled up at the bottom of the region. 7922 */ 7923 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) 7924 { 7925 for (i = line_count; i > 0; --i) 7926 { 7927 windgoto(cursor_end - i, 0); 7928 out_str(T_CE); /* erase a line */ 7929 screen_start(); /* don't know where cursor is now */ 7930 } 7931 } 7932 7933 #ifdef FEAT_GUI 7934 gui_can_update_cursor(); 7935 if (gui.in_use) 7936 out_flush(); /* always flush after a scroll */ 7937 #endif 7938 7939 return OK; 7940 } 7941 7942 /* 7943 * show the current mode and ruler 7944 * 7945 * If clear_cmdline is TRUE, clear the rest of the cmdline. 7946 * If clear_cmdline is FALSE there may be a message there that needs to be 7947 * cleared only if a mode is shown. 7948 * Return the length of the message (0 if no message). 7949 */ 7950 int 7951 showmode() 7952 { 7953 int need_clear; 7954 int length = 0; 7955 int do_mode; 7956 int attr; 7957 int nwr_save; 7958 #ifdef FEAT_INS_EXPAND 7959 int sub_attr; 7960 #endif 7961 7962 do_mode = (p_smd && ((State & INSERT) || restart_edit 7963 #ifdef FEAT_VISUAL 7964 || VIsual_active 7965 #endif 7966 )); 7967 if (do_mode || Recording) 7968 { 7969 /* 7970 * Don't show mode right now, when not redrawing or inside a mapping. 7971 * Call char_avail() only when we are going to show something, because 7972 * it takes a bit of time. 7973 */ 7974 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) 7975 { 7976 redraw_cmdline = TRUE; /* show mode later */ 7977 return 0; 7978 } 7979 7980 nwr_save = need_wait_return; 7981 7982 /* wait a bit before overwriting an important message */ 7983 check_for_delay(FALSE); 7984 7985 /* if the cmdline is more than one line high, erase top lines */ 7986 need_clear = clear_cmdline; 7987 if (clear_cmdline && cmdline_row < Rows - 1) 7988 msg_clr_cmdline(); /* will reset clear_cmdline */ 7989 7990 /* Position on the last line in the window, column 0 */ 7991 msg_pos_mode(); 7992 cursor_off(); 7993 attr = hl_attr(HLF_CM); /* Highlight mode */ 7994 if (do_mode) 7995 { 7996 MSG_PUTS_ATTR("--", attr); 7997 #if defined(FEAT_XIM) 7998 if (xic != NULL && im_get_status() && !p_imdisable 7999 && curbuf->b_p_iminsert == B_IMODE_IM) 8000 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */ 8001 MSG_PUTS_ATTR(" IM", attr); 8002 # else 8003 MSG_PUTS_ATTR(" XIM", attr); 8004 # endif 8005 #endif 8006 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) 8007 if (gui.in_use) 8008 { 8009 if (hangul_input_state_get()) 8010 MSG_PUTS_ATTR(" �ѱ�", attr); /* HANGUL */ 8011 } 8012 #endif 8013 #ifdef FEAT_INS_EXPAND 8014 if (edit_submode != NULL) /* CTRL-X in Insert mode */ 8015 { 8016 /* These messages can get long, avoid a wrap in a narrow 8017 * window. Prefer showing edit_submode_extra. */ 8018 length = (Rows - msg_row) * Columns - 3; 8019 if (edit_submode_extra != NULL) 8020 length -= vim_strsize(edit_submode_extra); 8021 if (length > 0) 8022 { 8023 if (edit_submode_pre != NULL) 8024 length -= vim_strsize(edit_submode_pre); 8025 if (length - vim_strsize(edit_submode) > 0) 8026 { 8027 if (edit_submode_pre != NULL) 8028 msg_puts_attr(edit_submode_pre, attr); 8029 msg_puts_attr(edit_submode, attr); 8030 } 8031 if (edit_submode_extra != NULL) 8032 { 8033 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ 8034 if ((int)edit_submode_highl < (int)HLF_COUNT) 8035 sub_attr = hl_attr(edit_submode_highl); 8036 else 8037 sub_attr = attr; 8038 msg_puts_attr(edit_submode_extra, sub_attr); 8039 } 8040 } 8041 length = 0; 8042 } 8043 else 8044 #endif 8045 { 8046 #ifdef FEAT_VREPLACE 8047 if (State & VREPLACE_FLAG) 8048 MSG_PUTS_ATTR(_(" VREPLACE"), attr); 8049 else 8050 #endif 8051 if (State & REPLACE_FLAG) 8052 MSG_PUTS_ATTR(_(" REPLACE"), attr); 8053 else if (State & INSERT) 8054 { 8055 #ifdef FEAT_RIGHTLEFT 8056 if (p_ri) 8057 MSG_PUTS_ATTR(_(" REVERSE"), attr); 8058 #endif 8059 MSG_PUTS_ATTR(_(" INSERT"), attr); 8060 } 8061 else if (restart_edit == 'I') 8062 MSG_PUTS_ATTR(_(" (insert)"), attr); 8063 else if (restart_edit == 'R') 8064 MSG_PUTS_ATTR(_(" (replace)"), attr); 8065 else if (restart_edit == 'V') 8066 MSG_PUTS_ATTR(_(" (vreplace)"), attr); 8067 #ifdef FEAT_RIGHTLEFT 8068 if (p_hkmap) 8069 MSG_PUTS_ATTR(_(" Hebrew"), attr); 8070 # ifdef FEAT_FKMAP 8071 if (p_fkmap) 8072 MSG_PUTS_ATTR(farsi_text_5, attr); 8073 # endif 8074 #endif 8075 #ifdef FEAT_KEYMAP 8076 if (State & LANGMAP) 8077 { 8078 # ifdef FEAT_ARABIC 8079 if (curwin->w_p_arab) 8080 MSG_PUTS_ATTR(_(" Arabic"), attr); 8081 else 8082 # endif 8083 MSG_PUTS_ATTR(_(" (lang)"), attr); 8084 } 8085 #endif 8086 if ((State & INSERT) && p_paste) 8087 MSG_PUTS_ATTR(_(" (paste)"), attr); 8088 8089 #ifdef FEAT_VISUAL 8090 if (VIsual_active) 8091 { 8092 char *p; 8093 8094 /* Don't concatenate separate words to avoid translation 8095 * problems. */ 8096 switch ((VIsual_select ? 4 : 0) 8097 + (VIsual_mode == Ctrl_V) * 2 8098 + (VIsual_mode == 'V')) 8099 { 8100 case 0: p = N_(" VISUAL"); break; 8101 case 1: p = N_(" VISUAL LINE"); break; 8102 case 2: p = N_(" VISUAL BLOCK"); break; 8103 case 4: p = N_(" SELECT"); break; 8104 case 5: p = N_(" SELECT LINE"); break; 8105 default: p = N_(" SELECT BLOCK"); break; 8106 } 8107 MSG_PUTS_ATTR(_(p), attr); 8108 } 8109 #endif 8110 MSG_PUTS_ATTR(" --", attr); 8111 } 8112 need_clear = TRUE; 8113 } 8114 if (Recording 8115 #ifdef FEAT_INS_EXPAND 8116 && edit_submode == NULL /* otherwise it gets too long */ 8117 #endif 8118 ) 8119 { 8120 MSG_PUTS_ATTR(_("recording"), attr); 8121 need_clear = TRUE; 8122 } 8123 if (need_clear || clear_cmdline) 8124 msg_clr_eos(); 8125 msg_didout = FALSE; /* overwrite this message */ 8126 length = msg_col; 8127 msg_col = 0; 8128 need_wait_return = nwr_save; /* never ask for hit-return for this */ 8129 } 8130 else if (clear_cmdline && msg_silent == 0) 8131 /* Clear the whole command line. Will reset "clear_cmdline". */ 8132 msg_clr_cmdline(); 8133 8134 #ifdef FEAT_CMDL_INFO 8135 # ifdef FEAT_VISUAL 8136 /* In Visual mode the size of the selected area must be redrawn. */ 8137 if (VIsual_active) 8138 clear_showcmd(); 8139 # endif 8140 8141 /* If the last window has no status line, the ruler is after the mode 8142 * message and must be redrawn */ 8143 if (redrawing() 8144 # ifdef FEAT_WINDOWS 8145 && lastwin->w_status_height == 0 8146 # endif 8147 ) 8148 win_redr_ruler(lastwin, TRUE); 8149 #endif 8150 redraw_cmdline = FALSE; 8151 clear_cmdline = FALSE; 8152 8153 return length; 8154 } 8155 8156 /* 8157 * Position for a mode message. 8158 */ 8159 static void 8160 msg_pos_mode() 8161 { 8162 msg_col = 0; 8163 msg_row = Rows - 1; 8164 } 8165 8166 /* 8167 * Delete mode message. Used when ESC is typed which is expected to end 8168 * Insert mode (but Insert mode didn't end yet!). 8169 */ 8170 void 8171 unshowmode(force) 8172 int force; 8173 { 8174 /* 8175 * Don't delete it right now, when not redrawing or insided a mapping. 8176 */ 8177 if (!redrawing() || (!force && char_avail() && !KeyTyped)) 8178 redraw_cmdline = TRUE; /* delete mode later */ 8179 else 8180 { 8181 msg_pos_mode(); 8182 if (Recording) 8183 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); 8184 msg_clr_eos(); 8185 } 8186 } 8187 8188 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) 8189 /* 8190 * Get the character to use in a status line. Get its attributes in "*attr". 8191 */ 8192 static int 8193 fillchar_status(attr, is_curwin) 8194 int *attr; 8195 int is_curwin; 8196 { 8197 int fill; 8198 if (is_curwin) 8199 { 8200 *attr = hl_attr(HLF_S); 8201 fill = fill_stl; 8202 } 8203 else 8204 { 8205 *attr = hl_attr(HLF_SNC); 8206 fill = fill_stlnc; 8207 } 8208 /* Use fill when there is highlighting, and highlighting of current 8209 * window differs, or the fillchars differ, or this is not the 8210 * current window */ 8211 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) 8212 || !is_curwin || firstwin == lastwin) 8213 || (fill_stl != fill_stlnc))) 8214 return fill; 8215 if (is_curwin) 8216 return '^'; 8217 return '='; 8218 } 8219 #endif 8220 8221 #ifdef FEAT_VERTSPLIT 8222 /* 8223 * Get the character to use in a separator between vertically split windows. 8224 * Get its attributes in "*attr". 8225 */ 8226 static int 8227 fillchar_vsep(attr) 8228 int *attr; 8229 { 8230 *attr = hl_attr(HLF_C); 8231 if (*attr == 0 && fill_vert == ' ') 8232 return '|'; 8233 else 8234 return fill_vert; 8235 } 8236 #endif 8237 8238 /* 8239 * Return TRUE if redrawing should currently be done. 8240 */ 8241 int 8242 redrawing() 8243 { 8244 return (!RedrawingDisabled 8245 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); 8246 } 8247 8248 /* 8249 * Return TRUE if printing messages should currently be done. 8250 */ 8251 int 8252 messaging() 8253 { 8254 return (!(p_lz && char_avail() && !KeyTyped)); 8255 } 8256 8257 /* 8258 * Show current status info in ruler and various other places 8259 * If always is FALSE, only show ruler if position has changed. 8260 */ 8261 void 8262 showruler(always) 8263 int always; 8264 { 8265 if (!always && !redrawing()) 8266 return; 8267 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) 8268 if (*p_stl && curwin->w_status_height) 8269 win_redr_custom(curwin, FALSE); 8270 else 8271 #endif 8272 #ifdef FEAT_CMDL_INFO 8273 win_redr_ruler(curwin, always); 8274 #endif 8275 8276 #ifdef FEAT_TITLE 8277 if (need_maketitle 8278 # ifdef FEAT_STL_OPT 8279 || (p_icon && (stl_syntax & STL_IN_ICON)) 8280 || (p_title && (stl_syntax & STL_IN_TITLE)) 8281 # endif 8282 ) 8283 maketitle(); 8284 #endif 8285 } 8286 8287 #ifdef FEAT_CMDL_INFO 8288 static void 8289 win_redr_ruler(wp, always) 8290 win_T *wp; 8291 int always; 8292 { 8293 char_u buffer[70]; 8294 int row; 8295 int fillchar; 8296 int attr; 8297 int empty_line = FALSE; 8298 colnr_T virtcol; 8299 int i; 8300 int o; 8301 #ifdef FEAT_VERTSPLIT 8302 int this_ru_col; 8303 int off = 0; 8304 int width = Columns; 8305 # define WITH_OFF(x) x 8306 # define WITH_WIDTH(x) x 8307 #else 8308 # define WITH_OFF(x) 0 8309 # define WITH_WIDTH(x) Columns 8310 # define this_ru_col ru_col 8311 #endif 8312 8313 /* If 'ruler' off or redrawing disabled, don't do anything */ 8314 if (!p_ru) 8315 return; 8316 8317 /* 8318 * Check if cursor.lnum is valid, since win_redr_ruler() may be called 8319 * after deleting lines, before cursor.lnum is corrected. 8320 */ 8321 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) 8322 return; 8323 8324 #ifdef FEAT_INS_EXPAND 8325 /* Don't draw the ruler while doing insert-completion, it might overwrite 8326 * the (long) mode message. */ 8327 # ifdef FEAT_WINDOWS 8328 if (wp == lastwin && lastwin->w_status_height == 0) 8329 # endif 8330 if (edit_submode != NULL) 8331 return; 8332 #endif 8333 8334 #ifdef FEAT_STL_OPT 8335 if (*p_ruf) 8336 { 8337 win_redr_custom(wp, TRUE); 8338 return; 8339 } 8340 #endif 8341 8342 /* 8343 * Check if not in Insert mode and the line is empty (will show "0-1"). 8344 */ 8345 if (!(State & INSERT) 8346 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) 8347 empty_line = TRUE; 8348 8349 /* 8350 * Only draw the ruler when something changed. 8351 */ 8352 validate_virtcol_win(wp); 8353 if ( redraw_cmdline 8354 || always 8355 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum 8356 || wp->w_cursor.col != wp->w_ru_cursor.col 8357 || wp->w_virtcol != wp->w_ru_virtcol 8358 #ifdef FEAT_VIRTUALEDIT 8359 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd 8360 #endif 8361 || wp->w_topline != wp->w_ru_topline 8362 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count 8363 #ifdef FEAT_DIFF 8364 || wp->w_topfill != wp->w_ru_topfill 8365 #endif 8366 || empty_line != wp->w_ru_empty) 8367 { 8368 cursor_off(); 8369 #ifdef FEAT_WINDOWS 8370 if (wp->w_status_height) 8371 { 8372 row = W_WINROW(wp) + wp->w_height; 8373 fillchar = fillchar_status(&attr, wp == curwin); 8374 # ifdef FEAT_VERTSPLIT 8375 off = W_WINCOL(wp); 8376 width = W_WIDTH(wp); 8377 # endif 8378 } 8379 else 8380 #endif 8381 { 8382 row = Rows - 1; 8383 fillchar = ' '; 8384 attr = 0; 8385 #ifdef FEAT_VERTSPLIT 8386 width = Columns; 8387 off = 0; 8388 #endif 8389 } 8390 8391 /* In list mode virtcol needs to be recomputed */ 8392 virtcol = wp->w_virtcol; 8393 if (wp->w_p_list && lcs_tab1 == NUL) 8394 { 8395 wp->w_p_list = FALSE; 8396 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); 8397 wp->w_p_list = TRUE; 8398 } 8399 8400 /* 8401 * Some sprintfs return the length, some return a pointer. 8402 * To avoid portability problems we use strlen() here. 8403 */ 8404 sprintf((char *)buffer, "%ld,", 8405 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) 8406 ? 0L 8407 : (long)(wp->w_cursor.lnum)); 8408 col_print(buffer + STRLEN(buffer), 8409 empty_line ? 0 : (int)wp->w_cursor.col + 1, 8410 (int)virtcol + 1); 8411 8412 /* 8413 * Add a "50%" if there is room for it. 8414 * On the last line, don't print in the last column (scrolls the 8415 * screen up on some terminals). 8416 */ 8417 i = (int)STRLEN(buffer); 8418 get_rel_pos(wp, buffer + i + 1); 8419 o = i + vim_strsize(buffer + i + 1); 8420 #ifdef FEAT_WINDOWS 8421 if (wp->w_status_height == 0) /* can't use last char of screen */ 8422 #endif 8423 ++o; 8424 #ifdef FEAT_VERTSPLIT 8425 this_ru_col = ru_col - (Columns - width); 8426 if (this_ru_col < 0) 8427 this_ru_col = 0; 8428 #endif 8429 /* Never use more than half the window/screen width, leave the other 8430 * half for the filename. */ 8431 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) 8432 this_ru_col = (WITH_WIDTH(width) + 1) / 2; 8433 if (this_ru_col + o < WITH_WIDTH(width)) 8434 { 8435 while (this_ru_col + o < WITH_WIDTH(width)) 8436 { 8437 #ifdef FEAT_MBYTE 8438 if (has_mbyte) 8439 i += (*mb_char2bytes)(fillchar, buffer + i); 8440 else 8441 #endif 8442 buffer[i++] = fillchar; 8443 ++o; 8444 } 8445 get_rel_pos(wp, buffer + i); 8446 } 8447 /* Truncate at window boundary. */ 8448 #ifdef FEAT_MBYTE 8449 if (has_mbyte) 8450 { 8451 o = 0; 8452 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len_check)(buffer + i)) 8453 { 8454 o += (*mb_ptr2cells)(buffer + i); 8455 if (this_ru_col + o > WITH_WIDTH(width)) 8456 { 8457 buffer[i] = NUL; 8458 break; 8459 } 8460 } 8461 } 8462 else 8463 #endif 8464 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) 8465 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; 8466 8467 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); 8468 i = redraw_cmdline; 8469 screen_fill(row, row + 1, 8470 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), 8471 (int)(WITH_OFF(off) + WITH_WIDTH(width)), 8472 fillchar, fillchar, attr); 8473 /* don't redraw the cmdline because of showing the ruler */ 8474 redraw_cmdline = i; 8475 wp->w_ru_cursor = wp->w_cursor; 8476 wp->w_ru_virtcol = wp->w_virtcol; 8477 wp->w_ru_empty = empty_line; 8478 wp->w_ru_topline = wp->w_topline; 8479 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; 8480 #ifdef FEAT_DIFF 8481 wp->w_ru_topfill = wp->w_topfill; 8482 #endif 8483 } 8484 } 8485 #endif 8486 8487 #if defined(FEAT_LINEBREAK) || defined(PROTO) 8488 /* 8489 * Return the width of the 'number' column. 8490 * Zero when 'number' isn't set. 8491 * Otherwise it depends on 'numberwidth' and the line count. 8492 */ 8493 int 8494 number_width(wp) 8495 win_T *wp; 8496 { 8497 int n; 8498 linenr_T lnum; 8499 8500 if (!wp->w_p_nu) 8501 return 0; 8502 8503 lnum = wp->w_buffer->b_ml.ml_line_count; 8504 if (lnum == wp->w_nrwidth_line_count) 8505 return wp->w_nrwidth_width; 8506 wp->w_nrwidth_line_count = lnum; 8507 8508 n = 0; 8509 do 8510 { 8511 lnum /= 10; 8512 ++n; 8513 } while (lnum > 0); 8514 8515 /* 'numberwidth' gives the minimal width plus one */ 8516 if (n < wp->w_p_nuw - 1) 8517 n = wp->w_p_nuw - 1; 8518 8519 wp->w_nrwidth_width = n; 8520 return n; 8521 } 8522 #endif 8523