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. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 30 | * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 40 | * called from other places when an immediate screen update is needed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | * |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 73 | * Commands that change highlighting and possibly cause a scroll too must call |
| 74 | * redraw_later(SOME_VALID) to update the whole window but still use scrolling |
| 75 | * to avoid redrawing everything. But the length of displayed lines must not |
| 76 | * change, use NOT_VALID then. |
| 77 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 78 | * Commands that move the window position must call redraw_later(NOT_VALID). |
| 79 | * TODO: should minimize redrawing by scrolling when possible. |
| 80 | * |
| 81 | * Commands that change everything (e.g., resizing the screen) must call |
| 82 | * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). |
| 83 | * |
| 84 | * Things that are handled indirectly: |
| 85 | * - When messages scroll the screen up, msg_scrolled will be set and |
| 86 | * update_screen() called to redraw. |
| 87 | */ |
| 88 | |
| 89 | #include "vim.h" |
| 90 | |
| 91 | /* |
| 92 | * The attributes that are actually active for writing to the screen. |
| 93 | */ |
| 94 | static int screen_attr = 0; |
| 95 | |
| 96 | /* |
| 97 | * Positioning the cursor is reduced by remembering the last position. |
| 98 | * Mostly used by windgoto() and screen_char(). |
| 99 | */ |
| 100 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 101 | |
| 102 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 103 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 104 | #endif |
| 105 | |
| 106 | #ifdef FEAT_FOLDING |
| 107 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
| 108 | #endif |
| 109 | |
| 110 | /* |
| 111 | * Buffer for one screen line (characters and attributes). |
| 112 | */ |
| 113 | static schar_T *current_ScreenLine; |
| 114 | |
| 115 | static void win_update __ARGS((win_T *wp)); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 116 | 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] | 117 | #ifdef FEAT_FOLDING |
| 118 | static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); |
| 119 | static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); |
| 120 | static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); |
| 121 | #endif |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 122 | 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] | 123 | static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
| 124 | #ifdef FEAT_RIGHTLEFT |
| 125 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); |
| 126 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 127 | #else |
| 128 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); |
| 129 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 130 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | #ifdef FEAT_VERTSPLIT |
| 132 | static void draw_vsep_win __ARGS((win_T *wp, int row)); |
| 133 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 134 | #ifdef FEAT_STL_OPT |
| 135 | static void redraw_custum_statusline __ARGS((win_T *wp)); |
| 136 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 137 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 138 | #define SEARCH_HL_PRIORITY 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 139 | static void start_search_hl __ARGS((void)); |
| 140 | static void end_search_hl __ARGS((void)); |
| 141 | static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
| 142 | static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); |
| 143 | #endif |
| 144 | static void screen_start_highlight __ARGS((int attr)); |
| 145 | static void screen_char __ARGS((unsigned off, int row, int col)); |
| 146 | #ifdef FEAT_MBYTE |
| 147 | static void screen_char_2 __ARGS((unsigned off, int row, int col)); |
| 148 | #endif |
| 149 | static void screenclear2 __ARGS((void)); |
| 150 | static void lineclear __ARGS((unsigned off, int width)); |
| 151 | static void lineinvalid __ARGS((unsigned off, int width)); |
| 152 | #ifdef FEAT_VERTSPLIT |
| 153 | static void linecopy __ARGS((int to, int from, win_T *wp)); |
| 154 | static void redraw_block __ARGS((int row, int end, win_T *wp)); |
| 155 | #endif |
| 156 | static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); |
| 157 | static void win_rest_invalid __ARGS((win_T *wp)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 158 | static void msg_pos_mode __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 159 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 160 | static void draw_tabline __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 161 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 162 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 163 | static int fillchar_status __ARGS((int *attr, int is_curwin)); |
| 164 | #endif |
| 165 | #ifdef FEAT_VERTSPLIT |
| 166 | static int fillchar_vsep __ARGS((int *attr)); |
| 167 | #endif |
| 168 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 169 | static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | #endif |
| 171 | #ifdef FEAT_CMDL_INFO |
| 172 | static void win_redr_ruler __ARGS((win_T *wp, int always)); |
| 173 | #endif |
| 174 | |
| 175 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 176 | /* Ugly global: overrule attribute used by screen_char() */ |
| 177 | static int screen_char_attr = 0; |
| 178 | #endif |
| 179 | |
| 180 | /* |
| 181 | * Redraw the current window later, with update_screen(type). |
| 182 | * Set must_redraw only if not already set to a higher value. |
| 183 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 184 | */ |
| 185 | void |
| 186 | redraw_later(type) |
| 187 | int type; |
| 188 | { |
| 189 | redraw_win_later(curwin, type); |
| 190 | } |
| 191 | |
| 192 | void |
| 193 | redraw_win_later(wp, type) |
| 194 | win_T *wp; |
| 195 | int type; |
| 196 | { |
| 197 | if (wp->w_redr_type < type) |
| 198 | { |
| 199 | wp->w_redr_type = type; |
| 200 | if (type >= NOT_VALID) |
| 201 | wp->w_lines_valid = 0; |
| 202 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 203 | must_redraw = type; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 209 | * after executing a shell command that messes up the screen. |
| 210 | */ |
| 211 | void |
| 212 | redraw_later_clear() |
| 213 | { |
| 214 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 215 | #ifdef FEAT_GUI |
| 216 | if (gui.in_use) |
| 217 | /* Use a code that will reset gui.highlight_mask in |
| 218 | * gui_stop_highlight(). */ |
| 219 | screen_attr = HL_ALL + 1; |
| 220 | else |
| 221 | #endif |
| 222 | /* Use attributes that is very unlikely to appear in text. */ |
| 223 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /* |
| 227 | * Mark all windows to be redrawn later. |
| 228 | */ |
| 229 | void |
| 230 | redraw_all_later(type) |
| 231 | int type; |
| 232 | { |
| 233 | win_T *wp; |
| 234 | |
| 235 | FOR_ALL_WINDOWS(wp) |
| 236 | { |
| 237 | redraw_win_later(wp, type); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 242 | * 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] | 243 | */ |
| 244 | void |
| 245 | redraw_curbuf_later(type) |
| 246 | int type; |
| 247 | { |
| 248 | redraw_buf_later(curbuf, type); |
| 249 | } |
| 250 | |
| 251 | void |
| 252 | redraw_buf_later(buf, type) |
| 253 | buf_T *buf; |
| 254 | int type; |
| 255 | { |
| 256 | win_T *wp; |
| 257 | |
| 258 | FOR_ALL_WINDOWS(wp) |
| 259 | { |
| 260 | if (wp->w_buffer == buf) |
| 261 | redraw_win_later(wp, type); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Changed something in the current window, at buffer line "lnum", that |
| 267 | * requires that line and possibly other lines to be redrawn. |
| 268 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 269 | * Used to remove the "$" from a change command. |
| 270 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 271 | * may become invalid and the whole window will have to be redrawn. |
| 272 | */ |
| 273 | /*ARGSUSED*/ |
| 274 | void |
| 275 | redrawWinline(lnum, invalid) |
| 276 | linenr_T lnum; |
| 277 | int invalid; /* window line height is invalid now */ |
| 278 | { |
| 279 | #ifdef FEAT_FOLDING |
| 280 | int i; |
| 281 | #endif |
| 282 | |
| 283 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 284 | curwin->w_redraw_top = lnum; |
| 285 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 286 | curwin->w_redraw_bot = lnum; |
| 287 | redraw_later(VALID); |
| 288 | |
| 289 | #ifdef FEAT_FOLDING |
| 290 | if (invalid) |
| 291 | { |
| 292 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 293 | i = find_wl_entry(curwin, lnum); |
| 294 | if (i >= 0) |
| 295 | curwin->w_lines[i].wl_valid = FALSE; |
| 296 | } |
| 297 | #endif |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * update all windows that are editing the current buffer |
| 302 | */ |
| 303 | void |
| 304 | update_curbuf(type) |
| 305 | int type; |
| 306 | { |
| 307 | redraw_curbuf_later(type); |
| 308 | update_screen(type); |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | * update_screen() |
| 313 | * |
| 314 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 315 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 316 | */ |
| 317 | void |
| 318 | update_screen(type) |
| 319 | int type; |
| 320 | { |
| 321 | win_T *wp; |
| 322 | static int did_intro = FALSE; |
| 323 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 324 | int did_one; |
| 325 | #endif |
| 326 | |
| 327 | if (!screen_valid(TRUE)) |
| 328 | return; |
| 329 | |
| 330 | if (must_redraw) |
| 331 | { |
| 332 | if (type < must_redraw) /* use maximal type */ |
| 333 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 334 | |
| 335 | /* must_redraw is reset here, so that when we run into some weird |
| 336 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 337 | * scrolling), or update_topline() in win_update() will cause a |
| 338 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 339 | must_redraw = 0; |
| 340 | } |
| 341 | |
| 342 | /* Need to update w_lines[]. */ |
| 343 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 344 | type = NOT_VALID; |
| 345 | |
| 346 | if (!redrawing()) |
| 347 | { |
| 348 | redraw_later(type); /* remember type for next time */ |
| 349 | must_redraw = type; |
| 350 | if (type > INVERTED_ALL) |
| 351 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | updating_screen = TRUE; |
| 356 | #ifdef FEAT_SYN_HL |
| 357 | ++display_tick; /* let syntax code know we're in a next round of |
| 358 | * display updating */ |
| 359 | #endif |
| 360 | |
| 361 | /* |
| 362 | * if the screen was scrolled up when displaying a message, scroll it down |
| 363 | */ |
| 364 | if (msg_scrolled) |
| 365 | { |
| 366 | clear_cmdline = TRUE; |
| 367 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 368 | type = CLEAR; |
| 369 | else if (type != CLEAR) |
| 370 | { |
| 371 | check_for_delay(FALSE); |
| 372 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 373 | type = CLEAR; |
| 374 | FOR_ALL_WINDOWS(wp) |
| 375 | { |
| 376 | if (W_WINROW(wp) < msg_scrolled) |
| 377 | { |
| 378 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 379 | && wp->w_redr_type < REDRAW_TOP |
| 380 | && wp->w_lines_valid > 0 |
| 381 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 382 | { |
| 383 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 384 | wp->w_redr_type = REDRAW_TOP; |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | wp->w_redr_type = NOT_VALID; |
| 389 | #ifdef FEAT_WINDOWS |
| 390 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 391 | <= msg_scrolled) |
| 392 | wp->w_redr_status = TRUE; |
| 393 | #endif |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 398 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 399 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 400 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 401 | } |
| 402 | msg_scrolled = 0; |
| 403 | need_wait_return = FALSE; |
| 404 | } |
| 405 | |
| 406 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 407 | compute_cmdrow(); |
| 408 | |
| 409 | /* Check for changed highlighting */ |
| 410 | if (need_highlight_changed) |
| 411 | highlight_changed(); |
| 412 | |
| 413 | if (type == CLEAR) /* first clear screen */ |
| 414 | { |
| 415 | screenclear(); /* will reset clear_cmdline */ |
| 416 | type = NOT_VALID; |
| 417 | } |
| 418 | |
| 419 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 420 | check_for_delay(FALSE); |
| 421 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 422 | #ifdef FEAT_LINEBREAK |
| 423 | /* Force redraw when width of 'number' column changes. */ |
| 424 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 425 | && curwin->w_nrwidth != (curwin->w_p_nu ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 426 | curwin->w_redr_type = NOT_VALID; |
| 427 | #endif |
| 428 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 429 | /* |
| 430 | * Only start redrawing if there is really something to do. |
| 431 | */ |
| 432 | if (type == INVERTED) |
| 433 | update_curswant(); |
| 434 | if (curwin->w_redr_type < type |
| 435 | && !((type == VALID |
| 436 | && curwin->w_lines[0].wl_valid |
| 437 | #ifdef FEAT_DIFF |
| 438 | && curwin->w_topfill == curwin->w_old_topfill |
| 439 | && curwin->w_botfill == curwin->w_old_botfill |
| 440 | #endif |
| 441 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
| 442 | #ifdef FEAT_VISUAL |
| 443 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 444 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 453 | #ifdef FEAT_WINDOWS |
| 454 | /* Redraw the tab pages line if needed. */ |
| 455 | if (redraw_tabline || type >= NOT_VALID) |
| 456 | draw_tabline(); |
| 457 | #endif |
| 458 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 459 | #ifdef FEAT_SYN_HL |
| 460 | /* |
| 461 | * Correct stored syntax highlighting info for changes in each displayed |
| 462 | * buffer. Each buffer must only be done once. |
| 463 | */ |
| 464 | FOR_ALL_WINDOWS(wp) |
| 465 | { |
| 466 | if (wp->w_buffer->b_mod_set) |
| 467 | { |
| 468 | # ifdef FEAT_WINDOWS |
| 469 | win_T *wwp; |
| 470 | |
| 471 | /* Check if we already did this buffer. */ |
| 472 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 473 | if (wwp->w_buffer == wp->w_buffer) |
| 474 | break; |
| 475 | # endif |
| 476 | if ( |
| 477 | # ifdef FEAT_WINDOWS |
| 478 | wwp == wp && |
| 479 | # endif |
| 480 | syntax_present(wp->w_buffer)) |
| 481 | syn_stack_apply_changes(wp->w_buffer); |
| 482 | } |
| 483 | } |
| 484 | #endif |
| 485 | |
| 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 |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 739 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 740 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 741 | * INVERTED redraw the changed part of the Visual area |
| 742 | * INVERTED_ALL redraw the whole Visual area |
| 743 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 744 | * 2. update lines at the top when scrolled down |
| 745 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 746 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 747 | * b_mod_top and b_mod_bot. |
| 748 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 749 | * wp->w_redraw_top and wp->w_redr_bot. |
| 750 | * - continue redrawing when syntax status is invalid. |
| 751 | * 4. if scrolled up, update lines at the bottom. |
| 752 | * This results in three areas that may need updating: |
| 753 | * top: from first row to top_end (when scrolled down) |
| 754 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 755 | * bot: from bot_start to last row (when scrolled up) |
| 756 | */ |
| 757 | static void |
| 758 | win_update(wp) |
| 759 | win_T *wp; |
| 760 | { |
| 761 | buf_T *buf = wp->w_buffer; |
| 762 | int type; |
| 763 | int top_end = 0; /* Below last row of the top area that needs |
| 764 | updating. 0 when no top area updating. */ |
| 765 | int mid_start = 999;/* first row of the mid area that needs |
| 766 | updating. 999 when no mid area updating. */ |
| 767 | int mid_end = 0; /* Below last row of the mid area that needs |
| 768 | updating. 0 when no mid area updating. */ |
| 769 | int bot_start = 999;/* first row of the bot area that needs |
| 770 | updating. 999 when no bot area updating */ |
| 771 | #ifdef FEAT_VISUAL |
| 772 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 773 | w_topline got smaller a bit */ |
| 774 | #endif |
| 775 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 776 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 777 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 778 | #endif |
| 779 | |
| 780 | int row; /* current window row to display */ |
| 781 | linenr_T lnum; /* current buffer lnum to display */ |
| 782 | int idx; /* current index in w_lines[] */ |
| 783 | int srow; /* starting row of the current line */ |
| 784 | |
| 785 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 786 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 787 | int i; |
| 788 | long j; |
| 789 | static int recursive = FALSE; /* being called recursively */ |
| 790 | int old_botline = wp->w_botline; |
| 791 | #ifdef FEAT_FOLDING |
| 792 | long fold_count; |
| 793 | #endif |
| 794 | #ifdef FEAT_SYN_HL |
| 795 | /* remember what happened to the previous line, to know if |
| 796 | * check_visual_highlight() can be used */ |
| 797 | #define DID_NONE 1 /* didn't update a line */ |
| 798 | #define DID_LINE 2 /* updated a normal line */ |
| 799 | #define DID_FOLD 3 /* updated a folded line */ |
| 800 | int did_update = DID_NONE; |
| 801 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 802 | #endif |
| 803 | linenr_T mod_top = 0; |
| 804 | linenr_T mod_bot = 0; |
| 805 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 806 | int save_got_int; |
| 807 | #endif |
| 808 | |
| 809 | type = wp->w_redr_type; |
| 810 | |
| 811 | if (type == NOT_VALID) |
| 812 | { |
| 813 | #ifdef FEAT_WINDOWS |
| 814 | wp->w_redr_status = TRUE; |
| 815 | #endif |
| 816 | wp->w_lines_valid = 0; |
| 817 | } |
| 818 | |
| 819 | /* Window is zero-height: nothing to draw. */ |
| 820 | if (wp->w_height == 0) |
| 821 | { |
| 822 | wp->w_redr_type = 0; |
| 823 | return; |
| 824 | } |
| 825 | |
| 826 | #ifdef FEAT_VERTSPLIT |
| 827 | /* Window is zero-width: Only need to draw the separator. */ |
| 828 | if (wp->w_width == 0) |
| 829 | { |
| 830 | /* draw the vertical separator right of this window */ |
| 831 | draw_vsep_win(wp, 0); |
| 832 | wp->w_redr_type = 0; |
| 833 | return; |
| 834 | } |
| 835 | #endif |
| 836 | |
| 837 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 838 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 839 | * match */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 840 | cur = wp->w_match_head; |
| 841 | while (cur != NULL) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 842 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 843 | cur->hl.rm = cur->match; |
| 844 | if (cur->hlg_id == 0) |
| 845 | cur->hl.attr = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 846 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 847 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 848 | cur->hl.buf = buf; |
| 849 | cur->hl.lnum = 0; |
| 850 | cur->hl.first_lnum = 0; |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 851 | # ifdef FEAT_RELTIME |
| 852 | /* Set the time limit to 'redrawtime'. */ |
| 853 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 854 | # endif |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 855 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 856 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 857 | search_hl.buf = buf; |
| 858 | search_hl.lnum = 0; |
| 859 | search_hl.first_lnum = 0; |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 860 | /* time limit is set at the toplevel, for all windows */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 861 | #endif |
| 862 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 863 | #ifdef FEAT_LINEBREAK |
| 864 | /* Force redraw when width of 'number' column changes. */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 865 | i = wp->w_p_nu ? number_width(wp) : 0; |
| 866 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 867 | { |
| 868 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 869 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 870 | } |
| 871 | else |
| 872 | #endif |
| 873 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 874 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 875 | { |
| 876 | /* |
| 877 | * When there are both inserted/deleted lines and specific lines to be |
| 878 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 879 | * everything (only happens when redrawing is off for while). |
| 880 | */ |
| 881 | type = NOT_VALID; |
| 882 | } |
| 883 | else |
| 884 | { |
| 885 | /* |
| 886 | * Set mod_top to the first line that needs displaying because of |
| 887 | * changes. Set mod_bot to the first line after the changes. |
| 888 | */ |
| 889 | mod_top = wp->w_redraw_top; |
| 890 | if (wp->w_redraw_bot != 0) |
| 891 | mod_bot = wp->w_redraw_bot + 1; |
| 892 | else |
| 893 | mod_bot = 0; |
| 894 | wp->w_redraw_top = 0; /* reset for next time */ |
| 895 | wp->w_redraw_bot = 0; |
| 896 | if (buf->b_mod_set) |
| 897 | { |
| 898 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 899 | { |
| 900 | mod_top = buf->b_mod_top; |
| 901 | #ifdef FEAT_SYN_HL |
| 902 | /* Need to redraw lines above the change that may be included |
| 903 | * in a pattern match. */ |
| 904 | if (syntax_present(buf)) |
| 905 | { |
| 906 | mod_top -= buf->b_syn_sync_linebreaks; |
| 907 | if (mod_top < 1) |
| 908 | mod_top = 1; |
| 909 | } |
| 910 | #endif |
| 911 | } |
| 912 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 913 | mod_bot = buf->b_mod_bot; |
| 914 | |
| 915 | #ifdef FEAT_SEARCH_EXTRA |
| 916 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 917 | * change in one line may make the Search highlighting in a |
| 918 | * previous line invalid. Simple solution: redraw all visible |
| 919 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 920 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 921 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 922 | if (search_hl.rm.regprog != NULL |
| 923 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 924 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 925 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 926 | { |
| 927 | cur = wp->w_match_head; |
| 928 | while (cur != NULL) |
| 929 | { |
| 930 | if (cur->match.regprog != NULL |
| 931 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 932 | { |
| 933 | top_to_mod = TRUE; |
| 934 | break; |
| 935 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 936 | cur = cur->next; |
| 937 | } |
| 938 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 939 | #endif |
| 940 | } |
| 941 | #ifdef FEAT_FOLDING |
| 942 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 943 | { |
| 944 | linenr_T lnumt, lnumb; |
| 945 | |
| 946 | /* |
| 947 | * A change in a line can cause lines above it to become folded or |
| 948 | * unfolded. Find the top most buffer line that may be affected. |
| 949 | * If the line was previously folded and displayed, get the first |
| 950 | * line of that fold. If the line is folded now, get the first |
| 951 | * folded line. Use the minimum of these two. |
| 952 | */ |
| 953 | |
| 954 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 955 | * the line below it. If there is no valid entry, use w_topline. |
| 956 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 957 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 958 | lnumt = wp->w_topline; |
| 959 | lnumb = MAXLNUM; |
| 960 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 961 | if (wp->w_lines[i].wl_valid) |
| 962 | { |
| 963 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 964 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 965 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 966 | { |
| 967 | lnumb = wp->w_lines[i].wl_lnum; |
| 968 | /* When there is a fold column it might need updating |
| 969 | * in the next line ("J" just above an open fold). */ |
| 970 | if (wp->w_p_fdc > 0) |
| 971 | ++lnumb; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 976 | if (mod_top > lnumt) |
| 977 | mod_top = lnumt; |
| 978 | |
| 979 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 980 | --mod_bot; |
| 981 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 982 | ++mod_bot; |
| 983 | if (mod_bot < lnumb) |
| 984 | mod_bot = lnumb; |
| 985 | } |
| 986 | #endif |
| 987 | |
| 988 | /* When a change starts above w_topline and the end is below |
| 989 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 990 | * If the end of the change is above w_topline: do like no change was |
| 991 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 992 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 993 | { |
| 994 | if (mod_bot > wp->w_topline) |
| 995 | mod_top = wp->w_topline; |
| 996 | #ifdef FEAT_SYN_HL |
| 997 | else if (syntax_present(buf)) |
| 998 | top_end = 1; |
| 999 | #endif |
| 1000 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1001 | |
| 1002 | /* When line numbers are displayed need to redraw all lines below |
| 1003 | * inserted/deleted lines. */ |
| 1004 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1005 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | * When only displaying the lines at the top, set top_end. Used when |
| 1010 | * window has scrolled down for msg_scrolled. |
| 1011 | */ |
| 1012 | if (type == REDRAW_TOP) |
| 1013 | { |
| 1014 | j = 0; |
| 1015 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1016 | { |
| 1017 | j += wp->w_lines[i].wl_size; |
| 1018 | if (j >= wp->w_upd_rows) |
| 1019 | { |
| 1020 | top_end = j; |
| 1021 | break; |
| 1022 | } |
| 1023 | } |
| 1024 | if (top_end == 0) |
| 1025 | /* not found (cannot happen?): redraw everything */ |
| 1026 | type = NOT_VALID; |
| 1027 | else |
| 1028 | /* top area defined, the rest is VALID */ |
| 1029 | type = VALID; |
| 1030 | } |
| 1031 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1032 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1033 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1034 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1035 | * called. */ |
| 1036 | if (screen_cleared) |
| 1037 | screen_cleared = MAYBE; |
| 1038 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1039 | /* |
| 1040 | * If there are no changes on the screen that require a complete redraw, |
| 1041 | * handle three cases: |
| 1042 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1043 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1044 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1045 | * w_lines[] that needs updating. |
| 1046 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1047 | if ((type == VALID || type == SOME_VALID |
| 1048 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1049 | #ifdef FEAT_DIFF |
| 1050 | && !wp->w_botfill && !wp->w_old_botfill |
| 1051 | #endif |
| 1052 | ) |
| 1053 | { |
| 1054 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1055 | { |
| 1056 | /* |
| 1057 | * w_topline is the first changed line, the scrolling will be done |
| 1058 | * further down. |
| 1059 | */ |
| 1060 | } |
| 1061 | else if (wp->w_lines[0].wl_valid |
| 1062 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1063 | #ifdef FEAT_DIFF |
| 1064 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1065 | && wp->w_topfill > wp->w_old_topfill) |
| 1066 | #endif |
| 1067 | )) |
| 1068 | { |
| 1069 | /* |
| 1070 | * New topline is above old topline: May scroll down. |
| 1071 | */ |
| 1072 | #ifdef FEAT_FOLDING |
| 1073 | if (hasAnyFolding(wp)) |
| 1074 | { |
| 1075 | linenr_T ln; |
| 1076 | |
| 1077 | /* count the number of lines we are off, counting a sequence |
| 1078 | * of folded lines as one */ |
| 1079 | j = 0; |
| 1080 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1081 | { |
| 1082 | ++j; |
| 1083 | if (j >= wp->w_height - 2) |
| 1084 | break; |
| 1085 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1086 | } |
| 1087 | } |
| 1088 | else |
| 1089 | #endif |
| 1090 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1091 | if (j < wp->w_height - 2) /* not too far off */ |
| 1092 | { |
| 1093 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1094 | #ifdef FEAT_DIFF |
| 1095 | /* insert extra lines for previously invisible filler lines */ |
| 1096 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1097 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1098 | - wp->w_old_topfill; |
| 1099 | #endif |
| 1100 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1101 | { |
| 1102 | /* |
| 1103 | * Try to insert the correct number of lines. |
| 1104 | * If not the last window, delete the lines at the bottom. |
| 1105 | * win_ins_lines may fail when the terminal can't do it. |
| 1106 | */ |
| 1107 | if (i > 0) |
| 1108 | check_for_delay(FALSE); |
| 1109 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1110 | { |
| 1111 | if (wp->w_lines_valid != 0) |
| 1112 | { |
| 1113 | /* Need to update rows that are new, stop at the |
| 1114 | * first one that scrolled down. */ |
| 1115 | top_end = i; |
| 1116 | #ifdef FEAT_VISUAL |
| 1117 | scrolled_down = TRUE; |
| 1118 | #endif |
| 1119 | |
| 1120 | /* Move the entries that were scrolled, disable |
| 1121 | * the entries for the lines to be redrawn. */ |
| 1122 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1123 | wp->w_lines_valid = wp->w_height; |
| 1124 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1125 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1126 | while (idx >= 0) |
| 1127 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1128 | } |
| 1129 | } |
| 1130 | else |
| 1131 | mid_start = 0; /* redraw all lines */ |
| 1132 | } |
| 1133 | else |
| 1134 | mid_start = 0; /* redraw all lines */ |
| 1135 | } |
| 1136 | else |
| 1137 | mid_start = 0; /* redraw all lines */ |
| 1138 | } |
| 1139 | else |
| 1140 | { |
| 1141 | /* |
| 1142 | * New topline is at or below old topline: May scroll up. |
| 1143 | * When topline didn't change, find first entry in w_lines[] that |
| 1144 | * needs updating. |
| 1145 | */ |
| 1146 | |
| 1147 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1148 | j = -1; |
| 1149 | row = 0; |
| 1150 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1151 | { |
| 1152 | if (wp->w_lines[i].wl_valid |
| 1153 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1154 | { |
| 1155 | j = i; |
| 1156 | break; |
| 1157 | } |
| 1158 | row += wp->w_lines[i].wl_size; |
| 1159 | } |
| 1160 | if (j == -1) |
| 1161 | { |
| 1162 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1163 | * lines */ |
| 1164 | mid_start = 0; |
| 1165 | } |
| 1166 | else |
| 1167 | { |
| 1168 | /* |
| 1169 | * Try to delete the correct number of lines. |
| 1170 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1171 | */ |
| 1172 | #ifdef FEAT_DIFF |
| 1173 | /* If the topline didn't change, delete old filler lines, |
| 1174 | * otherwise delete filler lines of the new topline... */ |
| 1175 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1176 | row += wp->w_old_topfill; |
| 1177 | else |
| 1178 | row += diff_check_fill(wp, wp->w_topline); |
| 1179 | /* ... but don't delete new filler lines. */ |
| 1180 | row -= wp->w_topfill; |
| 1181 | #endif |
| 1182 | if (row > 0) |
| 1183 | { |
| 1184 | check_for_delay(FALSE); |
| 1185 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1186 | bot_start = wp->w_height - row; |
| 1187 | else |
| 1188 | mid_start = 0; /* redraw all lines */ |
| 1189 | } |
| 1190 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1191 | { |
| 1192 | /* |
| 1193 | * Skip the lines (below the deleted lines) that are still |
| 1194 | * valid and don't need redrawing. Copy their info |
| 1195 | * upwards, to compensate for the deleted lines. Set |
| 1196 | * bot_start to the first row that needs redrawing. |
| 1197 | */ |
| 1198 | bot_start = 0; |
| 1199 | idx = 0; |
| 1200 | for (;;) |
| 1201 | { |
| 1202 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1203 | /* stop at line that didn't fit, unless it is still |
| 1204 | * valid (no lines deleted) */ |
| 1205 | if (row > 0 && bot_start + row |
| 1206 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1207 | { |
| 1208 | wp->w_lines_valid = idx + 1; |
| 1209 | break; |
| 1210 | } |
| 1211 | bot_start += wp->w_lines[idx++].wl_size; |
| 1212 | |
| 1213 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1214 | if (++j >= wp->w_lines_valid) |
| 1215 | { |
| 1216 | wp->w_lines_valid = idx; |
| 1217 | break; |
| 1218 | } |
| 1219 | } |
| 1220 | #ifdef FEAT_DIFF |
| 1221 | /* Correct the first entry for filler lines at the top |
| 1222 | * when it won't get updated below. */ |
| 1223 | if (wp->w_p_diff && bot_start > 0) |
| 1224 | wp->w_lines[0].wl_size = |
| 1225 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1226 | + wp->w_topfill; |
| 1227 | #endif |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | /* When starting redraw in the first line, redraw all lines. When |
| 1233 | * there is only one window it's probably faster to clear the screen |
| 1234 | * first. */ |
| 1235 | if (mid_start == 0) |
| 1236 | { |
| 1237 | mid_end = wp->w_height; |
| 1238 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1239 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1240 | /* Clear the screen when it was not done by win_del_lines() or |
| 1241 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1242 | * then. */ |
| 1243 | if (screen_cleared != TRUE) |
| 1244 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1245 | #ifdef FEAT_WINDOWS |
| 1246 | /* The screen was cleared, redraw the tab pages line. */ |
| 1247 | if (redraw_tabline) |
| 1248 | draw_tabline(); |
| 1249 | #endif |
| 1250 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1251 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1252 | |
| 1253 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1254 | * cleared (only happens for the first window) or when screenclear() |
| 1255 | * was called directly above, "must_redraw" will have been set to |
| 1256 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1257 | if (screen_cleared == TRUE) |
| 1258 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1259 | } |
| 1260 | else |
| 1261 | { |
| 1262 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1263 | mid_start = 0; |
| 1264 | mid_end = wp->w_height; |
| 1265 | } |
| 1266 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1267 | if (type == SOME_VALID) |
| 1268 | { |
| 1269 | /* SOME_VALID: redraw all lines. */ |
| 1270 | mid_start = 0; |
| 1271 | mid_end = wp->w_height; |
| 1272 | type = NOT_VALID; |
| 1273 | } |
| 1274 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | #ifdef FEAT_VISUAL |
| 1276 | /* check if we are updating or removing the inverted part */ |
| 1277 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1278 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1279 | { |
| 1280 | linenr_T from, to; |
| 1281 | |
| 1282 | if (VIsual_active) |
| 1283 | { |
| 1284 | if (VIsual_active |
| 1285 | && (VIsual_mode != wp->w_old_visual_mode |
| 1286 | || type == INVERTED_ALL)) |
| 1287 | { |
| 1288 | /* |
| 1289 | * If the type of Visual selection changed, redraw the whole |
| 1290 | * selection. Also when the ownership of the X selection is |
| 1291 | * gained or lost. |
| 1292 | */ |
| 1293 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1294 | { |
| 1295 | from = curwin->w_cursor.lnum; |
| 1296 | to = VIsual.lnum; |
| 1297 | } |
| 1298 | else |
| 1299 | { |
| 1300 | from = VIsual.lnum; |
| 1301 | to = curwin->w_cursor.lnum; |
| 1302 | } |
| 1303 | /* redraw more when the cursor moved as well */ |
| 1304 | if (wp->w_old_cursor_lnum < from) |
| 1305 | from = wp->w_old_cursor_lnum; |
| 1306 | if (wp->w_old_cursor_lnum > to) |
| 1307 | to = wp->w_old_cursor_lnum; |
| 1308 | if (wp->w_old_visual_lnum < from) |
| 1309 | from = wp->w_old_visual_lnum; |
| 1310 | if (wp->w_old_visual_lnum > to) |
| 1311 | to = wp->w_old_visual_lnum; |
| 1312 | } |
| 1313 | else |
| 1314 | { |
| 1315 | /* |
| 1316 | * Find the line numbers that need to be updated: The lines |
| 1317 | * between the old cursor position and the current cursor |
| 1318 | * position. Also check if the Visual position changed. |
| 1319 | */ |
| 1320 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1321 | { |
| 1322 | from = curwin->w_cursor.lnum; |
| 1323 | to = wp->w_old_cursor_lnum; |
| 1324 | } |
| 1325 | else |
| 1326 | { |
| 1327 | from = wp->w_old_cursor_lnum; |
| 1328 | to = curwin->w_cursor.lnum; |
| 1329 | if (from == 0) /* Visual mode just started */ |
| 1330 | from = to; |
| 1331 | } |
| 1332 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1333 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1334 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1335 | { |
| 1336 | if (wp->w_old_visual_lnum < from |
| 1337 | && wp->w_old_visual_lnum != 0) |
| 1338 | from = wp->w_old_visual_lnum; |
| 1339 | if (wp->w_old_visual_lnum > to) |
| 1340 | to = wp->w_old_visual_lnum; |
| 1341 | if (VIsual.lnum < from) |
| 1342 | from = VIsual.lnum; |
| 1343 | if (VIsual.lnum > to) |
| 1344 | to = VIsual.lnum; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | /* |
| 1349 | * If in block mode and changed column or curwin->w_curswant: |
| 1350 | * update all lines. |
| 1351 | * First compute the actual start and end column. |
| 1352 | */ |
| 1353 | if (VIsual_mode == Ctrl_V) |
| 1354 | { |
| 1355 | colnr_T fromc, toc; |
| 1356 | |
| 1357 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
| 1358 | ++toc; |
| 1359 | if (curwin->w_curswant == MAXCOL) |
| 1360 | toc = MAXCOL; |
| 1361 | |
| 1362 | if (fromc != wp->w_old_cursor_fcol |
| 1363 | || toc != wp->w_old_cursor_lcol) |
| 1364 | { |
| 1365 | if (from > VIsual.lnum) |
| 1366 | from = VIsual.lnum; |
| 1367 | if (to < VIsual.lnum) |
| 1368 | to = VIsual.lnum; |
| 1369 | } |
| 1370 | wp->w_old_cursor_fcol = fromc; |
| 1371 | wp->w_old_cursor_lcol = toc; |
| 1372 | } |
| 1373 | } |
| 1374 | else |
| 1375 | { |
| 1376 | /* Use the line numbers of the old Visual area. */ |
| 1377 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1378 | { |
| 1379 | from = wp->w_old_cursor_lnum; |
| 1380 | to = wp->w_old_visual_lnum; |
| 1381 | } |
| 1382 | else |
| 1383 | { |
| 1384 | from = wp->w_old_visual_lnum; |
| 1385 | to = wp->w_old_cursor_lnum; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /* |
| 1390 | * There is no need to update lines above the top of the window. |
| 1391 | */ |
| 1392 | if (from < wp->w_topline) |
| 1393 | from = wp->w_topline; |
| 1394 | |
| 1395 | /* |
| 1396 | * If we know the value of w_botline, use it to restrict the update to |
| 1397 | * the lines that are visible in the window. |
| 1398 | */ |
| 1399 | if (wp->w_valid & VALID_BOTLINE) |
| 1400 | { |
| 1401 | if (from >= wp->w_botline) |
| 1402 | from = wp->w_botline - 1; |
| 1403 | if (to >= wp->w_botline) |
| 1404 | to = wp->w_botline - 1; |
| 1405 | } |
| 1406 | |
| 1407 | /* |
| 1408 | * Find the minimal part to be updated. |
| 1409 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1410 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1411 | * top_end; need to redraw from top_end to the "to" line. |
| 1412 | * A middle mouse click with a Visual selection may change the text |
| 1413 | * above the Visual area and reset wl_valid, do count these for |
| 1414 | * mid_end (in srow). |
| 1415 | */ |
| 1416 | if (mid_start > 0) |
| 1417 | { |
| 1418 | lnum = wp->w_topline; |
| 1419 | idx = 0; |
| 1420 | srow = 0; |
| 1421 | if (scrolled_down) |
| 1422 | mid_start = top_end; |
| 1423 | else |
| 1424 | mid_start = 0; |
| 1425 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1426 | { |
| 1427 | if (wp->w_lines[idx].wl_valid) |
| 1428 | mid_start += wp->w_lines[idx].wl_size; |
| 1429 | else if (!scrolled_down) |
| 1430 | srow += wp->w_lines[idx].wl_size; |
| 1431 | ++idx; |
| 1432 | # ifdef FEAT_FOLDING |
| 1433 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1434 | lnum = wp->w_lines[idx].wl_lnum; |
| 1435 | else |
| 1436 | # endif |
| 1437 | ++lnum; |
| 1438 | } |
| 1439 | srow += mid_start; |
| 1440 | mid_end = wp->w_height; |
| 1441 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1442 | { |
| 1443 | if (wp->w_lines[idx].wl_valid |
| 1444 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1445 | { |
| 1446 | /* Only update until first row of this line */ |
| 1447 | mid_end = srow; |
| 1448 | break; |
| 1449 | } |
| 1450 | srow += wp->w_lines[idx].wl_size; |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | if (VIsual_active && buf == curwin->w_buffer) |
| 1456 | { |
| 1457 | wp->w_old_visual_mode = VIsual_mode; |
| 1458 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1459 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1460 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1461 | wp->w_old_curswant = curwin->w_curswant; |
| 1462 | } |
| 1463 | else |
| 1464 | { |
| 1465 | wp->w_old_visual_mode = 0; |
| 1466 | wp->w_old_cursor_lnum = 0; |
| 1467 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1468 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1469 | } |
| 1470 | #endif /* FEAT_VISUAL */ |
| 1471 | |
| 1472 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1473 | /* reset got_int, otherwise regexp won't work */ |
| 1474 | save_got_int = got_int; |
| 1475 | got_int = 0; |
| 1476 | #endif |
| 1477 | #ifdef FEAT_FOLDING |
| 1478 | win_foldinfo.fi_level = 0; |
| 1479 | #endif |
| 1480 | |
| 1481 | /* |
| 1482 | * Update all the window rows. |
| 1483 | */ |
| 1484 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1485 | row = 0; |
| 1486 | srow = 0; |
| 1487 | lnum = wp->w_topline; /* first line shown in window */ |
| 1488 | for (;;) |
| 1489 | { |
| 1490 | /* stop updating when reached the end of the window (check for _past_ |
| 1491 | * the end of the window is at the end of the loop) */ |
| 1492 | if (row == wp->w_height) |
| 1493 | { |
| 1494 | didline = TRUE; |
| 1495 | break; |
| 1496 | } |
| 1497 | |
| 1498 | /* stop updating when hit the end of the file */ |
| 1499 | if (lnum > buf->b_ml.ml_line_count) |
| 1500 | { |
| 1501 | eof = TRUE; |
| 1502 | break; |
| 1503 | } |
| 1504 | |
| 1505 | /* Remember the starting row of the line that is going to be dealt |
| 1506 | * with. It is used further down when the line doesn't fit. */ |
| 1507 | srow = row; |
| 1508 | |
| 1509 | /* |
| 1510 | * Update a line when it is in an area that needs updating, when it |
| 1511 | * has changes or w_lines[idx] is invalid. |
| 1512 | * bot_start may be halfway a wrapped line after using |
| 1513 | * win_del_lines(), check if the current line includes it. |
| 1514 | * When syntax folding is being used, the saved syntax states will |
| 1515 | * already have been updated, we can't see where the syntax state is |
| 1516 | * the same again, just update until the end of the window. |
| 1517 | */ |
| 1518 | if (row < top_end |
| 1519 | || (row >= mid_start && row < mid_end) |
| 1520 | #ifdef FEAT_SEARCH_EXTRA |
| 1521 | || top_to_mod |
| 1522 | #endif |
| 1523 | || idx >= wp->w_lines_valid |
| 1524 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1525 | || (mod_top != 0 |
| 1526 | && (lnum == mod_top |
| 1527 | || (lnum >= mod_top |
| 1528 | && (lnum < mod_bot |
| 1529 | #ifdef FEAT_SYN_HL |
| 1530 | || did_update == DID_FOLD |
| 1531 | || (did_update == DID_LINE |
| 1532 | && syntax_present(buf) |
| 1533 | && ( |
| 1534 | # ifdef FEAT_FOLDING |
| 1535 | (foldmethodIsSyntax(wp) |
| 1536 | && hasAnyFolding(wp)) || |
| 1537 | # endif |
| 1538 | syntax_check_changed(lnum))) |
| 1539 | #endif |
| 1540 | ))))) |
| 1541 | { |
| 1542 | #ifdef FEAT_SEARCH_EXTRA |
| 1543 | if (lnum == mod_top) |
| 1544 | top_to_mod = FALSE; |
| 1545 | #endif |
| 1546 | |
| 1547 | /* |
| 1548 | * When at start of changed lines: May scroll following lines |
| 1549 | * up or down to minimize redrawing. |
| 1550 | * Don't do this when the change continues until the end. |
| 1551 | * Don't scroll when dollar_vcol is non-zero, keep the "$". |
| 1552 | */ |
| 1553 | if (lnum == mod_top |
| 1554 | && mod_bot != MAXLNUM |
| 1555 | && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) |
| 1556 | { |
| 1557 | int old_rows = 0; |
| 1558 | int new_rows = 0; |
| 1559 | int xtra_rows; |
| 1560 | linenr_T l; |
| 1561 | |
| 1562 | /* Count the old number of window rows, using w_lines[], which |
| 1563 | * should still contain the sizes for the lines as they are |
| 1564 | * currently displayed. */ |
| 1565 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1566 | { |
| 1567 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1568 | * lines are part of the changed area. */ |
| 1569 | if (wp->w_lines[i].wl_valid |
| 1570 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1571 | break; |
| 1572 | old_rows += wp->w_lines[i].wl_size; |
| 1573 | #ifdef FEAT_FOLDING |
| 1574 | if (wp->w_lines[i].wl_valid |
| 1575 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1576 | { |
| 1577 | /* Must have found the last valid entry above mod_bot. |
| 1578 | * Add following invalid entries. */ |
| 1579 | ++i; |
| 1580 | while (i < wp->w_lines_valid |
| 1581 | && !wp->w_lines[i].wl_valid) |
| 1582 | old_rows += wp->w_lines[i++].wl_size; |
| 1583 | break; |
| 1584 | } |
| 1585 | #endif |
| 1586 | } |
| 1587 | |
| 1588 | if (i >= wp->w_lines_valid) |
| 1589 | { |
| 1590 | /* We can't find a valid line below the changed lines, |
| 1591 | * need to redraw until the end of the window. |
| 1592 | * Inserting/deleting lines has no use. */ |
| 1593 | bot_start = 0; |
| 1594 | } |
| 1595 | else |
| 1596 | { |
| 1597 | /* Able to count old number of rows: Count new window |
| 1598 | * rows, and may insert/delete lines */ |
| 1599 | j = idx; |
| 1600 | for (l = lnum; l < mod_bot; ++l) |
| 1601 | { |
| 1602 | #ifdef FEAT_FOLDING |
| 1603 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1604 | ++new_rows; |
| 1605 | else |
| 1606 | #endif |
| 1607 | #ifdef FEAT_DIFF |
| 1608 | if (l == wp->w_topline) |
| 1609 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1610 | + wp->w_topfill; |
| 1611 | else |
| 1612 | #endif |
| 1613 | new_rows += plines_win(wp, l, TRUE); |
| 1614 | ++j; |
| 1615 | if (new_rows > wp->w_height - row - 2) |
| 1616 | { |
| 1617 | /* it's getting too much, must redraw the rest */ |
| 1618 | new_rows = 9999; |
| 1619 | break; |
| 1620 | } |
| 1621 | } |
| 1622 | xtra_rows = new_rows - old_rows; |
| 1623 | if (xtra_rows < 0) |
| 1624 | { |
| 1625 | /* May scroll text up. If there is not enough |
| 1626 | * remaining text or scrolling fails, must redraw the |
| 1627 | * rest. If scrolling works, must redraw the text |
| 1628 | * below the scrolled text. */ |
| 1629 | if (row - xtra_rows >= wp->w_height - 2) |
| 1630 | mod_bot = MAXLNUM; |
| 1631 | else |
| 1632 | { |
| 1633 | check_for_delay(FALSE); |
| 1634 | if (win_del_lines(wp, row, |
| 1635 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1636 | mod_bot = MAXLNUM; |
| 1637 | else |
| 1638 | bot_start = wp->w_height + xtra_rows; |
| 1639 | } |
| 1640 | } |
| 1641 | else if (xtra_rows > 0) |
| 1642 | { |
| 1643 | /* May scroll text down. If there is not enough |
| 1644 | * remaining text of scrolling fails, must redraw the |
| 1645 | * rest. */ |
| 1646 | if (row + xtra_rows >= wp->w_height - 2) |
| 1647 | mod_bot = MAXLNUM; |
| 1648 | else |
| 1649 | { |
| 1650 | check_for_delay(FALSE); |
| 1651 | if (win_ins_lines(wp, row + old_rows, |
| 1652 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1653 | mod_bot = MAXLNUM; |
| 1654 | else if (top_end > row + old_rows) |
| 1655 | /* Scrolled the part at the top that requires |
| 1656 | * updating down. */ |
| 1657 | top_end += xtra_rows; |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | /* When not updating the rest, may need to move w_lines[] |
| 1662 | * entries. */ |
| 1663 | if (mod_bot != MAXLNUM && i != j) |
| 1664 | { |
| 1665 | if (j < i) |
| 1666 | { |
| 1667 | int x = row + new_rows; |
| 1668 | |
| 1669 | /* move entries in w_lines[] upwards */ |
| 1670 | for (;;) |
| 1671 | { |
| 1672 | /* stop at last valid entry in w_lines[] */ |
| 1673 | if (i >= wp->w_lines_valid) |
| 1674 | { |
| 1675 | wp->w_lines_valid = j; |
| 1676 | break; |
| 1677 | } |
| 1678 | wp->w_lines[j] = wp->w_lines[i]; |
| 1679 | /* stop at a line that won't fit */ |
| 1680 | if (x + (int)wp->w_lines[j].wl_size |
| 1681 | > wp->w_height) |
| 1682 | { |
| 1683 | wp->w_lines_valid = j + 1; |
| 1684 | break; |
| 1685 | } |
| 1686 | x += wp->w_lines[j++].wl_size; |
| 1687 | ++i; |
| 1688 | } |
| 1689 | if (bot_start > x) |
| 1690 | bot_start = x; |
| 1691 | } |
| 1692 | else /* j > i */ |
| 1693 | { |
| 1694 | /* move entries in w_lines[] downwards */ |
| 1695 | j -= i; |
| 1696 | wp->w_lines_valid += j; |
| 1697 | if (wp->w_lines_valid > wp->w_height) |
| 1698 | wp->w_lines_valid = wp->w_height; |
| 1699 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1700 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1701 | |
| 1702 | /* The w_lines[] entries for inserted lines are |
| 1703 | * now invalid, but wl_size may be used above. |
| 1704 | * Reset to zero. */ |
| 1705 | while (i >= idx) |
| 1706 | { |
| 1707 | wp->w_lines[i].wl_size = 0; |
| 1708 | wp->w_lines[i--].wl_valid = FALSE; |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | #ifdef FEAT_FOLDING |
| 1716 | /* |
| 1717 | * When lines are folded, display one line for all of them. |
| 1718 | * Otherwise, display normally (can be several display lines when |
| 1719 | * 'wrap' is on). |
| 1720 | */ |
| 1721 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1722 | if (fold_count != 0) |
| 1723 | { |
| 1724 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1725 | ++row; |
| 1726 | --fold_count; |
| 1727 | wp->w_lines[idx].wl_folded = TRUE; |
| 1728 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1729 | # ifdef FEAT_SYN_HL |
| 1730 | did_update = DID_FOLD; |
| 1731 | # endif |
| 1732 | } |
| 1733 | else |
| 1734 | #endif |
| 1735 | if (idx < wp->w_lines_valid |
| 1736 | && wp->w_lines[idx].wl_valid |
| 1737 | && wp->w_lines[idx].wl_lnum == lnum |
| 1738 | && lnum > wp->w_topline |
| 1739 | && !(dy_flags & DY_LASTLINE) |
| 1740 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1741 | #ifdef FEAT_DIFF |
| 1742 | && diff_check_fill(wp, lnum) == 0 |
| 1743 | #endif |
| 1744 | ) |
| 1745 | { |
| 1746 | /* This line is not going to fit. Don't draw anything here, |
| 1747 | * will draw "@ " lines below. */ |
| 1748 | row = wp->w_height + 1; |
| 1749 | } |
| 1750 | else |
| 1751 | { |
| 1752 | #ifdef FEAT_SEARCH_EXTRA |
| 1753 | prepare_search_hl(wp, lnum); |
| 1754 | #endif |
| 1755 | #ifdef FEAT_SYN_HL |
| 1756 | /* Let the syntax stuff know we skipped a few lines. */ |
| 1757 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
| 1758 | && syntax_present(buf)) |
| 1759 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1760 | #endif |
| 1761 | |
| 1762 | /* |
| 1763 | * Display one line. |
| 1764 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 1765 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1766 | |
| 1767 | #ifdef FEAT_FOLDING |
| 1768 | wp->w_lines[idx].wl_folded = FALSE; |
| 1769 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 1770 | #endif |
| 1771 | #ifdef FEAT_SYN_HL |
| 1772 | did_update = DID_LINE; |
| 1773 | syntax_last_parsed = lnum; |
| 1774 | #endif |
| 1775 | } |
| 1776 | |
| 1777 | wp->w_lines[idx].wl_lnum = lnum; |
| 1778 | wp->w_lines[idx].wl_valid = TRUE; |
| 1779 | if (row > wp->w_height) /* past end of screen */ |
| 1780 | { |
| 1781 | /* we may need the size of that too long line later on */ |
| 1782 | if (dollar_vcol == 0) |
| 1783 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 1784 | ++idx; |
| 1785 | break; |
| 1786 | } |
| 1787 | if (dollar_vcol == 0) |
| 1788 | wp->w_lines[idx].wl_size = row - srow; |
| 1789 | ++idx; |
| 1790 | #ifdef FEAT_FOLDING |
| 1791 | lnum += fold_count + 1; |
| 1792 | #else |
| 1793 | ++lnum; |
| 1794 | #endif |
| 1795 | } |
| 1796 | else |
| 1797 | { |
| 1798 | /* This line does not need updating, advance to the next one */ |
| 1799 | row += wp->w_lines[idx++].wl_size; |
| 1800 | if (row > wp->w_height) /* past end of screen */ |
| 1801 | break; |
| 1802 | #ifdef FEAT_FOLDING |
| 1803 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 1804 | #else |
| 1805 | ++lnum; |
| 1806 | #endif |
| 1807 | #ifdef FEAT_SYN_HL |
| 1808 | did_update = DID_NONE; |
| 1809 | #endif |
| 1810 | } |
| 1811 | |
| 1812 | if (lnum > buf->b_ml.ml_line_count) |
| 1813 | { |
| 1814 | eof = TRUE; |
| 1815 | break; |
| 1816 | } |
| 1817 | } |
| 1818 | /* |
| 1819 | * End of loop over all window lines. |
| 1820 | */ |
| 1821 | |
| 1822 | |
| 1823 | if (idx > wp->w_lines_valid) |
| 1824 | wp->w_lines_valid = idx; |
| 1825 | |
| 1826 | #ifdef FEAT_SYN_HL |
| 1827 | /* |
| 1828 | * Let the syntax stuff know we stop parsing here. |
| 1829 | */ |
| 1830 | if (syntax_last_parsed != 0 && syntax_present(buf)) |
| 1831 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1832 | #endif |
| 1833 | |
| 1834 | /* |
| 1835 | * If we didn't hit the end of the file, and we didn't finish the last |
| 1836 | * line we were working on, then the line didn't fit. |
| 1837 | */ |
| 1838 | wp->w_empty_rows = 0; |
| 1839 | #ifdef FEAT_DIFF |
| 1840 | wp->w_filler_rows = 0; |
| 1841 | #endif |
| 1842 | if (!eof && !didline) |
| 1843 | { |
| 1844 | if (lnum == wp->w_topline) |
| 1845 | { |
| 1846 | /* |
| 1847 | * Single line that does not fit! |
| 1848 | * Don't overwrite it, it can be edited. |
| 1849 | */ |
| 1850 | wp->w_botline = lnum + 1; |
| 1851 | } |
| 1852 | #ifdef FEAT_DIFF |
| 1853 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 1854 | { |
| 1855 | /* Window ends in filler lines. */ |
| 1856 | wp->w_botline = lnum; |
| 1857 | wp->w_filler_rows = wp->w_height - srow; |
| 1858 | } |
| 1859 | #endif |
| 1860 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 1861 | { |
| 1862 | /* |
| 1863 | * Last line isn't finished: Display "@@@" at the end. |
| 1864 | */ |
| 1865 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 1866 | W_WINROW(wp) + wp->w_height, |
| 1867 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 1868 | '@', '@', hl_attr(HLF_AT)); |
| 1869 | set_empty_rows(wp, srow); |
| 1870 | wp->w_botline = lnum; |
| 1871 | } |
| 1872 | else |
| 1873 | { |
| 1874 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 1875 | wp->w_botline = lnum; |
| 1876 | } |
| 1877 | } |
| 1878 | else |
| 1879 | { |
| 1880 | #ifdef FEAT_VERTSPLIT |
| 1881 | draw_vsep_win(wp, row); |
| 1882 | #endif |
| 1883 | if (eof) /* we hit the end of the file */ |
| 1884 | { |
| 1885 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 1886 | #ifdef FEAT_DIFF |
| 1887 | j = diff_check_fill(wp, wp->w_botline); |
| 1888 | if (j > 0 && !wp->w_botfill) |
| 1889 | { |
| 1890 | /* |
| 1891 | * Display filler lines at the end of the file |
| 1892 | */ |
| 1893 | if (char2cells(fill_diff) > 1) |
| 1894 | i = '-'; |
| 1895 | else |
| 1896 | i = fill_diff; |
| 1897 | if (row + j > wp->w_height) |
| 1898 | j = wp->w_height - row; |
| 1899 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 1900 | row += j; |
| 1901 | } |
| 1902 | #endif |
| 1903 | } |
| 1904 | else if (dollar_vcol == 0) |
| 1905 | wp->w_botline = lnum; |
| 1906 | |
| 1907 | /* make sure the rest of the screen is blank */ |
| 1908 | /* put '~'s on rows that aren't part of the file. */ |
| 1909 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 1910 | } |
| 1911 | |
| 1912 | /* Reset the type of redrawing required, the window has been updated. */ |
| 1913 | wp->w_redr_type = 0; |
| 1914 | #ifdef FEAT_DIFF |
| 1915 | wp->w_old_topfill = wp->w_topfill; |
| 1916 | wp->w_old_botfill = wp->w_botfill; |
| 1917 | #endif |
| 1918 | |
| 1919 | if (dollar_vcol == 0) |
| 1920 | { |
| 1921 | /* |
| 1922 | * There is a trick with w_botline. If we invalidate it on each |
| 1923 | * change that might modify it, this will cause a lot of expensive |
| 1924 | * calls to plines() in update_topline() each time. Therefore the |
| 1925 | * value of w_botline is often approximated, and this value is used to |
| 1926 | * compute the value of w_topline. If the value of w_botline was |
| 1927 | * wrong, check that the value of w_topline is correct (cursor is on |
| 1928 | * the visible part of the text). If it's not, we need to redraw |
| 1929 | * again. Mostly this just means scrolling up a few lines, so it |
| 1930 | * doesn't look too bad. Only do this for the current window (where |
| 1931 | * changes are relevant). |
| 1932 | */ |
| 1933 | wp->w_valid |= VALID_BOTLINE; |
| 1934 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 1935 | { |
| 1936 | recursive = TRUE; |
| 1937 | curwin->w_valid &= ~VALID_TOPLINE; |
| 1938 | update_topline(); /* may invalidate w_botline again */ |
| 1939 | if (must_redraw != 0) |
| 1940 | { |
| 1941 | /* Don't update for changes in buffer again. */ |
| 1942 | i = curbuf->b_mod_set; |
| 1943 | curbuf->b_mod_set = FALSE; |
| 1944 | win_update(curwin); |
| 1945 | must_redraw = 0; |
| 1946 | curbuf->b_mod_set = i; |
| 1947 | } |
| 1948 | recursive = FALSE; |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1953 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 1954 | if (!got_int) |
| 1955 | got_int = save_got_int; |
| 1956 | #endif |
| 1957 | } |
| 1958 | |
| 1959 | #ifdef FEAT_SIGNS |
| 1960 | static int draw_signcolumn __ARGS((win_T *wp)); |
| 1961 | |
| 1962 | /* |
| 1963 | * Return TRUE when window "wp" has a column to draw signs in. |
| 1964 | */ |
| 1965 | static int |
| 1966 | draw_signcolumn(wp) |
| 1967 | win_T *wp; |
| 1968 | { |
| 1969 | return (wp->w_buffer->b_signlist != NULL |
| 1970 | # ifdef FEAT_NETBEANS_INTG |
| 1971 | || usingNetbeans |
| 1972 | # endif |
| 1973 | ); |
| 1974 | } |
| 1975 | #endif |
| 1976 | |
| 1977 | /* |
| 1978 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 1979 | * as the filler character. |
| 1980 | */ |
| 1981 | static void |
| 1982 | win_draw_end(wp, c1, c2, row, endrow, hl) |
| 1983 | win_T *wp; |
| 1984 | int c1; |
| 1985 | int c2; |
| 1986 | int row; |
| 1987 | int endrow; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 1988 | hlf_T hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1989 | { |
| 1990 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 1991 | int n = 0; |
| 1992 | # define FDC_OFF n |
| 1993 | #else |
| 1994 | # define FDC_OFF 0 |
| 1995 | #endif |
| 1996 | |
| 1997 | #ifdef FEAT_RIGHTLEFT |
| 1998 | if (wp->w_p_rl) |
| 1999 | { |
| 2000 | /* No check for cmdline window: should never be right-left. */ |
| 2001 | # ifdef FEAT_FOLDING |
| 2002 | n = wp->w_p_fdc; |
| 2003 | |
| 2004 | if (n > 0) |
| 2005 | { |
| 2006 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2007 | if (n > W_WIDTH(wp)) |
| 2008 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2009 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2010 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2011 | ' ', ' ', hl_attr(HLF_FC)); |
| 2012 | } |
| 2013 | # endif |
| 2014 | # ifdef FEAT_SIGNS |
| 2015 | if (draw_signcolumn(wp)) |
| 2016 | { |
| 2017 | int nn = n + 2; |
| 2018 | |
| 2019 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2020 | if (nn > W_WIDTH(wp)) |
| 2021 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2022 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2023 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2024 | ' ', ' ', hl_attr(HLF_SC)); |
| 2025 | n = nn; |
| 2026 | } |
| 2027 | # endif |
| 2028 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2029 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2030 | c2, c2, hl_attr(hl)); |
| 2031 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2032 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2033 | c1, c2, hl_attr(hl)); |
| 2034 | } |
| 2035 | else |
| 2036 | #endif |
| 2037 | { |
| 2038 | #ifdef FEAT_CMDWIN |
| 2039 | if (cmdwin_type != 0 && wp == curwin) |
| 2040 | { |
| 2041 | /* draw the cmdline character in the leftmost column */ |
| 2042 | n = 1; |
| 2043 | if (n > wp->w_width) |
| 2044 | n = wp->w_width; |
| 2045 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2046 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2047 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2048 | } |
| 2049 | #endif |
| 2050 | #ifdef FEAT_FOLDING |
| 2051 | if (wp->w_p_fdc > 0) |
| 2052 | { |
| 2053 | int nn = n + wp->w_p_fdc; |
| 2054 | |
| 2055 | /* draw the fold column at the left */ |
| 2056 | if (nn > W_WIDTH(wp)) |
| 2057 | nn = W_WIDTH(wp); |
| 2058 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2059 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2060 | ' ', ' ', hl_attr(HLF_FC)); |
| 2061 | n = nn; |
| 2062 | } |
| 2063 | #endif |
| 2064 | #ifdef FEAT_SIGNS |
| 2065 | if (draw_signcolumn(wp)) |
| 2066 | { |
| 2067 | int nn = n + 2; |
| 2068 | |
| 2069 | /* draw the sign column after the fold column */ |
| 2070 | if (nn > W_WIDTH(wp)) |
| 2071 | nn = W_WIDTH(wp); |
| 2072 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2073 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2074 | ' ', ' ', hl_attr(HLF_SC)); |
| 2075 | n = nn; |
| 2076 | } |
| 2077 | #endif |
| 2078 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2079 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2080 | c1, c2, hl_attr(hl)); |
| 2081 | } |
| 2082 | set_empty_rows(wp, row); |
| 2083 | } |
| 2084 | |
| 2085 | #ifdef FEAT_FOLDING |
| 2086 | /* |
| 2087 | * Display one folded line. |
| 2088 | */ |
| 2089 | static void |
| 2090 | fold_line(wp, fold_count, foldinfo, lnum, row) |
| 2091 | win_T *wp; |
| 2092 | long fold_count; |
| 2093 | foldinfo_T *foldinfo; |
| 2094 | linenr_T lnum; |
| 2095 | int row; |
| 2096 | { |
| 2097 | char_u buf[51]; |
| 2098 | pos_T *top, *bot; |
| 2099 | linenr_T lnume = lnum + fold_count - 1; |
| 2100 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2101 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2102 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2103 | int col; |
| 2104 | int txtcol; |
| 2105 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2106 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2107 | |
| 2108 | /* Build the fold line: |
| 2109 | * 1. Add the cmdwin_type for the command-line window |
| 2110 | * 2. Add the 'foldcolumn' |
| 2111 | * 3. Add the 'number' column |
| 2112 | * 4. Compose the text |
| 2113 | * 5. Add the text |
| 2114 | * 6. set highlighting for the Visual area an other text |
| 2115 | */ |
| 2116 | col = 0; |
| 2117 | |
| 2118 | /* |
| 2119 | * 1. Add the cmdwin_type for the command-line window |
| 2120 | * Ignores 'rightleft', this window is never right-left. |
| 2121 | */ |
| 2122 | #ifdef FEAT_CMDWIN |
| 2123 | if (cmdwin_type != 0 && wp == curwin) |
| 2124 | { |
| 2125 | ScreenLines[off] = cmdwin_type; |
| 2126 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2127 | #ifdef FEAT_MBYTE |
| 2128 | if (enc_utf8) |
| 2129 | ScreenLinesUC[off] = 0; |
| 2130 | #endif |
| 2131 | ++col; |
| 2132 | } |
| 2133 | #endif |
| 2134 | |
| 2135 | /* |
| 2136 | * 2. Add the 'foldcolumn' |
| 2137 | */ |
| 2138 | fdc = wp->w_p_fdc; |
| 2139 | if (fdc > W_WIDTH(wp) - col) |
| 2140 | fdc = W_WIDTH(wp) - col; |
| 2141 | if (fdc > 0) |
| 2142 | { |
| 2143 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2144 | #ifdef FEAT_RIGHTLEFT |
| 2145 | if (wp->w_p_rl) |
| 2146 | { |
| 2147 | int i; |
| 2148 | |
| 2149 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2150 | hl_attr(HLF_FC)); |
| 2151 | /* reverse the fold column */ |
| 2152 | for (i = 0; i < fdc; ++i) |
| 2153 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2154 | } |
| 2155 | else |
| 2156 | #endif |
| 2157 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2158 | col += fdc; |
| 2159 | } |
| 2160 | |
| 2161 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2162 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2163 | for (ri = 0; ri < l; ++ri) \ |
| 2164 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2165 | else \ |
| 2166 | for (ri = 0; ri < l; ++ri) \ |
| 2167 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2168 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2169 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2170 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2171 | #endif |
| 2172 | |
| 2173 | /* Set all attributes of the 'number' column and the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2174 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2175 | |
| 2176 | #ifdef FEAT_SIGNS |
| 2177 | /* If signs are being displayed, add two spaces. */ |
| 2178 | if (draw_signcolumn(wp)) |
| 2179 | { |
| 2180 | len = W_WIDTH(wp) - col; |
| 2181 | if (len > 0) |
| 2182 | { |
| 2183 | if (len > 2) |
| 2184 | len = 2; |
| 2185 | # ifdef FEAT_RIGHTLEFT |
| 2186 | if (wp->w_p_rl) |
| 2187 | /* the line number isn't reversed */ |
| 2188 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2189 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2190 | else |
| 2191 | # endif |
| 2192 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2193 | col += len; |
| 2194 | } |
| 2195 | } |
| 2196 | #endif |
| 2197 | |
| 2198 | /* |
| 2199 | * 3. Add the 'number' column |
| 2200 | */ |
| 2201 | if (wp->w_p_nu) |
| 2202 | { |
| 2203 | len = W_WIDTH(wp) - col; |
| 2204 | if (len > 0) |
| 2205 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2206 | int w = number_width(wp); |
| 2207 | |
| 2208 | if (len > w + 1) |
| 2209 | len = w + 1; |
| 2210 | sprintf((char *)buf, "%*ld ", w, (long)lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2211 | #ifdef FEAT_RIGHTLEFT |
| 2212 | if (wp->w_p_rl) |
| 2213 | /* the line number isn't reversed */ |
| 2214 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2215 | hl_attr(HLF_FL)); |
| 2216 | else |
| 2217 | #endif |
| 2218 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2219 | col += len; |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | /* |
| 2224 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2225 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2226 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2227 | |
| 2228 | txtcol = col; /* remember where text starts */ |
| 2229 | |
| 2230 | /* |
| 2231 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2232 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2233 | * in columns number-col - window-width. |
| 2234 | */ |
| 2235 | #ifdef FEAT_MBYTE |
| 2236 | if (has_mbyte) |
| 2237 | { |
| 2238 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2239 | int u8c, u8cc[MAX_MCO]; |
| 2240 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2241 | int idx; |
| 2242 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2243 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2244 | # ifdef FEAT_ARABIC |
| 2245 | int prev_c = 0; /* previous Arabic character */ |
| 2246 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2247 | # endif |
| 2248 | |
| 2249 | # ifdef FEAT_RIGHTLEFT |
| 2250 | if (wp->w_p_rl) |
| 2251 | idx = off; |
| 2252 | else |
| 2253 | # endif |
| 2254 | idx = off + col; |
| 2255 | |
| 2256 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2257 | for (p = text; *p != NUL; ) |
| 2258 | { |
| 2259 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2260 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2261 | if (col + cells > W_WIDTH(wp) |
| 2262 | # ifdef FEAT_RIGHTLEFT |
| 2263 | - (wp->w_p_rl ? col : 0) |
| 2264 | # endif |
| 2265 | ) |
| 2266 | break; |
| 2267 | ScreenLines[idx] = *p; |
| 2268 | if (enc_utf8) |
| 2269 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2270 | u8c = utfc_ptr2char(p, u8cc); |
| 2271 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2272 | { |
| 2273 | ScreenLinesUC[idx] = 0; |
| 2274 | #ifdef FEAT_ARABIC |
| 2275 | prev_c = u8c; |
| 2276 | #endif |
| 2277 | } |
| 2278 | else |
| 2279 | { |
| 2280 | #ifdef FEAT_ARABIC |
| 2281 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2282 | { |
| 2283 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2284 | int pc, pc1, nc; |
| 2285 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2286 | int firstbyte = *p; |
| 2287 | |
| 2288 | /* The idea of what is the previous and next |
| 2289 | * character depends on 'rightleft'. */ |
| 2290 | if (wp->w_p_rl) |
| 2291 | { |
| 2292 | pc = prev_c; |
| 2293 | pc1 = prev_c1; |
| 2294 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2295 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2296 | } |
| 2297 | else |
| 2298 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2299 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2300 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2301 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2302 | } |
| 2303 | prev_c = u8c; |
| 2304 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2305 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2306 | pc, pc1, nc); |
| 2307 | ScreenLines[idx] = firstbyte; |
| 2308 | } |
| 2309 | else |
| 2310 | prev_c = u8c; |
| 2311 | #endif |
| 2312 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2313 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2314 | if (u8c >= 0x10000) |
| 2315 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2316 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2317 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2318 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2319 | for (i = 0; i < Screen_mco; ++i) |
| 2320 | { |
| 2321 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2322 | if (u8cc[i] == 0) |
| 2323 | break; |
| 2324 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2325 | } |
| 2326 | if (cells > 1) |
| 2327 | ScreenLines[idx + 1] = 0; |
| 2328 | } |
| 2329 | else if (cells > 1) /* double-byte character */ |
| 2330 | { |
| 2331 | if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2332 | ScreenLines2[idx] = p[1]; |
| 2333 | else |
| 2334 | ScreenLines[idx + 1] = p[1]; |
| 2335 | } |
| 2336 | col += cells; |
| 2337 | idx += cells; |
| 2338 | p += c_len; |
| 2339 | } |
| 2340 | } |
| 2341 | else |
| 2342 | #endif |
| 2343 | { |
| 2344 | len = (int)STRLEN(text); |
| 2345 | if (len > W_WIDTH(wp) - col) |
| 2346 | len = W_WIDTH(wp) - col; |
| 2347 | if (len > 0) |
| 2348 | { |
| 2349 | #ifdef FEAT_RIGHTLEFT |
| 2350 | if (wp->w_p_rl) |
| 2351 | STRNCPY(current_ScreenLine, text, len); |
| 2352 | else |
| 2353 | #endif |
| 2354 | STRNCPY(current_ScreenLine + col, text, len); |
| 2355 | col += len; |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | /* Fill the rest of the line with the fold filler */ |
| 2360 | #ifdef FEAT_RIGHTLEFT |
| 2361 | if (wp->w_p_rl) |
| 2362 | col -= txtcol; |
| 2363 | #endif |
| 2364 | while (col < W_WIDTH(wp) |
| 2365 | #ifdef FEAT_RIGHTLEFT |
| 2366 | - (wp->w_p_rl ? txtcol : 0) |
| 2367 | #endif |
| 2368 | ) |
| 2369 | { |
| 2370 | #ifdef FEAT_MBYTE |
| 2371 | if (enc_utf8) |
| 2372 | { |
| 2373 | if (fill_fold >= 0x80) |
| 2374 | { |
| 2375 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2376 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2377 | } |
| 2378 | else |
| 2379 | ScreenLinesUC[off + col] = 0; |
| 2380 | } |
| 2381 | #endif |
| 2382 | ScreenLines[off + col++] = fill_fold; |
| 2383 | } |
| 2384 | |
| 2385 | if (text != buf) |
| 2386 | vim_free(text); |
| 2387 | |
| 2388 | /* |
| 2389 | * 6. set highlighting for the Visual area an other text. |
| 2390 | * If all folded lines are in the Visual area, highlight the line. |
| 2391 | */ |
| 2392 | #ifdef FEAT_VISUAL |
| 2393 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2394 | { |
| 2395 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2396 | { |
| 2397 | /* Visual is after curwin->w_cursor */ |
| 2398 | top = &curwin->w_cursor; |
| 2399 | bot = &VIsual; |
| 2400 | } |
| 2401 | else |
| 2402 | { |
| 2403 | /* Visual is before curwin->w_cursor */ |
| 2404 | top = &VIsual; |
| 2405 | bot = &curwin->w_cursor; |
| 2406 | } |
| 2407 | if (lnum >= top->lnum |
| 2408 | && lnume <= bot->lnum |
| 2409 | && (VIsual_mode != 'v' |
| 2410 | || ((lnum > top->lnum |
| 2411 | || (lnum == top->lnum |
| 2412 | && top->col == 0)) |
| 2413 | && (lnume < bot->lnum |
| 2414 | || (lnume == bot->lnum |
| 2415 | && (bot->col - (*p_sel == 'e')) |
| 2416 | >= STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
| 2417 | { |
| 2418 | if (VIsual_mode == Ctrl_V) |
| 2419 | { |
| 2420 | /* Visual block mode: highlight the chars part of the block */ |
| 2421 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2422 | { |
| 2423 | if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2424 | len = wp->w_old_cursor_lcol; |
| 2425 | else |
| 2426 | len = W_WIDTH(wp) - txtcol; |
| 2427 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2428 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2432 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2433 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2434 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2435 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | #endif |
| 2439 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2440 | #ifdef FEAT_SYN_HL |
| 2441 | /* Show 'cursorcolumn' in the fold line. */ |
| 2442 | if (wp->w_p_cuc && (int)wp->w_virtcol + txtcol < W_WIDTH(wp)) |
| 2443 | ScreenAttrs[off + wp->w_virtcol + txtcol] = hl_combine_attr( |
| 2444 | ScreenAttrs[off + wp->w_virtcol + txtcol], hl_attr(HLF_CUC)); |
| 2445 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2446 | |
| 2447 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2448 | (int)W_WIDTH(wp), FALSE); |
| 2449 | |
| 2450 | /* |
| 2451 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2452 | * updated (saves a call to plines() later). |
| 2453 | */ |
| 2454 | if (wp == curwin |
| 2455 | && lnum <= curwin->w_cursor.lnum |
| 2456 | && lnume >= curwin->w_cursor.lnum) |
| 2457 | { |
| 2458 | curwin->w_cline_row = row; |
| 2459 | curwin->w_cline_height = 1; |
| 2460 | curwin->w_cline_folded = TRUE; |
| 2461 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | /* |
| 2466 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2467 | */ |
| 2468 | static void |
| 2469 | copy_text_attr(off, buf, len, attr) |
| 2470 | int off; |
| 2471 | char_u *buf; |
| 2472 | int len; |
| 2473 | int attr; |
| 2474 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2475 | int i; |
| 2476 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2477 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2478 | # ifdef FEAT_MBYTE |
| 2479 | if (enc_utf8) |
| 2480 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2481 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2482 | for (i = 0; i < len; ++i) |
| 2483 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | /* |
| 2487 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2488 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2489 | */ |
| 2490 | static void |
| 2491 | fill_foldcolumn(p, wp, closed, lnum) |
| 2492 | char_u *p; |
| 2493 | win_T *wp; |
| 2494 | int closed; /* TRUE of FALSE */ |
| 2495 | linenr_T lnum; /* current line number */ |
| 2496 | { |
| 2497 | int i = 0; |
| 2498 | int level; |
| 2499 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2500 | int empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2501 | |
| 2502 | /* Init to all spaces. */ |
| 2503 | copy_spaces(p, (size_t)wp->w_p_fdc); |
| 2504 | |
| 2505 | level = win_foldinfo.fi_level; |
| 2506 | if (level > 0) |
| 2507 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2508 | /* If there is only one column put more info in it. */ |
| 2509 | empty = (wp->w_p_fdc == 1) ? 0 : 1; |
| 2510 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2511 | /* If the column is too narrow, we start at the lowest level that |
| 2512 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2513 | first_level = level - wp->w_p_fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2514 | if (first_level < 1) |
| 2515 | first_level = 1; |
| 2516 | |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2517 | for (i = 0; i + empty < wp->w_p_fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2518 | { |
| 2519 | if (win_foldinfo.fi_lnum == lnum |
| 2520 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2521 | p[i] = '-'; |
| 2522 | else if (first_level == 1) |
| 2523 | p[i] = '|'; |
| 2524 | else if (first_level + i <= 9) |
| 2525 | p[i] = '0' + first_level + i; |
| 2526 | else |
| 2527 | p[i] = '>'; |
| 2528 | if (first_level + i == level) |
| 2529 | break; |
| 2530 | } |
| 2531 | } |
| 2532 | if (closed) |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2533 | p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2534 | } |
| 2535 | #endif /* FEAT_FOLDING */ |
| 2536 | |
| 2537 | /* |
| 2538 | * Display line "lnum" of window 'wp' on the screen. |
| 2539 | * Start at row "startrow", stop when "endrow" is reached. |
| 2540 | * wp->w_virtcol needs to be valid. |
| 2541 | * |
| 2542 | * Return the number of last row the line occupies. |
| 2543 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2544 | /* ARGSUSED */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2545 | static int |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2546 | win_line(wp, lnum, startrow, endrow, nochange) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2547 | win_T *wp; |
| 2548 | linenr_T lnum; |
| 2549 | int startrow; |
| 2550 | int endrow; |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2551 | int nochange; /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2552 | { |
| 2553 | int col; /* visual column on screen */ |
| 2554 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2555 | int c = 0; /* init for GCC */ |
| 2556 | long vcol = 0; /* virtual column (for tabs) */ |
| 2557 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2558 | char_u *line; /* current line */ |
| 2559 | char_u *ptr; /* current position in "line" */ |
| 2560 | int row; /* row in the window, excl w_winrow */ |
| 2561 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2562 | |
| 2563 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2564 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2565 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2566 | int c_extra = NUL; /* extra chars, all the same */ |
| 2567 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2568 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2569 | displaying lcs_eol at end-of-line */ |
| 2570 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2571 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2572 | |
| 2573 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2574 | int saved_n_extra = 0; |
| 2575 | char_u *saved_p_extra = NULL; |
| 2576 | int saved_c_extra = 0; |
| 2577 | int saved_char_attr = 0; |
| 2578 | |
| 2579 | int n_attr = 0; /* chars with special attr */ |
| 2580 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2581 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2582 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2583 | |
| 2584 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2585 | |
| 2586 | int fromcol, tocol; /* start/end of inverting */ |
| 2587 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2588 | int noinvcur = FALSE; /* don't invert the cursor */ |
| 2589 | #ifdef FEAT_VISUAL |
| 2590 | pos_T *top, *bot; |
| 2591 | #endif |
| 2592 | pos_T pos; |
| 2593 | long v; |
| 2594 | |
| 2595 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2596 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2597 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2598 | in this line */ |
| 2599 | int attr = 0; /* attributes for area highlighting */ |
| 2600 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2601 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2602 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2603 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2604 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2605 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2606 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2607 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2608 | #endif |
| 2609 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2610 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2611 | # define SPWORDLEN 150 |
| 2612 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2613 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2614 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2615 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2616 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2617 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2618 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2619 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2620 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2621 | static int cap_col = -1; /* column to check for Cap word */ |
| 2622 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2623 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2624 | #endif |
| 2625 | int extra_check; /* has syntax or linebreak */ |
| 2626 | #ifdef FEAT_MBYTE |
| 2627 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2628 | int mb_l = 1; /* multi-byte byte length */ |
| 2629 | int mb_c = 0; /* decoded multi-byte character */ |
| 2630 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2631 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2632 | #endif |
| 2633 | #ifdef FEAT_DIFF |
| 2634 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2635 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2636 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2637 | int change_start = MAXCOL; /* first col of changed area */ |
| 2638 | int change_end = -1; /* last col of changed area */ |
| 2639 | #endif |
| 2640 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2641 | #ifdef FEAT_LINEBREAK |
| 2642 | int need_showbreak = FALSE; |
| 2643 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2644 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2645 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2646 | # define LINE_ATTR |
| 2647 | int line_attr = 0; /* atrribute for the whole line */ |
| 2648 | #endif |
| 2649 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2650 | matchitem_T *cur; /* points to the match list */ |
| 2651 | match_T *shl; /* points to search_hl or a match */ |
| 2652 | int shl_flag; /* flag to indicate whether search_hl |
| 2653 | has been processed or not */ |
| 2654 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 2655 | equals startcol of search_hl or one |
| 2656 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2657 | #endif |
| 2658 | #ifdef FEAT_ARABIC |
| 2659 | int prev_c = 0; /* previous Arabic character */ |
| 2660 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2661 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2662 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 2663 | int did_line_attr = 0; |
| 2664 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2665 | |
| 2666 | /* draw_state: items that are drawn in sequence: */ |
| 2667 | #define WL_START 0 /* nothing done yet */ |
| 2668 | #ifdef FEAT_CMDWIN |
| 2669 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 2670 | #else |
| 2671 | # define WL_CMDLINE WL_START |
| 2672 | #endif |
| 2673 | #ifdef FEAT_FOLDING |
| 2674 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 2675 | #else |
| 2676 | # define WL_FOLD WL_CMDLINE |
| 2677 | #endif |
| 2678 | #ifdef FEAT_SIGNS |
| 2679 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 2680 | #else |
| 2681 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 2682 | #endif |
| 2683 | #define WL_NR WL_SIGN + 1 /* line number */ |
| 2684 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 2685 | # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ |
| 2686 | #else |
| 2687 | # define WL_SBR WL_NR |
| 2688 | #endif |
| 2689 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 2690 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 2691 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2692 | int feedback_col = 0; |
| 2693 | int feedback_old_attr = -1; |
| 2694 | #endif |
| 2695 | |
| 2696 | |
| 2697 | if (startrow > endrow) /* past the end already! */ |
| 2698 | return startrow; |
| 2699 | |
| 2700 | row = startrow; |
| 2701 | screen_row = row + W_WINROW(wp); |
| 2702 | |
| 2703 | /* |
| 2704 | * To speed up the loop below, set extra_check when there is linebreak, |
| 2705 | * trailing white space and/or syntax processing to be done. |
| 2706 | */ |
| 2707 | #ifdef FEAT_LINEBREAK |
| 2708 | extra_check = wp->w_p_lbr; |
| 2709 | #else |
| 2710 | extra_check = 0; |
| 2711 | #endif |
| 2712 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 2713 | if (syntax_present(wp->w_buffer) && !wp->w_buffer->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2714 | { |
| 2715 | /* Prepare for syntax highlighting in this line. When there is an |
| 2716 | * error, stop syntax highlighting. */ |
| 2717 | save_did_emsg = did_emsg; |
| 2718 | did_emsg = FALSE; |
| 2719 | syntax_start(wp, lnum); |
| 2720 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 2721 | wp->w_buffer->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2722 | else |
| 2723 | { |
| 2724 | did_emsg = save_did_emsg; |
| 2725 | has_syntax = TRUE; |
| 2726 | extra_check = TRUE; |
| 2727 | } |
| 2728 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2729 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2730 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2731 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 2732 | if (wp->w_p_spell |
| 2733 | && *wp->w_buffer->b_p_spl != NUL |
| 2734 | && wp->w_buffer->b_langp.ga_len > 0 |
| 2735 | && *(char **)(wp->w_buffer->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2736 | { |
| 2737 | /* Prepare for spell checking. */ |
| 2738 | has_spell = TRUE; |
| 2739 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2740 | |
| 2741 | /* Get the start of the next line, so that words that wrap to the next |
| 2742 | * line are found too: "et<line-break>al.". |
| 2743 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 2744 | nextline[SPWORDLEN] = NUL; |
| 2745 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 2746 | { |
| 2747 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 2748 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 2749 | } |
| 2750 | |
| 2751 | /* When a word wrapped from the previous line the start of the current |
| 2752 | * line is valid. */ |
| 2753 | if (lnum == checked_lnum) |
| 2754 | cur_checked_col = checked_col; |
| 2755 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2756 | |
| 2757 | /* When there was a sentence end in the previous line may require a |
| 2758 | * word starting with capital in this line. In line 1 always check |
| 2759 | * the first word. */ |
| 2760 | if (lnum != capcol_lnum) |
| 2761 | cap_col = -1; |
| 2762 | if (lnum == 1) |
| 2763 | cap_col = 0; |
| 2764 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2765 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2766 | #endif |
| 2767 | |
| 2768 | /* |
| 2769 | * handle visual active in this window |
| 2770 | */ |
| 2771 | fromcol = -10; |
| 2772 | tocol = MAXCOL; |
| 2773 | #ifdef FEAT_VISUAL |
| 2774 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2775 | { |
| 2776 | /* Visual is after curwin->w_cursor */ |
| 2777 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2778 | { |
| 2779 | top = &curwin->w_cursor; |
| 2780 | bot = &VIsual; |
| 2781 | } |
| 2782 | else /* Visual is before curwin->w_cursor */ |
| 2783 | { |
| 2784 | top = &VIsual; |
| 2785 | bot = &curwin->w_cursor; |
| 2786 | } |
| 2787 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 2788 | { |
| 2789 | if (lnum >= top->lnum && lnum <= bot->lnum) |
| 2790 | { |
| 2791 | fromcol = wp->w_old_cursor_fcol; |
| 2792 | tocol = wp->w_old_cursor_lcol; |
| 2793 | } |
| 2794 | } |
| 2795 | else /* non-block mode */ |
| 2796 | { |
| 2797 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 2798 | fromcol = 0; |
| 2799 | else if (lnum == top->lnum) |
| 2800 | { |
| 2801 | if (VIsual_mode == 'V') /* linewise */ |
| 2802 | fromcol = 0; |
| 2803 | else |
| 2804 | { |
| 2805 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 2806 | if (gchar_pos(top) == NUL) |
| 2807 | tocol = fromcol + 1; |
| 2808 | } |
| 2809 | } |
| 2810 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 2811 | { |
| 2812 | if (*p_sel == 'e' && bot->col == 0 |
| 2813 | #ifdef FEAT_VIRTUALEDIT |
| 2814 | && bot->coladd == 0 |
| 2815 | #endif |
| 2816 | ) |
| 2817 | { |
| 2818 | fromcol = -10; |
| 2819 | tocol = MAXCOL; |
| 2820 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2821 | else if (bot->col == MAXCOL) |
| 2822 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2823 | else |
| 2824 | { |
| 2825 | pos = *bot; |
| 2826 | if (*p_sel == 'e') |
| 2827 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2828 | else |
| 2829 | { |
| 2830 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 2831 | ++tocol; |
| 2832 | } |
| 2833 | } |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | #ifndef MSDOS |
| 2838 | /* Check if the character under the cursor should not be inverted */ |
| 2839 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
| 2840 | # ifdef FEAT_GUI |
| 2841 | && !gui.in_use |
| 2842 | # endif |
| 2843 | ) |
| 2844 | noinvcur = TRUE; |
| 2845 | #endif |
| 2846 | |
| 2847 | /* if inverting in this line set area_highlighting */ |
| 2848 | if (fromcol >= 0) |
| 2849 | { |
| 2850 | area_highlighting = TRUE; |
| 2851 | attr = hl_attr(HLF_V); |
| 2852 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
| 2853 | if (clip_star.available && !clip_star.owned && clip_isautosel()) |
| 2854 | attr = hl_attr(HLF_VNC); |
| 2855 | #endif |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2860 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2861 | */ |
| 2862 | else |
| 2863 | #endif /* FEAT_VISUAL */ |
| 2864 | if (highlight_match |
| 2865 | && wp == curwin |
| 2866 | && lnum >= curwin->w_cursor.lnum |
| 2867 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 2868 | { |
| 2869 | if (lnum == curwin->w_cursor.lnum) |
| 2870 | getvcol(curwin, &(curwin->w_cursor), |
| 2871 | (colnr_T *)&fromcol, NULL, NULL); |
| 2872 | else |
| 2873 | fromcol = 0; |
| 2874 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 2875 | { |
| 2876 | pos.lnum = lnum; |
| 2877 | pos.col = search_match_endcol; |
| 2878 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2879 | } |
| 2880 | else |
| 2881 | tocol = MAXCOL; |
| 2882 | if (fromcol == tocol) /* do at least one character */ |
| 2883 | tocol = fromcol + 1; /* happens when past end of line */ |
| 2884 | area_highlighting = TRUE; |
| 2885 | attr = hl_attr(HLF_I); |
| 2886 | } |
| 2887 | |
| 2888 | #ifdef FEAT_DIFF |
| 2889 | filler_lines = diff_check(wp, lnum); |
| 2890 | if (filler_lines < 0) |
| 2891 | { |
| 2892 | if (filler_lines == -1) |
| 2893 | { |
| 2894 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 2895 | diff_hlf = HLF_ADD; /* added line */ |
| 2896 | else if (change_start == 0) |
| 2897 | diff_hlf = HLF_TXD; /* changed text */ |
| 2898 | else |
| 2899 | diff_hlf = HLF_CHD; /* changed line */ |
| 2900 | } |
| 2901 | else |
| 2902 | diff_hlf = HLF_ADD; /* added line */ |
| 2903 | filler_lines = 0; |
| 2904 | area_highlighting = TRUE; |
| 2905 | } |
| 2906 | if (lnum == wp->w_topline) |
| 2907 | filler_lines = wp->w_topfill; |
| 2908 | filler_todo = filler_lines; |
| 2909 | #endif |
| 2910 | |
| 2911 | #ifdef LINE_ATTR |
| 2912 | # ifdef FEAT_SIGNS |
| 2913 | /* If this line has a sign with line highlighting set line_attr. */ |
| 2914 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 2915 | if (v != 0) |
| 2916 | line_attr = sign_get_attr((int)v, TRUE); |
| 2917 | # endif |
| 2918 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 2919 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 2920 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2921 | line_attr = hl_attr(HLF_L); |
| 2922 | # endif |
| 2923 | if (line_attr != 0) |
| 2924 | area_highlighting = TRUE; |
| 2925 | #endif |
| 2926 | |
| 2927 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 2928 | ptr = line; |
| 2929 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2930 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2931 | if (has_spell) |
| 2932 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2933 | /* For checking first word with a capital skip white space. */ |
| 2934 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 2935 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2936 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2937 | /* To be able to spell-check over line boundaries copy the end of the |
| 2938 | * current line into nextline[]. Above the start of the next line was |
| 2939 | * copied to nextline[SPWORDLEN]. */ |
| 2940 | if (nextline[SPWORDLEN] == NUL) |
| 2941 | { |
| 2942 | /* No next line or it is empty. */ |
| 2943 | nextlinecol = MAXCOL; |
| 2944 | nextline_idx = 0; |
| 2945 | } |
| 2946 | else |
| 2947 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 2948 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2949 | if (v < SPWORDLEN) |
| 2950 | { |
| 2951 | /* Short line, use it completely and append the start of the |
| 2952 | * next line. */ |
| 2953 | nextlinecol = 0; |
| 2954 | mch_memmove(nextline, line, (size_t)v); |
| 2955 | mch_memmove(nextline + v, nextline + SPWORDLEN, |
| 2956 | STRLEN(nextline + SPWORDLEN) + 1); |
| 2957 | nextline_idx = v + 1; |
| 2958 | } |
| 2959 | else |
| 2960 | { |
| 2961 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 2962 | nextlinecol = v - SPWORDLEN; |
| 2963 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 2964 | nextline_idx = SPWORDLEN + 1; |
| 2965 | } |
| 2966 | } |
| 2967 | } |
| 2968 | #endif |
| 2969 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2970 | /* find start of trailing whitespace */ |
| 2971 | if (wp->w_p_list && lcs_trail) |
| 2972 | { |
| 2973 | trailcol = (colnr_T)STRLEN(ptr); |
| 2974 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 2975 | --trailcol; |
| 2976 | trailcol += (colnr_T) (ptr - line); |
| 2977 | extra_check = TRUE; |
| 2978 | } |
| 2979 | |
| 2980 | /* |
| 2981 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 2982 | * first character to be displayed. |
| 2983 | */ |
| 2984 | if (wp->w_p_wrap) |
| 2985 | v = wp->w_skipcol; |
| 2986 | else |
| 2987 | v = wp->w_leftcol; |
| 2988 | if (v > 0) |
| 2989 | { |
| 2990 | #ifdef FEAT_MBYTE |
| 2991 | char_u *prev_ptr = ptr; |
| 2992 | #endif |
| 2993 | while (vcol < v && *ptr != NUL) |
| 2994 | { |
| 2995 | c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); |
| 2996 | vcol += c; |
| 2997 | #ifdef FEAT_MBYTE |
| 2998 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2999 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3000 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | #ifdef FEAT_VIRTUALEDIT |
| 3004 | /* When 'virtualedit' is set the end of the line may be before the |
| 3005 | * start of the displayed part. */ |
| 3006 | if (vcol < v && *ptr == NUL && virtual_active()) |
| 3007 | vcol = v; |
| 3008 | #endif |
| 3009 | |
| 3010 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3011 | * that character but skip the first few screen characters. */ |
| 3012 | if (vcol > v) |
| 3013 | { |
| 3014 | vcol -= c; |
| 3015 | #ifdef FEAT_MBYTE |
| 3016 | ptr = prev_ptr; |
| 3017 | #else |
| 3018 | --ptr; |
| 3019 | #endif |
| 3020 | n_skip = v - vcol; |
| 3021 | } |
| 3022 | |
| 3023 | /* |
| 3024 | * Adjust for when the inverted text is before the screen, |
| 3025 | * and when the start of the inverted text is before the screen. |
| 3026 | */ |
| 3027 | if (tocol <= vcol) |
| 3028 | fromcol = 0; |
| 3029 | else if (fromcol >= 0 && fromcol < vcol) |
| 3030 | fromcol = vcol; |
| 3031 | |
| 3032 | #ifdef FEAT_LINEBREAK |
| 3033 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3034 | if (wp->w_p_wrap) |
| 3035 | need_showbreak = TRUE; |
| 3036 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3037 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3038 | /* When spell checking a word we need to figure out the start of the |
| 3039 | * word and if it's badly spelled or not. */ |
| 3040 | if (has_spell) |
| 3041 | { |
| 3042 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3043 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3044 | |
| 3045 | pos = wp->w_cursor; |
| 3046 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3047 | wp->w_cursor.col = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3048 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3049 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3050 | { |
| 3051 | /* no bad word found at line start, don't check until end of a |
| 3052 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3053 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3054 | word_end = (int)(spell_to_word_end(ptr, wp->w_buffer) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3055 | } |
| 3056 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3057 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3058 | /* bad word found, use attributes until end of word */ |
| 3059 | word_end = wp->w_cursor.col + len + 1; |
| 3060 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3061 | /* Turn index into actual attributes. */ |
| 3062 | if (spell_hlf != HLF_COUNT) |
| 3063 | spell_attr = highlight_attr[spell_hlf]; |
| 3064 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3065 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3066 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3067 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3068 | /* Need to restart syntax highlighting for this line. */ |
| 3069 | if (has_syntax) |
| 3070 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3071 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3072 | } |
| 3073 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | /* |
| 3077 | * Correct highlighting for cursor that can't be disabled. |
| 3078 | * Avoids having to check this for each character. |
| 3079 | */ |
| 3080 | if (fromcol >= 0) |
| 3081 | { |
| 3082 | if (noinvcur) |
| 3083 | { |
| 3084 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3085 | { |
| 3086 | /* highlighting starts at cursor, let it start just after the |
| 3087 | * cursor */ |
| 3088 | fromcol_prev = fromcol; |
| 3089 | fromcol = -1; |
| 3090 | } |
| 3091 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3092 | /* restart highlighting after the cursor */ |
| 3093 | fromcol_prev = wp->w_virtcol; |
| 3094 | } |
| 3095 | if (fromcol >= tocol) |
| 3096 | fromcol = -1; |
| 3097 | } |
| 3098 | |
| 3099 | #ifdef FEAT_SEARCH_EXTRA |
| 3100 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3101 | * Handle highlighting the last used search pattern and matches. |
| 3102 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3103 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3104 | cur = wp->w_match_head; |
| 3105 | shl_flag = FALSE; |
| 3106 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3107 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3108 | if (shl_flag == FALSE) |
| 3109 | { |
| 3110 | shl = &search_hl; |
| 3111 | shl_flag = TRUE; |
| 3112 | } |
| 3113 | else |
| 3114 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3115 | shl->startcol = MAXCOL; |
| 3116 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3117 | shl->attr_cur = 0; |
| 3118 | if (shl->rm.regprog != NULL) |
| 3119 | { |
| 3120 | v = (long)(ptr - line); |
| 3121 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3122 | |
| 3123 | /* Need to get the line again, a multi-line regexp may have made it |
| 3124 | * invalid. */ |
| 3125 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3126 | ptr = line + v; |
| 3127 | |
| 3128 | if (shl->lnum != 0 && shl->lnum <= lnum) |
| 3129 | { |
| 3130 | if (shl->lnum == lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3131 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3132 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3133 | shl->startcol = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3134 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3135 | - shl->rm.startpos[0].lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3136 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3137 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3138 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3139 | /* Highlight one character for an empty match. */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3140 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3141 | { |
| 3142 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3143 | if (has_mbyte && line[shl->endcol] != NUL) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3144 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3145 | else |
| 3146 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3147 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3148 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3149 | if ((long)shl->startcol < v) /* match at leftcol */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3150 | { |
| 3151 | shl->attr_cur = shl->attr; |
| 3152 | search_attr = shl->attr; |
| 3153 | } |
| 3154 | area_highlighting = TRUE; |
| 3155 | } |
| 3156 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3157 | if (shl != &search_hl && cur != NULL) |
| 3158 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3159 | } |
| 3160 | #endif |
| 3161 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3162 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 3163 | /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
| 3164 | * active, because it's not clear what is selected then. */ |
| 3165 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3166 | { |
| 3167 | line_attr = hl_attr(HLF_CUL); |
| 3168 | area_highlighting = TRUE; |
| 3169 | } |
| 3170 | #endif |
| 3171 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3172 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3173 | col = 0; |
| 3174 | #ifdef FEAT_RIGHTLEFT |
| 3175 | if (wp->w_p_rl) |
| 3176 | { |
| 3177 | /* Rightleft window: process the text in the normal direction, but put |
| 3178 | * it in current_ScreenLine[] from right to left. Start at the |
| 3179 | * rightmost column of the window. */ |
| 3180 | col = W_WIDTH(wp) - 1; |
| 3181 | off += col; |
| 3182 | } |
| 3183 | #endif |
| 3184 | |
| 3185 | /* |
| 3186 | * Repeat for the whole displayed line. |
| 3187 | */ |
| 3188 | for (;;) |
| 3189 | { |
| 3190 | /* Skip this quickly when working on the text. */ |
| 3191 | if (draw_state != WL_LINE) |
| 3192 | { |
| 3193 | #ifdef FEAT_CMDWIN |
| 3194 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3195 | { |
| 3196 | draw_state = WL_CMDLINE; |
| 3197 | if (cmdwin_type != 0 && wp == curwin) |
| 3198 | { |
| 3199 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3200 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3201 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3202 | char_attr = hl_attr(HLF_AT); |
| 3203 | } |
| 3204 | } |
| 3205 | #endif |
| 3206 | |
| 3207 | #ifdef FEAT_FOLDING |
| 3208 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3209 | { |
| 3210 | draw_state = WL_FOLD; |
| 3211 | if (wp->w_p_fdc > 0) |
| 3212 | { |
| 3213 | /* Draw the 'foldcolumn'. */ |
| 3214 | fill_foldcolumn(extra, wp, FALSE, lnum); |
| 3215 | n_extra = wp->w_p_fdc; |
| 3216 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3217 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3218 | c_extra = NUL; |
| 3219 | char_attr = hl_attr(HLF_FC); |
| 3220 | } |
| 3221 | } |
| 3222 | #endif |
| 3223 | |
| 3224 | #ifdef FEAT_SIGNS |
| 3225 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3226 | { |
| 3227 | draw_state = WL_SIGN; |
| 3228 | /* Show the sign column when there are any signs in this |
| 3229 | * buffer or when using Netbeans. */ |
| 3230 | if (draw_signcolumn(wp) |
| 3231 | # ifdef FEAT_DIFF |
| 3232 | && filler_todo <= 0 |
| 3233 | # endif |
| 3234 | ) |
| 3235 | { |
| 3236 | int_u text_sign; |
| 3237 | # ifdef FEAT_SIGN_ICONS |
| 3238 | int_u icon_sign; |
| 3239 | # endif |
| 3240 | |
| 3241 | /* Draw two cells with the sign value or blank. */ |
| 3242 | c_extra = ' '; |
| 3243 | char_attr = hl_attr(HLF_SC); |
| 3244 | n_extra = 2; |
| 3245 | |
| 3246 | if (row == startrow) |
| 3247 | { |
| 3248 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3249 | SIGN_TEXT); |
| 3250 | # ifdef FEAT_SIGN_ICONS |
| 3251 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3252 | SIGN_ICON); |
| 3253 | if (gui.in_use && icon_sign != 0) |
| 3254 | { |
| 3255 | /* Use the image in this position. */ |
| 3256 | c_extra = SIGN_BYTE; |
| 3257 | # ifdef FEAT_NETBEANS_INTG |
| 3258 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3259 | c_extra = MULTISIGN_BYTE; |
| 3260 | # endif |
| 3261 | char_attr = icon_sign; |
| 3262 | } |
| 3263 | else |
| 3264 | # endif |
| 3265 | if (text_sign != 0) |
| 3266 | { |
| 3267 | p_extra = sign_get_text(text_sign); |
| 3268 | if (p_extra != NULL) |
| 3269 | { |
| 3270 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3271 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3272 | } |
| 3273 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | } |
| 3278 | #endif |
| 3279 | |
| 3280 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3281 | { |
| 3282 | draw_state = WL_NR; |
| 3283 | /* Display the line number. After the first fill with blanks |
| 3284 | * when the 'n' flag isn't in 'cpo' */ |
| 3285 | if (wp->w_p_nu |
| 3286 | && (row == startrow |
| 3287 | #ifdef FEAT_DIFF |
| 3288 | + filler_lines |
| 3289 | #endif |
| 3290 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3291 | { |
| 3292 | /* Draw the line number (empty space after wrapping). */ |
| 3293 | if (row == startrow |
| 3294 | #ifdef FEAT_DIFF |
| 3295 | + filler_lines |
| 3296 | #endif |
| 3297 | ) |
| 3298 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3299 | sprintf((char *)extra, "%*ld ", |
| 3300 | number_width(wp), (long)lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3301 | if (wp->w_skipcol > 0) |
| 3302 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3303 | *p_extra = '-'; |
| 3304 | #ifdef FEAT_RIGHTLEFT |
| 3305 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3306 | rl_mirror(extra); |
| 3307 | #endif |
| 3308 | p_extra = extra; |
| 3309 | c_extra = NUL; |
| 3310 | } |
| 3311 | else |
| 3312 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3313 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3314 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3315 | #ifdef FEAT_SYN_HL |
| 3316 | /* When 'cursorline' is set highlight the line number of |
| 3317 | * the current line differently. */ |
| 3318 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3319 | char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); |
| 3320 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3325 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3326 | { |
| 3327 | draw_state = WL_SBR; |
| 3328 | # ifdef FEAT_DIFF |
| 3329 | if (filler_todo > 0) |
| 3330 | { |
| 3331 | /* Draw "deleted" diff line(s). */ |
| 3332 | if (char2cells(fill_diff) > 1) |
| 3333 | c_extra = '-'; |
| 3334 | else |
| 3335 | c_extra = fill_diff; |
| 3336 | # ifdef FEAT_RIGHTLEFT |
| 3337 | if (wp->w_p_rl) |
| 3338 | n_extra = col + 1; |
| 3339 | else |
| 3340 | # endif |
| 3341 | n_extra = W_WIDTH(wp) - col; |
| 3342 | char_attr = hl_attr(HLF_DED); |
| 3343 | } |
| 3344 | # endif |
| 3345 | # ifdef FEAT_LINEBREAK |
| 3346 | if (*p_sbr != NUL && need_showbreak) |
| 3347 | { |
| 3348 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3349 | p_extra = p_sbr; |
| 3350 | c_extra = NUL; |
| 3351 | n_extra = (int)STRLEN(p_sbr); |
| 3352 | char_attr = hl_attr(HLF_AT); |
| 3353 | need_showbreak = FALSE; |
| 3354 | /* Correct end of highlighted area for 'showbreak', |
| 3355 | * required when 'linebreak' is also set. */ |
| 3356 | if (tocol == vcol) |
| 3357 | tocol += n_extra; |
| 3358 | } |
| 3359 | # endif |
| 3360 | } |
| 3361 | #endif |
| 3362 | |
| 3363 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3364 | { |
| 3365 | draw_state = WL_LINE; |
| 3366 | if (saved_n_extra) |
| 3367 | { |
| 3368 | /* Continue item from end of wrapped line. */ |
| 3369 | n_extra = saved_n_extra; |
| 3370 | c_extra = saved_c_extra; |
| 3371 | p_extra = saved_p_extra; |
| 3372 | char_attr = saved_char_attr; |
| 3373 | } |
| 3374 | else |
| 3375 | char_attr = 0; |
| 3376 | } |
| 3377 | } |
| 3378 | |
| 3379 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3380 | if (dollar_vcol != 0 && wp == curwin |
| 3381 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3382 | #ifdef FEAT_DIFF |
| 3383 | && filler_todo <= 0 |
| 3384 | #endif |
| 3385 | ) |
| 3386 | { |
| 3387 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3388 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3389 | /* Pretend we have finished updating the window. Except when |
| 3390 | * 'cursorcolumn' is set. */ |
| 3391 | #ifdef FEAT_SYN_HL |
| 3392 | if (wp->w_p_cuc) |
| 3393 | row = wp->w_cline_row + wp->w_cline_height; |
| 3394 | else |
| 3395 | #endif |
| 3396 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3397 | break; |
| 3398 | } |
| 3399 | |
| 3400 | if (draw_state == WL_LINE && area_highlighting) |
| 3401 | { |
| 3402 | /* handle Visual or match highlighting in this line */ |
| 3403 | if (vcol == fromcol |
| 3404 | #ifdef FEAT_MBYTE |
| 3405 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3406 | && (*mb_ptr2cells)(ptr) > 1) |
| 3407 | #endif |
| 3408 | || ((int)vcol_prev == fromcol_prev |
| 3409 | && vcol < tocol)) |
| 3410 | area_attr = attr; /* start highlighting */ |
| 3411 | else if (area_attr != 0 |
| 3412 | && (vcol == tocol |
| 3413 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3414 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3415 | |
| 3416 | #ifdef FEAT_SEARCH_EXTRA |
| 3417 | if (!n_extra) |
| 3418 | { |
| 3419 | /* |
| 3420 | * Check for start/end of search pattern match. |
| 3421 | * After end, check for start/end of next match. |
| 3422 | * When another match, have to check for start again. |
| 3423 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3424 | * Do this for 'search_hl' and the match list (ordered by |
| 3425 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3426 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3427 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3428 | cur = wp->w_match_head; |
| 3429 | shl_flag = FALSE; |
| 3430 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3431 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3432 | if (shl_flag == FALSE |
| 3433 | && ((cur != NULL |
| 3434 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3435 | || cur == NULL)) |
| 3436 | { |
| 3437 | shl = &search_hl; |
| 3438 | shl_flag = TRUE; |
| 3439 | } |
| 3440 | else |
| 3441 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3442 | while (shl->rm.regprog != NULL) |
| 3443 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3444 | if (shl->startcol != MAXCOL |
| 3445 | && v >= (long)shl->startcol |
| 3446 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3447 | { |
| 3448 | shl->attr_cur = shl->attr; |
| 3449 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3450 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3451 | { |
| 3452 | shl->attr_cur = 0; |
| 3453 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3454 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3455 | |
| 3456 | /* Need to get the line again, a multi-line regexp |
| 3457 | * may have made it invalid. */ |
| 3458 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3459 | ptr = line + v; |
| 3460 | |
| 3461 | if (shl->lnum == lnum) |
| 3462 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3463 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3464 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3465 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3466 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3467 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3468 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3469 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3470 | { |
| 3471 | /* highlight empty match, try again after |
| 3472 | * it */ |
| 3473 | #ifdef FEAT_MBYTE |
| 3474 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3475 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3476 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3477 | else |
| 3478 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3479 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | /* Loop to check if the match starts at the |
| 3483 | * current position */ |
| 3484 | continue; |
| 3485 | } |
| 3486 | } |
| 3487 | break; |
| 3488 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3489 | if (shl != &search_hl && cur != NULL) |
| 3490 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3491 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3492 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3493 | /* Use attributes from match with highest priority among |
| 3494 | * 'search_hl' and the match list. */ |
| 3495 | search_attr = search_hl.attr_cur; |
| 3496 | cur = wp->w_match_head; |
| 3497 | shl_flag = FALSE; |
| 3498 | while (cur != NULL || shl_flag == FALSE) |
| 3499 | { |
| 3500 | if (shl_flag == FALSE |
| 3501 | && ((cur != NULL |
| 3502 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3503 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3504 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3505 | shl = &search_hl; |
| 3506 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3507 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3508 | else |
| 3509 | shl = &cur->hl; |
| 3510 | if (shl->attr_cur != 0) |
| 3511 | search_attr = shl->attr_cur; |
| 3512 | if (shl != &search_hl && cur != NULL) |
| 3513 | cur = cur->next; |
| 3514 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3515 | } |
| 3516 | #endif |
| 3517 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3518 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3519 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3520 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3521 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 3522 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3523 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3524 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 3525 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3526 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3527 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3528 | } |
| 3529 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3530 | |
| 3531 | /* Decide which of the highlight attributes to use. */ |
| 3532 | attr_pri = TRUE; |
| 3533 | if (area_attr != 0) |
| 3534 | char_attr = area_attr; |
| 3535 | else if (search_attr != 0) |
| 3536 | char_attr = search_attr; |
| 3537 | #ifdef LINE_ATTR |
| 3538 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 3539 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 3540 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
| 3541 | || (vcol < fromcol || vcol >= tocol))) |
| 3542 | char_attr = line_attr; |
| 3543 | #endif |
| 3544 | else |
| 3545 | { |
| 3546 | attr_pri = FALSE; |
| 3547 | #ifdef FEAT_SYN_HL |
| 3548 | if (has_syntax) |
| 3549 | char_attr = syntax_attr; |
| 3550 | else |
| 3551 | #endif |
| 3552 | char_attr = 0; |
| 3553 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | /* |
| 3557 | * Get the next character to put on the screen. |
| 3558 | */ |
| 3559 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3560 | * The "p_extra" points to the extra stuff that is inserted to |
| 3561 | * represent special characters (non-printable stuff) and other |
| 3562 | * things. When all characters are the same, c_extra is used. |
| 3563 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 3564 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3565 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 3566 | */ |
| 3567 | if (n_extra > 0) |
| 3568 | { |
| 3569 | if (c_extra != NUL) |
| 3570 | { |
| 3571 | c = c_extra; |
| 3572 | #ifdef FEAT_MBYTE |
| 3573 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 3574 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3575 | { |
| 3576 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3577 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3578 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3579 | } |
| 3580 | else |
| 3581 | mb_utf8 = FALSE; |
| 3582 | #endif |
| 3583 | } |
| 3584 | else |
| 3585 | { |
| 3586 | c = *p_extra; |
| 3587 | #ifdef FEAT_MBYTE |
| 3588 | if (has_mbyte) |
| 3589 | { |
| 3590 | mb_c = c; |
| 3591 | if (enc_utf8) |
| 3592 | { |
| 3593 | /* If the UTF-8 character is more than one byte: |
| 3594 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3595 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3596 | mb_utf8 = FALSE; |
| 3597 | if (mb_l > n_extra) |
| 3598 | mb_l = 1; |
| 3599 | else if (mb_l > 1) |
| 3600 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3601 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3602 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3603 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3604 | } |
| 3605 | } |
| 3606 | else |
| 3607 | { |
| 3608 | /* if this is a DBCS character, put it in "mb_c" */ |
| 3609 | mb_l = MB_BYTE2LEN(c); |
| 3610 | if (mb_l >= n_extra) |
| 3611 | mb_l = 1; |
| 3612 | else if (mb_l > 1) |
| 3613 | mb_c = (c << 8) + p_extra[1]; |
| 3614 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3615 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3616 | mb_l = 1; |
| 3617 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3618 | /* If a double-width char doesn't fit display a '>' in the |
| 3619 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3620 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3621 | # ifdef FEAT_RIGHTLEFT |
| 3622 | wp->w_p_rl ? (col <= 0) : |
| 3623 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3624 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3625 | && (*mb_char2cells)(mb_c) == 2) |
| 3626 | { |
| 3627 | c = '>'; |
| 3628 | mb_c = c; |
| 3629 | mb_l = 1; |
| 3630 | mb_utf8 = FALSE; |
| 3631 | multi_attr = hl_attr(HLF_AT); |
| 3632 | /* put the pointer back to output the double-width |
| 3633 | * character at the start of the next line. */ |
| 3634 | ++n_extra; |
| 3635 | --p_extra; |
| 3636 | } |
| 3637 | else |
| 3638 | { |
| 3639 | n_extra -= mb_l - 1; |
| 3640 | p_extra += mb_l - 1; |
| 3641 | } |
| 3642 | } |
| 3643 | #endif |
| 3644 | ++p_extra; |
| 3645 | } |
| 3646 | --n_extra; |
| 3647 | } |
| 3648 | else |
| 3649 | { |
| 3650 | /* |
| 3651 | * Get a character from the line itself. |
| 3652 | */ |
| 3653 | c = *ptr; |
| 3654 | #ifdef FEAT_MBYTE |
| 3655 | if (has_mbyte) |
| 3656 | { |
| 3657 | mb_c = c; |
| 3658 | if (enc_utf8) |
| 3659 | { |
| 3660 | /* If the UTF-8 character is more than one byte: Decode it |
| 3661 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3662 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3663 | mb_utf8 = FALSE; |
| 3664 | if (mb_l > 1) |
| 3665 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3666 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3667 | /* Overlong encoded ASCII or ASCII with composing char |
| 3668 | * is displayed normally, except a NUL. */ |
| 3669 | if (mb_c < 0x80) |
| 3670 | c = mb_c; |
| 3671 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3672 | |
| 3673 | /* At start of the line we can have a composing char. |
| 3674 | * Draw it as a space with a composing char. */ |
| 3675 | if (utf_iscomposing(mb_c)) |
| 3676 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3677 | int i; |
| 3678 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3679 | for (i = Screen_mco - 1; i > 0; --i) |
| 3680 | u8cc[i] = u8cc[i - 1]; |
| 3681 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3682 | mb_c = ' '; |
| 3683 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | if ((mb_l == 1 && c >= 0x80) |
| 3687 | || (mb_l >= 1 && mb_c == 0) |
| 3688 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3689 | # ifdef UNICODE16 |
| 3690 | || mb_c >= 0x10000 |
| 3691 | # endif |
| 3692 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3693 | { |
| 3694 | /* |
| 3695 | * Illegal UTF-8 byte: display as <xx>. |
| 3696 | * Non-BMP character : display as ? or fullwidth ?. |
| 3697 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3698 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3699 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3700 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3701 | { |
| 3702 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3703 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3704 | if (wp->w_p_rl) /* reverse */ |
| 3705 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3706 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3707 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3708 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3709 | else if (utf_char2cells(mb_c) != 2) |
| 3710 | STRCPY(extra, "?"); |
| 3711 | else |
| 3712 | /* 0xff1f in UTF-8: full-width '?' */ |
| 3713 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3714 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3715 | |
| 3716 | p_extra = extra; |
| 3717 | c = *p_extra; |
| 3718 | mb_c = mb_ptr2char_adv(&p_extra); |
| 3719 | mb_utf8 = (c >= 0x80); |
| 3720 | n_extra = (int)STRLEN(p_extra); |
| 3721 | c_extra = NUL; |
| 3722 | if (area_attr == 0 && search_attr == 0) |
| 3723 | { |
| 3724 | n_attr = n_extra + 1; |
| 3725 | extra_attr = hl_attr(HLF_8); |
| 3726 | saved_attr2 = char_attr; /* save current attr */ |
| 3727 | } |
| 3728 | } |
| 3729 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3730 | mb_l = 1; |
| 3731 | #ifdef FEAT_ARABIC |
| 3732 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 3733 | { |
| 3734 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3735 | int pc, pc1, nc; |
| 3736 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3737 | |
| 3738 | /* The idea of what is the previous and next |
| 3739 | * character depends on 'rightleft'. */ |
| 3740 | if (wp->w_p_rl) |
| 3741 | { |
| 3742 | pc = prev_c; |
| 3743 | pc1 = prev_c1; |
| 3744 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3745 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3746 | } |
| 3747 | else |
| 3748 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3749 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3750 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3751 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3752 | } |
| 3753 | prev_c = mb_c; |
| 3754 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3755 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3756 | } |
| 3757 | else |
| 3758 | prev_c = mb_c; |
| 3759 | #endif |
| 3760 | } |
| 3761 | else /* enc_dbcs */ |
| 3762 | { |
| 3763 | mb_l = MB_BYTE2LEN(c); |
| 3764 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3765 | mb_l = 1; |
| 3766 | else if (mb_l > 1) |
| 3767 | { |
| 3768 | /* We assume a second byte below 32 is illegal. |
| 3769 | * Hopefully this is OK for all double-byte encodings! |
| 3770 | */ |
| 3771 | if (ptr[1] >= 32) |
| 3772 | mb_c = (c << 8) + ptr[1]; |
| 3773 | else |
| 3774 | { |
| 3775 | if (ptr[1] == NUL) |
| 3776 | { |
| 3777 | /* head byte at end of line */ |
| 3778 | mb_l = 1; |
| 3779 | transchar_nonprint(extra, c); |
| 3780 | } |
| 3781 | else |
| 3782 | { |
| 3783 | /* illegal tail byte */ |
| 3784 | mb_l = 2; |
| 3785 | STRCPY(extra, "XX"); |
| 3786 | } |
| 3787 | p_extra = extra; |
| 3788 | n_extra = (int)STRLEN(extra) - 1; |
| 3789 | c_extra = NUL; |
| 3790 | c = *p_extra++; |
| 3791 | if (area_attr == 0 && search_attr == 0) |
| 3792 | { |
| 3793 | n_attr = n_extra + 1; |
| 3794 | extra_attr = hl_attr(HLF_8); |
| 3795 | saved_attr2 = char_attr; /* save current attr */ |
| 3796 | } |
| 3797 | mb_c = c; |
| 3798 | } |
| 3799 | } |
| 3800 | } |
| 3801 | /* If a double-width char doesn't fit display a '>' in the |
| 3802 | * last column; the character is displayed at the start of the |
| 3803 | * next line. */ |
| 3804 | if (( |
| 3805 | # ifdef FEAT_RIGHTLEFT |
| 3806 | wp->w_p_rl ? (col <= 0) : |
| 3807 | # endif |
| 3808 | (col >= W_WIDTH(wp) - 1)) |
| 3809 | && (*mb_char2cells)(mb_c) == 2) |
| 3810 | { |
| 3811 | c = '>'; |
| 3812 | mb_c = c; |
| 3813 | mb_utf8 = FALSE; |
| 3814 | mb_l = 1; |
| 3815 | multi_attr = hl_attr(HLF_AT); |
| 3816 | /* Put pointer back so that the character will be |
| 3817 | * displayed at the start of the next line. */ |
| 3818 | --ptr; |
| 3819 | } |
| 3820 | else if (*ptr != NUL) |
| 3821 | ptr += mb_l - 1; |
| 3822 | |
| 3823 | /* If a double-width char doesn't fit at the left side display |
| 3824 | * a '<' in the first column. */ |
| 3825 | if (n_skip > 0 && mb_l > 1) |
| 3826 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3827 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3828 | c_extra = '<'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3829 | c = ' '; |
| 3830 | if (area_attr == 0 && search_attr == 0) |
| 3831 | { |
| 3832 | n_attr = n_extra + 1; |
| 3833 | extra_attr = hl_attr(HLF_AT); |
| 3834 | saved_attr2 = char_attr; /* save current attr */ |
| 3835 | } |
| 3836 | mb_c = c; |
| 3837 | mb_utf8 = FALSE; |
| 3838 | mb_l = 1; |
| 3839 | } |
| 3840 | |
| 3841 | } |
| 3842 | #endif |
| 3843 | ++ptr; |
| 3844 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3845 | /* 'list' : change char 160 to lcs_nbsp. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3846 | if (wp->w_p_list && (c == 160 |
| 3847 | #ifdef FEAT_MBYTE |
| 3848 | || (mb_utf8 && mb_c == 160) |
| 3849 | #endif |
| 3850 | ) && lcs_nbsp) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3851 | { |
| 3852 | c = lcs_nbsp; |
| 3853 | if (area_attr == 0 && search_attr == 0) |
| 3854 | { |
| 3855 | n_attr = 1; |
| 3856 | extra_attr = hl_attr(HLF_8); |
| 3857 | saved_attr2 = char_attr; /* save current attr */ |
| 3858 | } |
| 3859 | #ifdef FEAT_MBYTE |
| 3860 | mb_c = c; |
| 3861 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3862 | { |
| 3863 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3864 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3865 | c = 0xc0; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3866 | } |
| 3867 | else |
| 3868 | mb_utf8 = FALSE; |
| 3869 | #endif |
| 3870 | } |
| 3871 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3872 | if (extra_check) |
| 3873 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3874 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3875 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3876 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3877 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3878 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3879 | /* Get syntax attribute, unless still at the start of the line |
| 3880 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3881 | v = (long)(ptr - line); |
| 3882 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3883 | { |
| 3884 | /* Get the syntax attribute for the character. If there |
| 3885 | * is an error, disable syntax highlighting. */ |
| 3886 | save_did_emsg = did_emsg; |
| 3887 | did_emsg = FALSE; |
| 3888 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3889 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3890 | # ifdef FEAT_SPELL |
| 3891 | has_spell ? &can_spell : |
| 3892 | # endif |
Bram Moolenaar | 56cefaf | 2008-01-12 15:47:10 +0000 | [diff] [blame] | 3893 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3894 | |
| 3895 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 3896 | { |
| 3897 | wp->w_buffer->b_syn_error = TRUE; |
| 3898 | has_syntax = FALSE; |
| 3899 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3900 | else |
| 3901 | did_emsg = save_did_emsg; |
| 3902 | |
| 3903 | /* Need to get the line again, a multi-line regexp may |
| 3904 | * have made it invalid. */ |
| 3905 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3906 | ptr = line + v; |
| 3907 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3908 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3909 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3910 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 3911 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3912 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3913 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3914 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3915 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3916 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 3917 | * Only do this when there is no syntax highlighting, the |
| 3918 | * @Spell cluster is not used or the current syntax item |
| 3919 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3920 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3921 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 3922 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3923 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3924 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 3925 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3926 | # endif |
| 3927 | if (c != 0 && ( |
| 3928 | # ifdef FEAT_SYN_HL |
| 3929 | !has_syntax || |
| 3930 | # endif |
| 3931 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3932 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3933 | char_u *prev_ptr, *p; |
| 3934 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3935 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3936 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 3937 | if (has_mbyte) |
| 3938 | { |
| 3939 | prev_ptr = ptr - mb_l; |
| 3940 | v -= mb_l - 1; |
| 3941 | } |
| 3942 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3943 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 3944 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3945 | |
| 3946 | /* Use nextline[] if possible, it has the start of the |
| 3947 | * next line concatenated. */ |
| 3948 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 3949 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 3950 | else |
| 3951 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3952 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 3953 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 3954 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3955 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3956 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3957 | /* In Insert mode only highlight a word that |
| 3958 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3959 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3960 | && (State & INSERT) != 0 |
| 3961 | && wp->w_cursor.lnum == lnum |
| 3962 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3963 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3964 | && wp->w_cursor.col < (colnr_T)word_end) |
| 3965 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3966 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3967 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3968 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3969 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3970 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3971 | && (p - nextline) + len > nextline_idx) |
| 3972 | { |
| 3973 | /* Remember that the good word continues at the |
| 3974 | * start of the next line. */ |
| 3975 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3976 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3977 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3978 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3979 | /* Turn index into actual attributes. */ |
| 3980 | if (spell_hlf != HLF_COUNT) |
| 3981 | spell_attr = highlight_attr[spell_hlf]; |
| 3982 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3983 | if (cap_col > 0) |
| 3984 | { |
| 3985 | if (p != prev_ptr |
| 3986 | && (p - nextline) + cap_col >= nextline_idx) |
| 3987 | { |
| 3988 | /* Remember that the word in the next line |
| 3989 | * must start with a capital. */ |
| 3990 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3991 | cap_col = (int)((p - nextline) + cap_col |
| 3992 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3993 | } |
| 3994 | else |
| 3995 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3996 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3997 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3998 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3999 | } |
| 4000 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4001 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4002 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4003 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4004 | else |
| 4005 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4006 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4007 | #endif |
| 4008 | #ifdef FEAT_LINEBREAK |
| 4009 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4010 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4011 | */ |
| 4012 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4013 | && !wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4014 | { |
| 4015 | n_extra = win_lbr_chartabsize(wp, ptr - ( |
| 4016 | # ifdef FEAT_MBYTE |
| 4017 | has_mbyte ? mb_l : |
| 4018 | # endif |
| 4019 | 1), (colnr_T)vcol, NULL) - 1; |
| 4020 | c_extra = ' '; |
| 4021 | if (vim_iswhite(c)) |
| 4022 | c = ' '; |
| 4023 | } |
| 4024 | #endif |
| 4025 | |
| 4026 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4027 | { |
| 4028 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4029 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4030 | { |
| 4031 | n_attr = 1; |
| 4032 | extra_attr = hl_attr(HLF_8); |
| 4033 | saved_attr2 = char_attr; /* save current attr */ |
| 4034 | } |
| 4035 | #ifdef FEAT_MBYTE |
| 4036 | mb_c = c; |
| 4037 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4038 | { |
| 4039 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4040 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4041 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4042 | } |
| 4043 | else |
| 4044 | mb_utf8 = FALSE; |
| 4045 | #endif |
| 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | /* |
| 4050 | * Handling of non-printable characters. |
| 4051 | */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4052 | if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4053 | { |
| 4054 | /* |
| 4055 | * when getting a character from the file, we may have to |
| 4056 | * turn it into something else on the way to putting it |
| 4057 | * into "ScreenLines". |
| 4058 | */ |
| 4059 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4060 | { |
| 4061 | /* tab amount depends on current column */ |
| 4062 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4063 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4064 | #ifdef FEAT_MBYTE |
| 4065 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4066 | #endif |
| 4067 | if (wp->w_p_list) |
| 4068 | { |
| 4069 | c = lcs_tab1; |
| 4070 | c_extra = lcs_tab2; |
| 4071 | n_attr = n_extra + 1; |
| 4072 | extra_attr = hl_attr(HLF_8); |
| 4073 | saved_attr2 = char_attr; /* save current attr */ |
| 4074 | #ifdef FEAT_MBYTE |
| 4075 | mb_c = c; |
| 4076 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4077 | { |
| 4078 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4079 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4080 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4081 | } |
| 4082 | #endif |
| 4083 | } |
| 4084 | else |
| 4085 | { |
| 4086 | c_extra = ' '; |
| 4087 | c = ' '; |
| 4088 | } |
| 4089 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4090 | else if (c == NUL |
| 4091 | && ((wp->w_p_list && lcs_eol > 0) |
| 4092 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4093 | && tocol > vcol |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4094 | #ifdef FEAT_VISUAL |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4095 | && VIsual_mode != Ctrl_V |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4096 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4097 | && ( |
| 4098 | # ifdef FEAT_RIGHTLEFT |
| 4099 | wp->w_p_rl ? (col >= 0) : |
| 4100 | # endif |
| 4101 | (col < W_WIDTH(wp))) |
| 4102 | && !(noinvcur |
| 4103 | && (colnr_T)vcol == wp->w_virtcol))) |
| 4104 | && lcs_eol_one >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4105 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4106 | /* Display a '$' after the line or highlight an extra |
| 4107 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4108 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4109 | /* For a diff line the highlighting continues after the |
| 4110 | * "$". */ |
| 4111 | if ( |
| 4112 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4113 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4114 | # ifdef LINE_ATTR |
| 4115 | && |
| 4116 | # endif |
| 4117 | # endif |
| 4118 | # ifdef LINE_ATTR |
| 4119 | line_attr == 0 |
| 4120 | # endif |
| 4121 | ) |
| 4122 | #endif |
| 4123 | { |
| 4124 | #ifdef FEAT_VIRTUALEDIT |
| 4125 | /* In virtualedit, visual selections may extend |
| 4126 | * beyond end of line. */ |
| 4127 | if (area_highlighting && virtual_active() |
| 4128 | && tocol != MAXCOL && vcol < tocol) |
| 4129 | n_extra = 0; |
| 4130 | else |
| 4131 | #endif |
| 4132 | { |
| 4133 | p_extra = at_end_str; |
| 4134 | n_extra = 1; |
| 4135 | c_extra = NUL; |
| 4136 | } |
| 4137 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4138 | if (wp->w_p_list) |
| 4139 | c = lcs_eol; |
| 4140 | else |
| 4141 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4142 | lcs_eol_one = -1; |
| 4143 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4144 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4145 | { |
| 4146 | extra_attr = hl_attr(HLF_AT); |
| 4147 | n_attr = 1; |
| 4148 | } |
| 4149 | #ifdef FEAT_MBYTE |
| 4150 | mb_c = c; |
| 4151 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4152 | { |
| 4153 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4154 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4155 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4156 | } |
| 4157 | else |
| 4158 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4159 | #endif |
| 4160 | } |
| 4161 | else if (c != NUL) |
| 4162 | { |
| 4163 | p_extra = transchar(c); |
| 4164 | #ifdef FEAT_RIGHTLEFT |
| 4165 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4166 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4167 | #endif |
| 4168 | n_extra = byte2cells(c) - 1; |
| 4169 | c_extra = NUL; |
| 4170 | c = *p_extra++; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4171 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4172 | { |
| 4173 | n_attr = n_extra + 1; |
| 4174 | extra_attr = hl_attr(HLF_8); |
| 4175 | saved_attr2 = char_attr; /* save current attr */ |
| 4176 | } |
| 4177 | #ifdef FEAT_MBYTE |
| 4178 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4179 | #endif |
| 4180 | } |
| 4181 | #ifdef FEAT_VIRTUALEDIT |
| 4182 | else if (VIsual_active |
| 4183 | && (VIsual_mode == Ctrl_V |
| 4184 | || VIsual_mode == 'v') |
| 4185 | && virtual_active() |
| 4186 | && tocol != MAXCOL |
| 4187 | && vcol < tocol |
| 4188 | && ( |
| 4189 | # ifdef FEAT_RIGHTLEFT |
| 4190 | wp->w_p_rl ? (col >= 0) : |
| 4191 | # endif |
| 4192 | (col < W_WIDTH(wp)))) |
| 4193 | { |
| 4194 | c = ' '; |
| 4195 | --ptr; /* put it back at the NUL */ |
| 4196 | } |
| 4197 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4198 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4199 | else if (( |
| 4200 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4201 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4202 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4203 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4204 | ) && ( |
| 4205 | # ifdef FEAT_RIGHTLEFT |
| 4206 | wp->w_p_rl ? (col >= 0) : |
| 4207 | # endif |
| 4208 | (col < W_WIDTH(wp)))) |
| 4209 | { |
| 4210 | /* Highlight until the right side of the window */ |
| 4211 | c = ' '; |
| 4212 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4213 | |
| 4214 | /* Remember we do the char for line highlighting. */ |
| 4215 | ++did_line_attr; |
| 4216 | |
| 4217 | /* don't do search HL for the rest of the line */ |
| 4218 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4219 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4220 | # ifdef FEAT_DIFF |
| 4221 | if (diff_hlf == HLF_TXD) |
| 4222 | { |
| 4223 | diff_hlf = HLF_CHD; |
| 4224 | if (attr == 0 || char_attr != attr) |
| 4225 | char_attr = hl_attr(diff_hlf); |
| 4226 | } |
| 4227 | # endif |
| 4228 | } |
| 4229 | #endif |
| 4230 | } |
| 4231 | } |
| 4232 | |
| 4233 | /* Don't override visual selection highlighting. */ |
| 4234 | if (n_attr > 0 |
| 4235 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4236 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4237 | char_attr = extra_attr; |
| 4238 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4239 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4240 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4241 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4242 | * im_is_preediting() here. */ |
| 4243 | if (xic != NULL |
| 4244 | && lnum == curwin->w_cursor.lnum |
| 4245 | && (State & INSERT) |
| 4246 | && !p_imdisable |
| 4247 | && im_is_preediting() |
| 4248 | && draw_state == WL_LINE) |
| 4249 | { |
| 4250 | colnr_T tcol; |
| 4251 | |
| 4252 | if (preedit_end_col == MAXCOL) |
| 4253 | getvcol(curwin, &(curwin->w_cursor), &tcol, NULL, NULL); |
| 4254 | else |
| 4255 | tcol = preedit_end_col; |
| 4256 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 4257 | { |
| 4258 | if (feedback_old_attr < 0) |
| 4259 | { |
| 4260 | feedback_col = 0; |
| 4261 | feedback_old_attr = char_attr; |
| 4262 | } |
| 4263 | char_attr = im_get_feedback_attr(feedback_col); |
| 4264 | if (char_attr < 0) |
| 4265 | char_attr = feedback_old_attr; |
| 4266 | feedback_col++; |
| 4267 | } |
| 4268 | else if (feedback_old_attr >= 0) |
| 4269 | { |
| 4270 | char_attr = feedback_old_attr; |
| 4271 | feedback_old_attr = -1; |
| 4272 | feedback_col = 0; |
| 4273 | } |
| 4274 | } |
| 4275 | #endif |
| 4276 | /* |
| 4277 | * Handle the case where we are in column 0 but not on the first |
| 4278 | * character of the line and the user wants us to show us a |
| 4279 | * special character (via 'listchars' option "precedes:<char>". |
| 4280 | */ |
| 4281 | if (lcs_prec_todo != NUL |
| 4282 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 4283 | #ifdef FEAT_DIFF |
| 4284 | && filler_todo <= 0 |
| 4285 | #endif |
| 4286 | && draw_state > WL_NR |
| 4287 | && c != NUL) |
| 4288 | { |
| 4289 | c = lcs_prec; |
| 4290 | lcs_prec_todo = NUL; |
| 4291 | #ifdef FEAT_MBYTE |
| 4292 | mb_c = c; |
| 4293 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4294 | { |
| 4295 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4296 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4297 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4298 | } |
| 4299 | else |
| 4300 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4301 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4302 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4303 | { |
| 4304 | saved_attr3 = char_attr; /* save current attr */ |
| 4305 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 4306 | n_attr3 = 1; |
| 4307 | } |
| 4308 | } |
| 4309 | |
| 4310 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4311 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4312 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4313 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4314 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4315 | || did_line_attr == 1 |
| 4316 | #endif |
| 4317 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4318 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4319 | #ifdef FEAT_SEARCH_EXTRA |
| 4320 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4321 | |
| 4322 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 4323 | if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4324 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4325 | #endif |
| 4326 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4327 | /* invert at least one char, used for Visual and empty line or |
| 4328 | * highlight match at end of line. If it's beyond the last |
| 4329 | * char on the screen, just overwrite that one (tricky!) Not |
| 4330 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4331 | #ifdef FEAT_SEARCH_EXTRA |
| 4332 | prevcol_hl_flag = FALSE; |
| 4333 | if (prevcol == (long)search_hl.startcol) |
| 4334 | prevcol_hl_flag = TRUE; |
| 4335 | else |
| 4336 | { |
| 4337 | cur = wp->w_match_head; |
| 4338 | while (cur != NULL) |
| 4339 | { |
| 4340 | if (prevcol == (long)cur->hl.startcol) |
| 4341 | { |
| 4342 | prevcol_hl_flag = TRUE; |
| 4343 | break; |
| 4344 | } |
| 4345 | cur = cur->next; |
| 4346 | } |
| 4347 | } |
| 4348 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4349 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4350 | && ((area_attr != 0 && vcol == fromcol && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4351 | #ifdef FEAT_SEARCH_EXTRA |
| 4352 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4353 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4354 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4355 | && did_line_attr <= 1 |
| 4356 | # endif |
| 4357 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4358 | #endif |
| 4359 | )) |
| 4360 | { |
| 4361 | int n = 0; |
| 4362 | |
| 4363 | #ifdef FEAT_RIGHTLEFT |
| 4364 | if (wp->w_p_rl) |
| 4365 | { |
| 4366 | if (col < 0) |
| 4367 | n = 1; |
| 4368 | } |
| 4369 | else |
| 4370 | #endif |
| 4371 | { |
| 4372 | if (col >= W_WIDTH(wp)) |
| 4373 | n = -1; |
| 4374 | } |
| 4375 | if (n != 0) |
| 4376 | { |
| 4377 | /* At the window boundary, highlight the last character |
| 4378 | * instead (better than nothing). */ |
| 4379 | off += n; |
| 4380 | col += n; |
| 4381 | } |
| 4382 | else |
| 4383 | { |
| 4384 | /* Add a blank character to highlight. */ |
| 4385 | ScreenLines[off] = ' '; |
| 4386 | #ifdef FEAT_MBYTE |
| 4387 | if (enc_utf8) |
| 4388 | ScreenLinesUC[off] = 0; |
| 4389 | #endif |
| 4390 | } |
| 4391 | #ifdef FEAT_SEARCH_EXTRA |
| 4392 | if (area_attr == 0) |
| 4393 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4394 | /* Use attributes from match with highest priority among |
| 4395 | * 'search_hl' and the match list. */ |
| 4396 | char_attr = search_hl.attr; |
| 4397 | cur = wp->w_match_head; |
| 4398 | shl_flag = FALSE; |
| 4399 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4400 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4401 | if (shl_flag == FALSE |
| 4402 | && ((cur != NULL |
| 4403 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4404 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4405 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4406 | shl = &search_hl; |
| 4407 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4408 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4409 | else |
| 4410 | shl = &cur->hl; |
| 4411 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 4412 | char_attr = shl->attr; |
| 4413 | if (shl != &search_hl && cur != NULL) |
| 4414 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4415 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4416 | } |
| 4417 | #endif |
| 4418 | ScreenAttrs[off] = char_attr; |
| 4419 | #ifdef FEAT_RIGHTLEFT |
| 4420 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4421 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4422 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4423 | --off; |
| 4424 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4425 | else |
| 4426 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4427 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4428 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4429 | ++off; |
| 4430 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4431 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4432 | #ifdef FEAT_SYN_HL |
| 4433 | eol_hl_off = 1; |
| 4434 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4435 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4436 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4437 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4438 | /* |
| 4439 | * At end of the text line. |
| 4440 | */ |
| 4441 | if (c == NUL) |
| 4442 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4443 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4444 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol) |
| 4445 | { |
| 4446 | /* highlight last char after line */ |
| 4447 | --col; |
| 4448 | --off; |
| 4449 | --vcol; |
| 4450 | } |
| 4451 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4452 | /* Highlight 'cursorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 4453 | if (wp->w_p_wrap) |
| 4454 | v = wp->w_skipcol; |
| 4455 | else |
| 4456 | v = wp->w_leftcol; |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4457 | /* check if line ends before left margin */ |
| 4458 | if (vcol < v + col - win_col_off(wp)) |
| 4459 | |
| 4460 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4461 | if (wp->w_p_cuc |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4462 | && (int)wp->w_virtcol >= vcol - eol_hl_off |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4463 | && (int)wp->w_virtcol < W_WIDTH(wp) * (row - startrow + 1) |
| 4464 | + v |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4465 | && lnum != wp->w_cursor.lnum |
| 4466 | # ifdef FEAT_RIGHTLEFT |
| 4467 | && !wp->w_p_rl |
| 4468 | # endif |
| 4469 | ) |
| 4470 | { |
| 4471 | while (col < W_WIDTH(wp)) |
| 4472 | { |
| 4473 | ScreenLines[off] = ' '; |
| 4474 | #ifdef FEAT_MBYTE |
| 4475 | if (enc_utf8) |
| 4476 | ScreenLinesUC[off] = 0; |
| 4477 | #endif |
| 4478 | ++col; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4479 | if (vcol == (long)wp->w_virtcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4480 | { |
| 4481 | ScreenAttrs[off] = hl_attr(HLF_CUC); |
| 4482 | break; |
| 4483 | } |
| 4484 | ScreenAttrs[off++] = 0; |
| 4485 | ++vcol; |
| 4486 | } |
| 4487 | } |
| 4488 | #endif |
| 4489 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4490 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), |
| 4491 | wp->w_p_rl); |
| 4492 | row++; |
| 4493 | |
| 4494 | /* |
| 4495 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 4496 | * updated (saves a call to plines() later). |
| 4497 | */ |
| 4498 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 4499 | { |
| 4500 | curwin->w_cline_row = startrow; |
| 4501 | curwin->w_cline_height = row - startrow; |
| 4502 | #ifdef FEAT_FOLDING |
| 4503 | curwin->w_cline_folded = FALSE; |
| 4504 | #endif |
| 4505 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 4506 | } |
| 4507 | |
| 4508 | break; |
| 4509 | } |
| 4510 | |
| 4511 | /* line continues beyond line end */ |
| 4512 | if (lcs_ext |
| 4513 | && !wp->w_p_wrap |
| 4514 | #ifdef FEAT_DIFF |
| 4515 | && filler_todo <= 0 |
| 4516 | #endif |
| 4517 | && ( |
| 4518 | #ifdef FEAT_RIGHTLEFT |
| 4519 | wp->w_p_rl ? col == 0 : |
| 4520 | #endif |
| 4521 | col == W_WIDTH(wp) - 1) |
| 4522 | && (*ptr != NUL |
| 4523 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
| 4524 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 4525 | { |
| 4526 | c = lcs_ext; |
| 4527 | char_attr = hl_attr(HLF_AT); |
| 4528 | #ifdef FEAT_MBYTE |
| 4529 | mb_c = c; |
| 4530 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4531 | { |
| 4532 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4533 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4534 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4535 | } |
| 4536 | else |
| 4537 | mb_utf8 = FALSE; |
| 4538 | #endif |
| 4539 | } |
| 4540 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4541 | #ifdef FEAT_SYN_HL |
| 4542 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
| 4543 | * highlight the cursor position itself. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4544 | if (wp->w_p_cuc && vcol == (long)wp->w_virtcol |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4545 | && lnum != wp->w_cursor.lnum |
| 4546 | && draw_state == WL_LINE) |
| 4547 | { |
| 4548 | vcol_save_attr = char_attr; |
| 4549 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 4550 | } |
| 4551 | else |
| 4552 | vcol_save_attr = -1; |
| 4553 | #endif |
| 4554 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4555 | /* |
| 4556 | * Store character to be displayed. |
| 4557 | * Skip characters that are left of the screen for 'nowrap'. |
| 4558 | */ |
| 4559 | vcol_prev = vcol; |
| 4560 | if (draw_state < WL_LINE || n_skip <= 0) |
| 4561 | { |
| 4562 | /* |
| 4563 | * Store the character. |
| 4564 | */ |
| 4565 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 4566 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 4567 | { |
| 4568 | /* A double-wide character is: put first halve in left cell. */ |
| 4569 | --off; |
| 4570 | --col; |
| 4571 | } |
| 4572 | #endif |
| 4573 | ScreenLines[off] = c; |
| 4574 | #ifdef FEAT_MBYTE |
| 4575 | if (enc_dbcs == DBCS_JPNU) |
| 4576 | ScreenLines2[off] = mb_c & 0xff; |
| 4577 | else if (enc_utf8) |
| 4578 | { |
| 4579 | if (mb_utf8) |
| 4580 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4581 | int i; |
| 4582 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4583 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4584 | if ((c & 0xff) == 0) |
| 4585 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4586 | for (i = 0; i < Screen_mco; ++i) |
| 4587 | { |
| 4588 | ScreenLinesC[i][off] = u8cc[i]; |
| 4589 | if (u8cc[i] == 0) |
| 4590 | break; |
| 4591 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4592 | } |
| 4593 | else |
| 4594 | ScreenLinesUC[off] = 0; |
| 4595 | } |
| 4596 | if (multi_attr) |
| 4597 | { |
| 4598 | ScreenAttrs[off] = multi_attr; |
| 4599 | multi_attr = 0; |
| 4600 | } |
| 4601 | else |
| 4602 | #endif |
| 4603 | ScreenAttrs[off] = char_attr; |
| 4604 | |
| 4605 | #ifdef FEAT_MBYTE |
| 4606 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4607 | { |
| 4608 | /* Need to fill two screen columns. */ |
| 4609 | ++off; |
| 4610 | ++col; |
| 4611 | if (enc_utf8) |
| 4612 | /* UTF-8: Put a 0 in the second screen char. */ |
| 4613 | ScreenLines[off] = 0; |
| 4614 | else |
| 4615 | /* DBCS: Put second byte in the second screen char. */ |
| 4616 | ScreenLines[off] = mb_c & 0xff; |
| 4617 | ++vcol; |
| 4618 | /* When "tocol" is halfway a character, set it to the end of |
| 4619 | * the character, otherwise highlighting won't stop. */ |
| 4620 | if (tocol == vcol) |
| 4621 | ++tocol; |
| 4622 | #ifdef FEAT_RIGHTLEFT |
| 4623 | if (wp->w_p_rl) |
| 4624 | { |
| 4625 | /* now it's time to backup one cell */ |
| 4626 | --off; |
| 4627 | --col; |
| 4628 | } |
| 4629 | #endif |
| 4630 | } |
| 4631 | #endif |
| 4632 | #ifdef FEAT_RIGHTLEFT |
| 4633 | if (wp->w_p_rl) |
| 4634 | { |
| 4635 | --off; |
| 4636 | --col; |
| 4637 | } |
| 4638 | else |
| 4639 | #endif |
| 4640 | { |
| 4641 | ++off; |
| 4642 | ++col; |
| 4643 | } |
| 4644 | } |
| 4645 | else |
| 4646 | --n_skip; |
| 4647 | |
| 4648 | /* Only advance the "vcol" when after the 'number' column. */ |
| 4649 | if (draw_state >= WL_SBR |
| 4650 | #ifdef FEAT_DIFF |
| 4651 | && filler_todo <= 0 |
| 4652 | #endif |
| 4653 | ) |
| 4654 | ++vcol; |
| 4655 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4656 | #ifdef FEAT_SYN_HL |
| 4657 | if (vcol_save_attr >= 0) |
| 4658 | char_attr = vcol_save_attr; |
| 4659 | #endif |
| 4660 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4661 | /* restore attributes after "predeces" in 'listchars' */ |
| 4662 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 4663 | char_attr = saved_attr3; |
| 4664 | |
| 4665 | /* restore attributes after last 'listchars' or 'number' char */ |
| 4666 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 4667 | char_attr = saved_attr2; |
| 4668 | |
| 4669 | /* |
| 4670 | * At end of screen line and there is more to come: Display the line |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 4671 | * so far. If there is no more to display it is caught above. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4672 | */ |
| 4673 | if (( |
| 4674 | #ifdef FEAT_RIGHTLEFT |
| 4675 | wp->w_p_rl ? (col < 0) : |
| 4676 | #endif |
| 4677 | (col >= W_WIDTH(wp))) |
| 4678 | && (*ptr != NUL |
| 4679 | #ifdef FEAT_DIFF |
| 4680 | || filler_todo > 0 |
| 4681 | #endif |
| 4682 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
| 4683 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 4684 | ) |
| 4685 | { |
| 4686 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), |
| 4687 | wp->w_p_rl); |
| 4688 | ++row; |
| 4689 | ++screen_row; |
| 4690 | |
| 4691 | /* When not wrapping and finished diff lines, or when displayed |
| 4692 | * '$' and highlighting until last column, break here. */ |
| 4693 | if ((!wp->w_p_wrap |
| 4694 | #ifdef FEAT_DIFF |
| 4695 | && filler_todo <= 0 |
| 4696 | #endif |
| 4697 | ) || lcs_eol_one == -1) |
| 4698 | break; |
| 4699 | |
| 4700 | /* When the window is too narrow draw all "@" lines. */ |
| 4701 | if (draw_state != WL_LINE |
| 4702 | #ifdef FEAT_DIFF |
| 4703 | && filler_todo <= 0 |
| 4704 | #endif |
| 4705 | ) |
| 4706 | { |
| 4707 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 4708 | #ifdef FEAT_VERTSPLIT |
| 4709 | draw_vsep_win(wp, row); |
| 4710 | #endif |
| 4711 | row = endrow; |
| 4712 | } |
| 4713 | |
| 4714 | /* When line got too long for screen break here. */ |
| 4715 | if (row == endrow) |
| 4716 | { |
| 4717 | ++row; |
| 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | if (screen_cur_row == screen_row - 1 |
| 4722 | #ifdef FEAT_DIFF |
| 4723 | && filler_todo <= 0 |
| 4724 | #endif |
| 4725 | && W_WIDTH(wp) == Columns) |
| 4726 | { |
| 4727 | /* Remember that the line wraps, used for modeless copy. */ |
| 4728 | LineWraps[screen_row - 1] = TRUE; |
| 4729 | |
| 4730 | /* |
| 4731 | * Special trick to make copy/paste of wrapped lines work with |
| 4732 | * xterm/screen: write an extra character beyond the end of |
| 4733 | * the line. This will work with all terminal types |
| 4734 | * (regardless of the xn,am settings). |
| 4735 | * Only do this on a fast tty. |
| 4736 | * Only do this if the cursor is on the current line |
| 4737 | * (something has been written in it). |
| 4738 | * Don't do this for the GUI. |
| 4739 | * Don't do this for double-width characters. |
| 4740 | * Don't do this for a window not at the right screen border. |
| 4741 | */ |
| 4742 | if (p_tf |
| 4743 | #ifdef FEAT_GUI |
| 4744 | && !gui.in_use |
| 4745 | #endif |
| 4746 | #ifdef FEAT_MBYTE |
| 4747 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 4748 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 4749 | LineOffset[screen_row] + screen_Columns) |
| 4750 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4751 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 4752 | + (int)Columns - 2, |
| 4753 | LineOffset[screen_row] + screen_Columns) |
| 4754 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4755 | #endif |
| 4756 | ) |
| 4757 | { |
| 4758 | /* First make sure we are at the end of the screen line, |
| 4759 | * then output the same character again to let the |
| 4760 | * terminal know about the wrap. If the terminal doesn't |
| 4761 | * auto-wrap, we overwrite the character. */ |
| 4762 | if (screen_cur_col != W_WIDTH(wp)) |
| 4763 | screen_char(LineOffset[screen_row - 1] |
| 4764 | + (unsigned)Columns - 1, |
| 4765 | screen_row - 1, (int)(Columns - 1)); |
| 4766 | |
| 4767 | #ifdef FEAT_MBYTE |
| 4768 | /* When there is a multi-byte character, just output a |
| 4769 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 4770 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 4771 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4772 | out_char(' '); |
| 4773 | else |
| 4774 | #endif |
| 4775 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 4776 | + (Columns - 1)]); |
| 4777 | /* force a redraw of the first char on the next line */ |
| 4778 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 4779 | screen_start(); /* don't know where cursor is now */ |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | col = 0; |
| 4784 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 4785 | #ifdef FEAT_RIGHTLEFT |
| 4786 | if (wp->w_p_rl) |
| 4787 | { |
| 4788 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 4789 | off += col; |
| 4790 | } |
| 4791 | #endif |
| 4792 | |
| 4793 | /* reset the drawing state for the start of a wrapped line */ |
| 4794 | draw_state = WL_START; |
| 4795 | saved_n_extra = n_extra; |
| 4796 | saved_p_extra = p_extra; |
| 4797 | saved_c_extra = c_extra; |
| 4798 | saved_char_attr = char_attr; |
| 4799 | n_extra = 0; |
| 4800 | lcs_prec_todo = lcs_prec; |
| 4801 | #ifdef FEAT_LINEBREAK |
| 4802 | # ifdef FEAT_DIFF |
| 4803 | if (filler_todo <= 0) |
| 4804 | # endif |
| 4805 | need_showbreak = TRUE; |
| 4806 | #endif |
| 4807 | #ifdef FEAT_DIFF |
| 4808 | --filler_todo; |
| 4809 | /* When the filler lines are actually below the last line of the |
| 4810 | * file, don't draw the line itself, break here. */ |
| 4811 | if (filler_todo == 0 && wp->w_botfill) |
| 4812 | break; |
| 4813 | #endif |
| 4814 | } |
| 4815 | |
| 4816 | } /* for every character in the line */ |
| 4817 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4818 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4819 | /* After an empty line check first word for capital. */ |
| 4820 | if (*skipwhite(line) == NUL) |
| 4821 | { |
| 4822 | capcol_lnum = lnum + 1; |
| 4823 | cap_col = 0; |
| 4824 | } |
| 4825 | #endif |
| 4826 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4827 | return row; |
| 4828 | } |
| 4829 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4830 | #ifdef FEAT_MBYTE |
| 4831 | static int comp_char_differs __ARGS((int, int)); |
| 4832 | |
| 4833 | /* |
| 4834 | * Return if the composing characters at "off_from" and "off_to" differ. |
| 4835 | */ |
| 4836 | static int |
| 4837 | comp_char_differs(off_from, off_to) |
| 4838 | int off_from; |
| 4839 | int off_to; |
| 4840 | { |
| 4841 | int i; |
| 4842 | |
| 4843 | for (i = 0; i < Screen_mco; ++i) |
| 4844 | { |
| 4845 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 4846 | return TRUE; |
| 4847 | if (ScreenLinesC[i][off_from] == 0) |
| 4848 | break; |
| 4849 | } |
| 4850 | return FALSE; |
| 4851 | } |
| 4852 | #endif |
| 4853 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4854 | /* |
| 4855 | * Check whether the given character needs redrawing: |
| 4856 | * - the (first byte of the) character is different |
| 4857 | * - the attributes are different |
| 4858 | * - the character is multi-byte and the next byte is different |
| 4859 | */ |
| 4860 | static int |
| 4861 | char_needs_redraw(off_from, off_to, cols) |
| 4862 | int off_from; |
| 4863 | int off_to; |
| 4864 | int cols; |
| 4865 | { |
| 4866 | if (cols > 0 |
| 4867 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 4868 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 4869 | |
| 4870 | #ifdef FEAT_MBYTE |
| 4871 | || (enc_dbcs != 0 |
| 4872 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 4873 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 4874 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 4875 | : (cols > 1 && ScreenLines[off_from + 1] |
| 4876 | != ScreenLines[off_to + 1]))) |
| 4877 | || (enc_utf8 |
| 4878 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 4879 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4880 | && comp_char_differs(off_from, off_to)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4881 | #endif |
| 4882 | )) |
| 4883 | return TRUE; |
| 4884 | return FALSE; |
| 4885 | } |
| 4886 | |
| 4887 | /* |
| 4888 | * Move one "cooked" screen line to the screen, but only the characters that |
| 4889 | * have actually changed. Handle insert/delete character. |
| 4890 | * "coloff" gives the first column on the screen for this line. |
| 4891 | * "endcol" gives the columns where valid characters are. |
| 4892 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 4893 | * needs to be cleared, negative otherwise. |
| 4894 | * "rlflag" is TRUE in a rightleft window: |
| 4895 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 4896 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 4897 | */ |
| 4898 | static void |
| 4899 | screen_line(row, coloff, endcol, clear_width |
| 4900 | #ifdef FEAT_RIGHTLEFT |
| 4901 | , rlflag |
| 4902 | #endif |
| 4903 | ) |
| 4904 | int row; |
| 4905 | int coloff; |
| 4906 | int endcol; |
| 4907 | int clear_width; |
| 4908 | #ifdef FEAT_RIGHTLEFT |
| 4909 | int rlflag; |
| 4910 | #endif |
| 4911 | { |
| 4912 | unsigned off_from; |
| 4913 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 4914 | #ifdef FEAT_MBYTE |
| 4915 | unsigned max_off_from; |
| 4916 | unsigned max_off_to; |
| 4917 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4918 | int col = 0; |
| 4919 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 4920 | int hl; |
| 4921 | #endif |
| 4922 | int force = FALSE; /* force update rest of the line */ |
| 4923 | int redraw_this /* bool: does character need redraw? */ |
| 4924 | #ifdef FEAT_GUI |
| 4925 | = TRUE /* For GUI when while-loop empty */ |
| 4926 | #endif |
| 4927 | ; |
| 4928 | int redraw_next; /* redraw_this for next character */ |
| 4929 | #ifdef FEAT_MBYTE |
| 4930 | int clear_next = FALSE; |
| 4931 | int char_cells; /* 1: normal char */ |
| 4932 | /* 2: occupies two display cells */ |
| 4933 | # define CHAR_CELLS char_cells |
| 4934 | #else |
| 4935 | # define CHAR_CELLS 1 |
| 4936 | #endif |
| 4937 | |
| 4938 | # ifdef FEAT_CLIPBOARD |
| 4939 | clip_may_clear_selection(row, row); |
| 4940 | # endif |
| 4941 | |
| 4942 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 4943 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 4944 | #ifdef FEAT_MBYTE |
| 4945 | max_off_from = off_from + screen_Columns; |
| 4946 | max_off_to = LineOffset[row] + screen_Columns; |
| 4947 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4948 | |
| 4949 | #ifdef FEAT_RIGHTLEFT |
| 4950 | if (rlflag) |
| 4951 | { |
| 4952 | /* Clear rest first, because it's left of the text. */ |
| 4953 | if (clear_width > 0) |
| 4954 | { |
| 4955 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 4956 | && ScreenAttrs[off_to] == 0 |
| 4957 | # ifdef FEAT_MBYTE |
| 4958 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 4959 | # endif |
| 4960 | ) |
| 4961 | { |
| 4962 | ++off_to; |
| 4963 | ++col; |
| 4964 | } |
| 4965 | if (col <= endcol) |
| 4966 | screen_fill(row, row + 1, col + coloff, |
| 4967 | endcol + coloff + 1, ' ', ' ', 0); |
| 4968 | } |
| 4969 | col = endcol + 1; |
| 4970 | off_to = LineOffset[row] + col + coloff; |
| 4971 | off_from += col; |
| 4972 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 4973 | } |
| 4974 | #endif /* FEAT_RIGHTLEFT */ |
| 4975 | |
| 4976 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 4977 | |
| 4978 | while (col < endcol) |
| 4979 | { |
| 4980 | #ifdef FEAT_MBYTE |
| 4981 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 4982 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4983 | else |
| 4984 | char_cells = 1; |
| 4985 | #endif |
| 4986 | |
| 4987 | redraw_this = redraw_next; |
| 4988 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 4989 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 4990 | |
| 4991 | #ifdef FEAT_GUI |
| 4992 | /* If the next character was bold, then redraw the current character to |
| 4993 | * remove any pixels that might have spilt over into us. This only |
| 4994 | * happens in the GUI. |
| 4995 | */ |
| 4996 | if (redraw_next && gui.in_use) |
| 4997 | { |
| 4998 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4999 | if (hl > HL_ALL) |
| 5000 | hl = syn_attr2attr(hl); |
| 5001 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5002 | redraw_this = TRUE; |
| 5003 | } |
| 5004 | #endif |
| 5005 | |
| 5006 | if (redraw_this) |
| 5007 | { |
| 5008 | /* |
| 5009 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5010 | * Attributes for characters are stored at the position where the |
| 5011 | * cursor is when writing the highlighting code. The |
| 5012 | * start-highlighting code must be written with the cursor on the |
| 5013 | * first highlighted character. The stop-highlighting code must |
| 5014 | * be written with the cursor just after the last highlighted |
| 5015 | * character. |
| 5016 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5017 | * to clear the rest of the line, and force redrawing it |
| 5018 | * completely. |
| 5019 | */ |
| 5020 | if ( p_wiv |
| 5021 | && !force |
| 5022 | #ifdef FEAT_GUI |
| 5023 | && !gui.in_use |
| 5024 | #endif |
| 5025 | && ScreenAttrs[off_to] != 0 |
| 5026 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5027 | { |
| 5028 | /* |
| 5029 | * Need to remove highlighting attributes here. |
| 5030 | */ |
| 5031 | windgoto(row, col + coloff); |
| 5032 | out_str(T_CE); /* clear rest of this screen line */ |
| 5033 | screen_start(); /* don't know where cursor is now */ |
| 5034 | force = TRUE; /* force redraw of rest of the line */ |
| 5035 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5036 | |
| 5037 | /* |
| 5038 | * If the previous character was highlighted, need to stop |
| 5039 | * highlighting at this character. |
| 5040 | */ |
| 5041 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5042 | { |
| 5043 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5044 | term_windgoto(row, col + coloff); |
| 5045 | screen_stop_highlight(); |
| 5046 | } |
| 5047 | else |
| 5048 | screen_attr = 0; /* highlighting has stopped */ |
| 5049 | } |
| 5050 | #ifdef FEAT_MBYTE |
| 5051 | if (enc_dbcs != 0) |
| 5052 | { |
| 5053 | /* Check if overwriting a double-byte with a single-byte or |
| 5054 | * the other way around requires another character to be |
| 5055 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 5056 | * ScreenLinesUC[] is sufficient. */ |
| 5057 | if (char_cells == 1 |
| 5058 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5059 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5060 | { |
| 5061 | /* Writing a single-cell character over a double-cell |
| 5062 | * character: need to redraw the next cell. */ |
| 5063 | ScreenLines[off_to + 1] = 0; |
| 5064 | redraw_next = TRUE; |
| 5065 | } |
| 5066 | else if (char_cells == 2 |
| 5067 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5068 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5069 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5070 | { |
| 5071 | /* Writing the second half of a double-cell character over |
| 5072 | * a double-cell character: need to redraw the second |
| 5073 | * cell. */ |
| 5074 | ScreenLines[off_to + 2] = 0; |
| 5075 | redraw_next = TRUE; |
| 5076 | } |
| 5077 | |
| 5078 | if (enc_dbcs == DBCS_JPNU) |
| 5079 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 5080 | } |
| 5081 | /* When writing a single-width character over a double-width |
| 5082 | * character and at the end of the redrawn text, need to clear out |
| 5083 | * the right halve of the old character. |
| 5084 | * Also required when writing the right halve of a double-width |
| 5085 | * char over the left halve of an existing one. */ |
| 5086 | if (has_mbyte && col + char_cells == endcol |
| 5087 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5088 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5089 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5090 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5091 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5092 | clear_next = TRUE; |
| 5093 | #endif |
| 5094 | |
| 5095 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 5096 | #ifdef FEAT_MBYTE |
| 5097 | if (enc_utf8) |
| 5098 | { |
| 5099 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 5100 | if (ScreenLinesUC[off_from] != 0) |
| 5101 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5102 | int i; |
| 5103 | |
| 5104 | for (i = 0; i < Screen_mco; ++i) |
| 5105 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5106 | } |
| 5107 | } |
| 5108 | if (char_cells == 2) |
| 5109 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 5110 | #endif |
| 5111 | |
| 5112 | #if defined(FEAT_GUI) || defined(UNIX) |
| 5113 | /* The bold trick makes a single row of pixels appear in the next |
| 5114 | * character. When a bold character is removed, the next |
| 5115 | * character should be redrawn too. This happens for our own GUI |
| 5116 | * and for some xterms. */ |
| 5117 | if ( |
| 5118 | # ifdef FEAT_GUI |
| 5119 | gui.in_use |
| 5120 | # endif |
| 5121 | # if defined(FEAT_GUI) && defined(UNIX) |
| 5122 | || |
| 5123 | # endif |
| 5124 | # ifdef UNIX |
| 5125 | term_is_xterm |
| 5126 | # endif |
| 5127 | ) |
| 5128 | { |
| 5129 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5130 | if (hl > HL_ALL) |
| 5131 | hl = syn_attr2attr(hl); |
| 5132 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5133 | redraw_next = TRUE; |
| 5134 | } |
| 5135 | #endif |
| 5136 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 5137 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5138 | /* For simplicity set the attributes of second half of a |
| 5139 | * double-wide character equal to the first half. */ |
| 5140 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5141 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5142 | |
| 5143 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5144 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5145 | else |
| 5146 | #endif |
| 5147 | screen_char(off_to, row, col + coloff); |
| 5148 | } |
| 5149 | else if ( p_wiv |
| 5150 | #ifdef FEAT_GUI |
| 5151 | && !gui.in_use |
| 5152 | #endif |
| 5153 | && col + coloff > 0) |
| 5154 | { |
| 5155 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 5156 | { |
| 5157 | /* |
| 5158 | * Don't output stop-highlight when moving the cursor, it will |
| 5159 | * stop the highlighting when it should continue. |
| 5160 | */ |
| 5161 | screen_attr = 0; |
| 5162 | } |
| 5163 | else if (screen_attr != 0) |
| 5164 | screen_stop_highlight(); |
| 5165 | } |
| 5166 | |
| 5167 | off_to += CHAR_CELLS; |
| 5168 | off_from += CHAR_CELLS; |
| 5169 | col += CHAR_CELLS; |
| 5170 | } |
| 5171 | |
| 5172 | #ifdef FEAT_MBYTE |
| 5173 | if (clear_next) |
| 5174 | { |
| 5175 | /* Clear the second half of a double-wide character of which the left |
| 5176 | * half was overwritten with a single-wide character. */ |
| 5177 | ScreenLines[off_to] = ' '; |
| 5178 | if (enc_utf8) |
| 5179 | ScreenLinesUC[off_to] = 0; |
| 5180 | screen_char(off_to, row, col + coloff); |
| 5181 | } |
| 5182 | #endif |
| 5183 | |
| 5184 | if (clear_width > 0 |
| 5185 | #ifdef FEAT_RIGHTLEFT |
| 5186 | && !rlflag |
| 5187 | #endif |
| 5188 | ) |
| 5189 | { |
| 5190 | #ifdef FEAT_GUI |
| 5191 | int startCol = col; |
| 5192 | #endif |
| 5193 | |
| 5194 | /* blank out the rest of the line */ |
| 5195 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 5196 | && ScreenAttrs[off_to] == 0 |
| 5197 | #ifdef FEAT_MBYTE |
| 5198 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5199 | #endif |
| 5200 | ) |
| 5201 | { |
| 5202 | ++off_to; |
| 5203 | ++col; |
| 5204 | } |
| 5205 | if (col < clear_width) |
| 5206 | { |
| 5207 | #ifdef FEAT_GUI |
| 5208 | /* |
| 5209 | * In the GUI, clearing the rest of the line may leave pixels |
| 5210 | * behind if the first character cleared was bold. Some bold |
| 5211 | * fonts spill over the left. In this case we redraw the previous |
| 5212 | * character too. If we didn't skip any blanks above, then we |
| 5213 | * only redraw if the character wasn't already redrawn anyway. |
| 5214 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5215 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5216 | { |
| 5217 | hl = ScreenAttrs[off_to]; |
| 5218 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5219 | { |
| 5220 | int prev_cells = 1; |
| 5221 | # ifdef FEAT_MBYTE |
| 5222 | if (enc_utf8) |
| 5223 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 5224 | * that its width is 2. */ |
| 5225 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 5226 | else if (enc_dbcs != 0) |
| 5227 | { |
| 5228 | /* find previous character by counting from first |
| 5229 | * column and get its width. */ |
| 5230 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5231 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5232 | |
| 5233 | while (off < off_to) |
| 5234 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5235 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5236 | off += prev_cells; |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | if (enc_dbcs != 0 && prev_cells > 1) |
| 5241 | screen_char_2(off_to - prev_cells, row, |
| 5242 | col + coloff - prev_cells); |
| 5243 | else |
| 5244 | # endif |
| 5245 | screen_char(off_to - prev_cells, row, |
| 5246 | col + coloff - prev_cells); |
| 5247 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5248 | } |
| 5249 | #endif |
| 5250 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 5251 | ' ', ' ', 0); |
| 5252 | #ifdef FEAT_VERTSPLIT |
| 5253 | off_to += clear_width - col; |
| 5254 | col = clear_width; |
| 5255 | #endif |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | if (clear_width > 0) |
| 5260 | { |
| 5261 | #ifdef FEAT_VERTSPLIT |
| 5262 | /* For a window that's left of another, draw the separator char. */ |
| 5263 | if (col + coloff < Columns) |
| 5264 | { |
| 5265 | int c; |
| 5266 | |
| 5267 | c = fillchar_vsep(&hl); |
| 5268 | if (ScreenLines[off_to] != c |
| 5269 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5270 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 5271 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5272 | # endif |
| 5273 | || ScreenAttrs[off_to] != hl) |
| 5274 | { |
| 5275 | ScreenLines[off_to] = c; |
| 5276 | ScreenAttrs[off_to] = hl; |
| 5277 | # ifdef FEAT_MBYTE |
| 5278 | if (enc_utf8) |
| 5279 | { |
| 5280 | if (c >= 0x80) |
| 5281 | { |
| 5282 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5283 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5284 | } |
| 5285 | else |
| 5286 | ScreenLinesUC[off_to] = 0; |
| 5287 | } |
| 5288 | # endif |
| 5289 | screen_char(off_to, row, col + coloff); |
| 5290 | } |
| 5291 | } |
| 5292 | else |
| 5293 | #endif |
| 5294 | LineWraps[row] = FALSE; |
| 5295 | } |
| 5296 | } |
| 5297 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5298 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5299 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5300 | * Mirror text "str" for right-left displaying. |
| 5301 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5302 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5303 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5304 | rl_mirror(str) |
| 5305 | char_u *str; |
| 5306 | { |
| 5307 | char_u *p1, *p2; |
| 5308 | int t; |
| 5309 | |
| 5310 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 5311 | { |
| 5312 | t = *p1; |
| 5313 | *p1 = *p2; |
| 5314 | *p2 = t; |
| 5315 | } |
| 5316 | } |
| 5317 | #endif |
| 5318 | |
| 5319 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5320 | /* |
| 5321 | * mark all status lines for redraw; used after first :cd |
| 5322 | */ |
| 5323 | void |
| 5324 | status_redraw_all() |
| 5325 | { |
| 5326 | win_T *wp; |
| 5327 | |
| 5328 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5329 | if (wp->w_status_height) |
| 5330 | { |
| 5331 | wp->w_redr_status = TRUE; |
| 5332 | redraw_later(VALID); |
| 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | /* |
| 5337 | * mark all status lines of the current buffer for redraw |
| 5338 | */ |
| 5339 | void |
| 5340 | status_redraw_curbuf() |
| 5341 | { |
| 5342 | win_T *wp; |
| 5343 | |
| 5344 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5345 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 5346 | { |
| 5347 | wp->w_redr_status = TRUE; |
| 5348 | redraw_later(VALID); |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | /* |
| 5353 | * Redraw all status lines that need to be redrawn. |
| 5354 | */ |
| 5355 | void |
| 5356 | redraw_statuslines() |
| 5357 | { |
| 5358 | win_T *wp; |
| 5359 | |
| 5360 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5361 | if (wp->w_redr_status) |
| 5362 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 5363 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5364 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5365 | } |
| 5366 | #endif |
| 5367 | |
| 5368 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 5369 | /* |
| 5370 | * Redraw all status lines at the bottom of frame "frp". |
| 5371 | */ |
| 5372 | void |
| 5373 | win_redraw_last_status(frp) |
| 5374 | frame_T *frp; |
| 5375 | { |
| 5376 | if (frp->fr_layout == FR_LEAF) |
| 5377 | frp->fr_win->w_redr_status = TRUE; |
| 5378 | else if (frp->fr_layout == FR_ROW) |
| 5379 | { |
| 5380 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 5381 | win_redraw_last_status(frp); |
| 5382 | } |
| 5383 | else /* frp->fr_layout == FR_COL */ |
| 5384 | { |
| 5385 | frp = frp->fr_child; |
| 5386 | while (frp->fr_next != NULL) |
| 5387 | frp = frp->fr_next; |
| 5388 | win_redraw_last_status(frp); |
| 5389 | } |
| 5390 | } |
| 5391 | #endif |
| 5392 | |
| 5393 | #ifdef FEAT_VERTSPLIT |
| 5394 | /* |
| 5395 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 5396 | */ |
| 5397 | static void |
| 5398 | draw_vsep_win(wp, row) |
| 5399 | win_T *wp; |
| 5400 | int row; |
| 5401 | { |
| 5402 | int hl; |
| 5403 | int c; |
| 5404 | |
| 5405 | if (wp->w_vsep_width) |
| 5406 | { |
| 5407 | /* draw the vertical separator right of this window */ |
| 5408 | c = fillchar_vsep(&hl); |
| 5409 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 5410 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 5411 | c, ' ', hl); |
| 5412 | } |
| 5413 | } |
| 5414 | #endif |
| 5415 | |
| 5416 | #ifdef FEAT_WILDMENU |
| 5417 | static int status_match_len __ARGS((expand_T *xp, char_u *s)); |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5418 | 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] | 5419 | |
| 5420 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5421 | * Get the length of an item as it will be shown in the status line. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5422 | */ |
| 5423 | static int |
| 5424 | status_match_len(xp, s) |
| 5425 | expand_T *xp; |
| 5426 | char_u *s; |
| 5427 | { |
| 5428 | int len = 0; |
| 5429 | |
| 5430 | #ifdef FEAT_MENU |
| 5431 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 5432 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5433 | |
| 5434 | /* Check for menu separators - replace with '|'. */ |
| 5435 | if (emenu && menu_is_separator(s)) |
| 5436 | return 1; |
| 5437 | #endif |
| 5438 | |
| 5439 | while (*s != NUL) |
| 5440 | { |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5441 | if (skip_status_match_char(xp, s)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5442 | ++s; |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5443 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5444 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | return len; |
| 5448 | } |
| 5449 | |
| 5450 | /* |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5451 | * Return TRUE for characters that are not displayed in a status match. |
| 5452 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 5453 | */ |
| 5454 | static int |
| 5455 | skip_status_match_char(xp, s) |
| 5456 | expand_T *xp; |
| 5457 | char_u *s; |
| 5458 | { |
| 5459 | return ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
| 5460 | #ifdef FEAT_MENU |
| 5461 | || ((xp->xp_context == EXPAND_MENUS |
| 5462 | || xp->xp_context == EXPAND_MENUNAMES) |
| 5463 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 5464 | #endif |
| 5465 | ); |
| 5466 | } |
| 5467 | |
| 5468 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5469 | * Show wildchar matches in the status line. |
| 5470 | * Show at least the "match" item. |
| 5471 | * We start at item 'first_match' in the list and show all matches that fit. |
| 5472 | * |
| 5473 | * If inversion is possible we use it. Else '=' characters are used. |
| 5474 | */ |
| 5475 | void |
| 5476 | win_redr_status_matches(xp, num_matches, matches, match, showtail) |
| 5477 | expand_T *xp; |
| 5478 | int num_matches; |
| 5479 | char_u **matches; /* list of matches */ |
| 5480 | int match; |
| 5481 | int showtail; |
| 5482 | { |
| 5483 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 5484 | int row; |
| 5485 | char_u *buf; |
| 5486 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5487 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5488 | int fillchar; |
| 5489 | int attr; |
| 5490 | int i; |
| 5491 | int highlight = TRUE; |
| 5492 | char_u *selstart = NULL; |
| 5493 | int selstart_col = 0; |
| 5494 | char_u *selend = NULL; |
| 5495 | static int first_match = 0; |
| 5496 | int add_left = FALSE; |
| 5497 | char_u *s; |
| 5498 | #ifdef FEAT_MENU |
| 5499 | int emenu; |
| 5500 | #endif |
| 5501 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 5502 | int l; |
| 5503 | #endif |
| 5504 | |
| 5505 | if (matches == NULL) /* interrupted completion? */ |
| 5506 | return; |
| 5507 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5508 | #ifdef FEAT_MBYTE |
| 5509 | if (has_mbyte) |
| 5510 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 5511 | else |
| 5512 | #endif |
| 5513 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5514 | if (buf == NULL) |
| 5515 | return; |
| 5516 | |
| 5517 | if (match == -1) /* don't show match but original text */ |
| 5518 | { |
| 5519 | match = 0; |
| 5520 | highlight = FALSE; |
| 5521 | } |
| 5522 | /* count 1 for the ending ">" */ |
| 5523 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 5524 | if (match == 0) |
| 5525 | first_match = 0; |
| 5526 | else if (match < first_match) |
| 5527 | { |
| 5528 | /* jumping left, as far as we can go */ |
| 5529 | first_match = match; |
| 5530 | add_left = TRUE; |
| 5531 | } |
| 5532 | else |
| 5533 | { |
| 5534 | /* check if match fits on the screen */ |
| 5535 | for (i = first_match; i < match; ++i) |
| 5536 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5537 | if (first_match > 0) |
| 5538 | clen += 2; |
| 5539 | /* jumping right, put match at the left */ |
| 5540 | if ((long)clen > Columns) |
| 5541 | { |
| 5542 | first_match = match; |
| 5543 | /* if showing the last match, we can add some on the left */ |
| 5544 | clen = 2; |
| 5545 | for (i = match; i < num_matches; ++i) |
| 5546 | { |
| 5547 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5548 | if ((long)clen >= Columns) |
| 5549 | break; |
| 5550 | } |
| 5551 | if (i == num_matches) |
| 5552 | add_left = TRUE; |
| 5553 | } |
| 5554 | } |
| 5555 | if (add_left) |
| 5556 | while (first_match > 0) |
| 5557 | { |
| 5558 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 5559 | if ((long)clen >= Columns) |
| 5560 | break; |
| 5561 | --first_match; |
| 5562 | } |
| 5563 | |
| 5564 | fillchar = fillchar_status(&attr, TRUE); |
| 5565 | |
| 5566 | if (first_match == 0) |
| 5567 | { |
| 5568 | *buf = NUL; |
| 5569 | len = 0; |
| 5570 | } |
| 5571 | else |
| 5572 | { |
| 5573 | STRCPY(buf, "< "); |
| 5574 | len = 2; |
| 5575 | } |
| 5576 | clen = len; |
| 5577 | |
| 5578 | i = first_match; |
| 5579 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 5580 | { |
| 5581 | if (i == match) |
| 5582 | { |
| 5583 | selstart = buf + len; |
| 5584 | selstart_col = clen; |
| 5585 | } |
| 5586 | |
| 5587 | s = L_MATCH(i); |
| 5588 | /* Check for menu separators - replace with '|' */ |
| 5589 | #ifdef FEAT_MENU |
| 5590 | emenu = (xp->xp_context == EXPAND_MENUS |
| 5591 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5592 | if (emenu && menu_is_separator(s)) |
| 5593 | { |
| 5594 | STRCPY(buf + len, transchar('|')); |
| 5595 | l = (int)STRLEN(buf + len); |
| 5596 | len += l; |
| 5597 | clen += l; |
| 5598 | } |
| 5599 | else |
| 5600 | #endif |
| 5601 | for ( ; *s != NUL; ++s) |
| 5602 | { |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5603 | if (skip_status_match_char(xp, s)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5604 | ++s; |
| 5605 | clen += ptr2cells(s); |
| 5606 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5607 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5608 | { |
| 5609 | STRNCPY(buf + len, s, l); |
| 5610 | s += l - 1; |
| 5611 | len += l; |
| 5612 | } |
| 5613 | else |
| 5614 | #endif |
| 5615 | { |
| 5616 | STRCPY(buf + len, transchar_byte(*s)); |
| 5617 | len += (int)STRLEN(buf + len); |
| 5618 | } |
| 5619 | } |
| 5620 | if (i == match) |
| 5621 | selend = buf + len; |
| 5622 | |
| 5623 | *(buf + len++) = ' '; |
| 5624 | *(buf + len++) = ' '; |
| 5625 | clen += 2; |
| 5626 | if (++i == num_matches) |
| 5627 | break; |
| 5628 | } |
| 5629 | |
| 5630 | if (i != num_matches) |
| 5631 | { |
| 5632 | *(buf + len++) = '>'; |
| 5633 | ++clen; |
| 5634 | } |
| 5635 | |
| 5636 | buf[len] = NUL; |
| 5637 | |
| 5638 | row = cmdline_row - 1; |
| 5639 | if (row >= 0) |
| 5640 | { |
| 5641 | if (wild_menu_showing == 0) |
| 5642 | { |
| 5643 | if (msg_scrolled > 0) |
| 5644 | { |
| 5645 | /* Put the wildmenu just above the command line. If there is |
| 5646 | * no room, scroll the screen one line up. */ |
| 5647 | if (cmdline_row == Rows - 1) |
| 5648 | { |
| 5649 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 5650 | ++msg_scrolled; |
| 5651 | } |
| 5652 | else |
| 5653 | { |
| 5654 | ++cmdline_row; |
| 5655 | ++row; |
| 5656 | } |
| 5657 | wild_menu_showing = WM_SCROLLED; |
| 5658 | } |
| 5659 | else |
| 5660 | { |
| 5661 | /* Create status line if needed by setting 'laststatus' to 2. |
| 5662 | * Set 'winminheight' to zero to avoid that the window is |
| 5663 | * resized. */ |
| 5664 | if (lastwin->w_status_height == 0) |
| 5665 | { |
| 5666 | save_p_ls = p_ls; |
| 5667 | save_p_wmh = p_wmh; |
| 5668 | p_ls = 2; |
| 5669 | p_wmh = 0; |
| 5670 | last_status(FALSE); |
| 5671 | } |
| 5672 | wild_menu_showing = WM_SHOWN; |
| 5673 | } |
| 5674 | } |
| 5675 | |
| 5676 | screen_puts(buf, row, 0, attr); |
| 5677 | if (selstart != NULL && highlight) |
| 5678 | { |
| 5679 | *selend = NUL; |
| 5680 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 5681 | } |
| 5682 | |
| 5683 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 5684 | } |
| 5685 | |
| 5686 | #ifdef FEAT_VERTSPLIT |
| 5687 | win_redraw_last_status(topframe); |
| 5688 | #else |
| 5689 | lastwin->w_redr_status = TRUE; |
| 5690 | #endif |
| 5691 | vim_free(buf); |
| 5692 | } |
| 5693 | #endif |
| 5694 | |
| 5695 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5696 | /* |
| 5697 | * Redraw the status line of window wp. |
| 5698 | * |
| 5699 | * If inversion is possible we use it. Else '=' characters are used. |
| 5700 | */ |
| 5701 | void |
| 5702 | win_redr_status(wp) |
| 5703 | win_T *wp; |
| 5704 | { |
| 5705 | int row; |
| 5706 | char_u *p; |
| 5707 | int len; |
| 5708 | int fillchar; |
| 5709 | int attr; |
| 5710 | int this_ru_col; |
| 5711 | |
| 5712 | wp->w_redr_status = FALSE; |
| 5713 | if (wp->w_status_height == 0) |
| 5714 | { |
| 5715 | /* no status line, can only be last window */ |
| 5716 | redraw_cmdline = TRUE; |
| 5717 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 5718 | else if (!redrawing() |
| 5719 | #ifdef FEAT_INS_EXPAND |
| 5720 | /* don't update status line when popup menu is visible and may be |
| 5721 | * drawn over it */ |
| 5722 | || pum_visible() |
| 5723 | #endif |
| 5724 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5725 | { |
| 5726 | /* Don't redraw right now, do it later. */ |
| 5727 | wp->w_redr_status = TRUE; |
| 5728 | } |
| 5729 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5730 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5731 | { |
| 5732 | /* redraw custom status line */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5733 | redraw_custum_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5734 | } |
| 5735 | #endif |
| 5736 | else |
| 5737 | { |
| 5738 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5739 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 5740 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5741 | p = NameBuff; |
| 5742 | len = (int)STRLEN(p); |
| 5743 | |
| 5744 | if (wp->w_buffer->b_help |
| 5745 | #ifdef FEAT_QUICKFIX |
| 5746 | || wp->w_p_pvw |
| 5747 | #endif |
| 5748 | || bufIsChanged(wp->w_buffer) |
| 5749 | || wp->w_buffer->b_p_ro) |
| 5750 | *(p + len++) = ' '; |
| 5751 | if (wp->w_buffer->b_help) |
| 5752 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 5753 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5754 | len += (int)STRLEN(p + len); |
| 5755 | } |
| 5756 | #ifdef FEAT_QUICKFIX |
| 5757 | if (wp->w_p_pvw) |
| 5758 | { |
| 5759 | STRCPY(p + len, _("[Preview]")); |
| 5760 | len += (int)STRLEN(p + len); |
| 5761 | } |
| 5762 | #endif |
| 5763 | if (bufIsChanged(wp->w_buffer)) |
| 5764 | { |
| 5765 | STRCPY(p + len, "[+]"); |
| 5766 | len += 3; |
| 5767 | } |
| 5768 | if (wp->w_buffer->b_p_ro) |
| 5769 | { |
| 5770 | STRCPY(p + len, "[RO]"); |
| 5771 | len += 4; |
| 5772 | } |
| 5773 | |
| 5774 | #ifndef FEAT_VERTSPLIT |
| 5775 | this_ru_col = ru_col; |
| 5776 | if (this_ru_col < (Columns + 1) / 2) |
| 5777 | this_ru_col = (Columns + 1) / 2; |
| 5778 | #else |
| 5779 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 5780 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 5781 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 5782 | if (this_ru_col <= 1) |
| 5783 | { |
| 5784 | p = (char_u *)"<"; /* No room for file name! */ |
| 5785 | len = 1; |
| 5786 | } |
| 5787 | else |
| 5788 | #endif |
| 5789 | #ifdef FEAT_MBYTE |
| 5790 | if (has_mbyte) |
| 5791 | { |
| 5792 | int clen = 0, i; |
| 5793 | |
| 5794 | /* Count total number of display cells. */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5795 | for (i = 0; p[i] != NUL; i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5796 | clen += (*mb_ptr2cells)(p + i); |
| 5797 | /* Find first character that will fit. |
| 5798 | * Going from start to end is much faster for DBCS. */ |
| 5799 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5800 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5801 | clen -= (*mb_ptr2cells)(p + i); |
| 5802 | len = clen; |
| 5803 | if (i > 0) |
| 5804 | { |
| 5805 | p = p + i - 1; |
| 5806 | *p = '<'; |
| 5807 | ++len; |
| 5808 | } |
| 5809 | |
| 5810 | } |
| 5811 | else |
| 5812 | #endif |
| 5813 | if (len > this_ru_col - 1) |
| 5814 | { |
| 5815 | p += len - (this_ru_col - 1); |
| 5816 | *p = '<'; |
| 5817 | len = this_ru_col - 1; |
| 5818 | } |
| 5819 | |
| 5820 | row = W_WINROW(wp) + wp->w_height; |
| 5821 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 5822 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 5823 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 5824 | |
| 5825 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 5826 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 5827 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 5828 | - 1 + W_WINCOL(wp)), attr); |
| 5829 | |
| 5830 | #ifdef FEAT_CMDL_INFO |
| 5831 | win_redr_ruler(wp, TRUE); |
| 5832 | #endif |
| 5833 | } |
| 5834 | |
| 5835 | #ifdef FEAT_VERTSPLIT |
| 5836 | /* |
| 5837 | * May need to draw the character below the vertical separator. |
| 5838 | */ |
| 5839 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 5840 | { |
| 5841 | if (stl_connected(wp)) |
| 5842 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5843 | else |
| 5844 | fillchar = fillchar_vsep(&attr); |
| 5845 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 5846 | attr); |
| 5847 | } |
| 5848 | #endif |
| 5849 | } |
| 5850 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5851 | #ifdef FEAT_STL_OPT |
| 5852 | /* |
| 5853 | * Redraw the status line according to 'statusline' and take care of any |
| 5854 | * errors encountered. |
| 5855 | */ |
| 5856 | static void |
| 5857 | redraw_custum_statusline(wp) |
| 5858 | win_T *wp; |
| 5859 | { |
| 5860 | int save_called_emsg = called_emsg; |
| 5861 | |
| 5862 | called_emsg = FALSE; |
| 5863 | win_redr_custom(wp, FALSE); |
| 5864 | if (called_emsg) |
| 5865 | set_string_option_direct((char_u *)"statusline", -1, |
| 5866 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5867 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5868 | called_emsg |= save_called_emsg; |
| 5869 | } |
| 5870 | #endif |
| 5871 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5872 | # ifdef FEAT_VERTSPLIT |
| 5873 | /* |
| 5874 | * Return TRUE if the status line of window "wp" is connected to the status |
| 5875 | * line of the window right of it. If not, then it's a vertical separator. |
| 5876 | * Only call if (wp->w_vsep_width != 0). |
| 5877 | */ |
| 5878 | int |
| 5879 | stl_connected(wp) |
| 5880 | win_T *wp; |
| 5881 | { |
| 5882 | frame_T *fr; |
| 5883 | |
| 5884 | fr = wp->w_frame; |
| 5885 | while (fr->fr_parent != NULL) |
| 5886 | { |
| 5887 | if (fr->fr_parent->fr_layout == FR_COL) |
| 5888 | { |
| 5889 | if (fr->fr_next != NULL) |
| 5890 | break; |
| 5891 | } |
| 5892 | else |
| 5893 | { |
| 5894 | if (fr->fr_next != NULL) |
| 5895 | return TRUE; |
| 5896 | } |
| 5897 | fr = fr->fr_parent; |
| 5898 | } |
| 5899 | return FALSE; |
| 5900 | } |
| 5901 | # endif |
| 5902 | |
| 5903 | #endif /* FEAT_WINDOWS */ |
| 5904 | |
| 5905 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 5906 | /* |
| 5907 | * Get the value to show for the language mappings, active 'keymap'. |
| 5908 | */ |
| 5909 | int |
| 5910 | get_keymap_str(wp, buf, len) |
| 5911 | win_T *wp; |
| 5912 | char_u *buf; /* buffer for the result */ |
| 5913 | int len; /* length of buffer */ |
| 5914 | { |
| 5915 | char_u *p; |
| 5916 | |
| 5917 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 5918 | return FALSE; |
| 5919 | |
| 5920 | { |
| 5921 | #ifdef FEAT_EVAL |
| 5922 | buf_T *old_curbuf = curbuf; |
| 5923 | win_T *old_curwin = curwin; |
| 5924 | char_u *s; |
| 5925 | |
| 5926 | curbuf = wp->w_buffer; |
| 5927 | curwin = wp; |
| 5928 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 5929 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5930 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5931 | --emsg_skip; |
| 5932 | curbuf = old_curbuf; |
| 5933 | curwin = old_curwin; |
| 5934 | if (p == NULL || *p == NUL) |
| 5935 | #endif |
| 5936 | { |
| 5937 | #ifdef FEAT_KEYMAP |
| 5938 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 5939 | p = wp->w_buffer->b_p_keymap; |
| 5940 | else |
| 5941 | #endif |
| 5942 | p = (char_u *)"lang"; |
| 5943 | } |
| 5944 | if ((int)(STRLEN(p) + 3) < len) |
| 5945 | sprintf((char *)buf, "<%s>", p); |
| 5946 | else |
| 5947 | buf[0] = NUL; |
| 5948 | #ifdef FEAT_EVAL |
| 5949 | vim_free(s); |
| 5950 | #endif |
| 5951 | } |
| 5952 | return buf[0] != NUL; |
| 5953 | } |
| 5954 | #endif |
| 5955 | |
| 5956 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 5957 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5958 | * Redraw the status line or ruler of window "wp". |
| 5959 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5960 | */ |
| 5961 | static void |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 5962 | win_redr_custom(wp, draw_ruler) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5963 | win_T *wp; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 5964 | int draw_ruler; /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5965 | { |
| 5966 | int attr; |
| 5967 | int curattr; |
| 5968 | int row; |
| 5969 | int col = 0; |
| 5970 | int maxwidth; |
| 5971 | int width; |
| 5972 | int n; |
| 5973 | int len; |
| 5974 | int fillchar; |
| 5975 | char_u buf[MAXPATHL]; |
| 5976 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5977 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 5978 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5979 | int use_sandbox = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5980 | |
| 5981 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5982 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5983 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5984 | /* Use 'tabline'. Always at the first line of the screen. */ |
| 5985 | p = p_tal; |
| 5986 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 5987 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5988 | attr = hl_attr(HLF_TPF); |
| 5989 | maxwidth = Columns; |
| 5990 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5991 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5992 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5993 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5994 | else |
| 5995 | { |
| 5996 | row = W_WINROW(wp) + wp->w_height; |
| 5997 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5998 | maxwidth = W_WIDTH(wp); |
| 5999 | |
| 6000 | if (draw_ruler) |
| 6001 | { |
| 6002 | p = p_ruf; |
| 6003 | /* advance past any leading group spec - implicit in ru_col */ |
| 6004 | if (*p == '%') |
| 6005 | { |
| 6006 | if (*++p == '-') |
| 6007 | p++; |
| 6008 | if (atoi((char *) p)) |
| 6009 | while (VIM_ISDIGIT(*p)) |
| 6010 | p++; |
| 6011 | if (*p++ != '(') |
| 6012 | p = p_ruf; |
| 6013 | } |
| 6014 | #ifdef FEAT_VERTSPLIT |
| 6015 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6016 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6017 | col = (W_WIDTH(wp) + 1) / 2; |
| 6018 | #else |
| 6019 | col = ru_col; |
| 6020 | if (col > (Columns + 1) / 2) |
| 6021 | col = (Columns + 1) / 2; |
| 6022 | #endif |
| 6023 | maxwidth = W_WIDTH(wp) - col; |
| 6024 | #ifdef FEAT_WINDOWS |
| 6025 | if (!wp->w_status_height) |
| 6026 | #endif |
| 6027 | { |
| 6028 | row = Rows - 1; |
| 6029 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6030 | fillchar = ' '; |
| 6031 | attr = 0; |
| 6032 | } |
| 6033 | |
| 6034 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6035 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6036 | # endif |
| 6037 | } |
| 6038 | else |
| 6039 | { |
| 6040 | if (*wp->w_p_stl != NUL) |
| 6041 | p = wp->w_p_stl; |
| 6042 | else |
| 6043 | p = p_stl; |
| 6044 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6045 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 6046 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6047 | # endif |
| 6048 | } |
| 6049 | |
| 6050 | #ifdef FEAT_VERTSPLIT |
| 6051 | col += W_WINCOL(wp); |
| 6052 | #endif |
| 6053 | } |
| 6054 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6055 | if (maxwidth <= 0) |
| 6056 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6057 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6058 | width = build_stl_str_hl(wp == NULL ? curwin : wp, |
| 6059 | buf, sizeof(buf), |
| 6060 | p, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6061 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 6062 | len = (int)STRLEN(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6063 | |
| 6064 | while (width < maxwidth && len < sizeof(buf) - 1) |
| 6065 | { |
| 6066 | #ifdef FEAT_MBYTE |
| 6067 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 6068 | #else |
| 6069 | buf[len++] = fillchar; |
| 6070 | #endif |
| 6071 | ++width; |
| 6072 | } |
| 6073 | buf[len] = NUL; |
| 6074 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6075 | /* |
| 6076 | * Draw each snippet with the specified highlighting. |
| 6077 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6078 | curattr = attr; |
| 6079 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6080 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6081 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6082 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6083 | screen_puts_len(p, len, row, col, curattr); |
| 6084 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6085 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6086 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6087 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6088 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6089 | else if (hltab[n].userhl < 0) |
| 6090 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6091 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6092 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6093 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6094 | #endif |
| 6095 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6096 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6097 | } |
| 6098 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6099 | |
| 6100 | if (wp == NULL) |
| 6101 | { |
| 6102 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 6103 | col = 0; |
| 6104 | len = 0; |
| 6105 | p = buf; |
| 6106 | fillchar = 0; |
| 6107 | for (n = 0; tabtab[n].start != NULL; n++) |
| 6108 | { |
| 6109 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 6110 | while (col < len) |
| 6111 | TabPageIdxs[col++] = fillchar; |
| 6112 | p = tabtab[n].start; |
| 6113 | fillchar = tabtab[n].userhl; |
| 6114 | } |
| 6115 | while (col < Columns) |
| 6116 | TabPageIdxs[col++] = fillchar; |
| 6117 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | #endif /* FEAT_STL_OPT */ |
| 6121 | |
| 6122 | /* |
| 6123 | * Output a single character directly to the screen and update ScreenLines. |
| 6124 | */ |
| 6125 | void |
| 6126 | screen_putchar(c, row, col, attr) |
| 6127 | int c; |
| 6128 | int row, col; |
| 6129 | int attr; |
| 6130 | { |
| 6131 | #ifdef FEAT_MBYTE |
| 6132 | char_u buf[MB_MAXBYTES + 1]; |
| 6133 | |
| 6134 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 6135 | #else |
| 6136 | char_u buf[2]; |
| 6137 | |
| 6138 | buf[0] = c; |
| 6139 | buf[1] = NUL; |
| 6140 | #endif |
| 6141 | screen_puts(buf, row, col, attr); |
| 6142 | } |
| 6143 | |
| 6144 | /* |
| 6145 | * Get a single character directly from ScreenLines into "bytes[]". |
| 6146 | * Also return its attribute in *attrp; |
| 6147 | */ |
| 6148 | void |
| 6149 | screen_getbytes(row, col, bytes, attrp) |
| 6150 | int row, col; |
| 6151 | char_u *bytes; |
| 6152 | int *attrp; |
| 6153 | { |
| 6154 | unsigned off; |
| 6155 | |
| 6156 | /* safety check */ |
| 6157 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 6158 | { |
| 6159 | off = LineOffset[row] + col; |
| 6160 | *attrp = ScreenAttrs[off]; |
| 6161 | bytes[0] = ScreenLines[off]; |
| 6162 | bytes[1] = NUL; |
| 6163 | |
| 6164 | #ifdef FEAT_MBYTE |
| 6165 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6166 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 6167 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6168 | { |
| 6169 | bytes[0] = ScreenLines[off]; |
| 6170 | bytes[1] = ScreenLines2[off]; |
| 6171 | bytes[2] = NUL; |
| 6172 | } |
| 6173 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 6174 | { |
| 6175 | bytes[1] = ScreenLines[off + 1]; |
| 6176 | bytes[2] = NUL; |
| 6177 | } |
| 6178 | #endif |
| 6179 | } |
| 6180 | } |
| 6181 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6182 | #ifdef FEAT_MBYTE |
| 6183 | static int screen_comp_differs __ARGS((int, int*)); |
| 6184 | |
| 6185 | /* |
| 6186 | * Return TRUE if composing characters for screen posn "off" differs from |
| 6187 | * composing characters in "u8cc". |
| 6188 | */ |
| 6189 | static int |
| 6190 | screen_comp_differs(off, u8cc) |
| 6191 | int off; |
| 6192 | int *u8cc; |
| 6193 | { |
| 6194 | int i; |
| 6195 | |
| 6196 | for (i = 0; i < Screen_mco; ++i) |
| 6197 | { |
| 6198 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 6199 | return TRUE; |
| 6200 | if (u8cc[i] == 0) |
| 6201 | break; |
| 6202 | } |
| 6203 | return FALSE; |
| 6204 | } |
| 6205 | #endif |
| 6206 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6207 | /* |
| 6208 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 6209 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 6210 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 6211 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 6212 | */ |
| 6213 | void |
| 6214 | screen_puts(text, row, col, attr) |
| 6215 | char_u *text; |
| 6216 | int row; |
| 6217 | int col; |
| 6218 | int attr; |
| 6219 | { |
| 6220 | screen_puts_len(text, -1, row, col, attr); |
| 6221 | } |
| 6222 | |
| 6223 | /* |
| 6224 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 6225 | * a NUL. |
| 6226 | */ |
| 6227 | void |
| 6228 | screen_puts_len(text, len, row, col, attr) |
| 6229 | char_u *text; |
| 6230 | int len; |
| 6231 | int row; |
| 6232 | int col; |
| 6233 | int attr; |
| 6234 | { |
| 6235 | unsigned off; |
| 6236 | char_u *ptr = text; |
| 6237 | int c; |
| 6238 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6239 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6240 | int mbyte_blen = 1; |
| 6241 | int mbyte_cells = 1; |
| 6242 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6243 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6244 | int clear_next_cell = FALSE; |
| 6245 | # ifdef FEAT_ARABIC |
| 6246 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6247 | int pc, nc, nc1; |
| 6248 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6249 | # endif |
| 6250 | #endif |
| 6251 | |
| 6252 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 6253 | return; |
| 6254 | |
| 6255 | off = LineOffset[row] + col; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6256 | #ifdef FEAT_MBYTE |
| 6257 | max_off = LineOffset[row] + screen_Columns; |
| 6258 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 6259 | while (col < screen_Columns |
| 6260 | && (len < 0 || (int)(ptr - text) < len) |
| 6261 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6262 | { |
| 6263 | c = *ptr; |
| 6264 | #ifdef FEAT_MBYTE |
| 6265 | /* check if this is the first byte of a multibyte */ |
| 6266 | if (has_mbyte) |
| 6267 | { |
| 6268 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6269 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6270 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6271 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6272 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6273 | mbyte_cells = 1; |
| 6274 | else if (enc_dbcs != 0) |
| 6275 | mbyte_cells = mbyte_blen; |
| 6276 | else /* enc_utf8 */ |
| 6277 | { |
| 6278 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6279 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6280 | (int)((text + len) - ptr)); |
| 6281 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6282 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6283 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6284 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6285 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 6286 | if (u8c >= 0x10000) |
| 6287 | { |
| 6288 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 6289 | if (attr == 0) |
| 6290 | attr = hl_attr(HLF_8); |
| 6291 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6292 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6293 | # ifdef FEAT_ARABIC |
| 6294 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 6295 | { |
| 6296 | /* Do Arabic shaping. */ |
| 6297 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 6298 | { |
| 6299 | /* Past end of string to be displayed. */ |
| 6300 | nc = NUL; |
| 6301 | nc1 = NUL; |
| 6302 | } |
| 6303 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6304 | { |
| 6305 | nc = utfc_ptr2char(ptr + mbyte_blen, pcc); |
| 6306 | nc1 = pcc[0]; |
| 6307 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6308 | pc = prev_c; |
| 6309 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6310 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6311 | } |
| 6312 | else |
| 6313 | prev_c = u8c; |
| 6314 | # endif |
| 6315 | } |
| 6316 | } |
| 6317 | #endif |
| 6318 | |
| 6319 | if (ScreenLines[off] != c |
| 6320 | #ifdef FEAT_MBYTE |
| 6321 | || (mbyte_cells == 2 |
| 6322 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 6323 | || (enc_dbcs == DBCS_JPNU |
| 6324 | && c == 0x8e |
| 6325 | && ScreenLines2[off] != ptr[1]) |
| 6326 | || (enc_utf8 |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6327 | && (ScreenLinesUC[off] != (u8char_T)u8c |
| 6328 | || screen_comp_differs(off, u8cc))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6329 | #endif |
| 6330 | || ScreenAttrs[off] != attr |
| 6331 | || exmode_active |
| 6332 | ) |
| 6333 | { |
| 6334 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6335 | /* The bold trick makes a single row of pixels appear in the next |
| 6336 | * character. When a bold character is removed, the next |
| 6337 | * character should be redrawn too. This happens for our own GUI |
| 6338 | * and for some xterms. |
| 6339 | * Force the redraw by setting the attribute to a different value |
| 6340 | * than "attr", the contents of ScreenLines[] may be needed by |
| 6341 | * mb_off2cells() further on. |
| 6342 | * Don't do this for the last drawn character, because the next |
| 6343 | * character may not be redrawn. */ |
| 6344 | if ( |
| 6345 | # ifdef FEAT_GUI |
| 6346 | gui.in_use |
| 6347 | # endif |
| 6348 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6349 | || |
| 6350 | # endif |
| 6351 | # ifdef UNIX |
| 6352 | term_is_xterm |
| 6353 | # endif |
| 6354 | ) |
| 6355 | { |
| 6356 | int n; |
| 6357 | |
| 6358 | n = ScreenAttrs[off]; |
| 6359 | # ifdef FEAT_MBYTE |
| 6360 | if (col + mbyte_cells < screen_Columns |
| 6361 | && (n > HL_ALL || (n & HL_BOLD)) |
| 6362 | && (len < 0 ? ptr[mbyte_blen] != NUL |
| 6363 | : ptr + mbyte_blen < text + len)) |
| 6364 | ScreenAttrs[off + mbyte_cells] = attr + 1; |
| 6365 | # else |
| 6366 | if (col + 1 < screen_Columns |
| 6367 | && (n > HL_ALL || (n & HL_BOLD)) |
| 6368 | && (len < 0 ? ptr[1] != NUL : ptr + 1 < text + len)) |
| 6369 | ScreenLines[off + 1] = 0; |
| 6370 | # endif |
| 6371 | } |
| 6372 | #endif |
| 6373 | #ifdef FEAT_MBYTE |
| 6374 | /* When at the end of the text and overwriting a two-cell |
| 6375 | * character with a one-cell character, need to clear the next |
| 6376 | * cell. Also when overwriting the left halve of a two-cell char |
| 6377 | * with the right halve of a two-cell char. Do this only once |
| 6378 | * (mb_off2cells() may return 2 on the right halve). */ |
| 6379 | if (clear_next_cell) |
| 6380 | clear_next_cell = FALSE; |
| 6381 | else if (has_mbyte |
| 6382 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 6383 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6384 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6385 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6386 | && (*mb_off2cells)(off, max_off) == 1 |
| 6387 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6388 | clear_next_cell = TRUE; |
| 6389 | |
| 6390 | /* Make sure we never leave a second byte of a double-byte behind, |
| 6391 | * it confuses mb_off2cells(). */ |
| 6392 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6393 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6394 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6395 | && (*mb_off2cells)(off, max_off) == 1 |
| 6396 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6397 | ScreenLines[off + mbyte_blen] = 0; |
| 6398 | #endif |
| 6399 | ScreenLines[off] = c; |
| 6400 | ScreenAttrs[off] = attr; |
| 6401 | #ifdef FEAT_MBYTE |
| 6402 | if (enc_utf8) |
| 6403 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6404 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6405 | ScreenLinesUC[off] = 0; |
| 6406 | else |
| 6407 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6408 | int i; |
| 6409 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6410 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6411 | for (i = 0; i < Screen_mco; ++i) |
| 6412 | { |
| 6413 | ScreenLinesC[i][off] = u8cc[i]; |
| 6414 | if (u8cc[i] == 0) |
| 6415 | break; |
| 6416 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6417 | } |
| 6418 | if (mbyte_cells == 2) |
| 6419 | { |
| 6420 | ScreenLines[off + 1] = 0; |
| 6421 | ScreenAttrs[off + 1] = attr; |
| 6422 | } |
| 6423 | screen_char(off, row, col); |
| 6424 | } |
| 6425 | else if (mbyte_cells == 2) |
| 6426 | { |
| 6427 | ScreenLines[off + 1] = ptr[1]; |
| 6428 | ScreenAttrs[off + 1] = attr; |
| 6429 | screen_char_2(off, row, col); |
| 6430 | } |
| 6431 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6432 | { |
| 6433 | ScreenLines2[off] = ptr[1]; |
| 6434 | screen_char(off, row, col); |
| 6435 | } |
| 6436 | else |
| 6437 | #endif |
| 6438 | screen_char(off, row, col); |
| 6439 | } |
| 6440 | #ifdef FEAT_MBYTE |
| 6441 | if (has_mbyte) |
| 6442 | { |
| 6443 | off += mbyte_cells; |
| 6444 | col += mbyte_cells; |
| 6445 | ptr += mbyte_blen; |
| 6446 | if (clear_next_cell) |
| 6447 | ptr = (char_u *)" "; |
| 6448 | } |
| 6449 | else |
| 6450 | #endif |
| 6451 | { |
| 6452 | ++off; |
| 6453 | ++col; |
| 6454 | ++ptr; |
| 6455 | } |
| 6456 | } |
| 6457 | } |
| 6458 | |
| 6459 | #ifdef FEAT_SEARCH_EXTRA |
| 6460 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6461 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6462 | */ |
| 6463 | static void |
| 6464 | start_search_hl() |
| 6465 | { |
| 6466 | if (p_hls && !no_hlsearch) |
| 6467 | { |
| 6468 | last_pat_prog(&search_hl.rm); |
| 6469 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 6470 | # ifdef FEAT_RELTIME |
| 6471 | /* Set the time limit to 'redrawtime'. */ |
| 6472 | profile_setlimit(p_rdt, &search_hl.tm); |
| 6473 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6478 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6479 | */ |
| 6480 | static void |
| 6481 | end_search_hl() |
| 6482 | { |
| 6483 | if (search_hl.rm.regprog != NULL) |
| 6484 | { |
| 6485 | vim_free(search_hl.rm.regprog); |
| 6486 | search_hl.rm.regprog = NULL; |
| 6487 | } |
| 6488 | } |
| 6489 | |
| 6490 | /* |
| 6491 | * Advance to the match in window "wp" line "lnum" or past it. |
| 6492 | */ |
| 6493 | static void |
| 6494 | prepare_search_hl(wp, lnum) |
| 6495 | win_T *wp; |
| 6496 | linenr_T lnum; |
| 6497 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6498 | matchitem_T *cur; /* points to the match list */ |
| 6499 | match_T *shl; /* points to search_hl or a match */ |
| 6500 | int shl_flag; /* flag to indicate whether search_hl |
| 6501 | has been processed or not */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6502 | int n; |
| 6503 | |
| 6504 | /* |
| 6505 | * When using a multi-line pattern, start searching at the top |
| 6506 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6507 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6508 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6509 | cur = wp->w_match_head; |
| 6510 | shl_flag = FALSE; |
| 6511 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6512 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6513 | if (shl_flag == FALSE) |
| 6514 | { |
| 6515 | shl = &search_hl; |
| 6516 | shl_flag = TRUE; |
| 6517 | } |
| 6518 | else |
| 6519 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6520 | if (shl->rm.regprog != NULL |
| 6521 | && shl->lnum == 0 |
| 6522 | && re_multiline(shl->rm.regprog)) |
| 6523 | { |
| 6524 | if (shl->first_lnum == 0) |
| 6525 | { |
| 6526 | # ifdef FEAT_FOLDING |
| 6527 | for (shl->first_lnum = lnum; |
| 6528 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 6529 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 6530 | NULL, NULL, TRUE, NULL)) |
| 6531 | break; |
| 6532 | # else |
| 6533 | shl->first_lnum = wp->w_topline; |
| 6534 | # endif |
| 6535 | } |
| 6536 | n = 0; |
| 6537 | while (shl->first_lnum < lnum && shl->rm.regprog != NULL) |
| 6538 | { |
| 6539 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); |
| 6540 | if (shl->lnum != 0) |
| 6541 | { |
| 6542 | shl->first_lnum = shl->lnum |
| 6543 | + shl->rm.endpos[0].lnum |
| 6544 | - shl->rm.startpos[0].lnum; |
| 6545 | n = shl->rm.endpos[0].col; |
| 6546 | } |
| 6547 | else |
| 6548 | { |
| 6549 | ++shl->first_lnum; |
| 6550 | n = 0; |
| 6551 | } |
| 6552 | } |
| 6553 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6554 | if (shl != &search_hl && cur != NULL) |
| 6555 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6560 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6561 | * Uses shl->buf. |
| 6562 | * Sets shl->lnum and shl->rm contents. |
| 6563 | * Note: Assumes a previous match is always before "lnum", unless |
| 6564 | * shl->lnum is zero. |
| 6565 | * Careful: Any pointers for buffer lines will become invalid. |
| 6566 | */ |
| 6567 | static void |
| 6568 | next_search_hl(win, shl, lnum, mincol) |
| 6569 | win_T *win; |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6570 | match_T *shl; /* points to search_hl or a match */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6571 | linenr_T lnum; |
| 6572 | colnr_T mincol; /* minimal column for a match */ |
| 6573 | { |
| 6574 | linenr_T l; |
| 6575 | colnr_T matchcol; |
| 6576 | long nmatched; |
| 6577 | |
| 6578 | if (shl->lnum != 0) |
| 6579 | { |
| 6580 | /* Check for three situations: |
| 6581 | * 1. If the "lnum" is below a previous match, start a new search. |
| 6582 | * 2. If the previous match includes "mincol", use it. |
| 6583 | * 3. Continue after the previous match. |
| 6584 | */ |
| 6585 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 6586 | if (lnum > l) |
| 6587 | shl->lnum = 0; |
| 6588 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 6589 | return; |
| 6590 | } |
| 6591 | |
| 6592 | /* |
| 6593 | * Repeat searching for a match until one is found that includes "mincol" |
| 6594 | * or none is found in this line. |
| 6595 | */ |
| 6596 | called_emsg = FALSE; |
| 6597 | for (;;) |
| 6598 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 6599 | #ifdef FEAT_RELTIME |
| 6600 | /* Stop searching after passing the time limit. */ |
| 6601 | if (profile_passed_limit(&(shl->tm))) |
| 6602 | { |
| 6603 | shl->lnum = 0; /* no match found in time */ |
| 6604 | break; |
| 6605 | } |
| 6606 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6607 | /* Three situations: |
| 6608 | * 1. No useful previous match: search from start of line. |
| 6609 | * 2. Not Vi compatible or empty match: continue at next character. |
| 6610 | * Break the loop if this is beyond the end of the line. |
| 6611 | * 3. Vi compatible searching: continue at end of previous match. |
| 6612 | */ |
| 6613 | if (shl->lnum == 0) |
| 6614 | matchcol = 0; |
| 6615 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 6616 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6617 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6618 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 6619 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6620 | |
| 6621 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 6622 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6623 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6624 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6625 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6626 | shl->lnum = 0; |
| 6627 | break; |
| 6628 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6629 | #ifdef FEAT_MBYTE |
| 6630 | if (has_mbyte) |
| 6631 | matchcol += mb_ptr2len(ml); |
| 6632 | else |
| 6633 | #endif |
| 6634 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6635 | } |
| 6636 | else |
| 6637 | matchcol = shl->rm.endpos[0].col; |
| 6638 | |
| 6639 | shl->lnum = lnum; |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 6640 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
| 6641 | #ifdef FEAT_RELTIME |
| 6642 | &(shl->tm) |
| 6643 | #else |
| 6644 | NULL |
| 6645 | #endif |
| 6646 | ); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6647 | if (called_emsg) |
| 6648 | { |
| 6649 | /* Error while handling regexp: stop using this regexp. */ |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 6650 | if (shl == &search_hl) |
| 6651 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6652 | /* don't free regprog in the match list, it's a copy */ |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 6653 | vim_free(shl->rm.regprog); |
| 6654 | no_hlsearch = TRUE; |
| 6655 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6656 | shl->rm.regprog = NULL; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 6657 | shl->lnum = 0; |
| 6658 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6659 | break; |
| 6660 | } |
| 6661 | if (nmatched == 0) |
| 6662 | { |
| 6663 | shl->lnum = 0; /* no match found */ |
| 6664 | break; |
| 6665 | } |
| 6666 | if (shl->rm.startpos[0].lnum > 0 |
| 6667 | || shl->rm.startpos[0].col >= mincol |
| 6668 | || nmatched > 1 |
| 6669 | || shl->rm.endpos[0].col > mincol) |
| 6670 | { |
| 6671 | shl->lnum += shl->rm.startpos[0].lnum; |
| 6672 | break; /* useful match found */ |
| 6673 | } |
| 6674 | } |
| 6675 | } |
| 6676 | #endif |
| 6677 | |
| 6678 | static void |
| 6679 | screen_start_highlight(attr) |
| 6680 | int attr; |
| 6681 | { |
| 6682 | attrentry_T *aep = NULL; |
| 6683 | |
| 6684 | screen_attr = attr; |
| 6685 | if (full_screen |
| 6686 | #ifdef WIN3264 |
| 6687 | && termcap_active |
| 6688 | #endif |
| 6689 | ) |
| 6690 | { |
| 6691 | #ifdef FEAT_GUI |
| 6692 | if (gui.in_use) |
| 6693 | { |
| 6694 | char buf[20]; |
| 6695 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6696 | /* The GUI handles this internally. */ |
| 6697 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6698 | OUT_STR(buf); |
| 6699 | } |
| 6700 | else |
| 6701 | #endif |
| 6702 | { |
| 6703 | if (attr > HL_ALL) /* special HL attr. */ |
| 6704 | { |
| 6705 | if (t_colors > 1) |
| 6706 | aep = syn_cterm_attr2entry(attr); |
| 6707 | else |
| 6708 | aep = syn_term_attr2entry(attr); |
| 6709 | if (aep == NULL) /* did ":syntax clear" */ |
| 6710 | attr = 0; |
| 6711 | else |
| 6712 | attr = aep->ae_attr; |
| 6713 | } |
| 6714 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 6715 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6716 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 6717 | && cterm_normal_fg_bold) |
| 6718 | /* If the Normal FG color has BOLD attribute and the new HL |
| 6719 | * has a FG color defined, clear BOLD. */ |
| 6720 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6721 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 6722 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6723 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 6724 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6725 | out_str(T_US); |
| 6726 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 6727 | out_str(T_CZH); |
| 6728 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 6729 | out_str(T_MR); |
| 6730 | |
| 6731 | /* |
| 6732 | * Output the color or start string after bold etc., in case the |
| 6733 | * bold etc. override the color setting. |
| 6734 | */ |
| 6735 | if (aep != NULL) |
| 6736 | { |
| 6737 | if (t_colors > 1) |
| 6738 | { |
| 6739 | if (aep->ae_u.cterm.fg_color) |
| 6740 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 6741 | if (aep->ae_u.cterm.bg_color) |
| 6742 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 6743 | } |
| 6744 | else |
| 6745 | { |
| 6746 | if (aep->ae_u.term.start != NULL) |
| 6747 | out_str(aep->ae_u.term.start); |
| 6748 | } |
| 6749 | } |
| 6750 | } |
| 6751 | } |
| 6752 | } |
| 6753 | |
| 6754 | void |
| 6755 | screen_stop_highlight() |
| 6756 | { |
| 6757 | int do_ME = FALSE; /* output T_ME code */ |
| 6758 | |
| 6759 | if (screen_attr != 0 |
| 6760 | #ifdef WIN3264 |
| 6761 | && termcap_active |
| 6762 | #endif |
| 6763 | ) |
| 6764 | { |
| 6765 | #ifdef FEAT_GUI |
| 6766 | if (gui.in_use) |
| 6767 | { |
| 6768 | char buf[20]; |
| 6769 | |
| 6770 | /* use internal GUI code */ |
| 6771 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 6772 | OUT_STR(buf); |
| 6773 | } |
| 6774 | else |
| 6775 | #endif |
| 6776 | { |
| 6777 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 6778 | { |
| 6779 | attrentry_T *aep; |
| 6780 | |
| 6781 | if (t_colors > 1) |
| 6782 | { |
| 6783 | /* |
| 6784 | * Assume that t_me restores the original colors! |
| 6785 | */ |
| 6786 | aep = syn_cterm_attr2entry(screen_attr); |
| 6787 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 6788 | || aep->ae_u.cterm.bg_color)) |
| 6789 | do_ME = TRUE; |
| 6790 | } |
| 6791 | else |
| 6792 | { |
| 6793 | aep = syn_term_attr2entry(screen_attr); |
| 6794 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 6795 | { |
| 6796 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 6797 | do_ME = TRUE; |
| 6798 | else |
| 6799 | out_str(aep->ae_u.term.stop); |
| 6800 | } |
| 6801 | } |
| 6802 | if (aep == NULL) /* did ":syntax clear" */ |
| 6803 | screen_attr = 0; |
| 6804 | else |
| 6805 | screen_attr = aep->ae_attr; |
| 6806 | } |
| 6807 | |
| 6808 | /* |
| 6809 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 6810 | * same sequence several times. |
| 6811 | */ |
| 6812 | if (screen_attr & HL_STANDOUT) |
| 6813 | { |
| 6814 | if (STRCMP(T_SE, T_ME) == 0) |
| 6815 | do_ME = TRUE; |
| 6816 | else |
| 6817 | out_str(T_SE); |
| 6818 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6819 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6820 | { |
| 6821 | if (STRCMP(T_UE, T_ME) == 0) |
| 6822 | do_ME = TRUE; |
| 6823 | else |
| 6824 | out_str(T_UE); |
| 6825 | } |
| 6826 | if (screen_attr & HL_ITALIC) |
| 6827 | { |
| 6828 | if (STRCMP(T_CZR, T_ME) == 0) |
| 6829 | do_ME = TRUE; |
| 6830 | else |
| 6831 | out_str(T_CZR); |
| 6832 | } |
| 6833 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 6834 | out_str(T_ME); |
| 6835 | |
| 6836 | if (t_colors > 1) |
| 6837 | { |
| 6838 | /* set Normal cterm colors */ |
| 6839 | if (cterm_normal_fg_color != 0) |
| 6840 | term_fg_color(cterm_normal_fg_color - 1); |
| 6841 | if (cterm_normal_bg_color != 0) |
| 6842 | term_bg_color(cterm_normal_bg_color - 1); |
| 6843 | if (cterm_normal_fg_bold) |
| 6844 | out_str(T_MD); |
| 6845 | } |
| 6846 | } |
| 6847 | } |
| 6848 | screen_attr = 0; |
| 6849 | } |
| 6850 | |
| 6851 | /* |
| 6852 | * Reset the colors for a cterm. Used when leaving Vim. |
| 6853 | * The machine specific code may override this again. |
| 6854 | */ |
| 6855 | void |
| 6856 | reset_cterm_colors() |
| 6857 | { |
| 6858 | if (t_colors > 1) |
| 6859 | { |
| 6860 | /* set Normal cterm colors */ |
| 6861 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 6862 | { |
| 6863 | out_str(T_OP); |
| 6864 | screen_attr = -1; |
| 6865 | } |
| 6866 | if (cterm_normal_fg_bold) |
| 6867 | { |
| 6868 | out_str(T_ME); |
| 6869 | screen_attr = -1; |
| 6870 | } |
| 6871 | } |
| 6872 | } |
| 6873 | |
| 6874 | /* |
| 6875 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 6876 | * using the attributes from ScreenAttrs["off"]. |
| 6877 | */ |
| 6878 | static void |
| 6879 | screen_char(off, row, col) |
| 6880 | unsigned off; |
| 6881 | int row; |
| 6882 | int col; |
| 6883 | { |
| 6884 | int attr; |
| 6885 | |
| 6886 | /* Check for illegal values, just in case (could happen just after |
| 6887 | * resizing). */ |
| 6888 | if (row >= screen_Rows || col >= screen_Columns) |
| 6889 | return; |
| 6890 | |
| 6891 | /* Outputting the last character on the screen may scrollup the screen. |
| 6892 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 6893 | if (row == screen_Rows - 1 && col == screen_Columns - 1 |
| 6894 | #ifdef FEAT_RIGHTLEFT |
| 6895 | /* account for first command-line character in rightleft mode */ |
| 6896 | && !cmdmsg_rl |
| 6897 | #endif |
| 6898 | ) |
| 6899 | { |
| 6900 | ScreenAttrs[off] = (sattr_T)-1; |
| 6901 | return; |
| 6902 | } |
| 6903 | |
| 6904 | /* |
| 6905 | * Stop highlighting first, so it's easier to move the cursor. |
| 6906 | */ |
| 6907 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 6908 | if (screen_char_attr != 0) |
| 6909 | attr = screen_char_attr; |
| 6910 | else |
| 6911 | #endif |
| 6912 | attr = ScreenAttrs[off]; |
| 6913 | if (screen_attr != attr) |
| 6914 | screen_stop_highlight(); |
| 6915 | |
| 6916 | windgoto(row, col); |
| 6917 | |
| 6918 | if (screen_attr != attr) |
| 6919 | screen_start_highlight(attr); |
| 6920 | |
| 6921 | #ifdef FEAT_MBYTE |
| 6922 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6923 | { |
| 6924 | char_u buf[MB_MAXBYTES + 1]; |
| 6925 | |
| 6926 | /* Convert UTF-8 character to bytes and write it. */ |
| 6927 | |
| 6928 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 6929 | |
| 6930 | out_str(buf); |
| 6931 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 6932 | ++screen_cur_col; |
| 6933 | } |
| 6934 | else |
| 6935 | #endif |
| 6936 | { |
| 6937 | #ifdef FEAT_MBYTE |
| 6938 | out_flush_check(); |
| 6939 | #endif |
| 6940 | out_char(ScreenLines[off]); |
| 6941 | #ifdef FEAT_MBYTE |
| 6942 | /* double-byte character in single-width cell */ |
| 6943 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6944 | out_char(ScreenLines2[off]); |
| 6945 | #endif |
| 6946 | } |
| 6947 | |
| 6948 | screen_cur_col++; |
| 6949 | } |
| 6950 | |
| 6951 | #ifdef FEAT_MBYTE |
| 6952 | |
| 6953 | /* |
| 6954 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 6955 | * on the screen at position 'row' and 'col'. |
| 6956 | * The attributes of the first byte is used for all. This is required to |
| 6957 | * output the two bytes of a double-byte character with nothing in between. |
| 6958 | */ |
| 6959 | static void |
| 6960 | screen_char_2(off, row, col) |
| 6961 | unsigned off; |
| 6962 | int row; |
| 6963 | int col; |
| 6964 | { |
| 6965 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 6966 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 6967 | return; |
| 6968 | |
| 6969 | /* Outputting the last character on the screen may scrollup the screen. |
| 6970 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 6971 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 6972 | { |
| 6973 | ScreenAttrs[off] = (sattr_T)-1; |
| 6974 | return; |
| 6975 | } |
| 6976 | |
| 6977 | /* Output the first byte normally (positions the cursor), then write the |
| 6978 | * second byte directly. */ |
| 6979 | screen_char(off, row, col); |
| 6980 | out_char(ScreenLines[off + 1]); |
| 6981 | ++screen_cur_col; |
| 6982 | } |
| 6983 | #endif |
| 6984 | |
| 6985 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 6986 | /* |
| 6987 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 6988 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 6989 | */ |
| 6990 | void |
| 6991 | screen_draw_rectangle(row, col, height, width, invert) |
| 6992 | int row; |
| 6993 | int col; |
| 6994 | int height; |
| 6995 | int width; |
| 6996 | int invert; |
| 6997 | { |
| 6998 | int r, c; |
| 6999 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7000 | #ifdef FEAT_MBYTE |
| 7001 | int max_off; |
| 7002 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7003 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7004 | /* Can't use ScreenLines unless initialized */ |
| 7005 | if (ScreenLines == NULL) |
| 7006 | return; |
| 7007 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7008 | if (invert) |
| 7009 | screen_char_attr = HL_INVERSE; |
| 7010 | for (r = row; r < row + height; ++r) |
| 7011 | { |
| 7012 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7013 | #ifdef FEAT_MBYTE |
| 7014 | max_off = off + screen_Columns; |
| 7015 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7016 | for (c = col; c < col + width; ++c) |
| 7017 | { |
| 7018 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7019 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7020 | { |
| 7021 | screen_char_2(off + c, r, c); |
| 7022 | ++c; |
| 7023 | } |
| 7024 | else |
| 7025 | #endif |
| 7026 | { |
| 7027 | screen_char(off + c, r, c); |
| 7028 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7029 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7030 | ++c; |
| 7031 | #endif |
| 7032 | } |
| 7033 | } |
| 7034 | } |
| 7035 | screen_char_attr = 0; |
| 7036 | } |
| 7037 | #endif |
| 7038 | |
| 7039 | #ifdef FEAT_VERTSPLIT |
| 7040 | /* |
| 7041 | * Redraw the characters for a vertically split window. |
| 7042 | */ |
| 7043 | static void |
| 7044 | redraw_block(row, end, wp) |
| 7045 | int row; |
| 7046 | int end; |
| 7047 | win_T *wp; |
| 7048 | { |
| 7049 | int col; |
| 7050 | int width; |
| 7051 | |
| 7052 | # ifdef FEAT_CLIPBOARD |
| 7053 | clip_may_clear_selection(row, end - 1); |
| 7054 | # endif |
| 7055 | |
| 7056 | if (wp == NULL) |
| 7057 | { |
| 7058 | col = 0; |
| 7059 | width = Columns; |
| 7060 | } |
| 7061 | else |
| 7062 | { |
| 7063 | col = wp->w_wincol; |
| 7064 | width = wp->w_width; |
| 7065 | } |
| 7066 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 7067 | } |
| 7068 | #endif |
| 7069 | |
| 7070 | /* |
| 7071 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 7072 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 7073 | * Use attributes 'attr'. |
| 7074 | */ |
| 7075 | void |
| 7076 | screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) |
| 7077 | int start_row, end_row; |
| 7078 | int start_col, end_col; |
| 7079 | int c1, c2; |
| 7080 | int attr; |
| 7081 | { |
| 7082 | int row; |
| 7083 | int col; |
| 7084 | int off; |
| 7085 | int end_off; |
| 7086 | int did_delete; |
| 7087 | int c; |
| 7088 | int norm_term; |
| 7089 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7090 | int force_next = FALSE; |
| 7091 | #endif |
| 7092 | |
| 7093 | if (end_row > screen_Rows) /* safety check */ |
| 7094 | end_row = screen_Rows; |
| 7095 | if (end_col > screen_Columns) /* safety check */ |
| 7096 | end_col = screen_Columns; |
| 7097 | if (ScreenLines == NULL |
| 7098 | || start_row >= end_row |
| 7099 | || start_col >= end_col) /* nothing to do */ |
| 7100 | return; |
| 7101 | |
| 7102 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 7103 | norm_term = ( |
| 7104 | #ifdef FEAT_GUI |
| 7105 | !gui.in_use && |
| 7106 | #endif |
| 7107 | t_colors <= 1); |
| 7108 | for (row = start_row; row < end_row; ++row) |
| 7109 | { |
| 7110 | /* |
| 7111 | * Try to use delete-line termcap code, when no attributes or in a |
| 7112 | * "normal" terminal, where a bold/italic space is just a |
| 7113 | * space. |
| 7114 | */ |
| 7115 | did_delete = FALSE; |
| 7116 | if (c2 == ' ' |
| 7117 | && end_col == Columns |
| 7118 | && can_clear(T_CE) |
| 7119 | && (attr == 0 |
| 7120 | || (norm_term |
| 7121 | && attr <= HL_ALL |
| 7122 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 7123 | { |
| 7124 | /* |
| 7125 | * check if we really need to clear something |
| 7126 | */ |
| 7127 | col = start_col; |
| 7128 | if (c1 != ' ') /* don't clear first char */ |
| 7129 | ++col; |
| 7130 | |
| 7131 | off = LineOffset[row] + col; |
| 7132 | end_off = LineOffset[row] + end_col; |
| 7133 | |
| 7134 | /* skip blanks (used often, keep it fast!) */ |
| 7135 | #ifdef FEAT_MBYTE |
| 7136 | if (enc_utf8) |
| 7137 | while (off < end_off && ScreenLines[off] == ' ' |
| 7138 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 7139 | ++off; |
| 7140 | else |
| 7141 | #endif |
| 7142 | while (off < end_off && ScreenLines[off] == ' ' |
| 7143 | && ScreenAttrs[off] == 0) |
| 7144 | ++off; |
| 7145 | if (off < end_off) /* something to be cleared */ |
| 7146 | { |
| 7147 | col = off - LineOffset[row]; |
| 7148 | screen_stop_highlight(); |
| 7149 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 7150 | out_str(T_CE); |
| 7151 | screen_start(); /* don't know where cursor is now */ |
| 7152 | col = end_col - col; |
| 7153 | while (col--) /* clear chars in ScreenLines */ |
| 7154 | { |
| 7155 | ScreenLines[off] = ' '; |
| 7156 | #ifdef FEAT_MBYTE |
| 7157 | if (enc_utf8) |
| 7158 | ScreenLinesUC[off] = 0; |
| 7159 | #endif |
| 7160 | ScreenAttrs[off] = 0; |
| 7161 | ++off; |
| 7162 | } |
| 7163 | } |
| 7164 | did_delete = TRUE; /* the chars are cleared now */ |
| 7165 | } |
| 7166 | |
| 7167 | off = LineOffset[row] + start_col; |
| 7168 | c = c1; |
| 7169 | for (col = start_col; col < end_col; ++col) |
| 7170 | { |
| 7171 | if (ScreenLines[off] != c |
| 7172 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7173 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 7174 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7175 | #endif |
| 7176 | || ScreenAttrs[off] != attr |
| 7177 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7178 | || force_next |
| 7179 | #endif |
| 7180 | ) |
| 7181 | { |
| 7182 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7183 | /* The bold trick may make a single row of pixels appear in |
| 7184 | * the next character. When a bold character is removed, the |
| 7185 | * next character should be redrawn too. This happens for our |
| 7186 | * own GUI and for some xterms. */ |
| 7187 | if ( |
| 7188 | # ifdef FEAT_GUI |
| 7189 | gui.in_use |
| 7190 | # endif |
| 7191 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7192 | || |
| 7193 | # endif |
| 7194 | # ifdef UNIX |
| 7195 | term_is_xterm |
| 7196 | # endif |
| 7197 | ) |
| 7198 | { |
| 7199 | if (ScreenLines[off] != ' ' |
| 7200 | && (ScreenAttrs[off] > HL_ALL |
| 7201 | || ScreenAttrs[off] & HL_BOLD)) |
| 7202 | force_next = TRUE; |
| 7203 | else |
| 7204 | force_next = FALSE; |
| 7205 | } |
| 7206 | #endif |
| 7207 | ScreenLines[off] = c; |
| 7208 | #ifdef FEAT_MBYTE |
| 7209 | if (enc_utf8) |
| 7210 | { |
| 7211 | if (c >= 0x80) |
| 7212 | { |
| 7213 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7214 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7215 | } |
| 7216 | else |
| 7217 | ScreenLinesUC[off] = 0; |
| 7218 | } |
| 7219 | #endif |
| 7220 | ScreenAttrs[off] = attr; |
| 7221 | if (!did_delete || c != ' ') |
| 7222 | screen_char(off, row, col); |
| 7223 | } |
| 7224 | ++off; |
| 7225 | if (col == start_col) |
| 7226 | { |
| 7227 | if (did_delete) |
| 7228 | break; |
| 7229 | c = c2; |
| 7230 | } |
| 7231 | } |
| 7232 | if (end_col == Columns) |
| 7233 | LineWraps[row] = FALSE; |
| 7234 | if (row == Rows - 1) /* overwritten the command line */ |
| 7235 | { |
| 7236 | redraw_cmdline = TRUE; |
| 7237 | if (c1 == ' ' && c2 == ' ') |
| 7238 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7239 | if (start_col == 0) |
| 7240 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7241 | } |
| 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | /* |
| 7246 | * Check if there should be a delay. Used before clearing or redrawing the |
| 7247 | * screen or the command line. |
| 7248 | */ |
| 7249 | void |
| 7250 | check_for_delay(check_msg_scroll) |
| 7251 | int check_msg_scroll; |
| 7252 | { |
| 7253 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 7254 | && !did_wait_return |
| 7255 | && emsg_silent == 0) |
| 7256 | { |
| 7257 | out_flush(); |
| 7258 | ui_delay(1000L, TRUE); |
| 7259 | emsg_on_display = FALSE; |
| 7260 | if (check_msg_scroll) |
| 7261 | msg_scroll = FALSE; |
| 7262 | } |
| 7263 | } |
| 7264 | |
| 7265 | /* |
| 7266 | * screen_valid - allocate screen buffers if size changed |
| 7267 | * If "clear" is TRUE: clear screen if it has been resized. |
| 7268 | * Returns TRUE if there is a valid screen to write to. |
| 7269 | * Returns FALSE when starting up and screen not initialized yet. |
| 7270 | */ |
| 7271 | int |
| 7272 | screen_valid(clear) |
| 7273 | int clear; |
| 7274 | { |
| 7275 | screenalloc(clear); /* allocate screen buffers if size changed */ |
| 7276 | return (ScreenLines != NULL); |
| 7277 | } |
| 7278 | |
| 7279 | /* |
| 7280 | * Resize the shell to Rows and Columns. |
| 7281 | * Allocate ScreenLines[] and associated items. |
| 7282 | * |
| 7283 | * There may be some time between setting Rows and Columns and (re)allocating |
| 7284 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 7285 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 7286 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 7287 | * final size of the shell is needed. |
| 7288 | */ |
| 7289 | void |
| 7290 | screenalloc(clear) |
| 7291 | int clear; |
| 7292 | { |
| 7293 | int new_row, old_row; |
| 7294 | #ifdef FEAT_GUI |
| 7295 | int old_Rows; |
| 7296 | #endif |
| 7297 | win_T *wp; |
| 7298 | int outofmem = FALSE; |
| 7299 | int len; |
| 7300 | schar_T *new_ScreenLines; |
| 7301 | #ifdef FEAT_MBYTE |
| 7302 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7303 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7304 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7305 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7306 | #endif |
| 7307 | sattr_T *new_ScreenAttrs; |
| 7308 | unsigned *new_LineOffset; |
| 7309 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7310 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7311 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7312 | tabpage_T *tp; |
| 7313 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7314 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7315 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7316 | |
| 7317 | /* |
| 7318 | * Allocation of the screen buffers is done only when the size changes and |
| 7319 | * when Rows and Columns have been set and we have started doing full |
| 7320 | * screen stuff. |
| 7321 | */ |
| 7322 | if ((ScreenLines != NULL |
| 7323 | && Rows == screen_Rows |
| 7324 | && Columns == screen_Columns |
| 7325 | #ifdef FEAT_MBYTE |
| 7326 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 7327 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7328 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7329 | #endif |
| 7330 | ) |
| 7331 | || Rows == 0 |
| 7332 | || Columns == 0 |
| 7333 | || (!full_screen && ScreenLines == NULL)) |
| 7334 | return; |
| 7335 | |
| 7336 | /* |
| 7337 | * It's possible that we produce an out-of-memory message below, which |
| 7338 | * will cause this function to be called again. To break the loop, just |
| 7339 | * return here. |
| 7340 | */ |
| 7341 | if (entered) |
| 7342 | return; |
| 7343 | entered = TRUE; |
| 7344 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 7345 | /* |
| 7346 | * Note that the window sizes are updated before reallocating the arrays, |
| 7347 | * thus we must not redraw here! |
| 7348 | */ |
| 7349 | ++RedrawingDisabled; |
| 7350 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7351 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 7352 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7353 | comp_col(); /* recompute columns for shown command and ruler */ |
| 7354 | |
| 7355 | /* |
| 7356 | * We're changing the size of the screen. |
| 7357 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 7358 | * - Move lines from the old arrays into the new arrays, clear extra |
| 7359 | * lines (unless the screen is going to be cleared). |
| 7360 | * - Free the old arrays. |
| 7361 | * |
| 7362 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 7363 | * Continuing with the old ScreenLines may result in a crash, because the |
| 7364 | * size is wrong. |
| 7365 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7366 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7367 | win_free_lsize(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7368 | |
| 7369 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 7370 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 7371 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7372 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7373 | if (enc_utf8) |
| 7374 | { |
| 7375 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 7376 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7377 | for (i = 0; i < p_mco; ++i) |
| 7378 | new_ScreenLinesC[i] = (u8char_T *)lalloc((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7379 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 7380 | } |
| 7381 | if (enc_dbcs == DBCS_JPNU) |
| 7382 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 7383 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 7384 | #endif |
| 7385 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 7386 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 7387 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 7388 | Rows * sizeof(unsigned)), FALSE); |
| 7389 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7390 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7391 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7392 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7393 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7394 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7395 | { |
| 7396 | if (win_alloc_lines(wp) == FAIL) |
| 7397 | { |
| 7398 | outofmem = TRUE; |
| 7399 | #ifdef FEAT_WINDOWS |
| 7400 | break; |
| 7401 | #endif |
| 7402 | } |
| 7403 | } |
| 7404 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7405 | #ifdef FEAT_MBYTE |
| 7406 | for (i = 0; i < p_mco; ++i) |
| 7407 | if (new_ScreenLinesC[i] == NULL) |
| 7408 | break; |
| 7409 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7410 | if (new_ScreenLines == NULL |
| 7411 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7412 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7413 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 7414 | #endif |
| 7415 | || new_ScreenAttrs == NULL |
| 7416 | || new_LineOffset == NULL |
| 7417 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7418 | #ifdef FEAT_WINDOWS |
| 7419 | || new_TabPageIdxs == NULL |
| 7420 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7421 | || outofmem) |
| 7422 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7423 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7424 | { |
| 7425 | /* guess the size */ |
| 7426 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 7427 | |
| 7428 | /* Remember we did this to avoid getting outofmem messages over |
| 7429 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7430 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7431 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7432 | vim_free(new_ScreenLines); |
| 7433 | new_ScreenLines = NULL; |
| 7434 | #ifdef FEAT_MBYTE |
| 7435 | vim_free(new_ScreenLinesUC); |
| 7436 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7437 | for (i = 0; i < p_mco; ++i) |
| 7438 | { |
| 7439 | vim_free(new_ScreenLinesC[i]); |
| 7440 | new_ScreenLinesC[i] = NULL; |
| 7441 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7442 | vim_free(new_ScreenLines2); |
| 7443 | new_ScreenLines2 = NULL; |
| 7444 | #endif |
| 7445 | vim_free(new_ScreenAttrs); |
| 7446 | new_ScreenAttrs = NULL; |
| 7447 | vim_free(new_LineOffset); |
| 7448 | new_LineOffset = NULL; |
| 7449 | vim_free(new_LineWraps); |
| 7450 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7451 | #ifdef FEAT_WINDOWS |
| 7452 | vim_free(new_TabPageIdxs); |
| 7453 | new_TabPageIdxs = NULL; |
| 7454 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7455 | } |
| 7456 | else |
| 7457 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7458 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7459 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7460 | for (new_row = 0; new_row < Rows; ++new_row) |
| 7461 | { |
| 7462 | new_LineOffset[new_row] = new_row * Columns; |
| 7463 | new_LineWraps[new_row] = FALSE; |
| 7464 | |
| 7465 | /* |
| 7466 | * If the screen is not going to be cleared, copy as much as |
| 7467 | * possible from the old screen to the new one and clear the rest |
| 7468 | * (used when resizing the window at the "--more--" prompt or when |
| 7469 | * executing an external command, for the GUI). |
| 7470 | */ |
| 7471 | if (!clear) |
| 7472 | { |
| 7473 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 7474 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 7475 | #ifdef FEAT_MBYTE |
| 7476 | if (enc_utf8) |
| 7477 | { |
| 7478 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 7479 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7480 | for (i = 0; i < p_mco; ++i) |
| 7481 | (void)vim_memset(new_ScreenLinesC[i] |
| 7482 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7483 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 7484 | } |
| 7485 | if (enc_dbcs == DBCS_JPNU) |
| 7486 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 7487 | 0, (size_t)Columns * sizeof(schar_T)); |
| 7488 | #endif |
| 7489 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 7490 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 7491 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7492 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7493 | { |
| 7494 | if (screen_Columns < Columns) |
| 7495 | len = screen_Columns; |
| 7496 | else |
| 7497 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 7498 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 7499 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7500 | * may be invalid now. Also when p_mco changes. */ |
| 7501 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 7502 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 7503 | #endif |
| 7504 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 7505 | ScreenLines + LineOffset[old_row], |
| 7506 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7507 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7508 | if (enc_utf8 && ScreenLinesUC != NULL |
| 7509 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7510 | { |
| 7511 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 7512 | ScreenLinesUC + LineOffset[old_row], |
| 7513 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7514 | for (i = 0; i < p_mco; ++i) |
| 7515 | mch_memmove(new_ScreenLinesC[i] |
| 7516 | + new_LineOffset[new_row], |
| 7517 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7518 | (size_t)len * sizeof(u8char_T)); |
| 7519 | } |
| 7520 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 7521 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 7522 | ScreenLines2 + LineOffset[old_row], |
| 7523 | (size_t)len * sizeof(schar_T)); |
| 7524 | #endif |
| 7525 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 7526 | ScreenAttrs + LineOffset[old_row], |
| 7527 | (size_t)len * sizeof(sattr_T)); |
| 7528 | } |
| 7529 | } |
| 7530 | } |
| 7531 | /* Use the last line of the screen for the current line. */ |
| 7532 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 7533 | } |
| 7534 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7535 | free_screenlines(); |
| 7536 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7537 | ScreenLines = new_ScreenLines; |
| 7538 | #ifdef FEAT_MBYTE |
| 7539 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7540 | for (i = 0; i < p_mco; ++i) |
| 7541 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 7542 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7543 | ScreenLines2 = new_ScreenLines2; |
| 7544 | #endif |
| 7545 | ScreenAttrs = new_ScreenAttrs; |
| 7546 | LineOffset = new_LineOffset; |
| 7547 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7548 | #ifdef FEAT_WINDOWS |
| 7549 | TabPageIdxs = new_TabPageIdxs; |
| 7550 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7551 | |
| 7552 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 7553 | * size of ScreenLines[]. Set them before calling anything. */ |
| 7554 | #ifdef FEAT_GUI |
| 7555 | old_Rows = screen_Rows; |
| 7556 | #endif |
| 7557 | screen_Rows = Rows; |
| 7558 | screen_Columns = Columns; |
| 7559 | |
| 7560 | must_redraw = CLEAR; /* need to clear the screen later */ |
| 7561 | if (clear) |
| 7562 | screenclear2(); |
| 7563 | |
| 7564 | #ifdef FEAT_GUI |
| 7565 | else if (gui.in_use |
| 7566 | && !gui.starting |
| 7567 | && ScreenLines != NULL |
| 7568 | && old_Rows != Rows) |
| 7569 | { |
| 7570 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 7571 | /* |
| 7572 | * Adjust the position of the cursor, for when executing an external |
| 7573 | * command. |
| 7574 | */ |
| 7575 | if (msg_row >= Rows) /* Rows got smaller */ |
| 7576 | msg_row = Rows - 1; /* put cursor at last row */ |
| 7577 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 7578 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 7579 | if (msg_col >= Columns) /* Columns got smaller */ |
| 7580 | msg_col = Columns - 1; /* put cursor at last column */ |
| 7581 | } |
| 7582 | #endif |
| 7583 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7584 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 7585 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 7586 | |
| 7587 | #ifdef FEAT_AUTOCMD |
| 7588 | if (starting == 0) |
| 7589 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
| 7590 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7591 | } |
| 7592 | |
| 7593 | void |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7594 | free_screenlines() |
| 7595 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7596 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7597 | int i; |
| 7598 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7599 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7600 | for (i = 0; i < Screen_mco; ++i) |
| 7601 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7602 | vim_free(ScreenLines2); |
| 7603 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7604 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7605 | vim_free(ScreenAttrs); |
| 7606 | vim_free(LineOffset); |
| 7607 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7608 | #ifdef FEAT_WINDOWS |
| 7609 | vim_free(TabPageIdxs); |
| 7610 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7611 | } |
| 7612 | |
| 7613 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7614 | screenclear() |
| 7615 | { |
| 7616 | check_for_delay(FALSE); |
| 7617 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 7618 | screenclear2(); /* clear the screen */ |
| 7619 | } |
| 7620 | |
| 7621 | static void |
| 7622 | screenclear2() |
| 7623 | { |
| 7624 | int i; |
| 7625 | |
| 7626 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 7627 | #ifdef FEAT_GUI |
| 7628 | || (gui.in_use && gui.starting) |
| 7629 | #endif |
| 7630 | ) |
| 7631 | return; |
| 7632 | |
| 7633 | #ifdef FEAT_GUI |
| 7634 | if (!gui.in_use) |
| 7635 | #endif |
| 7636 | screen_attr = -1; /* force setting the Normal colors */ |
| 7637 | screen_stop_highlight(); /* don't want highlighting here */ |
| 7638 | |
| 7639 | #ifdef FEAT_CLIPBOARD |
| 7640 | /* disable selection without redrawing it */ |
| 7641 | clip_scroll_selection(9999); |
| 7642 | #endif |
| 7643 | |
| 7644 | /* blank out ScreenLines */ |
| 7645 | for (i = 0; i < Rows; ++i) |
| 7646 | { |
| 7647 | lineclear(LineOffset[i], (int)Columns); |
| 7648 | LineWraps[i] = FALSE; |
| 7649 | } |
| 7650 | |
| 7651 | if (can_clear(T_CL)) |
| 7652 | { |
| 7653 | out_str(T_CL); /* clear the display */ |
| 7654 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7655 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7656 | } |
| 7657 | else |
| 7658 | { |
| 7659 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 7660 | for (i = 0; i < Rows; ++i) |
| 7661 | lineinvalid(LineOffset[i], (int)Columns); |
| 7662 | clear_cmdline = TRUE; |
| 7663 | } |
| 7664 | |
| 7665 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 7666 | |
| 7667 | win_rest_invalid(firstwin); |
| 7668 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 7669 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 7670 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 7671 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7672 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 7673 | must_redraw = NOT_VALID; |
| 7674 | compute_cmdrow(); |
| 7675 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 7676 | msg_col = 0; |
| 7677 | screen_start(); /* don't know where cursor is now */ |
| 7678 | msg_scrolled = 0; /* can't scroll back */ |
| 7679 | msg_didany = FALSE; |
| 7680 | msg_didout = FALSE; |
| 7681 | } |
| 7682 | |
| 7683 | /* |
| 7684 | * Clear one line in ScreenLines. |
| 7685 | */ |
| 7686 | static void |
| 7687 | lineclear(off, width) |
| 7688 | unsigned off; |
| 7689 | int width; |
| 7690 | { |
| 7691 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 7692 | #ifdef FEAT_MBYTE |
| 7693 | if (enc_utf8) |
| 7694 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 7695 | (size_t)width * sizeof(u8char_T)); |
| 7696 | #endif |
| 7697 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 7698 | } |
| 7699 | |
| 7700 | /* |
| 7701 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 7702 | * invalid value. |
| 7703 | */ |
| 7704 | static void |
| 7705 | lineinvalid(off, width) |
| 7706 | unsigned off; |
| 7707 | int width; |
| 7708 | { |
| 7709 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 7710 | } |
| 7711 | |
| 7712 | #ifdef FEAT_VERTSPLIT |
| 7713 | /* |
| 7714 | * Copy part of a Screenline for vertically split window "wp". |
| 7715 | */ |
| 7716 | static void |
| 7717 | linecopy(to, from, wp) |
| 7718 | int to; |
| 7719 | int from; |
| 7720 | win_T *wp; |
| 7721 | { |
| 7722 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 7723 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 7724 | |
| 7725 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 7726 | wp->w_width * sizeof(schar_T)); |
| 7727 | # ifdef FEAT_MBYTE |
| 7728 | if (enc_utf8) |
| 7729 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7730 | int i; |
| 7731 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7732 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 7733 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7734 | for (i = 0; i < p_mco; ++i) |
| 7735 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 7736 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7737 | } |
| 7738 | if (enc_dbcs == DBCS_JPNU) |
| 7739 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 7740 | wp->w_width * sizeof(schar_T)); |
| 7741 | # endif |
| 7742 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 7743 | wp->w_width * sizeof(sattr_T)); |
| 7744 | } |
| 7745 | #endif |
| 7746 | |
| 7747 | /* |
| 7748 | * Return TRUE if clearing with term string "p" would work. |
| 7749 | * It can't work when the string is empty or it won't set the right background. |
| 7750 | */ |
| 7751 | int |
| 7752 | can_clear(p) |
| 7753 | char_u *p; |
| 7754 | { |
| 7755 | return (*p != NUL && (t_colors <= 1 |
| 7756 | #ifdef FEAT_GUI |
| 7757 | || gui.in_use |
| 7758 | #endif |
| 7759 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 7760 | } |
| 7761 | |
| 7762 | /* |
| 7763 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 7764 | * something directly to the screen (shell commands) or a terminal control |
| 7765 | * code. |
| 7766 | */ |
| 7767 | void |
| 7768 | screen_start() |
| 7769 | { |
| 7770 | screen_cur_row = screen_cur_col = 9999; |
| 7771 | } |
| 7772 | |
| 7773 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7774 | * Move the cursor to position "row","col" in the screen. |
| 7775 | * This tries to find the most efficient way to move, minimizing the number of |
| 7776 | * characters sent to the terminal. |
| 7777 | */ |
| 7778 | void |
| 7779 | windgoto(row, col) |
| 7780 | int row; |
| 7781 | int col; |
| 7782 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7783 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7784 | int i; |
| 7785 | int plan; |
| 7786 | int cost; |
| 7787 | int wouldbe_col; |
| 7788 | int noinvcurs; |
| 7789 | char_u *bs; |
| 7790 | int goto_cost; |
| 7791 | int attr; |
| 7792 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 7793 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7794 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 7795 | |
| 7796 | #define PLAN_LE 1 |
| 7797 | #define PLAN_CR 2 |
| 7798 | #define PLAN_NL 3 |
| 7799 | #define PLAN_WRITE 4 |
| 7800 | /* Can't use ScreenLines unless initialized */ |
| 7801 | if (ScreenLines == NULL) |
| 7802 | return; |
| 7803 | |
| 7804 | if (col != screen_cur_col || row != screen_cur_row) |
| 7805 | { |
| 7806 | /* Check for valid position. */ |
| 7807 | if (row < 0) /* window without text lines? */ |
| 7808 | row = 0; |
| 7809 | if (row >= screen_Rows) |
| 7810 | row = screen_Rows - 1; |
| 7811 | if (col >= screen_Columns) |
| 7812 | col = screen_Columns - 1; |
| 7813 | |
| 7814 | /* check if no cursor movement is allowed in highlight mode */ |
| 7815 | if (screen_attr && *T_MS == NUL) |
| 7816 | noinvcurs = HIGHL_COST; |
| 7817 | else |
| 7818 | noinvcurs = 0; |
| 7819 | goto_cost = GOTO_COST + noinvcurs; |
| 7820 | |
| 7821 | /* |
| 7822 | * Plan how to do the positioning: |
| 7823 | * 1. Use CR to move it to column 0, same row. |
| 7824 | * 2. Use T_LE to move it a few columns to the left. |
| 7825 | * 3. Use NL to move a few lines down, column 0. |
| 7826 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 7827 | * |
| 7828 | * Don't do this if the cursor went beyond the last column, the cursor |
| 7829 | * position is unknown then (some terminals wrap, some don't ) |
| 7830 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 7831 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7832 | * characters to move the cursor to the right. |
| 7833 | */ |
| 7834 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 7835 | { |
| 7836 | /* |
| 7837 | * If the cursor is in the same row, bigger col, we can use CR |
| 7838 | * or T_LE. |
| 7839 | */ |
| 7840 | bs = NULL; /* init for GCC */ |
| 7841 | attr = screen_attr; |
| 7842 | if (row == screen_cur_row && col < screen_cur_col) |
| 7843 | { |
| 7844 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 7845 | if (*T_LE) |
| 7846 | bs = T_LE; /* "cursor left" */ |
| 7847 | else |
| 7848 | bs = T_BC; /* "backspace character (old) */ |
| 7849 | if (*bs) |
| 7850 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 7851 | else |
| 7852 | cost = 999; |
| 7853 | if (col + 1 < cost) /* using CR is less characters */ |
| 7854 | { |
| 7855 | plan = PLAN_CR; |
| 7856 | wouldbe_col = 0; |
| 7857 | cost = 1; /* CR is just one character */ |
| 7858 | } |
| 7859 | else |
| 7860 | { |
| 7861 | plan = PLAN_LE; |
| 7862 | wouldbe_col = col; |
| 7863 | } |
| 7864 | if (noinvcurs) /* will stop highlighting */ |
| 7865 | { |
| 7866 | cost += noinvcurs; |
| 7867 | attr = 0; |
| 7868 | } |
| 7869 | } |
| 7870 | |
| 7871 | /* |
| 7872 | * If the cursor is above where we want to be, we can use CR LF. |
| 7873 | */ |
| 7874 | else if (row > screen_cur_row) |
| 7875 | { |
| 7876 | plan = PLAN_NL; |
| 7877 | wouldbe_col = 0; |
| 7878 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 7879 | if (noinvcurs) /* will stop highlighting */ |
| 7880 | { |
| 7881 | cost += noinvcurs; |
| 7882 | attr = 0; |
| 7883 | } |
| 7884 | } |
| 7885 | |
| 7886 | /* |
| 7887 | * If the cursor is in the same row, smaller col, just use write. |
| 7888 | */ |
| 7889 | else |
| 7890 | { |
| 7891 | plan = PLAN_WRITE; |
| 7892 | wouldbe_col = screen_cur_col; |
| 7893 | cost = 0; |
| 7894 | } |
| 7895 | |
| 7896 | /* |
| 7897 | * Check if any characters that need to be written have the |
| 7898 | * correct attributes. Also avoid UTF-8 characters. |
| 7899 | */ |
| 7900 | i = col - wouldbe_col; |
| 7901 | if (i > 0) |
| 7902 | cost += i; |
| 7903 | if (cost < goto_cost && i > 0) |
| 7904 | { |
| 7905 | /* |
| 7906 | * Check if the attributes are correct without additionally |
| 7907 | * stopping highlighting. |
| 7908 | */ |
| 7909 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 7910 | while (i && *p++ == attr) |
| 7911 | --i; |
| 7912 | if (i != 0) |
| 7913 | { |
| 7914 | /* |
| 7915 | * Try if it works when highlighting is stopped here. |
| 7916 | */ |
| 7917 | if (*--p == 0) |
| 7918 | { |
| 7919 | cost += noinvcurs; |
| 7920 | while (i && *p++ == 0) |
| 7921 | --i; |
| 7922 | } |
| 7923 | if (i != 0) |
| 7924 | cost = 999; /* different attributes, don't do it */ |
| 7925 | } |
| 7926 | #ifdef FEAT_MBYTE |
| 7927 | if (enc_utf8) |
| 7928 | { |
| 7929 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 7930 | for (i = wouldbe_col; i < col; ++i) |
| 7931 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 7932 | { |
| 7933 | cost = 999; |
| 7934 | break; |
| 7935 | } |
| 7936 | } |
| 7937 | #endif |
| 7938 | } |
| 7939 | |
| 7940 | /* |
| 7941 | * We can do it without term_windgoto()! |
| 7942 | */ |
| 7943 | if (cost < goto_cost) |
| 7944 | { |
| 7945 | if (plan == PLAN_LE) |
| 7946 | { |
| 7947 | if (noinvcurs) |
| 7948 | screen_stop_highlight(); |
| 7949 | while (screen_cur_col > col) |
| 7950 | { |
| 7951 | out_str(bs); |
| 7952 | --screen_cur_col; |
| 7953 | } |
| 7954 | } |
| 7955 | else if (plan == PLAN_CR) |
| 7956 | { |
| 7957 | if (noinvcurs) |
| 7958 | screen_stop_highlight(); |
| 7959 | out_char('\r'); |
| 7960 | screen_cur_col = 0; |
| 7961 | } |
| 7962 | else if (plan == PLAN_NL) |
| 7963 | { |
| 7964 | if (noinvcurs) |
| 7965 | screen_stop_highlight(); |
| 7966 | while (screen_cur_row < row) |
| 7967 | { |
| 7968 | out_char('\n'); |
| 7969 | ++screen_cur_row; |
| 7970 | } |
| 7971 | screen_cur_col = 0; |
| 7972 | } |
| 7973 | |
| 7974 | i = col - screen_cur_col; |
| 7975 | if (i > 0) |
| 7976 | { |
| 7977 | /* |
| 7978 | * Use cursor-right if it's one character only. Avoids |
| 7979 | * removing a line of pixels from the last bold char, when |
| 7980 | * using the bold trick in the GUI. |
| 7981 | */ |
| 7982 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 7983 | { |
| 7984 | while (i-- > 0) |
| 7985 | out_char(*T_ND); |
| 7986 | } |
| 7987 | else |
| 7988 | { |
| 7989 | int off; |
| 7990 | |
| 7991 | off = LineOffset[row] + screen_cur_col; |
| 7992 | while (i-- > 0) |
| 7993 | { |
| 7994 | if (ScreenAttrs[off] != screen_attr) |
| 7995 | screen_stop_highlight(); |
| 7996 | #ifdef FEAT_MBYTE |
| 7997 | out_flush_check(); |
| 7998 | #endif |
| 7999 | out_char(ScreenLines[off]); |
| 8000 | #ifdef FEAT_MBYTE |
| 8001 | if (enc_dbcs == DBCS_JPNU |
| 8002 | && ScreenLines[off] == 0x8e) |
| 8003 | out_char(ScreenLines2[off]); |
| 8004 | #endif |
| 8005 | ++off; |
| 8006 | } |
| 8007 | } |
| 8008 | } |
| 8009 | } |
| 8010 | } |
| 8011 | else |
| 8012 | cost = 999; |
| 8013 | |
| 8014 | if (cost >= goto_cost) |
| 8015 | { |
| 8016 | if (noinvcurs) |
| 8017 | screen_stop_highlight(); |
| 8018 | if (row == screen_cur_row && (col > screen_cur_col) && |
| 8019 | *T_CRI != NUL) |
| 8020 | term_cursor_right(col - screen_cur_col); |
| 8021 | else |
| 8022 | term_windgoto(row, col); |
| 8023 | } |
| 8024 | screen_cur_row = row; |
| 8025 | screen_cur_col = col; |
| 8026 | } |
| 8027 | } |
| 8028 | |
| 8029 | /* |
| 8030 | * Set cursor to its position in the current window. |
| 8031 | */ |
| 8032 | void |
| 8033 | setcursor() |
| 8034 | { |
| 8035 | if (redrawing()) |
| 8036 | { |
| 8037 | validate_cursor(); |
| 8038 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 8039 | W_WINCOL(curwin) + ( |
| 8040 | #ifdef FEAT_RIGHTLEFT |
| 8041 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 8042 | # ifdef FEAT_MBYTE |
| 8043 | has_mbyte ? (*mb_ptr2cells)(ml_get_cursor()) : |
| 8044 | # endif |
| 8045 | 1)) : |
| 8046 | #endif |
| 8047 | curwin->w_wcol)); |
| 8048 | } |
| 8049 | } |
| 8050 | |
| 8051 | |
| 8052 | /* |
| 8053 | * insert 'line_count' lines at 'row' in window 'wp' |
| 8054 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 8055 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 8056 | * scrolling. |
| 8057 | * Returns FAIL if the lines are not inserted, OK for success. |
| 8058 | */ |
| 8059 | int |
| 8060 | win_ins_lines(wp, row, line_count, invalid, mayclear) |
| 8061 | win_T *wp; |
| 8062 | int row; |
| 8063 | int line_count; |
| 8064 | int invalid; |
| 8065 | int mayclear; |
| 8066 | { |
| 8067 | int did_delete; |
| 8068 | int nextrow; |
| 8069 | int lastrow; |
| 8070 | int retval; |
| 8071 | |
| 8072 | if (invalid) |
| 8073 | wp->w_lines_valid = 0; |
| 8074 | |
| 8075 | if (wp->w_height < 5) |
| 8076 | return FAIL; |
| 8077 | |
| 8078 | if (line_count > wp->w_height - row) |
| 8079 | line_count = wp->w_height - row; |
| 8080 | |
| 8081 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 8082 | if (retval != MAYBE) |
| 8083 | return retval; |
| 8084 | |
| 8085 | /* |
| 8086 | * If there is a next window or a status line, we first try to delete the |
| 8087 | * lines at the bottom to avoid messing what is after the window. |
| 8088 | * If this fails and there are following windows, don't do anything to avoid |
| 8089 | * messing up those windows, better just redraw. |
| 8090 | */ |
| 8091 | did_delete = FALSE; |
| 8092 | #ifdef FEAT_WINDOWS |
| 8093 | if (wp->w_next != NULL || wp->w_status_height) |
| 8094 | { |
| 8095 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8096 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 8097 | did_delete = TRUE; |
| 8098 | else if (wp->w_next) |
| 8099 | return FAIL; |
| 8100 | } |
| 8101 | #endif |
| 8102 | /* |
| 8103 | * if no lines deleted, blank the lines that will end up below the window |
| 8104 | */ |
| 8105 | if (!did_delete) |
| 8106 | { |
| 8107 | #ifdef FEAT_WINDOWS |
| 8108 | wp->w_redr_status = TRUE; |
| 8109 | #endif |
| 8110 | redraw_cmdline = TRUE; |
| 8111 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 8112 | lastrow = nextrow + line_count; |
| 8113 | if (lastrow > Rows) |
| 8114 | lastrow = Rows; |
| 8115 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 8116 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8117 | ' ', ' ', 0); |
| 8118 | } |
| 8119 | |
| 8120 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 8121 | == FAIL) |
| 8122 | { |
| 8123 | /* deletion will have messed up other windows */ |
| 8124 | if (did_delete) |
| 8125 | { |
| 8126 | #ifdef FEAT_WINDOWS |
| 8127 | wp->w_redr_status = TRUE; |
| 8128 | #endif |
| 8129 | win_rest_invalid(W_NEXT(wp)); |
| 8130 | } |
| 8131 | return FAIL; |
| 8132 | } |
| 8133 | |
| 8134 | return OK; |
| 8135 | } |
| 8136 | |
| 8137 | /* |
| 8138 | * delete "line_count" window lines at "row" in window "wp" |
| 8139 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 8140 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 8141 | * scrolling |
| 8142 | * Return OK for success, FAIL if the lines are not deleted. |
| 8143 | */ |
| 8144 | int |
| 8145 | win_del_lines(wp, row, line_count, invalid, mayclear) |
| 8146 | win_T *wp; |
| 8147 | int row; |
| 8148 | int line_count; |
| 8149 | int invalid; |
| 8150 | int mayclear; |
| 8151 | { |
| 8152 | int retval; |
| 8153 | |
| 8154 | if (invalid) |
| 8155 | wp->w_lines_valid = 0; |
| 8156 | |
| 8157 | if (line_count > wp->w_height - row) |
| 8158 | line_count = wp->w_height - row; |
| 8159 | |
| 8160 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 8161 | if (retval != MAYBE) |
| 8162 | return retval; |
| 8163 | |
| 8164 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 8165 | (int)Rows, FALSE, NULL) == FAIL) |
| 8166 | return FAIL; |
| 8167 | |
| 8168 | #ifdef FEAT_WINDOWS |
| 8169 | /* |
| 8170 | * If there are windows or status lines below, try to put them at the |
| 8171 | * correct place. If we can't do that, they have to be redrawn. |
| 8172 | */ |
| 8173 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 8174 | { |
| 8175 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8176 | line_count, (int)Rows, NULL) == FAIL) |
| 8177 | { |
| 8178 | wp->w_redr_status = TRUE; |
| 8179 | win_rest_invalid(wp->w_next); |
| 8180 | } |
| 8181 | } |
| 8182 | /* |
| 8183 | * If this is the last window and there is no status line, redraw the |
| 8184 | * command line later. |
| 8185 | */ |
| 8186 | else |
| 8187 | #endif |
| 8188 | redraw_cmdline = TRUE; |
| 8189 | return OK; |
| 8190 | } |
| 8191 | |
| 8192 | /* |
| 8193 | * Common code for win_ins_lines() and win_del_lines(). |
| 8194 | * Returns OK or FAIL when the work has been done. |
| 8195 | * Returns MAYBE when not finished yet. |
| 8196 | */ |
| 8197 | static int |
| 8198 | win_do_lines(wp, row, line_count, mayclear, del) |
| 8199 | win_T *wp; |
| 8200 | int row; |
| 8201 | int line_count; |
| 8202 | int mayclear; |
| 8203 | int del; |
| 8204 | { |
| 8205 | int retval; |
| 8206 | |
| 8207 | if (!redrawing() || line_count <= 0) |
| 8208 | return FAIL; |
| 8209 | |
| 8210 | /* only a few lines left: redraw is faster */ |
| 8211 | if (mayclear && Rows - line_count < 5 |
| 8212 | #ifdef FEAT_VERTSPLIT |
| 8213 | && wp->w_width == Columns |
| 8214 | #endif |
| 8215 | ) |
| 8216 | { |
| 8217 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 8218 | return FAIL; |
| 8219 | } |
| 8220 | |
| 8221 | /* |
| 8222 | * Delete all remaining lines |
| 8223 | */ |
| 8224 | if (row + line_count >= wp->w_height) |
| 8225 | { |
| 8226 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 8227 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8228 | ' ', ' ', 0); |
| 8229 | return OK; |
| 8230 | } |
| 8231 | |
| 8232 | /* |
| 8233 | * when scrolling, the message on the command line should be cleared, |
| 8234 | * otherwise it will stay there forever. |
| 8235 | */ |
| 8236 | clear_cmdline = TRUE; |
| 8237 | |
| 8238 | /* |
| 8239 | * If the terminal can set a scroll region, use that. |
| 8240 | * Always do this in a vertically split window. This will redraw from |
| 8241 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 8242 | * win_line(). |
| 8243 | * Don't use a scroll region when we are going to redraw the text, writing |
| 8244 | * a character in the lower right corner of the scroll region causes a |
| 8245 | * scroll-up in the DJGPP version. |
| 8246 | */ |
| 8247 | if (scroll_region |
| 8248 | #ifdef FEAT_VERTSPLIT |
| 8249 | || W_WIDTH(wp) != Columns |
| 8250 | #endif |
| 8251 | ) |
| 8252 | { |
| 8253 | #ifdef FEAT_VERTSPLIT |
| 8254 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8255 | #endif |
| 8256 | scroll_region_set(wp, row); |
| 8257 | if (del) |
| 8258 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 8259 | wp->w_height - row, FALSE, wp); |
| 8260 | else |
| 8261 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 8262 | wp->w_height - row, wp); |
| 8263 | #ifdef FEAT_VERTSPLIT |
| 8264 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8265 | #endif |
| 8266 | scroll_region_reset(); |
| 8267 | return retval; |
| 8268 | } |
| 8269 | |
| 8270 | #ifdef FEAT_WINDOWS |
| 8271 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 8272 | return FAIL; |
| 8273 | #endif |
| 8274 | |
| 8275 | return MAYBE; |
| 8276 | } |
| 8277 | |
| 8278 | /* |
| 8279 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 8280 | */ |
| 8281 | static void |
| 8282 | win_rest_invalid(wp) |
| 8283 | win_T *wp; |
| 8284 | { |
| 8285 | #ifdef FEAT_WINDOWS |
| 8286 | while (wp != NULL) |
| 8287 | #else |
| 8288 | if (wp != NULL) |
| 8289 | #endif |
| 8290 | { |
| 8291 | redraw_win_later(wp, NOT_VALID); |
| 8292 | #ifdef FEAT_WINDOWS |
| 8293 | wp->w_redr_status = TRUE; |
| 8294 | wp = wp->w_next; |
| 8295 | #endif |
| 8296 | } |
| 8297 | redraw_cmdline = TRUE; |
| 8298 | } |
| 8299 | |
| 8300 | /* |
| 8301 | * The rest of the routines in this file perform screen manipulations. The |
| 8302 | * given operation is performed physically on the screen. The corresponding |
| 8303 | * change is also made to the internal screen image. In this way, the editor |
| 8304 | * anticipates the effect of editing changes on the appearance of the screen. |
| 8305 | * That way, when we call screenupdate a complete redraw isn't usually |
| 8306 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 8307 | * screen changes, and in the meantime, everything still works. |
| 8308 | */ |
| 8309 | |
| 8310 | /* |
| 8311 | * types for inserting or deleting lines |
| 8312 | */ |
| 8313 | #define USE_T_CAL 1 |
| 8314 | #define USE_T_CDL 2 |
| 8315 | #define USE_T_AL 3 |
| 8316 | #define USE_T_CE 4 |
| 8317 | #define USE_T_DL 5 |
| 8318 | #define USE_T_SR 6 |
| 8319 | #define USE_NL 7 |
| 8320 | #define USE_T_CD 8 |
| 8321 | #define USE_REDRAW 9 |
| 8322 | |
| 8323 | /* |
| 8324 | * insert lines on the screen and update ScreenLines[] |
| 8325 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 8326 | * When scrolling region used 'off' is the offset from the top for the region. |
| 8327 | * 'row' and 'end' are relative to the start of the region. |
| 8328 | * |
| 8329 | * return FAIL for failure, OK for success. |
| 8330 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 8331 | int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8332 | screen_ins_lines(off, row, line_count, end, wp) |
| 8333 | int off; |
| 8334 | int row; |
| 8335 | int line_count; |
| 8336 | int end; |
| 8337 | win_T *wp; /* NULL or window to use width from */ |
| 8338 | { |
| 8339 | int i; |
| 8340 | int j; |
| 8341 | unsigned temp; |
| 8342 | int cursor_row; |
| 8343 | int type; |
| 8344 | int result_empty; |
| 8345 | int can_ce = can_clear(T_CE); |
| 8346 | |
| 8347 | /* |
| 8348 | * FAIL if |
| 8349 | * - there is no valid screen |
| 8350 | * - the screen has to be redrawn completely |
| 8351 | * - the line count is less than one |
| 8352 | * - the line count is more than 'ttyscroll' |
| 8353 | */ |
| 8354 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 8355 | return FAIL; |
| 8356 | |
| 8357 | /* |
| 8358 | * There are seven ways to insert lines: |
| 8359 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 8360 | * characters from ScreenLines[]. |
| 8361 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 8362 | * the insert is just empty lines |
| 8363 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 8364 | * present or line_count > 1. It looks better if we do all the inserts |
| 8365 | * at once. |
| 8366 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 8367 | * insert is just empty lines and T_CE is not present or line_count > |
| 8368 | * 1. |
| 8369 | * 4. Use T_AL (insert line) if it exists. |
| 8370 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 8371 | * just empty lines. |
| 8372 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 8373 | * just empty lines. |
| 8374 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 8375 | * the 'da' flag is not set or we have clear line capability. |
| 8376 | * 8. redraw the characters from ScreenLines[]. |
| 8377 | * |
| 8378 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 8379 | * the scrollbar for the window. It does have insert line, use that if it |
| 8380 | * exists. |
| 8381 | */ |
| 8382 | result_empty = (row + line_count >= end); |
| 8383 | #ifdef FEAT_VERTSPLIT |
| 8384 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 8385 | type = USE_REDRAW; |
| 8386 | else |
| 8387 | #endif |
| 8388 | if (can_clear(T_CD) && result_empty) |
| 8389 | type = USE_T_CD; |
| 8390 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 8391 | type = USE_T_CAL; |
| 8392 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 8393 | type = USE_T_CDL; |
| 8394 | else if (*T_AL != NUL) |
| 8395 | type = USE_T_AL; |
| 8396 | else if (can_ce && result_empty) |
| 8397 | type = USE_T_CE; |
| 8398 | else if (*T_DL != NUL && result_empty) |
| 8399 | type = USE_T_DL; |
| 8400 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 8401 | type = USE_T_SR; |
| 8402 | else |
| 8403 | return FAIL; |
| 8404 | |
| 8405 | /* |
| 8406 | * For clearing the lines screen_del_lines() is used. This will also take |
| 8407 | * care of t_db if necessary. |
| 8408 | */ |
| 8409 | if (type == USE_T_CD || type == USE_T_CDL || |
| 8410 | type == USE_T_CE || type == USE_T_DL) |
| 8411 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 8412 | |
| 8413 | /* |
| 8414 | * If text is retained below the screen, first clear or delete as many |
| 8415 | * lines at the bottom of the window as are about to be inserted so that |
| 8416 | * the deleted lines won't later surface during a screen_del_lines. |
| 8417 | */ |
| 8418 | if (*T_DB) |
| 8419 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 8420 | |
| 8421 | #ifdef FEAT_CLIPBOARD |
| 8422 | /* Remove a modeless selection when inserting lines halfway the screen |
| 8423 | * or not the full width of the screen. */ |
| 8424 | if (off + row > 0 |
| 8425 | # ifdef FEAT_VERTSPLIT |
| 8426 | || (wp != NULL && wp->w_width != Columns) |
| 8427 | # endif |
| 8428 | ) |
| 8429 | clip_clear_selection(); |
| 8430 | else |
| 8431 | clip_scroll_selection(-line_count); |
| 8432 | #endif |
| 8433 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8434 | #ifdef FEAT_GUI |
| 8435 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 8436 | * scrolling is actually carried out. */ |
| 8437 | gui_dont_update_cursor(); |
| 8438 | #endif |
| 8439 | |
| 8440 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 8441 | cursor_row = row; |
| 8442 | else |
| 8443 | cursor_row = row + off; |
| 8444 | |
| 8445 | /* |
| 8446 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 8447 | * Clear the inserted lines in ScreenLines[]. |
| 8448 | */ |
| 8449 | row += off; |
| 8450 | end += off; |
| 8451 | for (i = 0; i < line_count; ++i) |
| 8452 | { |
| 8453 | #ifdef FEAT_VERTSPLIT |
| 8454 | if (wp != NULL && wp->w_width != Columns) |
| 8455 | { |
| 8456 | /* need to copy part of a line */ |
| 8457 | j = end - 1 - i; |
| 8458 | while ((j -= line_count) >= row) |
| 8459 | linecopy(j + line_count, j, wp); |
| 8460 | j += line_count; |
| 8461 | if (can_clear((char_u *)" ")) |
| 8462 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8463 | else |
| 8464 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8465 | LineWraps[j] = FALSE; |
| 8466 | } |
| 8467 | else |
| 8468 | #endif |
| 8469 | { |
| 8470 | j = end - 1 - i; |
| 8471 | temp = LineOffset[j]; |
| 8472 | while ((j -= line_count) >= row) |
| 8473 | { |
| 8474 | LineOffset[j + line_count] = LineOffset[j]; |
| 8475 | LineWraps[j + line_count] = LineWraps[j]; |
| 8476 | } |
| 8477 | LineOffset[j + line_count] = temp; |
| 8478 | LineWraps[j + line_count] = FALSE; |
| 8479 | if (can_clear((char_u *)" ")) |
| 8480 | lineclear(temp, (int)Columns); |
| 8481 | else |
| 8482 | lineinvalid(temp, (int)Columns); |
| 8483 | } |
| 8484 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8485 | |
| 8486 | screen_stop_highlight(); |
| 8487 | windgoto(cursor_row, 0); |
| 8488 | |
| 8489 | #ifdef FEAT_VERTSPLIT |
| 8490 | /* redraw the characters */ |
| 8491 | if (type == USE_REDRAW) |
| 8492 | redraw_block(row, end, wp); |
| 8493 | else |
| 8494 | #endif |
| 8495 | if (type == USE_T_CAL) |
| 8496 | { |
| 8497 | term_append_lines(line_count); |
| 8498 | screen_start(); /* don't know where cursor is now */ |
| 8499 | } |
| 8500 | else |
| 8501 | { |
| 8502 | for (i = 0; i < line_count; i++) |
| 8503 | { |
| 8504 | if (type == USE_T_AL) |
| 8505 | { |
| 8506 | if (i && cursor_row != 0) |
| 8507 | windgoto(cursor_row, 0); |
| 8508 | out_str(T_AL); |
| 8509 | } |
| 8510 | else /* type == USE_T_SR */ |
| 8511 | out_str(T_SR); |
| 8512 | screen_start(); /* don't know where cursor is now */ |
| 8513 | } |
| 8514 | } |
| 8515 | |
| 8516 | /* |
| 8517 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 8518 | * have been scrolled down into the region. |
| 8519 | */ |
| 8520 | if (type == USE_T_SR && *T_DA) |
| 8521 | { |
| 8522 | for (i = 0; i < line_count; ++i) |
| 8523 | { |
| 8524 | windgoto(off + i, 0); |
| 8525 | out_str(T_CE); |
| 8526 | screen_start(); /* don't know where cursor is now */ |
| 8527 | } |
| 8528 | } |
| 8529 | |
| 8530 | #ifdef FEAT_GUI |
| 8531 | gui_can_update_cursor(); |
| 8532 | if (gui.in_use) |
| 8533 | out_flush(); /* always flush after a scroll */ |
| 8534 | #endif |
| 8535 | return OK; |
| 8536 | } |
| 8537 | |
| 8538 | /* |
| 8539 | * delete lines on the screen and update ScreenLines[] |
| 8540 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 8541 | * When scrolling region used 'off' is the offset from the top for the region. |
| 8542 | * 'row' and 'end' are relative to the start of the region. |
| 8543 | * |
| 8544 | * Return OK for success, FAIL if the lines are not deleted. |
| 8545 | */ |
| 8546 | /*ARGSUSED*/ |
| 8547 | int |
| 8548 | screen_del_lines(off, row, line_count, end, force, wp) |
| 8549 | int off; |
| 8550 | int row; |
| 8551 | int line_count; |
| 8552 | int end; |
| 8553 | int force; /* even when line_count > p_ttyscroll */ |
| 8554 | win_T *wp; /* NULL or window to use width from */ |
| 8555 | { |
| 8556 | int j; |
| 8557 | int i; |
| 8558 | unsigned temp; |
| 8559 | int cursor_row; |
| 8560 | int cursor_end; |
| 8561 | int result_empty; /* result is empty until end of region */ |
| 8562 | int can_delete; /* deleting line codes can be used */ |
| 8563 | int type; |
| 8564 | |
| 8565 | /* |
| 8566 | * FAIL if |
| 8567 | * - there is no valid screen |
| 8568 | * - the screen has to be redrawn completely |
| 8569 | * - the line count is less than one |
| 8570 | * - the line count is more than 'ttyscroll' |
| 8571 | */ |
| 8572 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 8573 | (!force && line_count > p_ttyscroll)) |
| 8574 | return FAIL; |
| 8575 | |
| 8576 | /* |
| 8577 | * Check if the rest of the current region will become empty. |
| 8578 | */ |
| 8579 | result_empty = row + line_count >= end; |
| 8580 | |
| 8581 | /* |
| 8582 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 8583 | * available. |
| 8584 | */ |
| 8585 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 8586 | |
| 8587 | /* |
| 8588 | * There are six ways to delete lines: |
| 8589 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 8590 | * characters from ScreenLines[]. |
| 8591 | * 1. Use T_CD if it exists and the result is empty. |
| 8592 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 8593 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 8594 | * none of the other ways work. |
| 8595 | * 4. Use T_CE (erase line) if the result is empty. |
| 8596 | * 5. Use T_DL (delete line) if it exists. |
| 8597 | * 6. redraw the characters from ScreenLines[]. |
| 8598 | */ |
| 8599 | #ifdef FEAT_VERTSPLIT |
| 8600 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 8601 | type = USE_REDRAW; |
| 8602 | else |
| 8603 | #endif |
| 8604 | if (can_clear(T_CD) && result_empty) |
| 8605 | type = USE_T_CD; |
| 8606 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 8607 | /* |
| 8608 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 8609 | * its internal termcap... this works okay for tests which test *T_DB != |
| 8610 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 8611 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 8612 | * the trick... |
| 8613 | * Anyway, this hack will hopefully go away with the next OS release. |
| 8614 | * (Olaf Seibert) |
| 8615 | */ |
| 8616 | else if (row == 0 && T_DB == empty_option |
| 8617 | && (line_count == 1 || *T_CDL == NUL)) |
| 8618 | #else |
| 8619 | else if (row == 0 && ( |
| 8620 | #ifndef AMIGA |
| 8621 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 8622 | * up, so use delete-line command */ |
| 8623 | line_count == 1 || |
| 8624 | #endif |
| 8625 | *T_CDL == NUL)) |
| 8626 | #endif |
| 8627 | type = USE_NL; |
| 8628 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 8629 | type = USE_T_CDL; |
| 8630 | else if (can_clear(T_CE) && result_empty |
| 8631 | #ifdef FEAT_VERTSPLIT |
| 8632 | && (wp == NULL || wp->w_width == Columns) |
| 8633 | #endif |
| 8634 | ) |
| 8635 | type = USE_T_CE; |
| 8636 | else if (*T_DL != NUL && can_delete) |
| 8637 | type = USE_T_DL; |
| 8638 | else if (*T_CDL != NUL && can_delete) |
| 8639 | type = USE_T_CDL; |
| 8640 | else |
| 8641 | return FAIL; |
| 8642 | |
| 8643 | #ifdef FEAT_CLIPBOARD |
| 8644 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 8645 | * not the full width of the screen. */ |
| 8646 | if (off + row > 0 |
| 8647 | # ifdef FEAT_VERTSPLIT |
| 8648 | || (wp != NULL && wp->w_width != Columns) |
| 8649 | # endif |
| 8650 | ) |
| 8651 | clip_clear_selection(); |
| 8652 | else |
| 8653 | clip_scroll_selection(line_count); |
| 8654 | #endif |
| 8655 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8656 | #ifdef FEAT_GUI |
| 8657 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 8658 | * scrolling is actually carried out. */ |
| 8659 | gui_dont_update_cursor(); |
| 8660 | #endif |
| 8661 | |
| 8662 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 8663 | { |
| 8664 | cursor_row = row; |
| 8665 | cursor_end = end; |
| 8666 | } |
| 8667 | else |
| 8668 | { |
| 8669 | cursor_row = row + off; |
| 8670 | cursor_end = end + off; |
| 8671 | } |
| 8672 | |
| 8673 | /* |
| 8674 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 8675 | * Clear the inserted lines in ScreenLines[]. |
| 8676 | */ |
| 8677 | row += off; |
| 8678 | end += off; |
| 8679 | for (i = 0; i < line_count; ++i) |
| 8680 | { |
| 8681 | #ifdef FEAT_VERTSPLIT |
| 8682 | if (wp != NULL && wp->w_width != Columns) |
| 8683 | { |
| 8684 | /* need to copy part of a line */ |
| 8685 | j = row + i; |
| 8686 | while ((j += line_count) <= end - 1) |
| 8687 | linecopy(j - line_count, j, wp); |
| 8688 | j -= line_count; |
| 8689 | if (can_clear((char_u *)" ")) |
| 8690 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8691 | else |
| 8692 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8693 | LineWraps[j] = FALSE; |
| 8694 | } |
| 8695 | else |
| 8696 | #endif |
| 8697 | { |
| 8698 | /* whole width, moving the line pointers is faster */ |
| 8699 | j = row + i; |
| 8700 | temp = LineOffset[j]; |
| 8701 | while ((j += line_count) <= end - 1) |
| 8702 | { |
| 8703 | LineOffset[j - line_count] = LineOffset[j]; |
| 8704 | LineWraps[j - line_count] = LineWraps[j]; |
| 8705 | } |
| 8706 | LineOffset[j - line_count] = temp; |
| 8707 | LineWraps[j - line_count] = FALSE; |
| 8708 | if (can_clear((char_u *)" ")) |
| 8709 | lineclear(temp, (int)Columns); |
| 8710 | else |
| 8711 | lineinvalid(temp, (int)Columns); |
| 8712 | } |
| 8713 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8714 | |
| 8715 | screen_stop_highlight(); |
| 8716 | |
| 8717 | #ifdef FEAT_VERTSPLIT |
| 8718 | /* redraw the characters */ |
| 8719 | if (type == USE_REDRAW) |
| 8720 | redraw_block(row, end, wp); |
| 8721 | else |
| 8722 | #endif |
| 8723 | if (type == USE_T_CD) /* delete the lines */ |
| 8724 | { |
| 8725 | windgoto(cursor_row, 0); |
| 8726 | out_str(T_CD); |
| 8727 | screen_start(); /* don't know where cursor is now */ |
| 8728 | } |
| 8729 | else if (type == USE_T_CDL) |
| 8730 | { |
| 8731 | windgoto(cursor_row, 0); |
| 8732 | term_delete_lines(line_count); |
| 8733 | screen_start(); /* don't know where cursor is now */ |
| 8734 | } |
| 8735 | /* |
| 8736 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 8737 | * the whole screen (scroll region) up by outputting newlines on the |
| 8738 | * last line. |
| 8739 | */ |
| 8740 | else if (type == USE_NL) |
| 8741 | { |
| 8742 | windgoto(cursor_end - 1, 0); |
| 8743 | for (i = line_count; --i >= 0; ) |
| 8744 | out_char('\n'); /* cursor will remain on same line */ |
| 8745 | } |
| 8746 | else |
| 8747 | { |
| 8748 | for (i = line_count; --i >= 0; ) |
| 8749 | { |
| 8750 | if (type == USE_T_DL) |
| 8751 | { |
| 8752 | windgoto(cursor_row, 0); |
| 8753 | out_str(T_DL); /* delete a line */ |
| 8754 | } |
| 8755 | else /* type == USE_T_CE */ |
| 8756 | { |
| 8757 | windgoto(cursor_row + i, 0); |
| 8758 | out_str(T_CE); /* erase a line */ |
| 8759 | } |
| 8760 | screen_start(); /* don't know where cursor is now */ |
| 8761 | } |
| 8762 | } |
| 8763 | |
| 8764 | /* |
| 8765 | * If the 'db' flag is set, we need to clear the lines that have been |
| 8766 | * scrolled up at the bottom of the region. |
| 8767 | */ |
| 8768 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 8769 | { |
| 8770 | for (i = line_count; i > 0; --i) |
| 8771 | { |
| 8772 | windgoto(cursor_end - i, 0); |
| 8773 | out_str(T_CE); /* erase a line */ |
| 8774 | screen_start(); /* don't know where cursor is now */ |
| 8775 | } |
| 8776 | } |
| 8777 | |
| 8778 | #ifdef FEAT_GUI |
| 8779 | gui_can_update_cursor(); |
| 8780 | if (gui.in_use) |
| 8781 | out_flush(); /* always flush after a scroll */ |
| 8782 | #endif |
| 8783 | |
| 8784 | return OK; |
| 8785 | } |
| 8786 | |
| 8787 | /* |
| 8788 | * show the current mode and ruler |
| 8789 | * |
| 8790 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 8791 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 8792 | * cleared only if a mode is shown. |
| 8793 | * Return the length of the message (0 if no message). |
| 8794 | */ |
| 8795 | int |
| 8796 | showmode() |
| 8797 | { |
| 8798 | int need_clear; |
| 8799 | int length = 0; |
| 8800 | int do_mode; |
| 8801 | int attr; |
| 8802 | int nwr_save; |
| 8803 | #ifdef FEAT_INS_EXPAND |
| 8804 | int sub_attr; |
| 8805 | #endif |
| 8806 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 8807 | do_mode = ((p_smd && msg_silent == 0) |
| 8808 | && ((State & INSERT) |
| 8809 | || restart_edit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8810 | #ifdef FEAT_VISUAL |
| 8811 | || VIsual_active |
| 8812 | #endif |
| 8813 | )); |
| 8814 | if (do_mode || Recording) |
| 8815 | { |
| 8816 | /* |
| 8817 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 8818 | * Call char_avail() only when we are going to show something, because |
| 8819 | * it takes a bit of time. |
| 8820 | */ |
| 8821 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 8822 | { |
| 8823 | redraw_cmdline = TRUE; /* show mode later */ |
| 8824 | return 0; |
| 8825 | } |
| 8826 | |
| 8827 | nwr_save = need_wait_return; |
| 8828 | |
| 8829 | /* wait a bit before overwriting an important message */ |
| 8830 | check_for_delay(FALSE); |
| 8831 | |
| 8832 | /* if the cmdline is more than one line high, erase top lines */ |
| 8833 | need_clear = clear_cmdline; |
| 8834 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 8835 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 8836 | |
| 8837 | /* Position on the last line in the window, column 0 */ |
| 8838 | msg_pos_mode(); |
| 8839 | cursor_off(); |
| 8840 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 8841 | if (do_mode) |
| 8842 | { |
| 8843 | MSG_PUTS_ATTR("--", attr); |
| 8844 | #if defined(FEAT_XIM) |
| 8845 | if (xic != NULL && im_get_status() && !p_imdisable |
| 8846 | && curbuf->b_p_iminsert == B_IMODE_IM) |
| 8847 | # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */ |
| 8848 | MSG_PUTS_ATTR(" IM", attr); |
| 8849 | # else |
| 8850 | MSG_PUTS_ATTR(" XIM", attr); |
| 8851 | # endif |
| 8852 | #endif |
| 8853 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 8854 | if (gui.in_use) |
| 8855 | { |
| 8856 | if (hangul_input_state_get()) |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 8857 | MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8858 | } |
| 8859 | #endif |
| 8860 | #ifdef FEAT_INS_EXPAND |
| 8861 | if (edit_submode != NULL) /* CTRL-X in Insert mode */ |
| 8862 | { |
| 8863 | /* These messages can get long, avoid a wrap in a narrow |
| 8864 | * window. Prefer showing edit_submode_extra. */ |
| 8865 | length = (Rows - msg_row) * Columns - 3; |
| 8866 | if (edit_submode_extra != NULL) |
| 8867 | length -= vim_strsize(edit_submode_extra); |
| 8868 | if (length > 0) |
| 8869 | { |
| 8870 | if (edit_submode_pre != NULL) |
| 8871 | length -= vim_strsize(edit_submode_pre); |
| 8872 | if (length - vim_strsize(edit_submode) > 0) |
| 8873 | { |
| 8874 | if (edit_submode_pre != NULL) |
| 8875 | msg_puts_attr(edit_submode_pre, attr); |
| 8876 | msg_puts_attr(edit_submode, attr); |
| 8877 | } |
| 8878 | if (edit_submode_extra != NULL) |
| 8879 | { |
| 8880 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 8881 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 8882 | sub_attr = hl_attr(edit_submode_highl); |
| 8883 | else |
| 8884 | sub_attr = attr; |
| 8885 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 8886 | } |
| 8887 | } |
| 8888 | length = 0; |
| 8889 | } |
| 8890 | else |
| 8891 | #endif |
| 8892 | { |
| 8893 | #ifdef FEAT_VREPLACE |
| 8894 | if (State & VREPLACE_FLAG) |
| 8895 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 8896 | else |
| 8897 | #endif |
| 8898 | if (State & REPLACE_FLAG) |
| 8899 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 8900 | else if (State & INSERT) |
| 8901 | { |
| 8902 | #ifdef FEAT_RIGHTLEFT |
| 8903 | if (p_ri) |
| 8904 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 8905 | #endif |
| 8906 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 8907 | } |
| 8908 | else if (restart_edit == 'I') |
| 8909 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 8910 | else if (restart_edit == 'R') |
| 8911 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 8912 | else if (restart_edit == 'V') |
| 8913 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 8914 | #ifdef FEAT_RIGHTLEFT |
| 8915 | if (p_hkmap) |
| 8916 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 8917 | # ifdef FEAT_FKMAP |
| 8918 | if (p_fkmap) |
| 8919 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 8920 | # endif |
| 8921 | #endif |
| 8922 | #ifdef FEAT_KEYMAP |
| 8923 | if (State & LANGMAP) |
| 8924 | { |
| 8925 | # ifdef FEAT_ARABIC |
| 8926 | if (curwin->w_p_arab) |
| 8927 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 8928 | else |
| 8929 | # endif |
| 8930 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 8931 | } |
| 8932 | #endif |
| 8933 | if ((State & INSERT) && p_paste) |
| 8934 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 8935 | |
| 8936 | #ifdef FEAT_VISUAL |
| 8937 | if (VIsual_active) |
| 8938 | { |
| 8939 | char *p; |
| 8940 | |
| 8941 | /* Don't concatenate separate words to avoid translation |
| 8942 | * problems. */ |
| 8943 | switch ((VIsual_select ? 4 : 0) |
| 8944 | + (VIsual_mode == Ctrl_V) * 2 |
| 8945 | + (VIsual_mode == 'V')) |
| 8946 | { |
| 8947 | case 0: p = N_(" VISUAL"); break; |
| 8948 | case 1: p = N_(" VISUAL LINE"); break; |
| 8949 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 8950 | case 4: p = N_(" SELECT"); break; |
| 8951 | case 5: p = N_(" SELECT LINE"); break; |
| 8952 | default: p = N_(" SELECT BLOCK"); break; |
| 8953 | } |
| 8954 | MSG_PUTS_ATTR(_(p), attr); |
| 8955 | } |
| 8956 | #endif |
| 8957 | MSG_PUTS_ATTR(" --", attr); |
| 8958 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8959 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8960 | need_clear = TRUE; |
| 8961 | } |
| 8962 | if (Recording |
| 8963 | #ifdef FEAT_INS_EXPAND |
| 8964 | && edit_submode == NULL /* otherwise it gets too long */ |
| 8965 | #endif |
| 8966 | ) |
| 8967 | { |
| 8968 | MSG_PUTS_ATTR(_("recording"), attr); |
| 8969 | need_clear = TRUE; |
| 8970 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8971 | |
| 8972 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8973 | if (need_clear || clear_cmdline) |
| 8974 | msg_clr_eos(); |
| 8975 | msg_didout = FALSE; /* overwrite this message */ |
| 8976 | length = msg_col; |
| 8977 | msg_col = 0; |
| 8978 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 8979 | } |
| 8980 | else if (clear_cmdline && msg_silent == 0) |
| 8981 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 8982 | msg_clr_cmdline(); |
| 8983 | |
| 8984 | #ifdef FEAT_CMDL_INFO |
| 8985 | # ifdef FEAT_VISUAL |
| 8986 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 8987 | if (VIsual_active) |
| 8988 | clear_showcmd(); |
| 8989 | # endif |
| 8990 | |
| 8991 | /* If the last window has no status line, the ruler is after the mode |
| 8992 | * message and must be redrawn */ |
| 8993 | if (redrawing() |
| 8994 | # ifdef FEAT_WINDOWS |
| 8995 | && lastwin->w_status_height == 0 |
| 8996 | # endif |
| 8997 | ) |
| 8998 | win_redr_ruler(lastwin, TRUE); |
| 8999 | #endif |
| 9000 | redraw_cmdline = FALSE; |
| 9001 | clear_cmdline = FALSE; |
| 9002 | |
| 9003 | return length; |
| 9004 | } |
| 9005 | |
| 9006 | /* |
| 9007 | * Position for a mode message. |
| 9008 | */ |
| 9009 | static void |
| 9010 | msg_pos_mode() |
| 9011 | { |
| 9012 | msg_col = 0; |
| 9013 | msg_row = Rows - 1; |
| 9014 | } |
| 9015 | |
| 9016 | /* |
| 9017 | * Delete mode message. Used when ESC is typed which is expected to end |
| 9018 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9019 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9020 | */ |
| 9021 | void |
| 9022 | unshowmode(force) |
| 9023 | int force; |
| 9024 | { |
| 9025 | /* |
| 9026 | * Don't delete it right now, when not redrawing or insided a mapping. |
| 9027 | */ |
| 9028 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 9029 | redraw_cmdline = TRUE; /* delete mode later */ |
| 9030 | else |
| 9031 | { |
| 9032 | msg_pos_mode(); |
| 9033 | if (Recording) |
| 9034 | MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); |
| 9035 | msg_clr_eos(); |
| 9036 | } |
| 9037 | } |
| 9038 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9039 | #if defined(FEAT_WINDOWS) |
| 9040 | /* |
| 9041 | * Draw the tab pages line at the top of the Vim window. |
| 9042 | */ |
| 9043 | static void |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9044 | draw_tabline() |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9045 | { |
| 9046 | int tabcount = 0; |
| 9047 | tabpage_T *tp; |
| 9048 | int tabwidth; |
| 9049 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9050 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9051 | int attr; |
| 9052 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9053 | win_T *cwp; |
| 9054 | int wincount; |
| 9055 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9056 | int c; |
| 9057 | int len; |
| 9058 | int attr_sel = hl_attr(HLF_TPS); |
| 9059 | int attr_nosel = hl_attr(HLF_TP); |
| 9060 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9061 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9062 | int room; |
| 9063 | int use_sep_chars = (t_colors < 8 |
| 9064 | #ifdef FEAT_GUI |
| 9065 | && !gui.in_use |
| 9066 | #endif |
| 9067 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9068 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9069 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9070 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9071 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 9072 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9073 | if (gui_use_tabline()) |
| 9074 | { |
| 9075 | gui_update_tabline(); |
| 9076 | return; |
| 9077 | } |
| 9078 | #endif |
| 9079 | |
| 9080 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9081 | return; |
| 9082 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9083 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9084 | |
| 9085 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 9086 | for (scol = 0; scol < Columns; ++scol) |
| 9087 | TabPageIdxs[scol] = 0; |
| 9088 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9089 | /* Use the 'tabline' option if it's set. */ |
| 9090 | if (*p_tal != NUL) |
| 9091 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9092 | int save_called_emsg = called_emsg; |
| 9093 | |
| 9094 | /* Check for an error. If there is one we would loop in redrawing the |
| 9095 | * screen. Avoid that by making 'tabline' empty. */ |
| 9096 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9097 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9098 | if (called_emsg) |
| 9099 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 9100 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9101 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9102 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9103 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9104 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9105 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9106 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 9107 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9108 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9109 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 9110 | if (tabwidth < 6) |
| 9111 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9112 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9113 | attr = attr_nosel; |
| 9114 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9115 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9116 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 9117 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9118 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9119 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9120 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9121 | if (tp->tp_topframe == topframe) |
| 9122 | attr = attr_sel; |
| 9123 | if (use_sep_chars && col > 0) |
| 9124 | screen_putchar('|', 0, col++, attr); |
| 9125 | |
| 9126 | if (tp->tp_topframe != topframe) |
| 9127 | attr = attr_nosel; |
| 9128 | |
| 9129 | screen_putchar(' ', 0, col++, attr); |
| 9130 | |
| 9131 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9132 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9133 | cwp = curwin; |
| 9134 | wp = firstwin; |
| 9135 | } |
| 9136 | else |
| 9137 | { |
| 9138 | cwp = tp->tp_curwin; |
| 9139 | wp = tp->tp_firstwin; |
| 9140 | } |
| 9141 | |
| 9142 | modified = FALSE; |
| 9143 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 9144 | if (bufIsChanged(wp->w_buffer)) |
| 9145 | modified = TRUE; |
| 9146 | if (modified || wincount > 1) |
| 9147 | { |
| 9148 | if (wincount > 1) |
| 9149 | { |
| 9150 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9151 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9152 | if (col + len >= Columns - 3) |
| 9153 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9154 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9155 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9156 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9157 | #else |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9158 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9159 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9160 | ); |
| 9161 | col += len; |
| 9162 | } |
| 9163 | if (modified) |
| 9164 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 9165 | screen_putchar(' ', 0, col++, attr); |
| 9166 | } |
| 9167 | |
| 9168 | room = scol - col + tabwidth - 1; |
| 9169 | if (room > 0) |
| 9170 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9171 | /* Get buffer name in NameBuff[] */ |
| 9172 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 9173 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9174 | len = vim_strsize(NameBuff); |
| 9175 | p = NameBuff; |
| 9176 | #ifdef FEAT_MBYTE |
| 9177 | if (has_mbyte) |
| 9178 | while (len > room) |
| 9179 | { |
| 9180 | len -= ptr2cells(p); |
| 9181 | mb_ptr_adv(p); |
| 9182 | } |
| 9183 | else |
| 9184 | #endif |
| 9185 | if (len > room) |
| 9186 | { |
| 9187 | p += len - room; |
| 9188 | len = room; |
| 9189 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9190 | if (len > Columns - col - 1) |
| 9191 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9192 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9193 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9194 | col += len; |
| 9195 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9196 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9197 | |
| 9198 | /* Store the tab page number in TabPageIdxs[], so that |
| 9199 | * jump_to_mouse() knows where each one is. */ |
| 9200 | ++tabcount; |
| 9201 | while (scol < col) |
| 9202 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9203 | } |
| 9204 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9205 | if (use_sep_chars) |
| 9206 | c = '_'; |
| 9207 | else |
| 9208 | c = ' '; |
| 9209 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9210 | |
| 9211 | /* Put an "X" for closing the current tab if there are several. */ |
| 9212 | if (first_tabpage->tp_next != NULL) |
| 9213 | { |
| 9214 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 9215 | TabPageIdxs[Columns - 1] = -999; |
| 9216 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9217 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 9218 | |
| 9219 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 9220 | * set. */ |
| 9221 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9222 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9223 | |
| 9224 | /* |
| 9225 | * Get buffer name for "buf" into NameBuff[]. |
| 9226 | * Takes care of special buffer names and translates special characters. |
| 9227 | */ |
| 9228 | void |
| 9229 | get_trans_bufname(buf) |
| 9230 | buf_T *buf; |
| 9231 | { |
| 9232 | if (buf_spname(buf) != NULL) |
| 9233 | STRCPY(NameBuff, buf_spname(buf)); |
| 9234 | else |
| 9235 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 9236 | trans_characters(NameBuff, MAXPATHL); |
| 9237 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9238 | #endif |
| 9239 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9240 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 9241 | /* |
| 9242 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 9243 | */ |
| 9244 | static int |
| 9245 | fillchar_status(attr, is_curwin) |
| 9246 | int *attr; |
| 9247 | int is_curwin; |
| 9248 | { |
| 9249 | int fill; |
| 9250 | if (is_curwin) |
| 9251 | { |
| 9252 | *attr = hl_attr(HLF_S); |
| 9253 | fill = fill_stl; |
| 9254 | } |
| 9255 | else |
| 9256 | { |
| 9257 | *attr = hl_attr(HLF_SNC); |
| 9258 | fill = fill_stlnc; |
| 9259 | } |
| 9260 | /* Use fill when there is highlighting, and highlighting of current |
| 9261 | * window differs, or the fillchars differ, or this is not the |
| 9262 | * current window */ |
| 9263 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 9264 | || !is_curwin || firstwin == lastwin) |
| 9265 | || (fill_stl != fill_stlnc))) |
| 9266 | return fill; |
| 9267 | if (is_curwin) |
| 9268 | return '^'; |
| 9269 | return '='; |
| 9270 | } |
| 9271 | #endif |
| 9272 | |
| 9273 | #ifdef FEAT_VERTSPLIT |
| 9274 | /* |
| 9275 | * Get the character to use in a separator between vertically split windows. |
| 9276 | * Get its attributes in "*attr". |
| 9277 | */ |
| 9278 | static int |
| 9279 | fillchar_vsep(attr) |
| 9280 | int *attr; |
| 9281 | { |
| 9282 | *attr = hl_attr(HLF_C); |
| 9283 | if (*attr == 0 && fill_vert == ' ') |
| 9284 | return '|'; |
| 9285 | else |
| 9286 | return fill_vert; |
| 9287 | } |
| 9288 | #endif |
| 9289 | |
| 9290 | /* |
| 9291 | * Return TRUE if redrawing should currently be done. |
| 9292 | */ |
| 9293 | int |
| 9294 | redrawing() |
| 9295 | { |
| 9296 | return (!RedrawingDisabled |
| 9297 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 9298 | } |
| 9299 | |
| 9300 | /* |
| 9301 | * Return TRUE if printing messages should currently be done. |
| 9302 | */ |
| 9303 | int |
| 9304 | messaging() |
| 9305 | { |
| 9306 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 9307 | } |
| 9308 | |
| 9309 | /* |
| 9310 | * Show current status info in ruler and various other places |
| 9311 | * If always is FALSE, only show ruler if position has changed. |
| 9312 | */ |
| 9313 | void |
| 9314 | showruler(always) |
| 9315 | int always; |
| 9316 | { |
| 9317 | if (!always && !redrawing()) |
| 9318 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9319 | #ifdef FEAT_INS_EXPAND |
| 9320 | if (pum_visible()) |
| 9321 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9322 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9323 | /* Don't redraw right now, do it later. */ |
| 9324 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9325 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9326 | return; |
| 9327 | } |
| 9328 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9329 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 9330 | 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] | 9331 | { |
| 9332 | redraw_custum_statusline(curwin); |
| 9333 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9334 | else |
| 9335 | #endif |
| 9336 | #ifdef FEAT_CMDL_INFO |
| 9337 | win_redr_ruler(curwin, always); |
| 9338 | #endif |
| 9339 | |
| 9340 | #ifdef FEAT_TITLE |
| 9341 | if (need_maketitle |
| 9342 | # ifdef FEAT_STL_OPT |
| 9343 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 9344 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 9345 | # endif |
| 9346 | ) |
| 9347 | maketitle(); |
| 9348 | #endif |
| 9349 | } |
| 9350 | |
| 9351 | #ifdef FEAT_CMDL_INFO |
| 9352 | static void |
| 9353 | win_redr_ruler(wp, always) |
| 9354 | win_T *wp; |
| 9355 | int always; |
| 9356 | { |
| 9357 | char_u buffer[70]; |
| 9358 | int row; |
| 9359 | int fillchar; |
| 9360 | int attr; |
| 9361 | int empty_line = FALSE; |
| 9362 | colnr_T virtcol; |
| 9363 | int i; |
| 9364 | int o; |
| 9365 | #ifdef FEAT_VERTSPLIT |
| 9366 | int this_ru_col; |
| 9367 | int off = 0; |
| 9368 | int width = Columns; |
| 9369 | # define WITH_OFF(x) x |
| 9370 | # define WITH_WIDTH(x) x |
| 9371 | #else |
| 9372 | # define WITH_OFF(x) 0 |
| 9373 | # define WITH_WIDTH(x) Columns |
| 9374 | # define this_ru_col ru_col |
| 9375 | #endif |
| 9376 | |
| 9377 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 9378 | if (!p_ru) |
| 9379 | return; |
| 9380 | |
| 9381 | /* |
| 9382 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 9383 | * after deleting lines, before cursor.lnum is corrected. |
| 9384 | */ |
| 9385 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 9386 | return; |
| 9387 | |
| 9388 | #ifdef FEAT_INS_EXPAND |
| 9389 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 9390 | * the (long) mode message. */ |
| 9391 | # ifdef FEAT_WINDOWS |
| 9392 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 9393 | # endif |
| 9394 | if (edit_submode != NULL) |
| 9395 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 9396 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 9397 | if (pum_visible()) |
| 9398 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9399 | #endif |
| 9400 | |
| 9401 | #ifdef FEAT_STL_OPT |
| 9402 | if (*p_ruf) |
| 9403 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9404 | int save_called_emsg = called_emsg; |
| 9405 | |
| 9406 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9407 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9408 | if (called_emsg) |
| 9409 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 9410 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9411 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9412 | return; |
| 9413 | } |
| 9414 | #endif |
| 9415 | |
| 9416 | /* |
| 9417 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 9418 | */ |
| 9419 | if (!(State & INSERT) |
| 9420 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 9421 | empty_line = TRUE; |
| 9422 | |
| 9423 | /* |
| 9424 | * Only draw the ruler when something changed. |
| 9425 | */ |
| 9426 | validate_virtcol_win(wp); |
| 9427 | if ( redraw_cmdline |
| 9428 | || always |
| 9429 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 9430 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 9431 | || wp->w_virtcol != wp->w_ru_virtcol |
| 9432 | #ifdef FEAT_VIRTUALEDIT |
| 9433 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 9434 | #endif |
| 9435 | || wp->w_topline != wp->w_ru_topline |
| 9436 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 9437 | #ifdef FEAT_DIFF |
| 9438 | || wp->w_topfill != wp->w_ru_topfill |
| 9439 | #endif |
| 9440 | || empty_line != wp->w_ru_empty) |
| 9441 | { |
| 9442 | cursor_off(); |
| 9443 | #ifdef FEAT_WINDOWS |
| 9444 | if (wp->w_status_height) |
| 9445 | { |
| 9446 | row = W_WINROW(wp) + wp->w_height; |
| 9447 | fillchar = fillchar_status(&attr, wp == curwin); |
| 9448 | # ifdef FEAT_VERTSPLIT |
| 9449 | off = W_WINCOL(wp); |
| 9450 | width = W_WIDTH(wp); |
| 9451 | # endif |
| 9452 | } |
| 9453 | else |
| 9454 | #endif |
| 9455 | { |
| 9456 | row = Rows - 1; |
| 9457 | fillchar = ' '; |
| 9458 | attr = 0; |
| 9459 | #ifdef FEAT_VERTSPLIT |
| 9460 | width = Columns; |
| 9461 | off = 0; |
| 9462 | #endif |
| 9463 | } |
| 9464 | |
| 9465 | /* In list mode virtcol needs to be recomputed */ |
| 9466 | virtcol = wp->w_virtcol; |
| 9467 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 9468 | { |
| 9469 | wp->w_p_list = FALSE; |
| 9470 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 9471 | wp->w_p_list = TRUE; |
| 9472 | } |
| 9473 | |
| 9474 | /* |
| 9475 | * Some sprintfs return the length, some return a pointer. |
| 9476 | * To avoid portability problems we use strlen() here. |
| 9477 | */ |
| 9478 | sprintf((char *)buffer, "%ld,", |
| 9479 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 9480 | ? 0L |
| 9481 | : (long)(wp->w_cursor.lnum)); |
| 9482 | col_print(buffer + STRLEN(buffer), |
| 9483 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 9484 | (int)virtcol + 1); |
| 9485 | |
| 9486 | /* |
| 9487 | * Add a "50%" if there is room for it. |
| 9488 | * On the last line, don't print in the last column (scrolls the |
| 9489 | * screen up on some terminals). |
| 9490 | */ |
| 9491 | i = (int)STRLEN(buffer); |
| 9492 | get_rel_pos(wp, buffer + i + 1); |
| 9493 | o = i + vim_strsize(buffer + i + 1); |
| 9494 | #ifdef FEAT_WINDOWS |
| 9495 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 9496 | #endif |
| 9497 | ++o; |
| 9498 | #ifdef FEAT_VERTSPLIT |
| 9499 | this_ru_col = ru_col - (Columns - width); |
| 9500 | if (this_ru_col < 0) |
| 9501 | this_ru_col = 0; |
| 9502 | #endif |
| 9503 | /* Never use more than half the window/screen width, leave the other |
| 9504 | * half for the filename. */ |
| 9505 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 9506 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 9507 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 9508 | { |
| 9509 | while (this_ru_col + o < WITH_WIDTH(width)) |
| 9510 | { |
| 9511 | #ifdef FEAT_MBYTE |
| 9512 | if (has_mbyte) |
| 9513 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 9514 | else |
| 9515 | #endif |
| 9516 | buffer[i++] = fillchar; |
| 9517 | ++o; |
| 9518 | } |
| 9519 | get_rel_pos(wp, buffer + i); |
| 9520 | } |
| 9521 | /* Truncate at window boundary. */ |
| 9522 | #ifdef FEAT_MBYTE |
| 9523 | if (has_mbyte) |
| 9524 | { |
| 9525 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 9526 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9527 | { |
| 9528 | o += (*mb_ptr2cells)(buffer + i); |
| 9529 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 9530 | { |
| 9531 | buffer[i] = NUL; |
| 9532 | break; |
| 9533 | } |
| 9534 | } |
| 9535 | } |
| 9536 | else |
| 9537 | #endif |
| 9538 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 9539 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 9540 | |
| 9541 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 9542 | i = redraw_cmdline; |
| 9543 | screen_fill(row, row + 1, |
| 9544 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 9545 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 9546 | fillchar, fillchar, attr); |
| 9547 | /* don't redraw the cmdline because of showing the ruler */ |
| 9548 | redraw_cmdline = i; |
| 9549 | wp->w_ru_cursor = wp->w_cursor; |
| 9550 | wp->w_ru_virtcol = wp->w_virtcol; |
| 9551 | wp->w_ru_empty = empty_line; |
| 9552 | wp->w_ru_topline = wp->w_topline; |
| 9553 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 9554 | #ifdef FEAT_DIFF |
| 9555 | wp->w_ru_topfill = wp->w_topfill; |
| 9556 | #endif |
| 9557 | } |
| 9558 | } |
| 9559 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9560 | |
| 9561 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 9562 | /* |
| 9563 | * Return the width of the 'number' column. |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9564 | * Caller may need to check if 'number' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9565 | * Otherwise it depends on 'numberwidth' and the line count. |
| 9566 | */ |
| 9567 | int |
| 9568 | number_width(wp) |
| 9569 | win_T *wp; |
| 9570 | { |
| 9571 | int n; |
| 9572 | linenr_T lnum; |
| 9573 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9574 | lnum = wp->w_buffer->b_ml.ml_line_count; |
| 9575 | if (lnum == wp->w_nrwidth_line_count) |
| 9576 | return wp->w_nrwidth_width; |
| 9577 | wp->w_nrwidth_line_count = lnum; |
| 9578 | |
| 9579 | n = 0; |
| 9580 | do |
| 9581 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 9582 | lnum /= 10; |
| 9583 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9584 | } while (lnum > 0); |
| 9585 | |
| 9586 | /* 'numberwidth' gives the minimal width plus one */ |
| 9587 | if (n < wp->w_p_nuw - 1) |
| 9588 | n = wp->w_p_nuw - 1; |
| 9589 | |
| 9590 | wp->w_nrwidth_width = n; |
| 9591 | return n; |
| 9592 | } |
| 9593 | #endif |