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 |
| 40 | * called from other places when an immediated screen update is needed. |
| 41 | * |
| 42 | * The part of the buffer that is displayed in a window is set with: |
| 43 | * - w_topline (first buffer line in window) |
| 44 | * - w_topfill (filler line above the first line) |
| 45 | * - w_leftcol (leftmost window cell in window), |
| 46 | * - w_skipcol (skipped window cells of first line) |
| 47 | * |
| 48 | * Commands that only move the cursor around in a window, do not need to take |
| 49 | * action to update the display. The main loop will check if w_topline is |
| 50 | * valid and update it (scroll the window) when needed. |
| 51 | * |
| 52 | * Commands that scroll a window change w_topline and must call |
| 53 | * check_cursor() to move the cursor into the visible part of the window, and |
| 54 | * call redraw_later(VALID) to have the window displayed by update_screen() |
| 55 | * later. |
| 56 | * |
| 57 | * Commands that change text in the buffer must call changed_bytes() or |
| 58 | * changed_lines() to mark the area that changed and will require updating |
| 59 | * later. The main loop will call update_screen(), which will update each |
| 60 | * window that shows the changed buffer. This assumes text above the change |
| 61 | * can remain displayed as it is. Text after the change may need updating for |
| 62 | * scrolling, folding and syntax highlighting. |
| 63 | * |
| 64 | * Commands that change how a window is displayed (e.g., setting 'list') or |
| 65 | * invalidate the contents of a window in another way (e.g., change fold |
| 66 | * settings), must call redraw_later(NOT_VALID) to have the whole window |
| 67 | * redisplayed by update_screen() later. |
| 68 | * |
| 69 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
| 70 | * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the |
| 71 | * buffer redisplayed by update_screen() later. |
| 72 | * |
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 |
| 103 | /* |
| 104 | * Struct used for highlighting 'hlsearch' matches for the last use search |
| 105 | * pattern or a ":match" item. |
| 106 | * For 'hlsearch' there is one pattern for all windows. For ":match" there is |
| 107 | * a different pattern for each window. |
| 108 | */ |
| 109 | typedef struct |
| 110 | { |
| 111 | regmmatch_T rm; /* points to the regexp program; contains last found |
| 112 | match (may continue in next line) */ |
| 113 | buf_T *buf; /* the buffer to search for a match */ |
| 114 | linenr_T lnum; /* the line to search for a match */ |
| 115 | int attr; /* attributes to be used for a match */ |
| 116 | int attr_cur; /* attributes currently active in win_line() */ |
| 117 | linenr_T first_lnum; /* first lnum to search for multi-line pat */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 118 | colnr_T startcol; /* in win_line() points to char where HL starts */ |
| 119 | colnr_T endcol; /* in win_line() points to char where HL ends */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 120 | } match_T; |
| 121 | |
| 122 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 123 | static match_T match_hl[3]; /* used for ":match" highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 124 | #endif |
| 125 | |
| 126 | #ifdef FEAT_FOLDING |
| 127 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
| 128 | #endif |
| 129 | |
| 130 | /* |
| 131 | * Buffer for one screen line (characters and attributes). |
| 132 | */ |
| 133 | static schar_T *current_ScreenLine; |
| 134 | |
| 135 | static void win_update __ARGS((win_T *wp)); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 136 | 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] | 137 | #ifdef FEAT_FOLDING |
| 138 | static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); |
| 139 | static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); |
| 140 | static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); |
| 141 | #endif |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 142 | 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] | 143 | static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
| 144 | #ifdef FEAT_RIGHTLEFT |
| 145 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); |
| 146 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 147 | #else |
| 148 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); |
| 149 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 150 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 151 | #ifdef FEAT_VERTSPLIT |
| 152 | static void draw_vsep_win __ARGS((win_T *wp, int row)); |
| 153 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 154 | #ifdef FEAT_STL_OPT |
| 155 | static void redraw_custum_statusline __ARGS((win_T *wp)); |
| 156 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 157 | #ifdef FEAT_SEARCH_EXTRA |
| 158 | static void start_search_hl __ARGS((void)); |
| 159 | static void end_search_hl __ARGS((void)); |
| 160 | static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
| 161 | static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); |
| 162 | #endif |
| 163 | static void screen_start_highlight __ARGS((int attr)); |
| 164 | static void screen_char __ARGS((unsigned off, int row, int col)); |
| 165 | #ifdef FEAT_MBYTE |
| 166 | static void screen_char_2 __ARGS((unsigned off, int row, int col)); |
| 167 | #endif |
| 168 | static void screenclear2 __ARGS((void)); |
| 169 | static void lineclear __ARGS((unsigned off, int width)); |
| 170 | static void lineinvalid __ARGS((unsigned off, int width)); |
| 171 | #ifdef FEAT_VERTSPLIT |
| 172 | static void linecopy __ARGS((int to, int from, win_T *wp)); |
| 173 | static void redraw_block __ARGS((int row, int end, win_T *wp)); |
| 174 | #endif |
| 175 | static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); |
| 176 | static void win_rest_invalid __ARGS((win_T *wp)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 177 | static void msg_pos_mode __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 178 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 179 | static void draw_tabline __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 180 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 181 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 182 | static int fillchar_status __ARGS((int *attr, int is_curwin)); |
| 183 | #endif |
| 184 | #ifdef FEAT_VERTSPLIT |
| 185 | static int fillchar_vsep __ARGS((int *attr)); |
| 186 | #endif |
| 187 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 188 | static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 189 | #endif |
| 190 | #ifdef FEAT_CMDL_INFO |
| 191 | static void win_redr_ruler __ARGS((win_T *wp, int always)); |
| 192 | #endif |
| 193 | |
| 194 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 195 | /* Ugly global: overrule attribute used by screen_char() */ |
| 196 | static int screen_char_attr = 0; |
| 197 | #endif |
| 198 | |
| 199 | /* |
| 200 | * Redraw the current window later, with update_screen(type). |
| 201 | * Set must_redraw only if not already set to a higher value. |
| 202 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 203 | */ |
| 204 | void |
| 205 | redraw_later(type) |
| 206 | int type; |
| 207 | { |
| 208 | redraw_win_later(curwin, type); |
| 209 | } |
| 210 | |
| 211 | void |
| 212 | redraw_win_later(wp, type) |
| 213 | win_T *wp; |
| 214 | int type; |
| 215 | { |
| 216 | if (wp->w_redr_type < type) |
| 217 | { |
| 218 | wp->w_redr_type = type; |
| 219 | if (type >= NOT_VALID) |
| 220 | wp->w_lines_valid = 0; |
| 221 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 222 | must_redraw = type; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 228 | * after executing a shell command that messes up the screen. |
| 229 | */ |
| 230 | void |
| 231 | redraw_later_clear() |
| 232 | { |
| 233 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 234 | #ifdef FEAT_GUI |
| 235 | if (gui.in_use) |
| 236 | /* Use a code that will reset gui.highlight_mask in |
| 237 | * gui_stop_highlight(). */ |
| 238 | screen_attr = HL_ALL + 1; |
| 239 | else |
| 240 | #endif |
| 241 | /* Use attributes that is very unlikely to appear in text. */ |
| 242 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /* |
| 246 | * Mark all windows to be redrawn later. |
| 247 | */ |
| 248 | void |
| 249 | redraw_all_later(type) |
| 250 | int type; |
| 251 | { |
| 252 | win_T *wp; |
| 253 | |
| 254 | FOR_ALL_WINDOWS(wp) |
| 255 | { |
| 256 | redraw_win_later(wp, type); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 261 | * 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] | 262 | */ |
| 263 | void |
| 264 | redraw_curbuf_later(type) |
| 265 | int type; |
| 266 | { |
| 267 | redraw_buf_later(curbuf, type); |
| 268 | } |
| 269 | |
| 270 | void |
| 271 | redraw_buf_later(buf, type) |
| 272 | buf_T *buf; |
| 273 | int type; |
| 274 | { |
| 275 | win_T *wp; |
| 276 | |
| 277 | FOR_ALL_WINDOWS(wp) |
| 278 | { |
| 279 | if (wp->w_buffer == buf) |
| 280 | redraw_win_later(wp, type); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Changed something in the current window, at buffer line "lnum", that |
| 286 | * requires that line and possibly other lines to be redrawn. |
| 287 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 288 | * Used to remove the "$" from a change command. |
| 289 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 290 | * may become invalid and the whole window will have to be redrawn. |
| 291 | */ |
| 292 | /*ARGSUSED*/ |
| 293 | void |
| 294 | redrawWinline(lnum, invalid) |
| 295 | linenr_T lnum; |
| 296 | int invalid; /* window line height is invalid now */ |
| 297 | { |
| 298 | #ifdef FEAT_FOLDING |
| 299 | int i; |
| 300 | #endif |
| 301 | |
| 302 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 303 | curwin->w_redraw_top = lnum; |
| 304 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 305 | curwin->w_redraw_bot = lnum; |
| 306 | redraw_later(VALID); |
| 307 | |
| 308 | #ifdef FEAT_FOLDING |
| 309 | if (invalid) |
| 310 | { |
| 311 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 312 | i = find_wl_entry(curwin, lnum); |
| 313 | if (i >= 0) |
| 314 | curwin->w_lines[i].wl_valid = FALSE; |
| 315 | } |
| 316 | #endif |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * update all windows that are editing the current buffer |
| 321 | */ |
| 322 | void |
| 323 | update_curbuf(type) |
| 324 | int type; |
| 325 | { |
| 326 | redraw_curbuf_later(type); |
| 327 | update_screen(type); |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * update_screen() |
| 332 | * |
| 333 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 334 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 335 | */ |
| 336 | void |
| 337 | update_screen(type) |
| 338 | int type; |
| 339 | { |
| 340 | win_T *wp; |
| 341 | static int did_intro = FALSE; |
| 342 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 343 | int did_one; |
| 344 | #endif |
| 345 | |
| 346 | if (!screen_valid(TRUE)) |
| 347 | return; |
| 348 | |
| 349 | if (must_redraw) |
| 350 | { |
| 351 | if (type < must_redraw) /* use maximal type */ |
| 352 | type = must_redraw; |
| 353 | must_redraw = 0; |
| 354 | } |
| 355 | |
| 356 | /* Need to update w_lines[]. */ |
| 357 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 358 | type = NOT_VALID; |
| 359 | |
| 360 | if (!redrawing()) |
| 361 | { |
| 362 | redraw_later(type); /* remember type for next time */ |
| 363 | must_redraw = type; |
| 364 | if (type > INVERTED_ALL) |
| 365 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | updating_screen = TRUE; |
| 370 | #ifdef FEAT_SYN_HL |
| 371 | ++display_tick; /* let syntax code know we're in a next round of |
| 372 | * display updating */ |
| 373 | #endif |
| 374 | |
| 375 | /* |
| 376 | * if the screen was scrolled up when displaying a message, scroll it down |
| 377 | */ |
| 378 | if (msg_scrolled) |
| 379 | { |
| 380 | clear_cmdline = TRUE; |
| 381 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 382 | type = CLEAR; |
| 383 | else if (type != CLEAR) |
| 384 | { |
| 385 | check_for_delay(FALSE); |
| 386 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 387 | type = CLEAR; |
| 388 | FOR_ALL_WINDOWS(wp) |
| 389 | { |
| 390 | if (W_WINROW(wp) < msg_scrolled) |
| 391 | { |
| 392 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 393 | && wp->w_redr_type < REDRAW_TOP |
| 394 | && wp->w_lines_valid > 0 |
| 395 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 396 | { |
| 397 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 398 | wp->w_redr_type = REDRAW_TOP; |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | wp->w_redr_type = NOT_VALID; |
| 403 | #ifdef FEAT_WINDOWS |
| 404 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 405 | <= msg_scrolled) |
| 406 | wp->w_redr_status = TRUE; |
| 407 | #endif |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 412 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 413 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 414 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 415 | } |
| 416 | msg_scrolled = 0; |
| 417 | need_wait_return = FALSE; |
| 418 | } |
| 419 | |
| 420 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 421 | compute_cmdrow(); |
| 422 | |
| 423 | /* Check for changed highlighting */ |
| 424 | if (need_highlight_changed) |
| 425 | highlight_changed(); |
| 426 | |
| 427 | if (type == CLEAR) /* first clear screen */ |
| 428 | { |
| 429 | screenclear(); /* will reset clear_cmdline */ |
| 430 | type = NOT_VALID; |
| 431 | } |
| 432 | |
| 433 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 434 | check_for_delay(FALSE); |
| 435 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 436 | #ifdef FEAT_LINEBREAK |
| 437 | /* Force redraw when width of 'number' column changes. */ |
| 438 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 439 | && curwin->w_nrwidth != (curwin->w_p_nu ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 440 | curwin->w_redr_type = NOT_VALID; |
| 441 | #endif |
| 442 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 443 | /* |
| 444 | * Only start redrawing if there is really something to do. |
| 445 | */ |
| 446 | if (type == INVERTED) |
| 447 | update_curswant(); |
| 448 | if (curwin->w_redr_type < type |
| 449 | && !((type == VALID |
| 450 | && curwin->w_lines[0].wl_valid |
| 451 | #ifdef FEAT_DIFF |
| 452 | && curwin->w_topfill == curwin->w_old_topfill |
| 453 | && curwin->w_botfill == curwin->w_old_botfill |
| 454 | #endif |
| 455 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
| 456 | #ifdef FEAT_VISUAL |
| 457 | || (type == INVERTED |
| 458 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 459 | && curwin->w_old_visual_mode == VIsual_mode |
| 460 | && (curwin->w_valid & VALID_VIRTCOL) |
| 461 | && curwin->w_old_curswant == curwin->w_curswant) |
| 462 | #endif |
| 463 | )) |
| 464 | curwin->w_redr_type = type; |
| 465 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 466 | #ifdef FEAT_WINDOWS |
| 467 | /* Redraw the tab pages line if needed. */ |
| 468 | if (redraw_tabline || type >= NOT_VALID) |
| 469 | draw_tabline(); |
| 470 | #endif |
| 471 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 472 | #ifdef FEAT_SYN_HL |
| 473 | /* |
| 474 | * Correct stored syntax highlighting info for changes in each displayed |
| 475 | * buffer. Each buffer must only be done once. |
| 476 | */ |
| 477 | FOR_ALL_WINDOWS(wp) |
| 478 | { |
| 479 | if (wp->w_buffer->b_mod_set) |
| 480 | { |
| 481 | # ifdef FEAT_WINDOWS |
| 482 | win_T *wwp; |
| 483 | |
| 484 | /* Check if we already did this buffer. */ |
| 485 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 486 | if (wwp->w_buffer == wp->w_buffer) |
| 487 | break; |
| 488 | # endif |
| 489 | if ( |
| 490 | # ifdef FEAT_WINDOWS |
| 491 | wwp == wp && |
| 492 | # endif |
| 493 | syntax_present(wp->w_buffer)) |
| 494 | syn_stack_apply_changes(wp->w_buffer); |
| 495 | } |
| 496 | } |
| 497 | #endif |
| 498 | |
| 499 | /* |
| 500 | * Go from top to bottom through the windows, redrawing the ones that need |
| 501 | * it. |
| 502 | */ |
| 503 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 504 | did_one = FALSE; |
| 505 | #endif |
| 506 | #ifdef FEAT_SEARCH_EXTRA |
| 507 | search_hl.rm.regprog = NULL; |
| 508 | #endif |
| 509 | FOR_ALL_WINDOWS(wp) |
| 510 | { |
| 511 | if (wp->w_redr_type != 0) |
| 512 | { |
| 513 | cursor_off(); |
| 514 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 515 | if (!did_one) |
| 516 | { |
| 517 | did_one = TRUE; |
| 518 | # ifdef FEAT_SEARCH_EXTRA |
| 519 | start_search_hl(); |
| 520 | # endif |
| 521 | # ifdef FEAT_CLIPBOARD |
| 522 | /* When Visual area changed, may have to update selection. */ |
| 523 | if (clip_star.available && clip_isautosel()) |
| 524 | clip_update_selection(); |
| 525 | # endif |
| 526 | #ifdef FEAT_GUI |
| 527 | /* Remove the cursor before starting to do anything, because |
| 528 | * scrolling may make it difficult to redraw the text under |
| 529 | * it. */ |
| 530 | if (gui.in_use) |
| 531 | gui_undraw_cursor(); |
| 532 | #endif |
| 533 | } |
| 534 | #endif |
| 535 | win_update(wp); |
| 536 | } |
| 537 | |
| 538 | #ifdef FEAT_WINDOWS |
| 539 | /* redraw status line after the window to minimize cursor movement */ |
| 540 | if (wp->w_redr_status) |
| 541 | { |
| 542 | cursor_off(); |
| 543 | win_redr_status(wp); |
| 544 | } |
| 545 | #endif |
| 546 | } |
| 547 | #if defined(FEAT_SEARCH_EXTRA) |
| 548 | end_search_hl(); |
| 549 | #endif |
| 550 | |
| 551 | #ifdef FEAT_WINDOWS |
| 552 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 553 | * than going through all buffers (there could be many buffers). */ |
| 554 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 555 | wp->w_buffer->b_mod_set = FALSE; |
| 556 | #else |
| 557 | curbuf->b_mod_set = FALSE; |
| 558 | #endif |
| 559 | |
| 560 | updating_screen = FALSE; |
| 561 | #ifdef FEAT_GUI |
| 562 | gui_may_resize_shell(); |
| 563 | #endif |
| 564 | |
| 565 | /* Clear or redraw the command line. Done last, because scrolling may |
| 566 | * mess up the command line. */ |
| 567 | if (clear_cmdline || redraw_cmdline) |
| 568 | showmode(); |
| 569 | |
| 570 | /* May put up an introductory message when not editing a file */ |
| 571 | if (!did_intro && bufempty() |
| 572 | && curbuf->b_fname == NULL |
| 573 | #ifdef FEAT_WINDOWS |
| 574 | && firstwin->w_next == NULL |
| 575 | #endif |
| 576 | && vim_strchr(p_shm, SHM_INTRO) == NULL) |
| 577 | intro_message(FALSE); |
| 578 | did_intro = TRUE; |
| 579 | |
| 580 | #ifdef FEAT_GUI |
| 581 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 582 | * done. */ |
| 583 | if (gui.in_use) |
| 584 | { |
| 585 | out_flush(); /* required before updating the cursor */ |
| 586 | if (did_one) |
| 587 | gui_update_cursor(FALSE, FALSE); |
| 588 | gui_update_scrollbars(FALSE); |
| 589 | } |
| 590 | #endif |
| 591 | } |
| 592 | |
| 593 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
| 594 | static void update_prepare __ARGS((void)); |
| 595 | static void update_finish __ARGS((void)); |
| 596 | |
| 597 | /* |
| 598 | * Prepare for updating one or more windows. |
| 599 | */ |
| 600 | static void |
| 601 | update_prepare() |
| 602 | { |
| 603 | cursor_off(); |
| 604 | updating_screen = TRUE; |
| 605 | #ifdef FEAT_GUI |
| 606 | /* Remove the cursor before starting to do anything, because scrolling may |
| 607 | * make it difficult to redraw the text under it. */ |
| 608 | if (gui.in_use) |
| 609 | gui_undraw_cursor(); |
| 610 | #endif |
| 611 | #ifdef FEAT_SEARCH_EXTRA |
| 612 | start_search_hl(); |
| 613 | #endif |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * Finish updating one or more windows. |
| 618 | */ |
| 619 | static void |
| 620 | update_finish() |
| 621 | { |
| 622 | if (redraw_cmdline) |
| 623 | showmode(); |
| 624 | |
| 625 | # ifdef FEAT_SEARCH_EXTRA |
| 626 | end_search_hl(); |
| 627 | # endif |
| 628 | |
| 629 | updating_screen = FALSE; |
| 630 | |
| 631 | # ifdef FEAT_GUI |
| 632 | gui_may_resize_shell(); |
| 633 | |
| 634 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 635 | * done. */ |
| 636 | if (gui.in_use) |
| 637 | { |
| 638 | out_flush(); /* required before updating the cursor */ |
| 639 | gui_update_cursor(FALSE, FALSE); |
| 640 | gui_update_scrollbars(FALSE); |
| 641 | } |
| 642 | # endif |
| 643 | } |
| 644 | #endif |
| 645 | |
| 646 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 647 | void |
| 648 | update_debug_sign(buf, lnum) |
| 649 | buf_T *buf; |
| 650 | linenr_T lnum; |
| 651 | { |
| 652 | win_T *wp; |
| 653 | int doit = FALSE; |
| 654 | |
| 655 | # ifdef FEAT_FOLDING |
| 656 | win_foldinfo.fi_level = 0; |
| 657 | # endif |
| 658 | |
| 659 | /* update/delete a specific mark */ |
| 660 | FOR_ALL_WINDOWS(wp) |
| 661 | { |
| 662 | if (buf != NULL && lnum > 0) |
| 663 | { |
| 664 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 665 | && lnum < wp->w_botline) |
| 666 | { |
| 667 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 668 | wp->w_redraw_top = lnum; |
| 669 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 670 | wp->w_redraw_bot = lnum; |
| 671 | redraw_win_later(wp, VALID); |
| 672 | } |
| 673 | } |
| 674 | else |
| 675 | redraw_win_later(wp, VALID); |
| 676 | if (wp->w_redr_type != 0) |
| 677 | doit = TRUE; |
| 678 | } |
| 679 | |
| 680 | if (!doit) |
| 681 | return; |
| 682 | |
| 683 | /* update all windows that need updating */ |
| 684 | update_prepare(); |
| 685 | |
| 686 | # ifdef FEAT_WINDOWS |
| 687 | for (wp = firstwin; wp; wp = wp->w_next) |
| 688 | { |
| 689 | if (wp->w_redr_type != 0) |
| 690 | win_update(wp); |
| 691 | if (wp->w_redr_status) |
| 692 | win_redr_status(wp); |
| 693 | } |
| 694 | # else |
| 695 | if (curwin->w_redr_type != 0) |
| 696 | win_update(curwin); |
| 697 | # endif |
| 698 | |
| 699 | update_finish(); |
| 700 | } |
| 701 | #endif |
| 702 | |
| 703 | |
| 704 | #if defined(FEAT_GUI) || defined(PROTO) |
| 705 | /* |
| 706 | * Update a single window, its status line and maybe the command line msg. |
| 707 | * Used for the GUI scrollbar. |
| 708 | */ |
| 709 | void |
| 710 | updateWindow(wp) |
| 711 | win_T *wp; |
| 712 | { |
| 713 | update_prepare(); |
| 714 | |
| 715 | #ifdef FEAT_CLIPBOARD |
| 716 | /* When Visual area changed, may have to update selection. */ |
| 717 | if (clip_star.available && clip_isautosel()) |
| 718 | clip_update_selection(); |
| 719 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 720 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 721 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 722 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 723 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 724 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 725 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 726 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 727 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 728 | if (wp->w_redr_status |
| 729 | # ifdef FEAT_CMDL_INFO |
| 730 | || p_ru |
| 731 | # endif |
| 732 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 733 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 734 | # endif |
| 735 | ) |
| 736 | win_redr_status(wp); |
| 737 | #endif |
| 738 | |
| 739 | update_finish(); |
| 740 | } |
| 741 | #endif |
| 742 | |
| 743 | /* |
| 744 | * Update a single window. |
| 745 | * |
| 746 | * This may cause the windows below it also to be redrawn (when clearing the |
| 747 | * screen or scrolling lines). |
| 748 | * |
| 749 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 750 | * implies the one below it. |
| 751 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 752 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 753 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 754 | * INVERTED redraw the changed part of the Visual area |
| 755 | * INVERTED_ALL redraw the whole Visual area |
| 756 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 757 | * 2. update lines at the top when scrolled down |
| 758 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 759 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 760 | * b_mod_top and b_mod_bot. |
| 761 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 762 | * wp->w_redraw_top and wp->w_redr_bot. |
| 763 | * - continue redrawing when syntax status is invalid. |
| 764 | * 4. if scrolled up, update lines at the bottom. |
| 765 | * This results in three areas that may need updating: |
| 766 | * top: from first row to top_end (when scrolled down) |
| 767 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 768 | * bot: from bot_start to last row (when scrolled up) |
| 769 | */ |
| 770 | static void |
| 771 | win_update(wp) |
| 772 | win_T *wp; |
| 773 | { |
| 774 | buf_T *buf = wp->w_buffer; |
| 775 | int type; |
| 776 | int top_end = 0; /* Below last row of the top area that needs |
| 777 | updating. 0 when no top area updating. */ |
| 778 | int mid_start = 999;/* first row of the mid area that needs |
| 779 | updating. 999 when no mid area updating. */ |
| 780 | int mid_end = 0; /* Below last row of the mid area that needs |
| 781 | updating. 0 when no mid area updating. */ |
| 782 | int bot_start = 999;/* first row of the bot area that needs |
| 783 | updating. 999 when no bot area updating */ |
| 784 | #ifdef FEAT_VISUAL |
| 785 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 786 | w_topline got smaller a bit */ |
| 787 | #endif |
| 788 | #ifdef FEAT_SEARCH_EXTRA |
| 789 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 790 | #endif |
| 791 | |
| 792 | int row; /* current window row to display */ |
| 793 | linenr_T lnum; /* current buffer lnum to display */ |
| 794 | int idx; /* current index in w_lines[] */ |
| 795 | int srow; /* starting row of the current line */ |
| 796 | |
| 797 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 798 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 799 | int i; |
| 800 | long j; |
| 801 | static int recursive = FALSE; /* being called recursively */ |
| 802 | int old_botline = wp->w_botline; |
| 803 | #ifdef FEAT_FOLDING |
| 804 | long fold_count; |
| 805 | #endif |
| 806 | #ifdef FEAT_SYN_HL |
| 807 | /* remember what happened to the previous line, to know if |
| 808 | * check_visual_highlight() can be used */ |
| 809 | #define DID_NONE 1 /* didn't update a line */ |
| 810 | #define DID_LINE 2 /* updated a normal line */ |
| 811 | #define DID_FOLD 3 /* updated a folded line */ |
| 812 | int did_update = DID_NONE; |
| 813 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 814 | #endif |
| 815 | linenr_T mod_top = 0; |
| 816 | linenr_T mod_bot = 0; |
| 817 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 818 | int save_got_int; |
| 819 | #endif |
| 820 | |
| 821 | type = wp->w_redr_type; |
| 822 | |
| 823 | if (type == NOT_VALID) |
| 824 | { |
| 825 | #ifdef FEAT_WINDOWS |
| 826 | wp->w_redr_status = TRUE; |
| 827 | #endif |
| 828 | wp->w_lines_valid = 0; |
| 829 | } |
| 830 | |
| 831 | /* Window is zero-height: nothing to draw. */ |
| 832 | if (wp->w_height == 0) |
| 833 | { |
| 834 | wp->w_redr_type = 0; |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | #ifdef FEAT_VERTSPLIT |
| 839 | /* Window is zero-width: Only need to draw the separator. */ |
| 840 | if (wp->w_width == 0) |
| 841 | { |
| 842 | /* draw the vertical separator right of this window */ |
| 843 | draw_vsep_win(wp, 0); |
| 844 | wp->w_redr_type = 0; |
| 845 | return; |
| 846 | } |
| 847 | #endif |
| 848 | |
| 849 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 850 | /* Setup for ":match" and 'hlsearch' highlighting. Disable any previous |
| 851 | * match */ |
| 852 | for (i = 0; i < 3; ++i) |
| 853 | { |
| 854 | match_hl[i].rm = wp->w_match[i]; |
| 855 | if (wp->w_match_id[i] == 0) |
| 856 | match_hl[i].attr = 0; |
| 857 | else |
| 858 | match_hl[i].attr = syn_id2attr(wp->w_match_id[i]); |
| 859 | match_hl[i].buf = buf; |
| 860 | match_hl[i].lnum = 0; |
| 861 | match_hl[i].first_lnum = 0; |
| 862 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 863 | search_hl.buf = buf; |
| 864 | search_hl.lnum = 0; |
| 865 | search_hl.first_lnum = 0; |
| 866 | #endif |
| 867 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 868 | #ifdef FEAT_LINEBREAK |
| 869 | /* Force redraw when width of 'number' column changes. */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 870 | i = wp->w_p_nu ? number_width(wp) : 0; |
| 871 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 872 | { |
| 873 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 874 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 875 | } |
| 876 | else |
| 877 | #endif |
| 878 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 879 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 880 | { |
| 881 | /* |
| 882 | * When there are both inserted/deleted lines and specific lines to be |
| 883 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 884 | * everything (only happens when redrawing is off for while). |
| 885 | */ |
| 886 | type = NOT_VALID; |
| 887 | } |
| 888 | else |
| 889 | { |
| 890 | /* |
| 891 | * Set mod_top to the first line that needs displaying because of |
| 892 | * changes. Set mod_bot to the first line after the changes. |
| 893 | */ |
| 894 | mod_top = wp->w_redraw_top; |
| 895 | if (wp->w_redraw_bot != 0) |
| 896 | mod_bot = wp->w_redraw_bot + 1; |
| 897 | else |
| 898 | mod_bot = 0; |
| 899 | wp->w_redraw_top = 0; /* reset for next time */ |
| 900 | wp->w_redraw_bot = 0; |
| 901 | if (buf->b_mod_set) |
| 902 | { |
| 903 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 904 | { |
| 905 | mod_top = buf->b_mod_top; |
| 906 | #ifdef FEAT_SYN_HL |
| 907 | /* Need to redraw lines above the change that may be included |
| 908 | * in a pattern match. */ |
| 909 | if (syntax_present(buf)) |
| 910 | { |
| 911 | mod_top -= buf->b_syn_sync_linebreaks; |
| 912 | if (mod_top < 1) |
| 913 | mod_top = 1; |
| 914 | } |
| 915 | #endif |
| 916 | } |
| 917 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 918 | mod_bot = buf->b_mod_bot; |
| 919 | |
| 920 | #ifdef FEAT_SEARCH_EXTRA |
| 921 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 922 | * change in one line may make the Search highlighting in a |
| 923 | * previous line invalid. Simple solution: redraw all visible |
| 924 | * lines above the change. |
| 925 | * Same for a ":match" pattern. |
| 926 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 927 | if (search_hl.rm.regprog != NULL |
| 928 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 929 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 930 | else |
| 931 | for (i = 0; i < 3; ++i) |
| 932 | if (match_hl[i].rm.regprog != NULL |
| 933 | && re_multiline(match_hl[i].rm.regprog)) |
| 934 | { |
| 935 | top_to_mod = TRUE; |
| 936 | break; |
| 937 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 938 | #endif |
| 939 | } |
| 940 | #ifdef FEAT_FOLDING |
| 941 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 942 | { |
| 943 | linenr_T lnumt, lnumb; |
| 944 | |
| 945 | /* |
| 946 | * A change in a line can cause lines above it to become folded or |
| 947 | * unfolded. Find the top most buffer line that may be affected. |
| 948 | * If the line was previously folded and displayed, get the first |
| 949 | * line of that fold. If the line is folded now, get the first |
| 950 | * folded line. Use the minimum of these two. |
| 951 | */ |
| 952 | |
| 953 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 954 | * the line below it. If there is no valid entry, use w_topline. |
| 955 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 956 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 957 | lnumt = wp->w_topline; |
| 958 | lnumb = MAXLNUM; |
| 959 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 960 | if (wp->w_lines[i].wl_valid) |
| 961 | { |
| 962 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 963 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 964 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 965 | { |
| 966 | lnumb = wp->w_lines[i].wl_lnum; |
| 967 | /* When there is a fold column it might need updating |
| 968 | * in the next line ("J" just above an open fold). */ |
| 969 | if (wp->w_p_fdc > 0) |
| 970 | ++lnumb; |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 975 | if (mod_top > lnumt) |
| 976 | mod_top = lnumt; |
| 977 | |
| 978 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 979 | --mod_bot; |
| 980 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 981 | ++mod_bot; |
| 982 | if (mod_bot < lnumb) |
| 983 | mod_bot = lnumb; |
| 984 | } |
| 985 | #endif |
| 986 | |
| 987 | /* When a change starts above w_topline and the end is below |
| 988 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 989 | * If the end of the change is above w_topline: do like no change was |
| 990 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 991 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 992 | { |
| 993 | if (mod_bot > wp->w_topline) |
| 994 | mod_top = wp->w_topline; |
| 995 | #ifdef FEAT_SYN_HL |
| 996 | else if (syntax_present(buf)) |
| 997 | top_end = 1; |
| 998 | #endif |
| 999 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1000 | |
| 1001 | /* When line numbers are displayed need to redraw all lines below |
| 1002 | * inserted/deleted lines. */ |
| 1003 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1004 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * When only displaying the lines at the top, set top_end. Used when |
| 1009 | * window has scrolled down for msg_scrolled. |
| 1010 | */ |
| 1011 | if (type == REDRAW_TOP) |
| 1012 | { |
| 1013 | j = 0; |
| 1014 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1015 | { |
| 1016 | j += wp->w_lines[i].wl_size; |
| 1017 | if (j >= wp->w_upd_rows) |
| 1018 | { |
| 1019 | top_end = j; |
| 1020 | break; |
| 1021 | } |
| 1022 | } |
| 1023 | if (top_end == 0) |
| 1024 | /* not found (cannot happen?): redraw everything */ |
| 1025 | type = NOT_VALID; |
| 1026 | else |
| 1027 | /* top area defined, the rest is VALID */ |
| 1028 | type = VALID; |
| 1029 | } |
| 1030 | |
| 1031 | /* |
| 1032 | * If there are no changes on the screen that require a complete redraw, |
| 1033 | * handle three cases: |
| 1034 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1035 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1036 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1037 | * w_lines[] that needs updating. |
| 1038 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1039 | if ((type == VALID || type == SOME_VALID |
| 1040 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1041 | #ifdef FEAT_DIFF |
| 1042 | && !wp->w_botfill && !wp->w_old_botfill |
| 1043 | #endif |
| 1044 | ) |
| 1045 | { |
| 1046 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1047 | { |
| 1048 | /* |
| 1049 | * w_topline is the first changed line, the scrolling will be done |
| 1050 | * further down. |
| 1051 | */ |
| 1052 | } |
| 1053 | else if (wp->w_lines[0].wl_valid |
| 1054 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1055 | #ifdef FEAT_DIFF |
| 1056 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1057 | && wp->w_topfill > wp->w_old_topfill) |
| 1058 | #endif |
| 1059 | )) |
| 1060 | { |
| 1061 | /* |
| 1062 | * New topline is above old topline: May scroll down. |
| 1063 | */ |
| 1064 | #ifdef FEAT_FOLDING |
| 1065 | if (hasAnyFolding(wp)) |
| 1066 | { |
| 1067 | linenr_T ln; |
| 1068 | |
| 1069 | /* count the number of lines we are off, counting a sequence |
| 1070 | * of folded lines as one */ |
| 1071 | j = 0; |
| 1072 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1073 | { |
| 1074 | ++j; |
| 1075 | if (j >= wp->w_height - 2) |
| 1076 | break; |
| 1077 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1078 | } |
| 1079 | } |
| 1080 | else |
| 1081 | #endif |
| 1082 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1083 | if (j < wp->w_height - 2) /* not too far off */ |
| 1084 | { |
| 1085 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1086 | #ifdef FEAT_DIFF |
| 1087 | /* insert extra lines for previously invisible filler lines */ |
| 1088 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1089 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1090 | - wp->w_old_topfill; |
| 1091 | #endif |
| 1092 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1093 | { |
| 1094 | /* |
| 1095 | * Try to insert the correct number of lines. |
| 1096 | * If not the last window, delete the lines at the bottom. |
| 1097 | * win_ins_lines may fail when the terminal can't do it. |
| 1098 | */ |
| 1099 | if (i > 0) |
| 1100 | check_for_delay(FALSE); |
| 1101 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1102 | { |
| 1103 | if (wp->w_lines_valid != 0) |
| 1104 | { |
| 1105 | /* Need to update rows that are new, stop at the |
| 1106 | * first one that scrolled down. */ |
| 1107 | top_end = i; |
| 1108 | #ifdef FEAT_VISUAL |
| 1109 | scrolled_down = TRUE; |
| 1110 | #endif |
| 1111 | |
| 1112 | /* Move the entries that were scrolled, disable |
| 1113 | * the entries for the lines to be redrawn. */ |
| 1114 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1115 | wp->w_lines_valid = wp->w_height; |
| 1116 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1117 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1118 | while (idx >= 0) |
| 1119 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1120 | } |
| 1121 | } |
| 1122 | else |
| 1123 | mid_start = 0; /* redraw all lines */ |
| 1124 | } |
| 1125 | else |
| 1126 | mid_start = 0; /* redraw all lines */ |
| 1127 | } |
| 1128 | else |
| 1129 | mid_start = 0; /* redraw all lines */ |
| 1130 | } |
| 1131 | else |
| 1132 | { |
| 1133 | /* |
| 1134 | * New topline is at or below old topline: May scroll up. |
| 1135 | * When topline didn't change, find first entry in w_lines[] that |
| 1136 | * needs updating. |
| 1137 | */ |
| 1138 | |
| 1139 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1140 | j = -1; |
| 1141 | row = 0; |
| 1142 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1143 | { |
| 1144 | if (wp->w_lines[i].wl_valid |
| 1145 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1146 | { |
| 1147 | j = i; |
| 1148 | break; |
| 1149 | } |
| 1150 | row += wp->w_lines[i].wl_size; |
| 1151 | } |
| 1152 | if (j == -1) |
| 1153 | { |
| 1154 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1155 | * lines */ |
| 1156 | mid_start = 0; |
| 1157 | } |
| 1158 | else |
| 1159 | { |
| 1160 | /* |
| 1161 | * Try to delete the correct number of lines. |
| 1162 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1163 | */ |
| 1164 | #ifdef FEAT_DIFF |
| 1165 | /* If the topline didn't change, delete old filler lines, |
| 1166 | * otherwise delete filler lines of the new topline... */ |
| 1167 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1168 | row += wp->w_old_topfill; |
| 1169 | else |
| 1170 | row += diff_check_fill(wp, wp->w_topline); |
| 1171 | /* ... but don't delete new filler lines. */ |
| 1172 | row -= wp->w_topfill; |
| 1173 | #endif |
| 1174 | if (row > 0) |
| 1175 | { |
| 1176 | check_for_delay(FALSE); |
| 1177 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1178 | bot_start = wp->w_height - row; |
| 1179 | else |
| 1180 | mid_start = 0; /* redraw all lines */ |
| 1181 | } |
| 1182 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1183 | { |
| 1184 | /* |
| 1185 | * Skip the lines (below the deleted lines) that are still |
| 1186 | * valid and don't need redrawing. Copy their info |
| 1187 | * upwards, to compensate for the deleted lines. Set |
| 1188 | * bot_start to the first row that needs redrawing. |
| 1189 | */ |
| 1190 | bot_start = 0; |
| 1191 | idx = 0; |
| 1192 | for (;;) |
| 1193 | { |
| 1194 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1195 | /* stop at line that didn't fit, unless it is still |
| 1196 | * valid (no lines deleted) */ |
| 1197 | if (row > 0 && bot_start + row |
| 1198 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1199 | { |
| 1200 | wp->w_lines_valid = idx + 1; |
| 1201 | break; |
| 1202 | } |
| 1203 | bot_start += wp->w_lines[idx++].wl_size; |
| 1204 | |
| 1205 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1206 | if (++j >= wp->w_lines_valid) |
| 1207 | { |
| 1208 | wp->w_lines_valid = idx; |
| 1209 | break; |
| 1210 | } |
| 1211 | } |
| 1212 | #ifdef FEAT_DIFF |
| 1213 | /* Correct the first entry for filler lines at the top |
| 1214 | * when it won't get updated below. */ |
| 1215 | if (wp->w_p_diff && bot_start > 0) |
| 1216 | wp->w_lines[0].wl_size = |
| 1217 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1218 | + wp->w_topfill; |
| 1219 | #endif |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | /* When starting redraw in the first line, redraw all lines. When |
| 1225 | * there is only one window it's probably faster to clear the screen |
| 1226 | * first. */ |
| 1227 | if (mid_start == 0) |
| 1228 | { |
| 1229 | mid_end = wp->w_height; |
| 1230 | if (lastwin == firstwin) |
| 1231 | screenclear(); |
| 1232 | } |
| 1233 | } |
| 1234 | else |
| 1235 | { |
| 1236 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1237 | mid_start = 0; |
| 1238 | mid_end = wp->w_height; |
| 1239 | } |
| 1240 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1241 | if (type == SOME_VALID) |
| 1242 | { |
| 1243 | /* SOME_VALID: redraw all lines. */ |
| 1244 | mid_start = 0; |
| 1245 | mid_end = wp->w_height; |
| 1246 | type = NOT_VALID; |
| 1247 | } |
| 1248 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1249 | #ifdef FEAT_VISUAL |
| 1250 | /* check if we are updating or removing the inverted part */ |
| 1251 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1252 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1253 | { |
| 1254 | linenr_T from, to; |
| 1255 | |
| 1256 | if (VIsual_active) |
| 1257 | { |
| 1258 | if (VIsual_active |
| 1259 | && (VIsual_mode != wp->w_old_visual_mode |
| 1260 | || type == INVERTED_ALL)) |
| 1261 | { |
| 1262 | /* |
| 1263 | * If the type of Visual selection changed, redraw the whole |
| 1264 | * selection. Also when the ownership of the X selection is |
| 1265 | * gained or lost. |
| 1266 | */ |
| 1267 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1268 | { |
| 1269 | from = curwin->w_cursor.lnum; |
| 1270 | to = VIsual.lnum; |
| 1271 | } |
| 1272 | else |
| 1273 | { |
| 1274 | from = VIsual.lnum; |
| 1275 | to = curwin->w_cursor.lnum; |
| 1276 | } |
| 1277 | /* redraw more when the cursor moved as well */ |
| 1278 | if (wp->w_old_cursor_lnum < from) |
| 1279 | from = wp->w_old_cursor_lnum; |
| 1280 | if (wp->w_old_cursor_lnum > to) |
| 1281 | to = wp->w_old_cursor_lnum; |
| 1282 | if (wp->w_old_visual_lnum < from) |
| 1283 | from = wp->w_old_visual_lnum; |
| 1284 | if (wp->w_old_visual_lnum > to) |
| 1285 | to = wp->w_old_visual_lnum; |
| 1286 | } |
| 1287 | else |
| 1288 | { |
| 1289 | /* |
| 1290 | * Find the line numbers that need to be updated: The lines |
| 1291 | * between the old cursor position and the current cursor |
| 1292 | * position. Also check if the Visual position changed. |
| 1293 | */ |
| 1294 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1295 | { |
| 1296 | from = curwin->w_cursor.lnum; |
| 1297 | to = wp->w_old_cursor_lnum; |
| 1298 | } |
| 1299 | else |
| 1300 | { |
| 1301 | from = wp->w_old_cursor_lnum; |
| 1302 | to = curwin->w_cursor.lnum; |
| 1303 | if (from == 0) /* Visual mode just started */ |
| 1304 | from = to; |
| 1305 | } |
| 1306 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1307 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1308 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1309 | { |
| 1310 | if (wp->w_old_visual_lnum < from |
| 1311 | && wp->w_old_visual_lnum != 0) |
| 1312 | from = wp->w_old_visual_lnum; |
| 1313 | if (wp->w_old_visual_lnum > to) |
| 1314 | to = wp->w_old_visual_lnum; |
| 1315 | if (VIsual.lnum < from) |
| 1316 | from = VIsual.lnum; |
| 1317 | if (VIsual.lnum > to) |
| 1318 | to = VIsual.lnum; |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | /* |
| 1323 | * If in block mode and changed column or curwin->w_curswant: |
| 1324 | * update all lines. |
| 1325 | * First compute the actual start and end column. |
| 1326 | */ |
| 1327 | if (VIsual_mode == Ctrl_V) |
| 1328 | { |
| 1329 | colnr_T fromc, toc; |
| 1330 | |
| 1331 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
| 1332 | ++toc; |
| 1333 | if (curwin->w_curswant == MAXCOL) |
| 1334 | toc = MAXCOL; |
| 1335 | |
| 1336 | if (fromc != wp->w_old_cursor_fcol |
| 1337 | || toc != wp->w_old_cursor_lcol) |
| 1338 | { |
| 1339 | if (from > VIsual.lnum) |
| 1340 | from = VIsual.lnum; |
| 1341 | if (to < VIsual.lnum) |
| 1342 | to = VIsual.lnum; |
| 1343 | } |
| 1344 | wp->w_old_cursor_fcol = fromc; |
| 1345 | wp->w_old_cursor_lcol = toc; |
| 1346 | } |
| 1347 | } |
| 1348 | else |
| 1349 | { |
| 1350 | /* Use the line numbers of the old Visual area. */ |
| 1351 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1352 | { |
| 1353 | from = wp->w_old_cursor_lnum; |
| 1354 | to = wp->w_old_visual_lnum; |
| 1355 | } |
| 1356 | else |
| 1357 | { |
| 1358 | from = wp->w_old_visual_lnum; |
| 1359 | to = wp->w_old_cursor_lnum; |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | /* |
| 1364 | * There is no need to update lines above the top of the window. |
| 1365 | */ |
| 1366 | if (from < wp->w_topline) |
| 1367 | from = wp->w_topline; |
| 1368 | |
| 1369 | /* |
| 1370 | * If we know the value of w_botline, use it to restrict the update to |
| 1371 | * the lines that are visible in the window. |
| 1372 | */ |
| 1373 | if (wp->w_valid & VALID_BOTLINE) |
| 1374 | { |
| 1375 | if (from >= wp->w_botline) |
| 1376 | from = wp->w_botline - 1; |
| 1377 | if (to >= wp->w_botline) |
| 1378 | to = wp->w_botline - 1; |
| 1379 | } |
| 1380 | |
| 1381 | /* |
| 1382 | * Find the minimal part to be updated. |
| 1383 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1384 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1385 | * top_end; need to redraw from top_end to the "to" line. |
| 1386 | * A middle mouse click with a Visual selection may change the text |
| 1387 | * above the Visual area and reset wl_valid, do count these for |
| 1388 | * mid_end (in srow). |
| 1389 | */ |
| 1390 | if (mid_start > 0) |
| 1391 | { |
| 1392 | lnum = wp->w_topline; |
| 1393 | idx = 0; |
| 1394 | srow = 0; |
| 1395 | if (scrolled_down) |
| 1396 | mid_start = top_end; |
| 1397 | else |
| 1398 | mid_start = 0; |
| 1399 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1400 | { |
| 1401 | if (wp->w_lines[idx].wl_valid) |
| 1402 | mid_start += wp->w_lines[idx].wl_size; |
| 1403 | else if (!scrolled_down) |
| 1404 | srow += wp->w_lines[idx].wl_size; |
| 1405 | ++idx; |
| 1406 | # ifdef FEAT_FOLDING |
| 1407 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1408 | lnum = wp->w_lines[idx].wl_lnum; |
| 1409 | else |
| 1410 | # endif |
| 1411 | ++lnum; |
| 1412 | } |
| 1413 | srow += mid_start; |
| 1414 | mid_end = wp->w_height; |
| 1415 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1416 | { |
| 1417 | if (wp->w_lines[idx].wl_valid |
| 1418 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1419 | { |
| 1420 | /* Only update until first row of this line */ |
| 1421 | mid_end = srow; |
| 1422 | break; |
| 1423 | } |
| 1424 | srow += wp->w_lines[idx].wl_size; |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | if (VIsual_active && buf == curwin->w_buffer) |
| 1430 | { |
| 1431 | wp->w_old_visual_mode = VIsual_mode; |
| 1432 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1433 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1434 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1435 | wp->w_old_curswant = curwin->w_curswant; |
| 1436 | } |
| 1437 | else |
| 1438 | { |
| 1439 | wp->w_old_visual_mode = 0; |
| 1440 | wp->w_old_cursor_lnum = 0; |
| 1441 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1442 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1443 | } |
| 1444 | #endif /* FEAT_VISUAL */ |
| 1445 | |
| 1446 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1447 | /* reset got_int, otherwise regexp won't work */ |
| 1448 | save_got_int = got_int; |
| 1449 | got_int = 0; |
| 1450 | #endif |
| 1451 | #ifdef FEAT_FOLDING |
| 1452 | win_foldinfo.fi_level = 0; |
| 1453 | #endif |
| 1454 | |
| 1455 | /* |
| 1456 | * Update all the window rows. |
| 1457 | */ |
| 1458 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1459 | row = 0; |
| 1460 | srow = 0; |
| 1461 | lnum = wp->w_topline; /* first line shown in window */ |
| 1462 | for (;;) |
| 1463 | { |
| 1464 | /* stop updating when reached the end of the window (check for _past_ |
| 1465 | * the end of the window is at the end of the loop) */ |
| 1466 | if (row == wp->w_height) |
| 1467 | { |
| 1468 | didline = TRUE; |
| 1469 | break; |
| 1470 | } |
| 1471 | |
| 1472 | /* stop updating when hit the end of the file */ |
| 1473 | if (lnum > buf->b_ml.ml_line_count) |
| 1474 | { |
| 1475 | eof = TRUE; |
| 1476 | break; |
| 1477 | } |
| 1478 | |
| 1479 | /* Remember the starting row of the line that is going to be dealt |
| 1480 | * with. It is used further down when the line doesn't fit. */ |
| 1481 | srow = row; |
| 1482 | |
| 1483 | /* |
| 1484 | * Update a line when it is in an area that needs updating, when it |
| 1485 | * has changes or w_lines[idx] is invalid. |
| 1486 | * bot_start may be halfway a wrapped line after using |
| 1487 | * win_del_lines(), check if the current line includes it. |
| 1488 | * When syntax folding is being used, the saved syntax states will |
| 1489 | * already have been updated, we can't see where the syntax state is |
| 1490 | * the same again, just update until the end of the window. |
| 1491 | */ |
| 1492 | if (row < top_end |
| 1493 | || (row >= mid_start && row < mid_end) |
| 1494 | #ifdef FEAT_SEARCH_EXTRA |
| 1495 | || top_to_mod |
| 1496 | #endif |
| 1497 | || idx >= wp->w_lines_valid |
| 1498 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1499 | || (mod_top != 0 |
| 1500 | && (lnum == mod_top |
| 1501 | || (lnum >= mod_top |
| 1502 | && (lnum < mod_bot |
| 1503 | #ifdef FEAT_SYN_HL |
| 1504 | || did_update == DID_FOLD |
| 1505 | || (did_update == DID_LINE |
| 1506 | && syntax_present(buf) |
| 1507 | && ( |
| 1508 | # ifdef FEAT_FOLDING |
| 1509 | (foldmethodIsSyntax(wp) |
| 1510 | && hasAnyFolding(wp)) || |
| 1511 | # endif |
| 1512 | syntax_check_changed(lnum))) |
| 1513 | #endif |
| 1514 | ))))) |
| 1515 | { |
| 1516 | #ifdef FEAT_SEARCH_EXTRA |
| 1517 | if (lnum == mod_top) |
| 1518 | top_to_mod = FALSE; |
| 1519 | #endif |
| 1520 | |
| 1521 | /* |
| 1522 | * When at start of changed lines: May scroll following lines |
| 1523 | * up or down to minimize redrawing. |
| 1524 | * Don't do this when the change continues until the end. |
| 1525 | * Don't scroll when dollar_vcol is non-zero, keep the "$". |
| 1526 | */ |
| 1527 | if (lnum == mod_top |
| 1528 | && mod_bot != MAXLNUM |
| 1529 | && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) |
| 1530 | { |
| 1531 | int old_rows = 0; |
| 1532 | int new_rows = 0; |
| 1533 | int xtra_rows; |
| 1534 | linenr_T l; |
| 1535 | |
| 1536 | /* Count the old number of window rows, using w_lines[], which |
| 1537 | * should still contain the sizes for the lines as they are |
| 1538 | * currently displayed. */ |
| 1539 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1540 | { |
| 1541 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1542 | * lines are part of the changed area. */ |
| 1543 | if (wp->w_lines[i].wl_valid |
| 1544 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1545 | break; |
| 1546 | old_rows += wp->w_lines[i].wl_size; |
| 1547 | #ifdef FEAT_FOLDING |
| 1548 | if (wp->w_lines[i].wl_valid |
| 1549 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1550 | { |
| 1551 | /* Must have found the last valid entry above mod_bot. |
| 1552 | * Add following invalid entries. */ |
| 1553 | ++i; |
| 1554 | while (i < wp->w_lines_valid |
| 1555 | && !wp->w_lines[i].wl_valid) |
| 1556 | old_rows += wp->w_lines[i++].wl_size; |
| 1557 | break; |
| 1558 | } |
| 1559 | #endif |
| 1560 | } |
| 1561 | |
| 1562 | if (i >= wp->w_lines_valid) |
| 1563 | { |
| 1564 | /* We can't find a valid line below the changed lines, |
| 1565 | * need to redraw until the end of the window. |
| 1566 | * Inserting/deleting lines has no use. */ |
| 1567 | bot_start = 0; |
| 1568 | } |
| 1569 | else |
| 1570 | { |
| 1571 | /* Able to count old number of rows: Count new window |
| 1572 | * rows, and may insert/delete lines */ |
| 1573 | j = idx; |
| 1574 | for (l = lnum; l < mod_bot; ++l) |
| 1575 | { |
| 1576 | #ifdef FEAT_FOLDING |
| 1577 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1578 | ++new_rows; |
| 1579 | else |
| 1580 | #endif |
| 1581 | #ifdef FEAT_DIFF |
| 1582 | if (l == wp->w_topline) |
| 1583 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1584 | + wp->w_topfill; |
| 1585 | else |
| 1586 | #endif |
| 1587 | new_rows += plines_win(wp, l, TRUE); |
| 1588 | ++j; |
| 1589 | if (new_rows > wp->w_height - row - 2) |
| 1590 | { |
| 1591 | /* it's getting too much, must redraw the rest */ |
| 1592 | new_rows = 9999; |
| 1593 | break; |
| 1594 | } |
| 1595 | } |
| 1596 | xtra_rows = new_rows - old_rows; |
| 1597 | if (xtra_rows < 0) |
| 1598 | { |
| 1599 | /* May scroll text up. If there is not enough |
| 1600 | * remaining text or scrolling fails, must redraw the |
| 1601 | * rest. If scrolling works, must redraw the text |
| 1602 | * below the scrolled text. */ |
| 1603 | if (row - xtra_rows >= wp->w_height - 2) |
| 1604 | mod_bot = MAXLNUM; |
| 1605 | else |
| 1606 | { |
| 1607 | check_for_delay(FALSE); |
| 1608 | if (win_del_lines(wp, row, |
| 1609 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1610 | mod_bot = MAXLNUM; |
| 1611 | else |
| 1612 | bot_start = wp->w_height + xtra_rows; |
| 1613 | } |
| 1614 | } |
| 1615 | else if (xtra_rows > 0) |
| 1616 | { |
| 1617 | /* May scroll text down. If there is not enough |
| 1618 | * remaining text of scrolling fails, must redraw the |
| 1619 | * rest. */ |
| 1620 | if (row + xtra_rows >= wp->w_height - 2) |
| 1621 | mod_bot = MAXLNUM; |
| 1622 | else |
| 1623 | { |
| 1624 | check_for_delay(FALSE); |
| 1625 | if (win_ins_lines(wp, row + old_rows, |
| 1626 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1627 | mod_bot = MAXLNUM; |
| 1628 | else if (top_end > row + old_rows) |
| 1629 | /* Scrolled the part at the top that requires |
| 1630 | * updating down. */ |
| 1631 | top_end += xtra_rows; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | /* When not updating the rest, may need to move w_lines[] |
| 1636 | * entries. */ |
| 1637 | if (mod_bot != MAXLNUM && i != j) |
| 1638 | { |
| 1639 | if (j < i) |
| 1640 | { |
| 1641 | int x = row + new_rows; |
| 1642 | |
| 1643 | /* move entries in w_lines[] upwards */ |
| 1644 | for (;;) |
| 1645 | { |
| 1646 | /* stop at last valid entry in w_lines[] */ |
| 1647 | if (i >= wp->w_lines_valid) |
| 1648 | { |
| 1649 | wp->w_lines_valid = j; |
| 1650 | break; |
| 1651 | } |
| 1652 | wp->w_lines[j] = wp->w_lines[i]; |
| 1653 | /* stop at a line that won't fit */ |
| 1654 | if (x + (int)wp->w_lines[j].wl_size |
| 1655 | > wp->w_height) |
| 1656 | { |
| 1657 | wp->w_lines_valid = j + 1; |
| 1658 | break; |
| 1659 | } |
| 1660 | x += wp->w_lines[j++].wl_size; |
| 1661 | ++i; |
| 1662 | } |
| 1663 | if (bot_start > x) |
| 1664 | bot_start = x; |
| 1665 | } |
| 1666 | else /* j > i */ |
| 1667 | { |
| 1668 | /* move entries in w_lines[] downwards */ |
| 1669 | j -= i; |
| 1670 | wp->w_lines_valid += j; |
| 1671 | if (wp->w_lines_valid > wp->w_height) |
| 1672 | wp->w_lines_valid = wp->w_height; |
| 1673 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1674 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1675 | |
| 1676 | /* The w_lines[] entries for inserted lines are |
| 1677 | * now invalid, but wl_size may be used above. |
| 1678 | * Reset to zero. */ |
| 1679 | while (i >= idx) |
| 1680 | { |
| 1681 | wp->w_lines[i].wl_size = 0; |
| 1682 | wp->w_lines[i--].wl_valid = FALSE; |
| 1683 | } |
| 1684 | } |
| 1685 | } |
| 1686 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | #ifdef FEAT_FOLDING |
| 1690 | /* |
| 1691 | * When lines are folded, display one line for all of them. |
| 1692 | * Otherwise, display normally (can be several display lines when |
| 1693 | * 'wrap' is on). |
| 1694 | */ |
| 1695 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1696 | if (fold_count != 0) |
| 1697 | { |
| 1698 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1699 | ++row; |
| 1700 | --fold_count; |
| 1701 | wp->w_lines[idx].wl_folded = TRUE; |
| 1702 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1703 | # ifdef FEAT_SYN_HL |
| 1704 | did_update = DID_FOLD; |
| 1705 | # endif |
| 1706 | } |
| 1707 | else |
| 1708 | #endif |
| 1709 | if (idx < wp->w_lines_valid |
| 1710 | && wp->w_lines[idx].wl_valid |
| 1711 | && wp->w_lines[idx].wl_lnum == lnum |
| 1712 | && lnum > wp->w_topline |
| 1713 | && !(dy_flags & DY_LASTLINE) |
| 1714 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1715 | #ifdef FEAT_DIFF |
| 1716 | && diff_check_fill(wp, lnum) == 0 |
| 1717 | #endif |
| 1718 | ) |
| 1719 | { |
| 1720 | /* This line is not going to fit. Don't draw anything here, |
| 1721 | * will draw "@ " lines below. */ |
| 1722 | row = wp->w_height + 1; |
| 1723 | } |
| 1724 | else |
| 1725 | { |
| 1726 | #ifdef FEAT_SEARCH_EXTRA |
| 1727 | prepare_search_hl(wp, lnum); |
| 1728 | #endif |
| 1729 | #ifdef FEAT_SYN_HL |
| 1730 | /* Let the syntax stuff know we skipped a few lines. */ |
| 1731 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
| 1732 | && syntax_present(buf)) |
| 1733 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1734 | #endif |
| 1735 | |
| 1736 | /* |
| 1737 | * Display one line. |
| 1738 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 1739 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1740 | |
| 1741 | #ifdef FEAT_FOLDING |
| 1742 | wp->w_lines[idx].wl_folded = FALSE; |
| 1743 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 1744 | #endif |
| 1745 | #ifdef FEAT_SYN_HL |
| 1746 | did_update = DID_LINE; |
| 1747 | syntax_last_parsed = lnum; |
| 1748 | #endif |
| 1749 | } |
| 1750 | |
| 1751 | wp->w_lines[idx].wl_lnum = lnum; |
| 1752 | wp->w_lines[idx].wl_valid = TRUE; |
| 1753 | if (row > wp->w_height) /* past end of screen */ |
| 1754 | { |
| 1755 | /* we may need the size of that too long line later on */ |
| 1756 | if (dollar_vcol == 0) |
| 1757 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 1758 | ++idx; |
| 1759 | break; |
| 1760 | } |
| 1761 | if (dollar_vcol == 0) |
| 1762 | wp->w_lines[idx].wl_size = row - srow; |
| 1763 | ++idx; |
| 1764 | #ifdef FEAT_FOLDING |
| 1765 | lnum += fold_count + 1; |
| 1766 | #else |
| 1767 | ++lnum; |
| 1768 | #endif |
| 1769 | } |
| 1770 | else |
| 1771 | { |
| 1772 | /* This line does not need updating, advance to the next one */ |
| 1773 | row += wp->w_lines[idx++].wl_size; |
| 1774 | if (row > wp->w_height) /* past end of screen */ |
| 1775 | break; |
| 1776 | #ifdef FEAT_FOLDING |
| 1777 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 1778 | #else |
| 1779 | ++lnum; |
| 1780 | #endif |
| 1781 | #ifdef FEAT_SYN_HL |
| 1782 | did_update = DID_NONE; |
| 1783 | #endif |
| 1784 | } |
| 1785 | |
| 1786 | if (lnum > buf->b_ml.ml_line_count) |
| 1787 | { |
| 1788 | eof = TRUE; |
| 1789 | break; |
| 1790 | } |
| 1791 | } |
| 1792 | /* |
| 1793 | * End of loop over all window lines. |
| 1794 | */ |
| 1795 | |
| 1796 | |
| 1797 | if (idx > wp->w_lines_valid) |
| 1798 | wp->w_lines_valid = idx; |
| 1799 | |
| 1800 | #ifdef FEAT_SYN_HL |
| 1801 | /* |
| 1802 | * Let the syntax stuff know we stop parsing here. |
| 1803 | */ |
| 1804 | if (syntax_last_parsed != 0 && syntax_present(buf)) |
| 1805 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1806 | #endif |
| 1807 | |
| 1808 | /* |
| 1809 | * If we didn't hit the end of the file, and we didn't finish the last |
| 1810 | * line we were working on, then the line didn't fit. |
| 1811 | */ |
| 1812 | wp->w_empty_rows = 0; |
| 1813 | #ifdef FEAT_DIFF |
| 1814 | wp->w_filler_rows = 0; |
| 1815 | #endif |
| 1816 | if (!eof && !didline) |
| 1817 | { |
| 1818 | if (lnum == wp->w_topline) |
| 1819 | { |
| 1820 | /* |
| 1821 | * Single line that does not fit! |
| 1822 | * Don't overwrite it, it can be edited. |
| 1823 | */ |
| 1824 | wp->w_botline = lnum + 1; |
| 1825 | } |
| 1826 | #ifdef FEAT_DIFF |
| 1827 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 1828 | { |
| 1829 | /* Window ends in filler lines. */ |
| 1830 | wp->w_botline = lnum; |
| 1831 | wp->w_filler_rows = wp->w_height - srow; |
| 1832 | } |
| 1833 | #endif |
| 1834 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 1835 | { |
| 1836 | /* |
| 1837 | * Last line isn't finished: Display "@@@" at the end. |
| 1838 | */ |
| 1839 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 1840 | W_WINROW(wp) + wp->w_height, |
| 1841 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 1842 | '@', '@', hl_attr(HLF_AT)); |
| 1843 | set_empty_rows(wp, srow); |
| 1844 | wp->w_botline = lnum; |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 1849 | wp->w_botline = lnum; |
| 1850 | } |
| 1851 | } |
| 1852 | else |
| 1853 | { |
| 1854 | #ifdef FEAT_VERTSPLIT |
| 1855 | draw_vsep_win(wp, row); |
| 1856 | #endif |
| 1857 | if (eof) /* we hit the end of the file */ |
| 1858 | { |
| 1859 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 1860 | #ifdef FEAT_DIFF |
| 1861 | j = diff_check_fill(wp, wp->w_botline); |
| 1862 | if (j > 0 && !wp->w_botfill) |
| 1863 | { |
| 1864 | /* |
| 1865 | * Display filler lines at the end of the file |
| 1866 | */ |
| 1867 | if (char2cells(fill_diff) > 1) |
| 1868 | i = '-'; |
| 1869 | else |
| 1870 | i = fill_diff; |
| 1871 | if (row + j > wp->w_height) |
| 1872 | j = wp->w_height - row; |
| 1873 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 1874 | row += j; |
| 1875 | } |
| 1876 | #endif |
| 1877 | } |
| 1878 | else if (dollar_vcol == 0) |
| 1879 | wp->w_botline = lnum; |
| 1880 | |
| 1881 | /* make sure the rest of the screen is blank */ |
| 1882 | /* put '~'s on rows that aren't part of the file. */ |
| 1883 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 1884 | } |
| 1885 | |
| 1886 | /* Reset the type of redrawing required, the window has been updated. */ |
| 1887 | wp->w_redr_type = 0; |
| 1888 | #ifdef FEAT_DIFF |
| 1889 | wp->w_old_topfill = wp->w_topfill; |
| 1890 | wp->w_old_botfill = wp->w_botfill; |
| 1891 | #endif |
| 1892 | |
| 1893 | if (dollar_vcol == 0) |
| 1894 | { |
| 1895 | /* |
| 1896 | * There is a trick with w_botline. If we invalidate it on each |
| 1897 | * change that might modify it, this will cause a lot of expensive |
| 1898 | * calls to plines() in update_topline() each time. Therefore the |
| 1899 | * value of w_botline is often approximated, and this value is used to |
| 1900 | * compute the value of w_topline. If the value of w_botline was |
| 1901 | * wrong, check that the value of w_topline is correct (cursor is on |
| 1902 | * the visible part of the text). If it's not, we need to redraw |
| 1903 | * again. Mostly this just means scrolling up a few lines, so it |
| 1904 | * doesn't look too bad. Only do this for the current window (where |
| 1905 | * changes are relevant). |
| 1906 | */ |
| 1907 | wp->w_valid |= VALID_BOTLINE; |
| 1908 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 1909 | { |
| 1910 | recursive = TRUE; |
| 1911 | curwin->w_valid &= ~VALID_TOPLINE; |
| 1912 | update_topline(); /* may invalidate w_botline again */ |
| 1913 | if (must_redraw != 0) |
| 1914 | { |
| 1915 | /* Don't update for changes in buffer again. */ |
| 1916 | i = curbuf->b_mod_set; |
| 1917 | curbuf->b_mod_set = FALSE; |
| 1918 | win_update(curwin); |
| 1919 | must_redraw = 0; |
| 1920 | curbuf->b_mod_set = i; |
| 1921 | } |
| 1922 | recursive = FALSE; |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1927 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 1928 | if (!got_int) |
| 1929 | got_int = save_got_int; |
| 1930 | #endif |
| 1931 | } |
| 1932 | |
| 1933 | #ifdef FEAT_SIGNS |
| 1934 | static int draw_signcolumn __ARGS((win_T *wp)); |
| 1935 | |
| 1936 | /* |
| 1937 | * Return TRUE when window "wp" has a column to draw signs in. |
| 1938 | */ |
| 1939 | static int |
| 1940 | draw_signcolumn(wp) |
| 1941 | win_T *wp; |
| 1942 | { |
| 1943 | return (wp->w_buffer->b_signlist != NULL |
| 1944 | # ifdef FEAT_NETBEANS_INTG |
| 1945 | || usingNetbeans |
| 1946 | # endif |
| 1947 | ); |
| 1948 | } |
| 1949 | #endif |
| 1950 | |
| 1951 | /* |
| 1952 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 1953 | * as the filler character. |
| 1954 | */ |
| 1955 | static void |
| 1956 | win_draw_end(wp, c1, c2, row, endrow, hl) |
| 1957 | win_T *wp; |
| 1958 | int c1; |
| 1959 | int c2; |
| 1960 | int row; |
| 1961 | int endrow; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 1962 | hlf_T hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1963 | { |
| 1964 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 1965 | int n = 0; |
| 1966 | # define FDC_OFF n |
| 1967 | #else |
| 1968 | # define FDC_OFF 0 |
| 1969 | #endif |
| 1970 | |
| 1971 | #ifdef FEAT_RIGHTLEFT |
| 1972 | if (wp->w_p_rl) |
| 1973 | { |
| 1974 | /* No check for cmdline window: should never be right-left. */ |
| 1975 | # ifdef FEAT_FOLDING |
| 1976 | n = wp->w_p_fdc; |
| 1977 | |
| 1978 | if (n > 0) |
| 1979 | { |
| 1980 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 1981 | if (n > W_WIDTH(wp)) |
| 1982 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1983 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 1984 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 1985 | ' ', ' ', hl_attr(HLF_FC)); |
| 1986 | } |
| 1987 | # endif |
| 1988 | # ifdef FEAT_SIGNS |
| 1989 | if (draw_signcolumn(wp)) |
| 1990 | { |
| 1991 | int nn = n + 2; |
| 1992 | |
| 1993 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 1994 | if (nn > W_WIDTH(wp)) |
| 1995 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1996 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 1997 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 1998 | ' ', ' ', hl_attr(HLF_SC)); |
| 1999 | n = nn; |
| 2000 | } |
| 2001 | # endif |
| 2002 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2003 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2004 | c2, c2, hl_attr(hl)); |
| 2005 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2006 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2007 | c1, c2, hl_attr(hl)); |
| 2008 | } |
| 2009 | else |
| 2010 | #endif |
| 2011 | { |
| 2012 | #ifdef FEAT_CMDWIN |
| 2013 | if (cmdwin_type != 0 && wp == curwin) |
| 2014 | { |
| 2015 | /* draw the cmdline character in the leftmost column */ |
| 2016 | n = 1; |
| 2017 | if (n > wp->w_width) |
| 2018 | n = wp->w_width; |
| 2019 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2020 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2021 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2022 | } |
| 2023 | #endif |
| 2024 | #ifdef FEAT_FOLDING |
| 2025 | if (wp->w_p_fdc > 0) |
| 2026 | { |
| 2027 | int nn = n + wp->w_p_fdc; |
| 2028 | |
| 2029 | /* draw the fold column at the left */ |
| 2030 | if (nn > W_WIDTH(wp)) |
| 2031 | nn = W_WIDTH(wp); |
| 2032 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2033 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2034 | ' ', ' ', hl_attr(HLF_FC)); |
| 2035 | n = nn; |
| 2036 | } |
| 2037 | #endif |
| 2038 | #ifdef FEAT_SIGNS |
| 2039 | if (draw_signcolumn(wp)) |
| 2040 | { |
| 2041 | int nn = n + 2; |
| 2042 | |
| 2043 | /* draw the sign column after the fold column */ |
| 2044 | if (nn > W_WIDTH(wp)) |
| 2045 | nn = W_WIDTH(wp); |
| 2046 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2047 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2048 | ' ', ' ', hl_attr(HLF_SC)); |
| 2049 | n = nn; |
| 2050 | } |
| 2051 | #endif |
| 2052 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2053 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2054 | c1, c2, hl_attr(hl)); |
| 2055 | } |
| 2056 | set_empty_rows(wp, row); |
| 2057 | } |
| 2058 | |
| 2059 | #ifdef FEAT_FOLDING |
| 2060 | /* |
| 2061 | * Display one folded line. |
| 2062 | */ |
| 2063 | static void |
| 2064 | fold_line(wp, fold_count, foldinfo, lnum, row) |
| 2065 | win_T *wp; |
| 2066 | long fold_count; |
| 2067 | foldinfo_T *foldinfo; |
| 2068 | linenr_T lnum; |
| 2069 | int row; |
| 2070 | { |
| 2071 | char_u buf[51]; |
| 2072 | pos_T *top, *bot; |
| 2073 | linenr_T lnume = lnum + fold_count - 1; |
| 2074 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2075 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2076 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2077 | int col; |
| 2078 | int txtcol; |
| 2079 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2080 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2081 | |
| 2082 | /* Build the fold line: |
| 2083 | * 1. Add the cmdwin_type for the command-line window |
| 2084 | * 2. Add the 'foldcolumn' |
| 2085 | * 3. Add the 'number' column |
| 2086 | * 4. Compose the text |
| 2087 | * 5. Add the text |
| 2088 | * 6. set highlighting for the Visual area an other text |
| 2089 | */ |
| 2090 | col = 0; |
| 2091 | |
| 2092 | /* |
| 2093 | * 1. Add the cmdwin_type for the command-line window |
| 2094 | * Ignores 'rightleft', this window is never right-left. |
| 2095 | */ |
| 2096 | #ifdef FEAT_CMDWIN |
| 2097 | if (cmdwin_type != 0 && wp == curwin) |
| 2098 | { |
| 2099 | ScreenLines[off] = cmdwin_type; |
| 2100 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2101 | #ifdef FEAT_MBYTE |
| 2102 | if (enc_utf8) |
| 2103 | ScreenLinesUC[off] = 0; |
| 2104 | #endif |
| 2105 | ++col; |
| 2106 | } |
| 2107 | #endif |
| 2108 | |
| 2109 | /* |
| 2110 | * 2. Add the 'foldcolumn' |
| 2111 | */ |
| 2112 | fdc = wp->w_p_fdc; |
| 2113 | if (fdc > W_WIDTH(wp) - col) |
| 2114 | fdc = W_WIDTH(wp) - col; |
| 2115 | if (fdc > 0) |
| 2116 | { |
| 2117 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2118 | #ifdef FEAT_RIGHTLEFT |
| 2119 | if (wp->w_p_rl) |
| 2120 | { |
| 2121 | int i; |
| 2122 | |
| 2123 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2124 | hl_attr(HLF_FC)); |
| 2125 | /* reverse the fold column */ |
| 2126 | for (i = 0; i < fdc; ++i) |
| 2127 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2128 | } |
| 2129 | else |
| 2130 | #endif |
| 2131 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2132 | col += fdc; |
| 2133 | } |
| 2134 | |
| 2135 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2136 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2137 | for (ri = 0; ri < l; ++ri) \ |
| 2138 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2139 | else \ |
| 2140 | for (ri = 0; ri < l; ++ri) \ |
| 2141 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2142 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2143 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2144 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2145 | #endif |
| 2146 | |
| 2147 | /* Set all attributes of the 'number' column and the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2148 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2149 | |
| 2150 | #ifdef FEAT_SIGNS |
| 2151 | /* If signs are being displayed, add two spaces. */ |
| 2152 | if (draw_signcolumn(wp)) |
| 2153 | { |
| 2154 | len = W_WIDTH(wp) - col; |
| 2155 | if (len > 0) |
| 2156 | { |
| 2157 | if (len > 2) |
| 2158 | len = 2; |
| 2159 | # ifdef FEAT_RIGHTLEFT |
| 2160 | if (wp->w_p_rl) |
| 2161 | /* the line number isn't reversed */ |
| 2162 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2163 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2164 | else |
| 2165 | # endif |
| 2166 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2167 | col += len; |
| 2168 | } |
| 2169 | } |
| 2170 | #endif |
| 2171 | |
| 2172 | /* |
| 2173 | * 3. Add the 'number' column |
| 2174 | */ |
| 2175 | if (wp->w_p_nu) |
| 2176 | { |
| 2177 | len = W_WIDTH(wp) - col; |
| 2178 | if (len > 0) |
| 2179 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2180 | int w = number_width(wp); |
| 2181 | |
| 2182 | if (len > w + 1) |
| 2183 | len = w + 1; |
| 2184 | sprintf((char *)buf, "%*ld ", w, (long)lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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, buf, len, |
| 2189 | hl_attr(HLF_FL)); |
| 2190 | else |
| 2191 | #endif |
| 2192 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2193 | col += len; |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | /* |
| 2198 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2199 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2200 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2201 | |
| 2202 | txtcol = col; /* remember where text starts */ |
| 2203 | |
| 2204 | /* |
| 2205 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2206 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2207 | * in columns number-col - window-width. |
| 2208 | */ |
| 2209 | #ifdef FEAT_MBYTE |
| 2210 | if (has_mbyte) |
| 2211 | { |
| 2212 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2213 | int u8c, u8cc[MAX_MCO]; |
| 2214 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2215 | int idx; |
| 2216 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2217 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2218 | # ifdef FEAT_ARABIC |
| 2219 | int prev_c = 0; /* previous Arabic character */ |
| 2220 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2221 | # endif |
| 2222 | |
| 2223 | # ifdef FEAT_RIGHTLEFT |
| 2224 | if (wp->w_p_rl) |
| 2225 | idx = off; |
| 2226 | else |
| 2227 | # endif |
| 2228 | idx = off + col; |
| 2229 | |
| 2230 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2231 | for (p = text; *p != NUL; ) |
| 2232 | { |
| 2233 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2234 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2235 | if (col + cells > W_WIDTH(wp) |
| 2236 | # ifdef FEAT_RIGHTLEFT |
| 2237 | - (wp->w_p_rl ? col : 0) |
| 2238 | # endif |
| 2239 | ) |
| 2240 | break; |
| 2241 | ScreenLines[idx] = *p; |
| 2242 | if (enc_utf8) |
| 2243 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2244 | u8c = utfc_ptr2char(p, u8cc); |
| 2245 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2246 | { |
| 2247 | ScreenLinesUC[idx] = 0; |
| 2248 | #ifdef FEAT_ARABIC |
| 2249 | prev_c = u8c; |
| 2250 | #endif |
| 2251 | } |
| 2252 | else |
| 2253 | { |
| 2254 | #ifdef FEAT_ARABIC |
| 2255 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2256 | { |
| 2257 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2258 | int pc, pc1, nc; |
| 2259 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2260 | int firstbyte = *p; |
| 2261 | |
| 2262 | /* The idea of what is the previous and next |
| 2263 | * character depends on 'rightleft'. */ |
| 2264 | if (wp->w_p_rl) |
| 2265 | { |
| 2266 | pc = prev_c; |
| 2267 | pc1 = prev_c1; |
| 2268 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2269 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2270 | } |
| 2271 | else |
| 2272 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2273 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2274 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2275 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2276 | } |
| 2277 | prev_c = u8c; |
| 2278 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2279 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2280 | pc, pc1, nc); |
| 2281 | ScreenLines[idx] = firstbyte; |
| 2282 | } |
| 2283 | else |
| 2284 | prev_c = u8c; |
| 2285 | #endif |
| 2286 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 2287 | if (u8c >= 0x10000) |
| 2288 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2289 | else |
| 2290 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2291 | for (i = 0; i < Screen_mco; ++i) |
| 2292 | { |
| 2293 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2294 | if (u8cc[i] == 0) |
| 2295 | break; |
| 2296 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2297 | } |
| 2298 | if (cells > 1) |
| 2299 | ScreenLines[idx + 1] = 0; |
| 2300 | } |
| 2301 | else if (cells > 1) /* double-byte character */ |
| 2302 | { |
| 2303 | if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2304 | ScreenLines2[idx] = p[1]; |
| 2305 | else |
| 2306 | ScreenLines[idx + 1] = p[1]; |
| 2307 | } |
| 2308 | col += cells; |
| 2309 | idx += cells; |
| 2310 | p += c_len; |
| 2311 | } |
| 2312 | } |
| 2313 | else |
| 2314 | #endif |
| 2315 | { |
| 2316 | len = (int)STRLEN(text); |
| 2317 | if (len > W_WIDTH(wp) - col) |
| 2318 | len = W_WIDTH(wp) - col; |
| 2319 | if (len > 0) |
| 2320 | { |
| 2321 | #ifdef FEAT_RIGHTLEFT |
| 2322 | if (wp->w_p_rl) |
| 2323 | STRNCPY(current_ScreenLine, text, len); |
| 2324 | else |
| 2325 | #endif |
| 2326 | STRNCPY(current_ScreenLine + col, text, len); |
| 2327 | col += len; |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | /* Fill the rest of the line with the fold filler */ |
| 2332 | #ifdef FEAT_RIGHTLEFT |
| 2333 | if (wp->w_p_rl) |
| 2334 | col -= txtcol; |
| 2335 | #endif |
| 2336 | while (col < W_WIDTH(wp) |
| 2337 | #ifdef FEAT_RIGHTLEFT |
| 2338 | - (wp->w_p_rl ? txtcol : 0) |
| 2339 | #endif |
| 2340 | ) |
| 2341 | { |
| 2342 | #ifdef FEAT_MBYTE |
| 2343 | if (enc_utf8) |
| 2344 | { |
| 2345 | if (fill_fold >= 0x80) |
| 2346 | { |
| 2347 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2348 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2349 | } |
| 2350 | else |
| 2351 | ScreenLinesUC[off + col] = 0; |
| 2352 | } |
| 2353 | #endif |
| 2354 | ScreenLines[off + col++] = fill_fold; |
| 2355 | } |
| 2356 | |
| 2357 | if (text != buf) |
| 2358 | vim_free(text); |
| 2359 | |
| 2360 | /* |
| 2361 | * 6. set highlighting for the Visual area an other text. |
| 2362 | * If all folded lines are in the Visual area, highlight the line. |
| 2363 | */ |
| 2364 | #ifdef FEAT_VISUAL |
| 2365 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2366 | { |
| 2367 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2368 | { |
| 2369 | /* Visual is after curwin->w_cursor */ |
| 2370 | top = &curwin->w_cursor; |
| 2371 | bot = &VIsual; |
| 2372 | } |
| 2373 | else |
| 2374 | { |
| 2375 | /* Visual is before curwin->w_cursor */ |
| 2376 | top = &VIsual; |
| 2377 | bot = &curwin->w_cursor; |
| 2378 | } |
| 2379 | if (lnum >= top->lnum |
| 2380 | && lnume <= bot->lnum |
| 2381 | && (VIsual_mode != 'v' |
| 2382 | || ((lnum > top->lnum |
| 2383 | || (lnum == top->lnum |
| 2384 | && top->col == 0)) |
| 2385 | && (lnume < bot->lnum |
| 2386 | || (lnume == bot->lnum |
| 2387 | && (bot->col - (*p_sel == 'e')) |
| 2388 | >= STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
| 2389 | { |
| 2390 | if (VIsual_mode == Ctrl_V) |
| 2391 | { |
| 2392 | /* Visual block mode: highlight the chars part of the block */ |
| 2393 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2394 | { |
| 2395 | if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2396 | len = wp->w_old_cursor_lcol; |
| 2397 | else |
| 2398 | len = W_WIDTH(wp) - txtcol; |
| 2399 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2400 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2404 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2405 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2406 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2407 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | #endif |
| 2411 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2412 | #ifdef FEAT_SYN_HL |
| 2413 | /* Show 'cursorcolumn' in the fold line. */ |
| 2414 | if (wp->w_p_cuc && (int)wp->w_virtcol + txtcol < W_WIDTH(wp)) |
| 2415 | ScreenAttrs[off + wp->w_virtcol + txtcol] = hl_combine_attr( |
| 2416 | ScreenAttrs[off + wp->w_virtcol + txtcol], hl_attr(HLF_CUC)); |
| 2417 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2418 | |
| 2419 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2420 | (int)W_WIDTH(wp), FALSE); |
| 2421 | |
| 2422 | /* |
| 2423 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2424 | * updated (saves a call to plines() later). |
| 2425 | */ |
| 2426 | if (wp == curwin |
| 2427 | && lnum <= curwin->w_cursor.lnum |
| 2428 | && lnume >= curwin->w_cursor.lnum) |
| 2429 | { |
| 2430 | curwin->w_cline_row = row; |
| 2431 | curwin->w_cline_height = 1; |
| 2432 | curwin->w_cline_folded = TRUE; |
| 2433 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | /* |
| 2438 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2439 | */ |
| 2440 | static void |
| 2441 | copy_text_attr(off, buf, len, attr) |
| 2442 | int off; |
| 2443 | char_u *buf; |
| 2444 | int len; |
| 2445 | int attr; |
| 2446 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2447 | int i; |
| 2448 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2449 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2450 | # ifdef FEAT_MBYTE |
| 2451 | if (enc_utf8) |
| 2452 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2453 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2454 | for (i = 0; i < len; ++i) |
| 2455 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | /* |
| 2459 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2460 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2461 | */ |
| 2462 | static void |
| 2463 | fill_foldcolumn(p, wp, closed, lnum) |
| 2464 | char_u *p; |
| 2465 | win_T *wp; |
| 2466 | int closed; /* TRUE of FALSE */ |
| 2467 | linenr_T lnum; /* current line number */ |
| 2468 | { |
| 2469 | int i = 0; |
| 2470 | int level; |
| 2471 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2472 | int empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2473 | |
| 2474 | /* Init to all spaces. */ |
| 2475 | copy_spaces(p, (size_t)wp->w_p_fdc); |
| 2476 | |
| 2477 | level = win_foldinfo.fi_level; |
| 2478 | if (level > 0) |
| 2479 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2480 | /* If there is only one column put more info in it. */ |
| 2481 | empty = (wp->w_p_fdc == 1) ? 0 : 1; |
| 2482 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2483 | /* If the column is too narrow, we start at the lowest level that |
| 2484 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2485 | first_level = level - wp->w_p_fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2486 | if (first_level < 1) |
| 2487 | first_level = 1; |
| 2488 | |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2489 | for (i = 0; i + empty < wp->w_p_fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2490 | { |
| 2491 | if (win_foldinfo.fi_lnum == lnum |
| 2492 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2493 | p[i] = '-'; |
| 2494 | else if (first_level == 1) |
| 2495 | p[i] = '|'; |
| 2496 | else if (first_level + i <= 9) |
| 2497 | p[i] = '0' + first_level + i; |
| 2498 | else |
| 2499 | p[i] = '>'; |
| 2500 | if (first_level + i == level) |
| 2501 | break; |
| 2502 | } |
| 2503 | } |
| 2504 | if (closed) |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2505 | p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2506 | } |
| 2507 | #endif /* FEAT_FOLDING */ |
| 2508 | |
| 2509 | /* |
| 2510 | * Display line "lnum" of window 'wp' on the screen. |
| 2511 | * Start at row "startrow", stop when "endrow" is reached. |
| 2512 | * wp->w_virtcol needs to be valid. |
| 2513 | * |
| 2514 | * Return the number of last row the line occupies. |
| 2515 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2516 | /* ARGSUSED */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2517 | static int |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2518 | win_line(wp, lnum, startrow, endrow, nochange) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2519 | win_T *wp; |
| 2520 | linenr_T lnum; |
| 2521 | int startrow; |
| 2522 | int endrow; |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2523 | int nochange; /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2524 | { |
| 2525 | int col; /* visual column on screen */ |
| 2526 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2527 | int c = 0; /* init for GCC */ |
| 2528 | long vcol = 0; /* virtual column (for tabs) */ |
| 2529 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2530 | char_u *line; /* current line */ |
| 2531 | char_u *ptr; /* current position in "line" */ |
| 2532 | int row; /* row in the window, excl w_winrow */ |
| 2533 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2534 | |
| 2535 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2536 | int n_extra = 0; /* number of extra chars */ |
| 2537 | char_u *p_extra = NULL; /* string of extra chars */ |
| 2538 | int c_extra = NUL; /* extra chars, all the same */ |
| 2539 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2540 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2541 | displaying lcs_eol at end-of-line */ |
| 2542 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2543 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2544 | |
| 2545 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2546 | int saved_n_extra = 0; |
| 2547 | char_u *saved_p_extra = NULL; |
| 2548 | int saved_c_extra = 0; |
| 2549 | int saved_char_attr = 0; |
| 2550 | |
| 2551 | int n_attr = 0; /* chars with special attr */ |
| 2552 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2553 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2554 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2555 | |
| 2556 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2557 | |
| 2558 | int fromcol, tocol; /* start/end of inverting */ |
| 2559 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2560 | int noinvcur = FALSE; /* don't invert the cursor */ |
| 2561 | #ifdef FEAT_VISUAL |
| 2562 | pos_T *top, *bot; |
| 2563 | #endif |
| 2564 | pos_T pos; |
| 2565 | long v; |
| 2566 | |
| 2567 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2568 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2569 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2570 | in this line */ |
| 2571 | int attr = 0; /* attributes for area highlighting */ |
| 2572 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2573 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2574 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2575 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2576 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2577 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2578 | int save_did_emsg; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2579 | #endif |
| 2580 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2581 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2582 | # define SPWORDLEN 150 |
| 2583 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2584 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2585 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2586 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2587 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2588 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2589 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2590 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2591 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2592 | static int cap_col = -1; /* column to check for Cap word */ |
| 2593 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2594 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2595 | #endif |
| 2596 | int extra_check; /* has syntax or linebreak */ |
| 2597 | #ifdef FEAT_MBYTE |
| 2598 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2599 | int mb_l = 1; /* multi-byte byte length */ |
| 2600 | int mb_c = 0; /* decoded multi-byte character */ |
| 2601 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2602 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2603 | #endif |
| 2604 | #ifdef FEAT_DIFF |
| 2605 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2606 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2607 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2608 | int change_start = MAXCOL; /* first col of changed area */ |
| 2609 | int change_end = -1; /* last col of changed area */ |
| 2610 | #endif |
| 2611 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2612 | #ifdef FEAT_LINEBREAK |
| 2613 | int need_showbreak = FALSE; |
| 2614 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame^] | 2615 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2616 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2617 | # define LINE_ATTR |
| 2618 | int line_attr = 0; /* atrribute for the whole line */ |
| 2619 | #endif |
| 2620 | #ifdef FEAT_SEARCH_EXTRA |
| 2621 | match_T *shl; /* points to search_hl or match_hl */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2622 | #endif |
| 2623 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_MBYTE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 2624 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2625 | #endif |
| 2626 | #ifdef FEAT_ARABIC |
| 2627 | int prev_c = 0; /* previous Arabic character */ |
| 2628 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2629 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame^] | 2630 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 2631 | int did_line_attr = 0; |
| 2632 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2633 | |
| 2634 | /* draw_state: items that are drawn in sequence: */ |
| 2635 | #define WL_START 0 /* nothing done yet */ |
| 2636 | #ifdef FEAT_CMDWIN |
| 2637 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 2638 | #else |
| 2639 | # define WL_CMDLINE WL_START |
| 2640 | #endif |
| 2641 | #ifdef FEAT_FOLDING |
| 2642 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 2643 | #else |
| 2644 | # define WL_FOLD WL_CMDLINE |
| 2645 | #endif |
| 2646 | #ifdef FEAT_SIGNS |
| 2647 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 2648 | #else |
| 2649 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 2650 | #endif |
| 2651 | #define WL_NR WL_SIGN + 1 /* line number */ |
| 2652 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 2653 | # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ |
| 2654 | #else |
| 2655 | # define WL_SBR WL_NR |
| 2656 | #endif |
| 2657 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 2658 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 2659 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2660 | int feedback_col = 0; |
| 2661 | int feedback_old_attr = -1; |
| 2662 | #endif |
| 2663 | |
| 2664 | |
| 2665 | if (startrow > endrow) /* past the end already! */ |
| 2666 | return startrow; |
| 2667 | |
| 2668 | row = startrow; |
| 2669 | screen_row = row + W_WINROW(wp); |
| 2670 | |
| 2671 | /* |
| 2672 | * To speed up the loop below, set extra_check when there is linebreak, |
| 2673 | * trailing white space and/or syntax processing to be done. |
| 2674 | */ |
| 2675 | #ifdef FEAT_LINEBREAK |
| 2676 | extra_check = wp->w_p_lbr; |
| 2677 | #else |
| 2678 | extra_check = 0; |
| 2679 | #endif |
| 2680 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 2681 | if (syntax_present(wp->w_buffer) && !wp->w_buffer->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2682 | { |
| 2683 | /* Prepare for syntax highlighting in this line. When there is an |
| 2684 | * error, stop syntax highlighting. */ |
| 2685 | save_did_emsg = did_emsg; |
| 2686 | did_emsg = FALSE; |
| 2687 | syntax_start(wp, lnum); |
| 2688 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 2689 | wp->w_buffer->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2690 | else |
| 2691 | { |
| 2692 | did_emsg = save_did_emsg; |
| 2693 | has_syntax = TRUE; |
| 2694 | extra_check = TRUE; |
| 2695 | } |
| 2696 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2697 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2698 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2699 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 2700 | if (wp->w_p_spell |
| 2701 | && *wp->w_buffer->b_p_spl != NUL |
| 2702 | && wp->w_buffer->b_langp.ga_len > 0 |
| 2703 | && *(char **)(wp->w_buffer->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2704 | { |
| 2705 | /* Prepare for spell checking. */ |
| 2706 | has_spell = TRUE; |
| 2707 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2708 | |
| 2709 | /* Get the start of the next line, so that words that wrap to the next |
| 2710 | * line are found too: "et<line-break>al.". |
| 2711 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 2712 | nextline[SPWORDLEN] = NUL; |
| 2713 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 2714 | { |
| 2715 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 2716 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 2717 | } |
| 2718 | |
| 2719 | /* When a word wrapped from the previous line the start of the current |
| 2720 | * line is valid. */ |
| 2721 | if (lnum == checked_lnum) |
| 2722 | cur_checked_col = checked_col; |
| 2723 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2724 | |
| 2725 | /* When there was a sentence end in the previous line may require a |
| 2726 | * word starting with capital in this line. In line 1 always check |
| 2727 | * the first word. */ |
| 2728 | if (lnum != capcol_lnum) |
| 2729 | cap_col = -1; |
| 2730 | if (lnum == 1) |
| 2731 | cap_col = 0; |
| 2732 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2733 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2734 | #endif |
| 2735 | |
| 2736 | /* |
| 2737 | * handle visual active in this window |
| 2738 | */ |
| 2739 | fromcol = -10; |
| 2740 | tocol = MAXCOL; |
| 2741 | #ifdef FEAT_VISUAL |
| 2742 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2743 | { |
| 2744 | /* Visual is after curwin->w_cursor */ |
| 2745 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2746 | { |
| 2747 | top = &curwin->w_cursor; |
| 2748 | bot = &VIsual; |
| 2749 | } |
| 2750 | else /* Visual is before curwin->w_cursor */ |
| 2751 | { |
| 2752 | top = &VIsual; |
| 2753 | bot = &curwin->w_cursor; |
| 2754 | } |
| 2755 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 2756 | { |
| 2757 | if (lnum >= top->lnum && lnum <= bot->lnum) |
| 2758 | { |
| 2759 | fromcol = wp->w_old_cursor_fcol; |
| 2760 | tocol = wp->w_old_cursor_lcol; |
| 2761 | } |
| 2762 | } |
| 2763 | else /* non-block mode */ |
| 2764 | { |
| 2765 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 2766 | fromcol = 0; |
| 2767 | else if (lnum == top->lnum) |
| 2768 | { |
| 2769 | if (VIsual_mode == 'V') /* linewise */ |
| 2770 | fromcol = 0; |
| 2771 | else |
| 2772 | { |
| 2773 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 2774 | if (gchar_pos(top) == NUL) |
| 2775 | tocol = fromcol + 1; |
| 2776 | } |
| 2777 | } |
| 2778 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 2779 | { |
| 2780 | if (*p_sel == 'e' && bot->col == 0 |
| 2781 | #ifdef FEAT_VIRTUALEDIT |
| 2782 | && bot->coladd == 0 |
| 2783 | #endif |
| 2784 | ) |
| 2785 | { |
| 2786 | fromcol = -10; |
| 2787 | tocol = MAXCOL; |
| 2788 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2789 | else if (bot->col == MAXCOL) |
| 2790 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2791 | else |
| 2792 | { |
| 2793 | pos = *bot; |
| 2794 | if (*p_sel == 'e') |
| 2795 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2796 | else |
| 2797 | { |
| 2798 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 2799 | ++tocol; |
| 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | #ifndef MSDOS |
| 2806 | /* Check if the character under the cursor should not be inverted */ |
| 2807 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
| 2808 | # ifdef FEAT_GUI |
| 2809 | && !gui.in_use |
| 2810 | # endif |
| 2811 | ) |
| 2812 | noinvcur = TRUE; |
| 2813 | #endif |
| 2814 | |
| 2815 | /* if inverting in this line set area_highlighting */ |
| 2816 | if (fromcol >= 0) |
| 2817 | { |
| 2818 | area_highlighting = TRUE; |
| 2819 | attr = hl_attr(HLF_V); |
| 2820 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
| 2821 | if (clip_star.available && !clip_star.owned && clip_isautosel()) |
| 2822 | attr = hl_attr(HLF_VNC); |
| 2823 | #endif |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2828 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2829 | */ |
| 2830 | else |
| 2831 | #endif /* FEAT_VISUAL */ |
| 2832 | if (highlight_match |
| 2833 | && wp == curwin |
| 2834 | && lnum >= curwin->w_cursor.lnum |
| 2835 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 2836 | { |
| 2837 | if (lnum == curwin->w_cursor.lnum) |
| 2838 | getvcol(curwin, &(curwin->w_cursor), |
| 2839 | (colnr_T *)&fromcol, NULL, NULL); |
| 2840 | else |
| 2841 | fromcol = 0; |
| 2842 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 2843 | { |
| 2844 | pos.lnum = lnum; |
| 2845 | pos.col = search_match_endcol; |
| 2846 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2847 | } |
| 2848 | else |
| 2849 | tocol = MAXCOL; |
| 2850 | if (fromcol == tocol) /* do at least one character */ |
| 2851 | tocol = fromcol + 1; /* happens when past end of line */ |
| 2852 | area_highlighting = TRUE; |
| 2853 | attr = hl_attr(HLF_I); |
| 2854 | } |
| 2855 | |
| 2856 | #ifdef FEAT_DIFF |
| 2857 | filler_lines = diff_check(wp, lnum); |
| 2858 | if (filler_lines < 0) |
| 2859 | { |
| 2860 | if (filler_lines == -1) |
| 2861 | { |
| 2862 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 2863 | diff_hlf = HLF_ADD; /* added line */ |
| 2864 | else if (change_start == 0) |
| 2865 | diff_hlf = HLF_TXD; /* changed text */ |
| 2866 | else |
| 2867 | diff_hlf = HLF_CHD; /* changed line */ |
| 2868 | } |
| 2869 | else |
| 2870 | diff_hlf = HLF_ADD; /* added line */ |
| 2871 | filler_lines = 0; |
| 2872 | area_highlighting = TRUE; |
| 2873 | } |
| 2874 | if (lnum == wp->w_topline) |
| 2875 | filler_lines = wp->w_topfill; |
| 2876 | filler_todo = filler_lines; |
| 2877 | #endif |
| 2878 | |
| 2879 | #ifdef LINE_ATTR |
| 2880 | # ifdef FEAT_SIGNS |
| 2881 | /* If this line has a sign with line highlighting set line_attr. */ |
| 2882 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 2883 | if (v != 0) |
| 2884 | line_attr = sign_get_attr((int)v, TRUE); |
| 2885 | # endif |
| 2886 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 2887 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 2888 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2889 | line_attr = hl_attr(HLF_L); |
| 2890 | # endif |
| 2891 | if (line_attr != 0) |
| 2892 | area_highlighting = TRUE; |
| 2893 | #endif |
| 2894 | |
| 2895 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 2896 | ptr = line; |
| 2897 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2898 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2899 | if (has_spell) |
| 2900 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2901 | /* For checking first word with a capital skip white space. */ |
| 2902 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 2903 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2904 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2905 | /* To be able to spell-check over line boundaries copy the end of the |
| 2906 | * current line into nextline[]. Above the start of the next line was |
| 2907 | * copied to nextline[SPWORDLEN]. */ |
| 2908 | if (nextline[SPWORDLEN] == NUL) |
| 2909 | { |
| 2910 | /* No next line or it is empty. */ |
| 2911 | nextlinecol = MAXCOL; |
| 2912 | nextline_idx = 0; |
| 2913 | } |
| 2914 | else |
| 2915 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 2916 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2917 | if (v < SPWORDLEN) |
| 2918 | { |
| 2919 | /* Short line, use it completely and append the start of the |
| 2920 | * next line. */ |
| 2921 | nextlinecol = 0; |
| 2922 | mch_memmove(nextline, line, (size_t)v); |
| 2923 | mch_memmove(nextline + v, nextline + SPWORDLEN, |
| 2924 | STRLEN(nextline + SPWORDLEN) + 1); |
| 2925 | nextline_idx = v + 1; |
| 2926 | } |
| 2927 | else |
| 2928 | { |
| 2929 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 2930 | nextlinecol = v - SPWORDLEN; |
| 2931 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 2932 | nextline_idx = SPWORDLEN + 1; |
| 2933 | } |
| 2934 | } |
| 2935 | } |
| 2936 | #endif |
| 2937 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2938 | /* find start of trailing whitespace */ |
| 2939 | if (wp->w_p_list && lcs_trail) |
| 2940 | { |
| 2941 | trailcol = (colnr_T)STRLEN(ptr); |
| 2942 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 2943 | --trailcol; |
| 2944 | trailcol += (colnr_T) (ptr - line); |
| 2945 | extra_check = TRUE; |
| 2946 | } |
| 2947 | |
| 2948 | /* |
| 2949 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 2950 | * first character to be displayed. |
| 2951 | */ |
| 2952 | if (wp->w_p_wrap) |
| 2953 | v = wp->w_skipcol; |
| 2954 | else |
| 2955 | v = wp->w_leftcol; |
| 2956 | if (v > 0) |
| 2957 | { |
| 2958 | #ifdef FEAT_MBYTE |
| 2959 | char_u *prev_ptr = ptr; |
| 2960 | #endif |
| 2961 | while (vcol < v && *ptr != NUL) |
| 2962 | { |
| 2963 | c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); |
| 2964 | vcol += c; |
| 2965 | #ifdef FEAT_MBYTE |
| 2966 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2967 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 2968 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | #ifdef FEAT_VIRTUALEDIT |
| 2972 | /* When 'virtualedit' is set the end of the line may be before the |
| 2973 | * start of the displayed part. */ |
| 2974 | if (vcol < v && *ptr == NUL && virtual_active()) |
| 2975 | vcol = v; |
| 2976 | #endif |
| 2977 | |
| 2978 | /* Handle a character that's not completely on the screen: Put ptr at |
| 2979 | * that character but skip the first few screen characters. */ |
| 2980 | if (vcol > v) |
| 2981 | { |
| 2982 | vcol -= c; |
| 2983 | #ifdef FEAT_MBYTE |
| 2984 | ptr = prev_ptr; |
| 2985 | #else |
| 2986 | --ptr; |
| 2987 | #endif |
| 2988 | n_skip = v - vcol; |
| 2989 | } |
| 2990 | |
| 2991 | /* |
| 2992 | * Adjust for when the inverted text is before the screen, |
| 2993 | * and when the start of the inverted text is before the screen. |
| 2994 | */ |
| 2995 | if (tocol <= vcol) |
| 2996 | fromcol = 0; |
| 2997 | else if (fromcol >= 0 && fromcol < vcol) |
| 2998 | fromcol = vcol; |
| 2999 | |
| 3000 | #ifdef FEAT_LINEBREAK |
| 3001 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3002 | if (wp->w_p_wrap) |
| 3003 | need_showbreak = TRUE; |
| 3004 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3005 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3006 | /* When spell checking a word we need to figure out the start of the |
| 3007 | * word and if it's badly spelled or not. */ |
| 3008 | if (has_spell) |
| 3009 | { |
| 3010 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3011 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3012 | |
| 3013 | pos = wp->w_cursor; |
| 3014 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3015 | wp->w_cursor.col = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3016 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3017 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3018 | { |
| 3019 | /* no bad word found at line start, don't check until end of a |
| 3020 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3021 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3022 | 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] | 3023 | } |
| 3024 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3025 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3026 | /* bad word found, use attributes until end of word */ |
| 3027 | word_end = wp->w_cursor.col + len + 1; |
| 3028 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3029 | /* Turn index into actual attributes. */ |
| 3030 | if (spell_hlf != HLF_COUNT) |
| 3031 | spell_attr = highlight_attr[spell_hlf]; |
| 3032 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3033 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3034 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3035 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3036 | /* Need to restart syntax highlighting for this line. */ |
| 3037 | if (has_syntax) |
| 3038 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3039 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3040 | } |
| 3041 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | /* |
| 3045 | * Correct highlighting for cursor that can't be disabled. |
| 3046 | * Avoids having to check this for each character. |
| 3047 | */ |
| 3048 | if (fromcol >= 0) |
| 3049 | { |
| 3050 | if (noinvcur) |
| 3051 | { |
| 3052 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3053 | { |
| 3054 | /* highlighting starts at cursor, let it start just after the |
| 3055 | * cursor */ |
| 3056 | fromcol_prev = fromcol; |
| 3057 | fromcol = -1; |
| 3058 | } |
| 3059 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3060 | /* restart highlighting after the cursor */ |
| 3061 | fromcol_prev = wp->w_virtcol; |
| 3062 | } |
| 3063 | if (fromcol >= tocol) |
| 3064 | fromcol = -1; |
| 3065 | } |
| 3066 | |
| 3067 | #ifdef FEAT_SEARCH_EXTRA |
| 3068 | /* |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3069 | * Handle highlighting the last used search pattern and ":match". |
| 3070 | * Do this for both search_hl and match_hl[3]. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3071 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3072 | for (i = 3; i >= 0; --i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3073 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3074 | shl = (i == 3) ? &search_hl : &match_hl[i]; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3075 | shl->startcol = MAXCOL; |
| 3076 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3077 | shl->attr_cur = 0; |
| 3078 | if (shl->rm.regprog != NULL) |
| 3079 | { |
| 3080 | v = (long)(ptr - line); |
| 3081 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3082 | |
| 3083 | /* Need to get the line again, a multi-line regexp may have made it |
| 3084 | * invalid. */ |
| 3085 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3086 | ptr = line + v; |
| 3087 | |
| 3088 | if (shl->lnum != 0 && shl->lnum <= lnum) |
| 3089 | { |
| 3090 | if (shl->lnum == lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3091 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3092 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3093 | shl->startcol = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3094 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3095 | - shl->rm.startpos[0].lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3096 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3097 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3098 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3099 | /* Highlight one character for an empty match. */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3100 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3101 | { |
| 3102 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3103 | if (has_mbyte && line[shl->endcol] != NUL) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3104 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3105 | else |
| 3106 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3107 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3108 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3109 | if ((long)shl->startcol < v) /* match at leftcol */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3110 | { |
| 3111 | shl->attr_cur = shl->attr; |
| 3112 | search_attr = shl->attr; |
| 3113 | } |
| 3114 | area_highlighting = TRUE; |
| 3115 | } |
| 3116 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3117 | } |
| 3118 | #endif |
| 3119 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3120 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 3121 | /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
| 3122 | * active, because it's not clear what is selected then. */ |
| 3123 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3124 | { |
| 3125 | line_attr = hl_attr(HLF_CUL); |
| 3126 | area_highlighting = TRUE; |
| 3127 | } |
| 3128 | #endif |
| 3129 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3130 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3131 | col = 0; |
| 3132 | #ifdef FEAT_RIGHTLEFT |
| 3133 | if (wp->w_p_rl) |
| 3134 | { |
| 3135 | /* Rightleft window: process the text in the normal direction, but put |
| 3136 | * it in current_ScreenLine[] from right to left. Start at the |
| 3137 | * rightmost column of the window. */ |
| 3138 | col = W_WIDTH(wp) - 1; |
| 3139 | off += col; |
| 3140 | } |
| 3141 | #endif |
| 3142 | |
| 3143 | /* |
| 3144 | * Repeat for the whole displayed line. |
| 3145 | */ |
| 3146 | for (;;) |
| 3147 | { |
| 3148 | /* Skip this quickly when working on the text. */ |
| 3149 | if (draw_state != WL_LINE) |
| 3150 | { |
| 3151 | #ifdef FEAT_CMDWIN |
| 3152 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3153 | { |
| 3154 | draw_state = WL_CMDLINE; |
| 3155 | if (cmdwin_type != 0 && wp == curwin) |
| 3156 | { |
| 3157 | /* Draw the cmdline character. */ |
| 3158 | *extra = cmdwin_type; |
| 3159 | n_extra = 1; |
| 3160 | p_extra = extra; |
| 3161 | c_extra = NUL; |
| 3162 | char_attr = hl_attr(HLF_AT); |
| 3163 | } |
| 3164 | } |
| 3165 | #endif |
| 3166 | |
| 3167 | #ifdef FEAT_FOLDING |
| 3168 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3169 | { |
| 3170 | draw_state = WL_FOLD; |
| 3171 | if (wp->w_p_fdc > 0) |
| 3172 | { |
| 3173 | /* Draw the 'foldcolumn'. */ |
| 3174 | fill_foldcolumn(extra, wp, FALSE, lnum); |
| 3175 | n_extra = wp->w_p_fdc; |
| 3176 | p_extra = extra; |
| 3177 | c_extra = NUL; |
| 3178 | char_attr = hl_attr(HLF_FC); |
| 3179 | } |
| 3180 | } |
| 3181 | #endif |
| 3182 | |
| 3183 | #ifdef FEAT_SIGNS |
| 3184 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3185 | { |
| 3186 | draw_state = WL_SIGN; |
| 3187 | /* Show the sign column when there are any signs in this |
| 3188 | * buffer or when using Netbeans. */ |
| 3189 | if (draw_signcolumn(wp) |
| 3190 | # ifdef FEAT_DIFF |
| 3191 | && filler_todo <= 0 |
| 3192 | # endif |
| 3193 | ) |
| 3194 | { |
| 3195 | int_u text_sign; |
| 3196 | # ifdef FEAT_SIGN_ICONS |
| 3197 | int_u icon_sign; |
| 3198 | # endif |
| 3199 | |
| 3200 | /* Draw two cells with the sign value or blank. */ |
| 3201 | c_extra = ' '; |
| 3202 | char_attr = hl_attr(HLF_SC); |
| 3203 | n_extra = 2; |
| 3204 | |
| 3205 | if (row == startrow) |
| 3206 | { |
| 3207 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3208 | SIGN_TEXT); |
| 3209 | # ifdef FEAT_SIGN_ICONS |
| 3210 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3211 | SIGN_ICON); |
| 3212 | if (gui.in_use && icon_sign != 0) |
| 3213 | { |
| 3214 | /* Use the image in this position. */ |
| 3215 | c_extra = SIGN_BYTE; |
| 3216 | # ifdef FEAT_NETBEANS_INTG |
| 3217 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3218 | c_extra = MULTISIGN_BYTE; |
| 3219 | # endif |
| 3220 | char_attr = icon_sign; |
| 3221 | } |
| 3222 | else |
| 3223 | # endif |
| 3224 | if (text_sign != 0) |
| 3225 | { |
| 3226 | p_extra = sign_get_text(text_sign); |
| 3227 | if (p_extra != NULL) |
| 3228 | { |
| 3229 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3230 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3231 | } |
| 3232 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3233 | } |
| 3234 | } |
| 3235 | } |
| 3236 | } |
| 3237 | #endif |
| 3238 | |
| 3239 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3240 | { |
| 3241 | draw_state = WL_NR; |
| 3242 | /* Display the line number. After the first fill with blanks |
| 3243 | * when the 'n' flag isn't in 'cpo' */ |
| 3244 | if (wp->w_p_nu |
| 3245 | && (row == startrow |
| 3246 | #ifdef FEAT_DIFF |
| 3247 | + filler_lines |
| 3248 | #endif |
| 3249 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3250 | { |
| 3251 | /* Draw the line number (empty space after wrapping). */ |
| 3252 | if (row == startrow |
| 3253 | #ifdef FEAT_DIFF |
| 3254 | + filler_lines |
| 3255 | #endif |
| 3256 | ) |
| 3257 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3258 | sprintf((char *)extra, "%*ld ", |
| 3259 | number_width(wp), (long)lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3260 | if (wp->w_skipcol > 0) |
| 3261 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3262 | *p_extra = '-'; |
| 3263 | #ifdef FEAT_RIGHTLEFT |
| 3264 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3265 | rl_mirror(extra); |
| 3266 | #endif |
| 3267 | p_extra = extra; |
| 3268 | c_extra = NUL; |
| 3269 | } |
| 3270 | else |
| 3271 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3272 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3273 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3274 | #ifdef FEAT_SYN_HL |
| 3275 | /* When 'cursorline' is set highlight the line number of |
| 3276 | * the current line differently. */ |
| 3277 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3278 | char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); |
| 3279 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3284 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3285 | { |
| 3286 | draw_state = WL_SBR; |
| 3287 | # ifdef FEAT_DIFF |
| 3288 | if (filler_todo > 0) |
| 3289 | { |
| 3290 | /* Draw "deleted" diff line(s). */ |
| 3291 | if (char2cells(fill_diff) > 1) |
| 3292 | c_extra = '-'; |
| 3293 | else |
| 3294 | c_extra = fill_diff; |
| 3295 | # ifdef FEAT_RIGHTLEFT |
| 3296 | if (wp->w_p_rl) |
| 3297 | n_extra = col + 1; |
| 3298 | else |
| 3299 | # endif |
| 3300 | n_extra = W_WIDTH(wp) - col; |
| 3301 | char_attr = hl_attr(HLF_DED); |
| 3302 | } |
| 3303 | # endif |
| 3304 | # ifdef FEAT_LINEBREAK |
| 3305 | if (*p_sbr != NUL && need_showbreak) |
| 3306 | { |
| 3307 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3308 | p_extra = p_sbr; |
| 3309 | c_extra = NUL; |
| 3310 | n_extra = (int)STRLEN(p_sbr); |
| 3311 | char_attr = hl_attr(HLF_AT); |
| 3312 | need_showbreak = FALSE; |
| 3313 | /* Correct end of highlighted area for 'showbreak', |
| 3314 | * required when 'linebreak' is also set. */ |
| 3315 | if (tocol == vcol) |
| 3316 | tocol += n_extra; |
| 3317 | } |
| 3318 | # endif |
| 3319 | } |
| 3320 | #endif |
| 3321 | |
| 3322 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3323 | { |
| 3324 | draw_state = WL_LINE; |
| 3325 | if (saved_n_extra) |
| 3326 | { |
| 3327 | /* Continue item from end of wrapped line. */ |
| 3328 | n_extra = saved_n_extra; |
| 3329 | c_extra = saved_c_extra; |
| 3330 | p_extra = saved_p_extra; |
| 3331 | char_attr = saved_char_attr; |
| 3332 | } |
| 3333 | else |
| 3334 | char_attr = 0; |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3339 | if (dollar_vcol != 0 && wp == curwin |
| 3340 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3341 | #ifdef FEAT_DIFF |
| 3342 | && filler_todo <= 0 |
| 3343 | #endif |
| 3344 | ) |
| 3345 | { |
| 3346 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3347 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3348 | /* Pretend we have finished updating the window. Except when |
| 3349 | * 'cursorcolumn' is set. */ |
| 3350 | #ifdef FEAT_SYN_HL |
| 3351 | if (wp->w_p_cuc) |
| 3352 | row = wp->w_cline_row + wp->w_cline_height; |
| 3353 | else |
| 3354 | #endif |
| 3355 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3356 | break; |
| 3357 | } |
| 3358 | |
| 3359 | if (draw_state == WL_LINE && area_highlighting) |
| 3360 | { |
| 3361 | /* handle Visual or match highlighting in this line */ |
| 3362 | if (vcol == fromcol |
| 3363 | #ifdef FEAT_MBYTE |
| 3364 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3365 | && (*mb_ptr2cells)(ptr) > 1) |
| 3366 | #endif |
| 3367 | || ((int)vcol_prev == fromcol_prev |
| 3368 | && vcol < tocol)) |
| 3369 | area_attr = attr; /* start highlighting */ |
| 3370 | else if (area_attr != 0 |
| 3371 | && (vcol == tocol |
| 3372 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3373 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3374 | |
| 3375 | #ifdef FEAT_SEARCH_EXTRA |
| 3376 | if (!n_extra) |
| 3377 | { |
| 3378 | /* |
| 3379 | * Check for start/end of search pattern match. |
| 3380 | * After end, check for start/end of next match. |
| 3381 | * When another match, have to check for start again. |
| 3382 | * Watch out for matching an empty string! |
| 3383 | * Do this first for search_hl, then for match_hl, so that |
| 3384 | * ":match" overrules 'hlsearch'. |
| 3385 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3386 | v = (long)(ptr - line); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3387 | for (i = 3; i >= 0; --i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3388 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3389 | shl = (i == 3) ? &search_hl : &match_hl[i]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3390 | while (shl->rm.regprog != NULL) |
| 3391 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3392 | if (shl->startcol != MAXCOL |
| 3393 | && v >= (long)shl->startcol |
| 3394 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3395 | { |
| 3396 | shl->attr_cur = shl->attr; |
| 3397 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3398 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3399 | { |
| 3400 | shl->attr_cur = 0; |
| 3401 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3402 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3403 | |
| 3404 | /* Need to get the line again, a multi-line regexp |
| 3405 | * may have made it invalid. */ |
| 3406 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3407 | ptr = line + v; |
| 3408 | |
| 3409 | if (shl->lnum == lnum) |
| 3410 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3411 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3412 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3413 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3414 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3415 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3416 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3417 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3418 | { |
| 3419 | /* highlight empty match, try again after |
| 3420 | * it */ |
| 3421 | #ifdef FEAT_MBYTE |
| 3422 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3423 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3424 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3425 | else |
| 3426 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3427 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | /* Loop to check if the match starts at the |
| 3431 | * current position */ |
| 3432 | continue; |
| 3433 | } |
| 3434 | } |
| 3435 | break; |
| 3436 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3437 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3438 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3439 | /* ":match" highlighting overrules 'hlsearch' */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3440 | for (i = 0; i <= 3; ++i) |
| 3441 | if (i == 3) |
| 3442 | search_attr = search_hl.attr_cur; |
| 3443 | else if (match_hl[i].attr_cur != 0) |
| 3444 | { |
| 3445 | search_attr = match_hl[i].attr_cur; |
| 3446 | break; |
| 3447 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3448 | } |
| 3449 | #endif |
| 3450 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3451 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3452 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3453 | { |
| 3454 | if (diff_hlf == HLF_CHD && ptr - line >= change_start) |
| 3455 | diff_hlf = HLF_TXD; /* changed text */ |
| 3456 | if (diff_hlf == HLF_TXD && ptr - line > change_end) |
| 3457 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3458 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3459 | } |
| 3460 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3461 | |
| 3462 | /* Decide which of the highlight attributes to use. */ |
| 3463 | attr_pri = TRUE; |
| 3464 | if (area_attr != 0) |
| 3465 | char_attr = area_attr; |
| 3466 | else if (search_attr != 0) |
| 3467 | char_attr = search_attr; |
| 3468 | #ifdef LINE_ATTR |
| 3469 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 3470 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 3471 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
| 3472 | || (vcol < fromcol || vcol >= tocol))) |
| 3473 | char_attr = line_attr; |
| 3474 | #endif |
| 3475 | else |
| 3476 | { |
| 3477 | attr_pri = FALSE; |
| 3478 | #ifdef FEAT_SYN_HL |
| 3479 | if (has_syntax) |
| 3480 | char_attr = syntax_attr; |
| 3481 | else |
| 3482 | #endif |
| 3483 | char_attr = 0; |
| 3484 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | /* |
| 3488 | * Get the next character to put on the screen. |
| 3489 | */ |
| 3490 | /* |
| 3491 | * The 'extra' array contains the extra stuff that is inserted to |
| 3492 | * represent special characters (non-printable stuff). When all |
| 3493 | * characters are the same, c_extra is used. |
| 3494 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 3495 | */ |
| 3496 | if (n_extra > 0) |
| 3497 | { |
| 3498 | if (c_extra != NUL) |
| 3499 | { |
| 3500 | c = c_extra; |
| 3501 | #ifdef FEAT_MBYTE |
| 3502 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 3503 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3504 | { |
| 3505 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3506 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3507 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3508 | } |
| 3509 | else |
| 3510 | mb_utf8 = FALSE; |
| 3511 | #endif |
| 3512 | } |
| 3513 | else |
| 3514 | { |
| 3515 | c = *p_extra; |
| 3516 | #ifdef FEAT_MBYTE |
| 3517 | if (has_mbyte) |
| 3518 | { |
| 3519 | mb_c = c; |
| 3520 | if (enc_utf8) |
| 3521 | { |
| 3522 | /* If the UTF-8 character is more than one byte: |
| 3523 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3524 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3525 | mb_utf8 = FALSE; |
| 3526 | if (mb_l > n_extra) |
| 3527 | mb_l = 1; |
| 3528 | else if (mb_l > 1) |
| 3529 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3530 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3531 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3532 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | else |
| 3536 | { |
| 3537 | /* if this is a DBCS character, put it in "mb_c" */ |
| 3538 | mb_l = MB_BYTE2LEN(c); |
| 3539 | if (mb_l >= n_extra) |
| 3540 | mb_l = 1; |
| 3541 | else if (mb_l > 1) |
| 3542 | mb_c = (c << 8) + p_extra[1]; |
| 3543 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3544 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3545 | mb_l = 1; |
| 3546 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3547 | /* If a double-width char doesn't fit display a '>' in the |
| 3548 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3549 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3550 | # ifdef FEAT_RIGHTLEFT |
| 3551 | wp->w_p_rl ? (col <= 0) : |
| 3552 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3553 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3554 | && (*mb_char2cells)(mb_c) == 2) |
| 3555 | { |
| 3556 | c = '>'; |
| 3557 | mb_c = c; |
| 3558 | mb_l = 1; |
| 3559 | mb_utf8 = FALSE; |
| 3560 | multi_attr = hl_attr(HLF_AT); |
| 3561 | /* put the pointer back to output the double-width |
| 3562 | * character at the start of the next line. */ |
| 3563 | ++n_extra; |
| 3564 | --p_extra; |
| 3565 | } |
| 3566 | else |
| 3567 | { |
| 3568 | n_extra -= mb_l - 1; |
| 3569 | p_extra += mb_l - 1; |
| 3570 | } |
| 3571 | } |
| 3572 | #endif |
| 3573 | ++p_extra; |
| 3574 | } |
| 3575 | --n_extra; |
| 3576 | } |
| 3577 | else |
| 3578 | { |
| 3579 | /* |
| 3580 | * Get a character from the line itself. |
| 3581 | */ |
| 3582 | c = *ptr; |
| 3583 | #ifdef FEAT_MBYTE |
| 3584 | if (has_mbyte) |
| 3585 | { |
| 3586 | mb_c = c; |
| 3587 | if (enc_utf8) |
| 3588 | { |
| 3589 | /* If the UTF-8 character is more than one byte: Decode it |
| 3590 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3591 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3592 | mb_utf8 = FALSE; |
| 3593 | if (mb_l > 1) |
| 3594 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3595 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3596 | /* Overlong encoded ASCII or ASCII with composing char |
| 3597 | * is displayed normally, except a NUL. */ |
| 3598 | if (mb_c < 0x80) |
| 3599 | c = mb_c; |
| 3600 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3601 | |
| 3602 | /* At start of the line we can have a composing char. |
| 3603 | * Draw it as a space with a composing char. */ |
| 3604 | if (utf_iscomposing(mb_c)) |
| 3605 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3606 | for (i = Screen_mco - 1; i > 0; --i) |
| 3607 | u8cc[i] = u8cc[i - 1]; |
| 3608 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3609 | mb_c = ' '; |
| 3610 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | if ((mb_l == 1 && c >= 0x80) |
| 3614 | || (mb_l >= 1 && mb_c == 0) |
| 3615 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
| 3616 | || mb_c >= 0x10000))) |
| 3617 | { |
| 3618 | /* |
| 3619 | * Illegal UTF-8 byte: display as <xx>. |
| 3620 | * Non-BMP character : display as ? or fullwidth ?. |
| 3621 | */ |
| 3622 | if (mb_c < 0x10000) |
| 3623 | { |
| 3624 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3625 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3626 | if (wp->w_p_rl) /* reverse */ |
| 3627 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3628 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3629 | } |
| 3630 | else if (utf_char2cells(mb_c) != 2) |
| 3631 | STRCPY(extra, "?"); |
| 3632 | else |
| 3633 | /* 0xff1f in UTF-8: full-width '?' */ |
| 3634 | STRCPY(extra, "\357\274\237"); |
| 3635 | |
| 3636 | p_extra = extra; |
| 3637 | c = *p_extra; |
| 3638 | mb_c = mb_ptr2char_adv(&p_extra); |
| 3639 | mb_utf8 = (c >= 0x80); |
| 3640 | n_extra = (int)STRLEN(p_extra); |
| 3641 | c_extra = NUL; |
| 3642 | if (area_attr == 0 && search_attr == 0) |
| 3643 | { |
| 3644 | n_attr = n_extra + 1; |
| 3645 | extra_attr = hl_attr(HLF_8); |
| 3646 | saved_attr2 = char_attr; /* save current attr */ |
| 3647 | } |
| 3648 | } |
| 3649 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3650 | mb_l = 1; |
| 3651 | #ifdef FEAT_ARABIC |
| 3652 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 3653 | { |
| 3654 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3655 | int pc, pc1, nc; |
| 3656 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3657 | |
| 3658 | /* The idea of what is the previous and next |
| 3659 | * character depends on 'rightleft'. */ |
| 3660 | if (wp->w_p_rl) |
| 3661 | { |
| 3662 | pc = prev_c; |
| 3663 | pc1 = prev_c1; |
| 3664 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3665 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3666 | } |
| 3667 | else |
| 3668 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3669 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3670 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3671 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3672 | } |
| 3673 | prev_c = mb_c; |
| 3674 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3675 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3676 | } |
| 3677 | else |
| 3678 | prev_c = mb_c; |
| 3679 | #endif |
| 3680 | } |
| 3681 | else /* enc_dbcs */ |
| 3682 | { |
| 3683 | mb_l = MB_BYTE2LEN(c); |
| 3684 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3685 | mb_l = 1; |
| 3686 | else if (mb_l > 1) |
| 3687 | { |
| 3688 | /* We assume a second byte below 32 is illegal. |
| 3689 | * Hopefully this is OK for all double-byte encodings! |
| 3690 | */ |
| 3691 | if (ptr[1] >= 32) |
| 3692 | mb_c = (c << 8) + ptr[1]; |
| 3693 | else |
| 3694 | { |
| 3695 | if (ptr[1] == NUL) |
| 3696 | { |
| 3697 | /* head byte at end of line */ |
| 3698 | mb_l = 1; |
| 3699 | transchar_nonprint(extra, c); |
| 3700 | } |
| 3701 | else |
| 3702 | { |
| 3703 | /* illegal tail byte */ |
| 3704 | mb_l = 2; |
| 3705 | STRCPY(extra, "XX"); |
| 3706 | } |
| 3707 | p_extra = extra; |
| 3708 | n_extra = (int)STRLEN(extra) - 1; |
| 3709 | c_extra = NUL; |
| 3710 | c = *p_extra++; |
| 3711 | if (area_attr == 0 && search_attr == 0) |
| 3712 | { |
| 3713 | n_attr = n_extra + 1; |
| 3714 | extra_attr = hl_attr(HLF_8); |
| 3715 | saved_attr2 = char_attr; /* save current attr */ |
| 3716 | } |
| 3717 | mb_c = c; |
| 3718 | } |
| 3719 | } |
| 3720 | } |
| 3721 | /* If a double-width char doesn't fit display a '>' in the |
| 3722 | * last column; the character is displayed at the start of the |
| 3723 | * next line. */ |
| 3724 | if (( |
| 3725 | # ifdef FEAT_RIGHTLEFT |
| 3726 | wp->w_p_rl ? (col <= 0) : |
| 3727 | # endif |
| 3728 | (col >= W_WIDTH(wp) - 1)) |
| 3729 | && (*mb_char2cells)(mb_c) == 2) |
| 3730 | { |
| 3731 | c = '>'; |
| 3732 | mb_c = c; |
| 3733 | mb_utf8 = FALSE; |
| 3734 | mb_l = 1; |
| 3735 | multi_attr = hl_attr(HLF_AT); |
| 3736 | /* Put pointer back so that the character will be |
| 3737 | * displayed at the start of the next line. */ |
| 3738 | --ptr; |
| 3739 | } |
| 3740 | else if (*ptr != NUL) |
| 3741 | ptr += mb_l - 1; |
| 3742 | |
| 3743 | /* If a double-width char doesn't fit at the left side display |
| 3744 | * a '<' in the first column. */ |
| 3745 | if (n_skip > 0 && mb_l > 1) |
| 3746 | { |
| 3747 | extra[0] = '<'; |
| 3748 | p_extra = extra; |
| 3749 | n_extra = 1; |
| 3750 | c_extra = NUL; |
| 3751 | c = ' '; |
| 3752 | if (area_attr == 0 && search_attr == 0) |
| 3753 | { |
| 3754 | n_attr = n_extra + 1; |
| 3755 | extra_attr = hl_attr(HLF_AT); |
| 3756 | saved_attr2 = char_attr; /* save current attr */ |
| 3757 | } |
| 3758 | mb_c = c; |
| 3759 | mb_utf8 = FALSE; |
| 3760 | mb_l = 1; |
| 3761 | } |
| 3762 | |
| 3763 | } |
| 3764 | #endif |
| 3765 | ++ptr; |
| 3766 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3767 | /* 'list' : change char 160 to lcs_nbsp. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3768 | if (wp->w_p_list && (c == 160 |
| 3769 | #ifdef FEAT_MBYTE |
| 3770 | || (mb_utf8 && mb_c == 160) |
| 3771 | #endif |
| 3772 | ) && lcs_nbsp) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3773 | { |
| 3774 | c = lcs_nbsp; |
| 3775 | if (area_attr == 0 && search_attr == 0) |
| 3776 | { |
| 3777 | n_attr = 1; |
| 3778 | extra_attr = hl_attr(HLF_8); |
| 3779 | saved_attr2 = char_attr; /* save current attr */ |
| 3780 | } |
| 3781 | #ifdef FEAT_MBYTE |
| 3782 | mb_c = c; |
| 3783 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3784 | { |
| 3785 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3786 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3787 | c = 0xc0; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3788 | } |
| 3789 | else |
| 3790 | mb_utf8 = FALSE; |
| 3791 | #endif |
| 3792 | } |
| 3793 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3794 | if (extra_check) |
| 3795 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3796 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3797 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3798 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3799 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3800 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3801 | /* Get syntax attribute, unless still at the start of the line |
| 3802 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3803 | v = (long)(ptr - line); |
| 3804 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3805 | { |
| 3806 | /* Get the syntax attribute for the character. If there |
| 3807 | * is an error, disable syntax highlighting. */ |
| 3808 | save_did_emsg = did_emsg; |
| 3809 | did_emsg = FALSE; |
| 3810 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3811 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3812 | # ifdef FEAT_SPELL |
| 3813 | has_spell ? &can_spell : |
| 3814 | # endif |
| 3815 | NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3816 | |
| 3817 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 3818 | { |
| 3819 | wp->w_buffer->b_syn_error = TRUE; |
| 3820 | has_syntax = FALSE; |
| 3821 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3822 | else |
| 3823 | did_emsg = save_did_emsg; |
| 3824 | |
| 3825 | /* Need to get the line again, a multi-line regexp may |
| 3826 | * have made it invalid. */ |
| 3827 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3828 | ptr = line + v; |
| 3829 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3830 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3831 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3832 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 3833 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3834 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3835 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3836 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3837 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3838 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 3839 | * Only do this when there is no syntax highlighting, the |
| 3840 | * @Spell cluster is not used or the current syntax item |
| 3841 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3842 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3843 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 3844 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3845 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3846 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 3847 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3848 | # endif |
| 3849 | if (c != 0 && ( |
| 3850 | # ifdef FEAT_SYN_HL |
| 3851 | !has_syntax || |
| 3852 | # endif |
| 3853 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3854 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3855 | char_u *prev_ptr, *p; |
| 3856 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3857 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3858 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 3859 | if (has_mbyte) |
| 3860 | { |
| 3861 | prev_ptr = ptr - mb_l; |
| 3862 | v -= mb_l - 1; |
| 3863 | } |
| 3864 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3865 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 3866 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3867 | |
| 3868 | /* Use nextline[] if possible, it has the start of the |
| 3869 | * next line concatenated. */ |
| 3870 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 3871 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 3872 | else |
| 3873 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3874 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 3875 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 3876 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3877 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3878 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3879 | /* In Insert mode only highlight a word that |
| 3880 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3881 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3882 | && (State & INSERT) != 0 |
| 3883 | && wp->w_cursor.lnum == lnum |
| 3884 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3885 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3886 | && wp->w_cursor.col < (colnr_T)word_end) |
| 3887 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3888 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 3889 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3890 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3891 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3892 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3893 | && (p - nextline) + len > nextline_idx) |
| 3894 | { |
| 3895 | /* Remember that the good word continues at the |
| 3896 | * start of the next line. */ |
| 3897 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3898 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3899 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3900 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3901 | /* Turn index into actual attributes. */ |
| 3902 | if (spell_hlf != HLF_COUNT) |
| 3903 | spell_attr = highlight_attr[spell_hlf]; |
| 3904 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3905 | if (cap_col > 0) |
| 3906 | { |
| 3907 | if (p != prev_ptr |
| 3908 | && (p - nextline) + cap_col >= nextline_idx) |
| 3909 | { |
| 3910 | /* Remember that the word in the next line |
| 3911 | * must start with a capital. */ |
| 3912 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3913 | cap_col = (int)((p - nextline) + cap_col |
| 3914 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3915 | } |
| 3916 | else |
| 3917 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3918 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3919 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3920 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3921 | } |
| 3922 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3923 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3924 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3925 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 3926 | else |
| 3927 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 3928 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3929 | #endif |
| 3930 | #ifdef FEAT_LINEBREAK |
| 3931 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3932 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3933 | */ |
| 3934 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3935 | && !wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3936 | { |
| 3937 | n_extra = win_lbr_chartabsize(wp, ptr - ( |
| 3938 | # ifdef FEAT_MBYTE |
| 3939 | has_mbyte ? mb_l : |
| 3940 | # endif |
| 3941 | 1), (colnr_T)vcol, NULL) - 1; |
| 3942 | c_extra = ' '; |
| 3943 | if (vim_iswhite(c)) |
| 3944 | c = ' '; |
| 3945 | } |
| 3946 | #endif |
| 3947 | |
| 3948 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 3949 | { |
| 3950 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3951 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3952 | { |
| 3953 | n_attr = 1; |
| 3954 | extra_attr = hl_attr(HLF_8); |
| 3955 | saved_attr2 = char_attr; /* save current attr */ |
| 3956 | } |
| 3957 | #ifdef FEAT_MBYTE |
| 3958 | mb_c = c; |
| 3959 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3960 | { |
| 3961 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3962 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3963 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3964 | } |
| 3965 | else |
| 3966 | mb_utf8 = FALSE; |
| 3967 | #endif |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | /* |
| 3972 | * Handling of non-printable characters. |
| 3973 | */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3974 | if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3975 | { |
| 3976 | /* |
| 3977 | * when getting a character from the file, we may have to |
| 3978 | * turn it into something else on the way to putting it |
| 3979 | * into "ScreenLines". |
| 3980 | */ |
| 3981 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 3982 | { |
| 3983 | /* tab amount depends on current column */ |
| 3984 | n_extra = (int)wp->w_buffer->b_p_ts |
| 3985 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 3986 | #ifdef FEAT_MBYTE |
| 3987 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 3988 | #endif |
| 3989 | if (wp->w_p_list) |
| 3990 | { |
| 3991 | c = lcs_tab1; |
| 3992 | c_extra = lcs_tab2; |
| 3993 | n_attr = n_extra + 1; |
| 3994 | extra_attr = hl_attr(HLF_8); |
| 3995 | saved_attr2 = char_attr; /* save current attr */ |
| 3996 | #ifdef FEAT_MBYTE |
| 3997 | mb_c = c; |
| 3998 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3999 | { |
| 4000 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4001 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4002 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4003 | } |
| 4004 | #endif |
| 4005 | } |
| 4006 | else |
| 4007 | { |
| 4008 | c_extra = ' '; |
| 4009 | c = ' '; |
| 4010 | } |
| 4011 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4012 | else if (c == NUL |
| 4013 | && ((wp->w_p_list && lcs_eol > 0) |
| 4014 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4015 | && tocol > vcol |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4016 | #ifdef FEAT_VISUAL |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4017 | && VIsual_mode != Ctrl_V |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4018 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4019 | && ( |
| 4020 | # ifdef FEAT_RIGHTLEFT |
| 4021 | wp->w_p_rl ? (col >= 0) : |
| 4022 | # endif |
| 4023 | (col < W_WIDTH(wp))) |
| 4024 | && !(noinvcur |
| 4025 | && (colnr_T)vcol == wp->w_virtcol))) |
| 4026 | && lcs_eol_one >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4027 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4028 | /* Display a '$' after the line or highlight an extra |
| 4029 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4030 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4031 | /* For a diff line the highlighting continues after the |
| 4032 | * "$". */ |
| 4033 | if ( |
| 4034 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4035 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4036 | # ifdef LINE_ATTR |
| 4037 | && |
| 4038 | # endif |
| 4039 | # endif |
| 4040 | # ifdef LINE_ATTR |
| 4041 | line_attr == 0 |
| 4042 | # endif |
| 4043 | ) |
| 4044 | #endif |
| 4045 | { |
| 4046 | #ifdef FEAT_VIRTUALEDIT |
| 4047 | /* In virtualedit, visual selections may extend |
| 4048 | * beyond end of line. */ |
| 4049 | if (area_highlighting && virtual_active() |
| 4050 | && tocol != MAXCOL && vcol < tocol) |
| 4051 | n_extra = 0; |
| 4052 | else |
| 4053 | #endif |
| 4054 | { |
| 4055 | p_extra = at_end_str; |
| 4056 | n_extra = 1; |
| 4057 | c_extra = NUL; |
| 4058 | } |
| 4059 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4060 | if (wp->w_p_list) |
| 4061 | c = lcs_eol; |
| 4062 | else |
| 4063 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4064 | lcs_eol_one = -1; |
| 4065 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4066 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4067 | { |
| 4068 | extra_attr = hl_attr(HLF_AT); |
| 4069 | n_attr = 1; |
| 4070 | } |
| 4071 | #ifdef FEAT_MBYTE |
| 4072 | mb_c = c; |
| 4073 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4074 | { |
| 4075 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4076 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4077 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4078 | } |
| 4079 | else |
| 4080 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4081 | #endif |
| 4082 | } |
| 4083 | else if (c != NUL) |
| 4084 | { |
| 4085 | p_extra = transchar(c); |
| 4086 | #ifdef FEAT_RIGHTLEFT |
| 4087 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4088 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4089 | #endif |
| 4090 | n_extra = byte2cells(c) - 1; |
| 4091 | c_extra = NUL; |
| 4092 | c = *p_extra++; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4093 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4094 | { |
| 4095 | n_attr = n_extra + 1; |
| 4096 | extra_attr = hl_attr(HLF_8); |
| 4097 | saved_attr2 = char_attr; /* save current attr */ |
| 4098 | } |
| 4099 | #ifdef FEAT_MBYTE |
| 4100 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4101 | #endif |
| 4102 | } |
| 4103 | #ifdef FEAT_VIRTUALEDIT |
| 4104 | else if (VIsual_active |
| 4105 | && (VIsual_mode == Ctrl_V |
| 4106 | || VIsual_mode == 'v') |
| 4107 | && virtual_active() |
| 4108 | && tocol != MAXCOL |
| 4109 | && vcol < tocol |
| 4110 | && ( |
| 4111 | # ifdef FEAT_RIGHTLEFT |
| 4112 | wp->w_p_rl ? (col >= 0) : |
| 4113 | # endif |
| 4114 | (col < W_WIDTH(wp)))) |
| 4115 | { |
| 4116 | c = ' '; |
| 4117 | --ptr; /* put it back at the NUL */ |
| 4118 | } |
| 4119 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame^] | 4120 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4121 | else if (( |
| 4122 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame^] | 4123 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4124 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4125 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4126 | ) && ( |
| 4127 | # ifdef FEAT_RIGHTLEFT |
| 4128 | wp->w_p_rl ? (col >= 0) : |
| 4129 | # endif |
| 4130 | (col < W_WIDTH(wp)))) |
| 4131 | { |
| 4132 | /* Highlight until the right side of the window */ |
| 4133 | c = ' '; |
| 4134 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4135 | |
| 4136 | /* Remember we do the char for line highlighting. */ |
| 4137 | ++did_line_attr; |
| 4138 | |
| 4139 | /* don't do search HL for the rest of the line */ |
| 4140 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4141 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4142 | # ifdef FEAT_DIFF |
| 4143 | if (diff_hlf == HLF_TXD) |
| 4144 | { |
| 4145 | diff_hlf = HLF_CHD; |
| 4146 | if (attr == 0 || char_attr != attr) |
| 4147 | char_attr = hl_attr(diff_hlf); |
| 4148 | } |
| 4149 | # endif |
| 4150 | } |
| 4151 | #endif |
| 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | /* Don't override visual selection highlighting. */ |
| 4156 | if (n_attr > 0 |
| 4157 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4158 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4159 | char_attr = extra_attr; |
| 4160 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4161 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4162 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4163 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4164 | * im_is_preediting() here. */ |
| 4165 | if (xic != NULL |
| 4166 | && lnum == curwin->w_cursor.lnum |
| 4167 | && (State & INSERT) |
| 4168 | && !p_imdisable |
| 4169 | && im_is_preediting() |
| 4170 | && draw_state == WL_LINE) |
| 4171 | { |
| 4172 | colnr_T tcol; |
| 4173 | |
| 4174 | if (preedit_end_col == MAXCOL) |
| 4175 | getvcol(curwin, &(curwin->w_cursor), &tcol, NULL, NULL); |
| 4176 | else |
| 4177 | tcol = preedit_end_col; |
| 4178 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 4179 | { |
| 4180 | if (feedback_old_attr < 0) |
| 4181 | { |
| 4182 | feedback_col = 0; |
| 4183 | feedback_old_attr = char_attr; |
| 4184 | } |
| 4185 | char_attr = im_get_feedback_attr(feedback_col); |
| 4186 | if (char_attr < 0) |
| 4187 | char_attr = feedback_old_attr; |
| 4188 | feedback_col++; |
| 4189 | } |
| 4190 | else if (feedback_old_attr >= 0) |
| 4191 | { |
| 4192 | char_attr = feedback_old_attr; |
| 4193 | feedback_old_attr = -1; |
| 4194 | feedback_col = 0; |
| 4195 | } |
| 4196 | } |
| 4197 | #endif |
| 4198 | /* |
| 4199 | * Handle the case where we are in column 0 but not on the first |
| 4200 | * character of the line and the user wants us to show us a |
| 4201 | * special character (via 'listchars' option "precedes:<char>". |
| 4202 | */ |
| 4203 | if (lcs_prec_todo != NUL |
| 4204 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 4205 | #ifdef FEAT_DIFF |
| 4206 | && filler_todo <= 0 |
| 4207 | #endif |
| 4208 | && draw_state > WL_NR |
| 4209 | && c != NUL) |
| 4210 | { |
| 4211 | c = lcs_prec; |
| 4212 | lcs_prec_todo = NUL; |
| 4213 | #ifdef FEAT_MBYTE |
| 4214 | mb_c = c; |
| 4215 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4216 | { |
| 4217 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4218 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4219 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4220 | } |
| 4221 | else |
| 4222 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4223 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4224 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4225 | { |
| 4226 | saved_attr3 = char_attr; /* save current attr */ |
| 4227 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 4228 | n_attr3 = 1; |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4233 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4234 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4235 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame^] | 4236 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4237 | || did_line_attr == 1 |
| 4238 | #endif |
| 4239 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4240 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4241 | #ifdef FEAT_SEARCH_EXTRA |
| 4242 | long prevcol = (long)(ptr - line) - (c == NUL); |
| 4243 | #endif |
| 4244 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4245 | /* invert at least one char, used for Visual and empty line or |
| 4246 | * highlight match at end of line. If it's beyond the last |
| 4247 | * char on the screen, just overwrite that one (tricky!) Not |
| 4248 | * needed when a '$' was displayed for 'list'. */ |
| 4249 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4250 | && ((area_attr != 0 && vcol == fromcol && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4251 | #ifdef FEAT_SEARCH_EXTRA |
| 4252 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4253 | || ((prevcol == (long)search_hl.startcol |
| 4254 | || prevcol == (long)match_hl[0].startcol |
| 4255 | || prevcol == (long)match_hl[1].startcol |
| 4256 | || prevcol == (long)match_hl[2].startcol) |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame^] | 4257 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4258 | && did_line_attr <= 1 |
| 4259 | # endif |
| 4260 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4261 | #endif |
| 4262 | )) |
| 4263 | { |
| 4264 | int n = 0; |
| 4265 | |
| 4266 | #ifdef FEAT_RIGHTLEFT |
| 4267 | if (wp->w_p_rl) |
| 4268 | { |
| 4269 | if (col < 0) |
| 4270 | n = 1; |
| 4271 | } |
| 4272 | else |
| 4273 | #endif |
| 4274 | { |
| 4275 | if (col >= W_WIDTH(wp)) |
| 4276 | n = -1; |
| 4277 | } |
| 4278 | if (n != 0) |
| 4279 | { |
| 4280 | /* At the window boundary, highlight the last character |
| 4281 | * instead (better than nothing). */ |
| 4282 | off += n; |
| 4283 | col += n; |
| 4284 | } |
| 4285 | else |
| 4286 | { |
| 4287 | /* Add a blank character to highlight. */ |
| 4288 | ScreenLines[off] = ' '; |
| 4289 | #ifdef FEAT_MBYTE |
| 4290 | if (enc_utf8) |
| 4291 | ScreenLinesUC[off] = 0; |
| 4292 | #endif |
| 4293 | } |
| 4294 | #ifdef FEAT_SEARCH_EXTRA |
| 4295 | if (area_attr == 0) |
| 4296 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4297 | for (i = 0; i <= 3; ++i) |
| 4298 | { |
| 4299 | if (i == 3) |
| 4300 | char_attr = search_hl.attr; |
| 4301 | else if ((ptr - line) - 1 == (long)match_hl[i].startcol) |
| 4302 | { |
| 4303 | char_attr = match_hl[i].attr; |
| 4304 | break; |
| 4305 | } |
| 4306 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4307 | } |
| 4308 | #endif |
| 4309 | ScreenAttrs[off] = char_attr; |
| 4310 | #ifdef FEAT_RIGHTLEFT |
| 4311 | if (wp->w_p_rl) |
| 4312 | --col; |
| 4313 | else |
| 4314 | #endif |
| 4315 | ++col; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4316 | ++vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4317 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4318 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4319 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4320 | /* |
| 4321 | * At end of the text line. |
| 4322 | */ |
| 4323 | if (c == NUL) |
| 4324 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4325 | #ifdef FEAT_SYN_HL |
| 4326 | /* Highlight 'cursorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 4327 | if (wp->w_p_wrap) |
| 4328 | v = wp->w_skipcol; |
| 4329 | else |
| 4330 | v = wp->w_leftcol; |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4331 | /* check if line ends before left margin */ |
| 4332 | if (vcol < v + col - win_col_off(wp)) |
| 4333 | |
| 4334 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4335 | if (wp->w_p_cuc |
| 4336 | && (int)wp->w_virtcol >= vcol |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4337 | && (int)wp->w_virtcol < W_WIDTH(wp) * (row - startrow + 1) |
| 4338 | + v |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4339 | && lnum != wp->w_cursor.lnum |
| 4340 | # ifdef FEAT_RIGHTLEFT |
| 4341 | && !wp->w_p_rl |
| 4342 | # endif |
| 4343 | ) |
| 4344 | { |
| 4345 | while (col < W_WIDTH(wp)) |
| 4346 | { |
| 4347 | ScreenLines[off] = ' '; |
| 4348 | #ifdef FEAT_MBYTE |
| 4349 | if (enc_utf8) |
| 4350 | ScreenLinesUC[off] = 0; |
| 4351 | #endif |
| 4352 | ++col; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4353 | if (vcol == (long)wp->w_virtcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4354 | { |
| 4355 | ScreenAttrs[off] = hl_attr(HLF_CUC); |
| 4356 | break; |
| 4357 | } |
| 4358 | ScreenAttrs[off++] = 0; |
| 4359 | ++vcol; |
| 4360 | } |
| 4361 | } |
| 4362 | #endif |
| 4363 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4364 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), |
| 4365 | wp->w_p_rl); |
| 4366 | row++; |
| 4367 | |
| 4368 | /* |
| 4369 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 4370 | * updated (saves a call to plines() later). |
| 4371 | */ |
| 4372 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 4373 | { |
| 4374 | curwin->w_cline_row = startrow; |
| 4375 | curwin->w_cline_height = row - startrow; |
| 4376 | #ifdef FEAT_FOLDING |
| 4377 | curwin->w_cline_folded = FALSE; |
| 4378 | #endif |
| 4379 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 4380 | } |
| 4381 | |
| 4382 | break; |
| 4383 | } |
| 4384 | |
| 4385 | /* line continues beyond line end */ |
| 4386 | if (lcs_ext |
| 4387 | && !wp->w_p_wrap |
| 4388 | #ifdef FEAT_DIFF |
| 4389 | && filler_todo <= 0 |
| 4390 | #endif |
| 4391 | && ( |
| 4392 | #ifdef FEAT_RIGHTLEFT |
| 4393 | wp->w_p_rl ? col == 0 : |
| 4394 | #endif |
| 4395 | col == W_WIDTH(wp) - 1) |
| 4396 | && (*ptr != NUL |
| 4397 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
| 4398 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 4399 | { |
| 4400 | c = lcs_ext; |
| 4401 | char_attr = hl_attr(HLF_AT); |
| 4402 | #ifdef FEAT_MBYTE |
| 4403 | mb_c = c; |
| 4404 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4405 | { |
| 4406 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4407 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4408 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4409 | } |
| 4410 | else |
| 4411 | mb_utf8 = FALSE; |
| 4412 | #endif |
| 4413 | } |
| 4414 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4415 | #ifdef FEAT_SYN_HL |
| 4416 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
| 4417 | * highlight the cursor position itself. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4418 | if (wp->w_p_cuc && vcol == (long)wp->w_virtcol |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4419 | && lnum != wp->w_cursor.lnum |
| 4420 | && draw_state == WL_LINE) |
| 4421 | { |
| 4422 | vcol_save_attr = char_attr; |
| 4423 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 4424 | } |
| 4425 | else |
| 4426 | vcol_save_attr = -1; |
| 4427 | #endif |
| 4428 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4429 | /* |
| 4430 | * Store character to be displayed. |
| 4431 | * Skip characters that are left of the screen for 'nowrap'. |
| 4432 | */ |
| 4433 | vcol_prev = vcol; |
| 4434 | if (draw_state < WL_LINE || n_skip <= 0) |
| 4435 | { |
| 4436 | /* |
| 4437 | * Store the character. |
| 4438 | */ |
| 4439 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 4440 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 4441 | { |
| 4442 | /* A double-wide character is: put first halve in left cell. */ |
| 4443 | --off; |
| 4444 | --col; |
| 4445 | } |
| 4446 | #endif |
| 4447 | ScreenLines[off] = c; |
| 4448 | #ifdef FEAT_MBYTE |
| 4449 | if (enc_dbcs == DBCS_JPNU) |
| 4450 | ScreenLines2[off] = mb_c & 0xff; |
| 4451 | else if (enc_utf8) |
| 4452 | { |
| 4453 | if (mb_utf8) |
| 4454 | { |
| 4455 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4456 | if ((c & 0xff) == 0) |
| 4457 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4458 | for (i = 0; i < Screen_mco; ++i) |
| 4459 | { |
| 4460 | ScreenLinesC[i][off] = u8cc[i]; |
| 4461 | if (u8cc[i] == 0) |
| 4462 | break; |
| 4463 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4464 | } |
| 4465 | else |
| 4466 | ScreenLinesUC[off] = 0; |
| 4467 | } |
| 4468 | if (multi_attr) |
| 4469 | { |
| 4470 | ScreenAttrs[off] = multi_attr; |
| 4471 | multi_attr = 0; |
| 4472 | } |
| 4473 | else |
| 4474 | #endif |
| 4475 | ScreenAttrs[off] = char_attr; |
| 4476 | |
| 4477 | #ifdef FEAT_MBYTE |
| 4478 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4479 | { |
| 4480 | /* Need to fill two screen columns. */ |
| 4481 | ++off; |
| 4482 | ++col; |
| 4483 | if (enc_utf8) |
| 4484 | /* UTF-8: Put a 0 in the second screen char. */ |
| 4485 | ScreenLines[off] = 0; |
| 4486 | else |
| 4487 | /* DBCS: Put second byte in the second screen char. */ |
| 4488 | ScreenLines[off] = mb_c & 0xff; |
| 4489 | ++vcol; |
| 4490 | /* When "tocol" is halfway a character, set it to the end of |
| 4491 | * the character, otherwise highlighting won't stop. */ |
| 4492 | if (tocol == vcol) |
| 4493 | ++tocol; |
| 4494 | #ifdef FEAT_RIGHTLEFT |
| 4495 | if (wp->w_p_rl) |
| 4496 | { |
| 4497 | /* now it's time to backup one cell */ |
| 4498 | --off; |
| 4499 | --col; |
| 4500 | } |
| 4501 | #endif |
| 4502 | } |
| 4503 | #endif |
| 4504 | #ifdef FEAT_RIGHTLEFT |
| 4505 | if (wp->w_p_rl) |
| 4506 | { |
| 4507 | --off; |
| 4508 | --col; |
| 4509 | } |
| 4510 | else |
| 4511 | #endif |
| 4512 | { |
| 4513 | ++off; |
| 4514 | ++col; |
| 4515 | } |
| 4516 | } |
| 4517 | else |
| 4518 | --n_skip; |
| 4519 | |
| 4520 | /* Only advance the "vcol" when after the 'number' column. */ |
| 4521 | if (draw_state >= WL_SBR |
| 4522 | #ifdef FEAT_DIFF |
| 4523 | && filler_todo <= 0 |
| 4524 | #endif |
| 4525 | ) |
| 4526 | ++vcol; |
| 4527 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4528 | #ifdef FEAT_SYN_HL |
| 4529 | if (vcol_save_attr >= 0) |
| 4530 | char_attr = vcol_save_attr; |
| 4531 | #endif |
| 4532 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4533 | /* restore attributes after "predeces" in 'listchars' */ |
| 4534 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 4535 | char_attr = saved_attr3; |
| 4536 | |
| 4537 | /* restore attributes after last 'listchars' or 'number' char */ |
| 4538 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 4539 | char_attr = saved_attr2; |
| 4540 | |
| 4541 | /* |
| 4542 | * At end of screen line and there is more to come: Display the line |
| 4543 | * so far. If there is no more to display it is catched above. |
| 4544 | */ |
| 4545 | if (( |
| 4546 | #ifdef FEAT_RIGHTLEFT |
| 4547 | wp->w_p_rl ? (col < 0) : |
| 4548 | #endif |
| 4549 | (col >= W_WIDTH(wp))) |
| 4550 | && (*ptr != NUL |
| 4551 | #ifdef FEAT_DIFF |
| 4552 | || filler_todo > 0 |
| 4553 | #endif |
| 4554 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
| 4555 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 4556 | ) |
| 4557 | { |
| 4558 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), |
| 4559 | wp->w_p_rl); |
| 4560 | ++row; |
| 4561 | ++screen_row; |
| 4562 | |
| 4563 | /* When not wrapping and finished diff lines, or when displayed |
| 4564 | * '$' and highlighting until last column, break here. */ |
| 4565 | if ((!wp->w_p_wrap |
| 4566 | #ifdef FEAT_DIFF |
| 4567 | && filler_todo <= 0 |
| 4568 | #endif |
| 4569 | ) || lcs_eol_one == -1) |
| 4570 | break; |
| 4571 | |
| 4572 | /* When the window is too narrow draw all "@" lines. */ |
| 4573 | if (draw_state != WL_LINE |
| 4574 | #ifdef FEAT_DIFF |
| 4575 | && filler_todo <= 0 |
| 4576 | #endif |
| 4577 | ) |
| 4578 | { |
| 4579 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 4580 | #ifdef FEAT_VERTSPLIT |
| 4581 | draw_vsep_win(wp, row); |
| 4582 | #endif |
| 4583 | row = endrow; |
| 4584 | } |
| 4585 | |
| 4586 | /* When line got too long for screen break here. */ |
| 4587 | if (row == endrow) |
| 4588 | { |
| 4589 | ++row; |
| 4590 | break; |
| 4591 | } |
| 4592 | |
| 4593 | if (screen_cur_row == screen_row - 1 |
| 4594 | #ifdef FEAT_DIFF |
| 4595 | && filler_todo <= 0 |
| 4596 | #endif |
| 4597 | && W_WIDTH(wp) == Columns) |
| 4598 | { |
| 4599 | /* Remember that the line wraps, used for modeless copy. */ |
| 4600 | LineWraps[screen_row - 1] = TRUE; |
| 4601 | |
| 4602 | /* |
| 4603 | * Special trick to make copy/paste of wrapped lines work with |
| 4604 | * xterm/screen: write an extra character beyond the end of |
| 4605 | * the line. This will work with all terminal types |
| 4606 | * (regardless of the xn,am settings). |
| 4607 | * Only do this on a fast tty. |
| 4608 | * Only do this if the cursor is on the current line |
| 4609 | * (something has been written in it). |
| 4610 | * Don't do this for the GUI. |
| 4611 | * Don't do this for double-width characters. |
| 4612 | * Don't do this for a window not at the right screen border. |
| 4613 | */ |
| 4614 | if (p_tf |
| 4615 | #ifdef FEAT_GUI |
| 4616 | && !gui.in_use |
| 4617 | #endif |
| 4618 | #ifdef FEAT_MBYTE |
| 4619 | && !(has_mbyte |
| 4620 | && ((*mb_off2cells)(LineOffset[screen_row]) == 2 |
| 4621 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
| 4622 | + (int)Columns - 2) == 2)) |
| 4623 | #endif |
| 4624 | ) |
| 4625 | { |
| 4626 | /* First make sure we are at the end of the screen line, |
| 4627 | * then output the same character again to let the |
| 4628 | * terminal know about the wrap. If the terminal doesn't |
| 4629 | * auto-wrap, we overwrite the character. */ |
| 4630 | if (screen_cur_col != W_WIDTH(wp)) |
| 4631 | screen_char(LineOffset[screen_row - 1] |
| 4632 | + (unsigned)Columns - 1, |
| 4633 | screen_row - 1, (int)(Columns - 1)); |
| 4634 | |
| 4635 | #ifdef FEAT_MBYTE |
| 4636 | /* When there is a multi-byte character, just output a |
| 4637 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 4638 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 4639 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4640 | out_char(' '); |
| 4641 | else |
| 4642 | #endif |
| 4643 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 4644 | + (Columns - 1)]); |
| 4645 | /* force a redraw of the first char on the next line */ |
| 4646 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 4647 | screen_start(); /* don't know where cursor is now */ |
| 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | col = 0; |
| 4652 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 4653 | #ifdef FEAT_RIGHTLEFT |
| 4654 | if (wp->w_p_rl) |
| 4655 | { |
| 4656 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 4657 | off += col; |
| 4658 | } |
| 4659 | #endif |
| 4660 | |
| 4661 | /* reset the drawing state for the start of a wrapped line */ |
| 4662 | draw_state = WL_START; |
| 4663 | saved_n_extra = n_extra; |
| 4664 | saved_p_extra = p_extra; |
| 4665 | saved_c_extra = c_extra; |
| 4666 | saved_char_attr = char_attr; |
| 4667 | n_extra = 0; |
| 4668 | lcs_prec_todo = lcs_prec; |
| 4669 | #ifdef FEAT_LINEBREAK |
| 4670 | # ifdef FEAT_DIFF |
| 4671 | if (filler_todo <= 0) |
| 4672 | # endif |
| 4673 | need_showbreak = TRUE; |
| 4674 | #endif |
| 4675 | #ifdef FEAT_DIFF |
| 4676 | --filler_todo; |
| 4677 | /* When the filler lines are actually below the last line of the |
| 4678 | * file, don't draw the line itself, break here. */ |
| 4679 | if (filler_todo == 0 && wp->w_botfill) |
| 4680 | break; |
| 4681 | #endif |
| 4682 | } |
| 4683 | |
| 4684 | } /* for every character in the line */ |
| 4685 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4686 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4687 | /* After an empty line check first word for capital. */ |
| 4688 | if (*skipwhite(line) == NUL) |
| 4689 | { |
| 4690 | capcol_lnum = lnum + 1; |
| 4691 | cap_col = 0; |
| 4692 | } |
| 4693 | #endif |
| 4694 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4695 | return row; |
| 4696 | } |
| 4697 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4698 | #ifdef FEAT_MBYTE |
| 4699 | static int comp_char_differs __ARGS((int, int)); |
| 4700 | |
| 4701 | /* |
| 4702 | * Return if the composing characters at "off_from" and "off_to" differ. |
| 4703 | */ |
| 4704 | static int |
| 4705 | comp_char_differs(off_from, off_to) |
| 4706 | int off_from; |
| 4707 | int off_to; |
| 4708 | { |
| 4709 | int i; |
| 4710 | |
| 4711 | for (i = 0; i < Screen_mco; ++i) |
| 4712 | { |
| 4713 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 4714 | return TRUE; |
| 4715 | if (ScreenLinesC[i][off_from] == 0) |
| 4716 | break; |
| 4717 | } |
| 4718 | return FALSE; |
| 4719 | } |
| 4720 | #endif |
| 4721 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4722 | /* |
| 4723 | * Check whether the given character needs redrawing: |
| 4724 | * - the (first byte of the) character is different |
| 4725 | * - the attributes are different |
| 4726 | * - the character is multi-byte and the next byte is different |
| 4727 | */ |
| 4728 | static int |
| 4729 | char_needs_redraw(off_from, off_to, cols) |
| 4730 | int off_from; |
| 4731 | int off_to; |
| 4732 | int cols; |
| 4733 | { |
| 4734 | if (cols > 0 |
| 4735 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 4736 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 4737 | |
| 4738 | #ifdef FEAT_MBYTE |
| 4739 | || (enc_dbcs != 0 |
| 4740 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 4741 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 4742 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 4743 | : (cols > 1 && ScreenLines[off_from + 1] |
| 4744 | != ScreenLines[off_to + 1]))) |
| 4745 | || (enc_utf8 |
| 4746 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 4747 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4748 | && comp_char_differs(off_from, off_to)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4749 | #endif |
| 4750 | )) |
| 4751 | return TRUE; |
| 4752 | return FALSE; |
| 4753 | } |
| 4754 | |
| 4755 | /* |
| 4756 | * Move one "cooked" screen line to the screen, but only the characters that |
| 4757 | * have actually changed. Handle insert/delete character. |
| 4758 | * "coloff" gives the first column on the screen for this line. |
| 4759 | * "endcol" gives the columns where valid characters are. |
| 4760 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 4761 | * needs to be cleared, negative otherwise. |
| 4762 | * "rlflag" is TRUE in a rightleft window: |
| 4763 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 4764 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 4765 | */ |
| 4766 | static void |
| 4767 | screen_line(row, coloff, endcol, clear_width |
| 4768 | #ifdef FEAT_RIGHTLEFT |
| 4769 | , rlflag |
| 4770 | #endif |
| 4771 | ) |
| 4772 | int row; |
| 4773 | int coloff; |
| 4774 | int endcol; |
| 4775 | int clear_width; |
| 4776 | #ifdef FEAT_RIGHTLEFT |
| 4777 | int rlflag; |
| 4778 | #endif |
| 4779 | { |
| 4780 | unsigned off_from; |
| 4781 | unsigned off_to; |
| 4782 | int col = 0; |
| 4783 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 4784 | int hl; |
| 4785 | #endif |
| 4786 | int force = FALSE; /* force update rest of the line */ |
| 4787 | int redraw_this /* bool: does character need redraw? */ |
| 4788 | #ifdef FEAT_GUI |
| 4789 | = TRUE /* For GUI when while-loop empty */ |
| 4790 | #endif |
| 4791 | ; |
| 4792 | int redraw_next; /* redraw_this for next character */ |
| 4793 | #ifdef FEAT_MBYTE |
| 4794 | int clear_next = FALSE; |
| 4795 | int char_cells; /* 1: normal char */ |
| 4796 | /* 2: occupies two display cells */ |
| 4797 | # define CHAR_CELLS char_cells |
| 4798 | #else |
| 4799 | # define CHAR_CELLS 1 |
| 4800 | #endif |
| 4801 | |
| 4802 | # ifdef FEAT_CLIPBOARD |
| 4803 | clip_may_clear_selection(row, row); |
| 4804 | # endif |
| 4805 | |
| 4806 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 4807 | off_to = LineOffset[row] + coloff; |
| 4808 | |
| 4809 | #ifdef FEAT_RIGHTLEFT |
| 4810 | if (rlflag) |
| 4811 | { |
| 4812 | /* Clear rest first, because it's left of the text. */ |
| 4813 | if (clear_width > 0) |
| 4814 | { |
| 4815 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 4816 | && ScreenAttrs[off_to] == 0 |
| 4817 | # ifdef FEAT_MBYTE |
| 4818 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 4819 | # endif |
| 4820 | ) |
| 4821 | { |
| 4822 | ++off_to; |
| 4823 | ++col; |
| 4824 | } |
| 4825 | if (col <= endcol) |
| 4826 | screen_fill(row, row + 1, col + coloff, |
| 4827 | endcol + coloff + 1, ' ', ' ', 0); |
| 4828 | } |
| 4829 | col = endcol + 1; |
| 4830 | off_to = LineOffset[row] + col + coloff; |
| 4831 | off_from += col; |
| 4832 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 4833 | } |
| 4834 | #endif /* FEAT_RIGHTLEFT */ |
| 4835 | |
| 4836 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 4837 | |
| 4838 | while (col < endcol) |
| 4839 | { |
| 4840 | #ifdef FEAT_MBYTE |
| 4841 | if (has_mbyte && (col + 1 < endcol)) |
| 4842 | char_cells = (*mb_off2cells)(off_from); |
| 4843 | else |
| 4844 | char_cells = 1; |
| 4845 | #endif |
| 4846 | |
| 4847 | redraw_this = redraw_next; |
| 4848 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 4849 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 4850 | |
| 4851 | #ifdef FEAT_GUI |
| 4852 | /* If the next character was bold, then redraw the current character to |
| 4853 | * remove any pixels that might have spilt over into us. This only |
| 4854 | * happens in the GUI. |
| 4855 | */ |
| 4856 | if (redraw_next && gui.in_use) |
| 4857 | { |
| 4858 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4859 | if (hl > HL_ALL) |
| 4860 | hl = syn_attr2attr(hl); |
| 4861 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4862 | redraw_this = TRUE; |
| 4863 | } |
| 4864 | #endif |
| 4865 | |
| 4866 | if (redraw_this) |
| 4867 | { |
| 4868 | /* |
| 4869 | * Special handling when 'xs' termcap flag set (hpterm): |
| 4870 | * Attributes for characters are stored at the position where the |
| 4871 | * cursor is when writing the highlighting code. The |
| 4872 | * start-highlighting code must be written with the cursor on the |
| 4873 | * first highlighted character. The stop-highlighting code must |
| 4874 | * be written with the cursor just after the last highlighted |
| 4875 | * character. |
| 4876 | * Overwriting a character doesn't remove it's highlighting. Need |
| 4877 | * to clear the rest of the line, and force redrawing it |
| 4878 | * completely. |
| 4879 | */ |
| 4880 | if ( p_wiv |
| 4881 | && !force |
| 4882 | #ifdef FEAT_GUI |
| 4883 | && !gui.in_use |
| 4884 | #endif |
| 4885 | && ScreenAttrs[off_to] != 0 |
| 4886 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 4887 | { |
| 4888 | /* |
| 4889 | * Need to remove highlighting attributes here. |
| 4890 | */ |
| 4891 | windgoto(row, col + coloff); |
| 4892 | out_str(T_CE); /* clear rest of this screen line */ |
| 4893 | screen_start(); /* don't know where cursor is now */ |
| 4894 | force = TRUE; /* force redraw of rest of the line */ |
| 4895 | redraw_next = TRUE; /* or else next char would miss out */ |
| 4896 | |
| 4897 | /* |
| 4898 | * If the previous character was highlighted, need to stop |
| 4899 | * highlighting at this character. |
| 4900 | */ |
| 4901 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 4902 | { |
| 4903 | screen_attr = ScreenAttrs[off_to - 1]; |
| 4904 | term_windgoto(row, col + coloff); |
| 4905 | screen_stop_highlight(); |
| 4906 | } |
| 4907 | else |
| 4908 | screen_attr = 0; /* highlighting has stopped */ |
| 4909 | } |
| 4910 | #ifdef FEAT_MBYTE |
| 4911 | if (enc_dbcs != 0) |
| 4912 | { |
| 4913 | /* Check if overwriting a double-byte with a single-byte or |
| 4914 | * the other way around requires another character to be |
| 4915 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 4916 | * ScreenLinesUC[] is sufficient. */ |
| 4917 | if (char_cells == 1 |
| 4918 | && col + 1 < endcol |
| 4919 | && (*mb_off2cells)(off_to) > 1) |
| 4920 | { |
| 4921 | /* Writing a single-cell character over a double-cell |
| 4922 | * character: need to redraw the next cell. */ |
| 4923 | ScreenLines[off_to + 1] = 0; |
| 4924 | redraw_next = TRUE; |
| 4925 | } |
| 4926 | else if (char_cells == 2 |
| 4927 | && col + 2 < endcol |
| 4928 | && (*mb_off2cells)(off_to) == 1 |
| 4929 | && (*mb_off2cells)(off_to + 1) > 1) |
| 4930 | { |
| 4931 | /* Writing the second half of a double-cell character over |
| 4932 | * a double-cell character: need to redraw the second |
| 4933 | * cell. */ |
| 4934 | ScreenLines[off_to + 2] = 0; |
| 4935 | redraw_next = TRUE; |
| 4936 | } |
| 4937 | |
| 4938 | if (enc_dbcs == DBCS_JPNU) |
| 4939 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 4940 | } |
| 4941 | /* When writing a single-width character over a double-width |
| 4942 | * character and at the end of the redrawn text, need to clear out |
| 4943 | * the right halve of the old character. |
| 4944 | * Also required when writing the right halve of a double-width |
| 4945 | * char over the left halve of an existing one. */ |
| 4946 | if (has_mbyte && col + char_cells == endcol |
| 4947 | && ((char_cells == 1 |
| 4948 | && (*mb_off2cells)(off_to) > 1) |
| 4949 | || (char_cells == 2 |
| 4950 | && (*mb_off2cells)(off_to) == 1 |
| 4951 | && (*mb_off2cells)(off_to + 1) > 1))) |
| 4952 | clear_next = TRUE; |
| 4953 | #endif |
| 4954 | |
| 4955 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 4956 | #ifdef FEAT_MBYTE |
| 4957 | if (enc_utf8) |
| 4958 | { |
| 4959 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 4960 | if (ScreenLinesUC[off_from] != 0) |
| 4961 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4962 | int i; |
| 4963 | |
| 4964 | for (i = 0; i < Screen_mco; ++i) |
| 4965 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4966 | } |
| 4967 | } |
| 4968 | if (char_cells == 2) |
| 4969 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 4970 | #endif |
| 4971 | |
| 4972 | #if defined(FEAT_GUI) || defined(UNIX) |
| 4973 | /* The bold trick makes a single row of pixels appear in the next |
| 4974 | * character. When a bold character is removed, the next |
| 4975 | * character should be redrawn too. This happens for our own GUI |
| 4976 | * and for some xterms. */ |
| 4977 | if ( |
| 4978 | # ifdef FEAT_GUI |
| 4979 | gui.in_use |
| 4980 | # endif |
| 4981 | # if defined(FEAT_GUI) && defined(UNIX) |
| 4982 | || |
| 4983 | # endif |
| 4984 | # ifdef UNIX |
| 4985 | term_is_xterm |
| 4986 | # endif |
| 4987 | ) |
| 4988 | { |
| 4989 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4990 | if (hl > HL_ALL) |
| 4991 | hl = syn_attr2attr(hl); |
| 4992 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4993 | redraw_next = TRUE; |
| 4994 | } |
| 4995 | #endif |
| 4996 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 4997 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4998 | /* For simplicity set the attributes of second half of a |
| 4999 | * double-wide character equal to the first half. */ |
| 5000 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5001 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5002 | |
| 5003 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5004 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5005 | else |
| 5006 | #endif |
| 5007 | screen_char(off_to, row, col + coloff); |
| 5008 | } |
| 5009 | else if ( p_wiv |
| 5010 | #ifdef FEAT_GUI |
| 5011 | && !gui.in_use |
| 5012 | #endif |
| 5013 | && col + coloff > 0) |
| 5014 | { |
| 5015 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 5016 | { |
| 5017 | /* |
| 5018 | * Don't output stop-highlight when moving the cursor, it will |
| 5019 | * stop the highlighting when it should continue. |
| 5020 | */ |
| 5021 | screen_attr = 0; |
| 5022 | } |
| 5023 | else if (screen_attr != 0) |
| 5024 | screen_stop_highlight(); |
| 5025 | } |
| 5026 | |
| 5027 | off_to += CHAR_CELLS; |
| 5028 | off_from += CHAR_CELLS; |
| 5029 | col += CHAR_CELLS; |
| 5030 | } |
| 5031 | |
| 5032 | #ifdef FEAT_MBYTE |
| 5033 | if (clear_next) |
| 5034 | { |
| 5035 | /* Clear the second half of a double-wide character of which the left |
| 5036 | * half was overwritten with a single-wide character. */ |
| 5037 | ScreenLines[off_to] = ' '; |
| 5038 | if (enc_utf8) |
| 5039 | ScreenLinesUC[off_to] = 0; |
| 5040 | screen_char(off_to, row, col + coloff); |
| 5041 | } |
| 5042 | #endif |
| 5043 | |
| 5044 | if (clear_width > 0 |
| 5045 | #ifdef FEAT_RIGHTLEFT |
| 5046 | && !rlflag |
| 5047 | #endif |
| 5048 | ) |
| 5049 | { |
| 5050 | #ifdef FEAT_GUI |
| 5051 | int startCol = col; |
| 5052 | #endif |
| 5053 | |
| 5054 | /* blank out the rest of the line */ |
| 5055 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 5056 | && ScreenAttrs[off_to] == 0 |
| 5057 | #ifdef FEAT_MBYTE |
| 5058 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5059 | #endif |
| 5060 | ) |
| 5061 | { |
| 5062 | ++off_to; |
| 5063 | ++col; |
| 5064 | } |
| 5065 | if (col < clear_width) |
| 5066 | { |
| 5067 | #ifdef FEAT_GUI |
| 5068 | /* |
| 5069 | * In the GUI, clearing the rest of the line may leave pixels |
| 5070 | * behind if the first character cleared was bold. Some bold |
| 5071 | * fonts spill over the left. In this case we redraw the previous |
| 5072 | * character too. If we didn't skip any blanks above, then we |
| 5073 | * only redraw if the character wasn't already redrawn anyway. |
| 5074 | */ |
| 5075 | if (gui.in_use && (col > startCol || !redraw_this) |
| 5076 | # ifdef FEAT_MBYTE |
| 5077 | && enc_dbcs == 0 |
| 5078 | # endif |
| 5079 | ) |
| 5080 | { |
| 5081 | hl = ScreenAttrs[off_to]; |
| 5082 | if (hl > HL_ALL || (hl & HL_BOLD)) |
| 5083 | screen_char(off_to - 1, row, col + coloff - 1); |
| 5084 | } |
| 5085 | #endif |
| 5086 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 5087 | ' ', ' ', 0); |
| 5088 | #ifdef FEAT_VERTSPLIT |
| 5089 | off_to += clear_width - col; |
| 5090 | col = clear_width; |
| 5091 | #endif |
| 5092 | } |
| 5093 | } |
| 5094 | |
| 5095 | if (clear_width > 0) |
| 5096 | { |
| 5097 | #ifdef FEAT_VERTSPLIT |
| 5098 | /* For a window that's left of another, draw the separator char. */ |
| 5099 | if (col + coloff < Columns) |
| 5100 | { |
| 5101 | int c; |
| 5102 | |
| 5103 | c = fillchar_vsep(&hl); |
| 5104 | if (ScreenLines[off_to] != c |
| 5105 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5106 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 5107 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5108 | # endif |
| 5109 | || ScreenAttrs[off_to] != hl) |
| 5110 | { |
| 5111 | ScreenLines[off_to] = c; |
| 5112 | ScreenAttrs[off_to] = hl; |
| 5113 | # ifdef FEAT_MBYTE |
| 5114 | if (enc_utf8) |
| 5115 | { |
| 5116 | if (c >= 0x80) |
| 5117 | { |
| 5118 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5119 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5120 | } |
| 5121 | else |
| 5122 | ScreenLinesUC[off_to] = 0; |
| 5123 | } |
| 5124 | # endif |
| 5125 | screen_char(off_to, row, col + coloff); |
| 5126 | } |
| 5127 | } |
| 5128 | else |
| 5129 | #endif |
| 5130 | LineWraps[row] = FALSE; |
| 5131 | } |
| 5132 | } |
| 5133 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5134 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5135 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5136 | * Mirror text "str" for right-left displaying. |
| 5137 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5138 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5139 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5140 | rl_mirror(str) |
| 5141 | char_u *str; |
| 5142 | { |
| 5143 | char_u *p1, *p2; |
| 5144 | int t; |
| 5145 | |
| 5146 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 5147 | { |
| 5148 | t = *p1; |
| 5149 | *p1 = *p2; |
| 5150 | *p2 = t; |
| 5151 | } |
| 5152 | } |
| 5153 | #endif |
| 5154 | |
| 5155 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5156 | /* |
| 5157 | * mark all status lines for redraw; used after first :cd |
| 5158 | */ |
| 5159 | void |
| 5160 | status_redraw_all() |
| 5161 | { |
| 5162 | win_T *wp; |
| 5163 | |
| 5164 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5165 | if (wp->w_status_height) |
| 5166 | { |
| 5167 | wp->w_redr_status = TRUE; |
| 5168 | redraw_later(VALID); |
| 5169 | } |
| 5170 | } |
| 5171 | |
| 5172 | /* |
| 5173 | * mark all status lines of the current buffer for redraw |
| 5174 | */ |
| 5175 | void |
| 5176 | status_redraw_curbuf() |
| 5177 | { |
| 5178 | win_T *wp; |
| 5179 | |
| 5180 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5181 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 5182 | { |
| 5183 | wp->w_redr_status = TRUE; |
| 5184 | redraw_later(VALID); |
| 5185 | } |
| 5186 | } |
| 5187 | |
| 5188 | /* |
| 5189 | * Redraw all status lines that need to be redrawn. |
| 5190 | */ |
| 5191 | void |
| 5192 | redraw_statuslines() |
| 5193 | { |
| 5194 | win_T *wp; |
| 5195 | |
| 5196 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5197 | if (wp->w_redr_status) |
| 5198 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 5199 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5200 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5201 | } |
| 5202 | #endif |
| 5203 | |
| 5204 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 5205 | /* |
| 5206 | * Redraw all status lines at the bottom of frame "frp". |
| 5207 | */ |
| 5208 | void |
| 5209 | win_redraw_last_status(frp) |
| 5210 | frame_T *frp; |
| 5211 | { |
| 5212 | if (frp->fr_layout == FR_LEAF) |
| 5213 | frp->fr_win->w_redr_status = TRUE; |
| 5214 | else if (frp->fr_layout == FR_ROW) |
| 5215 | { |
| 5216 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 5217 | win_redraw_last_status(frp); |
| 5218 | } |
| 5219 | else /* frp->fr_layout == FR_COL */ |
| 5220 | { |
| 5221 | frp = frp->fr_child; |
| 5222 | while (frp->fr_next != NULL) |
| 5223 | frp = frp->fr_next; |
| 5224 | win_redraw_last_status(frp); |
| 5225 | } |
| 5226 | } |
| 5227 | #endif |
| 5228 | |
| 5229 | #ifdef FEAT_VERTSPLIT |
| 5230 | /* |
| 5231 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 5232 | */ |
| 5233 | static void |
| 5234 | draw_vsep_win(wp, row) |
| 5235 | win_T *wp; |
| 5236 | int row; |
| 5237 | { |
| 5238 | int hl; |
| 5239 | int c; |
| 5240 | |
| 5241 | if (wp->w_vsep_width) |
| 5242 | { |
| 5243 | /* draw the vertical separator right of this window */ |
| 5244 | c = fillchar_vsep(&hl); |
| 5245 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 5246 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 5247 | c, ' ', hl); |
| 5248 | } |
| 5249 | } |
| 5250 | #endif |
| 5251 | |
| 5252 | #ifdef FEAT_WILDMENU |
| 5253 | static int status_match_len __ARGS((expand_T *xp, char_u *s)); |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5254 | 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] | 5255 | |
| 5256 | /* |
| 5257 | * Get the lenght of an item as it will be shown in the status line. |
| 5258 | */ |
| 5259 | static int |
| 5260 | status_match_len(xp, s) |
| 5261 | expand_T *xp; |
| 5262 | char_u *s; |
| 5263 | { |
| 5264 | int len = 0; |
| 5265 | |
| 5266 | #ifdef FEAT_MENU |
| 5267 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 5268 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5269 | |
| 5270 | /* Check for menu separators - replace with '|'. */ |
| 5271 | if (emenu && menu_is_separator(s)) |
| 5272 | return 1; |
| 5273 | #endif |
| 5274 | |
| 5275 | while (*s != NUL) |
| 5276 | { |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5277 | if (skip_status_match_char(xp, s)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5278 | ++s; |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5279 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5280 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | return len; |
| 5284 | } |
| 5285 | |
| 5286 | /* |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5287 | * Return TRUE for characters that are not displayed in a status match. |
| 5288 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 5289 | */ |
| 5290 | static int |
| 5291 | skip_status_match_char(xp, s) |
| 5292 | expand_T *xp; |
| 5293 | char_u *s; |
| 5294 | { |
| 5295 | return ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
| 5296 | #ifdef FEAT_MENU |
| 5297 | || ((xp->xp_context == EXPAND_MENUS |
| 5298 | || xp->xp_context == EXPAND_MENUNAMES) |
| 5299 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 5300 | #endif |
| 5301 | ); |
| 5302 | } |
| 5303 | |
| 5304 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5305 | * Show wildchar matches in the status line. |
| 5306 | * Show at least the "match" item. |
| 5307 | * We start at item 'first_match' in the list and show all matches that fit. |
| 5308 | * |
| 5309 | * If inversion is possible we use it. Else '=' characters are used. |
| 5310 | */ |
| 5311 | void |
| 5312 | win_redr_status_matches(xp, num_matches, matches, match, showtail) |
| 5313 | expand_T *xp; |
| 5314 | int num_matches; |
| 5315 | char_u **matches; /* list of matches */ |
| 5316 | int match; |
| 5317 | int showtail; |
| 5318 | { |
| 5319 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 5320 | int row; |
| 5321 | char_u *buf; |
| 5322 | int len; |
| 5323 | int clen; /* lenght in screen cells */ |
| 5324 | int fillchar; |
| 5325 | int attr; |
| 5326 | int i; |
| 5327 | int highlight = TRUE; |
| 5328 | char_u *selstart = NULL; |
| 5329 | int selstart_col = 0; |
| 5330 | char_u *selend = NULL; |
| 5331 | static int first_match = 0; |
| 5332 | int add_left = FALSE; |
| 5333 | char_u *s; |
| 5334 | #ifdef FEAT_MENU |
| 5335 | int emenu; |
| 5336 | #endif |
| 5337 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 5338 | int l; |
| 5339 | #endif |
| 5340 | |
| 5341 | if (matches == NULL) /* interrupted completion? */ |
| 5342 | return; |
| 5343 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5344 | #ifdef FEAT_MBYTE |
| 5345 | if (has_mbyte) |
| 5346 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 5347 | else |
| 5348 | #endif |
| 5349 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5350 | if (buf == NULL) |
| 5351 | return; |
| 5352 | |
| 5353 | if (match == -1) /* don't show match but original text */ |
| 5354 | { |
| 5355 | match = 0; |
| 5356 | highlight = FALSE; |
| 5357 | } |
| 5358 | /* count 1 for the ending ">" */ |
| 5359 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 5360 | if (match == 0) |
| 5361 | first_match = 0; |
| 5362 | else if (match < first_match) |
| 5363 | { |
| 5364 | /* jumping left, as far as we can go */ |
| 5365 | first_match = match; |
| 5366 | add_left = TRUE; |
| 5367 | } |
| 5368 | else |
| 5369 | { |
| 5370 | /* check if match fits on the screen */ |
| 5371 | for (i = first_match; i < match; ++i) |
| 5372 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5373 | if (first_match > 0) |
| 5374 | clen += 2; |
| 5375 | /* jumping right, put match at the left */ |
| 5376 | if ((long)clen > Columns) |
| 5377 | { |
| 5378 | first_match = match; |
| 5379 | /* if showing the last match, we can add some on the left */ |
| 5380 | clen = 2; |
| 5381 | for (i = match; i < num_matches; ++i) |
| 5382 | { |
| 5383 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5384 | if ((long)clen >= Columns) |
| 5385 | break; |
| 5386 | } |
| 5387 | if (i == num_matches) |
| 5388 | add_left = TRUE; |
| 5389 | } |
| 5390 | } |
| 5391 | if (add_left) |
| 5392 | while (first_match > 0) |
| 5393 | { |
| 5394 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 5395 | if ((long)clen >= Columns) |
| 5396 | break; |
| 5397 | --first_match; |
| 5398 | } |
| 5399 | |
| 5400 | fillchar = fillchar_status(&attr, TRUE); |
| 5401 | |
| 5402 | if (first_match == 0) |
| 5403 | { |
| 5404 | *buf = NUL; |
| 5405 | len = 0; |
| 5406 | } |
| 5407 | else |
| 5408 | { |
| 5409 | STRCPY(buf, "< "); |
| 5410 | len = 2; |
| 5411 | } |
| 5412 | clen = len; |
| 5413 | |
| 5414 | i = first_match; |
| 5415 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 5416 | { |
| 5417 | if (i == match) |
| 5418 | { |
| 5419 | selstart = buf + len; |
| 5420 | selstart_col = clen; |
| 5421 | } |
| 5422 | |
| 5423 | s = L_MATCH(i); |
| 5424 | /* Check for menu separators - replace with '|' */ |
| 5425 | #ifdef FEAT_MENU |
| 5426 | emenu = (xp->xp_context == EXPAND_MENUS |
| 5427 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5428 | if (emenu && menu_is_separator(s)) |
| 5429 | { |
| 5430 | STRCPY(buf + len, transchar('|')); |
| 5431 | l = (int)STRLEN(buf + len); |
| 5432 | len += l; |
| 5433 | clen += l; |
| 5434 | } |
| 5435 | else |
| 5436 | #endif |
| 5437 | for ( ; *s != NUL; ++s) |
| 5438 | { |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5439 | if (skip_status_match_char(xp, s)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5440 | ++s; |
| 5441 | clen += ptr2cells(s); |
| 5442 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5443 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5444 | { |
| 5445 | STRNCPY(buf + len, s, l); |
| 5446 | s += l - 1; |
| 5447 | len += l; |
| 5448 | } |
| 5449 | else |
| 5450 | #endif |
| 5451 | { |
| 5452 | STRCPY(buf + len, transchar_byte(*s)); |
| 5453 | len += (int)STRLEN(buf + len); |
| 5454 | } |
| 5455 | } |
| 5456 | if (i == match) |
| 5457 | selend = buf + len; |
| 5458 | |
| 5459 | *(buf + len++) = ' '; |
| 5460 | *(buf + len++) = ' '; |
| 5461 | clen += 2; |
| 5462 | if (++i == num_matches) |
| 5463 | break; |
| 5464 | } |
| 5465 | |
| 5466 | if (i != num_matches) |
| 5467 | { |
| 5468 | *(buf + len++) = '>'; |
| 5469 | ++clen; |
| 5470 | } |
| 5471 | |
| 5472 | buf[len] = NUL; |
| 5473 | |
| 5474 | row = cmdline_row - 1; |
| 5475 | if (row >= 0) |
| 5476 | { |
| 5477 | if (wild_menu_showing == 0) |
| 5478 | { |
| 5479 | if (msg_scrolled > 0) |
| 5480 | { |
| 5481 | /* Put the wildmenu just above the command line. If there is |
| 5482 | * no room, scroll the screen one line up. */ |
| 5483 | if (cmdline_row == Rows - 1) |
| 5484 | { |
| 5485 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 5486 | ++msg_scrolled; |
| 5487 | } |
| 5488 | else |
| 5489 | { |
| 5490 | ++cmdline_row; |
| 5491 | ++row; |
| 5492 | } |
| 5493 | wild_menu_showing = WM_SCROLLED; |
| 5494 | } |
| 5495 | else |
| 5496 | { |
| 5497 | /* Create status line if needed by setting 'laststatus' to 2. |
| 5498 | * Set 'winminheight' to zero to avoid that the window is |
| 5499 | * resized. */ |
| 5500 | if (lastwin->w_status_height == 0) |
| 5501 | { |
| 5502 | save_p_ls = p_ls; |
| 5503 | save_p_wmh = p_wmh; |
| 5504 | p_ls = 2; |
| 5505 | p_wmh = 0; |
| 5506 | last_status(FALSE); |
| 5507 | } |
| 5508 | wild_menu_showing = WM_SHOWN; |
| 5509 | } |
| 5510 | } |
| 5511 | |
| 5512 | screen_puts(buf, row, 0, attr); |
| 5513 | if (selstart != NULL && highlight) |
| 5514 | { |
| 5515 | *selend = NUL; |
| 5516 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 5517 | } |
| 5518 | |
| 5519 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 5520 | } |
| 5521 | |
| 5522 | #ifdef FEAT_VERTSPLIT |
| 5523 | win_redraw_last_status(topframe); |
| 5524 | #else |
| 5525 | lastwin->w_redr_status = TRUE; |
| 5526 | #endif |
| 5527 | vim_free(buf); |
| 5528 | } |
| 5529 | #endif |
| 5530 | |
| 5531 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5532 | /* |
| 5533 | * Redraw the status line of window wp. |
| 5534 | * |
| 5535 | * If inversion is possible we use it. Else '=' characters are used. |
| 5536 | */ |
| 5537 | void |
| 5538 | win_redr_status(wp) |
| 5539 | win_T *wp; |
| 5540 | { |
| 5541 | int row; |
| 5542 | char_u *p; |
| 5543 | int len; |
| 5544 | int fillchar; |
| 5545 | int attr; |
| 5546 | int this_ru_col; |
| 5547 | |
| 5548 | wp->w_redr_status = FALSE; |
| 5549 | if (wp->w_status_height == 0) |
| 5550 | { |
| 5551 | /* no status line, can only be last window */ |
| 5552 | redraw_cmdline = TRUE; |
| 5553 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 5554 | else if (!redrawing() |
| 5555 | #ifdef FEAT_INS_EXPAND |
| 5556 | /* don't update status line when popup menu is visible and may be |
| 5557 | * drawn over it */ |
| 5558 | || pum_visible() |
| 5559 | #endif |
| 5560 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5561 | { |
| 5562 | /* Don't redraw right now, do it later. */ |
| 5563 | wp->w_redr_status = TRUE; |
| 5564 | } |
| 5565 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 5566 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5567 | { |
| 5568 | /* redraw custom status line */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5569 | redraw_custum_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5570 | } |
| 5571 | #endif |
| 5572 | else |
| 5573 | { |
| 5574 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5575 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 5576 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5577 | p = NameBuff; |
| 5578 | len = (int)STRLEN(p); |
| 5579 | |
| 5580 | if (wp->w_buffer->b_help |
| 5581 | #ifdef FEAT_QUICKFIX |
| 5582 | || wp->w_p_pvw |
| 5583 | #endif |
| 5584 | || bufIsChanged(wp->w_buffer) |
| 5585 | || wp->w_buffer->b_p_ro) |
| 5586 | *(p + len++) = ' '; |
| 5587 | if (wp->w_buffer->b_help) |
| 5588 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 5589 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5590 | len += (int)STRLEN(p + len); |
| 5591 | } |
| 5592 | #ifdef FEAT_QUICKFIX |
| 5593 | if (wp->w_p_pvw) |
| 5594 | { |
| 5595 | STRCPY(p + len, _("[Preview]")); |
| 5596 | len += (int)STRLEN(p + len); |
| 5597 | } |
| 5598 | #endif |
| 5599 | if (bufIsChanged(wp->w_buffer)) |
| 5600 | { |
| 5601 | STRCPY(p + len, "[+]"); |
| 5602 | len += 3; |
| 5603 | } |
| 5604 | if (wp->w_buffer->b_p_ro) |
| 5605 | { |
| 5606 | STRCPY(p + len, "[RO]"); |
| 5607 | len += 4; |
| 5608 | } |
| 5609 | |
| 5610 | #ifndef FEAT_VERTSPLIT |
| 5611 | this_ru_col = ru_col; |
| 5612 | if (this_ru_col < (Columns + 1) / 2) |
| 5613 | this_ru_col = (Columns + 1) / 2; |
| 5614 | #else |
| 5615 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 5616 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 5617 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 5618 | if (this_ru_col <= 1) |
| 5619 | { |
| 5620 | p = (char_u *)"<"; /* No room for file name! */ |
| 5621 | len = 1; |
| 5622 | } |
| 5623 | else |
| 5624 | #endif |
| 5625 | #ifdef FEAT_MBYTE |
| 5626 | if (has_mbyte) |
| 5627 | { |
| 5628 | int clen = 0, i; |
| 5629 | |
| 5630 | /* Count total number of display cells. */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5631 | for (i = 0; p[i] != NUL; i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5632 | clen += (*mb_ptr2cells)(p + i); |
| 5633 | /* Find first character that will fit. |
| 5634 | * Going from start to end is much faster for DBCS. */ |
| 5635 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5636 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5637 | clen -= (*mb_ptr2cells)(p + i); |
| 5638 | len = clen; |
| 5639 | if (i > 0) |
| 5640 | { |
| 5641 | p = p + i - 1; |
| 5642 | *p = '<'; |
| 5643 | ++len; |
| 5644 | } |
| 5645 | |
| 5646 | } |
| 5647 | else |
| 5648 | #endif |
| 5649 | if (len > this_ru_col - 1) |
| 5650 | { |
| 5651 | p += len - (this_ru_col - 1); |
| 5652 | *p = '<'; |
| 5653 | len = this_ru_col - 1; |
| 5654 | } |
| 5655 | |
| 5656 | row = W_WINROW(wp) + wp->w_height; |
| 5657 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 5658 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 5659 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 5660 | |
| 5661 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 5662 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 5663 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 5664 | - 1 + W_WINCOL(wp)), attr); |
| 5665 | |
| 5666 | #ifdef FEAT_CMDL_INFO |
| 5667 | win_redr_ruler(wp, TRUE); |
| 5668 | #endif |
| 5669 | } |
| 5670 | |
| 5671 | #ifdef FEAT_VERTSPLIT |
| 5672 | /* |
| 5673 | * May need to draw the character below the vertical separator. |
| 5674 | */ |
| 5675 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 5676 | { |
| 5677 | if (stl_connected(wp)) |
| 5678 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5679 | else |
| 5680 | fillchar = fillchar_vsep(&attr); |
| 5681 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 5682 | attr); |
| 5683 | } |
| 5684 | #endif |
| 5685 | } |
| 5686 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5687 | #ifdef FEAT_STL_OPT |
| 5688 | /* |
| 5689 | * Redraw the status line according to 'statusline' and take care of any |
| 5690 | * errors encountered. |
| 5691 | */ |
| 5692 | static void |
| 5693 | redraw_custum_statusline(wp) |
| 5694 | win_T *wp; |
| 5695 | { |
| 5696 | int save_called_emsg = called_emsg; |
| 5697 | |
| 5698 | called_emsg = FALSE; |
| 5699 | win_redr_custom(wp, FALSE); |
| 5700 | if (called_emsg) |
| 5701 | set_string_option_direct((char_u *)"statusline", -1, |
| 5702 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 5703 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5704 | called_emsg |= save_called_emsg; |
| 5705 | } |
| 5706 | #endif |
| 5707 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5708 | # ifdef FEAT_VERTSPLIT |
| 5709 | /* |
| 5710 | * Return TRUE if the status line of window "wp" is connected to the status |
| 5711 | * line of the window right of it. If not, then it's a vertical separator. |
| 5712 | * Only call if (wp->w_vsep_width != 0). |
| 5713 | */ |
| 5714 | int |
| 5715 | stl_connected(wp) |
| 5716 | win_T *wp; |
| 5717 | { |
| 5718 | frame_T *fr; |
| 5719 | |
| 5720 | fr = wp->w_frame; |
| 5721 | while (fr->fr_parent != NULL) |
| 5722 | { |
| 5723 | if (fr->fr_parent->fr_layout == FR_COL) |
| 5724 | { |
| 5725 | if (fr->fr_next != NULL) |
| 5726 | break; |
| 5727 | } |
| 5728 | else |
| 5729 | { |
| 5730 | if (fr->fr_next != NULL) |
| 5731 | return TRUE; |
| 5732 | } |
| 5733 | fr = fr->fr_parent; |
| 5734 | } |
| 5735 | return FALSE; |
| 5736 | } |
| 5737 | # endif |
| 5738 | |
| 5739 | #endif /* FEAT_WINDOWS */ |
| 5740 | |
| 5741 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 5742 | /* |
| 5743 | * Get the value to show for the language mappings, active 'keymap'. |
| 5744 | */ |
| 5745 | int |
| 5746 | get_keymap_str(wp, buf, len) |
| 5747 | win_T *wp; |
| 5748 | char_u *buf; /* buffer for the result */ |
| 5749 | int len; /* length of buffer */ |
| 5750 | { |
| 5751 | char_u *p; |
| 5752 | |
| 5753 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 5754 | return FALSE; |
| 5755 | |
| 5756 | { |
| 5757 | #ifdef FEAT_EVAL |
| 5758 | buf_T *old_curbuf = curbuf; |
| 5759 | win_T *old_curwin = curwin; |
| 5760 | char_u *s; |
| 5761 | |
| 5762 | curbuf = wp->w_buffer; |
| 5763 | curwin = wp; |
| 5764 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 5765 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5766 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5767 | --emsg_skip; |
| 5768 | curbuf = old_curbuf; |
| 5769 | curwin = old_curwin; |
| 5770 | if (p == NULL || *p == NUL) |
| 5771 | #endif |
| 5772 | { |
| 5773 | #ifdef FEAT_KEYMAP |
| 5774 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 5775 | p = wp->w_buffer->b_p_keymap; |
| 5776 | else |
| 5777 | #endif |
| 5778 | p = (char_u *)"lang"; |
| 5779 | } |
| 5780 | if ((int)(STRLEN(p) + 3) < len) |
| 5781 | sprintf((char *)buf, "<%s>", p); |
| 5782 | else |
| 5783 | buf[0] = NUL; |
| 5784 | #ifdef FEAT_EVAL |
| 5785 | vim_free(s); |
| 5786 | #endif |
| 5787 | } |
| 5788 | return buf[0] != NUL; |
| 5789 | } |
| 5790 | #endif |
| 5791 | |
| 5792 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 5793 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5794 | * Redraw the status line or ruler of window "wp". |
| 5795 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5796 | */ |
| 5797 | static void |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 5798 | win_redr_custom(wp, draw_ruler) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5799 | win_T *wp; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 5800 | int draw_ruler; /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5801 | { |
| 5802 | int attr; |
| 5803 | int curattr; |
| 5804 | int row; |
| 5805 | int col = 0; |
| 5806 | int maxwidth; |
| 5807 | int width; |
| 5808 | int n; |
| 5809 | int len; |
| 5810 | int fillchar; |
| 5811 | char_u buf[MAXPATHL]; |
| 5812 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5813 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 5814 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5815 | int use_sandbox = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5816 | |
| 5817 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5818 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5819 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5820 | /* Use 'tabline'. Always at the first line of the screen. */ |
| 5821 | p = p_tal; |
| 5822 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 5823 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5824 | attr = hl_attr(HLF_TPF); |
| 5825 | maxwidth = Columns; |
| 5826 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5827 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5828 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5829 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5830 | else |
| 5831 | { |
| 5832 | row = W_WINROW(wp) + wp->w_height; |
| 5833 | fillchar = fillchar_status(&attr, wp == curwin); |
| 5834 | maxwidth = W_WIDTH(wp); |
| 5835 | |
| 5836 | if (draw_ruler) |
| 5837 | { |
| 5838 | p = p_ruf; |
| 5839 | /* advance past any leading group spec - implicit in ru_col */ |
| 5840 | if (*p == '%') |
| 5841 | { |
| 5842 | if (*++p == '-') |
| 5843 | p++; |
| 5844 | if (atoi((char *) p)) |
| 5845 | while (VIM_ISDIGIT(*p)) |
| 5846 | p++; |
| 5847 | if (*p++ != '(') |
| 5848 | p = p_ruf; |
| 5849 | } |
| 5850 | #ifdef FEAT_VERTSPLIT |
| 5851 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 5852 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 5853 | col = (W_WIDTH(wp) + 1) / 2; |
| 5854 | #else |
| 5855 | col = ru_col; |
| 5856 | if (col > (Columns + 1) / 2) |
| 5857 | col = (Columns + 1) / 2; |
| 5858 | #endif |
| 5859 | maxwidth = W_WIDTH(wp) - col; |
| 5860 | #ifdef FEAT_WINDOWS |
| 5861 | if (!wp->w_status_height) |
| 5862 | #endif |
| 5863 | { |
| 5864 | row = Rows - 1; |
| 5865 | --maxwidth; /* writing in last column may cause scrolling */ |
| 5866 | fillchar = ' '; |
| 5867 | attr = 0; |
| 5868 | } |
| 5869 | |
| 5870 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5871 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5872 | # endif |
| 5873 | } |
| 5874 | else |
| 5875 | { |
| 5876 | if (*wp->w_p_stl != NUL) |
| 5877 | p = wp->w_p_stl; |
| 5878 | else |
| 5879 | p = p_stl; |
| 5880 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5881 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 5882 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5883 | # endif |
| 5884 | } |
| 5885 | |
| 5886 | #ifdef FEAT_VERTSPLIT |
| 5887 | col += W_WINCOL(wp); |
| 5888 | #endif |
| 5889 | } |
| 5890 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5891 | if (maxwidth <= 0) |
| 5892 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5893 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5894 | width = build_stl_str_hl(wp == NULL ? curwin : wp, |
| 5895 | buf, sizeof(buf), |
| 5896 | p, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5897 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 5898 | len = (int)STRLEN(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5899 | |
| 5900 | while (width < maxwidth && len < sizeof(buf) - 1) |
| 5901 | { |
| 5902 | #ifdef FEAT_MBYTE |
| 5903 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 5904 | #else |
| 5905 | buf[len++] = fillchar; |
| 5906 | #endif |
| 5907 | ++width; |
| 5908 | } |
| 5909 | buf[len] = NUL; |
| 5910 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5911 | /* |
| 5912 | * Draw each snippet with the specified highlighting. |
| 5913 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5914 | curattr = attr; |
| 5915 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5916 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5917 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5918 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5919 | screen_puts_len(p, len, row, col, curattr); |
| 5920 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5921 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5922 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5923 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5924 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5925 | else if (hltab[n].userhl < 0) |
| 5926 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5927 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 5928 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5929 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5930 | #endif |
| 5931 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5932 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5933 | } |
| 5934 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 5935 | |
| 5936 | if (wp == NULL) |
| 5937 | { |
| 5938 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 5939 | col = 0; |
| 5940 | len = 0; |
| 5941 | p = buf; |
| 5942 | fillchar = 0; |
| 5943 | for (n = 0; tabtab[n].start != NULL; n++) |
| 5944 | { |
| 5945 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 5946 | while (col < len) |
| 5947 | TabPageIdxs[col++] = fillchar; |
| 5948 | p = tabtab[n].start; |
| 5949 | fillchar = tabtab[n].userhl; |
| 5950 | } |
| 5951 | while (col < Columns) |
| 5952 | TabPageIdxs[col++] = fillchar; |
| 5953 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | #endif /* FEAT_STL_OPT */ |
| 5957 | |
| 5958 | /* |
| 5959 | * Output a single character directly to the screen and update ScreenLines. |
| 5960 | */ |
| 5961 | void |
| 5962 | screen_putchar(c, row, col, attr) |
| 5963 | int c; |
| 5964 | int row, col; |
| 5965 | int attr; |
| 5966 | { |
| 5967 | #ifdef FEAT_MBYTE |
| 5968 | char_u buf[MB_MAXBYTES + 1]; |
| 5969 | |
| 5970 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 5971 | #else |
| 5972 | char_u buf[2]; |
| 5973 | |
| 5974 | buf[0] = c; |
| 5975 | buf[1] = NUL; |
| 5976 | #endif |
| 5977 | screen_puts(buf, row, col, attr); |
| 5978 | } |
| 5979 | |
| 5980 | /* |
| 5981 | * Get a single character directly from ScreenLines into "bytes[]". |
| 5982 | * Also return its attribute in *attrp; |
| 5983 | */ |
| 5984 | void |
| 5985 | screen_getbytes(row, col, bytes, attrp) |
| 5986 | int row, col; |
| 5987 | char_u *bytes; |
| 5988 | int *attrp; |
| 5989 | { |
| 5990 | unsigned off; |
| 5991 | |
| 5992 | /* safety check */ |
| 5993 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 5994 | { |
| 5995 | off = LineOffset[row] + col; |
| 5996 | *attrp = ScreenAttrs[off]; |
| 5997 | bytes[0] = ScreenLines[off]; |
| 5998 | bytes[1] = NUL; |
| 5999 | |
| 6000 | #ifdef FEAT_MBYTE |
| 6001 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6002 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 6003 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6004 | { |
| 6005 | bytes[0] = ScreenLines[off]; |
| 6006 | bytes[1] = ScreenLines2[off]; |
| 6007 | bytes[2] = NUL; |
| 6008 | } |
| 6009 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 6010 | { |
| 6011 | bytes[1] = ScreenLines[off + 1]; |
| 6012 | bytes[2] = NUL; |
| 6013 | } |
| 6014 | #endif |
| 6015 | } |
| 6016 | } |
| 6017 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6018 | #ifdef FEAT_MBYTE |
| 6019 | static int screen_comp_differs __ARGS((int, int*)); |
| 6020 | |
| 6021 | /* |
| 6022 | * Return TRUE if composing characters for screen posn "off" differs from |
| 6023 | * composing characters in "u8cc". |
| 6024 | */ |
| 6025 | static int |
| 6026 | screen_comp_differs(off, u8cc) |
| 6027 | int off; |
| 6028 | int *u8cc; |
| 6029 | { |
| 6030 | int i; |
| 6031 | |
| 6032 | for (i = 0; i < Screen_mco; ++i) |
| 6033 | { |
| 6034 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 6035 | return TRUE; |
| 6036 | if (u8cc[i] == 0) |
| 6037 | break; |
| 6038 | } |
| 6039 | return FALSE; |
| 6040 | } |
| 6041 | #endif |
| 6042 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6043 | /* |
| 6044 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 6045 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 6046 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 6047 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 6048 | */ |
| 6049 | void |
| 6050 | screen_puts(text, row, col, attr) |
| 6051 | char_u *text; |
| 6052 | int row; |
| 6053 | int col; |
| 6054 | int attr; |
| 6055 | { |
| 6056 | screen_puts_len(text, -1, row, col, attr); |
| 6057 | } |
| 6058 | |
| 6059 | /* |
| 6060 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 6061 | * a NUL. |
| 6062 | */ |
| 6063 | void |
| 6064 | screen_puts_len(text, len, row, col, attr) |
| 6065 | char_u *text; |
| 6066 | int len; |
| 6067 | int row; |
| 6068 | int col; |
| 6069 | int attr; |
| 6070 | { |
| 6071 | unsigned off; |
| 6072 | char_u *ptr = text; |
| 6073 | int c; |
| 6074 | #ifdef FEAT_MBYTE |
| 6075 | int mbyte_blen = 1; |
| 6076 | int mbyte_cells = 1; |
| 6077 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6078 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6079 | int clear_next_cell = FALSE; |
| 6080 | # ifdef FEAT_ARABIC |
| 6081 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6082 | int pc, nc, nc1; |
| 6083 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6084 | # endif |
| 6085 | #endif |
| 6086 | |
| 6087 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 6088 | return; |
| 6089 | |
| 6090 | off = LineOffset[row] + col; |
| 6091 | while (*ptr != NUL && col < screen_Columns |
| 6092 | && (len < 0 || (int)(ptr - text) < len)) |
| 6093 | { |
| 6094 | c = *ptr; |
| 6095 | #ifdef FEAT_MBYTE |
| 6096 | /* check if this is the first byte of a multibyte */ |
| 6097 | if (has_mbyte) |
| 6098 | { |
| 6099 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6100 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6101 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6102 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6103 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6104 | mbyte_cells = 1; |
| 6105 | else if (enc_dbcs != 0) |
| 6106 | mbyte_cells = mbyte_blen; |
| 6107 | else /* enc_utf8 */ |
| 6108 | { |
| 6109 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6110 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6111 | (int)((text + len) - ptr)); |
| 6112 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6113 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6114 | mbyte_cells = utf_char2cells(u8c); |
| 6115 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 6116 | if (u8c >= 0x10000) |
| 6117 | { |
| 6118 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 6119 | if (attr == 0) |
| 6120 | attr = hl_attr(HLF_8); |
| 6121 | } |
| 6122 | # ifdef FEAT_ARABIC |
| 6123 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 6124 | { |
| 6125 | /* Do Arabic shaping. */ |
| 6126 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 6127 | { |
| 6128 | /* Past end of string to be displayed. */ |
| 6129 | nc = NUL; |
| 6130 | nc1 = NUL; |
| 6131 | } |
| 6132 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6133 | { |
| 6134 | nc = utfc_ptr2char(ptr + mbyte_blen, pcc); |
| 6135 | nc1 = pcc[0]; |
| 6136 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6137 | pc = prev_c; |
| 6138 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6139 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6140 | } |
| 6141 | else |
| 6142 | prev_c = u8c; |
| 6143 | # endif |
| 6144 | } |
| 6145 | } |
| 6146 | #endif |
| 6147 | |
| 6148 | if (ScreenLines[off] != c |
| 6149 | #ifdef FEAT_MBYTE |
| 6150 | || (mbyte_cells == 2 |
| 6151 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 6152 | || (enc_dbcs == DBCS_JPNU |
| 6153 | && c == 0x8e |
| 6154 | && ScreenLines2[off] != ptr[1]) |
| 6155 | || (enc_utf8 |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6156 | && (ScreenLinesUC[off] != (u8char_T)u8c |
| 6157 | || screen_comp_differs(off, u8cc))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6158 | #endif |
| 6159 | || ScreenAttrs[off] != attr |
| 6160 | || exmode_active |
| 6161 | ) |
| 6162 | { |
| 6163 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6164 | /* The bold trick makes a single row of pixels appear in the next |
| 6165 | * character. When a bold character is removed, the next |
| 6166 | * character should be redrawn too. This happens for our own GUI |
| 6167 | * and for some xterms. |
| 6168 | * Force the redraw by setting the attribute to a different value |
| 6169 | * than "attr", the contents of ScreenLines[] may be needed by |
| 6170 | * mb_off2cells() further on. |
| 6171 | * Don't do this for the last drawn character, because the next |
| 6172 | * character may not be redrawn. */ |
| 6173 | if ( |
| 6174 | # ifdef FEAT_GUI |
| 6175 | gui.in_use |
| 6176 | # endif |
| 6177 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6178 | || |
| 6179 | # endif |
| 6180 | # ifdef UNIX |
| 6181 | term_is_xterm |
| 6182 | # endif |
| 6183 | ) |
| 6184 | { |
| 6185 | int n; |
| 6186 | |
| 6187 | n = ScreenAttrs[off]; |
| 6188 | # ifdef FEAT_MBYTE |
| 6189 | if (col + mbyte_cells < screen_Columns |
| 6190 | && (n > HL_ALL || (n & HL_BOLD)) |
| 6191 | && (len < 0 ? ptr[mbyte_blen] != NUL |
| 6192 | : ptr + mbyte_blen < text + len)) |
| 6193 | ScreenAttrs[off + mbyte_cells] = attr + 1; |
| 6194 | # else |
| 6195 | if (col + 1 < screen_Columns |
| 6196 | && (n > HL_ALL || (n & HL_BOLD)) |
| 6197 | && (len < 0 ? ptr[1] != NUL : ptr + 1 < text + len)) |
| 6198 | ScreenLines[off + 1] = 0; |
| 6199 | # endif |
| 6200 | } |
| 6201 | #endif |
| 6202 | #ifdef FEAT_MBYTE |
| 6203 | /* When at the end of the text and overwriting a two-cell |
| 6204 | * character with a one-cell character, need to clear the next |
| 6205 | * cell. Also when overwriting the left halve of a two-cell char |
| 6206 | * with the right halve of a two-cell char. Do this only once |
| 6207 | * (mb_off2cells() may return 2 on the right halve). */ |
| 6208 | if (clear_next_cell) |
| 6209 | clear_next_cell = FALSE; |
| 6210 | else if (has_mbyte |
| 6211 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 6212 | : ptr + mbyte_blen >= text + len) |
| 6213 | && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) |
| 6214 | || (mbyte_cells == 2 |
| 6215 | && (*mb_off2cells)(off) == 1 |
| 6216 | && (*mb_off2cells)(off + 1) > 1))) |
| 6217 | clear_next_cell = TRUE; |
| 6218 | |
| 6219 | /* Make sure we never leave a second byte of a double-byte behind, |
| 6220 | * it confuses mb_off2cells(). */ |
| 6221 | if (enc_dbcs |
| 6222 | && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) |
| 6223 | || (mbyte_cells == 2 |
| 6224 | && (*mb_off2cells)(off) == 1 |
| 6225 | && (*mb_off2cells)(off + 1) > 1))) |
| 6226 | ScreenLines[off + mbyte_blen] = 0; |
| 6227 | #endif |
| 6228 | ScreenLines[off] = c; |
| 6229 | ScreenAttrs[off] = attr; |
| 6230 | #ifdef FEAT_MBYTE |
| 6231 | if (enc_utf8) |
| 6232 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6233 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6234 | ScreenLinesUC[off] = 0; |
| 6235 | else |
| 6236 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6237 | int i; |
| 6238 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6239 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6240 | for (i = 0; i < Screen_mco; ++i) |
| 6241 | { |
| 6242 | ScreenLinesC[i][off] = u8cc[i]; |
| 6243 | if (u8cc[i] == 0) |
| 6244 | break; |
| 6245 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6246 | } |
| 6247 | if (mbyte_cells == 2) |
| 6248 | { |
| 6249 | ScreenLines[off + 1] = 0; |
| 6250 | ScreenAttrs[off + 1] = attr; |
| 6251 | } |
| 6252 | screen_char(off, row, col); |
| 6253 | } |
| 6254 | else if (mbyte_cells == 2) |
| 6255 | { |
| 6256 | ScreenLines[off + 1] = ptr[1]; |
| 6257 | ScreenAttrs[off + 1] = attr; |
| 6258 | screen_char_2(off, row, col); |
| 6259 | } |
| 6260 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6261 | { |
| 6262 | ScreenLines2[off] = ptr[1]; |
| 6263 | screen_char(off, row, col); |
| 6264 | } |
| 6265 | else |
| 6266 | #endif |
| 6267 | screen_char(off, row, col); |
| 6268 | } |
| 6269 | #ifdef FEAT_MBYTE |
| 6270 | if (has_mbyte) |
| 6271 | { |
| 6272 | off += mbyte_cells; |
| 6273 | col += mbyte_cells; |
| 6274 | ptr += mbyte_blen; |
| 6275 | if (clear_next_cell) |
| 6276 | ptr = (char_u *)" "; |
| 6277 | } |
| 6278 | else |
| 6279 | #endif |
| 6280 | { |
| 6281 | ++off; |
| 6282 | ++col; |
| 6283 | ++ptr; |
| 6284 | } |
| 6285 | } |
| 6286 | } |
| 6287 | |
| 6288 | #ifdef FEAT_SEARCH_EXTRA |
| 6289 | /* |
| 6290 | * Prepare for 'searchhl' highlighting. |
| 6291 | */ |
| 6292 | static void |
| 6293 | start_search_hl() |
| 6294 | { |
| 6295 | if (p_hls && !no_hlsearch) |
| 6296 | { |
| 6297 | last_pat_prog(&search_hl.rm); |
| 6298 | search_hl.attr = hl_attr(HLF_L); |
| 6299 | } |
| 6300 | } |
| 6301 | |
| 6302 | /* |
| 6303 | * Clean up for 'searchhl' highlighting. |
| 6304 | */ |
| 6305 | static void |
| 6306 | end_search_hl() |
| 6307 | { |
| 6308 | if (search_hl.rm.regprog != NULL) |
| 6309 | { |
| 6310 | vim_free(search_hl.rm.regprog); |
| 6311 | search_hl.rm.regprog = NULL; |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | /* |
| 6316 | * Advance to the match in window "wp" line "lnum" or past it. |
| 6317 | */ |
| 6318 | static void |
| 6319 | prepare_search_hl(wp, lnum) |
| 6320 | win_T *wp; |
| 6321 | linenr_T lnum; |
| 6322 | { |
| 6323 | match_T *shl; /* points to search_hl or match_hl */ |
| 6324 | int n; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6325 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6326 | |
| 6327 | /* |
| 6328 | * When using a multi-line pattern, start searching at the top |
| 6329 | * of the window or just after a closed fold. |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6330 | * Do this both for search_hl and match_hl[3]. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6331 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6332 | for (i = 3; i >= 0; --i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6333 | { |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 6334 | shl = (i == 3) ? &search_hl : &match_hl[i]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6335 | if (shl->rm.regprog != NULL |
| 6336 | && shl->lnum == 0 |
| 6337 | && re_multiline(shl->rm.regprog)) |
| 6338 | { |
| 6339 | if (shl->first_lnum == 0) |
| 6340 | { |
| 6341 | # ifdef FEAT_FOLDING |
| 6342 | for (shl->first_lnum = lnum; |
| 6343 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 6344 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 6345 | NULL, NULL, TRUE, NULL)) |
| 6346 | break; |
| 6347 | # else |
| 6348 | shl->first_lnum = wp->w_topline; |
| 6349 | # endif |
| 6350 | } |
| 6351 | n = 0; |
| 6352 | while (shl->first_lnum < lnum && shl->rm.regprog != NULL) |
| 6353 | { |
| 6354 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); |
| 6355 | if (shl->lnum != 0) |
| 6356 | { |
| 6357 | shl->first_lnum = shl->lnum |
| 6358 | + shl->rm.endpos[0].lnum |
| 6359 | - shl->rm.startpos[0].lnum; |
| 6360 | n = shl->rm.endpos[0].col; |
| 6361 | } |
| 6362 | else |
| 6363 | { |
| 6364 | ++shl->first_lnum; |
| 6365 | n = 0; |
| 6366 | } |
| 6367 | } |
| 6368 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6369 | } |
| 6370 | } |
| 6371 | |
| 6372 | /* |
| 6373 | * Search for a next 'searchl' or ":match" match. |
| 6374 | * Uses shl->buf. |
| 6375 | * Sets shl->lnum and shl->rm contents. |
| 6376 | * Note: Assumes a previous match is always before "lnum", unless |
| 6377 | * shl->lnum is zero. |
| 6378 | * Careful: Any pointers for buffer lines will become invalid. |
| 6379 | */ |
| 6380 | static void |
| 6381 | next_search_hl(win, shl, lnum, mincol) |
| 6382 | win_T *win; |
| 6383 | match_T *shl; /* points to search_hl or match_hl */ |
| 6384 | linenr_T lnum; |
| 6385 | colnr_T mincol; /* minimal column for a match */ |
| 6386 | { |
| 6387 | linenr_T l; |
| 6388 | colnr_T matchcol; |
| 6389 | long nmatched; |
| 6390 | |
| 6391 | if (shl->lnum != 0) |
| 6392 | { |
| 6393 | /* Check for three situations: |
| 6394 | * 1. If the "lnum" is below a previous match, start a new search. |
| 6395 | * 2. If the previous match includes "mincol", use it. |
| 6396 | * 3. Continue after the previous match. |
| 6397 | */ |
| 6398 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 6399 | if (lnum > l) |
| 6400 | shl->lnum = 0; |
| 6401 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 6402 | return; |
| 6403 | } |
| 6404 | |
| 6405 | /* |
| 6406 | * Repeat searching for a match until one is found that includes "mincol" |
| 6407 | * or none is found in this line. |
| 6408 | */ |
| 6409 | called_emsg = FALSE; |
| 6410 | for (;;) |
| 6411 | { |
| 6412 | /* Three situations: |
| 6413 | * 1. No useful previous match: search from start of line. |
| 6414 | * 2. Not Vi compatible or empty match: continue at next character. |
| 6415 | * Break the loop if this is beyond the end of the line. |
| 6416 | * 3. Vi compatible searching: continue at end of previous match. |
| 6417 | */ |
| 6418 | if (shl->lnum == 0) |
| 6419 | matchcol = 0; |
| 6420 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 6421 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6422 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6423 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 6424 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6425 | |
| 6426 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 6427 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6428 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6429 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6430 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6431 | shl->lnum = 0; |
| 6432 | break; |
| 6433 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6434 | #ifdef FEAT_MBYTE |
| 6435 | if (has_mbyte) |
| 6436 | matchcol += mb_ptr2len(ml); |
| 6437 | else |
| 6438 | #endif |
| 6439 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6440 | } |
| 6441 | else |
| 6442 | matchcol = shl->rm.endpos[0].col; |
| 6443 | |
| 6444 | shl->lnum = lnum; |
| 6445 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol); |
| 6446 | if (called_emsg) |
| 6447 | { |
| 6448 | /* Error while handling regexp: stop using this regexp. */ |
| 6449 | vim_free(shl->rm.regprog); |
| 6450 | shl->rm.regprog = NULL; |
| 6451 | no_hlsearch = TRUE; |
| 6452 | break; |
| 6453 | } |
| 6454 | if (nmatched == 0) |
| 6455 | { |
| 6456 | shl->lnum = 0; /* no match found */ |
| 6457 | break; |
| 6458 | } |
| 6459 | if (shl->rm.startpos[0].lnum > 0 |
| 6460 | || shl->rm.startpos[0].col >= mincol |
| 6461 | || nmatched > 1 |
| 6462 | || shl->rm.endpos[0].col > mincol) |
| 6463 | { |
| 6464 | shl->lnum += shl->rm.startpos[0].lnum; |
| 6465 | break; /* useful match found */ |
| 6466 | } |
| 6467 | } |
| 6468 | } |
| 6469 | #endif |
| 6470 | |
| 6471 | static void |
| 6472 | screen_start_highlight(attr) |
| 6473 | int attr; |
| 6474 | { |
| 6475 | attrentry_T *aep = NULL; |
| 6476 | |
| 6477 | screen_attr = attr; |
| 6478 | if (full_screen |
| 6479 | #ifdef WIN3264 |
| 6480 | && termcap_active |
| 6481 | #endif |
| 6482 | ) |
| 6483 | { |
| 6484 | #ifdef FEAT_GUI |
| 6485 | if (gui.in_use) |
| 6486 | { |
| 6487 | char buf[20]; |
| 6488 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6489 | /* The GUI handles this internally. */ |
| 6490 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6491 | OUT_STR(buf); |
| 6492 | } |
| 6493 | else |
| 6494 | #endif |
| 6495 | { |
| 6496 | if (attr > HL_ALL) /* special HL attr. */ |
| 6497 | { |
| 6498 | if (t_colors > 1) |
| 6499 | aep = syn_cterm_attr2entry(attr); |
| 6500 | else |
| 6501 | aep = syn_term_attr2entry(attr); |
| 6502 | if (aep == NULL) /* did ":syntax clear" */ |
| 6503 | attr = 0; |
| 6504 | else |
| 6505 | attr = aep->ae_attr; |
| 6506 | } |
| 6507 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 6508 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6509 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 6510 | && cterm_normal_fg_bold) |
| 6511 | /* If the Normal FG color has BOLD attribute and the new HL |
| 6512 | * has a FG color defined, clear BOLD. */ |
| 6513 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6514 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 6515 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6516 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 6517 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6518 | out_str(T_US); |
| 6519 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 6520 | out_str(T_CZH); |
| 6521 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 6522 | out_str(T_MR); |
| 6523 | |
| 6524 | /* |
| 6525 | * Output the color or start string after bold etc., in case the |
| 6526 | * bold etc. override the color setting. |
| 6527 | */ |
| 6528 | if (aep != NULL) |
| 6529 | { |
| 6530 | if (t_colors > 1) |
| 6531 | { |
| 6532 | if (aep->ae_u.cterm.fg_color) |
| 6533 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 6534 | if (aep->ae_u.cterm.bg_color) |
| 6535 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 6536 | } |
| 6537 | else |
| 6538 | { |
| 6539 | if (aep->ae_u.term.start != NULL) |
| 6540 | out_str(aep->ae_u.term.start); |
| 6541 | } |
| 6542 | } |
| 6543 | } |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | void |
| 6548 | screen_stop_highlight() |
| 6549 | { |
| 6550 | int do_ME = FALSE; /* output T_ME code */ |
| 6551 | |
| 6552 | if (screen_attr != 0 |
| 6553 | #ifdef WIN3264 |
| 6554 | && termcap_active |
| 6555 | #endif |
| 6556 | ) |
| 6557 | { |
| 6558 | #ifdef FEAT_GUI |
| 6559 | if (gui.in_use) |
| 6560 | { |
| 6561 | char buf[20]; |
| 6562 | |
| 6563 | /* use internal GUI code */ |
| 6564 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 6565 | OUT_STR(buf); |
| 6566 | } |
| 6567 | else |
| 6568 | #endif |
| 6569 | { |
| 6570 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 6571 | { |
| 6572 | attrentry_T *aep; |
| 6573 | |
| 6574 | if (t_colors > 1) |
| 6575 | { |
| 6576 | /* |
| 6577 | * Assume that t_me restores the original colors! |
| 6578 | */ |
| 6579 | aep = syn_cterm_attr2entry(screen_attr); |
| 6580 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 6581 | || aep->ae_u.cterm.bg_color)) |
| 6582 | do_ME = TRUE; |
| 6583 | } |
| 6584 | else |
| 6585 | { |
| 6586 | aep = syn_term_attr2entry(screen_attr); |
| 6587 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 6588 | { |
| 6589 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 6590 | do_ME = TRUE; |
| 6591 | else |
| 6592 | out_str(aep->ae_u.term.stop); |
| 6593 | } |
| 6594 | } |
| 6595 | if (aep == NULL) /* did ":syntax clear" */ |
| 6596 | screen_attr = 0; |
| 6597 | else |
| 6598 | screen_attr = aep->ae_attr; |
| 6599 | } |
| 6600 | |
| 6601 | /* |
| 6602 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 6603 | * same sequence several times. |
| 6604 | */ |
| 6605 | if (screen_attr & HL_STANDOUT) |
| 6606 | { |
| 6607 | if (STRCMP(T_SE, T_ME) == 0) |
| 6608 | do_ME = TRUE; |
| 6609 | else |
| 6610 | out_str(T_SE); |
| 6611 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6612 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6613 | { |
| 6614 | if (STRCMP(T_UE, T_ME) == 0) |
| 6615 | do_ME = TRUE; |
| 6616 | else |
| 6617 | out_str(T_UE); |
| 6618 | } |
| 6619 | if (screen_attr & HL_ITALIC) |
| 6620 | { |
| 6621 | if (STRCMP(T_CZR, T_ME) == 0) |
| 6622 | do_ME = TRUE; |
| 6623 | else |
| 6624 | out_str(T_CZR); |
| 6625 | } |
| 6626 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 6627 | out_str(T_ME); |
| 6628 | |
| 6629 | if (t_colors > 1) |
| 6630 | { |
| 6631 | /* set Normal cterm colors */ |
| 6632 | if (cterm_normal_fg_color != 0) |
| 6633 | term_fg_color(cterm_normal_fg_color - 1); |
| 6634 | if (cterm_normal_bg_color != 0) |
| 6635 | term_bg_color(cterm_normal_bg_color - 1); |
| 6636 | if (cterm_normal_fg_bold) |
| 6637 | out_str(T_MD); |
| 6638 | } |
| 6639 | } |
| 6640 | } |
| 6641 | screen_attr = 0; |
| 6642 | } |
| 6643 | |
| 6644 | /* |
| 6645 | * Reset the colors for a cterm. Used when leaving Vim. |
| 6646 | * The machine specific code may override this again. |
| 6647 | */ |
| 6648 | void |
| 6649 | reset_cterm_colors() |
| 6650 | { |
| 6651 | if (t_colors > 1) |
| 6652 | { |
| 6653 | /* set Normal cterm colors */ |
| 6654 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 6655 | { |
| 6656 | out_str(T_OP); |
| 6657 | screen_attr = -1; |
| 6658 | } |
| 6659 | if (cterm_normal_fg_bold) |
| 6660 | { |
| 6661 | out_str(T_ME); |
| 6662 | screen_attr = -1; |
| 6663 | } |
| 6664 | } |
| 6665 | } |
| 6666 | |
| 6667 | /* |
| 6668 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 6669 | * using the attributes from ScreenAttrs["off"]. |
| 6670 | */ |
| 6671 | static void |
| 6672 | screen_char(off, row, col) |
| 6673 | unsigned off; |
| 6674 | int row; |
| 6675 | int col; |
| 6676 | { |
| 6677 | int attr; |
| 6678 | |
| 6679 | /* Check for illegal values, just in case (could happen just after |
| 6680 | * resizing). */ |
| 6681 | if (row >= screen_Rows || col >= screen_Columns) |
| 6682 | return; |
| 6683 | |
| 6684 | /* Outputting the last character on the screen may scrollup the screen. |
| 6685 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 6686 | if (row == screen_Rows - 1 && col == screen_Columns - 1 |
| 6687 | #ifdef FEAT_RIGHTLEFT |
| 6688 | /* account for first command-line character in rightleft mode */ |
| 6689 | && !cmdmsg_rl |
| 6690 | #endif |
| 6691 | ) |
| 6692 | { |
| 6693 | ScreenAttrs[off] = (sattr_T)-1; |
| 6694 | return; |
| 6695 | } |
| 6696 | |
| 6697 | /* |
| 6698 | * Stop highlighting first, so it's easier to move the cursor. |
| 6699 | */ |
| 6700 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 6701 | if (screen_char_attr != 0) |
| 6702 | attr = screen_char_attr; |
| 6703 | else |
| 6704 | #endif |
| 6705 | attr = ScreenAttrs[off]; |
| 6706 | if (screen_attr != attr) |
| 6707 | screen_stop_highlight(); |
| 6708 | |
| 6709 | windgoto(row, col); |
| 6710 | |
| 6711 | if (screen_attr != attr) |
| 6712 | screen_start_highlight(attr); |
| 6713 | |
| 6714 | #ifdef FEAT_MBYTE |
| 6715 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6716 | { |
| 6717 | char_u buf[MB_MAXBYTES + 1]; |
| 6718 | |
| 6719 | /* Convert UTF-8 character to bytes and write it. */ |
| 6720 | |
| 6721 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 6722 | |
| 6723 | out_str(buf); |
| 6724 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 6725 | ++screen_cur_col; |
| 6726 | } |
| 6727 | else |
| 6728 | #endif |
| 6729 | { |
| 6730 | #ifdef FEAT_MBYTE |
| 6731 | out_flush_check(); |
| 6732 | #endif |
| 6733 | out_char(ScreenLines[off]); |
| 6734 | #ifdef FEAT_MBYTE |
| 6735 | /* double-byte character in single-width cell */ |
| 6736 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6737 | out_char(ScreenLines2[off]); |
| 6738 | #endif |
| 6739 | } |
| 6740 | |
| 6741 | screen_cur_col++; |
| 6742 | } |
| 6743 | |
| 6744 | #ifdef FEAT_MBYTE |
| 6745 | |
| 6746 | /* |
| 6747 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 6748 | * on the screen at position 'row' and 'col'. |
| 6749 | * The attributes of the first byte is used for all. This is required to |
| 6750 | * output the two bytes of a double-byte character with nothing in between. |
| 6751 | */ |
| 6752 | static void |
| 6753 | screen_char_2(off, row, col) |
| 6754 | unsigned off; |
| 6755 | int row; |
| 6756 | int col; |
| 6757 | { |
| 6758 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 6759 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 6760 | return; |
| 6761 | |
| 6762 | /* Outputting the last character on the screen may scrollup the screen. |
| 6763 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 6764 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 6765 | { |
| 6766 | ScreenAttrs[off] = (sattr_T)-1; |
| 6767 | return; |
| 6768 | } |
| 6769 | |
| 6770 | /* Output the first byte normally (positions the cursor), then write the |
| 6771 | * second byte directly. */ |
| 6772 | screen_char(off, row, col); |
| 6773 | out_char(ScreenLines[off + 1]); |
| 6774 | ++screen_cur_col; |
| 6775 | } |
| 6776 | #endif |
| 6777 | |
| 6778 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 6779 | /* |
| 6780 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 6781 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 6782 | */ |
| 6783 | void |
| 6784 | screen_draw_rectangle(row, col, height, width, invert) |
| 6785 | int row; |
| 6786 | int col; |
| 6787 | int height; |
| 6788 | int width; |
| 6789 | int invert; |
| 6790 | { |
| 6791 | int r, c; |
| 6792 | int off; |
| 6793 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 6794 | /* Can't use ScreenLines unless initialized */ |
| 6795 | if (ScreenLines == NULL) |
| 6796 | return; |
| 6797 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6798 | if (invert) |
| 6799 | screen_char_attr = HL_INVERSE; |
| 6800 | for (r = row; r < row + height; ++r) |
| 6801 | { |
| 6802 | off = LineOffset[r]; |
| 6803 | for (c = col; c < col + width; ++c) |
| 6804 | { |
| 6805 | #ifdef FEAT_MBYTE |
| 6806 | if (enc_dbcs != 0 && dbcs_off2cells(off + c) > 1) |
| 6807 | { |
| 6808 | screen_char_2(off + c, r, c); |
| 6809 | ++c; |
| 6810 | } |
| 6811 | else |
| 6812 | #endif |
| 6813 | { |
| 6814 | screen_char(off + c, r, c); |
| 6815 | #ifdef FEAT_MBYTE |
| 6816 | if (utf_off2cells(off + c) > 1) |
| 6817 | ++c; |
| 6818 | #endif |
| 6819 | } |
| 6820 | } |
| 6821 | } |
| 6822 | screen_char_attr = 0; |
| 6823 | } |
| 6824 | #endif |
| 6825 | |
| 6826 | #ifdef FEAT_VERTSPLIT |
| 6827 | /* |
| 6828 | * Redraw the characters for a vertically split window. |
| 6829 | */ |
| 6830 | static void |
| 6831 | redraw_block(row, end, wp) |
| 6832 | int row; |
| 6833 | int end; |
| 6834 | win_T *wp; |
| 6835 | { |
| 6836 | int col; |
| 6837 | int width; |
| 6838 | |
| 6839 | # ifdef FEAT_CLIPBOARD |
| 6840 | clip_may_clear_selection(row, end - 1); |
| 6841 | # endif |
| 6842 | |
| 6843 | if (wp == NULL) |
| 6844 | { |
| 6845 | col = 0; |
| 6846 | width = Columns; |
| 6847 | } |
| 6848 | else |
| 6849 | { |
| 6850 | col = wp->w_wincol; |
| 6851 | width = wp->w_width; |
| 6852 | } |
| 6853 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 6854 | } |
| 6855 | #endif |
| 6856 | |
| 6857 | /* |
| 6858 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 6859 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 6860 | * Use attributes 'attr'. |
| 6861 | */ |
| 6862 | void |
| 6863 | screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) |
| 6864 | int start_row, end_row; |
| 6865 | int start_col, end_col; |
| 6866 | int c1, c2; |
| 6867 | int attr; |
| 6868 | { |
| 6869 | int row; |
| 6870 | int col; |
| 6871 | int off; |
| 6872 | int end_off; |
| 6873 | int did_delete; |
| 6874 | int c; |
| 6875 | int norm_term; |
| 6876 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6877 | int force_next = FALSE; |
| 6878 | #endif |
| 6879 | |
| 6880 | if (end_row > screen_Rows) /* safety check */ |
| 6881 | end_row = screen_Rows; |
| 6882 | if (end_col > screen_Columns) /* safety check */ |
| 6883 | end_col = screen_Columns; |
| 6884 | if (ScreenLines == NULL |
| 6885 | || start_row >= end_row |
| 6886 | || start_col >= end_col) /* nothing to do */ |
| 6887 | return; |
| 6888 | |
| 6889 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 6890 | norm_term = ( |
| 6891 | #ifdef FEAT_GUI |
| 6892 | !gui.in_use && |
| 6893 | #endif |
| 6894 | t_colors <= 1); |
| 6895 | for (row = start_row; row < end_row; ++row) |
| 6896 | { |
| 6897 | /* |
| 6898 | * Try to use delete-line termcap code, when no attributes or in a |
| 6899 | * "normal" terminal, where a bold/italic space is just a |
| 6900 | * space. |
| 6901 | */ |
| 6902 | did_delete = FALSE; |
| 6903 | if (c2 == ' ' |
| 6904 | && end_col == Columns |
| 6905 | && can_clear(T_CE) |
| 6906 | && (attr == 0 |
| 6907 | || (norm_term |
| 6908 | && attr <= HL_ALL |
| 6909 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 6910 | { |
| 6911 | /* |
| 6912 | * check if we really need to clear something |
| 6913 | */ |
| 6914 | col = start_col; |
| 6915 | if (c1 != ' ') /* don't clear first char */ |
| 6916 | ++col; |
| 6917 | |
| 6918 | off = LineOffset[row] + col; |
| 6919 | end_off = LineOffset[row] + end_col; |
| 6920 | |
| 6921 | /* skip blanks (used often, keep it fast!) */ |
| 6922 | #ifdef FEAT_MBYTE |
| 6923 | if (enc_utf8) |
| 6924 | while (off < end_off && ScreenLines[off] == ' ' |
| 6925 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 6926 | ++off; |
| 6927 | else |
| 6928 | #endif |
| 6929 | while (off < end_off && ScreenLines[off] == ' ' |
| 6930 | && ScreenAttrs[off] == 0) |
| 6931 | ++off; |
| 6932 | if (off < end_off) /* something to be cleared */ |
| 6933 | { |
| 6934 | col = off - LineOffset[row]; |
| 6935 | screen_stop_highlight(); |
| 6936 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 6937 | out_str(T_CE); |
| 6938 | screen_start(); /* don't know where cursor is now */ |
| 6939 | col = end_col - col; |
| 6940 | while (col--) /* clear chars in ScreenLines */ |
| 6941 | { |
| 6942 | ScreenLines[off] = ' '; |
| 6943 | #ifdef FEAT_MBYTE |
| 6944 | if (enc_utf8) |
| 6945 | ScreenLinesUC[off] = 0; |
| 6946 | #endif |
| 6947 | ScreenAttrs[off] = 0; |
| 6948 | ++off; |
| 6949 | } |
| 6950 | } |
| 6951 | did_delete = TRUE; /* the chars are cleared now */ |
| 6952 | } |
| 6953 | |
| 6954 | off = LineOffset[row] + start_col; |
| 6955 | c = c1; |
| 6956 | for (col = start_col; col < end_col; ++col) |
| 6957 | { |
| 6958 | if (ScreenLines[off] != c |
| 6959 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6960 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 6961 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6962 | #endif |
| 6963 | || ScreenAttrs[off] != attr |
| 6964 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6965 | || force_next |
| 6966 | #endif |
| 6967 | ) |
| 6968 | { |
| 6969 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6970 | /* The bold trick may make a single row of pixels appear in |
| 6971 | * the next character. When a bold character is removed, the |
| 6972 | * next character should be redrawn too. This happens for our |
| 6973 | * own GUI and for some xterms. */ |
| 6974 | if ( |
| 6975 | # ifdef FEAT_GUI |
| 6976 | gui.in_use |
| 6977 | # endif |
| 6978 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6979 | || |
| 6980 | # endif |
| 6981 | # ifdef UNIX |
| 6982 | term_is_xterm |
| 6983 | # endif |
| 6984 | ) |
| 6985 | { |
| 6986 | if (ScreenLines[off] != ' ' |
| 6987 | && (ScreenAttrs[off] > HL_ALL |
| 6988 | || ScreenAttrs[off] & HL_BOLD)) |
| 6989 | force_next = TRUE; |
| 6990 | else |
| 6991 | force_next = FALSE; |
| 6992 | } |
| 6993 | #endif |
| 6994 | ScreenLines[off] = c; |
| 6995 | #ifdef FEAT_MBYTE |
| 6996 | if (enc_utf8) |
| 6997 | { |
| 6998 | if (c >= 0x80) |
| 6999 | { |
| 7000 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7001 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7002 | } |
| 7003 | else |
| 7004 | ScreenLinesUC[off] = 0; |
| 7005 | } |
| 7006 | #endif |
| 7007 | ScreenAttrs[off] = attr; |
| 7008 | if (!did_delete || c != ' ') |
| 7009 | screen_char(off, row, col); |
| 7010 | } |
| 7011 | ++off; |
| 7012 | if (col == start_col) |
| 7013 | { |
| 7014 | if (did_delete) |
| 7015 | break; |
| 7016 | c = c2; |
| 7017 | } |
| 7018 | } |
| 7019 | if (end_col == Columns) |
| 7020 | LineWraps[row] = FALSE; |
| 7021 | if (row == Rows - 1) /* overwritten the command line */ |
| 7022 | { |
| 7023 | redraw_cmdline = TRUE; |
| 7024 | if (c1 == ' ' && c2 == ' ') |
| 7025 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7026 | if (start_col == 0) |
| 7027 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7028 | } |
| 7029 | } |
| 7030 | } |
| 7031 | |
| 7032 | /* |
| 7033 | * Check if there should be a delay. Used before clearing or redrawing the |
| 7034 | * screen or the command line. |
| 7035 | */ |
| 7036 | void |
| 7037 | check_for_delay(check_msg_scroll) |
| 7038 | int check_msg_scroll; |
| 7039 | { |
| 7040 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 7041 | && !did_wait_return |
| 7042 | && emsg_silent == 0) |
| 7043 | { |
| 7044 | out_flush(); |
| 7045 | ui_delay(1000L, TRUE); |
| 7046 | emsg_on_display = FALSE; |
| 7047 | if (check_msg_scroll) |
| 7048 | msg_scroll = FALSE; |
| 7049 | } |
| 7050 | } |
| 7051 | |
| 7052 | /* |
| 7053 | * screen_valid - allocate screen buffers if size changed |
| 7054 | * If "clear" is TRUE: clear screen if it has been resized. |
| 7055 | * Returns TRUE if there is a valid screen to write to. |
| 7056 | * Returns FALSE when starting up and screen not initialized yet. |
| 7057 | */ |
| 7058 | int |
| 7059 | screen_valid(clear) |
| 7060 | int clear; |
| 7061 | { |
| 7062 | screenalloc(clear); /* allocate screen buffers if size changed */ |
| 7063 | return (ScreenLines != NULL); |
| 7064 | } |
| 7065 | |
| 7066 | /* |
| 7067 | * Resize the shell to Rows and Columns. |
| 7068 | * Allocate ScreenLines[] and associated items. |
| 7069 | * |
| 7070 | * There may be some time between setting Rows and Columns and (re)allocating |
| 7071 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 7072 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 7073 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 7074 | * final size of the shell is needed. |
| 7075 | */ |
| 7076 | void |
| 7077 | screenalloc(clear) |
| 7078 | int clear; |
| 7079 | { |
| 7080 | int new_row, old_row; |
| 7081 | #ifdef FEAT_GUI |
| 7082 | int old_Rows; |
| 7083 | #endif |
| 7084 | win_T *wp; |
| 7085 | int outofmem = FALSE; |
| 7086 | int len; |
| 7087 | schar_T *new_ScreenLines; |
| 7088 | #ifdef FEAT_MBYTE |
| 7089 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7090 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7091 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7092 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7093 | #endif |
| 7094 | sattr_T *new_ScreenAttrs; |
| 7095 | unsigned *new_LineOffset; |
| 7096 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7097 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7098 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7099 | tabpage_T *tp; |
| 7100 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7101 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7102 | static int did_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7103 | |
| 7104 | /* |
| 7105 | * Allocation of the screen buffers is done only when the size changes and |
| 7106 | * when Rows and Columns have been set and we have started doing full |
| 7107 | * screen stuff. |
| 7108 | */ |
| 7109 | if ((ScreenLines != NULL |
| 7110 | && Rows == screen_Rows |
| 7111 | && Columns == screen_Columns |
| 7112 | #ifdef FEAT_MBYTE |
| 7113 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 7114 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7115 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7116 | #endif |
| 7117 | ) |
| 7118 | || Rows == 0 |
| 7119 | || Columns == 0 |
| 7120 | || (!full_screen && ScreenLines == NULL)) |
| 7121 | return; |
| 7122 | |
| 7123 | /* |
| 7124 | * It's possible that we produce an out-of-memory message below, which |
| 7125 | * will cause this function to be called again. To break the loop, just |
| 7126 | * return here. |
| 7127 | */ |
| 7128 | if (entered) |
| 7129 | return; |
| 7130 | entered = TRUE; |
| 7131 | |
| 7132 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 7133 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7134 | comp_col(); /* recompute columns for shown command and ruler */ |
| 7135 | |
| 7136 | /* |
| 7137 | * We're changing the size of the screen. |
| 7138 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 7139 | * - Move lines from the old arrays into the new arrays, clear extra |
| 7140 | * lines (unless the screen is going to be cleared). |
| 7141 | * - Free the old arrays. |
| 7142 | * |
| 7143 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 7144 | * Continuing with the old ScreenLines may result in a crash, because the |
| 7145 | * size is wrong. |
| 7146 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7147 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7148 | win_free_lsize(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7149 | |
| 7150 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 7151 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 7152 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7153 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7154 | if (enc_utf8) |
| 7155 | { |
| 7156 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 7157 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7158 | for (i = 0; i < p_mco; ++i) |
| 7159 | new_ScreenLinesC[i] = (u8char_T *)lalloc((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7160 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 7161 | } |
| 7162 | if (enc_dbcs == DBCS_JPNU) |
| 7163 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 7164 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 7165 | #endif |
| 7166 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 7167 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 7168 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 7169 | Rows * sizeof(unsigned)), FALSE); |
| 7170 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7171 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7172 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7173 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7174 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7175 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7176 | { |
| 7177 | if (win_alloc_lines(wp) == FAIL) |
| 7178 | { |
| 7179 | outofmem = TRUE; |
| 7180 | #ifdef FEAT_WINDOWS |
| 7181 | break; |
| 7182 | #endif |
| 7183 | } |
| 7184 | } |
| 7185 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7186 | #ifdef FEAT_MBYTE |
| 7187 | for (i = 0; i < p_mco; ++i) |
| 7188 | if (new_ScreenLinesC[i] == NULL) |
| 7189 | break; |
| 7190 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7191 | if (new_ScreenLines == NULL |
| 7192 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7193 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7194 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 7195 | #endif |
| 7196 | || new_ScreenAttrs == NULL |
| 7197 | || new_LineOffset == NULL |
| 7198 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7199 | #ifdef FEAT_WINDOWS |
| 7200 | || new_TabPageIdxs == NULL |
| 7201 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7202 | || outofmem) |
| 7203 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7204 | if (ScreenLines != NULL || !did_outofmem_msg) |
| 7205 | { |
| 7206 | /* guess the size */ |
| 7207 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 7208 | |
| 7209 | /* Remember we did this to avoid getting outofmem messages over |
| 7210 | * and over again. */ |
| 7211 | did_outofmem_msg = TRUE; |
| 7212 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7213 | vim_free(new_ScreenLines); |
| 7214 | new_ScreenLines = NULL; |
| 7215 | #ifdef FEAT_MBYTE |
| 7216 | vim_free(new_ScreenLinesUC); |
| 7217 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7218 | for (i = 0; i < p_mco; ++i) |
| 7219 | { |
| 7220 | vim_free(new_ScreenLinesC[i]); |
| 7221 | new_ScreenLinesC[i] = NULL; |
| 7222 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7223 | vim_free(new_ScreenLines2); |
| 7224 | new_ScreenLines2 = NULL; |
| 7225 | #endif |
| 7226 | vim_free(new_ScreenAttrs); |
| 7227 | new_ScreenAttrs = NULL; |
| 7228 | vim_free(new_LineOffset); |
| 7229 | new_LineOffset = NULL; |
| 7230 | vim_free(new_LineWraps); |
| 7231 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7232 | #ifdef FEAT_WINDOWS |
| 7233 | vim_free(new_TabPageIdxs); |
| 7234 | new_TabPageIdxs = NULL; |
| 7235 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7236 | } |
| 7237 | else |
| 7238 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7239 | did_outofmem_msg = FALSE; |
| 7240 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7241 | for (new_row = 0; new_row < Rows; ++new_row) |
| 7242 | { |
| 7243 | new_LineOffset[new_row] = new_row * Columns; |
| 7244 | new_LineWraps[new_row] = FALSE; |
| 7245 | |
| 7246 | /* |
| 7247 | * If the screen is not going to be cleared, copy as much as |
| 7248 | * possible from the old screen to the new one and clear the rest |
| 7249 | * (used when resizing the window at the "--more--" prompt or when |
| 7250 | * executing an external command, for the GUI). |
| 7251 | */ |
| 7252 | if (!clear) |
| 7253 | { |
| 7254 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 7255 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 7256 | #ifdef FEAT_MBYTE |
| 7257 | if (enc_utf8) |
| 7258 | { |
| 7259 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 7260 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7261 | for (i = 0; i < p_mco; ++i) |
| 7262 | (void)vim_memset(new_ScreenLinesC[i] |
| 7263 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7264 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 7265 | } |
| 7266 | if (enc_dbcs == DBCS_JPNU) |
| 7267 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 7268 | 0, (size_t)Columns * sizeof(schar_T)); |
| 7269 | #endif |
| 7270 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 7271 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 7272 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7273 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7274 | { |
| 7275 | if (screen_Columns < Columns) |
| 7276 | len = screen_Columns; |
| 7277 | else |
| 7278 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 7279 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 7280 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7281 | * may be invalid now. Also when p_mco changes. */ |
| 7282 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 7283 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 7284 | #endif |
| 7285 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 7286 | ScreenLines + LineOffset[old_row], |
| 7287 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7288 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7289 | if (enc_utf8 && ScreenLinesUC != NULL |
| 7290 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7291 | { |
| 7292 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 7293 | ScreenLinesUC + LineOffset[old_row], |
| 7294 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7295 | for (i = 0; i < p_mco; ++i) |
| 7296 | mch_memmove(new_ScreenLinesC[i] |
| 7297 | + new_LineOffset[new_row], |
| 7298 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7299 | (size_t)len * sizeof(u8char_T)); |
| 7300 | } |
| 7301 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 7302 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 7303 | ScreenLines2 + LineOffset[old_row], |
| 7304 | (size_t)len * sizeof(schar_T)); |
| 7305 | #endif |
| 7306 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 7307 | ScreenAttrs + LineOffset[old_row], |
| 7308 | (size_t)len * sizeof(sattr_T)); |
| 7309 | } |
| 7310 | } |
| 7311 | } |
| 7312 | /* Use the last line of the screen for the current line. */ |
| 7313 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 7314 | } |
| 7315 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7316 | free_screenlines(); |
| 7317 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7318 | ScreenLines = new_ScreenLines; |
| 7319 | #ifdef FEAT_MBYTE |
| 7320 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7321 | for (i = 0; i < p_mco; ++i) |
| 7322 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 7323 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7324 | ScreenLines2 = new_ScreenLines2; |
| 7325 | #endif |
| 7326 | ScreenAttrs = new_ScreenAttrs; |
| 7327 | LineOffset = new_LineOffset; |
| 7328 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7329 | #ifdef FEAT_WINDOWS |
| 7330 | TabPageIdxs = new_TabPageIdxs; |
| 7331 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7332 | |
| 7333 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 7334 | * size of ScreenLines[]. Set them before calling anything. */ |
| 7335 | #ifdef FEAT_GUI |
| 7336 | old_Rows = screen_Rows; |
| 7337 | #endif |
| 7338 | screen_Rows = Rows; |
| 7339 | screen_Columns = Columns; |
| 7340 | |
| 7341 | must_redraw = CLEAR; /* need to clear the screen later */ |
| 7342 | if (clear) |
| 7343 | screenclear2(); |
| 7344 | |
| 7345 | #ifdef FEAT_GUI |
| 7346 | else if (gui.in_use |
| 7347 | && !gui.starting |
| 7348 | && ScreenLines != NULL |
| 7349 | && old_Rows != Rows) |
| 7350 | { |
| 7351 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 7352 | /* |
| 7353 | * Adjust the position of the cursor, for when executing an external |
| 7354 | * command. |
| 7355 | */ |
| 7356 | if (msg_row >= Rows) /* Rows got smaller */ |
| 7357 | msg_row = Rows - 1; /* put cursor at last row */ |
| 7358 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 7359 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 7360 | if (msg_col >= Columns) /* Columns got smaller */ |
| 7361 | msg_col = Columns - 1; /* put cursor at last column */ |
| 7362 | } |
| 7363 | #endif |
| 7364 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7365 | entered = FALSE; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 7366 | |
| 7367 | #ifdef FEAT_AUTOCMD |
| 7368 | if (starting == 0) |
| 7369 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
| 7370 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7371 | } |
| 7372 | |
| 7373 | void |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7374 | free_screenlines() |
| 7375 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7376 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7377 | int i; |
| 7378 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7379 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7380 | for (i = 0; i < Screen_mco; ++i) |
| 7381 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7382 | vim_free(ScreenLines2); |
| 7383 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7384 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7385 | vim_free(ScreenAttrs); |
| 7386 | vim_free(LineOffset); |
| 7387 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7388 | #ifdef FEAT_WINDOWS |
| 7389 | vim_free(TabPageIdxs); |
| 7390 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 7391 | } |
| 7392 | |
| 7393 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7394 | screenclear() |
| 7395 | { |
| 7396 | check_for_delay(FALSE); |
| 7397 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 7398 | screenclear2(); /* clear the screen */ |
| 7399 | } |
| 7400 | |
| 7401 | static void |
| 7402 | screenclear2() |
| 7403 | { |
| 7404 | int i; |
| 7405 | |
| 7406 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 7407 | #ifdef FEAT_GUI |
| 7408 | || (gui.in_use && gui.starting) |
| 7409 | #endif |
| 7410 | ) |
| 7411 | return; |
| 7412 | |
| 7413 | #ifdef FEAT_GUI |
| 7414 | if (!gui.in_use) |
| 7415 | #endif |
| 7416 | screen_attr = -1; /* force setting the Normal colors */ |
| 7417 | screen_stop_highlight(); /* don't want highlighting here */ |
| 7418 | |
| 7419 | #ifdef FEAT_CLIPBOARD |
| 7420 | /* disable selection without redrawing it */ |
| 7421 | clip_scroll_selection(9999); |
| 7422 | #endif |
| 7423 | |
| 7424 | /* blank out ScreenLines */ |
| 7425 | for (i = 0; i < Rows; ++i) |
| 7426 | { |
| 7427 | lineclear(LineOffset[i], (int)Columns); |
| 7428 | LineWraps[i] = FALSE; |
| 7429 | } |
| 7430 | |
| 7431 | if (can_clear(T_CL)) |
| 7432 | { |
| 7433 | out_str(T_CL); /* clear the display */ |
| 7434 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7435 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7436 | } |
| 7437 | else |
| 7438 | { |
| 7439 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 7440 | for (i = 0; i < Rows; ++i) |
| 7441 | lineinvalid(LineOffset[i], (int)Columns); |
| 7442 | clear_cmdline = TRUE; |
| 7443 | } |
| 7444 | |
| 7445 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 7446 | |
| 7447 | win_rest_invalid(firstwin); |
| 7448 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 7449 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 7450 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 7451 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7452 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 7453 | must_redraw = NOT_VALID; |
| 7454 | compute_cmdrow(); |
| 7455 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 7456 | msg_col = 0; |
| 7457 | screen_start(); /* don't know where cursor is now */ |
| 7458 | msg_scrolled = 0; /* can't scroll back */ |
| 7459 | msg_didany = FALSE; |
| 7460 | msg_didout = FALSE; |
| 7461 | } |
| 7462 | |
| 7463 | /* |
| 7464 | * Clear one line in ScreenLines. |
| 7465 | */ |
| 7466 | static void |
| 7467 | lineclear(off, width) |
| 7468 | unsigned off; |
| 7469 | int width; |
| 7470 | { |
| 7471 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 7472 | #ifdef FEAT_MBYTE |
| 7473 | if (enc_utf8) |
| 7474 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 7475 | (size_t)width * sizeof(u8char_T)); |
| 7476 | #endif |
| 7477 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 7478 | } |
| 7479 | |
| 7480 | /* |
| 7481 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 7482 | * invalid value. |
| 7483 | */ |
| 7484 | static void |
| 7485 | lineinvalid(off, width) |
| 7486 | unsigned off; |
| 7487 | int width; |
| 7488 | { |
| 7489 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 7490 | } |
| 7491 | |
| 7492 | #ifdef FEAT_VERTSPLIT |
| 7493 | /* |
| 7494 | * Copy part of a Screenline for vertically split window "wp". |
| 7495 | */ |
| 7496 | static void |
| 7497 | linecopy(to, from, wp) |
| 7498 | int to; |
| 7499 | int from; |
| 7500 | win_T *wp; |
| 7501 | { |
| 7502 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 7503 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 7504 | |
| 7505 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 7506 | wp->w_width * sizeof(schar_T)); |
| 7507 | # ifdef FEAT_MBYTE |
| 7508 | if (enc_utf8) |
| 7509 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7510 | int i; |
| 7511 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7512 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 7513 | wp->w_width * 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(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 7516 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7517 | } |
| 7518 | if (enc_dbcs == DBCS_JPNU) |
| 7519 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 7520 | wp->w_width * sizeof(schar_T)); |
| 7521 | # endif |
| 7522 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 7523 | wp->w_width * sizeof(sattr_T)); |
| 7524 | } |
| 7525 | #endif |
| 7526 | |
| 7527 | /* |
| 7528 | * Return TRUE if clearing with term string "p" would work. |
| 7529 | * It can't work when the string is empty or it won't set the right background. |
| 7530 | */ |
| 7531 | int |
| 7532 | can_clear(p) |
| 7533 | char_u *p; |
| 7534 | { |
| 7535 | return (*p != NUL && (t_colors <= 1 |
| 7536 | #ifdef FEAT_GUI |
| 7537 | || gui.in_use |
| 7538 | #endif |
| 7539 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 7540 | } |
| 7541 | |
| 7542 | /* |
| 7543 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 7544 | * something directly to the screen (shell commands) or a terminal control |
| 7545 | * code. |
| 7546 | */ |
| 7547 | void |
| 7548 | screen_start() |
| 7549 | { |
| 7550 | screen_cur_row = screen_cur_col = 9999; |
| 7551 | } |
| 7552 | |
| 7553 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7554 | * Move the cursor to position "row","col" in the screen. |
| 7555 | * This tries to find the most efficient way to move, minimizing the number of |
| 7556 | * characters sent to the terminal. |
| 7557 | */ |
| 7558 | void |
| 7559 | windgoto(row, col) |
| 7560 | int row; |
| 7561 | int col; |
| 7562 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7563 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7564 | int i; |
| 7565 | int plan; |
| 7566 | int cost; |
| 7567 | int wouldbe_col; |
| 7568 | int noinvcurs; |
| 7569 | char_u *bs; |
| 7570 | int goto_cost; |
| 7571 | int attr; |
| 7572 | |
| 7573 | #define GOTO_COST 7 /* asssume a term_windgoto() takes about 7 chars */ |
| 7574 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 7575 | |
| 7576 | #define PLAN_LE 1 |
| 7577 | #define PLAN_CR 2 |
| 7578 | #define PLAN_NL 3 |
| 7579 | #define PLAN_WRITE 4 |
| 7580 | /* Can't use ScreenLines unless initialized */ |
| 7581 | if (ScreenLines == NULL) |
| 7582 | return; |
| 7583 | |
| 7584 | if (col != screen_cur_col || row != screen_cur_row) |
| 7585 | { |
| 7586 | /* Check for valid position. */ |
| 7587 | if (row < 0) /* window without text lines? */ |
| 7588 | row = 0; |
| 7589 | if (row >= screen_Rows) |
| 7590 | row = screen_Rows - 1; |
| 7591 | if (col >= screen_Columns) |
| 7592 | col = screen_Columns - 1; |
| 7593 | |
| 7594 | /* check if no cursor movement is allowed in highlight mode */ |
| 7595 | if (screen_attr && *T_MS == NUL) |
| 7596 | noinvcurs = HIGHL_COST; |
| 7597 | else |
| 7598 | noinvcurs = 0; |
| 7599 | goto_cost = GOTO_COST + noinvcurs; |
| 7600 | |
| 7601 | /* |
| 7602 | * Plan how to do the positioning: |
| 7603 | * 1. Use CR to move it to column 0, same row. |
| 7604 | * 2. Use T_LE to move it a few columns to the left. |
| 7605 | * 3. Use NL to move a few lines down, column 0. |
| 7606 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 7607 | * |
| 7608 | * Don't do this if the cursor went beyond the last column, the cursor |
| 7609 | * position is unknown then (some terminals wrap, some don't ) |
| 7610 | * |
| 7611 | * First check if the highlighting attibutes allow us to write |
| 7612 | * characters to move the cursor to the right. |
| 7613 | */ |
| 7614 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 7615 | { |
| 7616 | /* |
| 7617 | * If the cursor is in the same row, bigger col, we can use CR |
| 7618 | * or T_LE. |
| 7619 | */ |
| 7620 | bs = NULL; /* init for GCC */ |
| 7621 | attr = screen_attr; |
| 7622 | if (row == screen_cur_row && col < screen_cur_col) |
| 7623 | { |
| 7624 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 7625 | if (*T_LE) |
| 7626 | bs = T_LE; /* "cursor left" */ |
| 7627 | else |
| 7628 | bs = T_BC; /* "backspace character (old) */ |
| 7629 | if (*bs) |
| 7630 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 7631 | else |
| 7632 | cost = 999; |
| 7633 | if (col + 1 < cost) /* using CR is less characters */ |
| 7634 | { |
| 7635 | plan = PLAN_CR; |
| 7636 | wouldbe_col = 0; |
| 7637 | cost = 1; /* CR is just one character */ |
| 7638 | } |
| 7639 | else |
| 7640 | { |
| 7641 | plan = PLAN_LE; |
| 7642 | wouldbe_col = col; |
| 7643 | } |
| 7644 | if (noinvcurs) /* will stop highlighting */ |
| 7645 | { |
| 7646 | cost += noinvcurs; |
| 7647 | attr = 0; |
| 7648 | } |
| 7649 | } |
| 7650 | |
| 7651 | /* |
| 7652 | * If the cursor is above where we want to be, we can use CR LF. |
| 7653 | */ |
| 7654 | else if (row > screen_cur_row) |
| 7655 | { |
| 7656 | plan = PLAN_NL; |
| 7657 | wouldbe_col = 0; |
| 7658 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 7659 | if (noinvcurs) /* will stop highlighting */ |
| 7660 | { |
| 7661 | cost += noinvcurs; |
| 7662 | attr = 0; |
| 7663 | } |
| 7664 | } |
| 7665 | |
| 7666 | /* |
| 7667 | * If the cursor is in the same row, smaller col, just use write. |
| 7668 | */ |
| 7669 | else |
| 7670 | { |
| 7671 | plan = PLAN_WRITE; |
| 7672 | wouldbe_col = screen_cur_col; |
| 7673 | cost = 0; |
| 7674 | } |
| 7675 | |
| 7676 | /* |
| 7677 | * Check if any characters that need to be written have the |
| 7678 | * correct attributes. Also avoid UTF-8 characters. |
| 7679 | */ |
| 7680 | i = col - wouldbe_col; |
| 7681 | if (i > 0) |
| 7682 | cost += i; |
| 7683 | if (cost < goto_cost && i > 0) |
| 7684 | { |
| 7685 | /* |
| 7686 | * Check if the attributes are correct without additionally |
| 7687 | * stopping highlighting. |
| 7688 | */ |
| 7689 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 7690 | while (i && *p++ == attr) |
| 7691 | --i; |
| 7692 | if (i != 0) |
| 7693 | { |
| 7694 | /* |
| 7695 | * Try if it works when highlighting is stopped here. |
| 7696 | */ |
| 7697 | if (*--p == 0) |
| 7698 | { |
| 7699 | cost += noinvcurs; |
| 7700 | while (i && *p++ == 0) |
| 7701 | --i; |
| 7702 | } |
| 7703 | if (i != 0) |
| 7704 | cost = 999; /* different attributes, don't do it */ |
| 7705 | } |
| 7706 | #ifdef FEAT_MBYTE |
| 7707 | if (enc_utf8) |
| 7708 | { |
| 7709 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 7710 | for (i = wouldbe_col; i < col; ++i) |
| 7711 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 7712 | { |
| 7713 | cost = 999; |
| 7714 | break; |
| 7715 | } |
| 7716 | } |
| 7717 | #endif |
| 7718 | } |
| 7719 | |
| 7720 | /* |
| 7721 | * We can do it without term_windgoto()! |
| 7722 | */ |
| 7723 | if (cost < goto_cost) |
| 7724 | { |
| 7725 | if (plan == PLAN_LE) |
| 7726 | { |
| 7727 | if (noinvcurs) |
| 7728 | screen_stop_highlight(); |
| 7729 | while (screen_cur_col > col) |
| 7730 | { |
| 7731 | out_str(bs); |
| 7732 | --screen_cur_col; |
| 7733 | } |
| 7734 | } |
| 7735 | else if (plan == PLAN_CR) |
| 7736 | { |
| 7737 | if (noinvcurs) |
| 7738 | screen_stop_highlight(); |
| 7739 | out_char('\r'); |
| 7740 | screen_cur_col = 0; |
| 7741 | } |
| 7742 | else if (plan == PLAN_NL) |
| 7743 | { |
| 7744 | if (noinvcurs) |
| 7745 | screen_stop_highlight(); |
| 7746 | while (screen_cur_row < row) |
| 7747 | { |
| 7748 | out_char('\n'); |
| 7749 | ++screen_cur_row; |
| 7750 | } |
| 7751 | screen_cur_col = 0; |
| 7752 | } |
| 7753 | |
| 7754 | i = col - screen_cur_col; |
| 7755 | if (i > 0) |
| 7756 | { |
| 7757 | /* |
| 7758 | * Use cursor-right if it's one character only. Avoids |
| 7759 | * removing a line of pixels from the last bold char, when |
| 7760 | * using the bold trick in the GUI. |
| 7761 | */ |
| 7762 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 7763 | { |
| 7764 | while (i-- > 0) |
| 7765 | out_char(*T_ND); |
| 7766 | } |
| 7767 | else |
| 7768 | { |
| 7769 | int off; |
| 7770 | |
| 7771 | off = LineOffset[row] + screen_cur_col; |
| 7772 | while (i-- > 0) |
| 7773 | { |
| 7774 | if (ScreenAttrs[off] != screen_attr) |
| 7775 | screen_stop_highlight(); |
| 7776 | #ifdef FEAT_MBYTE |
| 7777 | out_flush_check(); |
| 7778 | #endif |
| 7779 | out_char(ScreenLines[off]); |
| 7780 | #ifdef FEAT_MBYTE |
| 7781 | if (enc_dbcs == DBCS_JPNU |
| 7782 | && ScreenLines[off] == 0x8e) |
| 7783 | out_char(ScreenLines2[off]); |
| 7784 | #endif |
| 7785 | ++off; |
| 7786 | } |
| 7787 | } |
| 7788 | } |
| 7789 | } |
| 7790 | } |
| 7791 | else |
| 7792 | cost = 999; |
| 7793 | |
| 7794 | if (cost >= goto_cost) |
| 7795 | { |
| 7796 | if (noinvcurs) |
| 7797 | screen_stop_highlight(); |
| 7798 | if (row == screen_cur_row && (col > screen_cur_col) && |
| 7799 | *T_CRI != NUL) |
| 7800 | term_cursor_right(col - screen_cur_col); |
| 7801 | else |
| 7802 | term_windgoto(row, col); |
| 7803 | } |
| 7804 | screen_cur_row = row; |
| 7805 | screen_cur_col = col; |
| 7806 | } |
| 7807 | } |
| 7808 | |
| 7809 | /* |
| 7810 | * Set cursor to its position in the current window. |
| 7811 | */ |
| 7812 | void |
| 7813 | setcursor() |
| 7814 | { |
| 7815 | if (redrawing()) |
| 7816 | { |
| 7817 | validate_cursor(); |
| 7818 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 7819 | W_WINCOL(curwin) + ( |
| 7820 | #ifdef FEAT_RIGHTLEFT |
| 7821 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 7822 | # ifdef FEAT_MBYTE |
| 7823 | has_mbyte ? (*mb_ptr2cells)(ml_get_cursor()) : |
| 7824 | # endif |
| 7825 | 1)) : |
| 7826 | #endif |
| 7827 | curwin->w_wcol)); |
| 7828 | } |
| 7829 | } |
| 7830 | |
| 7831 | |
| 7832 | /* |
| 7833 | * insert 'line_count' lines at 'row' in window 'wp' |
| 7834 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 7835 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 7836 | * scrolling. |
| 7837 | * Returns FAIL if the lines are not inserted, OK for success. |
| 7838 | */ |
| 7839 | int |
| 7840 | win_ins_lines(wp, row, line_count, invalid, mayclear) |
| 7841 | win_T *wp; |
| 7842 | int row; |
| 7843 | int line_count; |
| 7844 | int invalid; |
| 7845 | int mayclear; |
| 7846 | { |
| 7847 | int did_delete; |
| 7848 | int nextrow; |
| 7849 | int lastrow; |
| 7850 | int retval; |
| 7851 | |
| 7852 | if (invalid) |
| 7853 | wp->w_lines_valid = 0; |
| 7854 | |
| 7855 | if (wp->w_height < 5) |
| 7856 | return FAIL; |
| 7857 | |
| 7858 | if (line_count > wp->w_height - row) |
| 7859 | line_count = wp->w_height - row; |
| 7860 | |
| 7861 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 7862 | if (retval != MAYBE) |
| 7863 | return retval; |
| 7864 | |
| 7865 | /* |
| 7866 | * If there is a next window or a status line, we first try to delete the |
| 7867 | * lines at the bottom to avoid messing what is after the window. |
| 7868 | * If this fails and there are following windows, don't do anything to avoid |
| 7869 | * messing up those windows, better just redraw. |
| 7870 | */ |
| 7871 | did_delete = FALSE; |
| 7872 | #ifdef FEAT_WINDOWS |
| 7873 | if (wp->w_next != NULL || wp->w_status_height) |
| 7874 | { |
| 7875 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 7876 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 7877 | did_delete = TRUE; |
| 7878 | else if (wp->w_next) |
| 7879 | return FAIL; |
| 7880 | } |
| 7881 | #endif |
| 7882 | /* |
| 7883 | * if no lines deleted, blank the lines that will end up below the window |
| 7884 | */ |
| 7885 | if (!did_delete) |
| 7886 | { |
| 7887 | #ifdef FEAT_WINDOWS |
| 7888 | wp->w_redr_status = TRUE; |
| 7889 | #endif |
| 7890 | redraw_cmdline = TRUE; |
| 7891 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 7892 | lastrow = nextrow + line_count; |
| 7893 | if (lastrow > Rows) |
| 7894 | lastrow = Rows; |
| 7895 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 7896 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 7897 | ' ', ' ', 0); |
| 7898 | } |
| 7899 | |
| 7900 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 7901 | == FAIL) |
| 7902 | { |
| 7903 | /* deletion will have messed up other windows */ |
| 7904 | if (did_delete) |
| 7905 | { |
| 7906 | #ifdef FEAT_WINDOWS |
| 7907 | wp->w_redr_status = TRUE; |
| 7908 | #endif |
| 7909 | win_rest_invalid(W_NEXT(wp)); |
| 7910 | } |
| 7911 | return FAIL; |
| 7912 | } |
| 7913 | |
| 7914 | return OK; |
| 7915 | } |
| 7916 | |
| 7917 | /* |
| 7918 | * delete "line_count" window lines at "row" in window "wp" |
| 7919 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 7920 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 7921 | * scrolling |
| 7922 | * Return OK for success, FAIL if the lines are not deleted. |
| 7923 | */ |
| 7924 | int |
| 7925 | win_del_lines(wp, row, line_count, invalid, mayclear) |
| 7926 | win_T *wp; |
| 7927 | int row; |
| 7928 | int line_count; |
| 7929 | int invalid; |
| 7930 | int mayclear; |
| 7931 | { |
| 7932 | int retval; |
| 7933 | |
| 7934 | if (invalid) |
| 7935 | wp->w_lines_valid = 0; |
| 7936 | |
| 7937 | if (line_count > wp->w_height - row) |
| 7938 | line_count = wp->w_height - row; |
| 7939 | |
| 7940 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 7941 | if (retval != MAYBE) |
| 7942 | return retval; |
| 7943 | |
| 7944 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 7945 | (int)Rows, FALSE, NULL) == FAIL) |
| 7946 | return FAIL; |
| 7947 | |
| 7948 | #ifdef FEAT_WINDOWS |
| 7949 | /* |
| 7950 | * If there are windows or status lines below, try to put them at the |
| 7951 | * correct place. If we can't do that, they have to be redrawn. |
| 7952 | */ |
| 7953 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 7954 | { |
| 7955 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 7956 | line_count, (int)Rows, NULL) == FAIL) |
| 7957 | { |
| 7958 | wp->w_redr_status = TRUE; |
| 7959 | win_rest_invalid(wp->w_next); |
| 7960 | } |
| 7961 | } |
| 7962 | /* |
| 7963 | * If this is the last window and there is no status line, redraw the |
| 7964 | * command line later. |
| 7965 | */ |
| 7966 | else |
| 7967 | #endif |
| 7968 | redraw_cmdline = TRUE; |
| 7969 | return OK; |
| 7970 | } |
| 7971 | |
| 7972 | /* |
| 7973 | * Common code for win_ins_lines() and win_del_lines(). |
| 7974 | * Returns OK or FAIL when the work has been done. |
| 7975 | * Returns MAYBE when not finished yet. |
| 7976 | */ |
| 7977 | static int |
| 7978 | win_do_lines(wp, row, line_count, mayclear, del) |
| 7979 | win_T *wp; |
| 7980 | int row; |
| 7981 | int line_count; |
| 7982 | int mayclear; |
| 7983 | int del; |
| 7984 | { |
| 7985 | int retval; |
| 7986 | |
| 7987 | if (!redrawing() || line_count <= 0) |
| 7988 | return FAIL; |
| 7989 | |
| 7990 | /* only a few lines left: redraw is faster */ |
| 7991 | if (mayclear && Rows - line_count < 5 |
| 7992 | #ifdef FEAT_VERTSPLIT |
| 7993 | && wp->w_width == Columns |
| 7994 | #endif |
| 7995 | ) |
| 7996 | { |
| 7997 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 7998 | return FAIL; |
| 7999 | } |
| 8000 | |
| 8001 | /* |
| 8002 | * Delete all remaining lines |
| 8003 | */ |
| 8004 | if (row + line_count >= wp->w_height) |
| 8005 | { |
| 8006 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 8007 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8008 | ' ', ' ', 0); |
| 8009 | return OK; |
| 8010 | } |
| 8011 | |
| 8012 | /* |
| 8013 | * when scrolling, the message on the command line should be cleared, |
| 8014 | * otherwise it will stay there forever. |
| 8015 | */ |
| 8016 | clear_cmdline = TRUE; |
| 8017 | |
| 8018 | /* |
| 8019 | * If the terminal can set a scroll region, use that. |
| 8020 | * Always do this in a vertically split window. This will redraw from |
| 8021 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 8022 | * win_line(). |
| 8023 | * Don't use a scroll region when we are going to redraw the text, writing |
| 8024 | * a character in the lower right corner of the scroll region causes a |
| 8025 | * scroll-up in the DJGPP version. |
| 8026 | */ |
| 8027 | if (scroll_region |
| 8028 | #ifdef FEAT_VERTSPLIT |
| 8029 | || W_WIDTH(wp) != Columns |
| 8030 | #endif |
| 8031 | ) |
| 8032 | { |
| 8033 | #ifdef FEAT_VERTSPLIT |
| 8034 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8035 | #endif |
| 8036 | scroll_region_set(wp, row); |
| 8037 | if (del) |
| 8038 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 8039 | wp->w_height - row, FALSE, wp); |
| 8040 | else |
| 8041 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 8042 | wp->w_height - row, wp); |
| 8043 | #ifdef FEAT_VERTSPLIT |
| 8044 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8045 | #endif |
| 8046 | scroll_region_reset(); |
| 8047 | return retval; |
| 8048 | } |
| 8049 | |
| 8050 | #ifdef FEAT_WINDOWS |
| 8051 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 8052 | return FAIL; |
| 8053 | #endif |
| 8054 | |
| 8055 | return MAYBE; |
| 8056 | } |
| 8057 | |
| 8058 | /* |
| 8059 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 8060 | */ |
| 8061 | static void |
| 8062 | win_rest_invalid(wp) |
| 8063 | win_T *wp; |
| 8064 | { |
| 8065 | #ifdef FEAT_WINDOWS |
| 8066 | while (wp != NULL) |
| 8067 | #else |
| 8068 | if (wp != NULL) |
| 8069 | #endif |
| 8070 | { |
| 8071 | redraw_win_later(wp, NOT_VALID); |
| 8072 | #ifdef FEAT_WINDOWS |
| 8073 | wp->w_redr_status = TRUE; |
| 8074 | wp = wp->w_next; |
| 8075 | #endif |
| 8076 | } |
| 8077 | redraw_cmdline = TRUE; |
| 8078 | } |
| 8079 | |
| 8080 | /* |
| 8081 | * The rest of the routines in this file perform screen manipulations. The |
| 8082 | * given operation is performed physically on the screen. The corresponding |
| 8083 | * change is also made to the internal screen image. In this way, the editor |
| 8084 | * anticipates the effect of editing changes on the appearance of the screen. |
| 8085 | * That way, when we call screenupdate a complete redraw isn't usually |
| 8086 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 8087 | * screen changes, and in the meantime, everything still works. |
| 8088 | */ |
| 8089 | |
| 8090 | /* |
| 8091 | * types for inserting or deleting lines |
| 8092 | */ |
| 8093 | #define USE_T_CAL 1 |
| 8094 | #define USE_T_CDL 2 |
| 8095 | #define USE_T_AL 3 |
| 8096 | #define USE_T_CE 4 |
| 8097 | #define USE_T_DL 5 |
| 8098 | #define USE_T_SR 6 |
| 8099 | #define USE_NL 7 |
| 8100 | #define USE_T_CD 8 |
| 8101 | #define USE_REDRAW 9 |
| 8102 | |
| 8103 | /* |
| 8104 | * insert lines on the screen and update ScreenLines[] |
| 8105 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 8106 | * When scrolling region used 'off' is the offset from the top for the region. |
| 8107 | * 'row' and 'end' are relative to the start of the region. |
| 8108 | * |
| 8109 | * return FAIL for failure, OK for success. |
| 8110 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 8111 | int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8112 | screen_ins_lines(off, row, line_count, end, wp) |
| 8113 | int off; |
| 8114 | int row; |
| 8115 | int line_count; |
| 8116 | int end; |
| 8117 | win_T *wp; /* NULL or window to use width from */ |
| 8118 | { |
| 8119 | int i; |
| 8120 | int j; |
| 8121 | unsigned temp; |
| 8122 | int cursor_row; |
| 8123 | int type; |
| 8124 | int result_empty; |
| 8125 | int can_ce = can_clear(T_CE); |
| 8126 | |
| 8127 | /* |
| 8128 | * FAIL if |
| 8129 | * - there is no valid screen |
| 8130 | * - the screen has to be redrawn completely |
| 8131 | * - the line count is less than one |
| 8132 | * - the line count is more than 'ttyscroll' |
| 8133 | */ |
| 8134 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 8135 | return FAIL; |
| 8136 | |
| 8137 | /* |
| 8138 | * There are seven ways to insert lines: |
| 8139 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 8140 | * characters from ScreenLines[]. |
| 8141 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 8142 | * the insert is just empty lines |
| 8143 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 8144 | * present or line_count > 1. It looks better if we do all the inserts |
| 8145 | * at once. |
| 8146 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 8147 | * insert is just empty lines and T_CE is not present or line_count > |
| 8148 | * 1. |
| 8149 | * 4. Use T_AL (insert line) if it exists. |
| 8150 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 8151 | * just empty lines. |
| 8152 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 8153 | * just empty lines. |
| 8154 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 8155 | * the 'da' flag is not set or we have clear line capability. |
| 8156 | * 8. redraw the characters from ScreenLines[]. |
| 8157 | * |
| 8158 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 8159 | * the scrollbar for the window. It does have insert line, use that if it |
| 8160 | * exists. |
| 8161 | */ |
| 8162 | result_empty = (row + line_count >= end); |
| 8163 | #ifdef FEAT_VERTSPLIT |
| 8164 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 8165 | type = USE_REDRAW; |
| 8166 | else |
| 8167 | #endif |
| 8168 | if (can_clear(T_CD) && result_empty) |
| 8169 | type = USE_T_CD; |
| 8170 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 8171 | type = USE_T_CAL; |
| 8172 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 8173 | type = USE_T_CDL; |
| 8174 | else if (*T_AL != NUL) |
| 8175 | type = USE_T_AL; |
| 8176 | else if (can_ce && result_empty) |
| 8177 | type = USE_T_CE; |
| 8178 | else if (*T_DL != NUL && result_empty) |
| 8179 | type = USE_T_DL; |
| 8180 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 8181 | type = USE_T_SR; |
| 8182 | else |
| 8183 | return FAIL; |
| 8184 | |
| 8185 | /* |
| 8186 | * For clearing the lines screen_del_lines() is used. This will also take |
| 8187 | * care of t_db if necessary. |
| 8188 | */ |
| 8189 | if (type == USE_T_CD || type == USE_T_CDL || |
| 8190 | type == USE_T_CE || type == USE_T_DL) |
| 8191 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 8192 | |
| 8193 | /* |
| 8194 | * If text is retained below the screen, first clear or delete as many |
| 8195 | * lines at the bottom of the window as are about to be inserted so that |
| 8196 | * the deleted lines won't later surface during a screen_del_lines. |
| 8197 | */ |
| 8198 | if (*T_DB) |
| 8199 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 8200 | |
| 8201 | #ifdef FEAT_CLIPBOARD |
| 8202 | /* Remove a modeless selection when inserting lines halfway the screen |
| 8203 | * or not the full width of the screen. */ |
| 8204 | if (off + row > 0 |
| 8205 | # ifdef FEAT_VERTSPLIT |
| 8206 | || (wp != NULL && wp->w_width != Columns) |
| 8207 | # endif |
| 8208 | ) |
| 8209 | clip_clear_selection(); |
| 8210 | else |
| 8211 | clip_scroll_selection(-line_count); |
| 8212 | #endif |
| 8213 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8214 | #ifdef FEAT_GUI |
| 8215 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 8216 | * scrolling is actually carried out. */ |
| 8217 | gui_dont_update_cursor(); |
| 8218 | #endif |
| 8219 | |
| 8220 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 8221 | cursor_row = row; |
| 8222 | else |
| 8223 | cursor_row = row + off; |
| 8224 | |
| 8225 | /* |
| 8226 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 8227 | * Clear the inserted lines in ScreenLines[]. |
| 8228 | */ |
| 8229 | row += off; |
| 8230 | end += off; |
| 8231 | for (i = 0; i < line_count; ++i) |
| 8232 | { |
| 8233 | #ifdef FEAT_VERTSPLIT |
| 8234 | if (wp != NULL && wp->w_width != Columns) |
| 8235 | { |
| 8236 | /* need to copy part of a line */ |
| 8237 | j = end - 1 - i; |
| 8238 | while ((j -= line_count) >= row) |
| 8239 | linecopy(j + line_count, j, wp); |
| 8240 | j += line_count; |
| 8241 | if (can_clear((char_u *)" ")) |
| 8242 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8243 | else |
| 8244 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8245 | LineWraps[j] = FALSE; |
| 8246 | } |
| 8247 | else |
| 8248 | #endif |
| 8249 | { |
| 8250 | j = end - 1 - i; |
| 8251 | temp = LineOffset[j]; |
| 8252 | while ((j -= line_count) >= row) |
| 8253 | { |
| 8254 | LineOffset[j + line_count] = LineOffset[j]; |
| 8255 | LineWraps[j + line_count] = LineWraps[j]; |
| 8256 | } |
| 8257 | LineOffset[j + line_count] = temp; |
| 8258 | LineWraps[j + line_count] = FALSE; |
| 8259 | if (can_clear((char_u *)" ")) |
| 8260 | lineclear(temp, (int)Columns); |
| 8261 | else |
| 8262 | lineinvalid(temp, (int)Columns); |
| 8263 | } |
| 8264 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8265 | |
| 8266 | screen_stop_highlight(); |
| 8267 | windgoto(cursor_row, 0); |
| 8268 | |
| 8269 | #ifdef FEAT_VERTSPLIT |
| 8270 | /* redraw the characters */ |
| 8271 | if (type == USE_REDRAW) |
| 8272 | redraw_block(row, end, wp); |
| 8273 | else |
| 8274 | #endif |
| 8275 | if (type == USE_T_CAL) |
| 8276 | { |
| 8277 | term_append_lines(line_count); |
| 8278 | screen_start(); /* don't know where cursor is now */ |
| 8279 | } |
| 8280 | else |
| 8281 | { |
| 8282 | for (i = 0; i < line_count; i++) |
| 8283 | { |
| 8284 | if (type == USE_T_AL) |
| 8285 | { |
| 8286 | if (i && cursor_row != 0) |
| 8287 | windgoto(cursor_row, 0); |
| 8288 | out_str(T_AL); |
| 8289 | } |
| 8290 | else /* type == USE_T_SR */ |
| 8291 | out_str(T_SR); |
| 8292 | screen_start(); /* don't know where cursor is now */ |
| 8293 | } |
| 8294 | } |
| 8295 | |
| 8296 | /* |
| 8297 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 8298 | * have been scrolled down into the region. |
| 8299 | */ |
| 8300 | if (type == USE_T_SR && *T_DA) |
| 8301 | { |
| 8302 | for (i = 0; i < line_count; ++i) |
| 8303 | { |
| 8304 | windgoto(off + i, 0); |
| 8305 | out_str(T_CE); |
| 8306 | screen_start(); /* don't know where cursor is now */ |
| 8307 | } |
| 8308 | } |
| 8309 | |
| 8310 | #ifdef FEAT_GUI |
| 8311 | gui_can_update_cursor(); |
| 8312 | if (gui.in_use) |
| 8313 | out_flush(); /* always flush after a scroll */ |
| 8314 | #endif |
| 8315 | return OK; |
| 8316 | } |
| 8317 | |
| 8318 | /* |
| 8319 | * delete lines on the screen and update ScreenLines[] |
| 8320 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 8321 | * When scrolling region used 'off' is the offset from the top for the region. |
| 8322 | * 'row' and 'end' are relative to the start of the region. |
| 8323 | * |
| 8324 | * Return OK for success, FAIL if the lines are not deleted. |
| 8325 | */ |
| 8326 | /*ARGSUSED*/ |
| 8327 | int |
| 8328 | screen_del_lines(off, row, line_count, end, force, wp) |
| 8329 | int off; |
| 8330 | int row; |
| 8331 | int line_count; |
| 8332 | int end; |
| 8333 | int force; /* even when line_count > p_ttyscroll */ |
| 8334 | win_T *wp; /* NULL or window to use width from */ |
| 8335 | { |
| 8336 | int j; |
| 8337 | int i; |
| 8338 | unsigned temp; |
| 8339 | int cursor_row; |
| 8340 | int cursor_end; |
| 8341 | int result_empty; /* result is empty until end of region */ |
| 8342 | int can_delete; /* deleting line codes can be used */ |
| 8343 | int type; |
| 8344 | |
| 8345 | /* |
| 8346 | * FAIL if |
| 8347 | * - there is no valid screen |
| 8348 | * - the screen has to be redrawn completely |
| 8349 | * - the line count is less than one |
| 8350 | * - the line count is more than 'ttyscroll' |
| 8351 | */ |
| 8352 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 8353 | (!force && line_count > p_ttyscroll)) |
| 8354 | return FAIL; |
| 8355 | |
| 8356 | /* |
| 8357 | * Check if the rest of the current region will become empty. |
| 8358 | */ |
| 8359 | result_empty = row + line_count >= end; |
| 8360 | |
| 8361 | /* |
| 8362 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 8363 | * available. |
| 8364 | */ |
| 8365 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 8366 | |
| 8367 | /* |
| 8368 | * There are six ways to delete lines: |
| 8369 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 8370 | * characters from ScreenLines[]. |
| 8371 | * 1. Use T_CD if it exists and the result is empty. |
| 8372 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 8373 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 8374 | * none of the other ways work. |
| 8375 | * 4. Use T_CE (erase line) if the result is empty. |
| 8376 | * 5. Use T_DL (delete line) if it exists. |
| 8377 | * 6. redraw the characters from ScreenLines[]. |
| 8378 | */ |
| 8379 | #ifdef FEAT_VERTSPLIT |
| 8380 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 8381 | type = USE_REDRAW; |
| 8382 | else |
| 8383 | #endif |
| 8384 | if (can_clear(T_CD) && result_empty) |
| 8385 | type = USE_T_CD; |
| 8386 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 8387 | /* |
| 8388 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 8389 | * its internal termcap... this works okay for tests which test *T_DB != |
| 8390 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 8391 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 8392 | * the trick... |
| 8393 | * Anyway, this hack will hopefully go away with the next OS release. |
| 8394 | * (Olaf Seibert) |
| 8395 | */ |
| 8396 | else if (row == 0 && T_DB == empty_option |
| 8397 | && (line_count == 1 || *T_CDL == NUL)) |
| 8398 | #else |
| 8399 | else if (row == 0 && ( |
| 8400 | #ifndef AMIGA |
| 8401 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 8402 | * up, so use delete-line command */ |
| 8403 | line_count == 1 || |
| 8404 | #endif |
| 8405 | *T_CDL == NUL)) |
| 8406 | #endif |
| 8407 | type = USE_NL; |
| 8408 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 8409 | type = USE_T_CDL; |
| 8410 | else if (can_clear(T_CE) && result_empty |
| 8411 | #ifdef FEAT_VERTSPLIT |
| 8412 | && (wp == NULL || wp->w_width == Columns) |
| 8413 | #endif |
| 8414 | ) |
| 8415 | type = USE_T_CE; |
| 8416 | else if (*T_DL != NUL && can_delete) |
| 8417 | type = USE_T_DL; |
| 8418 | else if (*T_CDL != NUL && can_delete) |
| 8419 | type = USE_T_CDL; |
| 8420 | else |
| 8421 | return FAIL; |
| 8422 | |
| 8423 | #ifdef FEAT_CLIPBOARD |
| 8424 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 8425 | * not the full width of the screen. */ |
| 8426 | if (off + row > 0 |
| 8427 | # ifdef FEAT_VERTSPLIT |
| 8428 | || (wp != NULL && wp->w_width != Columns) |
| 8429 | # endif |
| 8430 | ) |
| 8431 | clip_clear_selection(); |
| 8432 | else |
| 8433 | clip_scroll_selection(line_count); |
| 8434 | #endif |
| 8435 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8436 | #ifdef FEAT_GUI |
| 8437 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 8438 | * scrolling is actually carried out. */ |
| 8439 | gui_dont_update_cursor(); |
| 8440 | #endif |
| 8441 | |
| 8442 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 8443 | { |
| 8444 | cursor_row = row; |
| 8445 | cursor_end = end; |
| 8446 | } |
| 8447 | else |
| 8448 | { |
| 8449 | cursor_row = row + off; |
| 8450 | cursor_end = end + off; |
| 8451 | } |
| 8452 | |
| 8453 | /* |
| 8454 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 8455 | * Clear the inserted lines in ScreenLines[]. |
| 8456 | */ |
| 8457 | row += off; |
| 8458 | end += off; |
| 8459 | for (i = 0; i < line_count; ++i) |
| 8460 | { |
| 8461 | #ifdef FEAT_VERTSPLIT |
| 8462 | if (wp != NULL && wp->w_width != Columns) |
| 8463 | { |
| 8464 | /* need to copy part of a line */ |
| 8465 | j = row + i; |
| 8466 | while ((j += line_count) <= end - 1) |
| 8467 | linecopy(j - line_count, j, wp); |
| 8468 | j -= line_count; |
| 8469 | if (can_clear((char_u *)" ")) |
| 8470 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8471 | else |
| 8472 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8473 | LineWraps[j] = FALSE; |
| 8474 | } |
| 8475 | else |
| 8476 | #endif |
| 8477 | { |
| 8478 | /* whole width, moving the line pointers is faster */ |
| 8479 | j = row + i; |
| 8480 | temp = LineOffset[j]; |
| 8481 | while ((j += line_count) <= end - 1) |
| 8482 | { |
| 8483 | LineOffset[j - line_count] = LineOffset[j]; |
| 8484 | LineWraps[j - line_count] = LineWraps[j]; |
| 8485 | } |
| 8486 | LineOffset[j - line_count] = temp; |
| 8487 | LineWraps[j - line_count] = FALSE; |
| 8488 | if (can_clear((char_u *)" ")) |
| 8489 | lineclear(temp, (int)Columns); |
| 8490 | else |
| 8491 | lineinvalid(temp, (int)Columns); |
| 8492 | } |
| 8493 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8494 | |
| 8495 | screen_stop_highlight(); |
| 8496 | |
| 8497 | #ifdef FEAT_VERTSPLIT |
| 8498 | /* redraw the characters */ |
| 8499 | if (type == USE_REDRAW) |
| 8500 | redraw_block(row, end, wp); |
| 8501 | else |
| 8502 | #endif |
| 8503 | if (type == USE_T_CD) /* delete the lines */ |
| 8504 | { |
| 8505 | windgoto(cursor_row, 0); |
| 8506 | out_str(T_CD); |
| 8507 | screen_start(); /* don't know where cursor is now */ |
| 8508 | } |
| 8509 | else if (type == USE_T_CDL) |
| 8510 | { |
| 8511 | windgoto(cursor_row, 0); |
| 8512 | term_delete_lines(line_count); |
| 8513 | screen_start(); /* don't know where cursor is now */ |
| 8514 | } |
| 8515 | /* |
| 8516 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 8517 | * the whole screen (scroll region) up by outputting newlines on the |
| 8518 | * last line. |
| 8519 | */ |
| 8520 | else if (type == USE_NL) |
| 8521 | { |
| 8522 | windgoto(cursor_end - 1, 0); |
| 8523 | for (i = line_count; --i >= 0; ) |
| 8524 | out_char('\n'); /* cursor will remain on same line */ |
| 8525 | } |
| 8526 | else |
| 8527 | { |
| 8528 | for (i = line_count; --i >= 0; ) |
| 8529 | { |
| 8530 | if (type == USE_T_DL) |
| 8531 | { |
| 8532 | windgoto(cursor_row, 0); |
| 8533 | out_str(T_DL); /* delete a line */ |
| 8534 | } |
| 8535 | else /* type == USE_T_CE */ |
| 8536 | { |
| 8537 | windgoto(cursor_row + i, 0); |
| 8538 | out_str(T_CE); /* erase a line */ |
| 8539 | } |
| 8540 | screen_start(); /* don't know where cursor is now */ |
| 8541 | } |
| 8542 | } |
| 8543 | |
| 8544 | /* |
| 8545 | * If the 'db' flag is set, we need to clear the lines that have been |
| 8546 | * scrolled up at the bottom of the region. |
| 8547 | */ |
| 8548 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 8549 | { |
| 8550 | for (i = line_count; i > 0; --i) |
| 8551 | { |
| 8552 | windgoto(cursor_end - i, 0); |
| 8553 | out_str(T_CE); /* erase a line */ |
| 8554 | screen_start(); /* don't know where cursor is now */ |
| 8555 | } |
| 8556 | } |
| 8557 | |
| 8558 | #ifdef FEAT_GUI |
| 8559 | gui_can_update_cursor(); |
| 8560 | if (gui.in_use) |
| 8561 | out_flush(); /* always flush after a scroll */ |
| 8562 | #endif |
| 8563 | |
| 8564 | return OK; |
| 8565 | } |
| 8566 | |
| 8567 | /* |
| 8568 | * show the current mode and ruler |
| 8569 | * |
| 8570 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 8571 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 8572 | * cleared only if a mode is shown. |
| 8573 | * Return the length of the message (0 if no message). |
| 8574 | */ |
| 8575 | int |
| 8576 | showmode() |
| 8577 | { |
| 8578 | int need_clear; |
| 8579 | int length = 0; |
| 8580 | int do_mode; |
| 8581 | int attr; |
| 8582 | int nwr_save; |
| 8583 | #ifdef FEAT_INS_EXPAND |
| 8584 | int sub_attr; |
| 8585 | #endif |
| 8586 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 8587 | do_mode = ((p_smd && msg_silent == 0) |
| 8588 | && ((State & INSERT) |
| 8589 | || restart_edit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8590 | #ifdef FEAT_VISUAL |
| 8591 | || VIsual_active |
| 8592 | #endif |
| 8593 | )); |
| 8594 | if (do_mode || Recording) |
| 8595 | { |
| 8596 | /* |
| 8597 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 8598 | * Call char_avail() only when we are going to show something, because |
| 8599 | * it takes a bit of time. |
| 8600 | */ |
| 8601 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 8602 | { |
| 8603 | redraw_cmdline = TRUE; /* show mode later */ |
| 8604 | return 0; |
| 8605 | } |
| 8606 | |
| 8607 | nwr_save = need_wait_return; |
| 8608 | |
| 8609 | /* wait a bit before overwriting an important message */ |
| 8610 | check_for_delay(FALSE); |
| 8611 | |
| 8612 | /* if the cmdline is more than one line high, erase top lines */ |
| 8613 | need_clear = clear_cmdline; |
| 8614 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 8615 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 8616 | |
| 8617 | /* Position on the last line in the window, column 0 */ |
| 8618 | msg_pos_mode(); |
| 8619 | cursor_off(); |
| 8620 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 8621 | if (do_mode) |
| 8622 | { |
| 8623 | MSG_PUTS_ATTR("--", attr); |
| 8624 | #if defined(FEAT_XIM) |
| 8625 | if (xic != NULL && im_get_status() && !p_imdisable |
| 8626 | && curbuf->b_p_iminsert == B_IMODE_IM) |
| 8627 | # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */ |
| 8628 | MSG_PUTS_ATTR(" IM", attr); |
| 8629 | # else |
| 8630 | MSG_PUTS_ATTR(" XIM", attr); |
| 8631 | # endif |
| 8632 | #endif |
| 8633 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 8634 | if (gui.in_use) |
| 8635 | { |
| 8636 | if (hangul_input_state_get()) |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 8637 | MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8638 | } |
| 8639 | #endif |
| 8640 | #ifdef FEAT_INS_EXPAND |
| 8641 | if (edit_submode != NULL) /* CTRL-X in Insert mode */ |
| 8642 | { |
| 8643 | /* These messages can get long, avoid a wrap in a narrow |
| 8644 | * window. Prefer showing edit_submode_extra. */ |
| 8645 | length = (Rows - msg_row) * Columns - 3; |
| 8646 | if (edit_submode_extra != NULL) |
| 8647 | length -= vim_strsize(edit_submode_extra); |
| 8648 | if (length > 0) |
| 8649 | { |
| 8650 | if (edit_submode_pre != NULL) |
| 8651 | length -= vim_strsize(edit_submode_pre); |
| 8652 | if (length - vim_strsize(edit_submode) > 0) |
| 8653 | { |
| 8654 | if (edit_submode_pre != NULL) |
| 8655 | msg_puts_attr(edit_submode_pre, attr); |
| 8656 | msg_puts_attr(edit_submode, attr); |
| 8657 | } |
| 8658 | if (edit_submode_extra != NULL) |
| 8659 | { |
| 8660 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 8661 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 8662 | sub_attr = hl_attr(edit_submode_highl); |
| 8663 | else |
| 8664 | sub_attr = attr; |
| 8665 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 8666 | } |
| 8667 | } |
| 8668 | length = 0; |
| 8669 | } |
| 8670 | else |
| 8671 | #endif |
| 8672 | { |
| 8673 | #ifdef FEAT_VREPLACE |
| 8674 | if (State & VREPLACE_FLAG) |
| 8675 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 8676 | else |
| 8677 | #endif |
| 8678 | if (State & REPLACE_FLAG) |
| 8679 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 8680 | else if (State & INSERT) |
| 8681 | { |
| 8682 | #ifdef FEAT_RIGHTLEFT |
| 8683 | if (p_ri) |
| 8684 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 8685 | #endif |
| 8686 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 8687 | } |
| 8688 | else if (restart_edit == 'I') |
| 8689 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 8690 | else if (restart_edit == 'R') |
| 8691 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 8692 | else if (restart_edit == 'V') |
| 8693 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 8694 | #ifdef FEAT_RIGHTLEFT |
| 8695 | if (p_hkmap) |
| 8696 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 8697 | # ifdef FEAT_FKMAP |
| 8698 | if (p_fkmap) |
| 8699 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 8700 | # endif |
| 8701 | #endif |
| 8702 | #ifdef FEAT_KEYMAP |
| 8703 | if (State & LANGMAP) |
| 8704 | { |
| 8705 | # ifdef FEAT_ARABIC |
| 8706 | if (curwin->w_p_arab) |
| 8707 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 8708 | else |
| 8709 | # endif |
| 8710 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 8711 | } |
| 8712 | #endif |
| 8713 | if ((State & INSERT) && p_paste) |
| 8714 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 8715 | |
| 8716 | #ifdef FEAT_VISUAL |
| 8717 | if (VIsual_active) |
| 8718 | { |
| 8719 | char *p; |
| 8720 | |
| 8721 | /* Don't concatenate separate words to avoid translation |
| 8722 | * problems. */ |
| 8723 | switch ((VIsual_select ? 4 : 0) |
| 8724 | + (VIsual_mode == Ctrl_V) * 2 |
| 8725 | + (VIsual_mode == 'V')) |
| 8726 | { |
| 8727 | case 0: p = N_(" VISUAL"); break; |
| 8728 | case 1: p = N_(" VISUAL LINE"); break; |
| 8729 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 8730 | case 4: p = N_(" SELECT"); break; |
| 8731 | case 5: p = N_(" SELECT LINE"); break; |
| 8732 | default: p = N_(" SELECT BLOCK"); break; |
| 8733 | } |
| 8734 | MSG_PUTS_ATTR(_(p), attr); |
| 8735 | } |
| 8736 | #endif |
| 8737 | MSG_PUTS_ATTR(" --", attr); |
| 8738 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8739 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8740 | need_clear = TRUE; |
| 8741 | } |
| 8742 | if (Recording |
| 8743 | #ifdef FEAT_INS_EXPAND |
| 8744 | && edit_submode == NULL /* otherwise it gets too long */ |
| 8745 | #endif |
| 8746 | ) |
| 8747 | { |
| 8748 | MSG_PUTS_ATTR(_("recording"), attr); |
| 8749 | need_clear = TRUE; |
| 8750 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8751 | |
| 8752 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8753 | if (need_clear || clear_cmdline) |
| 8754 | msg_clr_eos(); |
| 8755 | msg_didout = FALSE; /* overwrite this message */ |
| 8756 | length = msg_col; |
| 8757 | msg_col = 0; |
| 8758 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 8759 | } |
| 8760 | else if (clear_cmdline && msg_silent == 0) |
| 8761 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 8762 | msg_clr_cmdline(); |
| 8763 | |
| 8764 | #ifdef FEAT_CMDL_INFO |
| 8765 | # ifdef FEAT_VISUAL |
| 8766 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 8767 | if (VIsual_active) |
| 8768 | clear_showcmd(); |
| 8769 | # endif |
| 8770 | |
| 8771 | /* If the last window has no status line, the ruler is after the mode |
| 8772 | * message and must be redrawn */ |
| 8773 | if (redrawing() |
| 8774 | # ifdef FEAT_WINDOWS |
| 8775 | && lastwin->w_status_height == 0 |
| 8776 | # endif |
| 8777 | ) |
| 8778 | win_redr_ruler(lastwin, TRUE); |
| 8779 | #endif |
| 8780 | redraw_cmdline = FALSE; |
| 8781 | clear_cmdline = FALSE; |
| 8782 | |
| 8783 | return length; |
| 8784 | } |
| 8785 | |
| 8786 | /* |
| 8787 | * Position for a mode message. |
| 8788 | */ |
| 8789 | static void |
| 8790 | msg_pos_mode() |
| 8791 | { |
| 8792 | msg_col = 0; |
| 8793 | msg_row = Rows - 1; |
| 8794 | } |
| 8795 | |
| 8796 | /* |
| 8797 | * Delete mode message. Used when ESC is typed which is expected to end |
| 8798 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8799 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8800 | */ |
| 8801 | void |
| 8802 | unshowmode(force) |
| 8803 | int force; |
| 8804 | { |
| 8805 | /* |
| 8806 | * Don't delete it right now, when not redrawing or insided a mapping. |
| 8807 | */ |
| 8808 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 8809 | redraw_cmdline = TRUE; /* delete mode later */ |
| 8810 | else |
| 8811 | { |
| 8812 | msg_pos_mode(); |
| 8813 | if (Recording) |
| 8814 | MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); |
| 8815 | msg_clr_eos(); |
| 8816 | } |
| 8817 | } |
| 8818 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8819 | #if defined(FEAT_WINDOWS) |
| 8820 | /* |
| 8821 | * Draw the tab pages line at the top of the Vim window. |
| 8822 | */ |
| 8823 | static void |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8824 | draw_tabline() |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8825 | { |
| 8826 | int tabcount = 0; |
| 8827 | tabpage_T *tp; |
| 8828 | int tabwidth; |
| 8829 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8830 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8831 | int attr; |
| 8832 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8833 | win_T *cwp; |
| 8834 | int wincount; |
| 8835 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8836 | int c; |
| 8837 | int len; |
| 8838 | int attr_sel = hl_attr(HLF_TPS); |
| 8839 | int attr_nosel = hl_attr(HLF_TP); |
| 8840 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8841 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8842 | int room; |
| 8843 | int use_sep_chars = (t_colors < 8 |
| 8844 | #ifdef FEAT_GUI |
| 8845 | && !gui.in_use |
| 8846 | #endif |
| 8847 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8848 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8849 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8850 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 8851 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 8852 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 8853 | if (gui_use_tabline()) |
| 8854 | { |
| 8855 | gui_update_tabline(); |
| 8856 | return; |
| 8857 | } |
| 8858 | #endif |
| 8859 | |
| 8860 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8861 | return; |
| 8862 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8863 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8864 | |
| 8865 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 8866 | for (scol = 0; scol < Columns; ++scol) |
| 8867 | TabPageIdxs[scol] = 0; |
| 8868 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8869 | /* Use the 'tabline' option if it's set. */ |
| 8870 | if (*p_tal != NUL) |
| 8871 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8872 | int save_called_emsg = called_emsg; |
| 8873 | |
| 8874 | /* Check for an error. If there is one we would loop in redrawing the |
| 8875 | * screen. Avoid that by making 'tabline' empty. */ |
| 8876 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8877 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8878 | if (called_emsg) |
| 8879 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 8880 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8881 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8882 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8883 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8884 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8885 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8886 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 8887 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8888 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8889 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 8890 | if (tabwidth < 6) |
| 8891 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8892 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8893 | attr = attr_nosel; |
| 8894 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8895 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 8896 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 8897 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8898 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8899 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8900 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8901 | if (tp->tp_topframe == topframe) |
| 8902 | attr = attr_sel; |
| 8903 | if (use_sep_chars && col > 0) |
| 8904 | screen_putchar('|', 0, col++, attr); |
| 8905 | |
| 8906 | if (tp->tp_topframe != topframe) |
| 8907 | attr = attr_nosel; |
| 8908 | |
| 8909 | screen_putchar(' ', 0, col++, attr); |
| 8910 | |
| 8911 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8912 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8913 | cwp = curwin; |
| 8914 | wp = firstwin; |
| 8915 | } |
| 8916 | else |
| 8917 | { |
| 8918 | cwp = tp->tp_curwin; |
| 8919 | wp = tp->tp_firstwin; |
| 8920 | } |
| 8921 | |
| 8922 | modified = FALSE; |
| 8923 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 8924 | if (bufIsChanged(wp->w_buffer)) |
| 8925 | modified = TRUE; |
| 8926 | if (modified || wincount > 1) |
| 8927 | { |
| 8928 | if (wincount > 1) |
| 8929 | { |
| 8930 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 8931 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 8932 | if (col + len >= Columns - 3) |
| 8933 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8934 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8935 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8936 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8937 | #else |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8938 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8939 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8940 | ); |
| 8941 | col += len; |
| 8942 | } |
| 8943 | if (modified) |
| 8944 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 8945 | screen_putchar(' ', 0, col++, attr); |
| 8946 | } |
| 8947 | |
| 8948 | room = scol - col + tabwidth - 1; |
| 8949 | if (room > 0) |
| 8950 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 8951 | /* Get buffer name in NameBuff[] */ |
| 8952 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8953 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8954 | len = vim_strsize(NameBuff); |
| 8955 | p = NameBuff; |
| 8956 | #ifdef FEAT_MBYTE |
| 8957 | if (has_mbyte) |
| 8958 | while (len > room) |
| 8959 | { |
| 8960 | len -= ptr2cells(p); |
| 8961 | mb_ptr_adv(p); |
| 8962 | } |
| 8963 | else |
| 8964 | #endif |
| 8965 | if (len > room) |
| 8966 | { |
| 8967 | p += len - room; |
| 8968 | len = room; |
| 8969 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 8970 | if (len > Columns - col - 1) |
| 8971 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8972 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 8973 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8974 | col += len; |
| 8975 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8976 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8977 | |
| 8978 | /* Store the tab page number in TabPageIdxs[], so that |
| 8979 | * jump_to_mouse() knows where each one is. */ |
| 8980 | ++tabcount; |
| 8981 | while (scol < col) |
| 8982 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8983 | } |
| 8984 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 8985 | if (use_sep_chars) |
| 8986 | c = '_'; |
| 8987 | else |
| 8988 | c = ' '; |
| 8989 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8990 | |
| 8991 | /* Put an "X" for closing the current tab if there are several. */ |
| 8992 | if (first_tabpage->tp_next != NULL) |
| 8993 | { |
| 8994 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 8995 | TabPageIdxs[Columns - 1] = -999; |
| 8996 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 8997 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 8998 | |
| 8999 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 9000 | * set. */ |
| 9001 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9002 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9003 | |
| 9004 | /* |
| 9005 | * Get buffer name for "buf" into NameBuff[]. |
| 9006 | * Takes care of special buffer names and translates special characters. |
| 9007 | */ |
| 9008 | void |
| 9009 | get_trans_bufname(buf) |
| 9010 | buf_T *buf; |
| 9011 | { |
| 9012 | if (buf_spname(buf) != NULL) |
| 9013 | STRCPY(NameBuff, buf_spname(buf)); |
| 9014 | else |
| 9015 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 9016 | trans_characters(NameBuff, MAXPATHL); |
| 9017 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9018 | #endif |
| 9019 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9020 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 9021 | /* |
| 9022 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 9023 | */ |
| 9024 | static int |
| 9025 | fillchar_status(attr, is_curwin) |
| 9026 | int *attr; |
| 9027 | int is_curwin; |
| 9028 | { |
| 9029 | int fill; |
| 9030 | if (is_curwin) |
| 9031 | { |
| 9032 | *attr = hl_attr(HLF_S); |
| 9033 | fill = fill_stl; |
| 9034 | } |
| 9035 | else |
| 9036 | { |
| 9037 | *attr = hl_attr(HLF_SNC); |
| 9038 | fill = fill_stlnc; |
| 9039 | } |
| 9040 | /* Use fill when there is highlighting, and highlighting of current |
| 9041 | * window differs, or the fillchars differ, or this is not the |
| 9042 | * current window */ |
| 9043 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 9044 | || !is_curwin || firstwin == lastwin) |
| 9045 | || (fill_stl != fill_stlnc))) |
| 9046 | return fill; |
| 9047 | if (is_curwin) |
| 9048 | return '^'; |
| 9049 | return '='; |
| 9050 | } |
| 9051 | #endif |
| 9052 | |
| 9053 | #ifdef FEAT_VERTSPLIT |
| 9054 | /* |
| 9055 | * Get the character to use in a separator between vertically split windows. |
| 9056 | * Get its attributes in "*attr". |
| 9057 | */ |
| 9058 | static int |
| 9059 | fillchar_vsep(attr) |
| 9060 | int *attr; |
| 9061 | { |
| 9062 | *attr = hl_attr(HLF_C); |
| 9063 | if (*attr == 0 && fill_vert == ' ') |
| 9064 | return '|'; |
| 9065 | else |
| 9066 | return fill_vert; |
| 9067 | } |
| 9068 | #endif |
| 9069 | |
| 9070 | /* |
| 9071 | * Return TRUE if redrawing should currently be done. |
| 9072 | */ |
| 9073 | int |
| 9074 | redrawing() |
| 9075 | { |
| 9076 | return (!RedrawingDisabled |
| 9077 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 9078 | } |
| 9079 | |
| 9080 | /* |
| 9081 | * Return TRUE if printing messages should currently be done. |
| 9082 | */ |
| 9083 | int |
| 9084 | messaging() |
| 9085 | { |
| 9086 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 9087 | } |
| 9088 | |
| 9089 | /* |
| 9090 | * Show current status info in ruler and various other places |
| 9091 | * If always is FALSE, only show ruler if position has changed. |
| 9092 | */ |
| 9093 | void |
| 9094 | showruler(always) |
| 9095 | int always; |
| 9096 | { |
| 9097 | if (!always && !redrawing()) |
| 9098 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9099 | #ifdef FEAT_INS_EXPAND |
| 9100 | if (pum_visible()) |
| 9101 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9102 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9103 | /* Don't redraw right now, do it later. */ |
| 9104 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9105 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9106 | return; |
| 9107 | } |
| 9108 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9109 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 9110 | 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] | 9111 | { |
| 9112 | redraw_custum_statusline(curwin); |
| 9113 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9114 | else |
| 9115 | #endif |
| 9116 | #ifdef FEAT_CMDL_INFO |
| 9117 | win_redr_ruler(curwin, always); |
| 9118 | #endif |
| 9119 | |
| 9120 | #ifdef FEAT_TITLE |
| 9121 | if (need_maketitle |
| 9122 | # ifdef FEAT_STL_OPT |
| 9123 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 9124 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 9125 | # endif |
| 9126 | ) |
| 9127 | maketitle(); |
| 9128 | #endif |
| 9129 | } |
| 9130 | |
| 9131 | #ifdef FEAT_CMDL_INFO |
| 9132 | static void |
| 9133 | win_redr_ruler(wp, always) |
| 9134 | win_T *wp; |
| 9135 | int always; |
| 9136 | { |
| 9137 | char_u buffer[70]; |
| 9138 | int row; |
| 9139 | int fillchar; |
| 9140 | int attr; |
| 9141 | int empty_line = FALSE; |
| 9142 | colnr_T virtcol; |
| 9143 | int i; |
| 9144 | int o; |
| 9145 | #ifdef FEAT_VERTSPLIT |
| 9146 | int this_ru_col; |
| 9147 | int off = 0; |
| 9148 | int width = Columns; |
| 9149 | # define WITH_OFF(x) x |
| 9150 | # define WITH_WIDTH(x) x |
| 9151 | #else |
| 9152 | # define WITH_OFF(x) 0 |
| 9153 | # define WITH_WIDTH(x) Columns |
| 9154 | # define this_ru_col ru_col |
| 9155 | #endif |
| 9156 | |
| 9157 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 9158 | if (!p_ru) |
| 9159 | return; |
| 9160 | |
| 9161 | /* |
| 9162 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 9163 | * after deleting lines, before cursor.lnum is corrected. |
| 9164 | */ |
| 9165 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 9166 | return; |
| 9167 | |
| 9168 | #ifdef FEAT_INS_EXPAND |
| 9169 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 9170 | * the (long) mode message. */ |
| 9171 | # ifdef FEAT_WINDOWS |
| 9172 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 9173 | # endif |
| 9174 | if (edit_submode != NULL) |
| 9175 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 9176 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 9177 | if (pum_visible()) |
| 9178 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9179 | #endif |
| 9180 | |
| 9181 | #ifdef FEAT_STL_OPT |
| 9182 | if (*p_ruf) |
| 9183 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9184 | int save_called_emsg = called_emsg; |
| 9185 | |
| 9186 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9187 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9188 | if (called_emsg) |
| 9189 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 9190 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9191 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9192 | return; |
| 9193 | } |
| 9194 | #endif |
| 9195 | |
| 9196 | /* |
| 9197 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 9198 | */ |
| 9199 | if (!(State & INSERT) |
| 9200 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 9201 | empty_line = TRUE; |
| 9202 | |
| 9203 | /* |
| 9204 | * Only draw the ruler when something changed. |
| 9205 | */ |
| 9206 | validate_virtcol_win(wp); |
| 9207 | if ( redraw_cmdline |
| 9208 | || always |
| 9209 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 9210 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 9211 | || wp->w_virtcol != wp->w_ru_virtcol |
| 9212 | #ifdef FEAT_VIRTUALEDIT |
| 9213 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 9214 | #endif |
| 9215 | || wp->w_topline != wp->w_ru_topline |
| 9216 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 9217 | #ifdef FEAT_DIFF |
| 9218 | || wp->w_topfill != wp->w_ru_topfill |
| 9219 | #endif |
| 9220 | || empty_line != wp->w_ru_empty) |
| 9221 | { |
| 9222 | cursor_off(); |
| 9223 | #ifdef FEAT_WINDOWS |
| 9224 | if (wp->w_status_height) |
| 9225 | { |
| 9226 | row = W_WINROW(wp) + wp->w_height; |
| 9227 | fillchar = fillchar_status(&attr, wp == curwin); |
| 9228 | # ifdef FEAT_VERTSPLIT |
| 9229 | off = W_WINCOL(wp); |
| 9230 | width = W_WIDTH(wp); |
| 9231 | # endif |
| 9232 | } |
| 9233 | else |
| 9234 | #endif |
| 9235 | { |
| 9236 | row = Rows - 1; |
| 9237 | fillchar = ' '; |
| 9238 | attr = 0; |
| 9239 | #ifdef FEAT_VERTSPLIT |
| 9240 | width = Columns; |
| 9241 | off = 0; |
| 9242 | #endif |
| 9243 | } |
| 9244 | |
| 9245 | /* In list mode virtcol needs to be recomputed */ |
| 9246 | virtcol = wp->w_virtcol; |
| 9247 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 9248 | { |
| 9249 | wp->w_p_list = FALSE; |
| 9250 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 9251 | wp->w_p_list = TRUE; |
| 9252 | } |
| 9253 | |
| 9254 | /* |
| 9255 | * Some sprintfs return the length, some return a pointer. |
| 9256 | * To avoid portability problems we use strlen() here. |
| 9257 | */ |
| 9258 | sprintf((char *)buffer, "%ld,", |
| 9259 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 9260 | ? 0L |
| 9261 | : (long)(wp->w_cursor.lnum)); |
| 9262 | col_print(buffer + STRLEN(buffer), |
| 9263 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 9264 | (int)virtcol + 1); |
| 9265 | |
| 9266 | /* |
| 9267 | * Add a "50%" if there is room for it. |
| 9268 | * On the last line, don't print in the last column (scrolls the |
| 9269 | * screen up on some terminals). |
| 9270 | */ |
| 9271 | i = (int)STRLEN(buffer); |
| 9272 | get_rel_pos(wp, buffer + i + 1); |
| 9273 | o = i + vim_strsize(buffer + i + 1); |
| 9274 | #ifdef FEAT_WINDOWS |
| 9275 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 9276 | #endif |
| 9277 | ++o; |
| 9278 | #ifdef FEAT_VERTSPLIT |
| 9279 | this_ru_col = ru_col - (Columns - width); |
| 9280 | if (this_ru_col < 0) |
| 9281 | this_ru_col = 0; |
| 9282 | #endif |
| 9283 | /* Never use more than half the window/screen width, leave the other |
| 9284 | * half for the filename. */ |
| 9285 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 9286 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 9287 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 9288 | { |
| 9289 | while (this_ru_col + o < WITH_WIDTH(width)) |
| 9290 | { |
| 9291 | #ifdef FEAT_MBYTE |
| 9292 | if (has_mbyte) |
| 9293 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 9294 | else |
| 9295 | #endif |
| 9296 | buffer[i++] = fillchar; |
| 9297 | ++o; |
| 9298 | } |
| 9299 | get_rel_pos(wp, buffer + i); |
| 9300 | } |
| 9301 | /* Truncate at window boundary. */ |
| 9302 | #ifdef FEAT_MBYTE |
| 9303 | if (has_mbyte) |
| 9304 | { |
| 9305 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 9306 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9307 | { |
| 9308 | o += (*mb_ptr2cells)(buffer + i); |
| 9309 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 9310 | { |
| 9311 | buffer[i] = NUL; |
| 9312 | break; |
| 9313 | } |
| 9314 | } |
| 9315 | } |
| 9316 | else |
| 9317 | #endif |
| 9318 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 9319 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 9320 | |
| 9321 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 9322 | i = redraw_cmdline; |
| 9323 | screen_fill(row, row + 1, |
| 9324 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 9325 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 9326 | fillchar, fillchar, attr); |
| 9327 | /* don't redraw the cmdline because of showing the ruler */ |
| 9328 | redraw_cmdline = i; |
| 9329 | wp->w_ru_cursor = wp->w_cursor; |
| 9330 | wp->w_ru_virtcol = wp->w_virtcol; |
| 9331 | wp->w_ru_empty = empty_line; |
| 9332 | wp->w_ru_topline = wp->w_topline; |
| 9333 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 9334 | #ifdef FEAT_DIFF |
| 9335 | wp->w_ru_topfill = wp->w_topfill; |
| 9336 | #endif |
| 9337 | } |
| 9338 | } |
| 9339 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9340 | |
| 9341 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 9342 | /* |
| 9343 | * Return the width of the 'number' column. |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9344 | * Caller may need to check if 'number' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9345 | * Otherwise it depends on 'numberwidth' and the line count. |
| 9346 | */ |
| 9347 | int |
| 9348 | number_width(wp) |
| 9349 | win_T *wp; |
| 9350 | { |
| 9351 | int n; |
| 9352 | linenr_T lnum; |
| 9353 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9354 | lnum = wp->w_buffer->b_ml.ml_line_count; |
| 9355 | if (lnum == wp->w_nrwidth_line_count) |
| 9356 | return wp->w_nrwidth_width; |
| 9357 | wp->w_nrwidth_line_count = lnum; |
| 9358 | |
| 9359 | n = 0; |
| 9360 | do |
| 9361 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 9362 | lnum /= 10; |
| 9363 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 9364 | } while (lnum > 0); |
| 9365 | |
| 9366 | /* 'numberwidth' gives the minimal width plus one */ |
| 9367 | if (n < wp->w_p_nuw - 1) |
| 9368 | n = wp->w_p_nuw - 1; |
| 9369 | |
| 9370 | wp->w_nrwidth_width = n; |
| 9371 | return n; |
| 9372 | } |
| 9373 | #endif |