Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 113 | colnr_T startcol; /* in win_line() points to char where HL starts */ |
| 114 | colnr_T endcol; /* in win_line() points to char where HL ends */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 115 | } match_T; |
| 116 | |
| 117 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 118 | static match_T match_hl[3]; /* used for ":match" highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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)); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 131 | static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 137 | static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 146 | #ifdef FEAT_VERTSPLIT |
| 147 | static void draw_vsep_win __ARGS((win_T *wp, int row)); |
| 148 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 149 | #ifdef FEAT_STL_OPT |
| 150 | static void redraw_custum_statusline __ARGS((win_T *wp)); |
| 151 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | static void msg_pos_mode __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 173 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 174 | static void draw_tabline __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 175 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 176 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 177 | static int fillchar_status __ARGS((int *attr, int is_curwin)); |
| 178 | #endif |
| 179 | #ifdef FEAT_VERTSPLIT |
| 180 | static int fillchar_vsep __ARGS((int *attr)); |
| 181 | #endif |
| 182 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 183 | static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | #endif |
| 185 | #ifdef FEAT_CMDL_INFO |
| 186 | static void win_redr_ruler __ARGS((win_T *wp, int always)); |
| 187 | #endif |
| 188 | |
| 189 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 190 | /* Ugly global: overrule attribute used by screen_char() */ |
| 191 | static int screen_char_attr = 0; |
| 192 | #endif |
| 193 | |
| 194 | /* |
| 195 | * Redraw the current window later, with update_screen(type). |
| 196 | * Set must_redraw only if not already set to a higher value. |
| 197 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 198 | */ |
| 199 | void |
| 200 | redraw_later(type) |
| 201 | int type; |
| 202 | { |
| 203 | redraw_win_later(curwin, type); |
| 204 | } |
| 205 | |
| 206 | void |
| 207 | redraw_win_later(wp, type) |
| 208 | win_T *wp; |
| 209 | int type; |
| 210 | { |
| 211 | if (wp->w_redr_type < type) |
| 212 | { |
| 213 | wp->w_redr_type = type; |
| 214 | if (type >= NOT_VALID) |
| 215 | wp->w_lines_valid = 0; |
| 216 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 217 | must_redraw = type; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 223 | * after executing a shell command that messes up the screen. |
| 224 | */ |
| 225 | void |
| 226 | redraw_later_clear() |
| 227 | { |
| 228 | redraw_all_later(CLEAR); |
| 229 | screen_attr = HL_BOLD | HL_UNDERLINE; |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Mark all windows to be redrawn later. |
| 234 | */ |
| 235 | void |
| 236 | redraw_all_later(type) |
| 237 | int type; |
| 238 | { |
| 239 | win_T *wp; |
| 240 | |
| 241 | FOR_ALL_WINDOWS(wp) |
| 242 | { |
| 243 | redraw_win_later(wp, type); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 248 | * Mark all windows that are editing the current buffer to be updated later. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 249 | */ |
| 250 | void |
| 251 | redraw_curbuf_later(type) |
| 252 | int type; |
| 253 | { |
| 254 | redraw_buf_later(curbuf, type); |
| 255 | } |
| 256 | |
| 257 | void |
| 258 | redraw_buf_later(buf, type) |
| 259 | buf_T *buf; |
| 260 | int type; |
| 261 | { |
| 262 | win_T *wp; |
| 263 | |
| 264 | FOR_ALL_WINDOWS(wp) |
| 265 | { |
| 266 | if (wp->w_buffer == buf) |
| 267 | redraw_win_later(wp, type); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Changed something in the current window, at buffer line "lnum", that |
| 273 | * requires that line and possibly other lines to be redrawn. |
| 274 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 275 | * Used to remove the "$" from a change command. |
| 276 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 277 | * may become invalid and the whole window will have to be redrawn. |
| 278 | */ |
| 279 | /*ARGSUSED*/ |
| 280 | void |
| 281 | redrawWinline(lnum, invalid) |
| 282 | linenr_T lnum; |
| 283 | int invalid; /* window line height is invalid now */ |
| 284 | { |
| 285 | #ifdef FEAT_FOLDING |
| 286 | int i; |
| 287 | #endif |
| 288 | |
| 289 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 290 | curwin->w_redraw_top = lnum; |
| 291 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 292 | curwin->w_redraw_bot = lnum; |
| 293 | redraw_later(VALID); |
| 294 | |
| 295 | #ifdef FEAT_FOLDING |
| 296 | if (invalid) |
| 297 | { |
| 298 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 299 | i = find_wl_entry(curwin, lnum); |
| 300 | if (i >= 0) |
| 301 | curwin->w_lines[i].wl_valid = FALSE; |
| 302 | } |
| 303 | #endif |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * update all windows that are editing the current buffer |
| 308 | */ |
| 309 | void |
| 310 | update_curbuf(type) |
| 311 | int type; |
| 312 | { |
| 313 | redraw_curbuf_later(type); |
| 314 | update_screen(type); |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * update_screen() |
| 319 | * |
| 320 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 321 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 322 | */ |
| 323 | void |
| 324 | update_screen(type) |
| 325 | int type; |
| 326 | { |
| 327 | win_T *wp; |
| 328 | static int did_intro = FALSE; |
| 329 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 330 | int did_one; |
| 331 | #endif |
| 332 | |
| 333 | if (!screen_valid(TRUE)) |
| 334 | return; |
| 335 | |
| 336 | if (must_redraw) |
| 337 | { |
| 338 | if (type < must_redraw) /* use maximal type */ |
| 339 | type = must_redraw; |
| 340 | must_redraw = 0; |
| 341 | } |
| 342 | |
| 343 | /* Need to update w_lines[]. */ |
| 344 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 345 | type = NOT_VALID; |
| 346 | |
| 347 | if (!redrawing()) |
| 348 | { |
| 349 | redraw_later(type); /* remember type for next time */ |
| 350 | must_redraw = type; |
| 351 | if (type > INVERTED_ALL) |
| 352 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | updating_screen = TRUE; |
| 357 | #ifdef FEAT_SYN_HL |
| 358 | ++display_tick; /* let syntax code know we're in a next round of |
| 359 | * display updating */ |
| 360 | #endif |
| 361 | |
| 362 | /* |
| 363 | * if the screen was scrolled up when displaying a message, scroll it down |
| 364 | */ |
| 365 | if (msg_scrolled) |
| 366 | { |
| 367 | clear_cmdline = TRUE; |
| 368 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 369 | type = CLEAR; |
| 370 | else if (type != CLEAR) |
| 371 | { |
| 372 | check_for_delay(FALSE); |
| 373 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 374 | type = CLEAR; |
| 375 | FOR_ALL_WINDOWS(wp) |
| 376 | { |
| 377 | if (W_WINROW(wp) < msg_scrolled) |
| 378 | { |
| 379 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 380 | && wp->w_redr_type < REDRAW_TOP |
| 381 | && wp->w_lines_valid > 0 |
| 382 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 383 | { |
| 384 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 385 | wp->w_redr_type = REDRAW_TOP; |
| 386 | } |
| 387 | else |
| 388 | { |
| 389 | wp->w_redr_type = NOT_VALID; |
| 390 | #ifdef FEAT_WINDOWS |
| 391 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 392 | <= msg_scrolled) |
| 393 | wp->w_redr_status = TRUE; |
| 394 | #endif |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 399 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 400 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 401 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 402 | } |
| 403 | msg_scrolled = 0; |
| 404 | need_wait_return = FALSE; |
| 405 | } |
| 406 | |
| 407 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 408 | compute_cmdrow(); |
| 409 | |
| 410 | /* Check for changed highlighting */ |
| 411 | if (need_highlight_changed) |
| 412 | highlight_changed(); |
| 413 | |
| 414 | if (type == CLEAR) /* first clear screen */ |
| 415 | { |
| 416 | screenclear(); /* will reset clear_cmdline */ |
| 417 | type = NOT_VALID; |
| 418 | } |
| 419 | |
| 420 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 421 | check_for_delay(FALSE); |
| 422 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 423 | #ifdef FEAT_LINEBREAK |
| 424 | /* Force redraw when width of 'number' column changes. */ |
| 425 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 426 | && curwin->w_nrwidth != (curwin->w_p_nu ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 427 | curwin->w_redr_type = NOT_VALID; |
| 428 | #endif |
| 429 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 430 | /* |
| 431 | * Only start redrawing if there is really something to do. |
| 432 | */ |
| 433 | if (type == INVERTED) |
| 434 | update_curswant(); |
| 435 | if (curwin->w_redr_type < type |
| 436 | && !((type == VALID |
| 437 | && curwin->w_lines[0].wl_valid |
| 438 | #ifdef FEAT_DIFF |
| 439 | && curwin->w_topfill == curwin->w_old_topfill |
| 440 | && curwin->w_botfill == curwin->w_old_botfill |
| 441 | #endif |
| 442 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
| 443 | #ifdef FEAT_VISUAL |
| 444 | || (type == INVERTED |
| 445 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 446 | && curwin->w_old_visual_mode == VIsual_mode |
| 447 | && (curwin->w_valid & VALID_VIRTCOL) |
| 448 | && curwin->w_old_curswant == curwin->w_curswant) |
| 449 | #endif |
| 450 | )) |
| 451 | curwin->w_redr_type = type; |
| 452 | |
| 453 | #ifdef FEAT_SYN_HL |
| 454 | /* |
| 455 | * Correct stored syntax highlighting info for changes in each displayed |
| 456 | * buffer. Each buffer must only be done once. |
| 457 | */ |
| 458 | FOR_ALL_WINDOWS(wp) |
| 459 | { |
| 460 | if (wp->w_buffer->b_mod_set) |
| 461 | { |
| 462 | # ifdef FEAT_WINDOWS |
| 463 | win_T *wwp; |
| 464 | |
| 465 | /* Check if we already did this buffer. */ |
| 466 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 467 | if (wwp->w_buffer == wp->w_buffer) |
| 468 | break; |
| 469 | # endif |
| 470 | if ( |
| 471 | # ifdef FEAT_WINDOWS |
| 472 | wwp == wp && |
| 473 | # endif |
| 474 | syntax_present(wp->w_buffer)) |
| 475 | syn_stack_apply_changes(wp->w_buffer); |
| 476 | } |
| 477 | } |
| 478 | #endif |
| 479 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 480 | #ifdef FEAT_WINDOWS |
| 481 | /* Redraw the tab pages line if needed. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 482 | if (redraw_tabline || type >= NOT_VALID) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 483 | draw_tabline(); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 484 | #endif |
| 485 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 486 | /* |
| 487 | * Go from top to bottom through the windows, redrawing the ones that need |
| 488 | * it. |
| 489 | */ |
| 490 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 491 | did_one = FALSE; |
| 492 | #endif |
| 493 | #ifdef FEAT_SEARCH_EXTRA |
| 494 | search_hl.rm.regprog = NULL; |
| 495 | #endif |
| 496 | FOR_ALL_WINDOWS(wp) |
| 497 | { |
| 498 | if (wp->w_redr_type != 0) |
| 499 | { |
| 500 | cursor_off(); |
| 501 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 502 | if (!did_one) |
| 503 | { |
| 504 | did_one = TRUE; |
| 505 | # ifdef FEAT_SEARCH_EXTRA |
| 506 | start_search_hl(); |
| 507 | # endif |
| 508 | # ifdef FEAT_CLIPBOARD |
| 509 | /* When Visual area changed, may have to update selection. */ |
| 510 | if (clip_star.available && clip_isautosel()) |
| 511 | clip_update_selection(); |
| 512 | # endif |
| 513 | #ifdef FEAT_GUI |
| 514 | /* Remove the cursor before starting to do anything, because |
| 515 | * scrolling may make it difficult to redraw the text under |
| 516 | * it. */ |
| 517 | if (gui.in_use) |
| 518 | gui_undraw_cursor(); |
| 519 | #endif |
| 520 | } |
| 521 | #endif |
| 522 | win_update(wp); |
| 523 | } |
| 524 | |
| 525 | #ifdef FEAT_WINDOWS |
| 526 | /* redraw status line after the window to minimize cursor movement */ |
| 527 | if (wp->w_redr_status) |
| 528 | { |
| 529 | cursor_off(); |
| 530 | win_redr_status(wp); |
| 531 | } |
| 532 | #endif |
| 533 | } |
| 534 | #if defined(FEAT_SEARCH_EXTRA) |
| 535 | end_search_hl(); |
| 536 | #endif |
| 537 | |
| 538 | #ifdef FEAT_WINDOWS |
| 539 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 540 | * than going through all buffers (there could be many buffers). */ |
| 541 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 542 | wp->w_buffer->b_mod_set = FALSE; |
| 543 | #else |
| 544 | curbuf->b_mod_set = FALSE; |
| 545 | #endif |
| 546 | |
| 547 | updating_screen = FALSE; |
| 548 | #ifdef FEAT_GUI |
| 549 | gui_may_resize_shell(); |
| 550 | #endif |
| 551 | |
| 552 | /* Clear or redraw the command line. Done last, because scrolling may |
| 553 | * mess up the command line. */ |
| 554 | if (clear_cmdline || redraw_cmdline) |
| 555 | showmode(); |
| 556 | |
| 557 | /* May put up an introductory message when not editing a file */ |
| 558 | if (!did_intro && bufempty() |
| 559 | && curbuf->b_fname == NULL |
| 560 | #ifdef FEAT_WINDOWS |
| 561 | && firstwin->w_next == NULL |
| 562 | #endif |
| 563 | && vim_strchr(p_shm, SHM_INTRO) == NULL) |
| 564 | intro_message(FALSE); |
| 565 | did_intro = TRUE; |
| 566 | |
| 567 | #ifdef FEAT_GUI |
| 568 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 569 | * done. */ |
| 570 | if (gui.in_use) |
| 571 | { |
| 572 | out_flush(); /* required before updating the cursor */ |
| 573 | if (did_one) |
| 574 | gui_update_cursor(FALSE, FALSE); |
| 575 | gui_update_scrollbars(FALSE); |
| 576 | } |
| 577 | #endif |
| 578 | } |
| 579 | |
| 580 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
| 581 | static void update_prepare __ARGS((void)); |
| 582 | static void update_finish __ARGS((void)); |
| 583 | |
| 584 | /* |
| 585 | * Prepare for updating one or more windows. |
| 586 | */ |
| 587 | static void |
| 588 | update_prepare() |
| 589 | { |
| 590 | cursor_off(); |
| 591 | updating_screen = TRUE; |
| 592 | #ifdef FEAT_GUI |
| 593 | /* Remove the cursor before starting to do anything, because scrolling may |
| 594 | * make it difficult to redraw the text under it. */ |
| 595 | if (gui.in_use) |
| 596 | gui_undraw_cursor(); |
| 597 | #endif |
| 598 | #ifdef FEAT_SEARCH_EXTRA |
| 599 | start_search_hl(); |
| 600 | #endif |
| 601 | } |
| 602 | |
| 603 | /* |
| 604 | * Finish updating one or more windows. |
| 605 | */ |
| 606 | static void |
| 607 | update_finish() |
| 608 | { |
| 609 | if (redraw_cmdline) |
| 610 | showmode(); |
| 611 | |
| 612 | # ifdef FEAT_SEARCH_EXTRA |
| 613 | end_search_hl(); |
| 614 | # endif |
| 615 | |
| 616 | updating_screen = FALSE; |
| 617 | |
| 618 | # ifdef FEAT_GUI |
| 619 | gui_may_resize_shell(); |
| 620 | |
| 621 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 622 | * done. */ |
| 623 | if (gui.in_use) |
| 624 | { |
| 625 | out_flush(); /* required before updating the cursor */ |
| 626 | gui_update_cursor(FALSE, FALSE); |
| 627 | gui_update_scrollbars(FALSE); |
| 628 | } |
| 629 | # endif |
| 630 | } |
| 631 | #endif |
| 632 | |
| 633 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 634 | void |
| 635 | update_debug_sign(buf, lnum) |
| 636 | buf_T *buf; |
| 637 | linenr_T lnum; |
| 638 | { |
| 639 | win_T *wp; |
| 640 | int doit = FALSE; |
| 641 | |
| 642 | # ifdef FEAT_FOLDING |
| 643 | win_foldinfo.fi_level = 0; |
| 644 | # endif |
| 645 | |
| 646 | /* update/delete a specific mark */ |
| 647 | FOR_ALL_WINDOWS(wp) |
| 648 | { |
| 649 | if (buf != NULL && lnum > 0) |
| 650 | { |
| 651 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 652 | && lnum < wp->w_botline) |
| 653 | { |
| 654 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 655 | wp->w_redraw_top = lnum; |
| 656 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 657 | wp->w_redraw_bot = lnum; |
| 658 | redraw_win_later(wp, VALID); |
| 659 | } |
| 660 | } |
| 661 | else |
| 662 | redraw_win_later(wp, VALID); |
| 663 | if (wp->w_redr_type != 0) |
| 664 | doit = TRUE; |
| 665 | } |
| 666 | |
| 667 | if (!doit) |
| 668 | return; |
| 669 | |
| 670 | /* update all windows that need updating */ |
| 671 | update_prepare(); |
| 672 | |
| 673 | # ifdef FEAT_WINDOWS |
| 674 | for (wp = firstwin; wp; wp = wp->w_next) |
| 675 | { |
| 676 | if (wp->w_redr_type != 0) |
| 677 | win_update(wp); |
| 678 | if (wp->w_redr_status) |
| 679 | win_redr_status(wp); |
| 680 | } |
| 681 | # else |
| 682 | if (curwin->w_redr_type != 0) |
| 683 | win_update(curwin); |
| 684 | # endif |
| 685 | |
| 686 | update_finish(); |
| 687 | } |
| 688 | #endif |
| 689 | |
| 690 | |
| 691 | #if defined(FEAT_GUI) || defined(PROTO) |
| 692 | /* |
| 693 | * Update a single window, its status line and maybe the command line msg. |
| 694 | * Used for the GUI scrollbar. |
| 695 | */ |
| 696 | void |
| 697 | updateWindow(wp) |
| 698 | win_T *wp; |
| 699 | { |
| 700 | update_prepare(); |
| 701 | |
| 702 | #ifdef FEAT_CLIPBOARD |
| 703 | /* When Visual area changed, may have to update selection. */ |
| 704 | if (clip_star.available && clip_isautosel()) |
| 705 | clip_update_selection(); |
| 706 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 707 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 708 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 709 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 710 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 711 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 712 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 713 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 714 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 715 | if (wp->w_redr_status |
| 716 | # ifdef FEAT_CMDL_INFO |
| 717 | || p_ru |
| 718 | # endif |
| 719 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 720 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 721 | # endif |
| 722 | ) |
| 723 | win_redr_status(wp); |
| 724 | #endif |
| 725 | |
| 726 | update_finish(); |
| 727 | } |
| 728 | #endif |
| 729 | |
| 730 | /* |
| 731 | * Update a single window. |
| 732 | * |
| 733 | * This may cause the windows below it also to be redrawn (when clearing the |
| 734 | * screen or scrolling lines). |
| 735 | * |
| 736 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 737 | * implies the one below it. |
| 738 | * NOT_VALID redraw the whole window |
| 739 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 740 | * INVERTED redraw the changed part of the Visual area |
| 741 | * INVERTED_ALL redraw the whole Visual area |
| 742 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 743 | * 2. update lines at the top when scrolled down |
| 744 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 745 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 746 | * b_mod_top and b_mod_bot. |
| 747 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 748 | * wp->w_redraw_top and wp->w_redr_bot. |
| 749 | * - continue redrawing when syntax status is invalid. |
| 750 | * 4. if scrolled up, update lines at the bottom. |
| 751 | * This results in three areas that may need updating: |
| 752 | * top: from first row to top_end (when scrolled down) |
| 753 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 754 | * bot: from bot_start to last row (when scrolled up) |
| 755 | */ |
| 756 | static void |
| 757 | win_update(wp) |
| 758 | win_T *wp; |
| 759 | { |
| 760 | buf_T *buf = wp->w_buffer; |
| 761 | int type; |
| 762 | int top_end = 0; /* Below last row of the top area that needs |
| 763 | updating. 0 when no top area updating. */ |
| 764 | int mid_start = 999;/* first row of the mid area that needs |
| 765 | updating. 999 when no mid area updating. */ |
| 766 | int mid_end = 0; /* Below last row of the mid area that needs |
| 767 | updating. 0 when no mid area updating. */ |
| 768 | int bot_start = 999;/* first row of the bot area that needs |
| 769 | updating. 999 when no bot area updating */ |
| 770 | #ifdef FEAT_VISUAL |
| 771 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 772 | w_topline got smaller a bit */ |
| 773 | #endif |
| 774 | #ifdef FEAT_SEARCH_EXTRA |
| 775 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 776 | #endif |
| 777 | |
| 778 | int row; /* current window row to display */ |
| 779 | linenr_T lnum; /* current buffer lnum to display */ |
| 780 | int idx; /* current index in w_lines[] */ |
| 781 | int srow; /* starting row of the current line */ |
| 782 | |
| 783 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 784 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 785 | int i; |
| 786 | long j; |
| 787 | static int recursive = FALSE; /* being called recursively */ |
| 788 | int old_botline = wp->w_botline; |
| 789 | #ifdef FEAT_FOLDING |
| 790 | long fold_count; |
| 791 | #endif |
| 792 | #ifdef FEAT_SYN_HL |
| 793 | /* remember what happened to the previous line, to know if |
| 794 | * check_visual_highlight() can be used */ |
| 795 | #define DID_NONE 1 /* didn't update a line */ |
| 796 | #define DID_LINE 2 /* updated a normal line */ |
| 797 | #define DID_FOLD 3 /* updated a folded line */ |
| 798 | int did_update = DID_NONE; |
| 799 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 800 | #endif |
| 801 | linenr_T mod_top = 0; |
| 802 | linenr_T mod_bot = 0; |
| 803 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 804 | int save_got_int; |
| 805 | #endif |
| 806 | |
| 807 | type = wp->w_redr_type; |
| 808 | |
| 809 | if (type == NOT_VALID) |
| 810 | { |
| 811 | #ifdef FEAT_WINDOWS |
| 812 | wp->w_redr_status = TRUE; |
| 813 | #endif |
| 814 | wp->w_lines_valid = 0; |
| 815 | } |
| 816 | |
| 817 | /* Window is zero-height: nothing to draw. */ |
| 818 | if (wp->w_height == 0) |
| 819 | { |
| 820 | wp->w_redr_type = 0; |
| 821 | return; |
| 822 | } |
| 823 | |
| 824 | #ifdef FEAT_VERTSPLIT |
| 825 | /* Window is zero-width: Only need to draw the separator. */ |
| 826 | if (wp->w_width == 0) |
| 827 | { |
| 828 | /* draw the vertical separator right of this window */ |
| 829 | draw_vsep_win(wp, 0); |
| 830 | wp->w_redr_type = 0; |
| 831 | return; |
| 832 | } |
| 833 | #endif |
| 834 | |
| 835 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 836 | /* Setup for ":match" and 'hlsearch' highlighting. Disable any previous |
| 837 | * match */ |
| 838 | for (i = 0; i < 3; ++i) |
| 839 | { |
| 840 | match_hl[i].rm = wp->w_match[i]; |
| 841 | if (wp->w_match_id[i] == 0) |
| 842 | match_hl[i].attr = 0; |
| 843 | else |
| 844 | match_hl[i].attr = syn_id2attr(wp->w_match_id[i]); |
| 845 | match_hl[i].buf = buf; |
| 846 | match_hl[i].lnum = 0; |
| 847 | match_hl[i].first_lnum = 0; |
| 848 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 849 | search_hl.buf = buf; |
| 850 | search_hl.lnum = 0; |
| 851 | search_hl.first_lnum = 0; |
| 852 | #endif |
| 853 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 854 | #ifdef FEAT_LINEBREAK |
| 855 | /* Force redraw when width of 'number' column changes. */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 856 | i = wp->w_p_nu ? number_width(wp) : 0; |
| 857 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 858 | { |
| 859 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 860 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 861 | } |
| 862 | else |
| 863 | #endif |
| 864 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 865 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 866 | { |
| 867 | /* |
| 868 | * When there are both inserted/deleted lines and specific lines to be |
| 869 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 870 | * everything (only happens when redrawing is off for while). |
| 871 | */ |
| 872 | type = NOT_VALID; |
| 873 | } |
| 874 | else |
| 875 | { |
| 876 | /* |
| 877 | * Set mod_top to the first line that needs displaying because of |
| 878 | * changes. Set mod_bot to the first line after the changes. |
| 879 | */ |
| 880 | mod_top = wp->w_redraw_top; |
| 881 | if (wp->w_redraw_bot != 0) |
| 882 | mod_bot = wp->w_redraw_bot + 1; |
| 883 | else |
| 884 | mod_bot = 0; |
| 885 | wp->w_redraw_top = 0; /* reset for next time */ |
| 886 | wp->w_redraw_bot = 0; |
| 887 | if (buf->b_mod_set) |
| 888 | { |
| 889 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 890 | { |
| 891 | mod_top = buf->b_mod_top; |
| 892 | #ifdef FEAT_SYN_HL |
| 893 | /* Need to redraw lines above the change that may be included |
| 894 | * in a pattern match. */ |
| 895 | if (syntax_present(buf)) |
| 896 | { |
| 897 | mod_top -= buf->b_syn_sync_linebreaks; |
| 898 | if (mod_top < 1) |
| 899 | mod_top = 1; |
| 900 | } |
| 901 | #endif |
| 902 | } |
| 903 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 904 | mod_bot = buf->b_mod_bot; |
| 905 | |
| 906 | #ifdef FEAT_SEARCH_EXTRA |
| 907 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 908 | * change in one line may make the Search highlighting in a |
| 909 | * previous line invalid. Simple solution: redraw all visible |
| 910 | * lines above the change. |
| 911 | * Same for a ":match" pattern. |
| 912 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 913 | if (search_hl.rm.regprog != NULL |
| 914 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 915 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 916 | else |
| 917 | for (i = 0; i < 3; ++i) |
| 918 | if (match_hl[i].rm.regprog != NULL |
| 919 | && re_multiline(match_hl[i].rm.regprog)) |
| 920 | { |
| 921 | top_to_mod = TRUE; |
| 922 | break; |
| 923 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 924 | #endif |
| 925 | } |
| 926 | #ifdef FEAT_FOLDING |
| 927 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 928 | { |
| 929 | linenr_T lnumt, lnumb; |
| 930 | |
| 931 | /* |
| 932 | * A change in a line can cause lines above it to become folded or |
| 933 | * unfolded. Find the top most buffer line that may be affected. |
| 934 | * If the line was previously folded and displayed, get the first |
| 935 | * line of that fold. If the line is folded now, get the first |
| 936 | * folded line. Use the minimum of these two. |
| 937 | */ |
| 938 | |
| 939 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 940 | * the line below it. If there is no valid entry, use w_topline. |
| 941 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 942 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 943 | lnumt = wp->w_topline; |
| 944 | lnumb = MAXLNUM; |
| 945 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 946 | if (wp->w_lines[i].wl_valid) |
| 947 | { |
| 948 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 949 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 950 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 951 | { |
| 952 | lnumb = wp->w_lines[i].wl_lnum; |
| 953 | /* When there is a fold column it might need updating |
| 954 | * in the next line ("J" just above an open fold). */ |
| 955 | if (wp->w_p_fdc > 0) |
| 956 | ++lnumb; |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 961 | if (mod_top > lnumt) |
| 962 | mod_top = lnumt; |
| 963 | |
| 964 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 965 | --mod_bot; |
| 966 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 967 | ++mod_bot; |
| 968 | if (mod_bot < lnumb) |
| 969 | mod_bot = lnumb; |
| 970 | } |
| 971 | #endif |
| 972 | |
| 973 | /* When a change starts above w_topline and the end is below |
| 974 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 975 | * If the end of the change is above w_topline: do like no change was |
| 976 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 977 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 978 | { |
| 979 | if (mod_bot > wp->w_topline) |
| 980 | mod_top = wp->w_topline; |
| 981 | #ifdef FEAT_SYN_HL |
| 982 | else if (syntax_present(buf)) |
| 983 | top_end = 1; |
| 984 | #endif |
| 985 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 986 | |
| 987 | /* When line numbers are displayed need to redraw all lines below |
| 988 | * inserted/deleted lines. */ |
| 989 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 990 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /* |
| 994 | * When only displaying the lines at the top, set top_end. Used when |
| 995 | * window has scrolled down for msg_scrolled. |
| 996 | */ |
| 997 | if (type == REDRAW_TOP) |
| 998 | { |
| 999 | j = 0; |
| 1000 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1001 | { |
| 1002 | j += wp->w_lines[i].wl_size; |
| 1003 | if (j >= wp->w_upd_rows) |
| 1004 | { |
| 1005 | top_end = j; |
| 1006 | break; |
| 1007 | } |
| 1008 | } |
| 1009 | if (top_end == 0) |
| 1010 | /* not found (cannot happen?): redraw everything */ |
| 1011 | type = NOT_VALID; |
| 1012 | else |
| 1013 | /* top area defined, the rest is VALID */ |
| 1014 | type = VALID; |
| 1015 | } |
| 1016 | |
| 1017 | /* |
| 1018 | * If there are no changes on the screen that require a complete redraw, |
| 1019 | * handle three cases: |
| 1020 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1021 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1022 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1023 | * w_lines[] that needs updating. |
| 1024 | */ |
| 1025 | if ((type == VALID || type == INVERTED || type == INVERTED_ALL) |
| 1026 | #ifdef FEAT_DIFF |
| 1027 | && !wp->w_botfill && !wp->w_old_botfill |
| 1028 | #endif |
| 1029 | ) |
| 1030 | { |
| 1031 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1032 | { |
| 1033 | /* |
| 1034 | * w_topline is the first changed line, the scrolling will be done |
| 1035 | * further down. |
| 1036 | */ |
| 1037 | } |
| 1038 | else if (wp->w_lines[0].wl_valid |
| 1039 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1040 | #ifdef FEAT_DIFF |
| 1041 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1042 | && wp->w_topfill > wp->w_old_topfill) |
| 1043 | #endif |
| 1044 | )) |
| 1045 | { |
| 1046 | /* |
| 1047 | * New topline is above old topline: May scroll down. |
| 1048 | */ |
| 1049 | #ifdef FEAT_FOLDING |
| 1050 | if (hasAnyFolding(wp)) |
| 1051 | { |
| 1052 | linenr_T ln; |
| 1053 | |
| 1054 | /* count the number of lines we are off, counting a sequence |
| 1055 | * of folded lines as one */ |
| 1056 | j = 0; |
| 1057 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1058 | { |
| 1059 | ++j; |
| 1060 | if (j >= wp->w_height - 2) |
| 1061 | break; |
| 1062 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1063 | } |
| 1064 | } |
| 1065 | else |
| 1066 | #endif |
| 1067 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1068 | if (j < wp->w_height - 2) /* not too far off */ |
| 1069 | { |
| 1070 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1071 | #ifdef FEAT_DIFF |
| 1072 | /* insert extra lines for previously invisible filler lines */ |
| 1073 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1074 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1075 | - wp->w_old_topfill; |
| 1076 | #endif |
| 1077 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1078 | { |
| 1079 | /* |
| 1080 | * Try to insert the correct number of lines. |
| 1081 | * If not the last window, delete the lines at the bottom. |
| 1082 | * win_ins_lines may fail when the terminal can't do it. |
| 1083 | */ |
| 1084 | if (i > 0) |
| 1085 | check_for_delay(FALSE); |
| 1086 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1087 | { |
| 1088 | if (wp->w_lines_valid != 0) |
| 1089 | { |
| 1090 | /* Need to update rows that are new, stop at the |
| 1091 | * first one that scrolled down. */ |
| 1092 | top_end = i; |
| 1093 | #ifdef FEAT_VISUAL |
| 1094 | scrolled_down = TRUE; |
| 1095 | #endif |
| 1096 | |
| 1097 | /* Move the entries that were scrolled, disable |
| 1098 | * the entries for the lines to be redrawn. */ |
| 1099 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1100 | wp->w_lines_valid = wp->w_height; |
| 1101 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1102 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1103 | while (idx >= 0) |
| 1104 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1105 | } |
| 1106 | } |
| 1107 | else |
| 1108 | mid_start = 0; /* redraw all lines */ |
| 1109 | } |
| 1110 | else |
| 1111 | mid_start = 0; /* redraw all lines */ |
| 1112 | } |
| 1113 | else |
| 1114 | mid_start = 0; /* redraw all lines */ |
| 1115 | } |
| 1116 | else |
| 1117 | { |
| 1118 | /* |
| 1119 | * New topline is at or below old topline: May scroll up. |
| 1120 | * When topline didn't change, find first entry in w_lines[] that |
| 1121 | * needs updating. |
| 1122 | */ |
| 1123 | |
| 1124 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1125 | j = -1; |
| 1126 | row = 0; |
| 1127 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1128 | { |
| 1129 | if (wp->w_lines[i].wl_valid |
| 1130 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1131 | { |
| 1132 | j = i; |
| 1133 | break; |
| 1134 | } |
| 1135 | row += wp->w_lines[i].wl_size; |
| 1136 | } |
| 1137 | if (j == -1) |
| 1138 | { |
| 1139 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1140 | * lines */ |
| 1141 | mid_start = 0; |
| 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | /* |
| 1146 | * Try to delete the correct number of lines. |
| 1147 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1148 | */ |
| 1149 | #ifdef FEAT_DIFF |
| 1150 | /* If the topline didn't change, delete old filler lines, |
| 1151 | * otherwise delete filler lines of the new topline... */ |
| 1152 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1153 | row += wp->w_old_topfill; |
| 1154 | else |
| 1155 | row += diff_check_fill(wp, wp->w_topline); |
| 1156 | /* ... but don't delete new filler lines. */ |
| 1157 | row -= wp->w_topfill; |
| 1158 | #endif |
| 1159 | if (row > 0) |
| 1160 | { |
| 1161 | check_for_delay(FALSE); |
| 1162 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1163 | bot_start = wp->w_height - row; |
| 1164 | else |
| 1165 | mid_start = 0; /* redraw all lines */ |
| 1166 | } |
| 1167 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1168 | { |
| 1169 | /* |
| 1170 | * Skip the lines (below the deleted lines) that are still |
| 1171 | * valid and don't need redrawing. Copy their info |
| 1172 | * upwards, to compensate for the deleted lines. Set |
| 1173 | * bot_start to the first row that needs redrawing. |
| 1174 | */ |
| 1175 | bot_start = 0; |
| 1176 | idx = 0; |
| 1177 | for (;;) |
| 1178 | { |
| 1179 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1180 | /* stop at line that didn't fit, unless it is still |
| 1181 | * valid (no lines deleted) */ |
| 1182 | if (row > 0 && bot_start + row |
| 1183 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1184 | { |
| 1185 | wp->w_lines_valid = idx + 1; |
| 1186 | break; |
| 1187 | } |
| 1188 | bot_start += wp->w_lines[idx++].wl_size; |
| 1189 | |
| 1190 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1191 | if (++j >= wp->w_lines_valid) |
| 1192 | { |
| 1193 | wp->w_lines_valid = idx; |
| 1194 | break; |
| 1195 | } |
| 1196 | } |
| 1197 | #ifdef FEAT_DIFF |
| 1198 | /* Correct the first entry for filler lines at the top |
| 1199 | * when it won't get updated below. */ |
| 1200 | if (wp->w_p_diff && bot_start > 0) |
| 1201 | wp->w_lines[0].wl_size = |
| 1202 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1203 | + wp->w_topfill; |
| 1204 | #endif |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | /* When starting redraw in the first line, redraw all lines. When |
| 1210 | * there is only one window it's probably faster to clear the screen |
| 1211 | * first. */ |
| 1212 | if (mid_start == 0) |
| 1213 | { |
| 1214 | mid_end = wp->w_height; |
| 1215 | if (lastwin == firstwin) |
| 1216 | screenclear(); |
| 1217 | } |
| 1218 | } |
| 1219 | else |
| 1220 | { |
| 1221 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1222 | mid_start = 0; |
| 1223 | mid_end = wp->w_height; |
| 1224 | } |
| 1225 | |
| 1226 | #ifdef FEAT_VISUAL |
| 1227 | /* check if we are updating or removing the inverted part */ |
| 1228 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1229 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1230 | { |
| 1231 | linenr_T from, to; |
| 1232 | |
| 1233 | if (VIsual_active) |
| 1234 | { |
| 1235 | if (VIsual_active |
| 1236 | && (VIsual_mode != wp->w_old_visual_mode |
| 1237 | || type == INVERTED_ALL)) |
| 1238 | { |
| 1239 | /* |
| 1240 | * If the type of Visual selection changed, redraw the whole |
| 1241 | * selection. Also when the ownership of the X selection is |
| 1242 | * gained or lost. |
| 1243 | */ |
| 1244 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1245 | { |
| 1246 | from = curwin->w_cursor.lnum; |
| 1247 | to = VIsual.lnum; |
| 1248 | } |
| 1249 | else |
| 1250 | { |
| 1251 | from = VIsual.lnum; |
| 1252 | to = curwin->w_cursor.lnum; |
| 1253 | } |
| 1254 | /* redraw more when the cursor moved as well */ |
| 1255 | if (wp->w_old_cursor_lnum < from) |
| 1256 | from = wp->w_old_cursor_lnum; |
| 1257 | if (wp->w_old_cursor_lnum > to) |
| 1258 | to = wp->w_old_cursor_lnum; |
| 1259 | if (wp->w_old_visual_lnum < from) |
| 1260 | from = wp->w_old_visual_lnum; |
| 1261 | if (wp->w_old_visual_lnum > to) |
| 1262 | to = wp->w_old_visual_lnum; |
| 1263 | } |
| 1264 | else |
| 1265 | { |
| 1266 | /* |
| 1267 | * Find the line numbers that need to be updated: The lines |
| 1268 | * between the old cursor position and the current cursor |
| 1269 | * position. Also check if the Visual position changed. |
| 1270 | */ |
| 1271 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1272 | { |
| 1273 | from = curwin->w_cursor.lnum; |
| 1274 | to = wp->w_old_cursor_lnum; |
| 1275 | } |
| 1276 | else |
| 1277 | { |
| 1278 | from = wp->w_old_cursor_lnum; |
| 1279 | to = curwin->w_cursor.lnum; |
| 1280 | if (from == 0) /* Visual mode just started */ |
| 1281 | from = to; |
| 1282 | } |
| 1283 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1284 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1285 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1286 | { |
| 1287 | if (wp->w_old_visual_lnum < from |
| 1288 | && wp->w_old_visual_lnum != 0) |
| 1289 | from = wp->w_old_visual_lnum; |
| 1290 | if (wp->w_old_visual_lnum > to) |
| 1291 | to = wp->w_old_visual_lnum; |
| 1292 | if (VIsual.lnum < from) |
| 1293 | from = VIsual.lnum; |
| 1294 | if (VIsual.lnum > to) |
| 1295 | to = VIsual.lnum; |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | /* |
| 1300 | * If in block mode and changed column or curwin->w_curswant: |
| 1301 | * update all lines. |
| 1302 | * First compute the actual start and end column. |
| 1303 | */ |
| 1304 | if (VIsual_mode == Ctrl_V) |
| 1305 | { |
| 1306 | colnr_T fromc, toc; |
| 1307 | |
| 1308 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
| 1309 | ++toc; |
| 1310 | if (curwin->w_curswant == MAXCOL) |
| 1311 | toc = MAXCOL; |
| 1312 | |
| 1313 | if (fromc != wp->w_old_cursor_fcol |
| 1314 | || toc != wp->w_old_cursor_lcol) |
| 1315 | { |
| 1316 | if (from > VIsual.lnum) |
| 1317 | from = VIsual.lnum; |
| 1318 | if (to < VIsual.lnum) |
| 1319 | to = VIsual.lnum; |
| 1320 | } |
| 1321 | wp->w_old_cursor_fcol = fromc; |
| 1322 | wp->w_old_cursor_lcol = toc; |
| 1323 | } |
| 1324 | } |
| 1325 | else |
| 1326 | { |
| 1327 | /* Use the line numbers of the old Visual area. */ |
| 1328 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1329 | { |
| 1330 | from = wp->w_old_cursor_lnum; |
| 1331 | to = wp->w_old_visual_lnum; |
| 1332 | } |
| 1333 | else |
| 1334 | { |
| 1335 | from = wp->w_old_visual_lnum; |
| 1336 | to = wp->w_old_cursor_lnum; |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | /* |
| 1341 | * There is no need to update lines above the top of the window. |
| 1342 | */ |
| 1343 | if (from < wp->w_topline) |
| 1344 | from = wp->w_topline; |
| 1345 | |
| 1346 | /* |
| 1347 | * If we know the value of w_botline, use it to restrict the update to |
| 1348 | * the lines that are visible in the window. |
| 1349 | */ |
| 1350 | if (wp->w_valid & VALID_BOTLINE) |
| 1351 | { |
| 1352 | if (from >= wp->w_botline) |
| 1353 | from = wp->w_botline - 1; |
| 1354 | if (to >= wp->w_botline) |
| 1355 | to = wp->w_botline - 1; |
| 1356 | } |
| 1357 | |
| 1358 | /* |
| 1359 | * Find the minimal part to be updated. |
| 1360 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1361 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1362 | * top_end; need to redraw from top_end to the "to" line. |
| 1363 | * A middle mouse click with a Visual selection may change the text |
| 1364 | * above the Visual area and reset wl_valid, do count these for |
| 1365 | * mid_end (in srow). |
| 1366 | */ |
| 1367 | if (mid_start > 0) |
| 1368 | { |
| 1369 | lnum = wp->w_topline; |
| 1370 | idx = 0; |
| 1371 | srow = 0; |
| 1372 | if (scrolled_down) |
| 1373 | mid_start = top_end; |
| 1374 | else |
| 1375 | mid_start = 0; |
| 1376 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1377 | { |
| 1378 | if (wp->w_lines[idx].wl_valid) |
| 1379 | mid_start += wp->w_lines[idx].wl_size; |
| 1380 | else if (!scrolled_down) |
| 1381 | srow += wp->w_lines[idx].wl_size; |
| 1382 | ++idx; |
| 1383 | # ifdef FEAT_FOLDING |
| 1384 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1385 | lnum = wp->w_lines[idx].wl_lnum; |
| 1386 | else |
| 1387 | # endif |
| 1388 | ++lnum; |
| 1389 | } |
| 1390 | srow += mid_start; |
| 1391 | mid_end = wp->w_height; |
| 1392 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1393 | { |
| 1394 | if (wp->w_lines[idx].wl_valid |
| 1395 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1396 | { |
| 1397 | /* Only update until first row of this line */ |
| 1398 | mid_end = srow; |
| 1399 | break; |
| 1400 | } |
| 1401 | srow += wp->w_lines[idx].wl_size; |
| 1402 | } |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | if (VIsual_active && buf == curwin->w_buffer) |
| 1407 | { |
| 1408 | wp->w_old_visual_mode = VIsual_mode; |
| 1409 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1410 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1411 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1412 | wp->w_old_curswant = curwin->w_curswant; |
| 1413 | } |
| 1414 | else |
| 1415 | { |
| 1416 | wp->w_old_visual_mode = 0; |
| 1417 | wp->w_old_cursor_lnum = 0; |
| 1418 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1419 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1420 | } |
| 1421 | #endif /* FEAT_VISUAL */ |
| 1422 | |
| 1423 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1424 | /* reset got_int, otherwise regexp won't work */ |
| 1425 | save_got_int = got_int; |
| 1426 | got_int = 0; |
| 1427 | #endif |
| 1428 | #ifdef FEAT_FOLDING |
| 1429 | win_foldinfo.fi_level = 0; |
| 1430 | #endif |
| 1431 | |
| 1432 | /* |
| 1433 | * Update all the window rows. |
| 1434 | */ |
| 1435 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1436 | row = 0; |
| 1437 | srow = 0; |
| 1438 | lnum = wp->w_topline; /* first line shown in window */ |
| 1439 | for (;;) |
| 1440 | { |
| 1441 | /* stop updating when reached the end of the window (check for _past_ |
| 1442 | * the end of the window is at the end of the loop) */ |
| 1443 | if (row == wp->w_height) |
| 1444 | { |
| 1445 | didline = TRUE; |
| 1446 | break; |
| 1447 | } |
| 1448 | |
| 1449 | /* stop updating when hit the end of the file */ |
| 1450 | if (lnum > buf->b_ml.ml_line_count) |
| 1451 | { |
| 1452 | eof = TRUE; |
| 1453 | break; |
| 1454 | } |
| 1455 | |
| 1456 | /* Remember the starting row of the line that is going to be dealt |
| 1457 | * with. It is used further down when the line doesn't fit. */ |
| 1458 | srow = row; |
| 1459 | |
| 1460 | /* |
| 1461 | * Update a line when it is in an area that needs updating, when it |
| 1462 | * has changes or w_lines[idx] is invalid. |
| 1463 | * bot_start may be halfway a wrapped line after using |
| 1464 | * win_del_lines(), check if the current line includes it. |
| 1465 | * When syntax folding is being used, the saved syntax states will |
| 1466 | * already have been updated, we can't see where the syntax state is |
| 1467 | * the same again, just update until the end of the window. |
| 1468 | */ |
| 1469 | if (row < top_end |
| 1470 | || (row >= mid_start && row < mid_end) |
| 1471 | #ifdef FEAT_SEARCH_EXTRA |
| 1472 | || top_to_mod |
| 1473 | #endif |
| 1474 | || idx >= wp->w_lines_valid |
| 1475 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1476 | || (mod_top != 0 |
| 1477 | && (lnum == mod_top |
| 1478 | || (lnum >= mod_top |
| 1479 | && (lnum < mod_bot |
| 1480 | #ifdef FEAT_SYN_HL |
| 1481 | || did_update == DID_FOLD |
| 1482 | || (did_update == DID_LINE |
| 1483 | && syntax_present(buf) |
| 1484 | && ( |
| 1485 | # ifdef FEAT_FOLDING |
| 1486 | (foldmethodIsSyntax(wp) |
| 1487 | && hasAnyFolding(wp)) || |
| 1488 | # endif |
| 1489 | syntax_check_changed(lnum))) |
| 1490 | #endif |
| 1491 | ))))) |
| 1492 | { |
| 1493 | #ifdef FEAT_SEARCH_EXTRA |
| 1494 | if (lnum == mod_top) |
| 1495 | top_to_mod = FALSE; |
| 1496 | #endif |
| 1497 | |
| 1498 | /* |
| 1499 | * When at start of changed lines: May scroll following lines |
| 1500 | * up or down to minimize redrawing. |
| 1501 | * Don't do this when the change continues until the end. |
| 1502 | * Don't scroll when dollar_vcol is non-zero, keep the "$". |
| 1503 | */ |
| 1504 | if (lnum == mod_top |
| 1505 | && mod_bot != MAXLNUM |
| 1506 | && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) |
| 1507 | { |
| 1508 | int old_rows = 0; |
| 1509 | int new_rows = 0; |
| 1510 | int xtra_rows; |
| 1511 | linenr_T l; |
| 1512 | |
| 1513 | /* Count the old number of window rows, using w_lines[], which |
| 1514 | * should still contain the sizes for the lines as they are |
| 1515 | * currently displayed. */ |
| 1516 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1517 | { |
| 1518 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1519 | * lines are part of the changed area. */ |
| 1520 | if (wp->w_lines[i].wl_valid |
| 1521 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1522 | break; |
| 1523 | old_rows += wp->w_lines[i].wl_size; |
| 1524 | #ifdef FEAT_FOLDING |
| 1525 | if (wp->w_lines[i].wl_valid |
| 1526 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1527 | { |
| 1528 | /* Must have found the last valid entry above mod_bot. |
| 1529 | * Add following invalid entries. */ |
| 1530 | ++i; |
| 1531 | while (i < wp->w_lines_valid |
| 1532 | && !wp->w_lines[i].wl_valid) |
| 1533 | old_rows += wp->w_lines[i++].wl_size; |
| 1534 | break; |
| 1535 | } |
| 1536 | #endif |
| 1537 | } |
| 1538 | |
| 1539 | if (i >= wp->w_lines_valid) |
| 1540 | { |
| 1541 | /* We can't find a valid line below the changed lines, |
| 1542 | * need to redraw until the end of the window. |
| 1543 | * Inserting/deleting lines has no use. */ |
| 1544 | bot_start = 0; |
| 1545 | } |
| 1546 | else |
| 1547 | { |
| 1548 | /* Able to count old number of rows: Count new window |
| 1549 | * rows, and may insert/delete lines */ |
| 1550 | j = idx; |
| 1551 | for (l = lnum; l < mod_bot; ++l) |
| 1552 | { |
| 1553 | #ifdef FEAT_FOLDING |
| 1554 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1555 | ++new_rows; |
| 1556 | else |
| 1557 | #endif |
| 1558 | #ifdef FEAT_DIFF |
| 1559 | if (l == wp->w_topline) |
| 1560 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1561 | + wp->w_topfill; |
| 1562 | else |
| 1563 | #endif |
| 1564 | new_rows += plines_win(wp, l, TRUE); |
| 1565 | ++j; |
| 1566 | if (new_rows > wp->w_height - row - 2) |
| 1567 | { |
| 1568 | /* it's getting too much, must redraw the rest */ |
| 1569 | new_rows = 9999; |
| 1570 | break; |
| 1571 | } |
| 1572 | } |
| 1573 | xtra_rows = new_rows - old_rows; |
| 1574 | if (xtra_rows < 0) |
| 1575 | { |
| 1576 | /* May scroll text up. If there is not enough |
| 1577 | * remaining text or scrolling fails, must redraw the |
| 1578 | * rest. If scrolling works, must redraw the text |
| 1579 | * below the scrolled text. */ |
| 1580 | if (row - xtra_rows >= wp->w_height - 2) |
| 1581 | mod_bot = MAXLNUM; |
| 1582 | else |
| 1583 | { |
| 1584 | check_for_delay(FALSE); |
| 1585 | if (win_del_lines(wp, row, |
| 1586 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1587 | mod_bot = MAXLNUM; |
| 1588 | else |
| 1589 | bot_start = wp->w_height + xtra_rows; |
| 1590 | } |
| 1591 | } |
| 1592 | else if (xtra_rows > 0) |
| 1593 | { |
| 1594 | /* May scroll text down. If there is not enough |
| 1595 | * remaining text of scrolling fails, must redraw the |
| 1596 | * rest. */ |
| 1597 | if (row + xtra_rows >= wp->w_height - 2) |
| 1598 | mod_bot = MAXLNUM; |
| 1599 | else |
| 1600 | { |
| 1601 | check_for_delay(FALSE); |
| 1602 | if (win_ins_lines(wp, row + old_rows, |
| 1603 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1604 | mod_bot = MAXLNUM; |
| 1605 | else if (top_end > row + old_rows) |
| 1606 | /* Scrolled the part at the top that requires |
| 1607 | * updating down. */ |
| 1608 | top_end += xtra_rows; |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | /* When not updating the rest, may need to move w_lines[] |
| 1613 | * entries. */ |
| 1614 | if (mod_bot != MAXLNUM && i != j) |
| 1615 | { |
| 1616 | if (j < i) |
| 1617 | { |
| 1618 | int x = row + new_rows; |
| 1619 | |
| 1620 | /* move entries in w_lines[] upwards */ |
| 1621 | for (;;) |
| 1622 | { |
| 1623 | /* stop at last valid entry in w_lines[] */ |
| 1624 | if (i >= wp->w_lines_valid) |
| 1625 | { |
| 1626 | wp->w_lines_valid = j; |
| 1627 | break; |
| 1628 | } |
| 1629 | wp->w_lines[j] = wp->w_lines[i]; |
| 1630 | /* stop at a line that won't fit */ |
| 1631 | if (x + (int)wp->w_lines[j].wl_size |
| 1632 | > wp->w_height) |
| 1633 | { |
| 1634 | wp->w_lines_valid = j + 1; |
| 1635 | break; |
| 1636 | } |
| 1637 | x += wp->w_lines[j++].wl_size; |
| 1638 | ++i; |
| 1639 | } |
| 1640 | if (bot_start > x) |
| 1641 | bot_start = x; |
| 1642 | } |
| 1643 | else /* j > i */ |
| 1644 | { |
| 1645 | /* move entries in w_lines[] downwards */ |
| 1646 | j -= i; |
| 1647 | wp->w_lines_valid += j; |
| 1648 | if (wp->w_lines_valid > wp->w_height) |
| 1649 | wp->w_lines_valid = wp->w_height; |
| 1650 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1651 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1652 | |
| 1653 | /* The w_lines[] entries for inserted lines are |
| 1654 | * now invalid, but wl_size may be used above. |
| 1655 | * Reset to zero. */ |
| 1656 | while (i >= idx) |
| 1657 | { |
| 1658 | wp->w_lines[i].wl_size = 0; |
| 1659 | wp->w_lines[i--].wl_valid = FALSE; |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | #ifdef FEAT_FOLDING |
| 1667 | /* |
| 1668 | * When lines are folded, display one line for all of them. |
| 1669 | * Otherwise, display normally (can be several display lines when |
| 1670 | * 'wrap' is on). |
| 1671 | */ |
| 1672 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1673 | if (fold_count != 0) |
| 1674 | { |
| 1675 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1676 | ++row; |
| 1677 | --fold_count; |
| 1678 | wp->w_lines[idx].wl_folded = TRUE; |
| 1679 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1680 | # ifdef FEAT_SYN_HL |
| 1681 | did_update = DID_FOLD; |
| 1682 | # endif |
| 1683 | } |
| 1684 | else |
| 1685 | #endif |
| 1686 | if (idx < wp->w_lines_valid |
| 1687 | && wp->w_lines[idx].wl_valid |
| 1688 | && wp->w_lines[idx].wl_lnum == lnum |
| 1689 | && lnum > wp->w_topline |
| 1690 | && !(dy_flags & DY_LASTLINE) |
| 1691 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1692 | #ifdef FEAT_DIFF |
| 1693 | && diff_check_fill(wp, lnum) == 0 |
| 1694 | #endif |
| 1695 | ) |
| 1696 | { |
| 1697 | /* This line is not going to fit. Don't draw anything here, |
| 1698 | * will draw "@ " lines below. */ |
| 1699 | row = wp->w_height + 1; |
| 1700 | } |
| 1701 | else |
| 1702 | { |
| 1703 | #ifdef FEAT_SEARCH_EXTRA |
| 1704 | prepare_search_hl(wp, lnum); |
| 1705 | #endif |
| 1706 | #ifdef FEAT_SYN_HL |
| 1707 | /* Let the syntax stuff know we skipped a few lines. */ |
| 1708 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
| 1709 | && syntax_present(buf)) |
| 1710 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1711 | #endif |
| 1712 | |
| 1713 | /* |
| 1714 | * Display one line. |
| 1715 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 1716 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1717 | |
| 1718 | #ifdef FEAT_FOLDING |
| 1719 | wp->w_lines[idx].wl_folded = FALSE; |
| 1720 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 1721 | #endif |
| 1722 | #ifdef FEAT_SYN_HL |
| 1723 | did_update = DID_LINE; |
| 1724 | syntax_last_parsed = lnum; |
| 1725 | #endif |
| 1726 | } |
| 1727 | |
| 1728 | wp->w_lines[idx].wl_lnum = lnum; |
| 1729 | wp->w_lines[idx].wl_valid = TRUE; |
| 1730 | if (row > wp->w_height) /* past end of screen */ |
| 1731 | { |
| 1732 | /* we may need the size of that too long line later on */ |
| 1733 | if (dollar_vcol == 0) |
| 1734 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 1735 | ++idx; |
| 1736 | break; |
| 1737 | } |
| 1738 | if (dollar_vcol == 0) |
| 1739 | wp->w_lines[idx].wl_size = row - srow; |
| 1740 | ++idx; |
| 1741 | #ifdef FEAT_FOLDING |
| 1742 | lnum += fold_count + 1; |
| 1743 | #else |
| 1744 | ++lnum; |
| 1745 | #endif |
| 1746 | } |
| 1747 | else |
| 1748 | { |
| 1749 | /* This line does not need updating, advance to the next one */ |
| 1750 | row += wp->w_lines[idx++].wl_size; |
| 1751 | if (row > wp->w_height) /* past end of screen */ |
| 1752 | break; |
| 1753 | #ifdef FEAT_FOLDING |
| 1754 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 1755 | #else |
| 1756 | ++lnum; |
| 1757 | #endif |
| 1758 | #ifdef FEAT_SYN_HL |
| 1759 | did_update = DID_NONE; |
| 1760 | #endif |
| 1761 | } |
| 1762 | |
| 1763 | if (lnum > buf->b_ml.ml_line_count) |
| 1764 | { |
| 1765 | eof = TRUE; |
| 1766 | break; |
| 1767 | } |
| 1768 | } |
| 1769 | /* |
| 1770 | * End of loop over all window lines. |
| 1771 | */ |
| 1772 | |
| 1773 | |
| 1774 | if (idx > wp->w_lines_valid) |
| 1775 | wp->w_lines_valid = idx; |
| 1776 | |
| 1777 | #ifdef FEAT_SYN_HL |
| 1778 | /* |
| 1779 | * Let the syntax stuff know we stop parsing here. |
| 1780 | */ |
| 1781 | if (syntax_last_parsed != 0 && syntax_present(buf)) |
| 1782 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1783 | #endif |
| 1784 | |
| 1785 | /* |
| 1786 | * If we didn't hit the end of the file, and we didn't finish the last |
| 1787 | * line we were working on, then the line didn't fit. |
| 1788 | */ |
| 1789 | wp->w_empty_rows = 0; |
| 1790 | #ifdef FEAT_DIFF |
| 1791 | wp->w_filler_rows = 0; |
| 1792 | #endif |
| 1793 | if (!eof && !didline) |
| 1794 | { |
| 1795 | if (lnum == wp->w_topline) |
| 1796 | { |
| 1797 | /* |
| 1798 | * Single line that does not fit! |
| 1799 | * Don't overwrite it, it can be edited. |
| 1800 | */ |
| 1801 | wp->w_botline = lnum + 1; |
| 1802 | } |
| 1803 | #ifdef FEAT_DIFF |
| 1804 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 1805 | { |
| 1806 | /* Window ends in filler lines. */ |
| 1807 | wp->w_botline = lnum; |
| 1808 | wp->w_filler_rows = wp->w_height - srow; |
| 1809 | } |
| 1810 | #endif |
| 1811 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 1812 | { |
| 1813 | /* |
| 1814 | * Last line isn't finished: Display "@@@" at the end. |
| 1815 | */ |
| 1816 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 1817 | W_WINROW(wp) + wp->w_height, |
| 1818 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 1819 | '@', '@', hl_attr(HLF_AT)); |
| 1820 | set_empty_rows(wp, srow); |
| 1821 | wp->w_botline = lnum; |
| 1822 | } |
| 1823 | else |
| 1824 | { |
| 1825 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 1826 | wp->w_botline = lnum; |
| 1827 | } |
| 1828 | } |
| 1829 | else |
| 1830 | { |
| 1831 | #ifdef FEAT_VERTSPLIT |
| 1832 | draw_vsep_win(wp, row); |
| 1833 | #endif |
| 1834 | if (eof) /* we hit the end of the file */ |
| 1835 | { |
| 1836 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 1837 | #ifdef FEAT_DIFF |
| 1838 | j = diff_check_fill(wp, wp->w_botline); |
| 1839 | if (j > 0 && !wp->w_botfill) |
| 1840 | { |
| 1841 | /* |
| 1842 | * Display filler lines at the end of the file |
| 1843 | */ |
| 1844 | if (char2cells(fill_diff) > 1) |
| 1845 | i = '-'; |
| 1846 | else |
| 1847 | i = fill_diff; |
| 1848 | if (row + j > wp->w_height) |
| 1849 | j = wp->w_height - row; |
| 1850 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 1851 | row += j; |
| 1852 | } |
| 1853 | #endif |
| 1854 | } |
| 1855 | else if (dollar_vcol == 0) |
| 1856 | wp->w_botline = lnum; |
| 1857 | |
| 1858 | /* make sure the rest of the screen is blank */ |
| 1859 | /* put '~'s on rows that aren't part of the file. */ |
| 1860 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 1861 | } |
| 1862 | |
| 1863 | /* Reset the type of redrawing required, the window has been updated. */ |
| 1864 | wp->w_redr_type = 0; |
| 1865 | #ifdef FEAT_DIFF |
| 1866 | wp->w_old_topfill = wp->w_topfill; |
| 1867 | wp->w_old_botfill = wp->w_botfill; |
| 1868 | #endif |
| 1869 | |
| 1870 | if (dollar_vcol == 0) |
| 1871 | { |
| 1872 | /* |
| 1873 | * There is a trick with w_botline. If we invalidate it on each |
| 1874 | * change that might modify it, this will cause a lot of expensive |
| 1875 | * calls to plines() in update_topline() each time. Therefore the |
| 1876 | * value of w_botline is often approximated, and this value is used to |
| 1877 | * compute the value of w_topline. If the value of w_botline was |
| 1878 | * wrong, check that the value of w_topline is correct (cursor is on |
| 1879 | * the visible part of the text). If it's not, we need to redraw |
| 1880 | * again. Mostly this just means scrolling up a few lines, so it |
| 1881 | * doesn't look too bad. Only do this for the current window (where |
| 1882 | * changes are relevant). |
| 1883 | */ |
| 1884 | wp->w_valid |= VALID_BOTLINE; |
| 1885 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 1886 | { |
| 1887 | recursive = TRUE; |
| 1888 | curwin->w_valid &= ~VALID_TOPLINE; |
| 1889 | update_topline(); /* may invalidate w_botline again */ |
| 1890 | if (must_redraw != 0) |
| 1891 | { |
| 1892 | /* Don't update for changes in buffer again. */ |
| 1893 | i = curbuf->b_mod_set; |
| 1894 | curbuf->b_mod_set = FALSE; |
| 1895 | win_update(curwin); |
| 1896 | must_redraw = 0; |
| 1897 | curbuf->b_mod_set = i; |
| 1898 | } |
| 1899 | recursive = FALSE; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1904 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 1905 | if (!got_int) |
| 1906 | got_int = save_got_int; |
| 1907 | #endif |
| 1908 | } |
| 1909 | |
| 1910 | #ifdef FEAT_SIGNS |
| 1911 | static int draw_signcolumn __ARGS((win_T *wp)); |
| 1912 | |
| 1913 | /* |
| 1914 | * Return TRUE when window "wp" has a column to draw signs in. |
| 1915 | */ |
| 1916 | static int |
| 1917 | draw_signcolumn(wp) |
| 1918 | win_T *wp; |
| 1919 | { |
| 1920 | return (wp->w_buffer->b_signlist != NULL |
| 1921 | # ifdef FEAT_NETBEANS_INTG |
| 1922 | || usingNetbeans |
| 1923 | # endif |
| 1924 | ); |
| 1925 | } |
| 1926 | #endif |
| 1927 | |
| 1928 | /* |
| 1929 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 1930 | * as the filler character. |
| 1931 | */ |
| 1932 | static void |
| 1933 | win_draw_end(wp, c1, c2, row, endrow, hl) |
| 1934 | win_T *wp; |
| 1935 | int c1; |
| 1936 | int c2; |
| 1937 | int row; |
| 1938 | int endrow; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 1939 | hlf_T hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1940 | { |
| 1941 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 1942 | int n = 0; |
| 1943 | # define FDC_OFF n |
| 1944 | #else |
| 1945 | # define FDC_OFF 0 |
| 1946 | #endif |
| 1947 | |
| 1948 | #ifdef FEAT_RIGHTLEFT |
| 1949 | if (wp->w_p_rl) |
| 1950 | { |
| 1951 | /* No check for cmdline window: should never be right-left. */ |
| 1952 | # ifdef FEAT_FOLDING |
| 1953 | n = wp->w_p_fdc; |
| 1954 | |
| 1955 | if (n > 0) |
| 1956 | { |
| 1957 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 1958 | if (n > W_WIDTH(wp)) |
| 1959 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1960 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 1961 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 1962 | ' ', ' ', hl_attr(HLF_FC)); |
| 1963 | } |
| 1964 | # endif |
| 1965 | # ifdef FEAT_SIGNS |
| 1966 | if (draw_signcolumn(wp)) |
| 1967 | { |
| 1968 | int nn = n + 2; |
| 1969 | |
| 1970 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 1971 | if (nn > W_WIDTH(wp)) |
| 1972 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1973 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 1974 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 1975 | ' ', ' ', hl_attr(HLF_SC)); |
| 1976 | n = nn; |
| 1977 | } |
| 1978 | # endif |
| 1979 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 1980 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 1981 | c2, c2, hl_attr(hl)); |
| 1982 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 1983 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 1984 | c1, c2, hl_attr(hl)); |
| 1985 | } |
| 1986 | else |
| 1987 | #endif |
| 1988 | { |
| 1989 | #ifdef FEAT_CMDWIN |
| 1990 | if (cmdwin_type != 0 && wp == curwin) |
| 1991 | { |
| 1992 | /* draw the cmdline character in the leftmost column */ |
| 1993 | n = 1; |
| 1994 | if (n > wp->w_width) |
| 1995 | n = wp->w_width; |
| 1996 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 1997 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 1998 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 1999 | } |
| 2000 | #endif |
| 2001 | #ifdef FEAT_FOLDING |
| 2002 | if (wp->w_p_fdc > 0) |
| 2003 | { |
| 2004 | int nn = n + wp->w_p_fdc; |
| 2005 | |
| 2006 | /* draw the fold column at the left */ |
| 2007 | if (nn > W_WIDTH(wp)) |
| 2008 | nn = W_WIDTH(wp); |
| 2009 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2010 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2011 | ' ', ' ', hl_attr(HLF_FC)); |
| 2012 | n = nn; |
| 2013 | } |
| 2014 | #endif |
| 2015 | #ifdef FEAT_SIGNS |
| 2016 | if (draw_signcolumn(wp)) |
| 2017 | { |
| 2018 | int nn = n + 2; |
| 2019 | |
| 2020 | /* draw the sign column after the fold column */ |
| 2021 | if (nn > W_WIDTH(wp)) |
| 2022 | nn = W_WIDTH(wp); |
| 2023 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2024 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2025 | ' ', ' ', hl_attr(HLF_SC)); |
| 2026 | n = nn; |
| 2027 | } |
| 2028 | #endif |
| 2029 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2030 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2031 | c1, c2, hl_attr(hl)); |
| 2032 | } |
| 2033 | set_empty_rows(wp, row); |
| 2034 | } |
| 2035 | |
| 2036 | #ifdef FEAT_FOLDING |
| 2037 | /* |
| 2038 | * Display one folded line. |
| 2039 | */ |
| 2040 | static void |
| 2041 | fold_line(wp, fold_count, foldinfo, lnum, row) |
| 2042 | win_T *wp; |
| 2043 | long fold_count; |
| 2044 | foldinfo_T *foldinfo; |
| 2045 | linenr_T lnum; |
| 2046 | int row; |
| 2047 | { |
| 2048 | char_u buf[51]; |
| 2049 | pos_T *top, *bot; |
| 2050 | linenr_T lnume = lnum + fold_count - 1; |
| 2051 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2052 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2053 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2054 | int col; |
| 2055 | int txtcol; |
| 2056 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2057 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2058 | |
| 2059 | /* Build the fold line: |
| 2060 | * 1. Add the cmdwin_type for the command-line window |
| 2061 | * 2. Add the 'foldcolumn' |
| 2062 | * 3. Add the 'number' column |
| 2063 | * 4. Compose the text |
| 2064 | * 5. Add the text |
| 2065 | * 6. set highlighting for the Visual area an other text |
| 2066 | */ |
| 2067 | col = 0; |
| 2068 | |
| 2069 | /* |
| 2070 | * 1. Add the cmdwin_type for the command-line window |
| 2071 | * Ignores 'rightleft', this window is never right-left. |
| 2072 | */ |
| 2073 | #ifdef FEAT_CMDWIN |
| 2074 | if (cmdwin_type != 0 && wp == curwin) |
| 2075 | { |
| 2076 | ScreenLines[off] = cmdwin_type; |
| 2077 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2078 | #ifdef FEAT_MBYTE |
| 2079 | if (enc_utf8) |
| 2080 | ScreenLinesUC[off] = 0; |
| 2081 | #endif |
| 2082 | ++col; |
| 2083 | } |
| 2084 | #endif |
| 2085 | |
| 2086 | /* |
| 2087 | * 2. Add the 'foldcolumn' |
| 2088 | */ |
| 2089 | fdc = wp->w_p_fdc; |
| 2090 | if (fdc > W_WIDTH(wp) - col) |
| 2091 | fdc = W_WIDTH(wp) - col; |
| 2092 | if (fdc > 0) |
| 2093 | { |
| 2094 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2095 | #ifdef FEAT_RIGHTLEFT |
| 2096 | if (wp->w_p_rl) |
| 2097 | { |
| 2098 | int i; |
| 2099 | |
| 2100 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2101 | hl_attr(HLF_FC)); |
| 2102 | /* reverse the fold column */ |
| 2103 | for (i = 0; i < fdc; ++i) |
| 2104 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2105 | } |
| 2106 | else |
| 2107 | #endif |
| 2108 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2109 | col += fdc; |
| 2110 | } |
| 2111 | |
| 2112 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2113 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2114 | for (ri = 0; ri < l; ++ri) \ |
| 2115 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2116 | else \ |
| 2117 | for (ri = 0; ri < l; ++ri) \ |
| 2118 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2119 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2120 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2121 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2122 | #endif |
| 2123 | |
| 2124 | /* Set all attributes of the 'number' column and the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2125 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2126 | |
| 2127 | #ifdef FEAT_SIGNS |
| 2128 | /* If signs are being displayed, add two spaces. */ |
| 2129 | if (draw_signcolumn(wp)) |
| 2130 | { |
| 2131 | len = W_WIDTH(wp) - col; |
| 2132 | if (len > 0) |
| 2133 | { |
| 2134 | if (len > 2) |
| 2135 | len = 2; |
| 2136 | # ifdef FEAT_RIGHTLEFT |
| 2137 | if (wp->w_p_rl) |
| 2138 | /* the line number isn't reversed */ |
| 2139 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2140 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2141 | else |
| 2142 | # endif |
| 2143 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2144 | col += len; |
| 2145 | } |
| 2146 | } |
| 2147 | #endif |
| 2148 | |
| 2149 | /* |
| 2150 | * 3. Add the 'number' column |
| 2151 | */ |
| 2152 | if (wp->w_p_nu) |
| 2153 | { |
| 2154 | len = W_WIDTH(wp) - col; |
| 2155 | if (len > 0) |
| 2156 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2157 | int w = number_width(wp); |
| 2158 | |
| 2159 | if (len > w + 1) |
| 2160 | len = w + 1; |
| 2161 | sprintf((char *)buf, "%*ld ", w, (long)lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2162 | #ifdef FEAT_RIGHTLEFT |
| 2163 | if (wp->w_p_rl) |
| 2164 | /* the line number isn't reversed */ |
| 2165 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2166 | hl_attr(HLF_FL)); |
| 2167 | else |
| 2168 | #endif |
| 2169 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2170 | col += len; |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | /* |
| 2175 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2176 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2177 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2178 | |
| 2179 | txtcol = col; /* remember where text starts */ |
| 2180 | |
| 2181 | /* |
| 2182 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2183 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2184 | * in columns number-col - window-width. |
| 2185 | */ |
| 2186 | #ifdef FEAT_MBYTE |
| 2187 | if (has_mbyte) |
| 2188 | { |
| 2189 | int cells; |
| 2190 | int u8c, u8c_c1, u8c_c2; |
| 2191 | int idx; |
| 2192 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2193 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2194 | # ifdef FEAT_ARABIC |
| 2195 | int prev_c = 0; /* previous Arabic character */ |
| 2196 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2197 | # endif |
| 2198 | |
| 2199 | # ifdef FEAT_RIGHTLEFT |
| 2200 | if (wp->w_p_rl) |
| 2201 | idx = off; |
| 2202 | else |
| 2203 | # endif |
| 2204 | idx = off + col; |
| 2205 | |
| 2206 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2207 | for (p = text; *p != NUL; ) |
| 2208 | { |
| 2209 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2210 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2211 | if (col + cells > W_WIDTH(wp) |
| 2212 | # ifdef FEAT_RIGHTLEFT |
| 2213 | - (wp->w_p_rl ? col : 0) |
| 2214 | # endif |
| 2215 | ) |
| 2216 | break; |
| 2217 | ScreenLines[idx] = *p; |
| 2218 | if (enc_utf8) |
| 2219 | { |
| 2220 | u8c = utfc_ptr2char(p, &u8c_c1, &u8c_c2); |
| 2221 | if (*p < 0x80 && u8c_c1 == 0 && u8c_c2 == 0) |
| 2222 | { |
| 2223 | ScreenLinesUC[idx] = 0; |
| 2224 | #ifdef FEAT_ARABIC |
| 2225 | prev_c = u8c; |
| 2226 | #endif |
| 2227 | } |
| 2228 | else |
| 2229 | { |
| 2230 | #ifdef FEAT_ARABIC |
| 2231 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2232 | { |
| 2233 | /* Do Arabic shaping. */ |
| 2234 | int pc, pc1, nc, dummy; |
| 2235 | int firstbyte = *p; |
| 2236 | |
| 2237 | /* The idea of what is the previous and next |
| 2238 | * character depends on 'rightleft'. */ |
| 2239 | if (wp->w_p_rl) |
| 2240 | { |
| 2241 | pc = prev_c; |
| 2242 | pc1 = prev_c1; |
| 2243 | nc = utf_ptr2char(p + c_len); |
| 2244 | prev_c1 = u8c_c1; |
| 2245 | } |
| 2246 | else |
| 2247 | { |
| 2248 | pc = utfc_ptr2char(p + c_len, &pc1, &dummy); |
| 2249 | nc = prev_c; |
| 2250 | } |
| 2251 | prev_c = u8c; |
| 2252 | |
| 2253 | u8c = arabic_shape(u8c, &firstbyte, &u8c_c1, |
| 2254 | pc, pc1, nc); |
| 2255 | ScreenLines[idx] = firstbyte; |
| 2256 | } |
| 2257 | else |
| 2258 | prev_c = u8c; |
| 2259 | #endif |
| 2260 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 2261 | if (u8c >= 0x10000) |
| 2262 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2263 | else |
| 2264 | ScreenLinesUC[idx] = u8c; |
| 2265 | ScreenLinesC1[idx] = u8c_c1; |
| 2266 | ScreenLinesC2[idx] = u8c_c2; |
| 2267 | } |
| 2268 | if (cells > 1) |
| 2269 | ScreenLines[idx + 1] = 0; |
| 2270 | } |
| 2271 | else if (cells > 1) /* double-byte character */ |
| 2272 | { |
| 2273 | if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2274 | ScreenLines2[idx] = p[1]; |
| 2275 | else |
| 2276 | ScreenLines[idx + 1] = p[1]; |
| 2277 | } |
| 2278 | col += cells; |
| 2279 | idx += cells; |
| 2280 | p += c_len; |
| 2281 | } |
| 2282 | } |
| 2283 | else |
| 2284 | #endif |
| 2285 | { |
| 2286 | len = (int)STRLEN(text); |
| 2287 | if (len > W_WIDTH(wp) - col) |
| 2288 | len = W_WIDTH(wp) - col; |
| 2289 | if (len > 0) |
| 2290 | { |
| 2291 | #ifdef FEAT_RIGHTLEFT |
| 2292 | if (wp->w_p_rl) |
| 2293 | STRNCPY(current_ScreenLine, text, len); |
| 2294 | else |
| 2295 | #endif |
| 2296 | STRNCPY(current_ScreenLine + col, text, len); |
| 2297 | col += len; |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | /* Fill the rest of the line with the fold filler */ |
| 2302 | #ifdef FEAT_RIGHTLEFT |
| 2303 | if (wp->w_p_rl) |
| 2304 | col -= txtcol; |
| 2305 | #endif |
| 2306 | while (col < W_WIDTH(wp) |
| 2307 | #ifdef FEAT_RIGHTLEFT |
| 2308 | - (wp->w_p_rl ? txtcol : 0) |
| 2309 | #endif |
| 2310 | ) |
| 2311 | { |
| 2312 | #ifdef FEAT_MBYTE |
| 2313 | if (enc_utf8) |
| 2314 | { |
| 2315 | if (fill_fold >= 0x80) |
| 2316 | { |
| 2317 | ScreenLinesUC[off + col] = fill_fold; |
| 2318 | ScreenLinesC1[off + col] = 0; |
| 2319 | ScreenLinesC2[off + col] = 0; |
| 2320 | } |
| 2321 | else |
| 2322 | ScreenLinesUC[off + col] = 0; |
| 2323 | } |
| 2324 | #endif |
| 2325 | ScreenLines[off + col++] = fill_fold; |
| 2326 | } |
| 2327 | |
| 2328 | if (text != buf) |
| 2329 | vim_free(text); |
| 2330 | |
| 2331 | /* |
| 2332 | * 6. set highlighting for the Visual area an other text. |
| 2333 | * If all folded lines are in the Visual area, highlight the line. |
| 2334 | */ |
| 2335 | #ifdef FEAT_VISUAL |
| 2336 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2337 | { |
| 2338 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2339 | { |
| 2340 | /* Visual is after curwin->w_cursor */ |
| 2341 | top = &curwin->w_cursor; |
| 2342 | bot = &VIsual; |
| 2343 | } |
| 2344 | else |
| 2345 | { |
| 2346 | /* Visual is before curwin->w_cursor */ |
| 2347 | top = &VIsual; |
| 2348 | bot = &curwin->w_cursor; |
| 2349 | } |
| 2350 | if (lnum >= top->lnum |
| 2351 | && lnume <= bot->lnum |
| 2352 | && (VIsual_mode != 'v' |
| 2353 | || ((lnum > top->lnum |
| 2354 | || (lnum == top->lnum |
| 2355 | && top->col == 0)) |
| 2356 | && (lnume < bot->lnum |
| 2357 | || (lnume == bot->lnum |
| 2358 | && (bot->col - (*p_sel == 'e')) |
| 2359 | >= STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
| 2360 | { |
| 2361 | if (VIsual_mode == Ctrl_V) |
| 2362 | { |
| 2363 | /* Visual block mode: highlight the chars part of the block */ |
| 2364 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2365 | { |
| 2366 | if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2367 | len = wp->w_old_cursor_lcol; |
| 2368 | else |
| 2369 | len = W_WIDTH(wp) - txtcol; |
| 2370 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2371 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2375 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2376 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2377 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2378 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | #endif |
| 2382 | |
| 2383 | |
| 2384 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2385 | (int)W_WIDTH(wp), FALSE); |
| 2386 | |
| 2387 | /* |
| 2388 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2389 | * updated (saves a call to plines() later). |
| 2390 | */ |
| 2391 | if (wp == curwin |
| 2392 | && lnum <= curwin->w_cursor.lnum |
| 2393 | && lnume >= curwin->w_cursor.lnum) |
| 2394 | { |
| 2395 | curwin->w_cline_row = row; |
| 2396 | curwin->w_cline_height = 1; |
| 2397 | curwin->w_cline_folded = TRUE; |
| 2398 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | /* |
| 2403 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2404 | */ |
| 2405 | static void |
| 2406 | copy_text_attr(off, buf, len, attr) |
| 2407 | int off; |
| 2408 | char_u *buf; |
| 2409 | int len; |
| 2410 | int attr; |
| 2411 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2412 | int i; |
| 2413 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2414 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2415 | # ifdef FEAT_MBYTE |
| 2416 | if (enc_utf8) |
| 2417 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2418 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2419 | for (i = 0; i < len; ++i) |
| 2420 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | /* |
| 2424 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2425 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2426 | */ |
| 2427 | static void |
| 2428 | fill_foldcolumn(p, wp, closed, lnum) |
| 2429 | char_u *p; |
| 2430 | win_T *wp; |
| 2431 | int closed; /* TRUE of FALSE */ |
| 2432 | linenr_T lnum; /* current line number */ |
| 2433 | { |
| 2434 | int i = 0; |
| 2435 | int level; |
| 2436 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2437 | int empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2438 | |
| 2439 | /* Init to all spaces. */ |
| 2440 | copy_spaces(p, (size_t)wp->w_p_fdc); |
| 2441 | |
| 2442 | level = win_foldinfo.fi_level; |
| 2443 | if (level > 0) |
| 2444 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2445 | /* If there is only one column put more info in it. */ |
| 2446 | empty = (wp->w_p_fdc == 1) ? 0 : 1; |
| 2447 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2448 | /* If the column is too narrow, we start at the lowest level that |
| 2449 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2450 | first_level = level - wp->w_p_fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2451 | if (first_level < 1) |
| 2452 | first_level = 1; |
| 2453 | |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2454 | for (i = 0; i + empty < wp->w_p_fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2455 | { |
| 2456 | if (win_foldinfo.fi_lnum == lnum |
| 2457 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2458 | p[i] = '-'; |
| 2459 | else if (first_level == 1) |
| 2460 | p[i] = '|'; |
| 2461 | else if (first_level + i <= 9) |
| 2462 | p[i] = '0' + first_level + i; |
| 2463 | else |
| 2464 | p[i] = '>'; |
| 2465 | if (first_level + i == level) |
| 2466 | break; |
| 2467 | } |
| 2468 | } |
| 2469 | if (closed) |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2470 | p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2471 | } |
| 2472 | #endif /* FEAT_FOLDING */ |
| 2473 | |
| 2474 | /* |
| 2475 | * Display line "lnum" of window 'wp' on the screen. |
| 2476 | * Start at row "startrow", stop when "endrow" is reached. |
| 2477 | * wp->w_virtcol needs to be valid. |
| 2478 | * |
| 2479 | * Return the number of last row the line occupies. |
| 2480 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2481 | /* ARGSUSED */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2482 | static int |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2483 | win_line(wp, lnum, startrow, endrow, nochange) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2484 | win_T *wp; |
| 2485 | linenr_T lnum; |
| 2486 | int startrow; |
| 2487 | int endrow; |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2488 | int nochange; /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2489 | { |
| 2490 | int col; /* visual column on screen */ |
| 2491 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2492 | int c = 0; /* init for GCC */ |
| 2493 | long vcol = 0; /* virtual column (for tabs) */ |
| 2494 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2495 | char_u *line; /* current line */ |
| 2496 | char_u *ptr; /* current position in "line" */ |
| 2497 | int row; /* row in the window, excl w_winrow */ |
| 2498 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2499 | |
| 2500 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2501 | int n_extra = 0; /* number of extra chars */ |
| 2502 | char_u *p_extra = NULL; /* string of extra chars */ |
| 2503 | int c_extra = NUL; /* extra chars, all the same */ |
| 2504 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2505 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2506 | displaying lcs_eol at end-of-line */ |
| 2507 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2508 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2509 | |
| 2510 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2511 | int saved_n_extra = 0; |
| 2512 | char_u *saved_p_extra = NULL; |
| 2513 | int saved_c_extra = 0; |
| 2514 | int saved_char_attr = 0; |
| 2515 | |
| 2516 | int n_attr = 0; /* chars with special attr */ |
| 2517 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2518 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2519 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2520 | |
| 2521 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2522 | |
| 2523 | int fromcol, tocol; /* start/end of inverting */ |
| 2524 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2525 | int noinvcur = FALSE; /* don't invert the cursor */ |
| 2526 | #ifdef FEAT_VISUAL |
| 2527 | pos_T *top, *bot; |
| 2528 | #endif |
| 2529 | pos_T pos; |
| 2530 | long v; |
| 2531 | |
| 2532 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2533 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2534 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2535 | in this line */ |
| 2536 | int attr = 0; /* attributes for area highlighting */ |
| 2537 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2538 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2539 | #ifdef FEAT_SYN_HL |
| 2540 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2541 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2542 | int save_did_emsg; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2543 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2544 | # define SPWORDLEN 150 |
| 2545 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2546 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2547 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2548 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2549 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2550 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2551 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2552 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2553 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2554 | static int cap_col = -1; /* column to check for Cap word */ |
| 2555 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2556 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2557 | #endif |
| 2558 | int extra_check; /* has syntax or linebreak */ |
| 2559 | #ifdef FEAT_MBYTE |
| 2560 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2561 | int mb_l = 1; /* multi-byte byte length */ |
| 2562 | int mb_c = 0; /* decoded multi-byte character */ |
| 2563 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
| 2564 | int u8c_c1 = 0; /* first composing UTF-8 char */ |
| 2565 | int u8c_c2 = 0; /* second composing UTF-8 char */ |
| 2566 | #endif |
| 2567 | #ifdef FEAT_DIFF |
| 2568 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2569 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2570 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2571 | int change_start = MAXCOL; /* first col of changed area */ |
| 2572 | int change_end = -1; /* last col of changed area */ |
| 2573 | #endif |
| 2574 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2575 | #ifdef FEAT_LINEBREAK |
| 2576 | int need_showbreak = FALSE; |
| 2577 | #endif |
| 2578 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) |
| 2579 | # define LINE_ATTR |
| 2580 | int line_attr = 0; /* atrribute for the whole line */ |
| 2581 | #endif |
| 2582 | #ifdef FEAT_SEARCH_EXTRA |
| 2583 | match_T *shl; /* points to search_hl or match_hl */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 2584 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2585 | #endif |
| 2586 | #ifdef FEAT_ARABIC |
| 2587 | int prev_c = 0; /* previous Arabic character */ |
| 2588 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2589 | #endif |
| 2590 | |
| 2591 | /* draw_state: items that are drawn in sequence: */ |
| 2592 | #define WL_START 0 /* nothing done yet */ |
| 2593 | #ifdef FEAT_CMDWIN |
| 2594 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 2595 | #else |
| 2596 | # define WL_CMDLINE WL_START |
| 2597 | #endif |
| 2598 | #ifdef FEAT_FOLDING |
| 2599 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 2600 | #else |
| 2601 | # define WL_FOLD WL_CMDLINE |
| 2602 | #endif |
| 2603 | #ifdef FEAT_SIGNS |
| 2604 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 2605 | #else |
| 2606 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 2607 | #endif |
| 2608 | #define WL_NR WL_SIGN + 1 /* line number */ |
| 2609 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 2610 | # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ |
| 2611 | #else |
| 2612 | # define WL_SBR WL_NR |
| 2613 | #endif |
| 2614 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 2615 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 2616 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2617 | int feedback_col = 0; |
| 2618 | int feedback_old_attr = -1; |
| 2619 | #endif |
| 2620 | |
| 2621 | |
| 2622 | if (startrow > endrow) /* past the end already! */ |
| 2623 | return startrow; |
| 2624 | |
| 2625 | row = startrow; |
| 2626 | screen_row = row + W_WINROW(wp); |
| 2627 | |
| 2628 | /* |
| 2629 | * To speed up the loop below, set extra_check when there is linebreak, |
| 2630 | * trailing white space and/or syntax processing to be done. |
| 2631 | */ |
| 2632 | #ifdef FEAT_LINEBREAK |
| 2633 | extra_check = wp->w_p_lbr; |
| 2634 | #else |
| 2635 | extra_check = 0; |
| 2636 | #endif |
| 2637 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 2638 | if (syntax_present(wp->w_buffer) && !wp->w_buffer->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2639 | { |
| 2640 | /* Prepare for syntax highlighting in this line. When there is an |
| 2641 | * error, stop syntax highlighting. */ |
| 2642 | save_did_emsg = did_emsg; |
| 2643 | did_emsg = FALSE; |
| 2644 | syntax_start(wp, lnum); |
| 2645 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 2646 | wp->w_buffer->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2647 | else |
| 2648 | { |
| 2649 | did_emsg = save_did_emsg; |
| 2650 | has_syntax = TRUE; |
| 2651 | extra_check = TRUE; |
| 2652 | } |
| 2653 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2654 | |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 2655 | if (wp->w_p_spell |
| 2656 | && *wp->w_buffer->b_p_spl != NUL |
| 2657 | && wp->w_buffer->b_langp.ga_len > 0 |
| 2658 | && *(char **)(wp->w_buffer->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2659 | { |
| 2660 | /* Prepare for spell checking. */ |
| 2661 | has_spell = TRUE; |
| 2662 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2663 | |
| 2664 | /* Get the start of the next line, so that words that wrap to the next |
| 2665 | * line are found too: "et<line-break>al.". |
| 2666 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 2667 | nextline[SPWORDLEN] = NUL; |
| 2668 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 2669 | { |
| 2670 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 2671 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 2672 | } |
| 2673 | |
| 2674 | /* When a word wrapped from the previous line the start of the current |
| 2675 | * line is valid. */ |
| 2676 | if (lnum == checked_lnum) |
| 2677 | cur_checked_col = checked_col; |
| 2678 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2679 | |
| 2680 | /* When there was a sentence end in the previous line may require a |
| 2681 | * word starting with capital in this line. In line 1 always check |
| 2682 | * the first word. */ |
| 2683 | if (lnum != capcol_lnum) |
| 2684 | cap_col = -1; |
| 2685 | if (lnum == 1) |
| 2686 | cap_col = 0; |
| 2687 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2688 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2689 | #endif |
| 2690 | |
| 2691 | /* |
| 2692 | * handle visual active in this window |
| 2693 | */ |
| 2694 | fromcol = -10; |
| 2695 | tocol = MAXCOL; |
| 2696 | #ifdef FEAT_VISUAL |
| 2697 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2698 | { |
| 2699 | /* Visual is after curwin->w_cursor */ |
| 2700 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2701 | { |
| 2702 | top = &curwin->w_cursor; |
| 2703 | bot = &VIsual; |
| 2704 | } |
| 2705 | else /* Visual is before curwin->w_cursor */ |
| 2706 | { |
| 2707 | top = &VIsual; |
| 2708 | bot = &curwin->w_cursor; |
| 2709 | } |
| 2710 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 2711 | { |
| 2712 | if (lnum >= top->lnum && lnum <= bot->lnum) |
| 2713 | { |
| 2714 | fromcol = wp->w_old_cursor_fcol; |
| 2715 | tocol = wp->w_old_cursor_lcol; |
| 2716 | } |
| 2717 | } |
| 2718 | else /* non-block mode */ |
| 2719 | { |
| 2720 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 2721 | fromcol = 0; |
| 2722 | else if (lnum == top->lnum) |
| 2723 | { |
| 2724 | if (VIsual_mode == 'V') /* linewise */ |
| 2725 | fromcol = 0; |
| 2726 | else |
| 2727 | { |
| 2728 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 2729 | if (gchar_pos(top) == NUL) |
| 2730 | tocol = fromcol + 1; |
| 2731 | } |
| 2732 | } |
| 2733 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 2734 | { |
| 2735 | if (*p_sel == 'e' && bot->col == 0 |
| 2736 | #ifdef FEAT_VIRTUALEDIT |
| 2737 | && bot->coladd == 0 |
| 2738 | #endif |
| 2739 | ) |
| 2740 | { |
| 2741 | fromcol = -10; |
| 2742 | tocol = MAXCOL; |
| 2743 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2744 | else if (bot->col == MAXCOL) |
| 2745 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2746 | else |
| 2747 | { |
| 2748 | pos = *bot; |
| 2749 | if (*p_sel == 'e') |
| 2750 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2751 | else |
| 2752 | { |
| 2753 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 2754 | ++tocol; |
| 2755 | } |
| 2756 | } |
| 2757 | } |
| 2758 | } |
| 2759 | |
| 2760 | #ifndef MSDOS |
| 2761 | /* Check if the character under the cursor should not be inverted */ |
| 2762 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
| 2763 | # ifdef FEAT_GUI |
| 2764 | && !gui.in_use |
| 2765 | # endif |
| 2766 | ) |
| 2767 | noinvcur = TRUE; |
| 2768 | #endif |
| 2769 | |
| 2770 | /* if inverting in this line set area_highlighting */ |
| 2771 | if (fromcol >= 0) |
| 2772 | { |
| 2773 | area_highlighting = TRUE; |
| 2774 | attr = hl_attr(HLF_V); |
| 2775 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
| 2776 | if (clip_star.available && !clip_star.owned && clip_isautosel()) |
| 2777 | attr = hl_attr(HLF_VNC); |
| 2778 | #endif |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2783 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2784 | */ |
| 2785 | else |
| 2786 | #endif /* FEAT_VISUAL */ |
| 2787 | if (highlight_match |
| 2788 | && wp == curwin |
| 2789 | && lnum >= curwin->w_cursor.lnum |
| 2790 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 2791 | { |
| 2792 | if (lnum == curwin->w_cursor.lnum) |
| 2793 | getvcol(curwin, &(curwin->w_cursor), |
| 2794 | (colnr_T *)&fromcol, NULL, NULL); |
| 2795 | else |
| 2796 | fromcol = 0; |
| 2797 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 2798 | { |
| 2799 | pos.lnum = lnum; |
| 2800 | pos.col = search_match_endcol; |
| 2801 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2802 | } |
| 2803 | else |
| 2804 | tocol = MAXCOL; |
| 2805 | if (fromcol == tocol) /* do at least one character */ |
| 2806 | tocol = fromcol + 1; /* happens when past end of line */ |
| 2807 | area_highlighting = TRUE; |
| 2808 | attr = hl_attr(HLF_I); |
| 2809 | } |
| 2810 | |
| 2811 | #ifdef FEAT_DIFF |
| 2812 | filler_lines = diff_check(wp, lnum); |
| 2813 | if (filler_lines < 0) |
| 2814 | { |
| 2815 | if (filler_lines == -1) |
| 2816 | { |
| 2817 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 2818 | diff_hlf = HLF_ADD; /* added line */ |
| 2819 | else if (change_start == 0) |
| 2820 | diff_hlf = HLF_TXD; /* changed text */ |
| 2821 | else |
| 2822 | diff_hlf = HLF_CHD; /* changed line */ |
| 2823 | } |
| 2824 | else |
| 2825 | diff_hlf = HLF_ADD; /* added line */ |
| 2826 | filler_lines = 0; |
| 2827 | area_highlighting = TRUE; |
| 2828 | } |
| 2829 | if (lnum == wp->w_topline) |
| 2830 | filler_lines = wp->w_topfill; |
| 2831 | filler_todo = filler_lines; |
| 2832 | #endif |
| 2833 | |
| 2834 | #ifdef LINE_ATTR |
| 2835 | # ifdef FEAT_SIGNS |
| 2836 | /* If this line has a sign with line highlighting set line_attr. */ |
| 2837 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 2838 | if (v != 0) |
| 2839 | line_attr = sign_get_attr((int)v, TRUE); |
| 2840 | # endif |
| 2841 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 2842 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 2843 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2844 | line_attr = hl_attr(HLF_L); |
| 2845 | # endif |
| 2846 | if (line_attr != 0) |
| 2847 | area_highlighting = TRUE; |
| 2848 | #endif |
| 2849 | |
| 2850 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 2851 | ptr = line; |
| 2852 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2853 | #ifdef FEAT_SYN_HL |
| 2854 | if (has_spell) |
| 2855 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2856 | /* For checking first word with a capital skip white space. */ |
| 2857 | if (cap_col == 0) |
| 2858 | cap_col = skipwhite(line) - line; |
| 2859 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2860 | /* To be able to spell-check over line boundaries copy the end of the |
| 2861 | * current line into nextline[]. Above the start of the next line was |
| 2862 | * copied to nextline[SPWORDLEN]. */ |
| 2863 | if (nextline[SPWORDLEN] == NUL) |
| 2864 | { |
| 2865 | /* No next line or it is empty. */ |
| 2866 | nextlinecol = MAXCOL; |
| 2867 | nextline_idx = 0; |
| 2868 | } |
| 2869 | else |
| 2870 | { |
| 2871 | v = STRLEN(line); |
| 2872 | if (v < SPWORDLEN) |
| 2873 | { |
| 2874 | /* Short line, use it completely and append the start of the |
| 2875 | * next line. */ |
| 2876 | nextlinecol = 0; |
| 2877 | mch_memmove(nextline, line, (size_t)v); |
| 2878 | mch_memmove(nextline + v, nextline + SPWORDLEN, |
| 2879 | STRLEN(nextline + SPWORDLEN) + 1); |
| 2880 | nextline_idx = v + 1; |
| 2881 | } |
| 2882 | else |
| 2883 | { |
| 2884 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 2885 | nextlinecol = v - SPWORDLEN; |
| 2886 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 2887 | nextline_idx = SPWORDLEN + 1; |
| 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | #endif |
| 2892 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2893 | /* find start of trailing whitespace */ |
| 2894 | if (wp->w_p_list && lcs_trail) |
| 2895 | { |
| 2896 | trailcol = (colnr_T)STRLEN(ptr); |
| 2897 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 2898 | --trailcol; |
| 2899 | trailcol += (colnr_T) (ptr - line); |
| 2900 | extra_check = TRUE; |
| 2901 | } |
| 2902 | |
| 2903 | /* |
| 2904 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 2905 | * first character to be displayed. |
| 2906 | */ |
| 2907 | if (wp->w_p_wrap) |
| 2908 | v = wp->w_skipcol; |
| 2909 | else |
| 2910 | v = wp->w_leftcol; |
| 2911 | if (v > 0) |
| 2912 | { |
| 2913 | #ifdef FEAT_MBYTE |
| 2914 | char_u *prev_ptr = ptr; |
| 2915 | #endif |
| 2916 | while (vcol < v && *ptr != NUL) |
| 2917 | { |
| 2918 | c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); |
| 2919 | vcol += c; |
| 2920 | #ifdef FEAT_MBYTE |
| 2921 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2922 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 2923 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | #ifdef FEAT_VIRTUALEDIT |
| 2927 | /* When 'virtualedit' is set the end of the line may be before the |
| 2928 | * start of the displayed part. */ |
| 2929 | if (vcol < v && *ptr == NUL && virtual_active()) |
| 2930 | vcol = v; |
| 2931 | #endif |
| 2932 | |
| 2933 | /* Handle a character that's not completely on the screen: Put ptr at |
| 2934 | * that character but skip the first few screen characters. */ |
| 2935 | if (vcol > v) |
| 2936 | { |
| 2937 | vcol -= c; |
| 2938 | #ifdef FEAT_MBYTE |
| 2939 | ptr = prev_ptr; |
| 2940 | #else |
| 2941 | --ptr; |
| 2942 | #endif |
| 2943 | n_skip = v - vcol; |
| 2944 | } |
| 2945 | |
| 2946 | /* |
| 2947 | * Adjust for when the inverted text is before the screen, |
| 2948 | * and when the start of the inverted text is before the screen. |
| 2949 | */ |
| 2950 | if (tocol <= vcol) |
| 2951 | fromcol = 0; |
| 2952 | else if (fromcol >= 0 && fromcol < vcol) |
| 2953 | fromcol = vcol; |
| 2954 | |
| 2955 | #ifdef FEAT_LINEBREAK |
| 2956 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 2957 | if (wp->w_p_wrap) |
| 2958 | need_showbreak = TRUE; |
| 2959 | #endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 2960 | #ifdef FEAT_SYN_HL |
| 2961 | /* When spell checking a word we need to figure out the start of the |
| 2962 | * word and if it's badly spelled or not. */ |
| 2963 | if (has_spell) |
| 2964 | { |
| 2965 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2966 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 2967 | |
| 2968 | pos = wp->w_cursor; |
| 2969 | wp->w_cursor.lnum = lnum; |
| 2970 | wp->w_cursor.col = ptr - line; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2971 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 2972 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 2973 | { |
| 2974 | /* no bad word found at line start, don't check until end of a |
| 2975 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2976 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 2977 | word_end = spell_to_word_end(ptr, wp->w_buffer) - line + 1; |
| 2978 | } |
| 2979 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2980 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 2981 | /* bad word found, use attributes until end of word */ |
| 2982 | word_end = wp->w_cursor.col + len + 1; |
| 2983 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2984 | /* Turn index into actual attributes. */ |
| 2985 | if (spell_hlf != HLF_COUNT) |
| 2986 | spell_attr = highlight_attr[spell_hlf]; |
| 2987 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 2988 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 2989 | |
| 2990 | /* Need to restart syntax highlighting for this line. */ |
| 2991 | if (has_syntax) |
| 2992 | syntax_start(wp, lnum); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 2993 | } |
| 2994 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | /* |
| 2998 | * Correct highlighting for cursor that can't be disabled. |
| 2999 | * Avoids having to check this for each character. |
| 3000 | */ |
| 3001 | if (fromcol >= 0) |
| 3002 | { |
| 3003 | if (noinvcur) |
| 3004 | { |
| 3005 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3006 | { |
| 3007 | /* highlighting starts at cursor, let it start just after the |
| 3008 | * cursor */ |
| 3009 | fromcol_prev = fromcol; |
| 3010 | fromcol = -1; |
| 3011 | } |
| 3012 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3013 | /* restart highlighting after the cursor */ |
| 3014 | fromcol_prev = wp->w_virtcol; |
| 3015 | } |
| 3016 | if (fromcol >= tocol) |
| 3017 | fromcol = -1; |
| 3018 | } |
| 3019 | |
| 3020 | #ifdef FEAT_SEARCH_EXTRA |
| 3021 | /* |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3022 | * Handle highlighting the last used search pattern and ":match". |
| 3023 | * Do this for both search_hl and match_hl[3]. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3024 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3025 | for (i = 3; i >= 0; --i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3026 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3027 | shl = (i == 3) ? &search_hl : &match_hl[i]; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3028 | shl->startcol = MAXCOL; |
| 3029 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3030 | shl->attr_cur = 0; |
| 3031 | if (shl->rm.regprog != NULL) |
| 3032 | { |
| 3033 | v = (long)(ptr - line); |
| 3034 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3035 | |
| 3036 | /* Need to get the line again, a multi-line regexp may have made it |
| 3037 | * invalid. */ |
| 3038 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3039 | ptr = line + v; |
| 3040 | |
| 3041 | if (shl->lnum != 0 && shl->lnum <= lnum) |
| 3042 | { |
| 3043 | if (shl->lnum == lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3044 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3045 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3046 | shl->startcol = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3047 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3048 | - shl->rm.startpos[0].lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3049 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3050 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3051 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3052 | /* Highlight one character for an empty match. */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3053 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3054 | { |
| 3055 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3056 | if (has_mbyte && line[shl->endcol] != NUL) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3057 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3058 | else |
| 3059 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3060 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3061 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3062 | if ((long)shl->startcol < v) /* match at leftcol */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3063 | { |
| 3064 | shl->attr_cur = shl->attr; |
| 3065 | search_attr = shl->attr; |
| 3066 | } |
| 3067 | area_highlighting = TRUE; |
| 3068 | } |
| 3069 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3070 | } |
| 3071 | #endif |
| 3072 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3073 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3074 | col = 0; |
| 3075 | #ifdef FEAT_RIGHTLEFT |
| 3076 | if (wp->w_p_rl) |
| 3077 | { |
| 3078 | /* Rightleft window: process the text in the normal direction, but put |
| 3079 | * it in current_ScreenLine[] from right to left. Start at the |
| 3080 | * rightmost column of the window. */ |
| 3081 | col = W_WIDTH(wp) - 1; |
| 3082 | off += col; |
| 3083 | } |
| 3084 | #endif |
| 3085 | |
| 3086 | /* |
| 3087 | * Repeat for the whole displayed line. |
| 3088 | */ |
| 3089 | for (;;) |
| 3090 | { |
| 3091 | /* Skip this quickly when working on the text. */ |
| 3092 | if (draw_state != WL_LINE) |
| 3093 | { |
| 3094 | #ifdef FEAT_CMDWIN |
| 3095 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3096 | { |
| 3097 | draw_state = WL_CMDLINE; |
| 3098 | if (cmdwin_type != 0 && wp == curwin) |
| 3099 | { |
| 3100 | /* Draw the cmdline character. */ |
| 3101 | *extra = cmdwin_type; |
| 3102 | n_extra = 1; |
| 3103 | p_extra = extra; |
| 3104 | c_extra = NUL; |
| 3105 | char_attr = hl_attr(HLF_AT); |
| 3106 | } |
| 3107 | } |
| 3108 | #endif |
| 3109 | |
| 3110 | #ifdef FEAT_FOLDING |
| 3111 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3112 | { |
| 3113 | draw_state = WL_FOLD; |
| 3114 | if (wp->w_p_fdc > 0) |
| 3115 | { |
| 3116 | /* Draw the 'foldcolumn'. */ |
| 3117 | fill_foldcolumn(extra, wp, FALSE, lnum); |
| 3118 | n_extra = wp->w_p_fdc; |
| 3119 | p_extra = extra; |
| 3120 | c_extra = NUL; |
| 3121 | char_attr = hl_attr(HLF_FC); |
| 3122 | } |
| 3123 | } |
| 3124 | #endif |
| 3125 | |
| 3126 | #ifdef FEAT_SIGNS |
| 3127 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3128 | { |
| 3129 | draw_state = WL_SIGN; |
| 3130 | /* Show the sign column when there are any signs in this |
| 3131 | * buffer or when using Netbeans. */ |
| 3132 | if (draw_signcolumn(wp) |
| 3133 | # ifdef FEAT_DIFF |
| 3134 | && filler_todo <= 0 |
| 3135 | # endif |
| 3136 | ) |
| 3137 | { |
| 3138 | int_u text_sign; |
| 3139 | # ifdef FEAT_SIGN_ICONS |
| 3140 | int_u icon_sign; |
| 3141 | # endif |
| 3142 | |
| 3143 | /* Draw two cells with the sign value or blank. */ |
| 3144 | c_extra = ' '; |
| 3145 | char_attr = hl_attr(HLF_SC); |
| 3146 | n_extra = 2; |
| 3147 | |
| 3148 | if (row == startrow) |
| 3149 | { |
| 3150 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3151 | SIGN_TEXT); |
| 3152 | # ifdef FEAT_SIGN_ICONS |
| 3153 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3154 | SIGN_ICON); |
| 3155 | if (gui.in_use && icon_sign != 0) |
| 3156 | { |
| 3157 | /* Use the image in this position. */ |
| 3158 | c_extra = SIGN_BYTE; |
| 3159 | # ifdef FEAT_NETBEANS_INTG |
| 3160 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3161 | c_extra = MULTISIGN_BYTE; |
| 3162 | # endif |
| 3163 | char_attr = icon_sign; |
| 3164 | } |
| 3165 | else |
| 3166 | # endif |
| 3167 | if (text_sign != 0) |
| 3168 | { |
| 3169 | p_extra = sign_get_text(text_sign); |
| 3170 | if (p_extra != NULL) |
| 3171 | { |
| 3172 | c_extra = NUL; |
| 3173 | n_extra = STRLEN(p_extra); |
| 3174 | } |
| 3175 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3176 | } |
| 3177 | } |
| 3178 | } |
| 3179 | } |
| 3180 | #endif |
| 3181 | |
| 3182 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3183 | { |
| 3184 | draw_state = WL_NR; |
| 3185 | /* Display the line number. After the first fill with blanks |
| 3186 | * when the 'n' flag isn't in 'cpo' */ |
| 3187 | if (wp->w_p_nu |
| 3188 | && (row == startrow |
| 3189 | #ifdef FEAT_DIFF |
| 3190 | + filler_lines |
| 3191 | #endif |
| 3192 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3193 | { |
| 3194 | /* Draw the line number (empty space after wrapping). */ |
| 3195 | if (row == startrow |
| 3196 | #ifdef FEAT_DIFF |
| 3197 | + filler_lines |
| 3198 | #endif |
| 3199 | ) |
| 3200 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3201 | sprintf((char *)extra, "%*ld ", |
| 3202 | number_width(wp), (long)lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3203 | if (wp->w_skipcol > 0) |
| 3204 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3205 | *p_extra = '-'; |
| 3206 | #ifdef FEAT_RIGHTLEFT |
| 3207 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3208 | rl_mirror(extra); |
| 3209 | #endif |
| 3210 | p_extra = extra; |
| 3211 | c_extra = NUL; |
| 3212 | } |
| 3213 | else |
| 3214 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3215 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3216 | char_attr = hl_attr(HLF_N); |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3221 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3222 | { |
| 3223 | draw_state = WL_SBR; |
| 3224 | # ifdef FEAT_DIFF |
| 3225 | if (filler_todo > 0) |
| 3226 | { |
| 3227 | /* Draw "deleted" diff line(s). */ |
| 3228 | if (char2cells(fill_diff) > 1) |
| 3229 | c_extra = '-'; |
| 3230 | else |
| 3231 | c_extra = fill_diff; |
| 3232 | # ifdef FEAT_RIGHTLEFT |
| 3233 | if (wp->w_p_rl) |
| 3234 | n_extra = col + 1; |
| 3235 | else |
| 3236 | # endif |
| 3237 | n_extra = W_WIDTH(wp) - col; |
| 3238 | char_attr = hl_attr(HLF_DED); |
| 3239 | } |
| 3240 | # endif |
| 3241 | # ifdef FEAT_LINEBREAK |
| 3242 | if (*p_sbr != NUL && need_showbreak) |
| 3243 | { |
| 3244 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3245 | p_extra = p_sbr; |
| 3246 | c_extra = NUL; |
| 3247 | n_extra = (int)STRLEN(p_sbr); |
| 3248 | char_attr = hl_attr(HLF_AT); |
| 3249 | need_showbreak = FALSE; |
| 3250 | /* Correct end of highlighted area for 'showbreak', |
| 3251 | * required when 'linebreak' is also set. */ |
| 3252 | if (tocol == vcol) |
| 3253 | tocol += n_extra; |
| 3254 | } |
| 3255 | # endif |
| 3256 | } |
| 3257 | #endif |
| 3258 | |
| 3259 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3260 | { |
| 3261 | draw_state = WL_LINE; |
| 3262 | if (saved_n_extra) |
| 3263 | { |
| 3264 | /* Continue item from end of wrapped line. */ |
| 3265 | n_extra = saved_n_extra; |
| 3266 | c_extra = saved_c_extra; |
| 3267 | p_extra = saved_p_extra; |
| 3268 | char_attr = saved_char_attr; |
| 3269 | } |
| 3270 | else |
| 3271 | char_attr = 0; |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | /* When still displaying '$' of change command, stop at cursor */ |
| 3276 | if (dollar_vcol != 0 && wp == curwin && vcol >= (long)wp->w_virtcol |
| 3277 | #ifdef FEAT_DIFF |
| 3278 | && filler_todo <= 0 |
| 3279 | #endif |
| 3280 | ) |
| 3281 | { |
| 3282 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3283 | wp->w_p_rl); |
| 3284 | /* Pretend we have finished updating the window. */ |
| 3285 | row = wp->w_height; |
| 3286 | break; |
| 3287 | } |
| 3288 | |
| 3289 | if (draw_state == WL_LINE && area_highlighting) |
| 3290 | { |
| 3291 | /* handle Visual or match highlighting in this line */ |
| 3292 | if (vcol == fromcol |
| 3293 | #ifdef FEAT_MBYTE |
| 3294 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3295 | && (*mb_ptr2cells)(ptr) > 1) |
| 3296 | #endif |
| 3297 | || ((int)vcol_prev == fromcol_prev |
| 3298 | && vcol < tocol)) |
| 3299 | area_attr = attr; /* start highlighting */ |
| 3300 | else if (area_attr != 0 |
| 3301 | && (vcol == tocol |
| 3302 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3303 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3304 | |
| 3305 | #ifdef FEAT_SEARCH_EXTRA |
| 3306 | if (!n_extra) |
| 3307 | { |
| 3308 | /* |
| 3309 | * Check for start/end of search pattern match. |
| 3310 | * After end, check for start/end of next match. |
| 3311 | * When another match, have to check for start again. |
| 3312 | * Watch out for matching an empty string! |
| 3313 | * Do this first for search_hl, then for match_hl, so that |
| 3314 | * ":match" overrules 'hlsearch'. |
| 3315 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3316 | v = (long)(ptr - line); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3317 | for (i = 3; i >= 0; --i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3318 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3319 | shl = (i == 3) ? &search_hl : &match_hl[i]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3320 | while (shl->rm.regprog != NULL) |
| 3321 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3322 | if (shl->startcol != MAXCOL |
| 3323 | && v >= (long)shl->startcol |
| 3324 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3325 | { |
| 3326 | shl->attr_cur = shl->attr; |
| 3327 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3328 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3329 | { |
| 3330 | shl->attr_cur = 0; |
| 3331 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3332 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3333 | |
| 3334 | /* Need to get the line again, a multi-line regexp |
| 3335 | * may have made it invalid. */ |
| 3336 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3337 | ptr = line + v; |
| 3338 | |
| 3339 | if (shl->lnum == lnum) |
| 3340 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3341 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3342 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3343 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3344 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3345 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3346 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3347 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3348 | { |
| 3349 | /* highlight empty match, try again after |
| 3350 | * it */ |
| 3351 | #ifdef FEAT_MBYTE |
| 3352 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3353 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3354 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3355 | else |
| 3356 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3357 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /* Loop to check if the match starts at the |
| 3361 | * current position */ |
| 3362 | continue; |
| 3363 | } |
| 3364 | } |
| 3365 | break; |
| 3366 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3367 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3368 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3369 | /* ":match" highlighting overrules 'hlsearch' */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3370 | for (i = 0; i <= 3; ++i) |
| 3371 | if (i == 3) |
| 3372 | search_attr = search_hl.attr_cur; |
| 3373 | else if (match_hl[i].attr_cur != 0) |
| 3374 | { |
| 3375 | search_attr = match_hl[i].attr_cur; |
| 3376 | break; |
| 3377 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3378 | } |
| 3379 | #endif |
| 3380 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3381 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3382 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3383 | { |
| 3384 | if (diff_hlf == HLF_CHD && ptr - line >= change_start) |
| 3385 | diff_hlf = HLF_TXD; /* changed text */ |
| 3386 | if (diff_hlf == HLF_TXD && ptr - line > change_end) |
| 3387 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3388 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3389 | } |
| 3390 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3391 | |
| 3392 | /* Decide which of the highlight attributes to use. */ |
| 3393 | attr_pri = TRUE; |
| 3394 | if (area_attr != 0) |
| 3395 | char_attr = area_attr; |
| 3396 | else if (search_attr != 0) |
| 3397 | char_attr = search_attr; |
| 3398 | #ifdef LINE_ATTR |
| 3399 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 3400 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 3401 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
| 3402 | || (vcol < fromcol || vcol >= tocol))) |
| 3403 | char_attr = line_attr; |
| 3404 | #endif |
| 3405 | else |
| 3406 | { |
| 3407 | attr_pri = FALSE; |
| 3408 | #ifdef FEAT_SYN_HL |
| 3409 | if (has_syntax) |
| 3410 | char_attr = syntax_attr; |
| 3411 | else |
| 3412 | #endif |
| 3413 | char_attr = 0; |
| 3414 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | /* |
| 3418 | * Get the next character to put on the screen. |
| 3419 | */ |
| 3420 | /* |
| 3421 | * The 'extra' array contains the extra stuff that is inserted to |
| 3422 | * represent special characters (non-printable stuff). When all |
| 3423 | * characters are the same, c_extra is used. |
| 3424 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 3425 | */ |
| 3426 | if (n_extra > 0) |
| 3427 | { |
| 3428 | if (c_extra != NUL) |
| 3429 | { |
| 3430 | c = c_extra; |
| 3431 | #ifdef FEAT_MBYTE |
| 3432 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 3433 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3434 | { |
| 3435 | mb_utf8 = TRUE; |
| 3436 | u8c_c1 = u8c_c2 = 0; |
| 3437 | } |
| 3438 | else |
| 3439 | mb_utf8 = FALSE; |
| 3440 | #endif |
| 3441 | } |
| 3442 | else |
| 3443 | { |
| 3444 | c = *p_extra; |
| 3445 | #ifdef FEAT_MBYTE |
| 3446 | if (has_mbyte) |
| 3447 | { |
| 3448 | mb_c = c; |
| 3449 | if (enc_utf8) |
| 3450 | { |
| 3451 | /* If the UTF-8 character is more than one byte: |
| 3452 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3453 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3454 | mb_utf8 = FALSE; |
| 3455 | if (mb_l > n_extra) |
| 3456 | mb_l = 1; |
| 3457 | else if (mb_l > 1) |
| 3458 | { |
| 3459 | mb_c = utfc_ptr2char(p_extra, &u8c_c1, &u8c_c2); |
| 3460 | mb_utf8 = TRUE; |
| 3461 | } |
| 3462 | } |
| 3463 | else |
| 3464 | { |
| 3465 | /* if this is a DBCS character, put it in "mb_c" */ |
| 3466 | mb_l = MB_BYTE2LEN(c); |
| 3467 | if (mb_l >= n_extra) |
| 3468 | mb_l = 1; |
| 3469 | else if (mb_l > 1) |
| 3470 | mb_c = (c << 8) + p_extra[1]; |
| 3471 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3472 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3473 | mb_l = 1; |
| 3474 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3475 | /* If a double-width char doesn't fit display a '>' in the |
| 3476 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3477 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3478 | # ifdef FEAT_RIGHTLEFT |
| 3479 | wp->w_p_rl ? (col <= 0) : |
| 3480 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3481 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3482 | && (*mb_char2cells)(mb_c) == 2) |
| 3483 | { |
| 3484 | c = '>'; |
| 3485 | mb_c = c; |
| 3486 | mb_l = 1; |
| 3487 | mb_utf8 = FALSE; |
| 3488 | multi_attr = hl_attr(HLF_AT); |
| 3489 | /* put the pointer back to output the double-width |
| 3490 | * character at the start of the next line. */ |
| 3491 | ++n_extra; |
| 3492 | --p_extra; |
| 3493 | } |
| 3494 | else |
| 3495 | { |
| 3496 | n_extra -= mb_l - 1; |
| 3497 | p_extra += mb_l - 1; |
| 3498 | } |
| 3499 | } |
| 3500 | #endif |
| 3501 | ++p_extra; |
| 3502 | } |
| 3503 | --n_extra; |
| 3504 | } |
| 3505 | else |
| 3506 | { |
| 3507 | /* |
| 3508 | * Get a character from the line itself. |
| 3509 | */ |
| 3510 | c = *ptr; |
| 3511 | #ifdef FEAT_MBYTE |
| 3512 | if (has_mbyte) |
| 3513 | { |
| 3514 | mb_c = c; |
| 3515 | if (enc_utf8) |
| 3516 | { |
| 3517 | /* If the UTF-8 character is more than one byte: Decode it |
| 3518 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3519 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3520 | mb_utf8 = FALSE; |
| 3521 | if (mb_l > 1) |
| 3522 | { |
| 3523 | mb_c = utfc_ptr2char(ptr, &u8c_c1, &u8c_c2); |
| 3524 | /* Overlong encoded ASCII or ASCII with composing char |
| 3525 | * is displayed normally, except a NUL. */ |
| 3526 | if (mb_c < 0x80) |
| 3527 | c = mb_c; |
| 3528 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3529 | |
| 3530 | /* At start of the line we can have a composing char. |
| 3531 | * Draw it as a space with a composing char. */ |
| 3532 | if (utf_iscomposing(mb_c)) |
| 3533 | { |
| 3534 | u8c_c2 = u8c_c1; |
| 3535 | u8c_c1 = mb_c; |
| 3536 | mb_c = ' '; |
| 3537 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | if ((mb_l == 1 && c >= 0x80) |
| 3541 | || (mb_l >= 1 && mb_c == 0) |
| 3542 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
| 3543 | || mb_c >= 0x10000))) |
| 3544 | { |
| 3545 | /* |
| 3546 | * Illegal UTF-8 byte: display as <xx>. |
| 3547 | * Non-BMP character : display as ? or fullwidth ?. |
| 3548 | */ |
| 3549 | if (mb_c < 0x10000) |
| 3550 | { |
| 3551 | transchar_hex(extra, mb_c); |
| 3552 | #ifdef FEAT_RIGHTLEFT |
| 3553 | if (wp->w_p_rl) /* reverse */ |
| 3554 | rl_mirror(extra); |
| 3555 | #endif |
| 3556 | } |
| 3557 | else if (utf_char2cells(mb_c) != 2) |
| 3558 | STRCPY(extra, "?"); |
| 3559 | else |
| 3560 | /* 0xff1f in UTF-8: full-width '?' */ |
| 3561 | STRCPY(extra, "\357\274\237"); |
| 3562 | |
| 3563 | p_extra = extra; |
| 3564 | c = *p_extra; |
| 3565 | mb_c = mb_ptr2char_adv(&p_extra); |
| 3566 | mb_utf8 = (c >= 0x80); |
| 3567 | n_extra = (int)STRLEN(p_extra); |
| 3568 | c_extra = NUL; |
| 3569 | if (area_attr == 0 && search_attr == 0) |
| 3570 | { |
| 3571 | n_attr = n_extra + 1; |
| 3572 | extra_attr = hl_attr(HLF_8); |
| 3573 | saved_attr2 = char_attr; /* save current attr */ |
| 3574 | } |
| 3575 | } |
| 3576 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3577 | mb_l = 1; |
| 3578 | #ifdef FEAT_ARABIC |
| 3579 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 3580 | { |
| 3581 | /* Do Arabic shaping. */ |
| 3582 | int pc, pc1, nc, dummy; |
| 3583 | |
| 3584 | /* The idea of what is the previous and next |
| 3585 | * character depends on 'rightleft'. */ |
| 3586 | if (wp->w_p_rl) |
| 3587 | { |
| 3588 | pc = prev_c; |
| 3589 | pc1 = prev_c1; |
| 3590 | nc = utf_ptr2char(ptr + mb_l); |
| 3591 | prev_c1 = u8c_c1; |
| 3592 | } |
| 3593 | else |
| 3594 | { |
| 3595 | pc = utfc_ptr2char(ptr + mb_l, &pc1, &dummy); |
| 3596 | nc = prev_c; |
| 3597 | } |
| 3598 | prev_c = mb_c; |
| 3599 | |
| 3600 | mb_c = arabic_shape(mb_c, &c, &u8c_c1, pc, pc1, nc); |
| 3601 | } |
| 3602 | else |
| 3603 | prev_c = mb_c; |
| 3604 | #endif |
| 3605 | } |
| 3606 | else /* enc_dbcs */ |
| 3607 | { |
| 3608 | mb_l = MB_BYTE2LEN(c); |
| 3609 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3610 | mb_l = 1; |
| 3611 | else if (mb_l > 1) |
| 3612 | { |
| 3613 | /* We assume a second byte below 32 is illegal. |
| 3614 | * Hopefully this is OK for all double-byte encodings! |
| 3615 | */ |
| 3616 | if (ptr[1] >= 32) |
| 3617 | mb_c = (c << 8) + ptr[1]; |
| 3618 | else |
| 3619 | { |
| 3620 | if (ptr[1] == NUL) |
| 3621 | { |
| 3622 | /* head byte at end of line */ |
| 3623 | mb_l = 1; |
| 3624 | transchar_nonprint(extra, c); |
| 3625 | } |
| 3626 | else |
| 3627 | { |
| 3628 | /* illegal tail byte */ |
| 3629 | mb_l = 2; |
| 3630 | STRCPY(extra, "XX"); |
| 3631 | } |
| 3632 | p_extra = extra; |
| 3633 | n_extra = (int)STRLEN(extra) - 1; |
| 3634 | c_extra = NUL; |
| 3635 | c = *p_extra++; |
| 3636 | if (area_attr == 0 && search_attr == 0) |
| 3637 | { |
| 3638 | n_attr = n_extra + 1; |
| 3639 | extra_attr = hl_attr(HLF_8); |
| 3640 | saved_attr2 = char_attr; /* save current attr */ |
| 3641 | } |
| 3642 | mb_c = c; |
| 3643 | } |
| 3644 | } |
| 3645 | } |
| 3646 | /* If a double-width char doesn't fit display a '>' in the |
| 3647 | * last column; the character is displayed at the start of the |
| 3648 | * next line. */ |
| 3649 | if (( |
| 3650 | # ifdef FEAT_RIGHTLEFT |
| 3651 | wp->w_p_rl ? (col <= 0) : |
| 3652 | # endif |
| 3653 | (col >= W_WIDTH(wp) - 1)) |
| 3654 | && (*mb_char2cells)(mb_c) == 2) |
| 3655 | { |
| 3656 | c = '>'; |
| 3657 | mb_c = c; |
| 3658 | mb_utf8 = FALSE; |
| 3659 | mb_l = 1; |
| 3660 | multi_attr = hl_attr(HLF_AT); |
| 3661 | /* Put pointer back so that the character will be |
| 3662 | * displayed at the start of the next line. */ |
| 3663 | --ptr; |
| 3664 | } |
| 3665 | else if (*ptr != NUL) |
| 3666 | ptr += mb_l - 1; |
| 3667 | |
| 3668 | /* If a double-width char doesn't fit at the left side display |
| 3669 | * a '<' in the first column. */ |
| 3670 | if (n_skip > 0 && mb_l > 1) |
| 3671 | { |
| 3672 | extra[0] = '<'; |
| 3673 | p_extra = extra; |
| 3674 | n_extra = 1; |
| 3675 | c_extra = NUL; |
| 3676 | c = ' '; |
| 3677 | if (area_attr == 0 && search_attr == 0) |
| 3678 | { |
| 3679 | n_attr = n_extra + 1; |
| 3680 | extra_attr = hl_attr(HLF_AT); |
| 3681 | saved_attr2 = char_attr; /* save current attr */ |
| 3682 | } |
| 3683 | mb_c = c; |
| 3684 | mb_utf8 = FALSE; |
| 3685 | mb_l = 1; |
| 3686 | } |
| 3687 | |
| 3688 | } |
| 3689 | #endif |
| 3690 | ++ptr; |
| 3691 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3692 | /* 'list' : change char 160 to lcs_nbsp. */ |
| 3693 | if (wp->w_p_list && c == 160 && lcs_nbsp) |
| 3694 | { |
| 3695 | c = lcs_nbsp; |
| 3696 | if (area_attr == 0 && search_attr == 0) |
| 3697 | { |
| 3698 | n_attr = 1; |
| 3699 | extra_attr = hl_attr(HLF_8); |
| 3700 | saved_attr2 = char_attr; /* save current attr */ |
| 3701 | } |
| 3702 | #ifdef FEAT_MBYTE |
| 3703 | mb_c = c; |
| 3704 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3705 | { |
| 3706 | mb_utf8 = TRUE; |
| 3707 | u8c_c1 = u8c_c2 = 0; |
| 3708 | } |
| 3709 | else |
| 3710 | mb_utf8 = FALSE; |
| 3711 | #endif |
| 3712 | } |
| 3713 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3714 | if (extra_check) |
| 3715 | { |
| 3716 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3717 | int can_spell = TRUE; |
| 3718 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3719 | /* Get syntax attribute, unless still at the start of the line |
| 3720 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3721 | v = (long)(ptr - line); |
| 3722 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3723 | { |
| 3724 | /* Get the syntax attribute for the character. If there |
| 3725 | * is an error, disable syntax highlighting. */ |
| 3726 | save_did_emsg = did_emsg; |
| 3727 | did_emsg = FALSE; |
| 3728 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3729 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
| 3730 | has_spell ? &can_spell : NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3731 | |
| 3732 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 3733 | { |
| 3734 | wp->w_buffer->b_syn_error = TRUE; |
| 3735 | has_syntax = FALSE; |
| 3736 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3737 | else |
| 3738 | did_emsg = save_did_emsg; |
| 3739 | |
| 3740 | /* Need to get the line again, a multi-line regexp may |
| 3741 | * have made it invalid. */ |
| 3742 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3743 | ptr = line + v; |
| 3744 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3745 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3746 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3747 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 3748 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3749 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3750 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3751 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 3752 | * Only do this when there is no syntax highlighting, the |
| 3753 | * @Spell cluster is not used or the current syntax item |
| 3754 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3755 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3756 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 3757 | spell_attr = 0; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3758 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 3759 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3760 | if (c != 0 && (!has_syntax || can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3761 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3762 | char_u *prev_ptr, *p; |
| 3763 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3764 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3765 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 3766 | if (has_mbyte) |
| 3767 | { |
| 3768 | prev_ptr = ptr - mb_l; |
| 3769 | v -= mb_l - 1; |
| 3770 | } |
| 3771 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3772 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 3773 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3774 | |
| 3775 | /* Use nextline[] if possible, it has the start of the |
| 3776 | * next line concatenated. */ |
| 3777 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 3778 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 3779 | else |
| 3780 | p = prev_ptr; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3781 | cap_col -= (prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 3782 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 3783 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3784 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3785 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3786 | /* In Insert mode only highlight a word that |
| 3787 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3788 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3789 | && (State & INSERT) != 0 |
| 3790 | && wp->w_cursor.lnum == lnum |
| 3791 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3792 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3793 | && wp->w_cursor.col < (colnr_T)word_end) |
| 3794 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3795 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3796 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3797 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3798 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3799 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3800 | && (p - nextline) + len > nextline_idx) |
| 3801 | { |
| 3802 | /* Remember that the good word continues at the |
| 3803 | * start of the next line. */ |
| 3804 | checked_lnum = lnum + 1; |
| 3805 | checked_col = (p - nextline) + len - nextline_idx; |
| 3806 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3807 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3808 | /* Turn index into actual attributes. */ |
| 3809 | if (spell_hlf != HLF_COUNT) |
| 3810 | spell_attr = highlight_attr[spell_hlf]; |
| 3811 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3812 | if (cap_col > 0) |
| 3813 | { |
| 3814 | if (p != prev_ptr |
| 3815 | && (p - nextline) + cap_col >= nextline_idx) |
| 3816 | { |
| 3817 | /* Remember that the word in the next line |
| 3818 | * must start with a capital. */ |
| 3819 | capcol_lnum = lnum + 1; |
| 3820 | cap_col = (p - nextline) + cap_col |
| 3821 | - nextline_idx; |
| 3822 | } |
| 3823 | else |
| 3824 | /* Compute the actual column. */ |
| 3825 | cap_col += (prev_ptr - line); |
| 3826 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3827 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3828 | } |
| 3829 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3830 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3831 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3832 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 3833 | else |
| 3834 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 3835 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3836 | #endif |
| 3837 | #ifdef FEAT_LINEBREAK |
| 3838 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3839 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3840 | */ |
| 3841 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) |
| 3842 | && !wp->w_p_list) |
| 3843 | { |
| 3844 | n_extra = win_lbr_chartabsize(wp, ptr - ( |
| 3845 | # ifdef FEAT_MBYTE |
| 3846 | has_mbyte ? mb_l : |
| 3847 | # endif |
| 3848 | 1), (colnr_T)vcol, NULL) - 1; |
| 3849 | c_extra = ' '; |
| 3850 | if (vim_iswhite(c)) |
| 3851 | c = ' '; |
| 3852 | } |
| 3853 | #endif |
| 3854 | |
| 3855 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 3856 | { |
| 3857 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3858 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3859 | { |
| 3860 | n_attr = 1; |
| 3861 | extra_attr = hl_attr(HLF_8); |
| 3862 | saved_attr2 = char_attr; /* save current attr */ |
| 3863 | } |
| 3864 | #ifdef FEAT_MBYTE |
| 3865 | mb_c = c; |
| 3866 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3867 | { |
| 3868 | mb_utf8 = TRUE; |
| 3869 | u8c_c1 = u8c_c2 = 0; |
| 3870 | } |
| 3871 | else |
| 3872 | mb_utf8 = FALSE; |
| 3873 | #endif |
| 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | /* |
| 3878 | * Handling of non-printable characters. |
| 3879 | */ |
| 3880 | if (!(chartab[c] & CT_PRINT_CHAR)) |
| 3881 | { |
| 3882 | /* |
| 3883 | * when getting a character from the file, we may have to |
| 3884 | * turn it into something else on the way to putting it |
| 3885 | * into "ScreenLines". |
| 3886 | */ |
| 3887 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 3888 | { |
| 3889 | /* tab amount depends on current column */ |
| 3890 | n_extra = (int)wp->w_buffer->b_p_ts |
| 3891 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 3892 | #ifdef FEAT_MBYTE |
| 3893 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 3894 | #endif |
| 3895 | if (wp->w_p_list) |
| 3896 | { |
| 3897 | c = lcs_tab1; |
| 3898 | c_extra = lcs_tab2; |
| 3899 | n_attr = n_extra + 1; |
| 3900 | extra_attr = hl_attr(HLF_8); |
| 3901 | saved_attr2 = char_attr; /* save current attr */ |
| 3902 | #ifdef FEAT_MBYTE |
| 3903 | mb_c = c; |
| 3904 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3905 | { |
| 3906 | mb_utf8 = TRUE; |
| 3907 | u8c_c1 = u8c_c2 = 0; |
| 3908 | } |
| 3909 | #endif |
| 3910 | } |
| 3911 | else |
| 3912 | { |
| 3913 | c_extra = ' '; |
| 3914 | c = ' '; |
| 3915 | } |
| 3916 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3917 | else if (c == NUL |
| 3918 | && ((wp->w_p_list && lcs_eol > 0) |
| 3919 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 3920 | && tocol > vcol |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3921 | #ifdef FEAT_VISUAL |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3922 | && VIsual_mode != Ctrl_V |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3923 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3924 | && ( |
| 3925 | # ifdef FEAT_RIGHTLEFT |
| 3926 | wp->w_p_rl ? (col >= 0) : |
| 3927 | # endif |
| 3928 | (col < W_WIDTH(wp))) |
| 3929 | && !(noinvcur |
| 3930 | && (colnr_T)vcol == wp->w_virtcol))) |
| 3931 | && lcs_eol_one >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3932 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3933 | /* Display a '$' after the line or highlight an extra |
| 3934 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3935 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 3936 | /* For a diff line the highlighting continues after the |
| 3937 | * "$". */ |
| 3938 | if ( |
| 3939 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3940 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3941 | # ifdef LINE_ATTR |
| 3942 | && |
| 3943 | # endif |
| 3944 | # endif |
| 3945 | # ifdef LINE_ATTR |
| 3946 | line_attr == 0 |
| 3947 | # endif |
| 3948 | ) |
| 3949 | #endif |
| 3950 | { |
| 3951 | #ifdef FEAT_VIRTUALEDIT |
| 3952 | /* In virtualedit, visual selections may extend |
| 3953 | * beyond end of line. */ |
| 3954 | if (area_highlighting && virtual_active() |
| 3955 | && tocol != MAXCOL && vcol < tocol) |
| 3956 | n_extra = 0; |
| 3957 | else |
| 3958 | #endif |
| 3959 | { |
| 3960 | p_extra = at_end_str; |
| 3961 | n_extra = 1; |
| 3962 | c_extra = NUL; |
| 3963 | } |
| 3964 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3965 | if (wp->w_p_list) |
| 3966 | c = lcs_eol; |
| 3967 | else |
| 3968 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3969 | lcs_eol_one = -1; |
| 3970 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3971 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3972 | { |
| 3973 | extra_attr = hl_attr(HLF_AT); |
| 3974 | n_attr = 1; |
| 3975 | } |
| 3976 | #ifdef FEAT_MBYTE |
| 3977 | mb_c = c; |
| 3978 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3979 | { |
| 3980 | mb_utf8 = TRUE; |
| 3981 | u8c_c1 = u8c_c2 = 0; |
| 3982 | } |
| 3983 | else |
| 3984 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 3985 | #endif |
| 3986 | } |
| 3987 | else if (c != NUL) |
| 3988 | { |
| 3989 | p_extra = transchar(c); |
| 3990 | #ifdef FEAT_RIGHTLEFT |
| 3991 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 3992 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 3993 | #endif |
| 3994 | n_extra = byte2cells(c) - 1; |
| 3995 | c_extra = NUL; |
| 3996 | c = *p_extra++; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3997 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3998 | { |
| 3999 | n_attr = n_extra + 1; |
| 4000 | extra_attr = hl_attr(HLF_8); |
| 4001 | saved_attr2 = char_attr; /* save current attr */ |
| 4002 | } |
| 4003 | #ifdef FEAT_MBYTE |
| 4004 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4005 | #endif |
| 4006 | } |
| 4007 | #ifdef FEAT_VIRTUALEDIT |
| 4008 | else if (VIsual_active |
| 4009 | && (VIsual_mode == Ctrl_V |
| 4010 | || VIsual_mode == 'v') |
| 4011 | && virtual_active() |
| 4012 | && tocol != MAXCOL |
| 4013 | && vcol < tocol |
| 4014 | && ( |
| 4015 | # ifdef FEAT_RIGHTLEFT |
| 4016 | wp->w_p_rl ? (col >= 0) : |
| 4017 | # endif |
| 4018 | (col < W_WIDTH(wp)))) |
| 4019 | { |
| 4020 | c = ' '; |
| 4021 | --ptr; /* put it back at the NUL */ |
| 4022 | } |
| 4023 | #endif |
| 4024 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4025 | else if (( |
| 4026 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4027 | diff_hlf != (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4028 | # ifdef LINE_ATTR |
| 4029 | || |
| 4030 | # endif |
| 4031 | # endif |
| 4032 | # ifdef LINE_ATTR |
| 4033 | line_attr != 0 |
| 4034 | # endif |
| 4035 | ) && ( |
| 4036 | # ifdef FEAT_RIGHTLEFT |
| 4037 | wp->w_p_rl ? (col >= 0) : |
| 4038 | # endif |
| 4039 | (col < W_WIDTH(wp)))) |
| 4040 | { |
| 4041 | /* Highlight until the right side of the window */ |
| 4042 | c = ' '; |
| 4043 | --ptr; /* put it back at the NUL */ |
| 4044 | # ifdef FEAT_DIFF |
| 4045 | if (diff_hlf == HLF_TXD) |
| 4046 | { |
| 4047 | diff_hlf = HLF_CHD; |
| 4048 | if (attr == 0 || char_attr != attr) |
| 4049 | char_attr = hl_attr(diff_hlf); |
| 4050 | } |
| 4051 | # endif |
| 4052 | } |
| 4053 | #endif |
| 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | /* Don't override visual selection highlighting. */ |
| 4058 | if (n_attr > 0 |
| 4059 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4060 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4061 | char_attr = extra_attr; |
| 4062 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4063 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4064 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4065 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4066 | * im_is_preediting() here. */ |
| 4067 | if (xic != NULL |
| 4068 | && lnum == curwin->w_cursor.lnum |
| 4069 | && (State & INSERT) |
| 4070 | && !p_imdisable |
| 4071 | && im_is_preediting() |
| 4072 | && draw_state == WL_LINE) |
| 4073 | { |
| 4074 | colnr_T tcol; |
| 4075 | |
| 4076 | if (preedit_end_col == MAXCOL) |
| 4077 | getvcol(curwin, &(curwin->w_cursor), &tcol, NULL, NULL); |
| 4078 | else |
| 4079 | tcol = preedit_end_col; |
| 4080 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 4081 | { |
| 4082 | if (feedback_old_attr < 0) |
| 4083 | { |
| 4084 | feedback_col = 0; |
| 4085 | feedback_old_attr = char_attr; |
| 4086 | } |
| 4087 | char_attr = im_get_feedback_attr(feedback_col); |
| 4088 | if (char_attr < 0) |
| 4089 | char_attr = feedback_old_attr; |
| 4090 | feedback_col++; |
| 4091 | } |
| 4092 | else if (feedback_old_attr >= 0) |
| 4093 | { |
| 4094 | char_attr = feedback_old_attr; |
| 4095 | feedback_old_attr = -1; |
| 4096 | feedback_col = 0; |
| 4097 | } |
| 4098 | } |
| 4099 | #endif |
| 4100 | /* |
| 4101 | * Handle the case where we are in column 0 but not on the first |
| 4102 | * character of the line and the user wants us to show us a |
| 4103 | * special character (via 'listchars' option "precedes:<char>". |
| 4104 | */ |
| 4105 | if (lcs_prec_todo != NUL |
| 4106 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 4107 | #ifdef FEAT_DIFF |
| 4108 | && filler_todo <= 0 |
| 4109 | #endif |
| 4110 | && draw_state > WL_NR |
| 4111 | && c != NUL) |
| 4112 | { |
| 4113 | c = lcs_prec; |
| 4114 | lcs_prec_todo = NUL; |
| 4115 | #ifdef FEAT_MBYTE |
| 4116 | mb_c = c; |
| 4117 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4118 | { |
| 4119 | mb_utf8 = TRUE; |
| 4120 | u8c_c1 = u8c_c2 = 0; |
| 4121 | } |
| 4122 | else |
| 4123 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4124 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4125 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4126 | { |
| 4127 | saved_attr3 = char_attr; /* save current attr */ |
| 4128 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 4129 | n_attr3 = 1; |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | /* |
| 4134 | * At end of the text line. |
| 4135 | */ |
| 4136 | if (c == NUL) |
| 4137 | { |
| 4138 | /* invert at least one char, used for Visual and empty line or |
| 4139 | * highlight match at end of line. If it's beyond the last |
| 4140 | * char on the screen, just overwrite that one (tricky!) Not |
| 4141 | * needed when a '$' was displayed for 'list'. */ |
| 4142 | if (lcs_eol == lcs_eol_one |
| 4143 | && ((area_attr != 0 && vcol == fromcol) |
| 4144 | #ifdef FEAT_SEARCH_EXTRA |
| 4145 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4146 | || (ptr - line) - 1 == (long)search_hl.startcol |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4147 | || (ptr - line) - 1 == (long)match_hl[0].startcol |
| 4148 | || (ptr - line) - 1 == (long)match_hl[1].startcol |
| 4149 | || (ptr - line) - 1 == (long)match_hl[2].startcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4150 | #endif |
| 4151 | )) |
| 4152 | { |
| 4153 | int n = 0; |
| 4154 | |
| 4155 | #ifdef FEAT_RIGHTLEFT |
| 4156 | if (wp->w_p_rl) |
| 4157 | { |
| 4158 | if (col < 0) |
| 4159 | n = 1; |
| 4160 | } |
| 4161 | else |
| 4162 | #endif |
| 4163 | { |
| 4164 | if (col >= W_WIDTH(wp)) |
| 4165 | n = -1; |
| 4166 | } |
| 4167 | if (n != 0) |
| 4168 | { |
| 4169 | /* At the window boundary, highlight the last character |
| 4170 | * instead (better than nothing). */ |
| 4171 | off += n; |
| 4172 | col += n; |
| 4173 | } |
| 4174 | else |
| 4175 | { |
| 4176 | /* Add a blank character to highlight. */ |
| 4177 | ScreenLines[off] = ' '; |
| 4178 | #ifdef FEAT_MBYTE |
| 4179 | if (enc_utf8) |
| 4180 | ScreenLinesUC[off] = 0; |
| 4181 | #endif |
| 4182 | } |
| 4183 | #ifdef FEAT_SEARCH_EXTRA |
| 4184 | if (area_attr == 0) |
| 4185 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4186 | for (i = 0; i <= 3; ++i) |
| 4187 | { |
| 4188 | if (i == 3) |
| 4189 | char_attr = search_hl.attr; |
| 4190 | else if ((ptr - line) - 1 == (long)match_hl[i].startcol) |
| 4191 | { |
| 4192 | char_attr = match_hl[i].attr; |
| 4193 | break; |
| 4194 | } |
| 4195 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4196 | } |
| 4197 | #endif |
| 4198 | ScreenAttrs[off] = char_attr; |
| 4199 | #ifdef FEAT_RIGHTLEFT |
| 4200 | if (wp->w_p_rl) |
| 4201 | --col; |
| 4202 | else |
| 4203 | #endif |
| 4204 | ++col; |
| 4205 | } |
| 4206 | |
| 4207 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), |
| 4208 | wp->w_p_rl); |
| 4209 | row++; |
| 4210 | |
| 4211 | /* |
| 4212 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 4213 | * updated (saves a call to plines() later). |
| 4214 | */ |
| 4215 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 4216 | { |
| 4217 | curwin->w_cline_row = startrow; |
| 4218 | curwin->w_cline_height = row - startrow; |
| 4219 | #ifdef FEAT_FOLDING |
| 4220 | curwin->w_cline_folded = FALSE; |
| 4221 | #endif |
| 4222 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 4223 | } |
| 4224 | |
| 4225 | break; |
| 4226 | } |
| 4227 | |
| 4228 | /* line continues beyond line end */ |
| 4229 | if (lcs_ext |
| 4230 | && !wp->w_p_wrap |
| 4231 | #ifdef FEAT_DIFF |
| 4232 | && filler_todo <= 0 |
| 4233 | #endif |
| 4234 | && ( |
| 4235 | #ifdef FEAT_RIGHTLEFT |
| 4236 | wp->w_p_rl ? col == 0 : |
| 4237 | #endif |
| 4238 | col == W_WIDTH(wp) - 1) |
| 4239 | && (*ptr != NUL |
| 4240 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
| 4241 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 4242 | { |
| 4243 | c = lcs_ext; |
| 4244 | char_attr = hl_attr(HLF_AT); |
| 4245 | #ifdef FEAT_MBYTE |
| 4246 | mb_c = c; |
| 4247 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4248 | { |
| 4249 | mb_utf8 = TRUE; |
| 4250 | u8c_c1 = u8c_c2 = 0; |
| 4251 | } |
| 4252 | else |
| 4253 | mb_utf8 = FALSE; |
| 4254 | #endif |
| 4255 | } |
| 4256 | |
| 4257 | /* |
| 4258 | * Store character to be displayed. |
| 4259 | * Skip characters that are left of the screen for 'nowrap'. |
| 4260 | */ |
| 4261 | vcol_prev = vcol; |
| 4262 | if (draw_state < WL_LINE || n_skip <= 0) |
| 4263 | { |
| 4264 | /* |
| 4265 | * Store the character. |
| 4266 | */ |
| 4267 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 4268 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 4269 | { |
| 4270 | /* A double-wide character is: put first halve in left cell. */ |
| 4271 | --off; |
| 4272 | --col; |
| 4273 | } |
| 4274 | #endif |
| 4275 | ScreenLines[off] = c; |
| 4276 | #ifdef FEAT_MBYTE |
| 4277 | if (enc_dbcs == DBCS_JPNU) |
| 4278 | ScreenLines2[off] = mb_c & 0xff; |
| 4279 | else if (enc_utf8) |
| 4280 | { |
| 4281 | if (mb_utf8) |
| 4282 | { |
| 4283 | ScreenLinesUC[off] = mb_c; |
| 4284 | ScreenLinesC1[off] = u8c_c1; |
| 4285 | ScreenLinesC2[off] = u8c_c2; |
| 4286 | } |
| 4287 | else |
| 4288 | ScreenLinesUC[off] = 0; |
| 4289 | } |
| 4290 | if (multi_attr) |
| 4291 | { |
| 4292 | ScreenAttrs[off] = multi_attr; |
| 4293 | multi_attr = 0; |
| 4294 | } |
| 4295 | else |
| 4296 | #endif |
| 4297 | ScreenAttrs[off] = char_attr; |
| 4298 | |
| 4299 | #ifdef FEAT_MBYTE |
| 4300 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4301 | { |
| 4302 | /* Need to fill two screen columns. */ |
| 4303 | ++off; |
| 4304 | ++col; |
| 4305 | if (enc_utf8) |
| 4306 | /* UTF-8: Put a 0 in the second screen char. */ |
| 4307 | ScreenLines[off] = 0; |
| 4308 | else |
| 4309 | /* DBCS: Put second byte in the second screen char. */ |
| 4310 | ScreenLines[off] = mb_c & 0xff; |
| 4311 | ++vcol; |
| 4312 | /* When "tocol" is halfway a character, set it to the end of |
| 4313 | * the character, otherwise highlighting won't stop. */ |
| 4314 | if (tocol == vcol) |
| 4315 | ++tocol; |
| 4316 | #ifdef FEAT_RIGHTLEFT |
| 4317 | if (wp->w_p_rl) |
| 4318 | { |
| 4319 | /* now it's time to backup one cell */ |
| 4320 | --off; |
| 4321 | --col; |
| 4322 | } |
| 4323 | #endif |
| 4324 | } |
| 4325 | #endif |
| 4326 | #ifdef FEAT_RIGHTLEFT |
| 4327 | if (wp->w_p_rl) |
| 4328 | { |
| 4329 | --off; |
| 4330 | --col; |
| 4331 | } |
| 4332 | else |
| 4333 | #endif |
| 4334 | { |
| 4335 | ++off; |
| 4336 | ++col; |
| 4337 | } |
| 4338 | } |
| 4339 | else |
| 4340 | --n_skip; |
| 4341 | |
| 4342 | /* Only advance the "vcol" when after the 'number' column. */ |
| 4343 | if (draw_state >= WL_SBR |
| 4344 | #ifdef FEAT_DIFF |
| 4345 | && filler_todo <= 0 |
| 4346 | #endif |
| 4347 | ) |
| 4348 | ++vcol; |
| 4349 | |
| 4350 | /* restore attributes after "predeces" in 'listchars' */ |
| 4351 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 4352 | char_attr = saved_attr3; |
| 4353 | |
| 4354 | /* restore attributes after last 'listchars' or 'number' char */ |
| 4355 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 4356 | char_attr = saved_attr2; |
| 4357 | |
| 4358 | /* |
| 4359 | * At end of screen line and there is more to come: Display the line |
| 4360 | * so far. If there is no more to display it is catched above. |
| 4361 | */ |
| 4362 | if (( |
| 4363 | #ifdef FEAT_RIGHTLEFT |
| 4364 | wp->w_p_rl ? (col < 0) : |
| 4365 | #endif |
| 4366 | (col >= W_WIDTH(wp))) |
| 4367 | && (*ptr != NUL |
| 4368 | #ifdef FEAT_DIFF |
| 4369 | || filler_todo > 0 |
| 4370 | #endif |
| 4371 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
| 4372 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 4373 | ) |
| 4374 | { |
| 4375 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), |
| 4376 | wp->w_p_rl); |
| 4377 | ++row; |
| 4378 | ++screen_row; |
| 4379 | |
| 4380 | /* When not wrapping and finished diff lines, or when displayed |
| 4381 | * '$' and highlighting until last column, break here. */ |
| 4382 | if ((!wp->w_p_wrap |
| 4383 | #ifdef FEAT_DIFF |
| 4384 | && filler_todo <= 0 |
| 4385 | #endif |
| 4386 | ) || lcs_eol_one == -1) |
| 4387 | break; |
| 4388 | |
| 4389 | /* When the window is too narrow draw all "@" lines. */ |
| 4390 | if (draw_state != WL_LINE |
| 4391 | #ifdef FEAT_DIFF |
| 4392 | && filler_todo <= 0 |
| 4393 | #endif |
| 4394 | ) |
| 4395 | { |
| 4396 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 4397 | #ifdef FEAT_VERTSPLIT |
| 4398 | draw_vsep_win(wp, row); |
| 4399 | #endif |
| 4400 | row = endrow; |
| 4401 | } |
| 4402 | |
| 4403 | /* When line got too long for screen break here. */ |
| 4404 | if (row == endrow) |
| 4405 | { |
| 4406 | ++row; |
| 4407 | break; |
| 4408 | } |
| 4409 | |
| 4410 | if (screen_cur_row == screen_row - 1 |
| 4411 | #ifdef FEAT_DIFF |
| 4412 | && filler_todo <= 0 |
| 4413 | #endif |
| 4414 | && W_WIDTH(wp) == Columns) |
| 4415 | { |
| 4416 | /* Remember that the line wraps, used for modeless copy. */ |
| 4417 | LineWraps[screen_row - 1] = TRUE; |
| 4418 | |
| 4419 | /* |
| 4420 | * Special trick to make copy/paste of wrapped lines work with |
| 4421 | * xterm/screen: write an extra character beyond the end of |
| 4422 | * the line. This will work with all terminal types |
| 4423 | * (regardless of the xn,am settings). |
| 4424 | * Only do this on a fast tty. |
| 4425 | * Only do this if the cursor is on the current line |
| 4426 | * (something has been written in it). |
| 4427 | * Don't do this for the GUI. |
| 4428 | * Don't do this for double-width characters. |
| 4429 | * Don't do this for a window not at the right screen border. |
| 4430 | */ |
| 4431 | if (p_tf |
| 4432 | #ifdef FEAT_GUI |
| 4433 | && !gui.in_use |
| 4434 | #endif |
| 4435 | #ifdef FEAT_MBYTE |
| 4436 | && !(has_mbyte |
| 4437 | && ((*mb_off2cells)(LineOffset[screen_row]) == 2 |
| 4438 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
| 4439 | + (int)Columns - 2) == 2)) |
| 4440 | #endif |
| 4441 | ) |
| 4442 | { |
| 4443 | /* First make sure we are at the end of the screen line, |
| 4444 | * then output the same character again to let the |
| 4445 | * terminal know about the wrap. If the terminal doesn't |
| 4446 | * auto-wrap, we overwrite the character. */ |
| 4447 | if (screen_cur_col != W_WIDTH(wp)) |
| 4448 | screen_char(LineOffset[screen_row - 1] |
| 4449 | + (unsigned)Columns - 1, |
| 4450 | screen_row - 1, (int)(Columns - 1)); |
| 4451 | |
| 4452 | #ifdef FEAT_MBYTE |
| 4453 | /* When there is a multi-byte character, just output a |
| 4454 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 4455 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 4456 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4457 | out_char(' '); |
| 4458 | else |
| 4459 | #endif |
| 4460 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 4461 | + (Columns - 1)]); |
| 4462 | /* force a redraw of the first char on the next line */ |
| 4463 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 4464 | screen_start(); /* don't know where cursor is now */ |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | col = 0; |
| 4469 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 4470 | #ifdef FEAT_RIGHTLEFT |
| 4471 | if (wp->w_p_rl) |
| 4472 | { |
| 4473 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 4474 | off += col; |
| 4475 | } |
| 4476 | #endif |
| 4477 | |
| 4478 | /* reset the drawing state for the start of a wrapped line */ |
| 4479 | draw_state = WL_START; |
| 4480 | saved_n_extra = n_extra; |
| 4481 | saved_p_extra = p_extra; |
| 4482 | saved_c_extra = c_extra; |
| 4483 | saved_char_attr = char_attr; |
| 4484 | n_extra = 0; |
| 4485 | lcs_prec_todo = lcs_prec; |
| 4486 | #ifdef FEAT_LINEBREAK |
| 4487 | # ifdef FEAT_DIFF |
| 4488 | if (filler_todo <= 0) |
| 4489 | # endif |
| 4490 | need_showbreak = TRUE; |
| 4491 | #endif |
| 4492 | #ifdef FEAT_DIFF |
| 4493 | --filler_todo; |
| 4494 | /* When the filler lines are actually below the last line of the |
| 4495 | * file, don't draw the line itself, break here. */ |
| 4496 | if (filler_todo == 0 && wp->w_botfill) |
| 4497 | break; |
| 4498 | #endif |
| 4499 | } |
| 4500 | |
| 4501 | } /* for every character in the line */ |
| 4502 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4503 | #ifdef FEAT_SYN_HL |
| 4504 | /* After an empty line check first word for capital. */ |
| 4505 | if (*skipwhite(line) == NUL) |
| 4506 | { |
| 4507 | capcol_lnum = lnum + 1; |
| 4508 | cap_col = 0; |
| 4509 | } |
| 4510 | #endif |
| 4511 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4512 | return row; |
| 4513 | } |
| 4514 | |
| 4515 | /* |
| 4516 | * Check whether the given character needs redrawing: |
| 4517 | * - the (first byte of the) character is different |
| 4518 | * - the attributes are different |
| 4519 | * - the character is multi-byte and the next byte is different |
| 4520 | */ |
| 4521 | static int |
| 4522 | char_needs_redraw(off_from, off_to, cols) |
| 4523 | int off_from; |
| 4524 | int off_to; |
| 4525 | int cols; |
| 4526 | { |
| 4527 | if (cols > 0 |
| 4528 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 4529 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 4530 | |
| 4531 | #ifdef FEAT_MBYTE |
| 4532 | || (enc_dbcs != 0 |
| 4533 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 4534 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 4535 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 4536 | : (cols > 1 && ScreenLines[off_from + 1] |
| 4537 | != ScreenLines[off_to + 1]))) |
| 4538 | || (enc_utf8 |
| 4539 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 4540 | || (ScreenLinesUC[off_from] != 0 |
| 4541 | && (ScreenLinesC1[off_from] |
| 4542 | != ScreenLinesC1[off_to] |
| 4543 | || ScreenLinesC2[off_from] |
| 4544 | != ScreenLinesC2[off_to])))) |
| 4545 | #endif |
| 4546 | )) |
| 4547 | return TRUE; |
| 4548 | return FALSE; |
| 4549 | } |
| 4550 | |
| 4551 | /* |
| 4552 | * Move one "cooked" screen line to the screen, but only the characters that |
| 4553 | * have actually changed. Handle insert/delete character. |
| 4554 | * "coloff" gives the first column on the screen for this line. |
| 4555 | * "endcol" gives the columns where valid characters are. |
| 4556 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 4557 | * needs to be cleared, negative otherwise. |
| 4558 | * "rlflag" is TRUE in a rightleft window: |
| 4559 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 4560 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 4561 | */ |
| 4562 | static void |
| 4563 | screen_line(row, coloff, endcol, clear_width |
| 4564 | #ifdef FEAT_RIGHTLEFT |
| 4565 | , rlflag |
| 4566 | #endif |
| 4567 | ) |
| 4568 | int row; |
| 4569 | int coloff; |
| 4570 | int endcol; |
| 4571 | int clear_width; |
| 4572 | #ifdef FEAT_RIGHTLEFT |
| 4573 | int rlflag; |
| 4574 | #endif |
| 4575 | { |
| 4576 | unsigned off_from; |
| 4577 | unsigned off_to; |
| 4578 | int col = 0; |
| 4579 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 4580 | int hl; |
| 4581 | #endif |
| 4582 | int force = FALSE; /* force update rest of the line */ |
| 4583 | int redraw_this /* bool: does character need redraw? */ |
| 4584 | #ifdef FEAT_GUI |
| 4585 | = TRUE /* For GUI when while-loop empty */ |
| 4586 | #endif |
| 4587 | ; |
| 4588 | int redraw_next; /* redraw_this for next character */ |
| 4589 | #ifdef FEAT_MBYTE |
| 4590 | int clear_next = FALSE; |
| 4591 | int char_cells; /* 1: normal char */ |
| 4592 | /* 2: occupies two display cells */ |
| 4593 | # define CHAR_CELLS char_cells |
| 4594 | #else |
| 4595 | # define CHAR_CELLS 1 |
| 4596 | #endif |
| 4597 | |
| 4598 | # ifdef FEAT_CLIPBOARD |
| 4599 | clip_may_clear_selection(row, row); |
| 4600 | # endif |
| 4601 | |
| 4602 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 4603 | off_to = LineOffset[row] + coloff; |
| 4604 | |
| 4605 | #ifdef FEAT_RIGHTLEFT |
| 4606 | if (rlflag) |
| 4607 | { |
| 4608 | /* Clear rest first, because it's left of the text. */ |
| 4609 | if (clear_width > 0) |
| 4610 | { |
| 4611 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 4612 | && ScreenAttrs[off_to] == 0 |
| 4613 | # ifdef FEAT_MBYTE |
| 4614 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 4615 | # endif |
| 4616 | ) |
| 4617 | { |
| 4618 | ++off_to; |
| 4619 | ++col; |
| 4620 | } |
| 4621 | if (col <= endcol) |
| 4622 | screen_fill(row, row + 1, col + coloff, |
| 4623 | endcol + coloff + 1, ' ', ' ', 0); |
| 4624 | } |
| 4625 | col = endcol + 1; |
| 4626 | off_to = LineOffset[row] + col + coloff; |
| 4627 | off_from += col; |
| 4628 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 4629 | } |
| 4630 | #endif /* FEAT_RIGHTLEFT */ |
| 4631 | |
| 4632 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 4633 | |
| 4634 | while (col < endcol) |
| 4635 | { |
| 4636 | #ifdef FEAT_MBYTE |
| 4637 | if (has_mbyte && (col + 1 < endcol)) |
| 4638 | char_cells = (*mb_off2cells)(off_from); |
| 4639 | else |
| 4640 | char_cells = 1; |
| 4641 | #endif |
| 4642 | |
| 4643 | redraw_this = redraw_next; |
| 4644 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 4645 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 4646 | |
| 4647 | #ifdef FEAT_GUI |
| 4648 | /* If the next character was bold, then redraw the current character to |
| 4649 | * remove any pixels that might have spilt over into us. This only |
| 4650 | * happens in the GUI. |
| 4651 | */ |
| 4652 | if (redraw_next && gui.in_use) |
| 4653 | { |
| 4654 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
| 4655 | if (hl > HL_ALL || (hl & HL_BOLD)) |
| 4656 | redraw_this = TRUE; |
| 4657 | } |
| 4658 | #endif |
| 4659 | |
| 4660 | if (redraw_this) |
| 4661 | { |
| 4662 | /* |
| 4663 | * Special handling when 'xs' termcap flag set (hpterm): |
| 4664 | * Attributes for characters are stored at the position where the |
| 4665 | * cursor is when writing the highlighting code. The |
| 4666 | * start-highlighting code must be written with the cursor on the |
| 4667 | * first highlighted character. The stop-highlighting code must |
| 4668 | * be written with the cursor just after the last highlighted |
| 4669 | * character. |
| 4670 | * Overwriting a character doesn't remove it's highlighting. Need |
| 4671 | * to clear the rest of the line, and force redrawing it |
| 4672 | * completely. |
| 4673 | */ |
| 4674 | if ( p_wiv |
| 4675 | && !force |
| 4676 | #ifdef FEAT_GUI |
| 4677 | && !gui.in_use |
| 4678 | #endif |
| 4679 | && ScreenAttrs[off_to] != 0 |
| 4680 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 4681 | { |
| 4682 | /* |
| 4683 | * Need to remove highlighting attributes here. |
| 4684 | */ |
| 4685 | windgoto(row, col + coloff); |
| 4686 | out_str(T_CE); /* clear rest of this screen line */ |
| 4687 | screen_start(); /* don't know where cursor is now */ |
| 4688 | force = TRUE; /* force redraw of rest of the line */ |
| 4689 | redraw_next = TRUE; /* or else next char would miss out */ |
| 4690 | |
| 4691 | /* |
| 4692 | * If the previous character was highlighted, need to stop |
| 4693 | * highlighting at this character. |
| 4694 | */ |
| 4695 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 4696 | { |
| 4697 | screen_attr = ScreenAttrs[off_to - 1]; |
| 4698 | term_windgoto(row, col + coloff); |
| 4699 | screen_stop_highlight(); |
| 4700 | } |
| 4701 | else |
| 4702 | screen_attr = 0; /* highlighting has stopped */ |
| 4703 | } |
| 4704 | #ifdef FEAT_MBYTE |
| 4705 | if (enc_dbcs != 0) |
| 4706 | { |
| 4707 | /* Check if overwriting a double-byte with a single-byte or |
| 4708 | * the other way around requires another character to be |
| 4709 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 4710 | * ScreenLinesUC[] is sufficient. */ |
| 4711 | if (char_cells == 1 |
| 4712 | && col + 1 < endcol |
| 4713 | && (*mb_off2cells)(off_to) > 1) |
| 4714 | { |
| 4715 | /* Writing a single-cell character over a double-cell |
| 4716 | * character: need to redraw the next cell. */ |
| 4717 | ScreenLines[off_to + 1] = 0; |
| 4718 | redraw_next = TRUE; |
| 4719 | } |
| 4720 | else if (char_cells == 2 |
| 4721 | && col + 2 < endcol |
| 4722 | && (*mb_off2cells)(off_to) == 1 |
| 4723 | && (*mb_off2cells)(off_to + 1) > 1) |
| 4724 | { |
| 4725 | /* Writing the second half of a double-cell character over |
| 4726 | * a double-cell character: need to redraw the second |
| 4727 | * cell. */ |
| 4728 | ScreenLines[off_to + 2] = 0; |
| 4729 | redraw_next = TRUE; |
| 4730 | } |
| 4731 | |
| 4732 | if (enc_dbcs == DBCS_JPNU) |
| 4733 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 4734 | } |
| 4735 | /* When writing a single-width character over a double-width |
| 4736 | * character and at the end of the redrawn text, need to clear out |
| 4737 | * the right halve of the old character. |
| 4738 | * Also required when writing the right halve of a double-width |
| 4739 | * char over the left halve of an existing one. */ |
| 4740 | if (has_mbyte && col + char_cells == endcol |
| 4741 | && ((char_cells == 1 |
| 4742 | && (*mb_off2cells)(off_to) > 1) |
| 4743 | || (char_cells == 2 |
| 4744 | && (*mb_off2cells)(off_to) == 1 |
| 4745 | && (*mb_off2cells)(off_to + 1) > 1))) |
| 4746 | clear_next = TRUE; |
| 4747 | #endif |
| 4748 | |
| 4749 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 4750 | #ifdef FEAT_MBYTE |
| 4751 | if (enc_utf8) |
| 4752 | { |
| 4753 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 4754 | if (ScreenLinesUC[off_from] != 0) |
| 4755 | { |
| 4756 | ScreenLinesC1[off_to] = ScreenLinesC1[off_from]; |
| 4757 | ScreenLinesC2[off_to] = ScreenLinesC2[off_from]; |
| 4758 | } |
| 4759 | } |
| 4760 | if (char_cells == 2) |
| 4761 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 4762 | #endif |
| 4763 | |
| 4764 | #if defined(FEAT_GUI) || defined(UNIX) |
| 4765 | /* The bold trick makes a single row of pixels appear in the next |
| 4766 | * character. When a bold character is removed, the next |
| 4767 | * character should be redrawn too. This happens for our own GUI |
| 4768 | * and for some xterms. */ |
| 4769 | if ( |
| 4770 | # ifdef FEAT_GUI |
| 4771 | gui.in_use |
| 4772 | # endif |
| 4773 | # if defined(FEAT_GUI) && defined(UNIX) |
| 4774 | || |
| 4775 | # endif |
| 4776 | # ifdef UNIX |
| 4777 | term_is_xterm |
| 4778 | # endif |
| 4779 | ) |
| 4780 | { |
| 4781 | hl = ScreenAttrs[off_to]; |
| 4782 | if (hl > HL_ALL || (hl & HL_BOLD)) |
| 4783 | redraw_next = TRUE; |
| 4784 | } |
| 4785 | #endif |
| 4786 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 4787 | #ifdef FEAT_MBYTE |
| 4788 | if (enc_dbcs != 0 && char_cells == 2) |
| 4789 | { |
| 4790 | /* just a hack: It makes two bytes of DBCS have same attr */ |
| 4791 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
| 4792 | screen_char_2(off_to, row, col + coloff); |
| 4793 | } |
| 4794 | else |
| 4795 | #endif |
| 4796 | screen_char(off_to, row, col + coloff); |
| 4797 | } |
| 4798 | else if ( p_wiv |
| 4799 | #ifdef FEAT_GUI |
| 4800 | && !gui.in_use |
| 4801 | #endif |
| 4802 | && col + coloff > 0) |
| 4803 | { |
| 4804 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 4805 | { |
| 4806 | /* |
| 4807 | * Don't output stop-highlight when moving the cursor, it will |
| 4808 | * stop the highlighting when it should continue. |
| 4809 | */ |
| 4810 | screen_attr = 0; |
| 4811 | } |
| 4812 | else if (screen_attr != 0) |
| 4813 | screen_stop_highlight(); |
| 4814 | } |
| 4815 | |
| 4816 | off_to += CHAR_CELLS; |
| 4817 | off_from += CHAR_CELLS; |
| 4818 | col += CHAR_CELLS; |
| 4819 | } |
| 4820 | |
| 4821 | #ifdef FEAT_MBYTE |
| 4822 | if (clear_next) |
| 4823 | { |
| 4824 | /* Clear the second half of a double-wide character of which the left |
| 4825 | * half was overwritten with a single-wide character. */ |
| 4826 | ScreenLines[off_to] = ' '; |
| 4827 | if (enc_utf8) |
| 4828 | ScreenLinesUC[off_to] = 0; |
| 4829 | screen_char(off_to, row, col + coloff); |
| 4830 | } |
| 4831 | #endif |
| 4832 | |
| 4833 | if (clear_width > 0 |
| 4834 | #ifdef FEAT_RIGHTLEFT |
| 4835 | && !rlflag |
| 4836 | #endif |
| 4837 | ) |
| 4838 | { |
| 4839 | #ifdef FEAT_GUI |
| 4840 | int startCol = col; |
| 4841 | #endif |
| 4842 | |
| 4843 | /* blank out the rest of the line */ |
| 4844 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 4845 | && ScreenAttrs[off_to] == 0 |
| 4846 | #ifdef FEAT_MBYTE |
| 4847 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 4848 | #endif |
| 4849 | ) |
| 4850 | { |
| 4851 | ++off_to; |
| 4852 | ++col; |
| 4853 | } |
| 4854 | if (col < clear_width) |
| 4855 | { |
| 4856 | #ifdef FEAT_GUI |
| 4857 | /* |
| 4858 | * In the GUI, clearing the rest of the line may leave pixels |
| 4859 | * behind if the first character cleared was bold. Some bold |
| 4860 | * fonts spill over the left. In this case we redraw the previous |
| 4861 | * character too. If we didn't skip any blanks above, then we |
| 4862 | * only redraw if the character wasn't already redrawn anyway. |
| 4863 | */ |
| 4864 | if (gui.in_use && (col > startCol || !redraw_this) |
| 4865 | # ifdef FEAT_MBYTE |
| 4866 | && enc_dbcs == 0 |
| 4867 | # endif |
| 4868 | ) |
| 4869 | { |
| 4870 | hl = ScreenAttrs[off_to]; |
| 4871 | if (hl > HL_ALL || (hl & HL_BOLD)) |
| 4872 | screen_char(off_to - 1, row, col + coloff - 1); |
| 4873 | } |
| 4874 | #endif |
| 4875 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 4876 | ' ', ' ', 0); |
| 4877 | #ifdef FEAT_VERTSPLIT |
| 4878 | off_to += clear_width - col; |
| 4879 | col = clear_width; |
| 4880 | #endif |
| 4881 | } |
| 4882 | } |
| 4883 | |
| 4884 | if (clear_width > 0) |
| 4885 | { |
| 4886 | #ifdef FEAT_VERTSPLIT |
| 4887 | /* For a window that's left of another, draw the separator char. */ |
| 4888 | if (col + coloff < Columns) |
| 4889 | { |
| 4890 | int c; |
| 4891 | |
| 4892 | c = fillchar_vsep(&hl); |
| 4893 | if (ScreenLines[off_to] != c |
| 4894 | # ifdef FEAT_MBYTE |
| 4895 | || (enc_utf8 |
| 4896 | && ScreenLinesUC[off_to] != (c >= 0x80 ? c : 0)) |
| 4897 | # endif |
| 4898 | || ScreenAttrs[off_to] != hl) |
| 4899 | { |
| 4900 | ScreenLines[off_to] = c; |
| 4901 | ScreenAttrs[off_to] = hl; |
| 4902 | # ifdef FEAT_MBYTE |
| 4903 | if (enc_utf8) |
| 4904 | { |
| 4905 | if (c >= 0x80) |
| 4906 | { |
| 4907 | ScreenLinesUC[off_to] = c; |
| 4908 | ScreenLinesC1[off_to] = 0; |
| 4909 | ScreenLinesC2[off_to] = 0; |
| 4910 | } |
| 4911 | else |
| 4912 | ScreenLinesUC[off_to] = 0; |
| 4913 | } |
| 4914 | # endif |
| 4915 | screen_char(off_to, row, col + coloff); |
| 4916 | } |
| 4917 | } |
| 4918 | else |
| 4919 | #endif |
| 4920 | LineWraps[row] = FALSE; |
| 4921 | } |
| 4922 | } |
| 4923 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4924 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4925 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4926 | * Mirror text "str" for right-left displaying. |
| 4927 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4928 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4929 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4930 | rl_mirror(str) |
| 4931 | char_u *str; |
| 4932 | { |
| 4933 | char_u *p1, *p2; |
| 4934 | int t; |
| 4935 | |
| 4936 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 4937 | { |
| 4938 | t = *p1; |
| 4939 | *p1 = *p2; |
| 4940 | *p2 = t; |
| 4941 | } |
| 4942 | } |
| 4943 | #endif |
| 4944 | |
| 4945 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 4946 | /* |
| 4947 | * mark all status lines for redraw; used after first :cd |
| 4948 | */ |
| 4949 | void |
| 4950 | status_redraw_all() |
| 4951 | { |
| 4952 | win_T *wp; |
| 4953 | |
| 4954 | for (wp = firstwin; wp; wp = wp->w_next) |
| 4955 | if (wp->w_status_height) |
| 4956 | { |
| 4957 | wp->w_redr_status = TRUE; |
| 4958 | redraw_later(VALID); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | /* |
| 4963 | * mark all status lines of the current buffer for redraw |
| 4964 | */ |
| 4965 | void |
| 4966 | status_redraw_curbuf() |
| 4967 | { |
| 4968 | win_T *wp; |
| 4969 | |
| 4970 | for (wp = firstwin; wp; wp = wp->w_next) |
| 4971 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 4972 | { |
| 4973 | wp->w_redr_status = TRUE; |
| 4974 | redraw_later(VALID); |
| 4975 | } |
| 4976 | } |
| 4977 | |
| 4978 | /* |
| 4979 | * Redraw all status lines that need to be redrawn. |
| 4980 | */ |
| 4981 | void |
| 4982 | redraw_statuslines() |
| 4983 | { |
| 4984 | win_T *wp; |
| 4985 | |
| 4986 | for (wp = firstwin; wp; wp = wp->w_next) |
| 4987 | if (wp->w_redr_status) |
| 4988 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 4989 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 4990 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4991 | } |
| 4992 | #endif |
| 4993 | |
| 4994 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 4995 | /* |
| 4996 | * Redraw all status lines at the bottom of frame "frp". |
| 4997 | */ |
| 4998 | void |
| 4999 | win_redraw_last_status(frp) |
| 5000 | frame_T *frp; |
| 5001 | { |
| 5002 | if (frp->fr_layout == FR_LEAF) |
| 5003 | frp->fr_win->w_redr_status = TRUE; |
| 5004 | else if (frp->fr_layout == FR_ROW) |
| 5005 | { |
| 5006 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 5007 | win_redraw_last_status(frp); |
| 5008 | } |
| 5009 | else /* frp->fr_layout == FR_COL */ |
| 5010 | { |
| 5011 | frp = frp->fr_child; |
| 5012 | while (frp->fr_next != NULL) |
| 5013 | frp = frp->fr_next; |
| 5014 | win_redraw_last_status(frp); |
| 5015 | } |
| 5016 | } |
| 5017 | #endif |
| 5018 | |
| 5019 | #ifdef FEAT_VERTSPLIT |
| 5020 | /* |
| 5021 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 5022 | */ |
| 5023 | static void |
| 5024 | draw_vsep_win(wp, row) |
| 5025 | win_T *wp; |
| 5026 | int row; |
| 5027 | { |
| 5028 | int hl; |
| 5029 | int c; |
| 5030 | |
| 5031 | if (wp->w_vsep_width) |
| 5032 | { |
| 5033 | /* draw the vertical separator right of this window */ |
| 5034 | c = fillchar_vsep(&hl); |
| 5035 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 5036 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 5037 | c, ' ', hl); |
| 5038 | } |
| 5039 | } |
| 5040 | #endif |
| 5041 | |
| 5042 | #ifdef FEAT_WILDMENU |
| 5043 | static int status_match_len __ARGS((expand_T *xp, char_u *s)); |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5044 | static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5045 | |
| 5046 | /* |
| 5047 | * Get the lenght of an item as it will be shown in the status line. |
| 5048 | */ |
| 5049 | static int |
| 5050 | status_match_len(xp, s) |
| 5051 | expand_T *xp; |
| 5052 | char_u *s; |
| 5053 | { |
| 5054 | int len = 0; |
| 5055 | |
| 5056 | #ifdef FEAT_MENU |
| 5057 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 5058 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5059 | |
| 5060 | /* Check for menu separators - replace with '|'. */ |
| 5061 | if (emenu && menu_is_separator(s)) |
| 5062 | return 1; |
| 5063 | #endif |
| 5064 | |
| 5065 | while (*s != NUL) |
| 5066 | { |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5067 | if (skip_status_match_char(xp, s)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5068 | ++s; |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5069 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5070 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | return len; |
| 5074 | } |
| 5075 | |
| 5076 | /* |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5077 | * Return TRUE for characters that are not displayed in a status match. |
| 5078 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 5079 | */ |
| 5080 | static int |
| 5081 | skip_status_match_char(xp, s) |
| 5082 | expand_T *xp; |
| 5083 | char_u *s; |
| 5084 | { |
| 5085 | return ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
| 5086 | #ifdef FEAT_MENU |
| 5087 | || ((xp->xp_context == EXPAND_MENUS |
| 5088 | || xp->xp_context == EXPAND_MENUNAMES) |
| 5089 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 5090 | #endif |
| 5091 | ); |
| 5092 | } |
| 5093 | |
| 5094 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5095 | * Show wildchar matches in the status line. |
| 5096 | * Show at least the "match" item. |
| 5097 | * We start at item 'first_match' in the list and show all matches that fit. |
| 5098 | * |
| 5099 | * If inversion is possible we use it. Else '=' characters are used. |
| 5100 | */ |
| 5101 | void |
| 5102 | win_redr_status_matches(xp, num_matches, matches, match, showtail) |
| 5103 | expand_T *xp; |
| 5104 | int num_matches; |
| 5105 | char_u **matches; /* list of matches */ |
| 5106 | int match; |
| 5107 | int showtail; |
| 5108 | { |
| 5109 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 5110 | int row; |
| 5111 | char_u *buf; |
| 5112 | int len; |
| 5113 | int clen; /* lenght in screen cells */ |
| 5114 | int fillchar; |
| 5115 | int attr; |
| 5116 | int i; |
| 5117 | int highlight = TRUE; |
| 5118 | char_u *selstart = NULL; |
| 5119 | int selstart_col = 0; |
| 5120 | char_u *selend = NULL; |
| 5121 | static int first_match = 0; |
| 5122 | int add_left = FALSE; |
| 5123 | char_u *s; |
| 5124 | #ifdef FEAT_MENU |
| 5125 | int emenu; |
| 5126 | #endif |
| 5127 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 5128 | int l; |
| 5129 | #endif |
| 5130 | |
| 5131 | if (matches == NULL) /* interrupted completion? */ |
| 5132 | return; |
| 5133 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5134 | #ifdef FEAT_MBYTE |
| 5135 | if (has_mbyte) |
| 5136 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 5137 | else |
| 5138 | #endif |
| 5139 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5140 | if (buf == NULL) |
| 5141 | return; |
| 5142 | |
| 5143 | if (match == -1) /* don't show match but original text */ |
| 5144 | { |
| 5145 | match = 0; |
| 5146 | highlight = FALSE; |
| 5147 | } |
| 5148 | /* count 1 for the ending ">" */ |
| 5149 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 5150 | if (match == 0) |
| 5151 | first_match = 0; |
| 5152 | else if (match < first_match) |
| 5153 | { |
| 5154 | /* jumping left, as far as we can go */ |
| 5155 | first_match = match; |
| 5156 | add_left = TRUE; |
| 5157 | } |
| 5158 | else |
| 5159 | { |
| 5160 | /* check if match fits on the screen */ |
| 5161 | for (i = first_match; i < match; ++i) |
| 5162 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5163 | if (first_match > 0) |
| 5164 | clen += 2; |
| 5165 | /* jumping right, put match at the left */ |
| 5166 | if ((long)clen > Columns) |
| 5167 | { |
| 5168 | first_match = match; |
| 5169 | /* if showing the last match, we can add some on the left */ |
| 5170 | clen = 2; |
| 5171 | for (i = match; i < num_matches; ++i) |
| 5172 | { |
| 5173 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5174 | if ((long)clen >= Columns) |
| 5175 | break; |
| 5176 | } |
| 5177 | if (i == num_matches) |
| 5178 | add_left = TRUE; |
| 5179 | } |
| 5180 | } |
| 5181 | if (add_left) |
| 5182 | while (first_match > 0) |
| 5183 | { |
| 5184 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 5185 | if ((long)clen >= Columns) |
| 5186 | break; |
| 5187 | --first_match; |
| 5188 | } |
| 5189 | |
| 5190 | fillchar = fillchar_status(&attr, TRUE); |
| 5191 | |
| 5192 | if (first_match == 0) |
| 5193 | { |
| 5194 | *buf = NUL; |
| 5195 | len = 0; |
| 5196 | } |
| 5197 | else |
| 5198 | { |
| 5199 | STRCPY(buf, "< "); |
| 5200 | len = 2; |
| 5201 | } |
| 5202 | clen = len; |
| 5203 | |
| 5204 | i = first_match; |
| 5205 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 5206 | { |
| 5207 | if (i == match) |
| 5208 | { |
| 5209 | selstart = buf + len; |
| 5210 | selstart_col = clen; |
| 5211 | } |
| 5212 | |
| 5213 | s = L_MATCH(i); |
| 5214 | /* Check for menu separators - replace with '|' */ |
| 5215 | #ifdef FEAT_MENU |
| 5216 | emenu = (xp->xp_context == EXPAND_MENUS |
| 5217 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5218 | if (emenu && menu_is_separator(s)) |
| 5219 | { |
| 5220 | STRCPY(buf + len, transchar('|')); |
| 5221 | l = (int)STRLEN(buf + len); |
| 5222 | len += l; |
| 5223 | clen += l; |
| 5224 | } |
| 5225 | else |
| 5226 | #endif |
| 5227 | for ( ; *s != NUL; ++s) |
| 5228 | { |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5229 | if (skip_status_match_char(xp, s)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5230 | ++s; |
| 5231 | clen += ptr2cells(s); |
| 5232 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5233 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5234 | { |
| 5235 | STRNCPY(buf + len, s, l); |
| 5236 | s += l - 1; |
| 5237 | len += l; |
| 5238 | } |
| 5239 | else |
| 5240 | #endif |
| 5241 | { |
| 5242 | STRCPY(buf + len, transchar_byte(*s)); |
| 5243 | len += (int)STRLEN(buf + len); |
| 5244 | } |
| 5245 | } |
| 5246 | if (i == match) |
| 5247 | selend = buf + len; |
| 5248 | |
| 5249 | *(buf + len++) = ' '; |
| 5250 | *(buf + len++) = ' '; |
| 5251 | clen += 2; |
| 5252 | if (++i == num_matches) |
| 5253 | break; |
| 5254 | } |
| 5255 | |
| 5256 | if (i != num_matches) |
| 5257 | { |
| 5258 | *(buf + len++) = '>'; |
| 5259 | ++clen; |
| 5260 | } |
| 5261 | |
| 5262 | buf[len] = NUL; |
| 5263 | |
| 5264 | row = cmdline_row - 1; |
| 5265 | if (row >= 0) |
| 5266 | { |
| 5267 | if (wild_menu_showing == 0) |
| 5268 | { |
| 5269 | if (msg_scrolled > 0) |
| 5270 | { |
| 5271 | /* Put the wildmenu just above the command line. If there is |
| 5272 | * no room, scroll the screen one line up. */ |
| 5273 | if (cmdline_row == Rows - 1) |
| 5274 | { |
| 5275 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 5276 | ++msg_scrolled; |
| 5277 | } |
| 5278 | else |
| 5279 | { |
| 5280 | ++cmdline_row; |
| 5281 | ++row; |
| 5282 | } |
| 5283 | wild_menu_showing = WM_SCROLLED; |
| 5284 | } |
| 5285 | else |
| 5286 | { |
| 5287 | /* Create status line if needed by setting 'laststatus' to 2. |
| 5288 | * Set 'winminheight' to zero to avoid that the window is |
| 5289 | * resized. */ |
| 5290 | if (lastwin->w_status_height == 0) |
| 5291 | { |
| 5292 | save_p_ls = p_ls; |
| 5293 | save_p_wmh = p_wmh; |
| 5294 | p_ls = 2; |
| 5295 | p_wmh = 0; |
| 5296 | last_status(FALSE); |
| 5297 | } |
| 5298 | wild_menu_showing = WM_SHOWN; |
| 5299 | } |
| 5300 | } |
| 5301 | |
| 5302 | screen_puts(buf, row, 0, attr); |
| 5303 | if (selstart != NULL && highlight) |
| 5304 | { |
| 5305 | *selend = NUL; |
| 5306 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 5307 | } |
| 5308 | |
| 5309 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 5310 | } |
| 5311 | |
| 5312 | #ifdef FEAT_VERTSPLIT |
| 5313 | win_redraw_last_status(topframe); |
| 5314 | #else |
| 5315 | lastwin->w_redr_status = TRUE; |
| 5316 | #endif |
| 5317 | vim_free(buf); |
| 5318 | } |
| 5319 | #endif |
| 5320 | |
| 5321 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5322 | /* |
| 5323 | * Redraw the status line of window wp. |
| 5324 | * |
| 5325 | * If inversion is possible we use it. Else '=' characters are used. |
| 5326 | */ |
| 5327 | void |
| 5328 | win_redr_status(wp) |
| 5329 | win_T *wp; |
| 5330 | { |
| 5331 | int row; |
| 5332 | char_u *p; |
| 5333 | int len; |
| 5334 | int fillchar; |
| 5335 | int attr; |
| 5336 | int this_ru_col; |
| 5337 | |
| 5338 | wp->w_redr_status = FALSE; |
| 5339 | if (wp->w_status_height == 0) |
| 5340 | { |
| 5341 | /* no status line, can only be last window */ |
| 5342 | redraw_cmdline = TRUE; |
| 5343 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 5344 | else if (!redrawing() |
| 5345 | #ifdef FEAT_INS_EXPAND |
| 5346 | /* don't update status line when popup menu is visible and may be |
| 5347 | * drawn over it */ |
| 5348 | || pum_visible() |
| 5349 | #endif |
| 5350 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5351 | { |
| 5352 | /* Don't redraw right now, do it later. */ |
| 5353 | wp->w_redr_status = TRUE; |
| 5354 | } |
| 5355 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5356 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5357 | { |
| 5358 | /* redraw custom status line */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5359 | redraw_custum_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5360 | } |
| 5361 | #endif |
| 5362 | else |
| 5363 | { |
| 5364 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5365 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 5366 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5367 | p = NameBuff; |
| 5368 | len = (int)STRLEN(p); |
| 5369 | |
| 5370 | if (wp->w_buffer->b_help |
| 5371 | #ifdef FEAT_QUICKFIX |
| 5372 | || wp->w_p_pvw |
| 5373 | #endif |
| 5374 | || bufIsChanged(wp->w_buffer) |
| 5375 | || wp->w_buffer->b_p_ro) |
| 5376 | *(p + len++) = ' '; |
| 5377 | if (wp->w_buffer->b_help) |
| 5378 | { |
| 5379 | STRCPY(p + len, _("[help]")); |
| 5380 | len += (int)STRLEN(p + len); |
| 5381 | } |
| 5382 | #ifdef FEAT_QUICKFIX |
| 5383 | if (wp->w_p_pvw) |
| 5384 | { |
| 5385 | STRCPY(p + len, _("[Preview]")); |
| 5386 | len += (int)STRLEN(p + len); |
| 5387 | } |
| 5388 | #endif |
| 5389 | if (bufIsChanged(wp->w_buffer)) |
| 5390 | { |
| 5391 | STRCPY(p + len, "[+]"); |
| 5392 | len += 3; |
| 5393 | } |
| 5394 | if (wp->w_buffer->b_p_ro) |
| 5395 | { |
| 5396 | STRCPY(p + len, "[RO]"); |
| 5397 | len += 4; |
| 5398 | } |
| 5399 | |
| 5400 | #ifndef FEAT_VERTSPLIT |
| 5401 | this_ru_col = ru_col; |
| 5402 | if (this_ru_col < (Columns + 1) / 2) |
| 5403 | this_ru_col = (Columns + 1) / 2; |
| 5404 | #else |
| 5405 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 5406 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 5407 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 5408 | if (this_ru_col <= 1) |
| 5409 | { |
| 5410 | p = (char_u *)"<"; /* No room for file name! */ |
| 5411 | len = 1; |
| 5412 | } |
| 5413 | else |
| 5414 | #endif |
| 5415 | #ifdef FEAT_MBYTE |
| 5416 | if (has_mbyte) |
| 5417 | { |
| 5418 | int clen = 0, i; |
| 5419 | |
| 5420 | /* Count total number of display cells. */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5421 | for (i = 0; p[i] != NUL; i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5422 | clen += (*mb_ptr2cells)(p + i); |
| 5423 | /* Find first character that will fit. |
| 5424 | * Going from start to end is much faster for DBCS. */ |
| 5425 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5426 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5427 | clen -= (*mb_ptr2cells)(p + i); |
| 5428 | len = clen; |
| 5429 | if (i > 0) |
| 5430 | { |
| 5431 | p = p + i - 1; |
| 5432 | *p = '<'; |
| 5433 | ++len; |
| 5434 | } |
| 5435 | |
| 5436 | } |
| 5437 | else |
| 5438 | #endif |
| 5439 | if (len > this_ru_col - 1) |
| 5440 | { |
| 5441 | p += len - (this_ru_col - 1); |
| 5442 | *p = '<'; |
| 5443 | len = this_ru_col - 1; |
| 5444 | } |
| 5445 | |
| 5446 | row = W_WINROW(wp) + wp->w_height; |
| 5447 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 5448 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 5449 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 5450 | |
| 5451 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 5452 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 5453 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 5454 | - 1 + W_WINCOL(wp)), attr); |
| 5455 | |
| 5456 | #ifdef FEAT_CMDL_INFO |
| 5457 | win_redr_ruler(wp, TRUE); |
| 5458 | #endif |
| 5459 | } |
| 5460 | |
| 5461 | #ifdef FEAT_VERTSPLIT |
| 5462 | /* |
| 5463 | * May need to draw the character below the vertical separator. |
| 5464 | */ |
| 5465 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 5466 | { |
| 5467 | if (stl_connected(wp)) |
| 5468 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5469 | else |
| 5470 | fillchar = fillchar_vsep(&attr); |
| 5471 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 5472 | attr); |
| 5473 | } |
| 5474 | #endif |
| 5475 | } |
| 5476 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5477 | #ifdef FEAT_STL_OPT |
| 5478 | /* |
| 5479 | * Redraw the status line according to 'statusline' and take care of any |
| 5480 | * errors encountered. |
| 5481 | */ |
| 5482 | static void |
| 5483 | redraw_custum_statusline(wp) |
| 5484 | win_T *wp; |
| 5485 | { |
| 5486 | int save_called_emsg = called_emsg; |
| 5487 | |
| 5488 | called_emsg = FALSE; |
| 5489 | win_redr_custom(wp, FALSE); |
| 5490 | if (called_emsg) |
| 5491 | set_string_option_direct((char_u *)"statusline", -1, |
| 5492 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5493 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5494 | called_emsg |= save_called_emsg; |
| 5495 | } |
| 5496 | #endif |
| 5497 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5498 | # ifdef FEAT_VERTSPLIT |
| 5499 | /* |
| 5500 | * Return TRUE if the status line of window "wp" is connected to the status |
| 5501 | * line of the window right of it. If not, then it's a vertical separator. |
| 5502 | * Only call if (wp->w_vsep_width != 0). |
| 5503 | */ |
| 5504 | int |
| 5505 | stl_connected(wp) |
| 5506 | win_T *wp; |
| 5507 | { |
| 5508 | frame_T *fr; |
| 5509 | |
| 5510 | fr = wp->w_frame; |
| 5511 | while (fr->fr_parent != NULL) |
| 5512 | { |
| 5513 | if (fr->fr_parent->fr_layout == FR_COL) |
| 5514 | { |
| 5515 | if (fr->fr_next != NULL) |
| 5516 | break; |
| 5517 | } |
| 5518 | else |
| 5519 | { |
| 5520 | if (fr->fr_next != NULL) |
| 5521 | return TRUE; |
| 5522 | } |
| 5523 | fr = fr->fr_parent; |
| 5524 | } |
| 5525 | return FALSE; |
| 5526 | } |
| 5527 | # endif |
| 5528 | |
| 5529 | #endif /* FEAT_WINDOWS */ |
| 5530 | |
| 5531 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 5532 | /* |
| 5533 | * Get the value to show for the language mappings, active 'keymap'. |
| 5534 | */ |
| 5535 | int |
| 5536 | get_keymap_str(wp, buf, len) |
| 5537 | win_T *wp; |
| 5538 | char_u *buf; /* buffer for the result */ |
| 5539 | int len; /* length of buffer */ |
| 5540 | { |
| 5541 | char_u *p; |
| 5542 | |
| 5543 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 5544 | return FALSE; |
| 5545 | |
| 5546 | { |
| 5547 | #ifdef FEAT_EVAL |
| 5548 | buf_T *old_curbuf = curbuf; |
| 5549 | win_T *old_curwin = curwin; |
| 5550 | char_u *s; |
| 5551 | |
| 5552 | curbuf = wp->w_buffer; |
| 5553 | curwin = wp; |
| 5554 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 5555 | ++emsg_skip; |
| 5556 | s = p = eval_to_string(buf, NULL); |
| 5557 | --emsg_skip; |
| 5558 | curbuf = old_curbuf; |
| 5559 | curwin = old_curwin; |
| 5560 | if (p == NULL || *p == NUL) |
| 5561 | #endif |
| 5562 | { |
| 5563 | #ifdef FEAT_KEYMAP |
| 5564 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 5565 | p = wp->w_buffer->b_p_keymap; |
| 5566 | else |
| 5567 | #endif |
| 5568 | p = (char_u *)"lang"; |
| 5569 | } |
| 5570 | if ((int)(STRLEN(p) + 3) < len) |
| 5571 | sprintf((char *)buf, "<%s>", p); |
| 5572 | else |
| 5573 | buf[0] = NUL; |
| 5574 | #ifdef FEAT_EVAL |
| 5575 | vim_free(s); |
| 5576 | #endif |
| 5577 | } |
| 5578 | return buf[0] != NUL; |
| 5579 | } |
| 5580 | #endif |
| 5581 | |
| 5582 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 5583 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5584 | * Redraw the status line or ruler of window "wp". |
| 5585 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5586 | */ |
| 5587 | static void |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 5588 | win_redr_custom(wp, draw_ruler) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5589 | win_T *wp; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 5590 | int draw_ruler; /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5591 | { |
| 5592 | int attr; |
| 5593 | int curattr; |
| 5594 | int row; |
| 5595 | int col = 0; |
| 5596 | int maxwidth; |
| 5597 | int width; |
| 5598 | int n; |
| 5599 | int len; |
| 5600 | int fillchar; |
| 5601 | char_u buf[MAXPATHL]; |
| 5602 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5603 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 5604 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5605 | int use_sandbox = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5606 | |
| 5607 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5608 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5609 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5610 | /* Use 'tabline'. Always at the first line of the screen. */ |
| 5611 | p = p_tal; |
| 5612 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 5613 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5614 | attr = hl_attr(HLF_TPF); |
| 5615 | maxwidth = Columns; |
| 5616 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5617 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5618 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5619 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5620 | else |
| 5621 | { |
| 5622 | row = W_WINROW(wp) + wp->w_height; |
| 5623 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5624 | maxwidth = W_WIDTH(wp); |
| 5625 | |
| 5626 | if (draw_ruler) |
| 5627 | { |
| 5628 | p = p_ruf; |
| 5629 | /* advance past any leading group spec - implicit in ru_col */ |
| 5630 | if (*p == '%') |
| 5631 | { |
| 5632 | if (*++p == '-') |
| 5633 | p++; |
| 5634 | if (atoi((char *) p)) |
| 5635 | while (VIM_ISDIGIT(*p)) |
| 5636 | p++; |
| 5637 | if (*p++ != '(') |
| 5638 | p = p_ruf; |
| 5639 | } |
| 5640 | #ifdef FEAT_VERTSPLIT |
| 5641 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 5642 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 5643 | col = (W_WIDTH(wp) + 1) / 2; |
| 5644 | #else |
| 5645 | col = ru_col; |
| 5646 | if (col > (Columns + 1) / 2) |
| 5647 | col = (Columns + 1) / 2; |
| 5648 | #endif |
| 5649 | maxwidth = W_WIDTH(wp) - col; |
| 5650 | #ifdef FEAT_WINDOWS |
| 5651 | if (!wp->w_status_height) |
| 5652 | #endif |
| 5653 | { |
| 5654 | row = Rows - 1; |
| 5655 | --maxwidth; /* writing in last column may cause scrolling */ |
| 5656 | fillchar = ' '; |
| 5657 | attr = 0; |
| 5658 | } |
| 5659 | |
| 5660 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5661 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5662 | # endif |
| 5663 | } |
| 5664 | else |
| 5665 | { |
| 5666 | if (*wp->w_p_stl != NUL) |
| 5667 | p = wp->w_p_stl; |
| 5668 | else |
| 5669 | p = p_stl; |
| 5670 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5671 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 5672 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5673 | # endif |
| 5674 | } |
| 5675 | |
| 5676 | #ifdef FEAT_VERTSPLIT |
| 5677 | col += W_WINCOL(wp); |
| 5678 | #endif |
| 5679 | } |
| 5680 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5681 | if (maxwidth <= 0) |
| 5682 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5683 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5684 | width = build_stl_str_hl(wp == NULL ? curwin : wp, |
| 5685 | buf, sizeof(buf), |
| 5686 | p, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5687 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5688 | len = STRLEN(buf); |
| 5689 | |
| 5690 | while (width < maxwidth && len < sizeof(buf) - 1) |
| 5691 | { |
| 5692 | #ifdef FEAT_MBYTE |
| 5693 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 5694 | #else |
| 5695 | buf[len++] = fillchar; |
| 5696 | #endif |
| 5697 | ++width; |
| 5698 | } |
| 5699 | buf[len] = NUL; |
| 5700 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5701 | /* |
| 5702 | * Draw each snippet with the specified highlighting. |
| 5703 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5704 | curattr = attr; |
| 5705 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5706 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5707 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5708 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5709 | screen_puts_len(p, len, row, col, curattr); |
| 5710 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5711 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5712 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5713 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5714 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5715 | else if (hltab[n].userhl < 0) |
| 5716 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5717 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5718 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5719 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5720 | #endif |
| 5721 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5722 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5723 | } |
| 5724 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5725 | |
| 5726 | if (wp == NULL) |
| 5727 | { |
| 5728 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 5729 | col = 0; |
| 5730 | len = 0; |
| 5731 | p = buf; |
| 5732 | fillchar = 0; |
| 5733 | for (n = 0; tabtab[n].start != NULL; n++) |
| 5734 | { |
| 5735 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 5736 | while (col < len) |
| 5737 | TabPageIdxs[col++] = fillchar; |
| 5738 | p = tabtab[n].start; |
| 5739 | fillchar = tabtab[n].userhl; |
| 5740 | } |
| 5741 | while (col < Columns) |
| 5742 | TabPageIdxs[col++] = fillchar; |
| 5743 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | #endif /* FEAT_STL_OPT */ |
| 5747 | |
| 5748 | /* |
| 5749 | * Output a single character directly to the screen and update ScreenLines. |
| 5750 | */ |
| 5751 | void |
| 5752 | screen_putchar(c, row, col, attr) |
| 5753 | int c; |
| 5754 | int row, col; |
| 5755 | int attr; |
| 5756 | { |
| 5757 | #ifdef FEAT_MBYTE |
| 5758 | char_u buf[MB_MAXBYTES + 1]; |
| 5759 | |
| 5760 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 5761 | #else |
| 5762 | char_u buf[2]; |
| 5763 | |
| 5764 | buf[0] = c; |
| 5765 | buf[1] = NUL; |
| 5766 | #endif |
| 5767 | screen_puts(buf, row, col, attr); |
| 5768 | } |
| 5769 | |
| 5770 | /* |
| 5771 | * Get a single character directly from ScreenLines into "bytes[]". |
| 5772 | * Also return its attribute in *attrp; |
| 5773 | */ |
| 5774 | void |
| 5775 | screen_getbytes(row, col, bytes, attrp) |
| 5776 | int row, col; |
| 5777 | char_u *bytes; |
| 5778 | int *attrp; |
| 5779 | { |
| 5780 | unsigned off; |
| 5781 | |
| 5782 | /* safety check */ |
| 5783 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 5784 | { |
| 5785 | off = LineOffset[row] + col; |
| 5786 | *attrp = ScreenAttrs[off]; |
| 5787 | bytes[0] = ScreenLines[off]; |
| 5788 | bytes[1] = NUL; |
| 5789 | |
| 5790 | #ifdef FEAT_MBYTE |
| 5791 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 5792 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 5793 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 5794 | { |
| 5795 | bytes[0] = ScreenLines[off]; |
| 5796 | bytes[1] = ScreenLines2[off]; |
| 5797 | bytes[2] = NUL; |
| 5798 | } |
| 5799 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 5800 | { |
| 5801 | bytes[1] = ScreenLines[off + 1]; |
| 5802 | bytes[2] = NUL; |
| 5803 | } |
| 5804 | #endif |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | /* |
| 5809 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 5810 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 5811 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 5812 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 5813 | */ |
| 5814 | void |
| 5815 | screen_puts(text, row, col, attr) |
| 5816 | char_u *text; |
| 5817 | int row; |
| 5818 | int col; |
| 5819 | int attr; |
| 5820 | { |
| 5821 | screen_puts_len(text, -1, row, col, attr); |
| 5822 | } |
| 5823 | |
| 5824 | /* |
| 5825 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 5826 | * a NUL. |
| 5827 | */ |
| 5828 | void |
| 5829 | screen_puts_len(text, len, row, col, attr) |
| 5830 | char_u *text; |
| 5831 | int len; |
| 5832 | int row; |
| 5833 | int col; |
| 5834 | int attr; |
| 5835 | { |
| 5836 | unsigned off; |
| 5837 | char_u *ptr = text; |
| 5838 | int c; |
| 5839 | #ifdef FEAT_MBYTE |
| 5840 | int mbyte_blen = 1; |
| 5841 | int mbyte_cells = 1; |
| 5842 | int u8c = 0; |
| 5843 | int u8c_c1 = 0; |
| 5844 | int u8c_c2 = 0; |
| 5845 | int clear_next_cell = FALSE; |
| 5846 | # ifdef FEAT_ARABIC |
| 5847 | int prev_c = 0; /* previous Arabic character */ |
| 5848 | int pc, nc, nc1, dummy; |
| 5849 | # endif |
| 5850 | #endif |
| 5851 | |
| 5852 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 5853 | return; |
| 5854 | |
| 5855 | off = LineOffset[row] + col; |
| 5856 | while (*ptr != NUL && col < screen_Columns |
| 5857 | && (len < 0 || (int)(ptr - text) < len)) |
| 5858 | { |
| 5859 | c = *ptr; |
| 5860 | #ifdef FEAT_MBYTE |
| 5861 | /* check if this is the first byte of a multibyte */ |
| 5862 | if (has_mbyte) |
| 5863 | { |
| 5864 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5865 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5866 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5867 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5868 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 5869 | mbyte_cells = 1; |
| 5870 | else if (enc_dbcs != 0) |
| 5871 | mbyte_cells = mbyte_blen; |
| 5872 | else /* enc_utf8 */ |
| 5873 | { |
| 5874 | if (len >= 0) |
| 5875 | u8c = utfc_ptr2char_len(ptr, &u8c_c1, &u8c_c2, |
| 5876 | (int)((text + len) - ptr)); |
| 5877 | else |
| 5878 | u8c = utfc_ptr2char(ptr, &u8c_c1, &u8c_c2); |
| 5879 | mbyte_cells = utf_char2cells(u8c); |
| 5880 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 5881 | if (u8c >= 0x10000) |
| 5882 | { |
| 5883 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 5884 | if (attr == 0) |
| 5885 | attr = hl_attr(HLF_8); |
| 5886 | } |
| 5887 | # ifdef FEAT_ARABIC |
| 5888 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 5889 | { |
| 5890 | /* Do Arabic shaping. */ |
| 5891 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 5892 | { |
| 5893 | /* Past end of string to be displayed. */ |
| 5894 | nc = NUL; |
| 5895 | nc1 = NUL; |
| 5896 | } |
| 5897 | else |
| 5898 | nc = utfc_ptr2char(ptr + mbyte_blen, &nc1, &dummy); |
| 5899 | pc = prev_c; |
| 5900 | prev_c = u8c; |
| 5901 | u8c = arabic_shape(u8c, &c, &u8c_c1, nc, nc1, pc); |
| 5902 | } |
| 5903 | else |
| 5904 | prev_c = u8c; |
| 5905 | # endif |
| 5906 | } |
| 5907 | } |
| 5908 | #endif |
| 5909 | |
| 5910 | if (ScreenLines[off] != c |
| 5911 | #ifdef FEAT_MBYTE |
| 5912 | || (mbyte_cells == 2 |
| 5913 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 5914 | || (enc_dbcs == DBCS_JPNU |
| 5915 | && c == 0x8e |
| 5916 | && ScreenLines2[off] != ptr[1]) |
| 5917 | || (enc_utf8 |
| 5918 | && mbyte_blen > 1 |
| 5919 | && (ScreenLinesUC[off] != u8c |
| 5920 | || ScreenLinesC1[off] != u8c_c1 |
| 5921 | || ScreenLinesC2[off] != u8c_c2)) |
| 5922 | #endif |
| 5923 | || ScreenAttrs[off] != attr |
| 5924 | || exmode_active |
| 5925 | ) |
| 5926 | { |
| 5927 | #if defined(FEAT_GUI) || defined(UNIX) |
| 5928 | /* The bold trick makes a single row of pixels appear in the next |
| 5929 | * character. When a bold character is removed, the next |
| 5930 | * character should be redrawn too. This happens for our own GUI |
| 5931 | * and for some xterms. |
| 5932 | * Force the redraw by setting the attribute to a different value |
| 5933 | * than "attr", the contents of ScreenLines[] may be needed by |
| 5934 | * mb_off2cells() further on. |
| 5935 | * Don't do this for the last drawn character, because the next |
| 5936 | * character may not be redrawn. */ |
| 5937 | if ( |
| 5938 | # ifdef FEAT_GUI |
| 5939 | gui.in_use |
| 5940 | # endif |
| 5941 | # if defined(FEAT_GUI) && defined(UNIX) |
| 5942 | || |
| 5943 | # endif |
| 5944 | # ifdef UNIX |
| 5945 | term_is_xterm |
| 5946 | # endif |
| 5947 | ) |
| 5948 | { |
| 5949 | int n; |
| 5950 | |
| 5951 | n = ScreenAttrs[off]; |
| 5952 | # ifdef FEAT_MBYTE |
| 5953 | if (col + mbyte_cells < screen_Columns |
| 5954 | && (n > HL_ALL || (n & HL_BOLD)) |
| 5955 | && (len < 0 ? ptr[mbyte_blen] != NUL |
| 5956 | : ptr + mbyte_blen < text + len)) |
| 5957 | ScreenAttrs[off + mbyte_cells] = attr + 1; |
| 5958 | # else |
| 5959 | if (col + 1 < screen_Columns |
| 5960 | && (n > HL_ALL || (n & HL_BOLD)) |
| 5961 | && (len < 0 ? ptr[1] != NUL : ptr + 1 < text + len)) |
| 5962 | ScreenLines[off + 1] = 0; |
| 5963 | # endif |
| 5964 | } |
| 5965 | #endif |
| 5966 | #ifdef FEAT_MBYTE |
| 5967 | /* When at the end of the text and overwriting a two-cell |
| 5968 | * character with a one-cell character, need to clear the next |
| 5969 | * cell. Also when overwriting the left halve of a two-cell char |
| 5970 | * with the right halve of a two-cell char. Do this only once |
| 5971 | * (mb_off2cells() may return 2 on the right halve). */ |
| 5972 | if (clear_next_cell) |
| 5973 | clear_next_cell = FALSE; |
| 5974 | else if (has_mbyte |
| 5975 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 5976 | : ptr + mbyte_blen >= text + len) |
| 5977 | && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) |
| 5978 | || (mbyte_cells == 2 |
| 5979 | && (*mb_off2cells)(off) == 1 |
| 5980 | && (*mb_off2cells)(off + 1) > 1))) |
| 5981 | clear_next_cell = TRUE; |
| 5982 | |
| 5983 | /* Make sure we never leave a second byte of a double-byte behind, |
| 5984 | * it confuses mb_off2cells(). */ |
| 5985 | if (enc_dbcs |
| 5986 | && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) |
| 5987 | || (mbyte_cells == 2 |
| 5988 | && (*mb_off2cells)(off) == 1 |
| 5989 | && (*mb_off2cells)(off + 1) > 1))) |
| 5990 | ScreenLines[off + mbyte_blen] = 0; |
| 5991 | #endif |
| 5992 | ScreenLines[off] = c; |
| 5993 | ScreenAttrs[off] = attr; |
| 5994 | #ifdef FEAT_MBYTE |
| 5995 | if (enc_utf8) |
| 5996 | { |
| 5997 | if (c < 0x80 && u8c_c1 == 0 && u8c_c2 == 0) |
| 5998 | ScreenLinesUC[off] = 0; |
| 5999 | else |
| 6000 | { |
| 6001 | ScreenLinesUC[off] = u8c; |
| 6002 | ScreenLinesC1[off] = u8c_c1; |
| 6003 | ScreenLinesC2[off] = u8c_c2; |
| 6004 | } |
| 6005 | if (mbyte_cells == 2) |
| 6006 | { |
| 6007 | ScreenLines[off + 1] = 0; |
| 6008 | ScreenAttrs[off + 1] = attr; |
| 6009 | } |
| 6010 | screen_char(off, row, col); |
| 6011 | } |
| 6012 | else if (mbyte_cells == 2) |
| 6013 | { |
| 6014 | ScreenLines[off + 1] = ptr[1]; |
| 6015 | ScreenAttrs[off + 1] = attr; |
| 6016 | screen_char_2(off, row, col); |
| 6017 | } |
| 6018 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6019 | { |
| 6020 | ScreenLines2[off] = ptr[1]; |
| 6021 | screen_char(off, row, col); |
| 6022 | } |
| 6023 | else |
| 6024 | #endif |
| 6025 | screen_char(off, row, col); |
| 6026 | } |
| 6027 | #ifdef FEAT_MBYTE |
| 6028 | if (has_mbyte) |
| 6029 | { |
| 6030 | off += mbyte_cells; |
| 6031 | col += mbyte_cells; |
| 6032 | ptr += mbyte_blen; |
| 6033 | if (clear_next_cell) |
| 6034 | ptr = (char_u *)" "; |
| 6035 | } |
| 6036 | else |
| 6037 | #endif |
| 6038 | { |
| 6039 | ++off; |
| 6040 | ++col; |
| 6041 | ++ptr; |
| 6042 | } |
| 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | #ifdef FEAT_SEARCH_EXTRA |
| 6047 | /* |
| 6048 | * Prepare for 'searchhl' highlighting. |
| 6049 | */ |
| 6050 | static void |
| 6051 | start_search_hl() |
| 6052 | { |
| 6053 | if (p_hls && !no_hlsearch) |
| 6054 | { |
| 6055 | last_pat_prog(&search_hl.rm); |
| 6056 | search_hl.attr = hl_attr(HLF_L); |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | /* |
| 6061 | * Clean up for 'searchhl' highlighting. |
| 6062 | */ |
| 6063 | static void |
| 6064 | end_search_hl() |
| 6065 | { |
| 6066 | if (search_hl.rm.regprog != NULL) |
| 6067 | { |
| 6068 | vim_free(search_hl.rm.regprog); |
| 6069 | search_hl.rm.regprog = NULL; |
| 6070 | } |
| 6071 | } |
| 6072 | |
| 6073 | /* |
| 6074 | * Advance to the match in window "wp" line "lnum" or past it. |
| 6075 | */ |
| 6076 | static void |
| 6077 | prepare_search_hl(wp, lnum) |
| 6078 | win_T *wp; |
| 6079 | linenr_T lnum; |
| 6080 | { |
| 6081 | match_T *shl; /* points to search_hl or match_hl */ |
| 6082 | int n; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6083 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6084 | |
| 6085 | /* |
| 6086 | * When using a multi-line pattern, start searching at the top |
| 6087 | * of the window or just after a closed fold. |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6088 | * Do this both for search_hl and match_hl[3]. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6089 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6090 | for (i = 3; i >= 0; --i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6091 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6092 | shl = (i == 3) ? &search_hl : &match_hl[i]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6093 | if (shl->rm.regprog != NULL |
| 6094 | && shl->lnum == 0 |
| 6095 | && re_multiline(shl->rm.regprog)) |
| 6096 | { |
| 6097 | if (shl->first_lnum == 0) |
| 6098 | { |
| 6099 | # ifdef FEAT_FOLDING |
| 6100 | for (shl->first_lnum = lnum; |
| 6101 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 6102 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 6103 | NULL, NULL, TRUE, NULL)) |
| 6104 | break; |
| 6105 | # else |
| 6106 | shl->first_lnum = wp->w_topline; |
| 6107 | # endif |
| 6108 | } |
| 6109 | n = 0; |
| 6110 | while (shl->first_lnum < lnum && shl->rm.regprog != NULL) |
| 6111 | { |
| 6112 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); |
| 6113 | if (shl->lnum != 0) |
| 6114 | { |
| 6115 | shl->first_lnum = shl->lnum |
| 6116 | + shl->rm.endpos[0].lnum |
| 6117 | - shl->rm.startpos[0].lnum; |
| 6118 | n = shl->rm.endpos[0].col; |
| 6119 | } |
| 6120 | else |
| 6121 | { |
| 6122 | ++shl->first_lnum; |
| 6123 | n = 0; |
| 6124 | } |
| 6125 | } |
| 6126 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | /* |
| 6131 | * Search for a next 'searchl' or ":match" match. |
| 6132 | * Uses shl->buf. |
| 6133 | * Sets shl->lnum and shl->rm contents. |
| 6134 | * Note: Assumes a previous match is always before "lnum", unless |
| 6135 | * shl->lnum is zero. |
| 6136 | * Careful: Any pointers for buffer lines will become invalid. |
| 6137 | */ |
| 6138 | static void |
| 6139 | next_search_hl(win, shl, lnum, mincol) |
| 6140 | win_T *win; |
| 6141 | match_T *shl; /* points to search_hl or match_hl */ |
| 6142 | linenr_T lnum; |
| 6143 | colnr_T mincol; /* minimal column for a match */ |
| 6144 | { |
| 6145 | linenr_T l; |
| 6146 | colnr_T matchcol; |
| 6147 | long nmatched; |
| 6148 | |
| 6149 | if (shl->lnum != 0) |
| 6150 | { |
| 6151 | /* Check for three situations: |
| 6152 | * 1. If the "lnum" is below a previous match, start a new search. |
| 6153 | * 2. If the previous match includes "mincol", use it. |
| 6154 | * 3. Continue after the previous match. |
| 6155 | */ |
| 6156 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 6157 | if (lnum > l) |
| 6158 | shl->lnum = 0; |
| 6159 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 6160 | return; |
| 6161 | } |
| 6162 | |
| 6163 | /* |
| 6164 | * Repeat searching for a match until one is found that includes "mincol" |
| 6165 | * or none is found in this line. |
| 6166 | */ |
| 6167 | called_emsg = FALSE; |
| 6168 | for (;;) |
| 6169 | { |
| 6170 | /* Three situations: |
| 6171 | * 1. No useful previous match: search from start of line. |
| 6172 | * 2. Not Vi compatible or empty match: continue at next character. |
| 6173 | * Break the loop if this is beyond the end of the line. |
| 6174 | * 3. Vi compatible searching: continue at end of previous match. |
| 6175 | */ |
| 6176 | if (shl->lnum == 0) |
| 6177 | matchcol = 0; |
| 6178 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 6179 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6180 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6181 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 6182 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6183 | |
| 6184 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 6185 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6186 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6187 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6188 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6189 | shl->lnum = 0; |
| 6190 | break; |
| 6191 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6192 | #ifdef FEAT_MBYTE |
| 6193 | if (has_mbyte) |
| 6194 | matchcol += mb_ptr2len(ml); |
| 6195 | else |
| 6196 | #endif |
| 6197 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6198 | } |
| 6199 | else |
| 6200 | matchcol = shl->rm.endpos[0].col; |
| 6201 | |
| 6202 | shl->lnum = lnum; |
| 6203 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol); |
| 6204 | if (called_emsg) |
| 6205 | { |
| 6206 | /* Error while handling regexp: stop using this regexp. */ |
| 6207 | vim_free(shl->rm.regprog); |
| 6208 | shl->rm.regprog = NULL; |
| 6209 | no_hlsearch = TRUE; |
| 6210 | break; |
| 6211 | } |
| 6212 | if (nmatched == 0) |
| 6213 | { |
| 6214 | shl->lnum = 0; /* no match found */ |
| 6215 | break; |
| 6216 | } |
| 6217 | if (shl->rm.startpos[0].lnum > 0 |
| 6218 | || shl->rm.startpos[0].col >= mincol |
| 6219 | || nmatched > 1 |
| 6220 | || shl->rm.endpos[0].col > mincol) |
| 6221 | { |
| 6222 | shl->lnum += shl->rm.startpos[0].lnum; |
| 6223 | break; /* useful match found */ |
| 6224 | } |
| 6225 | } |
| 6226 | } |
| 6227 | #endif |
| 6228 | |
| 6229 | static void |
| 6230 | screen_start_highlight(attr) |
| 6231 | int attr; |
| 6232 | { |
| 6233 | attrentry_T *aep = NULL; |
| 6234 | |
| 6235 | screen_attr = attr; |
| 6236 | if (full_screen |
| 6237 | #ifdef WIN3264 |
| 6238 | && termcap_active |
| 6239 | #endif |
| 6240 | ) |
| 6241 | { |
| 6242 | #ifdef FEAT_GUI |
| 6243 | if (gui.in_use) |
| 6244 | { |
| 6245 | char buf[20]; |
| 6246 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6247 | /* The GUI handles this internally. */ |
| 6248 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6249 | OUT_STR(buf); |
| 6250 | } |
| 6251 | else |
| 6252 | #endif |
| 6253 | { |
| 6254 | if (attr > HL_ALL) /* special HL attr. */ |
| 6255 | { |
| 6256 | if (t_colors > 1) |
| 6257 | aep = syn_cterm_attr2entry(attr); |
| 6258 | else |
| 6259 | aep = syn_term_attr2entry(attr); |
| 6260 | if (aep == NULL) /* did ":syntax clear" */ |
| 6261 | attr = 0; |
| 6262 | else |
| 6263 | attr = aep->ae_attr; |
| 6264 | } |
| 6265 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 6266 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6267 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 6268 | && cterm_normal_fg_bold) |
| 6269 | /* If the Normal FG color has BOLD attribute and the new HL |
| 6270 | * has a FG color defined, clear BOLD. */ |
| 6271 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6272 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 6273 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6274 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 6275 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6276 | out_str(T_US); |
| 6277 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 6278 | out_str(T_CZH); |
| 6279 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 6280 | out_str(T_MR); |
| 6281 | |
| 6282 | /* |
| 6283 | * Output the color or start string after bold etc., in case the |
| 6284 | * bold etc. override the color setting. |
| 6285 | */ |
| 6286 | if (aep != NULL) |
| 6287 | { |
| 6288 | if (t_colors > 1) |
| 6289 | { |
| 6290 | if (aep->ae_u.cterm.fg_color) |
| 6291 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 6292 | if (aep->ae_u.cterm.bg_color) |
| 6293 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 6294 | } |
| 6295 | else |
| 6296 | { |
| 6297 | if (aep->ae_u.term.start != NULL) |
| 6298 | out_str(aep->ae_u.term.start); |
| 6299 | } |
| 6300 | } |
| 6301 | } |
| 6302 | } |
| 6303 | } |
| 6304 | |
| 6305 | void |
| 6306 | screen_stop_highlight() |
| 6307 | { |
| 6308 | int do_ME = FALSE; /* output T_ME code */ |
| 6309 | |
| 6310 | if (screen_attr != 0 |
| 6311 | #ifdef WIN3264 |
| 6312 | && termcap_active |
| 6313 | #endif |
| 6314 | ) |
| 6315 | { |
| 6316 | #ifdef FEAT_GUI |
| 6317 | if (gui.in_use) |
| 6318 | { |
| 6319 | char buf[20]; |
| 6320 | |
| 6321 | /* use internal GUI code */ |
| 6322 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 6323 | OUT_STR(buf); |
| 6324 | } |
| 6325 | else |
| 6326 | #endif |
| 6327 | { |
| 6328 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 6329 | { |
| 6330 | attrentry_T *aep; |
| 6331 | |
| 6332 | if (t_colors > 1) |
| 6333 | { |
| 6334 | /* |
| 6335 | * Assume that t_me restores the original colors! |
| 6336 | */ |
| 6337 | aep = syn_cterm_attr2entry(screen_attr); |
| 6338 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 6339 | || aep->ae_u.cterm.bg_color)) |
| 6340 | do_ME = TRUE; |
| 6341 | } |
| 6342 | else |
| 6343 | { |
| 6344 | aep = syn_term_attr2entry(screen_attr); |
| 6345 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 6346 | { |
| 6347 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 6348 | do_ME = TRUE; |
| 6349 | else |
| 6350 | out_str(aep->ae_u.term.stop); |
| 6351 | } |
| 6352 | } |
| 6353 | if (aep == NULL) /* did ":syntax clear" */ |
| 6354 | screen_attr = 0; |
| 6355 | else |
| 6356 | screen_attr = aep->ae_attr; |
| 6357 | } |
| 6358 | |
| 6359 | /* |
| 6360 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 6361 | * same sequence several times. |
| 6362 | */ |
| 6363 | if (screen_attr & HL_STANDOUT) |
| 6364 | { |
| 6365 | if (STRCMP(T_SE, T_ME) == 0) |
| 6366 | do_ME = TRUE; |
| 6367 | else |
| 6368 | out_str(T_SE); |
| 6369 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6370 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6371 | { |
| 6372 | if (STRCMP(T_UE, T_ME) == 0) |
| 6373 | do_ME = TRUE; |
| 6374 | else |
| 6375 | out_str(T_UE); |
| 6376 | } |
| 6377 | if (screen_attr & HL_ITALIC) |
| 6378 | { |
| 6379 | if (STRCMP(T_CZR, T_ME) == 0) |
| 6380 | do_ME = TRUE; |
| 6381 | else |
| 6382 | out_str(T_CZR); |
| 6383 | } |
| 6384 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 6385 | out_str(T_ME); |
| 6386 | |
| 6387 | if (t_colors > 1) |
| 6388 | { |
| 6389 | /* set Normal cterm colors */ |
| 6390 | if (cterm_normal_fg_color != 0) |
| 6391 | term_fg_color(cterm_normal_fg_color - 1); |
| 6392 | if (cterm_normal_bg_color != 0) |
| 6393 | term_bg_color(cterm_normal_bg_color - 1); |
| 6394 | if (cterm_normal_fg_bold) |
| 6395 | out_str(T_MD); |
| 6396 | } |
| 6397 | } |
| 6398 | } |
| 6399 | screen_attr = 0; |
| 6400 | } |
| 6401 | |
| 6402 | /* |
| 6403 | * Reset the colors for a cterm. Used when leaving Vim. |
| 6404 | * The machine specific code may override this again. |
| 6405 | */ |
| 6406 | void |
| 6407 | reset_cterm_colors() |
| 6408 | { |
| 6409 | if (t_colors > 1) |
| 6410 | { |
| 6411 | /* set Normal cterm colors */ |
| 6412 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 6413 | { |
| 6414 | out_str(T_OP); |
| 6415 | screen_attr = -1; |
| 6416 | } |
| 6417 | if (cterm_normal_fg_bold) |
| 6418 | { |
| 6419 | out_str(T_ME); |
| 6420 | screen_attr = -1; |
| 6421 | } |
| 6422 | } |
| 6423 | } |
| 6424 | |
| 6425 | /* |
| 6426 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 6427 | * using the attributes from ScreenAttrs["off"]. |
| 6428 | */ |
| 6429 | static void |
| 6430 | screen_char(off, row, col) |
| 6431 | unsigned off; |
| 6432 | int row; |
| 6433 | int col; |
| 6434 | { |
| 6435 | int attr; |
| 6436 | |
| 6437 | /* Check for illegal values, just in case (could happen just after |
| 6438 | * resizing). */ |
| 6439 | if (row >= screen_Rows || col >= screen_Columns) |
| 6440 | return; |
| 6441 | |
| 6442 | /* Outputting the last character on the screen may scrollup the screen. |
| 6443 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 6444 | if (row == screen_Rows - 1 && col == screen_Columns - 1 |
| 6445 | #ifdef FEAT_RIGHTLEFT |
| 6446 | /* account for first command-line character in rightleft mode */ |
| 6447 | && !cmdmsg_rl |
| 6448 | #endif |
| 6449 | ) |
| 6450 | { |
| 6451 | ScreenAttrs[off] = (sattr_T)-1; |
| 6452 | return; |
| 6453 | } |
| 6454 | |
| 6455 | /* |
| 6456 | * Stop highlighting first, so it's easier to move the cursor. |
| 6457 | */ |
| 6458 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 6459 | if (screen_char_attr != 0) |
| 6460 | attr = screen_char_attr; |
| 6461 | else |
| 6462 | #endif |
| 6463 | attr = ScreenAttrs[off]; |
| 6464 | if (screen_attr != attr) |
| 6465 | screen_stop_highlight(); |
| 6466 | |
| 6467 | windgoto(row, col); |
| 6468 | |
| 6469 | if (screen_attr != attr) |
| 6470 | screen_start_highlight(attr); |
| 6471 | |
| 6472 | #ifdef FEAT_MBYTE |
| 6473 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6474 | { |
| 6475 | char_u buf[MB_MAXBYTES + 1]; |
| 6476 | |
| 6477 | /* Convert UTF-8 character to bytes and write it. */ |
| 6478 | |
| 6479 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 6480 | |
| 6481 | out_str(buf); |
| 6482 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 6483 | ++screen_cur_col; |
| 6484 | } |
| 6485 | else |
| 6486 | #endif |
| 6487 | { |
| 6488 | #ifdef FEAT_MBYTE |
| 6489 | out_flush_check(); |
| 6490 | #endif |
| 6491 | out_char(ScreenLines[off]); |
| 6492 | #ifdef FEAT_MBYTE |
| 6493 | /* double-byte character in single-width cell */ |
| 6494 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6495 | out_char(ScreenLines2[off]); |
| 6496 | #endif |
| 6497 | } |
| 6498 | |
| 6499 | screen_cur_col++; |
| 6500 | } |
| 6501 | |
| 6502 | #ifdef FEAT_MBYTE |
| 6503 | |
| 6504 | /* |
| 6505 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 6506 | * on the screen at position 'row' and 'col'. |
| 6507 | * The attributes of the first byte is used for all. This is required to |
| 6508 | * output the two bytes of a double-byte character with nothing in between. |
| 6509 | */ |
| 6510 | static void |
| 6511 | screen_char_2(off, row, col) |
| 6512 | unsigned off; |
| 6513 | int row; |
| 6514 | int col; |
| 6515 | { |
| 6516 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 6517 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 6518 | return; |
| 6519 | |
| 6520 | /* Outputting the last character on the screen may scrollup the screen. |
| 6521 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 6522 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 6523 | { |
| 6524 | ScreenAttrs[off] = (sattr_T)-1; |
| 6525 | return; |
| 6526 | } |
| 6527 | |
| 6528 | /* Output the first byte normally (positions the cursor), then write the |
| 6529 | * second byte directly. */ |
| 6530 | screen_char(off, row, col); |
| 6531 | out_char(ScreenLines[off + 1]); |
| 6532 | ++screen_cur_col; |
| 6533 | } |
| 6534 | #endif |
| 6535 | |
| 6536 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 6537 | /* |
| 6538 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 6539 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 6540 | */ |
| 6541 | void |
| 6542 | screen_draw_rectangle(row, col, height, width, invert) |
| 6543 | int row; |
| 6544 | int col; |
| 6545 | int height; |
| 6546 | int width; |
| 6547 | int invert; |
| 6548 | { |
| 6549 | int r, c; |
| 6550 | int off; |
| 6551 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 6552 | /* Can't use ScreenLines unless initialized */ |
| 6553 | if (ScreenLines == NULL) |
| 6554 | return; |
| 6555 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6556 | if (invert) |
| 6557 | screen_char_attr = HL_INVERSE; |
| 6558 | for (r = row; r < row + height; ++r) |
| 6559 | { |
| 6560 | off = LineOffset[r]; |
| 6561 | for (c = col; c < col + width; ++c) |
| 6562 | { |
| 6563 | #ifdef FEAT_MBYTE |
| 6564 | if (enc_dbcs != 0 && dbcs_off2cells(off + c) > 1) |
| 6565 | { |
| 6566 | screen_char_2(off + c, r, c); |
| 6567 | ++c; |
| 6568 | } |
| 6569 | else |
| 6570 | #endif |
| 6571 | { |
| 6572 | screen_char(off + c, r, c); |
| 6573 | #ifdef FEAT_MBYTE |
| 6574 | if (utf_off2cells(off + c) > 1) |
| 6575 | ++c; |
| 6576 | #endif |
| 6577 | } |
| 6578 | } |
| 6579 | } |
| 6580 | screen_char_attr = 0; |
| 6581 | } |
| 6582 | #endif |
| 6583 | |
| 6584 | #ifdef FEAT_VERTSPLIT |
| 6585 | /* |
| 6586 | * Redraw the characters for a vertically split window. |
| 6587 | */ |
| 6588 | static void |
| 6589 | redraw_block(row, end, wp) |
| 6590 | int row; |
| 6591 | int end; |
| 6592 | win_T *wp; |
| 6593 | { |
| 6594 | int col; |
| 6595 | int width; |
| 6596 | |
| 6597 | # ifdef FEAT_CLIPBOARD |
| 6598 | clip_may_clear_selection(row, end - 1); |
| 6599 | # endif |
| 6600 | |
| 6601 | if (wp == NULL) |
| 6602 | { |
| 6603 | col = 0; |
| 6604 | width = Columns; |
| 6605 | } |
| 6606 | else |
| 6607 | { |
| 6608 | col = wp->w_wincol; |
| 6609 | width = wp->w_width; |
| 6610 | } |
| 6611 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 6612 | } |
| 6613 | #endif |
| 6614 | |
| 6615 | /* |
| 6616 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 6617 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 6618 | * Use attributes 'attr'. |
| 6619 | */ |
| 6620 | void |
| 6621 | screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) |
| 6622 | int start_row, end_row; |
| 6623 | int start_col, end_col; |
| 6624 | int c1, c2; |
| 6625 | int attr; |
| 6626 | { |
| 6627 | int row; |
| 6628 | int col; |
| 6629 | int off; |
| 6630 | int end_off; |
| 6631 | int did_delete; |
| 6632 | int c; |
| 6633 | int norm_term; |
| 6634 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6635 | int force_next = FALSE; |
| 6636 | #endif |
| 6637 | |
| 6638 | if (end_row > screen_Rows) /* safety check */ |
| 6639 | end_row = screen_Rows; |
| 6640 | if (end_col > screen_Columns) /* safety check */ |
| 6641 | end_col = screen_Columns; |
| 6642 | if (ScreenLines == NULL |
| 6643 | || start_row >= end_row |
| 6644 | || start_col >= end_col) /* nothing to do */ |
| 6645 | return; |
| 6646 | |
| 6647 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 6648 | norm_term = ( |
| 6649 | #ifdef FEAT_GUI |
| 6650 | !gui.in_use && |
| 6651 | #endif |
| 6652 | t_colors <= 1); |
| 6653 | for (row = start_row; row < end_row; ++row) |
| 6654 | { |
| 6655 | /* |
| 6656 | * Try to use delete-line termcap code, when no attributes or in a |
| 6657 | * "normal" terminal, where a bold/italic space is just a |
| 6658 | * space. |
| 6659 | */ |
| 6660 | did_delete = FALSE; |
| 6661 | if (c2 == ' ' |
| 6662 | && end_col == Columns |
| 6663 | && can_clear(T_CE) |
| 6664 | && (attr == 0 |
| 6665 | || (norm_term |
| 6666 | && attr <= HL_ALL |
| 6667 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 6668 | { |
| 6669 | /* |
| 6670 | * check if we really need to clear something |
| 6671 | */ |
| 6672 | col = start_col; |
| 6673 | if (c1 != ' ') /* don't clear first char */ |
| 6674 | ++col; |
| 6675 | |
| 6676 | off = LineOffset[row] + col; |
| 6677 | end_off = LineOffset[row] + end_col; |
| 6678 | |
| 6679 | /* skip blanks (used often, keep it fast!) */ |
| 6680 | #ifdef FEAT_MBYTE |
| 6681 | if (enc_utf8) |
| 6682 | while (off < end_off && ScreenLines[off] == ' ' |
| 6683 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 6684 | ++off; |
| 6685 | else |
| 6686 | #endif |
| 6687 | while (off < end_off && ScreenLines[off] == ' ' |
| 6688 | && ScreenAttrs[off] == 0) |
| 6689 | ++off; |
| 6690 | if (off < end_off) /* something to be cleared */ |
| 6691 | { |
| 6692 | col = off - LineOffset[row]; |
| 6693 | screen_stop_highlight(); |
| 6694 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 6695 | out_str(T_CE); |
| 6696 | screen_start(); /* don't know where cursor is now */ |
| 6697 | col = end_col - col; |
| 6698 | while (col--) /* clear chars in ScreenLines */ |
| 6699 | { |
| 6700 | ScreenLines[off] = ' '; |
| 6701 | #ifdef FEAT_MBYTE |
| 6702 | if (enc_utf8) |
| 6703 | ScreenLinesUC[off] = 0; |
| 6704 | #endif |
| 6705 | ScreenAttrs[off] = 0; |
| 6706 | ++off; |
| 6707 | } |
| 6708 | } |
| 6709 | did_delete = TRUE; /* the chars are cleared now */ |
| 6710 | } |
| 6711 | |
| 6712 | off = LineOffset[row] + start_col; |
| 6713 | c = c1; |
| 6714 | for (col = start_col; col < end_col; ++col) |
| 6715 | { |
| 6716 | if (ScreenLines[off] != c |
| 6717 | #ifdef FEAT_MBYTE |
| 6718 | || (enc_utf8 && ScreenLinesUC[off] != (c >= 0x80 ? c : 0)) |
| 6719 | #endif |
| 6720 | || ScreenAttrs[off] != attr |
| 6721 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6722 | || force_next |
| 6723 | #endif |
| 6724 | ) |
| 6725 | { |
| 6726 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6727 | /* The bold trick may make a single row of pixels appear in |
| 6728 | * the next character. When a bold character is removed, the |
| 6729 | * next character should be redrawn too. This happens for our |
| 6730 | * own GUI and for some xterms. */ |
| 6731 | if ( |
| 6732 | # ifdef FEAT_GUI |
| 6733 | gui.in_use |
| 6734 | # endif |
| 6735 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6736 | || |
| 6737 | # endif |
| 6738 | # ifdef UNIX |
| 6739 | term_is_xterm |
| 6740 | # endif |
| 6741 | ) |
| 6742 | { |
| 6743 | if (ScreenLines[off] != ' ' |
| 6744 | && (ScreenAttrs[off] > HL_ALL |
| 6745 | || ScreenAttrs[off] & HL_BOLD)) |
| 6746 | force_next = TRUE; |
| 6747 | else |
| 6748 | force_next = FALSE; |
| 6749 | } |
| 6750 | #endif |
| 6751 | ScreenLines[off] = c; |
| 6752 | #ifdef FEAT_MBYTE |
| 6753 | if (enc_utf8) |
| 6754 | { |
| 6755 | if (c >= 0x80) |
| 6756 | { |
| 6757 | ScreenLinesUC[off] = c; |
| 6758 | ScreenLinesC1[off] = 0; |
| 6759 | ScreenLinesC2[off] = 0; |
| 6760 | } |
| 6761 | else |
| 6762 | ScreenLinesUC[off] = 0; |
| 6763 | } |
| 6764 | #endif |
| 6765 | ScreenAttrs[off] = attr; |
| 6766 | if (!did_delete || c != ' ') |
| 6767 | screen_char(off, row, col); |
| 6768 | } |
| 6769 | ++off; |
| 6770 | if (col == start_col) |
| 6771 | { |
| 6772 | if (did_delete) |
| 6773 | break; |
| 6774 | c = c2; |
| 6775 | } |
| 6776 | } |
| 6777 | if (end_col == Columns) |
| 6778 | LineWraps[row] = FALSE; |
| 6779 | if (row == Rows - 1) /* overwritten the command line */ |
| 6780 | { |
| 6781 | redraw_cmdline = TRUE; |
| 6782 | if (c1 == ' ' && c2 == ' ') |
| 6783 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 6784 | if (start_col == 0) |
| 6785 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6786 | } |
| 6787 | } |
| 6788 | } |
| 6789 | |
| 6790 | /* |
| 6791 | * Check if there should be a delay. Used before clearing or redrawing the |
| 6792 | * screen or the command line. |
| 6793 | */ |
| 6794 | void |
| 6795 | check_for_delay(check_msg_scroll) |
| 6796 | int check_msg_scroll; |
| 6797 | { |
| 6798 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 6799 | && !did_wait_return |
| 6800 | && emsg_silent == 0) |
| 6801 | { |
| 6802 | out_flush(); |
| 6803 | ui_delay(1000L, TRUE); |
| 6804 | emsg_on_display = FALSE; |
| 6805 | if (check_msg_scroll) |
| 6806 | msg_scroll = FALSE; |
| 6807 | } |
| 6808 | } |
| 6809 | |
| 6810 | /* |
| 6811 | * screen_valid - allocate screen buffers if size changed |
| 6812 | * If "clear" is TRUE: clear screen if it has been resized. |
| 6813 | * Returns TRUE if there is a valid screen to write to. |
| 6814 | * Returns FALSE when starting up and screen not initialized yet. |
| 6815 | */ |
| 6816 | int |
| 6817 | screen_valid(clear) |
| 6818 | int clear; |
| 6819 | { |
| 6820 | screenalloc(clear); /* allocate screen buffers if size changed */ |
| 6821 | return (ScreenLines != NULL); |
| 6822 | } |
| 6823 | |
| 6824 | /* |
| 6825 | * Resize the shell to Rows and Columns. |
| 6826 | * Allocate ScreenLines[] and associated items. |
| 6827 | * |
| 6828 | * There may be some time between setting Rows and Columns and (re)allocating |
| 6829 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 6830 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 6831 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 6832 | * final size of the shell is needed. |
| 6833 | */ |
| 6834 | void |
| 6835 | screenalloc(clear) |
| 6836 | int clear; |
| 6837 | { |
| 6838 | int new_row, old_row; |
| 6839 | #ifdef FEAT_GUI |
| 6840 | int old_Rows; |
| 6841 | #endif |
| 6842 | win_T *wp; |
| 6843 | int outofmem = FALSE; |
| 6844 | int len; |
| 6845 | schar_T *new_ScreenLines; |
| 6846 | #ifdef FEAT_MBYTE |
| 6847 | u8char_T *new_ScreenLinesUC = NULL; |
| 6848 | u8char_T *new_ScreenLinesC1 = NULL; |
| 6849 | u8char_T *new_ScreenLinesC2 = NULL; |
| 6850 | schar_T *new_ScreenLines2 = NULL; |
| 6851 | #endif |
| 6852 | sattr_T *new_ScreenAttrs; |
| 6853 | unsigned *new_LineOffset; |
| 6854 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 6855 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6856 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 6857 | tabpage_T *tp; |
| 6858 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6859 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 6860 | static int did_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6861 | |
| 6862 | /* |
| 6863 | * Allocation of the screen buffers is done only when the size changes and |
| 6864 | * when Rows and Columns have been set and we have started doing full |
| 6865 | * screen stuff. |
| 6866 | */ |
| 6867 | if ((ScreenLines != NULL |
| 6868 | && Rows == screen_Rows |
| 6869 | && Columns == screen_Columns |
| 6870 | #ifdef FEAT_MBYTE |
| 6871 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 6872 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
| 6873 | #endif |
| 6874 | ) |
| 6875 | || Rows == 0 |
| 6876 | || Columns == 0 |
| 6877 | || (!full_screen && ScreenLines == NULL)) |
| 6878 | return; |
| 6879 | |
| 6880 | /* |
| 6881 | * It's possible that we produce an out-of-memory message below, which |
| 6882 | * will cause this function to be called again. To break the loop, just |
| 6883 | * return here. |
| 6884 | */ |
| 6885 | if (entered) |
| 6886 | return; |
| 6887 | entered = TRUE; |
| 6888 | |
| 6889 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 6890 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6891 | comp_col(); /* recompute columns for shown command and ruler */ |
| 6892 | |
| 6893 | /* |
| 6894 | * We're changing the size of the screen. |
| 6895 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 6896 | * - Move lines from the old arrays into the new arrays, clear extra |
| 6897 | * lines (unless the screen is going to be cleared). |
| 6898 | * - Free the old arrays. |
| 6899 | * |
| 6900 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 6901 | * Continuing with the old ScreenLines may result in a crash, because the |
| 6902 | * size is wrong. |
| 6903 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 6904 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6905 | win_free_lsize(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6906 | |
| 6907 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 6908 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 6909 | #ifdef FEAT_MBYTE |
| 6910 | if (enc_utf8) |
| 6911 | { |
| 6912 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 6913 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 6914 | new_ScreenLinesC1 = (u8char_T *)lalloc((long_u)( |
| 6915 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 6916 | new_ScreenLinesC2 = (u8char_T *)lalloc((long_u)( |
| 6917 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 6918 | } |
| 6919 | if (enc_dbcs == DBCS_JPNU) |
| 6920 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 6921 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 6922 | #endif |
| 6923 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 6924 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 6925 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 6926 | Rows * sizeof(unsigned)), FALSE); |
| 6927 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 6928 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6929 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 6930 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6931 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6932 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6933 | { |
| 6934 | if (win_alloc_lines(wp) == FAIL) |
| 6935 | { |
| 6936 | outofmem = TRUE; |
| 6937 | #ifdef FEAT_WINDOWS |
| 6938 | break; |
| 6939 | #endif |
| 6940 | } |
| 6941 | } |
| 6942 | |
| 6943 | if (new_ScreenLines == NULL |
| 6944 | #ifdef FEAT_MBYTE |
| 6945 | || (enc_utf8 && (new_ScreenLinesUC == NULL |
| 6946 | || new_ScreenLinesC1 == NULL || new_ScreenLinesC2 == NULL)) |
| 6947 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 6948 | #endif |
| 6949 | || new_ScreenAttrs == NULL |
| 6950 | || new_LineOffset == NULL |
| 6951 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 6952 | #ifdef FEAT_WINDOWS |
| 6953 | || new_TabPageIdxs == NULL |
| 6954 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6955 | || outofmem) |
| 6956 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 6957 | if (ScreenLines != NULL || !did_outofmem_msg) |
| 6958 | { |
| 6959 | /* guess the size */ |
| 6960 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 6961 | |
| 6962 | /* Remember we did this to avoid getting outofmem messages over |
| 6963 | * and over again. */ |
| 6964 | did_outofmem_msg = TRUE; |
| 6965 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6966 | vim_free(new_ScreenLines); |
| 6967 | new_ScreenLines = NULL; |
| 6968 | #ifdef FEAT_MBYTE |
| 6969 | vim_free(new_ScreenLinesUC); |
| 6970 | new_ScreenLinesUC = NULL; |
| 6971 | vim_free(new_ScreenLinesC1); |
| 6972 | new_ScreenLinesC1 = NULL; |
| 6973 | vim_free(new_ScreenLinesC2); |
| 6974 | new_ScreenLinesC2 = NULL; |
| 6975 | vim_free(new_ScreenLines2); |
| 6976 | new_ScreenLines2 = NULL; |
| 6977 | #endif |
| 6978 | vim_free(new_ScreenAttrs); |
| 6979 | new_ScreenAttrs = NULL; |
| 6980 | vim_free(new_LineOffset); |
| 6981 | new_LineOffset = NULL; |
| 6982 | vim_free(new_LineWraps); |
| 6983 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 6984 | #ifdef FEAT_WINDOWS |
| 6985 | vim_free(new_TabPageIdxs); |
| 6986 | new_TabPageIdxs = NULL; |
| 6987 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6988 | } |
| 6989 | else |
| 6990 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 6991 | did_outofmem_msg = FALSE; |
| 6992 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6993 | for (new_row = 0; new_row < Rows; ++new_row) |
| 6994 | { |
| 6995 | new_LineOffset[new_row] = new_row * Columns; |
| 6996 | new_LineWraps[new_row] = FALSE; |
| 6997 | |
| 6998 | /* |
| 6999 | * If the screen is not going to be cleared, copy as much as |
| 7000 | * possible from the old screen to the new one and clear the rest |
| 7001 | * (used when resizing the window at the "--more--" prompt or when |
| 7002 | * executing an external command, for the GUI). |
| 7003 | */ |
| 7004 | if (!clear) |
| 7005 | { |
| 7006 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 7007 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 7008 | #ifdef FEAT_MBYTE |
| 7009 | if (enc_utf8) |
| 7010 | { |
| 7011 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 7012 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 7013 | (void)vim_memset(new_ScreenLinesC1 + new_row * Columns, |
| 7014 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 7015 | (void)vim_memset(new_ScreenLinesC2 + new_row * Columns, |
| 7016 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 7017 | } |
| 7018 | if (enc_dbcs == DBCS_JPNU) |
| 7019 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 7020 | 0, (size_t)Columns * sizeof(schar_T)); |
| 7021 | #endif |
| 7022 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 7023 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 7024 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7025 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7026 | { |
| 7027 | if (screen_Columns < Columns) |
| 7028 | len = screen_Columns; |
| 7029 | else |
| 7030 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 7031 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 7032 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 7033 | * may be invalid now. */ |
| 7034 | if (!(enc_utf8 && ScreenLinesUC == NULL)) |
| 7035 | #endif |
| 7036 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 7037 | ScreenLines + LineOffset[old_row], |
| 7038 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7039 | #ifdef FEAT_MBYTE |
| 7040 | if (enc_utf8 && ScreenLinesUC != NULL) |
| 7041 | { |
| 7042 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 7043 | ScreenLinesUC + LineOffset[old_row], |
| 7044 | (size_t)len * sizeof(u8char_T)); |
| 7045 | mch_memmove(new_ScreenLinesC1 + new_LineOffset[new_row], |
| 7046 | ScreenLinesC1 + LineOffset[old_row], |
| 7047 | (size_t)len * sizeof(u8char_T)); |
| 7048 | mch_memmove(new_ScreenLinesC2 + new_LineOffset[new_row], |
| 7049 | ScreenLinesC2 + LineOffset[old_row], |
| 7050 | (size_t)len * sizeof(u8char_T)); |
| 7051 | } |
| 7052 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 7053 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 7054 | ScreenLines2 + LineOffset[old_row], |
| 7055 | (size_t)len * sizeof(schar_T)); |
| 7056 | #endif |
| 7057 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 7058 | ScreenAttrs + LineOffset[old_row], |
| 7059 | (size_t)len * sizeof(sattr_T)); |
| 7060 | } |
| 7061 | } |
| 7062 | } |
| 7063 | /* Use the last line of the screen for the current line. */ |
| 7064 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 7065 | } |
| 7066 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7067 | free_screenlines(); |
| 7068 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7069 | ScreenLines = new_ScreenLines; |
| 7070 | #ifdef FEAT_MBYTE |
| 7071 | ScreenLinesUC = new_ScreenLinesUC; |
| 7072 | ScreenLinesC1 = new_ScreenLinesC1; |
| 7073 | ScreenLinesC2 = new_ScreenLinesC2; |
| 7074 | ScreenLines2 = new_ScreenLines2; |
| 7075 | #endif |
| 7076 | ScreenAttrs = new_ScreenAttrs; |
| 7077 | LineOffset = new_LineOffset; |
| 7078 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7079 | #ifdef FEAT_WINDOWS |
| 7080 | TabPageIdxs = new_TabPageIdxs; |
| 7081 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7082 | |
| 7083 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 7084 | * size of ScreenLines[]. Set them before calling anything. */ |
| 7085 | #ifdef FEAT_GUI |
| 7086 | old_Rows = screen_Rows; |
| 7087 | #endif |
| 7088 | screen_Rows = Rows; |
| 7089 | screen_Columns = Columns; |
| 7090 | |
| 7091 | must_redraw = CLEAR; /* need to clear the screen later */ |
| 7092 | if (clear) |
| 7093 | screenclear2(); |
| 7094 | |
| 7095 | #ifdef FEAT_GUI |
| 7096 | else if (gui.in_use |
| 7097 | && !gui.starting |
| 7098 | && ScreenLines != NULL |
| 7099 | && old_Rows != Rows) |
| 7100 | { |
| 7101 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 7102 | /* |
| 7103 | * Adjust the position of the cursor, for when executing an external |
| 7104 | * command. |
| 7105 | */ |
| 7106 | if (msg_row >= Rows) /* Rows got smaller */ |
| 7107 | msg_row = Rows - 1; /* put cursor at last row */ |
| 7108 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 7109 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 7110 | if (msg_col >= Columns) /* Columns got smaller */ |
| 7111 | msg_col = Columns - 1; /* put cursor at last column */ |
| 7112 | } |
| 7113 | #endif |
| 7114 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7115 | entered = FALSE; |
| 7116 | } |
| 7117 | |
| 7118 | void |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7119 | free_screenlines() |
| 7120 | { |
| 7121 | vim_free(ScreenLines); |
| 7122 | #ifdef FEAT_MBYTE |
| 7123 | vim_free(ScreenLinesUC); |
| 7124 | vim_free(ScreenLinesC1); |
| 7125 | vim_free(ScreenLinesC2); |
| 7126 | vim_free(ScreenLines2); |
| 7127 | #endif |
| 7128 | vim_free(ScreenAttrs); |
| 7129 | vim_free(LineOffset); |
| 7130 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7131 | #ifdef FEAT_WINDOWS |
| 7132 | vim_free(TabPageIdxs); |
| 7133 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7137 | screenclear() |
| 7138 | { |
| 7139 | check_for_delay(FALSE); |
| 7140 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 7141 | screenclear2(); /* clear the screen */ |
| 7142 | } |
| 7143 | |
| 7144 | static void |
| 7145 | screenclear2() |
| 7146 | { |
| 7147 | int i; |
| 7148 | |
| 7149 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 7150 | #ifdef FEAT_GUI |
| 7151 | || (gui.in_use && gui.starting) |
| 7152 | #endif |
| 7153 | ) |
| 7154 | return; |
| 7155 | |
| 7156 | #ifdef FEAT_GUI |
| 7157 | if (!gui.in_use) |
| 7158 | #endif |
| 7159 | screen_attr = -1; /* force setting the Normal colors */ |
| 7160 | screen_stop_highlight(); /* don't want highlighting here */ |
| 7161 | |
| 7162 | #ifdef FEAT_CLIPBOARD |
| 7163 | /* disable selection without redrawing it */ |
| 7164 | clip_scroll_selection(9999); |
| 7165 | #endif |
| 7166 | |
| 7167 | /* blank out ScreenLines */ |
| 7168 | for (i = 0; i < Rows; ++i) |
| 7169 | { |
| 7170 | lineclear(LineOffset[i], (int)Columns); |
| 7171 | LineWraps[i] = FALSE; |
| 7172 | } |
| 7173 | |
| 7174 | if (can_clear(T_CL)) |
| 7175 | { |
| 7176 | out_str(T_CL); /* clear the display */ |
| 7177 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7178 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7179 | } |
| 7180 | else |
| 7181 | { |
| 7182 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 7183 | for (i = 0; i < Rows; ++i) |
| 7184 | lineinvalid(LineOffset[i], (int)Columns); |
| 7185 | clear_cmdline = TRUE; |
| 7186 | } |
| 7187 | |
| 7188 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 7189 | |
| 7190 | win_rest_invalid(firstwin); |
| 7191 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 7192 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 7193 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 7194 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7195 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 7196 | must_redraw = NOT_VALID; |
| 7197 | compute_cmdrow(); |
| 7198 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 7199 | msg_col = 0; |
| 7200 | screen_start(); /* don't know where cursor is now */ |
| 7201 | msg_scrolled = 0; /* can't scroll back */ |
| 7202 | msg_didany = FALSE; |
| 7203 | msg_didout = FALSE; |
| 7204 | } |
| 7205 | |
| 7206 | /* |
| 7207 | * Clear one line in ScreenLines. |
| 7208 | */ |
| 7209 | static void |
| 7210 | lineclear(off, width) |
| 7211 | unsigned off; |
| 7212 | int width; |
| 7213 | { |
| 7214 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 7215 | #ifdef FEAT_MBYTE |
| 7216 | if (enc_utf8) |
| 7217 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 7218 | (size_t)width * sizeof(u8char_T)); |
| 7219 | #endif |
| 7220 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 7221 | } |
| 7222 | |
| 7223 | /* |
| 7224 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 7225 | * invalid value. |
| 7226 | */ |
| 7227 | static void |
| 7228 | lineinvalid(off, width) |
| 7229 | unsigned off; |
| 7230 | int width; |
| 7231 | { |
| 7232 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 7233 | } |
| 7234 | |
| 7235 | #ifdef FEAT_VERTSPLIT |
| 7236 | /* |
| 7237 | * Copy part of a Screenline for vertically split window "wp". |
| 7238 | */ |
| 7239 | static void |
| 7240 | linecopy(to, from, wp) |
| 7241 | int to; |
| 7242 | int from; |
| 7243 | win_T *wp; |
| 7244 | { |
| 7245 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 7246 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 7247 | |
| 7248 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 7249 | wp->w_width * sizeof(schar_T)); |
| 7250 | # ifdef FEAT_MBYTE |
| 7251 | if (enc_utf8) |
| 7252 | { |
| 7253 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 7254 | wp->w_width * sizeof(u8char_T)); |
| 7255 | mch_memmove(ScreenLinesC1 + off_to, ScreenLinesC1 + off_from, |
| 7256 | wp->w_width * sizeof(u8char_T)); |
| 7257 | mch_memmove(ScreenLinesC2 + off_to, ScreenLinesC2 + off_from, |
| 7258 | wp->w_width * sizeof(u8char_T)); |
| 7259 | } |
| 7260 | if (enc_dbcs == DBCS_JPNU) |
| 7261 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 7262 | wp->w_width * sizeof(schar_T)); |
| 7263 | # endif |
| 7264 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 7265 | wp->w_width * sizeof(sattr_T)); |
| 7266 | } |
| 7267 | #endif |
| 7268 | |
| 7269 | /* |
| 7270 | * Return TRUE if clearing with term string "p" would work. |
| 7271 | * It can't work when the string is empty or it won't set the right background. |
| 7272 | */ |
| 7273 | int |
| 7274 | can_clear(p) |
| 7275 | char_u *p; |
| 7276 | { |
| 7277 | return (*p != NUL && (t_colors <= 1 |
| 7278 | #ifdef FEAT_GUI |
| 7279 | || gui.in_use |
| 7280 | #endif |
| 7281 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 7282 | } |
| 7283 | |
| 7284 | /* |
| 7285 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 7286 | * something directly to the screen (shell commands) or a terminal control |
| 7287 | * code. |
| 7288 | */ |
| 7289 | void |
| 7290 | screen_start() |
| 7291 | { |
| 7292 | screen_cur_row = screen_cur_col = 9999; |
| 7293 | } |
| 7294 | |
| 7295 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7296 | * Move the cursor to position "row","col" in the screen. |
| 7297 | * This tries to find the most efficient way to move, minimizing the number of |
| 7298 | * characters sent to the terminal. |
| 7299 | */ |
| 7300 | void |
| 7301 | windgoto(row, col) |
| 7302 | int row; |
| 7303 | int col; |
| 7304 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7305 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7306 | int i; |
| 7307 | int plan; |
| 7308 | int cost; |
| 7309 | int wouldbe_col; |
| 7310 | int noinvcurs; |
| 7311 | char_u *bs; |
| 7312 | int goto_cost; |
| 7313 | int attr; |
| 7314 | |
| 7315 | #define GOTO_COST 7 /* asssume a term_windgoto() takes about 7 chars */ |
| 7316 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 7317 | |
| 7318 | #define PLAN_LE 1 |
| 7319 | #define PLAN_CR 2 |
| 7320 | #define PLAN_NL 3 |
| 7321 | #define PLAN_WRITE 4 |
| 7322 | /* Can't use ScreenLines unless initialized */ |
| 7323 | if (ScreenLines == NULL) |
| 7324 | return; |
| 7325 | |
| 7326 | if (col != screen_cur_col || row != screen_cur_row) |
| 7327 | { |
| 7328 | /* Check for valid position. */ |
| 7329 | if (row < 0) /* window without text lines? */ |
| 7330 | row = 0; |
| 7331 | if (row >= screen_Rows) |
| 7332 | row = screen_Rows - 1; |
| 7333 | if (col >= screen_Columns) |
| 7334 | col = screen_Columns - 1; |
| 7335 | |
| 7336 | /* check if no cursor movement is allowed in highlight mode */ |
| 7337 | if (screen_attr && *T_MS == NUL) |
| 7338 | noinvcurs = HIGHL_COST; |
| 7339 | else |
| 7340 | noinvcurs = 0; |
| 7341 | goto_cost = GOTO_COST + noinvcurs; |
| 7342 | |
| 7343 | /* |
| 7344 | * Plan how to do the positioning: |
| 7345 | * 1. Use CR to move it to column 0, same row. |
| 7346 | * 2. Use T_LE to move it a few columns to the left. |
| 7347 | * 3. Use NL to move a few lines down, column 0. |
| 7348 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 7349 | * |
| 7350 | * Don't do this if the cursor went beyond the last column, the cursor |
| 7351 | * position is unknown then (some terminals wrap, some don't ) |
| 7352 | * |
| 7353 | * First check if the highlighting attibutes allow us to write |
| 7354 | * characters to move the cursor to the right. |
| 7355 | */ |
| 7356 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 7357 | { |
| 7358 | /* |
| 7359 | * If the cursor is in the same row, bigger col, we can use CR |
| 7360 | * or T_LE. |
| 7361 | */ |
| 7362 | bs = NULL; /* init for GCC */ |
| 7363 | attr = screen_attr; |
| 7364 | if (row == screen_cur_row && col < screen_cur_col) |
| 7365 | { |
| 7366 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 7367 | if (*T_LE) |
| 7368 | bs = T_LE; /* "cursor left" */ |
| 7369 | else |
| 7370 | bs = T_BC; /* "backspace character (old) */ |
| 7371 | if (*bs) |
| 7372 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 7373 | else |
| 7374 | cost = 999; |
| 7375 | if (col + 1 < cost) /* using CR is less characters */ |
| 7376 | { |
| 7377 | plan = PLAN_CR; |
| 7378 | wouldbe_col = 0; |
| 7379 | cost = 1; /* CR is just one character */ |
| 7380 | } |
| 7381 | else |
| 7382 | { |
| 7383 | plan = PLAN_LE; |
| 7384 | wouldbe_col = col; |
| 7385 | } |
| 7386 | if (noinvcurs) /* will stop highlighting */ |
| 7387 | { |
| 7388 | cost += noinvcurs; |
| 7389 | attr = 0; |
| 7390 | } |
| 7391 | } |
| 7392 | |
| 7393 | /* |
| 7394 | * If the cursor is above where we want to be, we can use CR LF. |
| 7395 | */ |
| 7396 | else if (row > screen_cur_row) |
| 7397 | { |
| 7398 | plan = PLAN_NL; |
| 7399 | wouldbe_col = 0; |
| 7400 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 7401 | if (noinvcurs) /* will stop highlighting */ |
| 7402 | { |
| 7403 | cost += noinvcurs; |
| 7404 | attr = 0; |
| 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | /* |
| 7409 | * If the cursor is in the same row, smaller col, just use write. |
| 7410 | */ |
| 7411 | else |
| 7412 | { |
| 7413 | plan = PLAN_WRITE; |
| 7414 | wouldbe_col = screen_cur_col; |
| 7415 | cost = 0; |
| 7416 | } |
| 7417 | |
| 7418 | /* |
| 7419 | * Check if any characters that need to be written have the |
| 7420 | * correct attributes. Also avoid UTF-8 characters. |
| 7421 | */ |
| 7422 | i = col - wouldbe_col; |
| 7423 | if (i > 0) |
| 7424 | cost += i; |
| 7425 | if (cost < goto_cost && i > 0) |
| 7426 | { |
| 7427 | /* |
| 7428 | * Check if the attributes are correct without additionally |
| 7429 | * stopping highlighting. |
| 7430 | */ |
| 7431 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 7432 | while (i && *p++ == attr) |
| 7433 | --i; |
| 7434 | if (i != 0) |
| 7435 | { |
| 7436 | /* |
| 7437 | * Try if it works when highlighting is stopped here. |
| 7438 | */ |
| 7439 | if (*--p == 0) |
| 7440 | { |
| 7441 | cost += noinvcurs; |
| 7442 | while (i && *p++ == 0) |
| 7443 | --i; |
| 7444 | } |
| 7445 | if (i != 0) |
| 7446 | cost = 999; /* different attributes, don't do it */ |
| 7447 | } |
| 7448 | #ifdef FEAT_MBYTE |
| 7449 | if (enc_utf8) |
| 7450 | { |
| 7451 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 7452 | for (i = wouldbe_col; i < col; ++i) |
| 7453 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 7454 | { |
| 7455 | cost = 999; |
| 7456 | break; |
| 7457 | } |
| 7458 | } |
| 7459 | #endif |
| 7460 | } |
| 7461 | |
| 7462 | /* |
| 7463 | * We can do it without term_windgoto()! |
| 7464 | */ |
| 7465 | if (cost < goto_cost) |
| 7466 | { |
| 7467 | if (plan == PLAN_LE) |
| 7468 | { |
| 7469 | if (noinvcurs) |
| 7470 | screen_stop_highlight(); |
| 7471 | while (screen_cur_col > col) |
| 7472 | { |
| 7473 | out_str(bs); |
| 7474 | --screen_cur_col; |
| 7475 | } |
| 7476 | } |
| 7477 | else if (plan == PLAN_CR) |
| 7478 | { |
| 7479 | if (noinvcurs) |
| 7480 | screen_stop_highlight(); |
| 7481 | out_char('\r'); |
| 7482 | screen_cur_col = 0; |
| 7483 | } |
| 7484 | else if (plan == PLAN_NL) |
| 7485 | { |
| 7486 | if (noinvcurs) |
| 7487 | screen_stop_highlight(); |
| 7488 | while (screen_cur_row < row) |
| 7489 | { |
| 7490 | out_char('\n'); |
| 7491 | ++screen_cur_row; |
| 7492 | } |
| 7493 | screen_cur_col = 0; |
| 7494 | } |
| 7495 | |
| 7496 | i = col - screen_cur_col; |
| 7497 | if (i > 0) |
| 7498 | { |
| 7499 | /* |
| 7500 | * Use cursor-right if it's one character only. Avoids |
| 7501 | * removing a line of pixels from the last bold char, when |
| 7502 | * using the bold trick in the GUI. |
| 7503 | */ |
| 7504 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 7505 | { |
| 7506 | while (i-- > 0) |
| 7507 | out_char(*T_ND); |
| 7508 | } |
| 7509 | else |
| 7510 | { |
| 7511 | int off; |
| 7512 | |
| 7513 | off = LineOffset[row] + screen_cur_col; |
| 7514 | while (i-- > 0) |
| 7515 | { |
| 7516 | if (ScreenAttrs[off] != screen_attr) |
| 7517 | screen_stop_highlight(); |
| 7518 | #ifdef FEAT_MBYTE |
| 7519 | out_flush_check(); |
| 7520 | #endif |
| 7521 | out_char(ScreenLines[off]); |
| 7522 | #ifdef FEAT_MBYTE |
| 7523 | if (enc_dbcs == DBCS_JPNU |
| 7524 | && ScreenLines[off] == 0x8e) |
| 7525 | out_char(ScreenLines2[off]); |
| 7526 | #endif |
| 7527 | ++off; |
| 7528 | } |
| 7529 | } |
| 7530 | } |
| 7531 | } |
| 7532 | } |
| 7533 | else |
| 7534 | cost = 999; |
| 7535 | |
| 7536 | if (cost >= goto_cost) |
| 7537 | { |
| 7538 | if (noinvcurs) |
| 7539 | screen_stop_highlight(); |
| 7540 | if (row == screen_cur_row && (col > screen_cur_col) && |
| 7541 | *T_CRI != NUL) |
| 7542 | term_cursor_right(col - screen_cur_col); |
| 7543 | else |
| 7544 | term_windgoto(row, col); |
| 7545 | } |
| 7546 | screen_cur_row = row; |
| 7547 | screen_cur_col = col; |
| 7548 | } |
| 7549 | } |
| 7550 | |
| 7551 | /* |
| 7552 | * Set cursor to its position in the current window. |
| 7553 | */ |
| 7554 | void |
| 7555 | setcursor() |
| 7556 | { |
| 7557 | if (redrawing()) |
| 7558 | { |
| 7559 | validate_cursor(); |
| 7560 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 7561 | W_WINCOL(curwin) + ( |
| 7562 | #ifdef FEAT_RIGHTLEFT |
| 7563 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 7564 | # ifdef FEAT_MBYTE |
| 7565 | has_mbyte ? (*mb_ptr2cells)(ml_get_cursor()) : |
| 7566 | # endif |
| 7567 | 1)) : |
| 7568 | #endif |
| 7569 | curwin->w_wcol)); |
| 7570 | } |
| 7571 | } |
| 7572 | |
| 7573 | |
| 7574 | /* |
| 7575 | * insert 'line_count' lines at 'row' in window 'wp' |
| 7576 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 7577 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 7578 | * scrolling. |
| 7579 | * Returns FAIL if the lines are not inserted, OK for success. |
| 7580 | */ |
| 7581 | int |
| 7582 | win_ins_lines(wp, row, line_count, invalid, mayclear) |
| 7583 | win_T *wp; |
| 7584 | int row; |
| 7585 | int line_count; |
| 7586 | int invalid; |
| 7587 | int mayclear; |
| 7588 | { |
| 7589 | int did_delete; |
| 7590 | int nextrow; |
| 7591 | int lastrow; |
| 7592 | int retval; |
| 7593 | |
| 7594 | if (invalid) |
| 7595 | wp->w_lines_valid = 0; |
| 7596 | |
| 7597 | if (wp->w_height < 5) |
| 7598 | return FAIL; |
| 7599 | |
| 7600 | if (line_count > wp->w_height - row) |
| 7601 | line_count = wp->w_height - row; |
| 7602 | |
| 7603 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 7604 | if (retval != MAYBE) |
| 7605 | return retval; |
| 7606 | |
| 7607 | /* |
| 7608 | * If there is a next window or a status line, we first try to delete the |
| 7609 | * lines at the bottom to avoid messing what is after the window. |
| 7610 | * If this fails and there are following windows, don't do anything to avoid |
| 7611 | * messing up those windows, better just redraw. |
| 7612 | */ |
| 7613 | did_delete = FALSE; |
| 7614 | #ifdef FEAT_WINDOWS |
| 7615 | if (wp->w_next != NULL || wp->w_status_height) |
| 7616 | { |
| 7617 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 7618 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 7619 | did_delete = TRUE; |
| 7620 | else if (wp->w_next) |
| 7621 | return FAIL; |
| 7622 | } |
| 7623 | #endif |
| 7624 | /* |
| 7625 | * if no lines deleted, blank the lines that will end up below the window |
| 7626 | */ |
| 7627 | if (!did_delete) |
| 7628 | { |
| 7629 | #ifdef FEAT_WINDOWS |
| 7630 | wp->w_redr_status = TRUE; |
| 7631 | #endif |
| 7632 | redraw_cmdline = TRUE; |
| 7633 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 7634 | lastrow = nextrow + line_count; |
| 7635 | if (lastrow > Rows) |
| 7636 | lastrow = Rows; |
| 7637 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 7638 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 7639 | ' ', ' ', 0); |
| 7640 | } |
| 7641 | |
| 7642 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 7643 | == FAIL) |
| 7644 | { |
| 7645 | /* deletion will have messed up other windows */ |
| 7646 | if (did_delete) |
| 7647 | { |
| 7648 | #ifdef FEAT_WINDOWS |
| 7649 | wp->w_redr_status = TRUE; |
| 7650 | #endif |
| 7651 | win_rest_invalid(W_NEXT(wp)); |
| 7652 | } |
| 7653 | return FAIL; |
| 7654 | } |
| 7655 | |
| 7656 | return OK; |
| 7657 | } |
| 7658 | |
| 7659 | /* |
| 7660 | * delete "line_count" window lines at "row" in window "wp" |
| 7661 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 7662 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 7663 | * scrolling |
| 7664 | * Return OK for success, FAIL if the lines are not deleted. |
| 7665 | */ |
| 7666 | int |
| 7667 | win_del_lines(wp, row, line_count, invalid, mayclear) |
| 7668 | win_T *wp; |
| 7669 | int row; |
| 7670 | int line_count; |
| 7671 | int invalid; |
| 7672 | int mayclear; |
| 7673 | { |
| 7674 | int retval; |
| 7675 | |
| 7676 | if (invalid) |
| 7677 | wp->w_lines_valid = 0; |
| 7678 | |
| 7679 | if (line_count > wp->w_height - row) |
| 7680 | line_count = wp->w_height - row; |
| 7681 | |
| 7682 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 7683 | if (retval != MAYBE) |
| 7684 | return retval; |
| 7685 | |
| 7686 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 7687 | (int)Rows, FALSE, NULL) == FAIL) |
| 7688 | return FAIL; |
| 7689 | |
| 7690 | #ifdef FEAT_WINDOWS |
| 7691 | /* |
| 7692 | * If there are windows or status lines below, try to put them at the |
| 7693 | * correct place. If we can't do that, they have to be redrawn. |
| 7694 | */ |
| 7695 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 7696 | { |
| 7697 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 7698 | line_count, (int)Rows, NULL) == FAIL) |
| 7699 | { |
| 7700 | wp->w_redr_status = TRUE; |
| 7701 | win_rest_invalid(wp->w_next); |
| 7702 | } |
| 7703 | } |
| 7704 | /* |
| 7705 | * If this is the last window and there is no status line, redraw the |
| 7706 | * command line later. |
| 7707 | */ |
| 7708 | else |
| 7709 | #endif |
| 7710 | redraw_cmdline = TRUE; |
| 7711 | return OK; |
| 7712 | } |
| 7713 | |
| 7714 | /* |
| 7715 | * Common code for win_ins_lines() and win_del_lines(). |
| 7716 | * Returns OK or FAIL when the work has been done. |
| 7717 | * Returns MAYBE when not finished yet. |
| 7718 | */ |
| 7719 | static int |
| 7720 | win_do_lines(wp, row, line_count, mayclear, del) |
| 7721 | win_T *wp; |
| 7722 | int row; |
| 7723 | int line_count; |
| 7724 | int mayclear; |
| 7725 | int del; |
| 7726 | { |
| 7727 | int retval; |
| 7728 | |
| 7729 | if (!redrawing() || line_count <= 0) |
| 7730 | return FAIL; |
| 7731 | |
| 7732 | /* only a few lines left: redraw is faster */ |
| 7733 | if (mayclear && Rows - line_count < 5 |
| 7734 | #ifdef FEAT_VERTSPLIT |
| 7735 | && wp->w_width == Columns |
| 7736 | #endif |
| 7737 | ) |
| 7738 | { |
| 7739 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 7740 | return FAIL; |
| 7741 | } |
| 7742 | |
| 7743 | /* |
| 7744 | * Delete all remaining lines |
| 7745 | */ |
| 7746 | if (row + line_count >= wp->w_height) |
| 7747 | { |
| 7748 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 7749 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 7750 | ' ', ' ', 0); |
| 7751 | return OK; |
| 7752 | } |
| 7753 | |
| 7754 | /* |
| 7755 | * when scrolling, the message on the command line should be cleared, |
| 7756 | * otherwise it will stay there forever. |
| 7757 | */ |
| 7758 | clear_cmdline = TRUE; |
| 7759 | |
| 7760 | /* |
| 7761 | * If the terminal can set a scroll region, use that. |
| 7762 | * Always do this in a vertically split window. This will redraw from |
| 7763 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 7764 | * win_line(). |
| 7765 | * Don't use a scroll region when we are going to redraw the text, writing |
| 7766 | * a character in the lower right corner of the scroll region causes a |
| 7767 | * scroll-up in the DJGPP version. |
| 7768 | */ |
| 7769 | if (scroll_region |
| 7770 | #ifdef FEAT_VERTSPLIT |
| 7771 | || W_WIDTH(wp) != Columns |
| 7772 | #endif |
| 7773 | ) |
| 7774 | { |
| 7775 | #ifdef FEAT_VERTSPLIT |
| 7776 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 7777 | #endif |
| 7778 | scroll_region_set(wp, row); |
| 7779 | if (del) |
| 7780 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 7781 | wp->w_height - row, FALSE, wp); |
| 7782 | else |
| 7783 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 7784 | wp->w_height - row, wp); |
| 7785 | #ifdef FEAT_VERTSPLIT |
| 7786 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 7787 | #endif |
| 7788 | scroll_region_reset(); |
| 7789 | return retval; |
| 7790 | } |
| 7791 | |
| 7792 | #ifdef FEAT_WINDOWS |
| 7793 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 7794 | return FAIL; |
| 7795 | #endif |
| 7796 | |
| 7797 | return MAYBE; |
| 7798 | } |
| 7799 | |
| 7800 | /* |
| 7801 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 7802 | */ |
| 7803 | static void |
| 7804 | win_rest_invalid(wp) |
| 7805 | win_T *wp; |
| 7806 | { |
| 7807 | #ifdef FEAT_WINDOWS |
| 7808 | while (wp != NULL) |
| 7809 | #else |
| 7810 | if (wp != NULL) |
| 7811 | #endif |
| 7812 | { |
| 7813 | redraw_win_later(wp, NOT_VALID); |
| 7814 | #ifdef FEAT_WINDOWS |
| 7815 | wp->w_redr_status = TRUE; |
| 7816 | wp = wp->w_next; |
| 7817 | #endif |
| 7818 | } |
| 7819 | redraw_cmdline = TRUE; |
| 7820 | } |
| 7821 | |
| 7822 | /* |
| 7823 | * The rest of the routines in this file perform screen manipulations. The |
| 7824 | * given operation is performed physically on the screen. The corresponding |
| 7825 | * change is also made to the internal screen image. In this way, the editor |
| 7826 | * anticipates the effect of editing changes on the appearance of the screen. |
| 7827 | * That way, when we call screenupdate a complete redraw isn't usually |
| 7828 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 7829 | * screen changes, and in the meantime, everything still works. |
| 7830 | */ |
| 7831 | |
| 7832 | /* |
| 7833 | * types for inserting or deleting lines |
| 7834 | */ |
| 7835 | #define USE_T_CAL 1 |
| 7836 | #define USE_T_CDL 2 |
| 7837 | #define USE_T_AL 3 |
| 7838 | #define USE_T_CE 4 |
| 7839 | #define USE_T_DL 5 |
| 7840 | #define USE_T_SR 6 |
| 7841 | #define USE_NL 7 |
| 7842 | #define USE_T_CD 8 |
| 7843 | #define USE_REDRAW 9 |
| 7844 | |
| 7845 | /* |
| 7846 | * insert lines on the screen and update ScreenLines[] |
| 7847 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 7848 | * When scrolling region used 'off' is the offset from the top for the region. |
| 7849 | * 'row' and 'end' are relative to the start of the region. |
| 7850 | * |
| 7851 | * return FAIL for failure, OK for success. |
| 7852 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 7853 | int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7854 | screen_ins_lines(off, row, line_count, end, wp) |
| 7855 | int off; |
| 7856 | int row; |
| 7857 | int line_count; |
| 7858 | int end; |
| 7859 | win_T *wp; /* NULL or window to use width from */ |
| 7860 | { |
| 7861 | int i; |
| 7862 | int j; |
| 7863 | unsigned temp; |
| 7864 | int cursor_row; |
| 7865 | int type; |
| 7866 | int result_empty; |
| 7867 | int can_ce = can_clear(T_CE); |
| 7868 | |
| 7869 | /* |
| 7870 | * FAIL if |
| 7871 | * - there is no valid screen |
| 7872 | * - the screen has to be redrawn completely |
| 7873 | * - the line count is less than one |
| 7874 | * - the line count is more than 'ttyscroll' |
| 7875 | */ |
| 7876 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 7877 | return FAIL; |
| 7878 | |
| 7879 | /* |
| 7880 | * There are seven ways to insert lines: |
| 7881 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 7882 | * characters from ScreenLines[]. |
| 7883 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 7884 | * the insert is just empty lines |
| 7885 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 7886 | * present or line_count > 1. It looks better if we do all the inserts |
| 7887 | * at once. |
| 7888 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 7889 | * insert is just empty lines and T_CE is not present or line_count > |
| 7890 | * 1. |
| 7891 | * 4. Use T_AL (insert line) if it exists. |
| 7892 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 7893 | * just empty lines. |
| 7894 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 7895 | * just empty lines. |
| 7896 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 7897 | * the 'da' flag is not set or we have clear line capability. |
| 7898 | * 8. redraw the characters from ScreenLines[]. |
| 7899 | * |
| 7900 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 7901 | * the scrollbar for the window. It does have insert line, use that if it |
| 7902 | * exists. |
| 7903 | */ |
| 7904 | result_empty = (row + line_count >= end); |
| 7905 | #ifdef FEAT_VERTSPLIT |
| 7906 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 7907 | type = USE_REDRAW; |
| 7908 | else |
| 7909 | #endif |
| 7910 | if (can_clear(T_CD) && result_empty) |
| 7911 | type = USE_T_CD; |
| 7912 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 7913 | type = USE_T_CAL; |
| 7914 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 7915 | type = USE_T_CDL; |
| 7916 | else if (*T_AL != NUL) |
| 7917 | type = USE_T_AL; |
| 7918 | else if (can_ce && result_empty) |
| 7919 | type = USE_T_CE; |
| 7920 | else if (*T_DL != NUL && result_empty) |
| 7921 | type = USE_T_DL; |
| 7922 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 7923 | type = USE_T_SR; |
| 7924 | else |
| 7925 | return FAIL; |
| 7926 | |
| 7927 | /* |
| 7928 | * For clearing the lines screen_del_lines() is used. This will also take |
| 7929 | * care of t_db if necessary. |
| 7930 | */ |
| 7931 | if (type == USE_T_CD || type == USE_T_CDL || |
| 7932 | type == USE_T_CE || type == USE_T_DL) |
| 7933 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 7934 | |
| 7935 | /* |
| 7936 | * If text is retained below the screen, first clear or delete as many |
| 7937 | * lines at the bottom of the window as are about to be inserted so that |
| 7938 | * the deleted lines won't later surface during a screen_del_lines. |
| 7939 | */ |
| 7940 | if (*T_DB) |
| 7941 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 7942 | |
| 7943 | #ifdef FEAT_CLIPBOARD |
| 7944 | /* Remove a modeless selection when inserting lines halfway the screen |
| 7945 | * or not the full width of the screen. */ |
| 7946 | if (off + row > 0 |
| 7947 | # ifdef FEAT_VERTSPLIT |
| 7948 | || (wp != NULL && wp->w_width != Columns) |
| 7949 | # endif |
| 7950 | ) |
| 7951 | clip_clear_selection(); |
| 7952 | else |
| 7953 | clip_scroll_selection(-line_count); |
| 7954 | #endif |
| 7955 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7956 | #ifdef FEAT_GUI |
| 7957 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 7958 | * scrolling is actually carried out. */ |
| 7959 | gui_dont_update_cursor(); |
| 7960 | #endif |
| 7961 | |
| 7962 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 7963 | cursor_row = row; |
| 7964 | else |
| 7965 | cursor_row = row + off; |
| 7966 | |
| 7967 | /* |
| 7968 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 7969 | * Clear the inserted lines in ScreenLines[]. |
| 7970 | */ |
| 7971 | row += off; |
| 7972 | end += off; |
| 7973 | for (i = 0; i < line_count; ++i) |
| 7974 | { |
| 7975 | #ifdef FEAT_VERTSPLIT |
| 7976 | if (wp != NULL && wp->w_width != Columns) |
| 7977 | { |
| 7978 | /* need to copy part of a line */ |
| 7979 | j = end - 1 - i; |
| 7980 | while ((j -= line_count) >= row) |
| 7981 | linecopy(j + line_count, j, wp); |
| 7982 | j += line_count; |
| 7983 | if (can_clear((char_u *)" ")) |
| 7984 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 7985 | else |
| 7986 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 7987 | LineWraps[j] = FALSE; |
| 7988 | } |
| 7989 | else |
| 7990 | #endif |
| 7991 | { |
| 7992 | j = end - 1 - i; |
| 7993 | temp = LineOffset[j]; |
| 7994 | while ((j -= line_count) >= row) |
| 7995 | { |
| 7996 | LineOffset[j + line_count] = LineOffset[j]; |
| 7997 | LineWraps[j + line_count] = LineWraps[j]; |
| 7998 | } |
| 7999 | LineOffset[j + line_count] = temp; |
| 8000 | LineWraps[j + line_count] = FALSE; |
| 8001 | if (can_clear((char_u *)" ")) |
| 8002 | lineclear(temp, (int)Columns); |
| 8003 | else |
| 8004 | lineinvalid(temp, (int)Columns); |
| 8005 | } |
| 8006 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8007 | |
| 8008 | screen_stop_highlight(); |
| 8009 | windgoto(cursor_row, 0); |
| 8010 | |
| 8011 | #ifdef FEAT_VERTSPLIT |
| 8012 | /* redraw the characters */ |
| 8013 | if (type == USE_REDRAW) |
| 8014 | redraw_block(row, end, wp); |
| 8015 | else |
| 8016 | #endif |
| 8017 | if (type == USE_T_CAL) |
| 8018 | { |
| 8019 | term_append_lines(line_count); |
| 8020 | screen_start(); /* don't know where cursor is now */ |
| 8021 | } |
| 8022 | else |
| 8023 | { |
| 8024 | for (i = 0; i < line_count; i++) |
| 8025 | { |
| 8026 | if (type == USE_T_AL) |
| 8027 | { |
| 8028 | if (i && cursor_row != 0) |
| 8029 | windgoto(cursor_row, 0); |
| 8030 | out_str(T_AL); |
| 8031 | } |
| 8032 | else /* type == USE_T_SR */ |
| 8033 | out_str(T_SR); |
| 8034 | screen_start(); /* don't know where cursor is now */ |
| 8035 | } |
| 8036 | } |
| 8037 | |
| 8038 | /* |
| 8039 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 8040 | * have been scrolled down into the region. |
| 8041 | */ |
| 8042 | if (type == USE_T_SR && *T_DA) |
| 8043 | { |
| 8044 | for (i = 0; i < line_count; ++i) |
| 8045 | { |
| 8046 | windgoto(off + i, 0); |
| 8047 | out_str(T_CE); |
| 8048 | screen_start(); /* don't know where cursor is now */ |
| 8049 | } |
| 8050 | } |
| 8051 | |
| 8052 | #ifdef FEAT_GUI |
| 8053 | gui_can_update_cursor(); |
| 8054 | if (gui.in_use) |
| 8055 | out_flush(); /* always flush after a scroll */ |
| 8056 | #endif |
| 8057 | return OK; |
| 8058 | } |
| 8059 | |
| 8060 | /* |
| 8061 | * delete lines on the screen and update ScreenLines[] |
| 8062 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 8063 | * When scrolling region used 'off' is the offset from the top for the region. |
| 8064 | * 'row' and 'end' are relative to the start of the region. |
| 8065 | * |
| 8066 | * Return OK for success, FAIL if the lines are not deleted. |
| 8067 | */ |
| 8068 | /*ARGSUSED*/ |
| 8069 | int |
| 8070 | screen_del_lines(off, row, line_count, end, force, wp) |
| 8071 | int off; |
| 8072 | int row; |
| 8073 | int line_count; |
| 8074 | int end; |
| 8075 | int force; /* even when line_count > p_ttyscroll */ |
| 8076 | win_T *wp; /* NULL or window to use width from */ |
| 8077 | { |
| 8078 | int j; |
| 8079 | int i; |
| 8080 | unsigned temp; |
| 8081 | int cursor_row; |
| 8082 | int cursor_end; |
| 8083 | int result_empty; /* result is empty until end of region */ |
| 8084 | int can_delete; /* deleting line codes can be used */ |
| 8085 | int type; |
| 8086 | |
| 8087 | /* |
| 8088 | * FAIL if |
| 8089 | * - there is no valid screen |
| 8090 | * - the screen has to be redrawn completely |
| 8091 | * - the line count is less than one |
| 8092 | * - the line count is more than 'ttyscroll' |
| 8093 | */ |
| 8094 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 8095 | (!force && line_count > p_ttyscroll)) |
| 8096 | return FAIL; |
| 8097 | |
| 8098 | /* |
| 8099 | * Check if the rest of the current region will become empty. |
| 8100 | */ |
| 8101 | result_empty = row + line_count >= end; |
| 8102 | |
| 8103 | /* |
| 8104 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 8105 | * available. |
| 8106 | */ |
| 8107 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 8108 | |
| 8109 | /* |
| 8110 | * There are six ways to delete lines: |
| 8111 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 8112 | * characters from ScreenLines[]. |
| 8113 | * 1. Use T_CD if it exists and the result is empty. |
| 8114 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 8115 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 8116 | * none of the other ways work. |
| 8117 | * 4. Use T_CE (erase line) if the result is empty. |
| 8118 | * 5. Use T_DL (delete line) if it exists. |
| 8119 | * 6. redraw the characters from ScreenLines[]. |
| 8120 | */ |
| 8121 | #ifdef FEAT_VERTSPLIT |
| 8122 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 8123 | type = USE_REDRAW; |
| 8124 | else |
| 8125 | #endif |
| 8126 | if (can_clear(T_CD) && result_empty) |
| 8127 | type = USE_T_CD; |
| 8128 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 8129 | /* |
| 8130 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 8131 | * its internal termcap... this works okay for tests which test *T_DB != |
| 8132 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 8133 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 8134 | * the trick... |
| 8135 | * Anyway, this hack will hopefully go away with the next OS release. |
| 8136 | * (Olaf Seibert) |
| 8137 | */ |
| 8138 | else if (row == 0 && T_DB == empty_option |
| 8139 | && (line_count == 1 || *T_CDL == NUL)) |
| 8140 | #else |
| 8141 | else if (row == 0 && ( |
| 8142 | #ifndef AMIGA |
| 8143 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 8144 | * up, so use delete-line command */ |
| 8145 | line_count == 1 || |
| 8146 | #endif |
| 8147 | *T_CDL == NUL)) |
| 8148 | #endif |
| 8149 | type = USE_NL; |
| 8150 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 8151 | type = USE_T_CDL; |
| 8152 | else if (can_clear(T_CE) && result_empty |
| 8153 | #ifdef FEAT_VERTSPLIT |
| 8154 | && (wp == NULL || wp->w_width == Columns) |
| 8155 | #endif |
| 8156 | ) |
| 8157 | type = USE_T_CE; |
| 8158 | else if (*T_DL != NUL && can_delete) |
| 8159 | type = USE_T_DL; |
| 8160 | else if (*T_CDL != NUL && can_delete) |
| 8161 | type = USE_T_CDL; |
| 8162 | else |
| 8163 | return FAIL; |
| 8164 | |
| 8165 | #ifdef FEAT_CLIPBOARD |
| 8166 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 8167 | * not the full width of the screen. */ |
| 8168 | if (off + row > 0 |
| 8169 | # ifdef FEAT_VERTSPLIT |
| 8170 | || (wp != NULL && wp->w_width != Columns) |
| 8171 | # endif |
| 8172 | ) |
| 8173 | clip_clear_selection(); |
| 8174 | else |
| 8175 | clip_scroll_selection(line_count); |
| 8176 | #endif |
| 8177 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8178 | #ifdef FEAT_GUI |
| 8179 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 8180 | * scrolling is actually carried out. */ |
| 8181 | gui_dont_update_cursor(); |
| 8182 | #endif |
| 8183 | |
| 8184 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 8185 | { |
| 8186 | cursor_row = row; |
| 8187 | cursor_end = end; |
| 8188 | } |
| 8189 | else |
| 8190 | { |
| 8191 | cursor_row = row + off; |
| 8192 | cursor_end = end + off; |
| 8193 | } |
| 8194 | |
| 8195 | /* |
| 8196 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 8197 | * Clear the inserted lines in ScreenLines[]. |
| 8198 | */ |
| 8199 | row += off; |
| 8200 | end += off; |
| 8201 | for (i = 0; i < line_count; ++i) |
| 8202 | { |
| 8203 | #ifdef FEAT_VERTSPLIT |
| 8204 | if (wp != NULL && wp->w_width != Columns) |
| 8205 | { |
| 8206 | /* need to copy part of a line */ |
| 8207 | j = row + i; |
| 8208 | while ((j += line_count) <= end - 1) |
| 8209 | linecopy(j - line_count, j, wp); |
| 8210 | j -= line_count; |
| 8211 | if (can_clear((char_u *)" ")) |
| 8212 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8213 | else |
| 8214 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8215 | LineWraps[j] = FALSE; |
| 8216 | } |
| 8217 | else |
| 8218 | #endif |
| 8219 | { |
| 8220 | /* whole width, moving the line pointers is faster */ |
| 8221 | j = row + i; |
| 8222 | temp = LineOffset[j]; |
| 8223 | while ((j += line_count) <= end - 1) |
| 8224 | { |
| 8225 | LineOffset[j - line_count] = LineOffset[j]; |
| 8226 | LineWraps[j - line_count] = LineWraps[j]; |
| 8227 | } |
| 8228 | LineOffset[j - line_count] = temp; |
| 8229 | LineWraps[j - line_count] = FALSE; |
| 8230 | if (can_clear((char_u *)" ")) |
| 8231 | lineclear(temp, (int)Columns); |
| 8232 | else |
| 8233 | lineinvalid(temp, (int)Columns); |
| 8234 | } |
| 8235 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8236 | |
| 8237 | screen_stop_highlight(); |
| 8238 | |
| 8239 | #ifdef FEAT_VERTSPLIT |
| 8240 | /* redraw the characters */ |
| 8241 | if (type == USE_REDRAW) |
| 8242 | redraw_block(row, end, wp); |
| 8243 | else |
| 8244 | #endif |
| 8245 | if (type == USE_T_CD) /* delete the lines */ |
| 8246 | { |
| 8247 | windgoto(cursor_row, 0); |
| 8248 | out_str(T_CD); |
| 8249 | screen_start(); /* don't know where cursor is now */ |
| 8250 | } |
| 8251 | else if (type == USE_T_CDL) |
| 8252 | { |
| 8253 | windgoto(cursor_row, 0); |
| 8254 | term_delete_lines(line_count); |
| 8255 | screen_start(); /* don't know where cursor is now */ |
| 8256 | } |
| 8257 | /* |
| 8258 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 8259 | * the whole screen (scroll region) up by outputting newlines on the |
| 8260 | * last line. |
| 8261 | */ |
| 8262 | else if (type == USE_NL) |
| 8263 | { |
| 8264 | windgoto(cursor_end - 1, 0); |
| 8265 | for (i = line_count; --i >= 0; ) |
| 8266 | out_char('\n'); /* cursor will remain on same line */ |
| 8267 | } |
| 8268 | else |
| 8269 | { |
| 8270 | for (i = line_count; --i >= 0; ) |
| 8271 | { |
| 8272 | if (type == USE_T_DL) |
| 8273 | { |
| 8274 | windgoto(cursor_row, 0); |
| 8275 | out_str(T_DL); /* delete a line */ |
| 8276 | } |
| 8277 | else /* type == USE_T_CE */ |
| 8278 | { |
| 8279 | windgoto(cursor_row + i, 0); |
| 8280 | out_str(T_CE); /* erase a line */ |
| 8281 | } |
| 8282 | screen_start(); /* don't know where cursor is now */ |
| 8283 | } |
| 8284 | } |
| 8285 | |
| 8286 | /* |
| 8287 | * If the 'db' flag is set, we need to clear the lines that have been |
| 8288 | * scrolled up at the bottom of the region. |
| 8289 | */ |
| 8290 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 8291 | { |
| 8292 | for (i = line_count; i > 0; --i) |
| 8293 | { |
| 8294 | windgoto(cursor_end - i, 0); |
| 8295 | out_str(T_CE); /* erase a line */ |
| 8296 | screen_start(); /* don't know where cursor is now */ |
| 8297 | } |
| 8298 | } |
| 8299 | |
| 8300 | #ifdef FEAT_GUI |
| 8301 | gui_can_update_cursor(); |
| 8302 | if (gui.in_use) |
| 8303 | out_flush(); /* always flush after a scroll */ |
| 8304 | #endif |
| 8305 | |
| 8306 | return OK; |
| 8307 | } |
| 8308 | |
| 8309 | /* |
| 8310 | * show the current mode and ruler |
| 8311 | * |
| 8312 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 8313 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 8314 | * cleared only if a mode is shown. |
| 8315 | * Return the length of the message (0 if no message). |
| 8316 | */ |
| 8317 | int |
| 8318 | showmode() |
| 8319 | { |
| 8320 | int need_clear; |
| 8321 | int length = 0; |
| 8322 | int do_mode; |
| 8323 | int attr; |
| 8324 | int nwr_save; |
| 8325 | #ifdef FEAT_INS_EXPAND |
| 8326 | int sub_attr; |
| 8327 | #endif |
| 8328 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 8329 | do_mode = ((p_smd && msg_silent == 0) |
| 8330 | && ((State & INSERT) |
| 8331 | || restart_edit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8332 | #ifdef FEAT_VISUAL |
| 8333 | || VIsual_active |
| 8334 | #endif |
| 8335 | )); |
| 8336 | if (do_mode || Recording) |
| 8337 | { |
| 8338 | /* |
| 8339 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 8340 | * Call char_avail() only when we are going to show something, because |
| 8341 | * it takes a bit of time. |
| 8342 | */ |
| 8343 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 8344 | { |
| 8345 | redraw_cmdline = TRUE; /* show mode later */ |
| 8346 | return 0; |
| 8347 | } |
| 8348 | |
| 8349 | nwr_save = need_wait_return; |
| 8350 | |
| 8351 | /* wait a bit before overwriting an important message */ |
| 8352 | check_for_delay(FALSE); |
| 8353 | |
| 8354 | /* if the cmdline is more than one line high, erase top lines */ |
| 8355 | need_clear = clear_cmdline; |
| 8356 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 8357 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 8358 | |
| 8359 | /* Position on the last line in the window, column 0 */ |
| 8360 | msg_pos_mode(); |
| 8361 | cursor_off(); |
| 8362 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 8363 | if (do_mode) |
| 8364 | { |
| 8365 | MSG_PUTS_ATTR("--", attr); |
| 8366 | #if defined(FEAT_XIM) |
| 8367 | if (xic != NULL && im_get_status() && !p_imdisable |
| 8368 | && curbuf->b_p_iminsert == B_IMODE_IM) |
| 8369 | # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */ |
| 8370 | MSG_PUTS_ATTR(" IM", attr); |
| 8371 | # else |
| 8372 | MSG_PUTS_ATTR(" XIM", attr); |
| 8373 | # endif |
| 8374 | #endif |
| 8375 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 8376 | if (gui.in_use) |
| 8377 | { |
| 8378 | if (hangul_input_state_get()) |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 8379 | MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8380 | } |
| 8381 | #endif |
| 8382 | #ifdef FEAT_INS_EXPAND |
| 8383 | if (edit_submode != NULL) /* CTRL-X in Insert mode */ |
| 8384 | { |
| 8385 | /* These messages can get long, avoid a wrap in a narrow |
| 8386 | * window. Prefer showing edit_submode_extra. */ |
| 8387 | length = (Rows - msg_row) * Columns - 3; |
| 8388 | if (edit_submode_extra != NULL) |
| 8389 | length -= vim_strsize(edit_submode_extra); |
| 8390 | if (length > 0) |
| 8391 | { |
| 8392 | if (edit_submode_pre != NULL) |
| 8393 | length -= vim_strsize(edit_submode_pre); |
| 8394 | if (length - vim_strsize(edit_submode) > 0) |
| 8395 | { |
| 8396 | if (edit_submode_pre != NULL) |
| 8397 | msg_puts_attr(edit_submode_pre, attr); |
| 8398 | msg_puts_attr(edit_submode, attr); |
| 8399 | } |
| 8400 | if (edit_submode_extra != NULL) |
| 8401 | { |
| 8402 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 8403 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 8404 | sub_attr = hl_attr(edit_submode_highl); |
| 8405 | else |
| 8406 | sub_attr = attr; |
| 8407 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 8408 | } |
| 8409 | } |
| 8410 | length = 0; |
| 8411 | } |
| 8412 | else |
| 8413 | #endif |
| 8414 | { |
| 8415 | #ifdef FEAT_VREPLACE |
| 8416 | if (State & VREPLACE_FLAG) |
| 8417 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 8418 | else |
| 8419 | #endif |
| 8420 | if (State & REPLACE_FLAG) |
| 8421 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 8422 | else if (State & INSERT) |
| 8423 | { |
| 8424 | #ifdef FEAT_RIGHTLEFT |
| 8425 | if (p_ri) |
| 8426 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 8427 | #endif |
| 8428 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 8429 | } |
| 8430 | else if (restart_edit == 'I') |
| 8431 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 8432 | else if (restart_edit == 'R') |
| 8433 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 8434 | else if (restart_edit == 'V') |
| 8435 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 8436 | #ifdef FEAT_RIGHTLEFT |
| 8437 | if (p_hkmap) |
| 8438 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 8439 | # ifdef FEAT_FKMAP |
| 8440 | if (p_fkmap) |
| 8441 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 8442 | # endif |
| 8443 | #endif |
| 8444 | #ifdef FEAT_KEYMAP |
| 8445 | if (State & LANGMAP) |
| 8446 | { |
| 8447 | # ifdef FEAT_ARABIC |
| 8448 | if (curwin->w_p_arab) |
| 8449 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 8450 | else |
| 8451 | # endif |
| 8452 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 8453 | } |
| 8454 | #endif |
| 8455 | if ((State & INSERT) && p_paste) |
| 8456 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 8457 | |
| 8458 | #ifdef FEAT_VISUAL |
| 8459 | if (VIsual_active) |
| 8460 | { |
| 8461 | char *p; |
| 8462 | |
| 8463 | /* Don't concatenate separate words to avoid translation |
| 8464 | * problems. */ |
| 8465 | switch ((VIsual_select ? 4 : 0) |
| 8466 | + (VIsual_mode == Ctrl_V) * 2 |
| 8467 | + (VIsual_mode == 'V')) |
| 8468 | { |
| 8469 | case 0: p = N_(" VISUAL"); break; |
| 8470 | case 1: p = N_(" VISUAL LINE"); break; |
| 8471 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 8472 | case 4: p = N_(" SELECT"); break; |
| 8473 | case 5: p = N_(" SELECT LINE"); break; |
| 8474 | default: p = N_(" SELECT BLOCK"); break; |
| 8475 | } |
| 8476 | MSG_PUTS_ATTR(_(p), attr); |
| 8477 | } |
| 8478 | #endif |
| 8479 | MSG_PUTS_ATTR(" --", attr); |
| 8480 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8481 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8482 | need_clear = TRUE; |
| 8483 | } |
| 8484 | if (Recording |
| 8485 | #ifdef FEAT_INS_EXPAND |
| 8486 | && edit_submode == NULL /* otherwise it gets too long */ |
| 8487 | #endif |
| 8488 | ) |
| 8489 | { |
| 8490 | MSG_PUTS_ATTR(_("recording"), attr); |
| 8491 | need_clear = TRUE; |
| 8492 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8493 | |
| 8494 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8495 | if (need_clear || clear_cmdline) |
| 8496 | msg_clr_eos(); |
| 8497 | msg_didout = FALSE; /* overwrite this message */ |
| 8498 | length = msg_col; |
| 8499 | msg_col = 0; |
| 8500 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 8501 | } |
| 8502 | else if (clear_cmdline && msg_silent == 0) |
| 8503 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 8504 | msg_clr_cmdline(); |
| 8505 | |
| 8506 | #ifdef FEAT_CMDL_INFO |
| 8507 | # ifdef FEAT_VISUAL |
| 8508 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 8509 | if (VIsual_active) |
| 8510 | clear_showcmd(); |
| 8511 | # endif |
| 8512 | |
| 8513 | /* If the last window has no status line, the ruler is after the mode |
| 8514 | * message and must be redrawn */ |
| 8515 | if (redrawing() |
| 8516 | # ifdef FEAT_WINDOWS |
| 8517 | && lastwin->w_status_height == 0 |
| 8518 | # endif |
| 8519 | ) |
| 8520 | win_redr_ruler(lastwin, TRUE); |
| 8521 | #endif |
| 8522 | redraw_cmdline = FALSE; |
| 8523 | clear_cmdline = FALSE; |
| 8524 | |
| 8525 | return length; |
| 8526 | } |
| 8527 | |
| 8528 | /* |
| 8529 | * Position for a mode message. |
| 8530 | */ |
| 8531 | static void |
| 8532 | msg_pos_mode() |
| 8533 | { |
| 8534 | msg_col = 0; |
| 8535 | msg_row = Rows - 1; |
| 8536 | } |
| 8537 | |
| 8538 | /* |
| 8539 | * Delete mode message. Used when ESC is typed which is expected to end |
| 8540 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8541 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8542 | */ |
| 8543 | void |
| 8544 | unshowmode(force) |
| 8545 | int force; |
| 8546 | { |
| 8547 | /* |
| 8548 | * Don't delete it right now, when not redrawing or insided a mapping. |
| 8549 | */ |
| 8550 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 8551 | redraw_cmdline = TRUE; /* delete mode later */ |
| 8552 | else |
| 8553 | { |
| 8554 | msg_pos_mode(); |
| 8555 | if (Recording) |
| 8556 | MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); |
| 8557 | msg_clr_eos(); |
| 8558 | } |
| 8559 | } |
| 8560 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8561 | #if defined(FEAT_WINDOWS) |
| 8562 | /* |
| 8563 | * Draw the tab pages line at the top of the Vim window. |
| 8564 | */ |
| 8565 | static void |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8566 | draw_tabline() |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8567 | { |
| 8568 | int tabcount = 0; |
| 8569 | tabpage_T *tp; |
| 8570 | int tabwidth; |
| 8571 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8572 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8573 | int attr; |
| 8574 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8575 | win_T *cwp; |
| 8576 | int wincount; |
| 8577 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8578 | int c; |
| 8579 | int len; |
| 8580 | int attr_sel = hl_attr(HLF_TPS); |
| 8581 | int attr_nosel = hl_attr(HLF_TP); |
| 8582 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8583 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8584 | int room; |
| 8585 | int use_sep_chars = (t_colors < 8 |
| 8586 | #ifdef FEAT_GUI |
| 8587 | && !gui.in_use |
| 8588 | #endif |
| 8589 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8590 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8591 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8592 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 8593 | #ifdef FEAT_GUI_TABLINE |
| 8594 | /* When the GUI has the tabline then this always returns zero. */ |
| 8595 | if (gui_use_tabline()) |
| 8596 | { |
| 8597 | gui_update_tabline(); |
| 8598 | return; |
| 8599 | } |
| 8600 | #endif |
| 8601 | |
| 8602 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8603 | return; |
| 8604 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8605 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8606 | |
| 8607 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 8608 | for (scol = 0; scol < Columns; ++scol) |
| 8609 | TabPageIdxs[scol] = 0; |
| 8610 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8611 | /* Use the 'tabline' option if it's set. */ |
| 8612 | if (*p_tal != NUL) |
| 8613 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8614 | int save_called_emsg = called_emsg; |
| 8615 | |
| 8616 | /* Check for an error. If there is one we would loop in redrawing the |
| 8617 | * screen. Avoid that by making 'tabline' empty. */ |
| 8618 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8619 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8620 | if (called_emsg) |
| 8621 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 8622 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8623 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8624 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8625 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8626 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8627 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8628 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 8629 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8630 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8631 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 8632 | if (tabwidth < 6) |
| 8633 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8634 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8635 | attr = attr_nosel; |
| 8636 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8637 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 8638 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 8639 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8640 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8641 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8642 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8643 | if (tp->tp_topframe == topframe) |
| 8644 | attr = attr_sel; |
| 8645 | if (use_sep_chars && col > 0) |
| 8646 | screen_putchar('|', 0, col++, attr); |
| 8647 | |
| 8648 | if (tp->tp_topframe != topframe) |
| 8649 | attr = attr_nosel; |
| 8650 | |
| 8651 | screen_putchar(' ', 0, col++, attr); |
| 8652 | |
| 8653 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8654 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8655 | cwp = curwin; |
| 8656 | wp = firstwin; |
| 8657 | } |
| 8658 | else |
| 8659 | { |
| 8660 | cwp = tp->tp_curwin; |
| 8661 | wp = tp->tp_firstwin; |
| 8662 | } |
| 8663 | |
| 8664 | modified = FALSE; |
| 8665 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 8666 | if (bufIsChanged(wp->w_buffer)) |
| 8667 | modified = TRUE; |
| 8668 | if (modified || wincount > 1) |
| 8669 | { |
| 8670 | if (wincount > 1) |
| 8671 | { |
| 8672 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
| 8673 | len = STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 8674 | if (col + len >= Columns - 3) |
| 8675 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8676 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8677 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8678 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8679 | #else |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8680 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8681 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8682 | ); |
| 8683 | col += len; |
| 8684 | } |
| 8685 | if (modified) |
| 8686 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 8687 | screen_putchar(' ', 0, col++, attr); |
| 8688 | } |
| 8689 | |
| 8690 | room = scol - col + tabwidth - 1; |
| 8691 | if (room > 0) |
| 8692 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 8693 | /* Get buffer name in NameBuff[] */ |
| 8694 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8695 | len = vim_strsize(NameBuff); |
| 8696 | p = NameBuff; |
| 8697 | #ifdef FEAT_MBYTE |
| 8698 | if (has_mbyte) |
| 8699 | while (len > room) |
| 8700 | { |
| 8701 | len -= ptr2cells(p); |
| 8702 | mb_ptr_adv(p); |
| 8703 | } |
| 8704 | else |
| 8705 | #endif |
| 8706 | if (len > room) |
| 8707 | { |
| 8708 | p += len - room; |
| 8709 | len = room; |
| 8710 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 8711 | if (len > Columns - col - 1) |
| 8712 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8713 | |
| 8714 | screen_puts_len(p, STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8715 | col += len; |
| 8716 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8717 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8718 | |
| 8719 | /* Store the tab page number in TabPageIdxs[], so that |
| 8720 | * jump_to_mouse() knows where each one is. */ |
| 8721 | ++tabcount; |
| 8722 | while (scol < col) |
| 8723 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8724 | } |
| 8725 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8726 | if (use_sep_chars) |
| 8727 | c = '_'; |
| 8728 | else |
| 8729 | c = ' '; |
| 8730 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8731 | |
| 8732 | /* Put an "X" for closing the current tab if there are several. */ |
| 8733 | if (first_tabpage->tp_next != NULL) |
| 8734 | { |
| 8735 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 8736 | TabPageIdxs[Columns - 1] = -999; |
| 8737 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8738 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8739 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 8740 | |
| 8741 | /* |
| 8742 | * Get buffer name for "buf" into NameBuff[]. |
| 8743 | * Takes care of special buffer names and translates special characters. |
| 8744 | */ |
| 8745 | void |
| 8746 | get_trans_bufname(buf) |
| 8747 | buf_T *buf; |
| 8748 | { |
| 8749 | if (buf_spname(buf) != NULL) |
| 8750 | STRCPY(NameBuff, buf_spname(buf)); |
| 8751 | else |
| 8752 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 8753 | trans_characters(NameBuff, MAXPATHL); |
| 8754 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8755 | #endif |
| 8756 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8757 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 8758 | /* |
| 8759 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 8760 | */ |
| 8761 | static int |
| 8762 | fillchar_status(attr, is_curwin) |
| 8763 | int *attr; |
| 8764 | int is_curwin; |
| 8765 | { |
| 8766 | int fill; |
| 8767 | if (is_curwin) |
| 8768 | { |
| 8769 | *attr = hl_attr(HLF_S); |
| 8770 | fill = fill_stl; |
| 8771 | } |
| 8772 | else |
| 8773 | { |
| 8774 | *attr = hl_attr(HLF_SNC); |
| 8775 | fill = fill_stlnc; |
| 8776 | } |
| 8777 | /* Use fill when there is highlighting, and highlighting of current |
| 8778 | * window differs, or the fillchars differ, or this is not the |
| 8779 | * current window */ |
| 8780 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 8781 | || !is_curwin || firstwin == lastwin) |
| 8782 | || (fill_stl != fill_stlnc))) |
| 8783 | return fill; |
| 8784 | if (is_curwin) |
| 8785 | return '^'; |
| 8786 | return '='; |
| 8787 | } |
| 8788 | #endif |
| 8789 | |
| 8790 | #ifdef FEAT_VERTSPLIT |
| 8791 | /* |
| 8792 | * Get the character to use in a separator between vertically split windows. |
| 8793 | * Get its attributes in "*attr". |
| 8794 | */ |
| 8795 | static int |
| 8796 | fillchar_vsep(attr) |
| 8797 | int *attr; |
| 8798 | { |
| 8799 | *attr = hl_attr(HLF_C); |
| 8800 | if (*attr == 0 && fill_vert == ' ') |
| 8801 | return '|'; |
| 8802 | else |
| 8803 | return fill_vert; |
| 8804 | } |
| 8805 | #endif |
| 8806 | |
| 8807 | /* |
| 8808 | * Return TRUE if redrawing should currently be done. |
| 8809 | */ |
| 8810 | int |
| 8811 | redrawing() |
| 8812 | { |
| 8813 | return (!RedrawingDisabled |
| 8814 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 8815 | } |
| 8816 | |
| 8817 | /* |
| 8818 | * Return TRUE if printing messages should currently be done. |
| 8819 | */ |
| 8820 | int |
| 8821 | messaging() |
| 8822 | { |
| 8823 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 8824 | } |
| 8825 | |
| 8826 | /* |
| 8827 | * Show current status info in ruler and various other places |
| 8828 | * If always is FALSE, only show ruler if position has changed. |
| 8829 | */ |
| 8830 | void |
| 8831 | showruler(always) |
| 8832 | int always; |
| 8833 | { |
| 8834 | if (!always && !redrawing()) |
| 8835 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 8836 | #ifdef FEAT_INS_EXPAND |
| 8837 | if (pum_visible()) |
| 8838 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 8839 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 8840 | /* Don't redraw right now, do it later. */ |
| 8841 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 8842 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 8843 | return; |
| 8844 | } |
| 8845 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8846 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 8847 | if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8848 | { |
| 8849 | redraw_custum_statusline(curwin); |
| 8850 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8851 | else |
| 8852 | #endif |
| 8853 | #ifdef FEAT_CMDL_INFO |
| 8854 | win_redr_ruler(curwin, always); |
| 8855 | #endif |
| 8856 | |
| 8857 | #ifdef FEAT_TITLE |
| 8858 | if (need_maketitle |
| 8859 | # ifdef FEAT_STL_OPT |
| 8860 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 8861 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 8862 | # endif |
| 8863 | ) |
| 8864 | maketitle(); |
| 8865 | #endif |
| 8866 | } |
| 8867 | |
| 8868 | #ifdef FEAT_CMDL_INFO |
| 8869 | static void |
| 8870 | win_redr_ruler(wp, always) |
| 8871 | win_T *wp; |
| 8872 | int always; |
| 8873 | { |
| 8874 | char_u buffer[70]; |
| 8875 | int row; |
| 8876 | int fillchar; |
| 8877 | int attr; |
| 8878 | int empty_line = FALSE; |
| 8879 | colnr_T virtcol; |
| 8880 | int i; |
| 8881 | int o; |
| 8882 | #ifdef FEAT_VERTSPLIT |
| 8883 | int this_ru_col; |
| 8884 | int off = 0; |
| 8885 | int width = Columns; |
| 8886 | # define WITH_OFF(x) x |
| 8887 | # define WITH_WIDTH(x) x |
| 8888 | #else |
| 8889 | # define WITH_OFF(x) 0 |
| 8890 | # define WITH_WIDTH(x) Columns |
| 8891 | # define this_ru_col ru_col |
| 8892 | #endif |
| 8893 | |
| 8894 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 8895 | if (!p_ru) |
| 8896 | return; |
| 8897 | |
| 8898 | /* |
| 8899 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 8900 | * after deleting lines, before cursor.lnum is corrected. |
| 8901 | */ |
| 8902 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 8903 | return; |
| 8904 | |
| 8905 | #ifdef FEAT_INS_EXPAND |
| 8906 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 8907 | * the (long) mode message. */ |
| 8908 | # ifdef FEAT_WINDOWS |
| 8909 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 8910 | # endif |
| 8911 | if (edit_submode != NULL) |
| 8912 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 8913 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 8914 | if (pum_visible()) |
| 8915 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8916 | #endif |
| 8917 | |
| 8918 | #ifdef FEAT_STL_OPT |
| 8919 | if (*p_ruf) |
| 8920 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8921 | int save_called_emsg = called_emsg; |
| 8922 | |
| 8923 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8924 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8925 | if (called_emsg) |
| 8926 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 8927 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8928 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8929 | return; |
| 8930 | } |
| 8931 | #endif |
| 8932 | |
| 8933 | /* |
| 8934 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 8935 | */ |
| 8936 | if (!(State & INSERT) |
| 8937 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 8938 | empty_line = TRUE; |
| 8939 | |
| 8940 | /* |
| 8941 | * Only draw the ruler when something changed. |
| 8942 | */ |
| 8943 | validate_virtcol_win(wp); |
| 8944 | if ( redraw_cmdline |
| 8945 | || always |
| 8946 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 8947 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 8948 | || wp->w_virtcol != wp->w_ru_virtcol |
| 8949 | #ifdef FEAT_VIRTUALEDIT |
| 8950 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 8951 | #endif |
| 8952 | || wp->w_topline != wp->w_ru_topline |
| 8953 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 8954 | #ifdef FEAT_DIFF |
| 8955 | || wp->w_topfill != wp->w_ru_topfill |
| 8956 | #endif |
| 8957 | || empty_line != wp->w_ru_empty) |
| 8958 | { |
| 8959 | cursor_off(); |
| 8960 | #ifdef FEAT_WINDOWS |
| 8961 | if (wp->w_status_height) |
| 8962 | { |
| 8963 | row = W_WINROW(wp) + wp->w_height; |
| 8964 | fillchar = fillchar_status(&attr, wp == curwin); |
| 8965 | # ifdef FEAT_VERTSPLIT |
| 8966 | off = W_WINCOL(wp); |
| 8967 | width = W_WIDTH(wp); |
| 8968 | # endif |
| 8969 | } |
| 8970 | else |
| 8971 | #endif |
| 8972 | { |
| 8973 | row = Rows - 1; |
| 8974 | fillchar = ' '; |
| 8975 | attr = 0; |
| 8976 | #ifdef FEAT_VERTSPLIT |
| 8977 | width = Columns; |
| 8978 | off = 0; |
| 8979 | #endif |
| 8980 | } |
| 8981 | |
| 8982 | /* In list mode virtcol needs to be recomputed */ |
| 8983 | virtcol = wp->w_virtcol; |
| 8984 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 8985 | { |
| 8986 | wp->w_p_list = FALSE; |
| 8987 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 8988 | wp->w_p_list = TRUE; |
| 8989 | } |
| 8990 | |
| 8991 | /* |
| 8992 | * Some sprintfs return the length, some return a pointer. |
| 8993 | * To avoid portability problems we use strlen() here. |
| 8994 | */ |
| 8995 | sprintf((char *)buffer, "%ld,", |
| 8996 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 8997 | ? 0L |
| 8998 | : (long)(wp->w_cursor.lnum)); |
| 8999 | col_print(buffer + STRLEN(buffer), |
| 9000 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 9001 | (int)virtcol + 1); |
| 9002 | |
| 9003 | /* |
| 9004 | * Add a "50%" if there is room for it. |
| 9005 | * On the last line, don't print in the last column (scrolls the |
| 9006 | * screen up on some terminals). |
| 9007 | */ |
| 9008 | i = (int)STRLEN(buffer); |
| 9009 | get_rel_pos(wp, buffer + i + 1); |
| 9010 | o = i + vim_strsize(buffer + i + 1); |
| 9011 | #ifdef FEAT_WINDOWS |
| 9012 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 9013 | #endif |
| 9014 | ++o; |
| 9015 | #ifdef FEAT_VERTSPLIT |
| 9016 | this_ru_col = ru_col - (Columns - width); |
| 9017 | if (this_ru_col < 0) |
| 9018 | this_ru_col = 0; |
| 9019 | #endif |
| 9020 | /* Never use more than half the window/screen width, leave the other |
| 9021 | * half for the filename. */ |
| 9022 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 9023 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 9024 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 9025 | { |
| 9026 | while (this_ru_col + o < WITH_WIDTH(width)) |
| 9027 | { |
| 9028 | #ifdef FEAT_MBYTE |
| 9029 | if (has_mbyte) |
| 9030 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 9031 | else |
| 9032 | #endif |
| 9033 | buffer[i++] = fillchar; |
| 9034 | ++o; |
| 9035 | } |
| 9036 | get_rel_pos(wp, buffer + i); |
| 9037 | } |
| 9038 | /* Truncate at window boundary. */ |
| 9039 | #ifdef FEAT_MBYTE |
| 9040 | if (has_mbyte) |
| 9041 | { |
| 9042 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 9043 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9044 | { |
| 9045 | o += (*mb_ptr2cells)(buffer + i); |
| 9046 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 9047 | { |
| 9048 | buffer[i] = NUL; |
| 9049 | break; |
| 9050 | } |
| 9051 | } |
| 9052 | } |
| 9053 | else |
| 9054 | #endif |
| 9055 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 9056 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 9057 | |
| 9058 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 9059 | i = redraw_cmdline; |
| 9060 | screen_fill(row, row + 1, |
| 9061 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 9062 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 9063 | fillchar, fillchar, attr); |
| 9064 | /* don't redraw the cmdline because of showing the ruler */ |
| 9065 | redraw_cmdline = i; |
| 9066 | wp->w_ru_cursor = wp->w_cursor; |
| 9067 | wp->w_ru_virtcol = wp->w_virtcol; |
| 9068 | wp->w_ru_empty = empty_line; |
| 9069 | wp->w_ru_topline = wp->w_topline; |
| 9070 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 9071 | #ifdef FEAT_DIFF |
| 9072 | wp->w_ru_topfill = wp->w_topfill; |
| 9073 | #endif |
| 9074 | } |
| 9075 | } |
| 9076 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9077 | |
| 9078 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 9079 | /* |
| 9080 | * Return the width of the 'number' column. |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9081 | * Caller may need to check if 'number' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9082 | * Otherwise it depends on 'numberwidth' and the line count. |
| 9083 | */ |
| 9084 | int |
| 9085 | number_width(wp) |
| 9086 | win_T *wp; |
| 9087 | { |
| 9088 | int n; |
| 9089 | linenr_T lnum; |
| 9090 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9091 | lnum = wp->w_buffer->b_ml.ml_line_count; |
| 9092 | if (lnum == wp->w_nrwidth_line_count) |
| 9093 | return wp->w_nrwidth_width; |
| 9094 | wp->w_nrwidth_line_count = lnum; |
| 9095 | |
| 9096 | n = 0; |
| 9097 | do |
| 9098 | { |
| 9099 | lnum /= 10; |
| 9100 | ++n; |
| 9101 | } while (lnum > 0); |
| 9102 | |
| 9103 | /* 'numberwidth' gives the minimal width plus one */ |
| 9104 | if (n < wp->w_p_nuw - 1) |
| 9105 | n = wp->w_p_nuw - 1; |
| 9106 | |
| 9107 | wp->w_nrwidth_width = n; |
| 9108 | return n; |
| 9109 | } |
| 9110 | #endif |