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 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 28 | * character without composing chars ScreenLinesUC[] will be 0 and |
| 29 | * ScreenLinesC[][] is not used. When the character occupies two display |
| 30 | * cells the next byte in ScreenLines[] is 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 31 | * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 32 | * (drawn on top of the first character). There is 0 after the last one used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | * ScreenLines2[] is only used for euc-jp to store the second byte if the |
| 34 | * first byte is 0x8e (single-width character). |
| 35 | * |
| 36 | * The screen_*() functions write to the screen and handle updating |
| 37 | * ScreenLines[]. |
| 38 | * |
| 39 | * update_screen() is the function that updates all windows and status lines. |
| 40 | * It is called form the main loop when must_redraw is non-zero. It may be |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 41 | * called from other places when an immediate screen update is needed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | * |
| 43 | * The part of the buffer that is displayed in a window is set with: |
| 44 | * - w_topline (first buffer line in window) |
| 45 | * - w_topfill (filler line above the first line) |
| 46 | * - w_leftcol (leftmost window cell in window), |
| 47 | * - w_skipcol (skipped window cells of first line) |
| 48 | * |
| 49 | * Commands that only move the cursor around in a window, do not need to take |
| 50 | * action to update the display. The main loop will check if w_topline is |
| 51 | * valid and update it (scroll the window) when needed. |
| 52 | * |
| 53 | * Commands that scroll a window change w_topline and must call |
| 54 | * check_cursor() to move the cursor into the visible part of the window, and |
| 55 | * call redraw_later(VALID) to have the window displayed by update_screen() |
| 56 | * later. |
| 57 | * |
| 58 | * Commands that change text in the buffer must call changed_bytes() or |
| 59 | * changed_lines() to mark the area that changed and will require updating |
| 60 | * later. The main loop will call update_screen(), which will update each |
| 61 | * window that shows the changed buffer. This assumes text above the change |
| 62 | * can remain displayed as it is. Text after the change may need updating for |
| 63 | * scrolling, folding and syntax highlighting. |
| 64 | * |
| 65 | * Commands that change how a window is displayed (e.g., setting 'list') or |
| 66 | * invalidate the contents of a window in another way (e.g., change fold |
| 67 | * settings), must call redraw_later(NOT_VALID) to have the whole window |
| 68 | * redisplayed by update_screen() later. |
| 69 | * |
| 70 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
| 71 | * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the |
| 72 | * buffer redisplayed by update_screen() later. |
| 73 | * |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 74 | * Commands that change highlighting and possibly cause a scroll too must call |
| 75 | * redraw_later(SOME_VALID) to update the whole window but still use scrolling |
| 76 | * to avoid redrawing everything. But the length of displayed lines must not |
| 77 | * change, use NOT_VALID then. |
| 78 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | * Commands that move the window position must call redraw_later(NOT_VALID). |
| 80 | * TODO: should minimize redrawing by scrolling when possible. |
| 81 | * |
| 82 | * Commands that change everything (e.g., resizing the screen) must call |
| 83 | * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). |
| 84 | * |
| 85 | * Things that are handled indirectly: |
| 86 | * - When messages scroll the screen up, msg_scrolled will be set and |
| 87 | * update_screen() called to redraw. |
| 88 | */ |
| 89 | |
| 90 | #include "vim.h" |
| 91 | |
| 92 | /* |
| 93 | * The attributes that are actually active for writing to the screen. |
| 94 | */ |
| 95 | static int screen_attr = 0; |
| 96 | |
| 97 | /* |
| 98 | * Positioning the cursor is reduced by remembering the last position. |
| 99 | * Mostly used by windgoto() and screen_char(). |
| 100 | */ |
| 101 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 102 | |
| 103 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 104 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 105 | #endif |
| 106 | |
| 107 | #ifdef FEAT_FOLDING |
| 108 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
| 109 | #endif |
| 110 | |
| 111 | /* |
| 112 | * Buffer for one screen line (characters and attributes). |
| 113 | */ |
| 114 | static schar_T *current_ScreenLine; |
| 115 | |
| 116 | static void win_update __ARGS((win_T *wp)); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 117 | 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] | 118 | #ifdef FEAT_FOLDING |
| 119 | static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); |
| 120 | static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); |
| 121 | static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); |
| 122 | #endif |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 123 | 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] | 124 | static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
| 125 | #ifdef FEAT_RIGHTLEFT |
| 126 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); |
| 127 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 128 | #else |
| 129 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); |
| 130 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 131 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 132 | #ifdef FEAT_VERTSPLIT |
| 133 | static void draw_vsep_win __ARGS((win_T *wp, int row)); |
| 134 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 135 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 136 | static void redraw_custom_statusline __ARGS((win_T *wp)); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 137 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 139 | #define SEARCH_HL_PRIORITY 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 140 | static void start_search_hl __ARGS((void)); |
| 141 | static void end_search_hl __ARGS((void)); |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 142 | static void init_search_hl __ARGS((win_T *wp)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
| 144 | static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); |
| 145 | #endif |
| 146 | static void screen_start_highlight __ARGS((int attr)); |
| 147 | static void screen_char __ARGS((unsigned off, int row, int col)); |
| 148 | #ifdef FEAT_MBYTE |
| 149 | static void screen_char_2 __ARGS((unsigned off, int row, int col)); |
| 150 | #endif |
| 151 | static void screenclear2 __ARGS((void)); |
| 152 | static void lineclear __ARGS((unsigned off, int width)); |
| 153 | static void lineinvalid __ARGS((unsigned off, int width)); |
| 154 | #ifdef FEAT_VERTSPLIT |
| 155 | static void linecopy __ARGS((int to, int from, win_T *wp)); |
| 156 | static void redraw_block __ARGS((int row, int end, win_T *wp)); |
| 157 | #endif |
| 158 | static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); |
| 159 | static void win_rest_invalid __ARGS((win_T *wp)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 160 | static void msg_pos_mode __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 161 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 162 | static void draw_tabline __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 163 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 164 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 165 | static int fillchar_status __ARGS((int *attr, int is_curwin)); |
| 166 | #endif |
| 167 | #ifdef FEAT_VERTSPLIT |
| 168 | static int fillchar_vsep __ARGS((int *attr)); |
| 169 | #endif |
| 170 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 171 | static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | #endif |
| 173 | #ifdef FEAT_CMDL_INFO |
| 174 | static void win_redr_ruler __ARGS((win_T *wp, int always)); |
| 175 | #endif |
| 176 | |
| 177 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 178 | /* Ugly global: overrule attribute used by screen_char() */ |
| 179 | static int screen_char_attr = 0; |
| 180 | #endif |
| 181 | |
| 182 | /* |
| 183 | * Redraw the current window later, with update_screen(type). |
| 184 | * Set must_redraw only if not already set to a higher value. |
| 185 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 186 | */ |
| 187 | void |
| 188 | redraw_later(type) |
| 189 | int type; |
| 190 | { |
| 191 | redraw_win_later(curwin, type); |
| 192 | } |
| 193 | |
| 194 | void |
| 195 | redraw_win_later(wp, type) |
| 196 | win_T *wp; |
| 197 | int type; |
| 198 | { |
| 199 | if (wp->w_redr_type < type) |
| 200 | { |
| 201 | wp->w_redr_type = type; |
| 202 | if (type >= NOT_VALID) |
| 203 | wp->w_lines_valid = 0; |
| 204 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 205 | must_redraw = type; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 211 | * after executing a shell command that messes up the screen. |
| 212 | */ |
| 213 | void |
| 214 | redraw_later_clear() |
| 215 | { |
| 216 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 217 | #ifdef FEAT_GUI |
| 218 | if (gui.in_use) |
| 219 | /* Use a code that will reset gui.highlight_mask in |
| 220 | * gui_stop_highlight(). */ |
| 221 | screen_attr = HL_ALL + 1; |
| 222 | else |
| 223 | #endif |
| 224 | /* Use attributes that is very unlikely to appear in text. */ |
| 225 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Mark all windows to be redrawn later. |
| 230 | */ |
| 231 | void |
| 232 | redraw_all_later(type) |
| 233 | int type; |
| 234 | { |
| 235 | win_T *wp; |
| 236 | |
| 237 | FOR_ALL_WINDOWS(wp) |
| 238 | { |
| 239 | redraw_win_later(wp, type); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 244 | * 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] | 245 | */ |
| 246 | void |
| 247 | redraw_curbuf_later(type) |
| 248 | int type; |
| 249 | { |
| 250 | redraw_buf_later(curbuf, type); |
| 251 | } |
| 252 | |
| 253 | void |
| 254 | redraw_buf_later(buf, type) |
| 255 | buf_T *buf; |
| 256 | int type; |
| 257 | { |
| 258 | win_T *wp; |
| 259 | |
| 260 | FOR_ALL_WINDOWS(wp) |
| 261 | { |
| 262 | if (wp->w_buffer == buf) |
| 263 | redraw_win_later(wp, type); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * Changed something in the current window, at buffer line "lnum", that |
| 269 | * requires that line and possibly other lines to be redrawn. |
| 270 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 271 | * Used to remove the "$" from a change command. |
| 272 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 273 | * may become invalid and the whole window will have to be redrawn. |
| 274 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 275 | void |
| 276 | redrawWinline(lnum, invalid) |
| 277 | linenr_T lnum; |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 278 | int invalid UNUSED; /* window line height is invalid now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 279 | { |
| 280 | #ifdef FEAT_FOLDING |
| 281 | int i; |
| 282 | #endif |
| 283 | |
| 284 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 285 | curwin->w_redraw_top = lnum; |
| 286 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 287 | curwin->w_redraw_bot = lnum; |
| 288 | redraw_later(VALID); |
| 289 | |
| 290 | #ifdef FEAT_FOLDING |
| 291 | if (invalid) |
| 292 | { |
| 293 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 294 | i = find_wl_entry(curwin, lnum); |
| 295 | if (i >= 0) |
| 296 | curwin->w_lines[i].wl_valid = FALSE; |
| 297 | } |
| 298 | #endif |
| 299 | } |
| 300 | |
Bram Moolenaar | 9d6650f | 2010-06-06 23:04:47 +0200 | [diff] [blame] | 301 | #if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \ |
Bram Moolenaar | fd3e5dc | 2010-05-30 19:00:15 +0200 | [diff] [blame] | 302 | (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 303 | /* |
| 304 | * update all windows that are editing the current buffer |
| 305 | */ |
| 306 | void |
| 307 | update_curbuf(type) |
| 308 | int type; |
| 309 | { |
| 310 | redraw_curbuf_later(type); |
| 311 | update_screen(type); |
| 312 | } |
Bram Moolenaar | fd3e5dc | 2010-05-30 19:00:15 +0200 | [diff] [blame] | 313 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * update_screen() |
| 317 | * |
| 318 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 319 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 320 | */ |
| 321 | void |
| 322 | update_screen(type) |
| 323 | int type; |
| 324 | { |
| 325 | win_T *wp; |
| 326 | static int did_intro = FALSE; |
| 327 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 328 | int did_one; |
| 329 | #endif |
| 330 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 331 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 332 | if (!screen_valid(TRUE)) |
| 333 | return; |
| 334 | |
| 335 | if (must_redraw) |
| 336 | { |
| 337 | if (type < must_redraw) /* use maximal type */ |
| 338 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 339 | |
| 340 | /* must_redraw is reset here, so that when we run into some weird |
| 341 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 342 | * scrolling), or update_topline() in win_update() will cause a |
| 343 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 344 | must_redraw = 0; |
| 345 | } |
| 346 | |
| 347 | /* Need to update w_lines[]. */ |
| 348 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 349 | type = NOT_VALID; |
| 350 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 351 | /* Postpone the redrawing when it's not needed and when being called |
| 352 | * recursively. */ |
| 353 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 354 | { |
| 355 | redraw_later(type); /* remember type for next time */ |
| 356 | must_redraw = type; |
| 357 | if (type > INVERTED_ALL) |
| 358 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | updating_screen = TRUE; |
| 363 | #ifdef FEAT_SYN_HL |
| 364 | ++display_tick; /* let syntax code know we're in a next round of |
| 365 | * display updating */ |
| 366 | #endif |
| 367 | |
| 368 | /* |
| 369 | * if the screen was scrolled up when displaying a message, scroll it down |
| 370 | */ |
| 371 | if (msg_scrolled) |
| 372 | { |
| 373 | clear_cmdline = TRUE; |
| 374 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 375 | type = CLEAR; |
| 376 | else if (type != CLEAR) |
| 377 | { |
| 378 | check_for_delay(FALSE); |
| 379 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 380 | type = CLEAR; |
| 381 | FOR_ALL_WINDOWS(wp) |
| 382 | { |
| 383 | if (W_WINROW(wp) < msg_scrolled) |
| 384 | { |
| 385 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 386 | && wp->w_redr_type < REDRAW_TOP |
| 387 | && wp->w_lines_valid > 0 |
| 388 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 389 | { |
| 390 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 391 | wp->w_redr_type = REDRAW_TOP; |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | wp->w_redr_type = NOT_VALID; |
| 396 | #ifdef FEAT_WINDOWS |
| 397 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 398 | <= msg_scrolled) |
| 399 | wp->w_redr_status = TRUE; |
| 400 | #endif |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 405 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 406 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 407 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 408 | } |
| 409 | msg_scrolled = 0; |
| 410 | need_wait_return = FALSE; |
| 411 | } |
| 412 | |
| 413 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 414 | compute_cmdrow(); |
| 415 | |
| 416 | /* Check for changed highlighting */ |
| 417 | if (need_highlight_changed) |
| 418 | highlight_changed(); |
| 419 | |
| 420 | if (type == CLEAR) /* first clear screen */ |
| 421 | { |
| 422 | screenclear(); /* will reset clear_cmdline */ |
| 423 | type = NOT_VALID; |
| 424 | } |
| 425 | |
| 426 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 427 | check_for_delay(FALSE); |
| 428 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 429 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 430 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 431 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 432 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 433 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 434 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 435 | curwin->w_redr_type = NOT_VALID; |
| 436 | #endif |
| 437 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 438 | /* |
| 439 | * Only start redrawing if there is really something to do. |
| 440 | */ |
| 441 | if (type == INVERTED) |
| 442 | update_curswant(); |
| 443 | if (curwin->w_redr_type < type |
| 444 | && !((type == VALID |
| 445 | && curwin->w_lines[0].wl_valid |
| 446 | #ifdef FEAT_DIFF |
| 447 | && curwin->w_topfill == curwin->w_old_topfill |
| 448 | && curwin->w_botfill == curwin->w_old_botfill |
| 449 | #endif |
| 450 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
| 451 | #ifdef FEAT_VISUAL |
| 452 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 453 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 454 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 455 | && curwin->w_old_visual_mode == VIsual_mode |
| 456 | && (curwin->w_valid & VALID_VIRTCOL) |
| 457 | && curwin->w_old_curswant == curwin->w_curswant) |
| 458 | #endif |
| 459 | )) |
| 460 | curwin->w_redr_type = type; |
| 461 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 462 | #ifdef FEAT_WINDOWS |
| 463 | /* Redraw the tab pages line if needed. */ |
| 464 | if (redraw_tabline || type >= NOT_VALID) |
| 465 | draw_tabline(); |
| 466 | #endif |
| 467 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 468 | #ifdef FEAT_SYN_HL |
| 469 | /* |
| 470 | * Correct stored syntax highlighting info for changes in each displayed |
| 471 | * buffer. Each buffer must only be done once. |
| 472 | */ |
| 473 | FOR_ALL_WINDOWS(wp) |
| 474 | { |
| 475 | if (wp->w_buffer->b_mod_set) |
| 476 | { |
| 477 | # ifdef FEAT_WINDOWS |
| 478 | win_T *wwp; |
| 479 | |
| 480 | /* Check if we already did this buffer. */ |
| 481 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 482 | if (wwp->w_buffer == wp->w_buffer) |
| 483 | break; |
| 484 | # endif |
| 485 | if ( |
| 486 | # ifdef FEAT_WINDOWS |
| 487 | wwp == wp && |
| 488 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 489 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 490 | syn_stack_apply_changes(wp->w_buffer); |
| 491 | } |
| 492 | } |
| 493 | #endif |
| 494 | |
| 495 | /* |
| 496 | * Go from top to bottom through the windows, redrawing the ones that need |
| 497 | * it. |
| 498 | */ |
| 499 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 500 | did_one = FALSE; |
| 501 | #endif |
| 502 | #ifdef FEAT_SEARCH_EXTRA |
| 503 | search_hl.rm.regprog = NULL; |
| 504 | #endif |
| 505 | FOR_ALL_WINDOWS(wp) |
| 506 | { |
| 507 | if (wp->w_redr_type != 0) |
| 508 | { |
| 509 | cursor_off(); |
| 510 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 511 | if (!did_one) |
| 512 | { |
| 513 | did_one = TRUE; |
| 514 | # ifdef FEAT_SEARCH_EXTRA |
| 515 | start_search_hl(); |
| 516 | # endif |
| 517 | # ifdef FEAT_CLIPBOARD |
| 518 | /* When Visual area changed, may have to update selection. */ |
| 519 | if (clip_star.available && clip_isautosel()) |
| 520 | clip_update_selection(); |
| 521 | # endif |
| 522 | #ifdef FEAT_GUI |
| 523 | /* Remove the cursor before starting to do anything, because |
| 524 | * scrolling may make it difficult to redraw the text under |
| 525 | * it. */ |
| 526 | if (gui.in_use) |
| 527 | gui_undraw_cursor(); |
| 528 | #endif |
| 529 | } |
| 530 | #endif |
| 531 | win_update(wp); |
| 532 | } |
| 533 | |
| 534 | #ifdef FEAT_WINDOWS |
| 535 | /* redraw status line after the window to minimize cursor movement */ |
| 536 | if (wp->w_redr_status) |
| 537 | { |
| 538 | cursor_off(); |
| 539 | win_redr_status(wp); |
| 540 | } |
| 541 | #endif |
| 542 | } |
| 543 | #if defined(FEAT_SEARCH_EXTRA) |
| 544 | end_search_hl(); |
| 545 | #endif |
| 546 | |
| 547 | #ifdef FEAT_WINDOWS |
| 548 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 549 | * than going through all buffers (there could be many buffers). */ |
| 550 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 551 | wp->w_buffer->b_mod_set = FALSE; |
| 552 | #else |
| 553 | curbuf->b_mod_set = FALSE; |
| 554 | #endif |
| 555 | |
| 556 | updating_screen = FALSE; |
| 557 | #ifdef FEAT_GUI |
| 558 | gui_may_resize_shell(); |
| 559 | #endif |
| 560 | |
| 561 | /* Clear or redraw the command line. Done last, because scrolling may |
| 562 | * mess up the command line. */ |
| 563 | if (clear_cmdline || redraw_cmdline) |
| 564 | showmode(); |
| 565 | |
| 566 | /* May put up an introductory message when not editing a file */ |
| 567 | if (!did_intro && bufempty() |
| 568 | && curbuf->b_fname == NULL |
| 569 | #ifdef FEAT_WINDOWS |
| 570 | && firstwin->w_next == NULL |
| 571 | #endif |
| 572 | && vim_strchr(p_shm, SHM_INTRO) == NULL) |
| 573 | intro_message(FALSE); |
| 574 | did_intro = TRUE; |
| 575 | |
| 576 | #ifdef FEAT_GUI |
| 577 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 578 | * done. */ |
| 579 | if (gui.in_use) |
| 580 | { |
| 581 | out_flush(); /* required before updating the cursor */ |
| 582 | if (did_one) |
| 583 | gui_update_cursor(FALSE, FALSE); |
| 584 | gui_update_scrollbars(FALSE); |
| 585 | } |
| 586 | #endif |
| 587 | } |
| 588 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 589 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
| 590 | void |
| 591 | update_single_line(wp, lnum) |
| 592 | win_T *wp; |
| 593 | linenr_T lnum; |
| 594 | { |
| 595 | int row; |
| 596 | int j; |
| 597 | |
| 598 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 599 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 600 | { |
| 601 | # ifdef FEAT_GUI |
| 602 | /* Remove the cursor before starting to do anything, because scrolling |
| 603 | * may make it difficult to redraw the text under it. */ |
| 604 | if (gui.in_use) |
| 605 | gui_undraw_cursor(); |
| 606 | # endif |
| 607 | row = 0; |
| 608 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 609 | { |
| 610 | if (lnum == wp->w_lines[j].wl_lnum) |
| 611 | { |
| 612 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 613 | # ifdef FEAT_SEARCH_EXTRA |
| 614 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 615 | start_search_hl(); |
| 616 | prepare_search_hl(wp, lnum); |
| 617 | # endif |
| 618 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 619 | # if defined(FEAT_SEARCH_EXTRA) |
| 620 | end_search_hl(); |
| 621 | # endif |
| 622 | break; |
| 623 | } |
| 624 | row += wp->w_lines[j].wl_size; |
| 625 | } |
| 626 | # ifdef FEAT_GUI |
| 627 | /* Redraw the cursor */ |
| 628 | if (gui.in_use) |
| 629 | { |
| 630 | out_flush(); /* required before updating the cursor */ |
| 631 | gui_update_cursor(FALSE, FALSE); |
| 632 | } |
| 633 | # endif |
| 634 | } |
| 635 | } |
| 636 | #endif |
| 637 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 638 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
| 639 | static void update_prepare __ARGS((void)); |
| 640 | static void update_finish __ARGS((void)); |
| 641 | |
| 642 | /* |
| 643 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 644 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 645 | */ |
| 646 | static void |
| 647 | update_prepare() |
| 648 | { |
| 649 | cursor_off(); |
| 650 | updating_screen = TRUE; |
| 651 | #ifdef FEAT_GUI |
| 652 | /* Remove the cursor before starting to do anything, because scrolling may |
| 653 | * make it difficult to redraw the text under it. */ |
| 654 | if (gui.in_use) |
| 655 | gui_undraw_cursor(); |
| 656 | #endif |
| 657 | #ifdef FEAT_SEARCH_EXTRA |
| 658 | start_search_hl(); |
| 659 | #endif |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | * Finish updating one or more windows. |
| 664 | */ |
| 665 | static void |
| 666 | update_finish() |
| 667 | { |
| 668 | if (redraw_cmdline) |
| 669 | showmode(); |
| 670 | |
| 671 | # ifdef FEAT_SEARCH_EXTRA |
| 672 | end_search_hl(); |
| 673 | # endif |
| 674 | |
| 675 | updating_screen = FALSE; |
| 676 | |
| 677 | # ifdef FEAT_GUI |
| 678 | gui_may_resize_shell(); |
| 679 | |
| 680 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 681 | * done. */ |
| 682 | if (gui.in_use) |
| 683 | { |
| 684 | out_flush(); /* required before updating the cursor */ |
| 685 | gui_update_cursor(FALSE, FALSE); |
| 686 | gui_update_scrollbars(FALSE); |
| 687 | } |
| 688 | # endif |
| 689 | } |
| 690 | #endif |
| 691 | |
| 692 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 693 | void |
| 694 | update_debug_sign(buf, lnum) |
| 695 | buf_T *buf; |
| 696 | linenr_T lnum; |
| 697 | { |
| 698 | win_T *wp; |
| 699 | int doit = FALSE; |
| 700 | |
| 701 | # ifdef FEAT_FOLDING |
| 702 | win_foldinfo.fi_level = 0; |
| 703 | # endif |
| 704 | |
| 705 | /* update/delete a specific mark */ |
| 706 | FOR_ALL_WINDOWS(wp) |
| 707 | { |
| 708 | if (buf != NULL && lnum > 0) |
| 709 | { |
| 710 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 711 | && lnum < wp->w_botline) |
| 712 | { |
| 713 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 714 | wp->w_redraw_top = lnum; |
| 715 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 716 | wp->w_redraw_bot = lnum; |
| 717 | redraw_win_later(wp, VALID); |
| 718 | } |
| 719 | } |
| 720 | else |
| 721 | redraw_win_later(wp, VALID); |
| 722 | if (wp->w_redr_type != 0) |
| 723 | doit = TRUE; |
| 724 | } |
| 725 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 726 | /* Return when there is nothing to do or screen updating already |
| 727 | * happening. */ |
| 728 | if (!doit || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 729 | return; |
| 730 | |
| 731 | /* update all windows that need updating */ |
| 732 | update_prepare(); |
| 733 | |
| 734 | # ifdef FEAT_WINDOWS |
| 735 | for (wp = firstwin; wp; wp = wp->w_next) |
| 736 | { |
| 737 | if (wp->w_redr_type != 0) |
| 738 | win_update(wp); |
| 739 | if (wp->w_redr_status) |
| 740 | win_redr_status(wp); |
| 741 | } |
| 742 | # else |
| 743 | if (curwin->w_redr_type != 0) |
| 744 | win_update(curwin); |
| 745 | # endif |
| 746 | |
| 747 | update_finish(); |
| 748 | } |
| 749 | #endif |
| 750 | |
| 751 | |
| 752 | #if defined(FEAT_GUI) || defined(PROTO) |
| 753 | /* |
| 754 | * Update a single window, its status line and maybe the command line msg. |
| 755 | * Used for the GUI scrollbar. |
| 756 | */ |
| 757 | void |
| 758 | updateWindow(wp) |
| 759 | win_T *wp; |
| 760 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 761 | /* return if already busy updating */ |
| 762 | if (updating_screen) |
| 763 | return; |
| 764 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 765 | update_prepare(); |
| 766 | |
| 767 | #ifdef FEAT_CLIPBOARD |
| 768 | /* When Visual area changed, may have to update selection. */ |
| 769 | if (clip_star.available && clip_isautosel()) |
| 770 | clip_update_selection(); |
| 771 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 772 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 773 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 774 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 775 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 776 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 777 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 778 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 779 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 780 | if (wp->w_redr_status |
| 781 | # ifdef FEAT_CMDL_INFO |
| 782 | || p_ru |
| 783 | # endif |
| 784 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 785 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 786 | # endif |
| 787 | ) |
| 788 | win_redr_status(wp); |
| 789 | #endif |
| 790 | |
| 791 | update_finish(); |
| 792 | } |
| 793 | #endif |
| 794 | |
| 795 | /* |
| 796 | * Update a single window. |
| 797 | * |
| 798 | * This may cause the windows below it also to be redrawn (when clearing the |
| 799 | * screen or scrolling lines). |
| 800 | * |
| 801 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 802 | * implies the one below it. |
| 803 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 804 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 805 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 806 | * INVERTED redraw the changed part of the Visual area |
| 807 | * INVERTED_ALL redraw the whole Visual area |
| 808 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 809 | * 2. update lines at the top when scrolled down |
| 810 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 811 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 812 | * b_mod_top and b_mod_bot. |
| 813 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 814 | * wp->w_redraw_top and wp->w_redr_bot. |
| 815 | * - continue redrawing when syntax status is invalid. |
| 816 | * 4. if scrolled up, update lines at the bottom. |
| 817 | * This results in three areas that may need updating: |
| 818 | * top: from first row to top_end (when scrolled down) |
| 819 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 820 | * bot: from bot_start to last row (when scrolled up) |
| 821 | */ |
| 822 | static void |
| 823 | win_update(wp) |
| 824 | win_T *wp; |
| 825 | { |
| 826 | buf_T *buf = wp->w_buffer; |
| 827 | int type; |
| 828 | int top_end = 0; /* Below last row of the top area that needs |
| 829 | updating. 0 when no top area updating. */ |
| 830 | int mid_start = 999;/* first row of the mid area that needs |
| 831 | updating. 999 when no mid area updating. */ |
| 832 | int mid_end = 0; /* Below last row of the mid area that needs |
| 833 | updating. 0 when no mid area updating. */ |
| 834 | int bot_start = 999;/* first row of the bot area that needs |
| 835 | updating. 999 when no bot area updating */ |
| 836 | #ifdef FEAT_VISUAL |
| 837 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 838 | w_topline got smaller a bit */ |
| 839 | #endif |
| 840 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 841 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 842 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 843 | #endif |
| 844 | |
| 845 | int row; /* current window row to display */ |
| 846 | linenr_T lnum; /* current buffer lnum to display */ |
| 847 | int idx; /* current index in w_lines[] */ |
| 848 | int srow; /* starting row of the current line */ |
| 849 | |
| 850 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 851 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 852 | int i; |
| 853 | long j; |
| 854 | static int recursive = FALSE; /* being called recursively */ |
| 855 | int old_botline = wp->w_botline; |
| 856 | #ifdef FEAT_FOLDING |
| 857 | long fold_count; |
| 858 | #endif |
| 859 | #ifdef FEAT_SYN_HL |
| 860 | /* remember what happened to the previous line, to know if |
| 861 | * check_visual_highlight() can be used */ |
| 862 | #define DID_NONE 1 /* didn't update a line */ |
| 863 | #define DID_LINE 2 /* updated a normal line */ |
| 864 | #define DID_FOLD 3 /* updated a folded line */ |
| 865 | int did_update = DID_NONE; |
| 866 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 867 | #endif |
| 868 | linenr_T mod_top = 0; |
| 869 | linenr_T mod_bot = 0; |
| 870 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 871 | int save_got_int; |
| 872 | #endif |
| 873 | |
| 874 | type = wp->w_redr_type; |
| 875 | |
| 876 | if (type == NOT_VALID) |
| 877 | { |
| 878 | #ifdef FEAT_WINDOWS |
| 879 | wp->w_redr_status = TRUE; |
| 880 | #endif |
| 881 | wp->w_lines_valid = 0; |
| 882 | } |
| 883 | |
| 884 | /* Window is zero-height: nothing to draw. */ |
| 885 | if (wp->w_height == 0) |
| 886 | { |
| 887 | wp->w_redr_type = 0; |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | #ifdef FEAT_VERTSPLIT |
| 892 | /* Window is zero-width: Only need to draw the separator. */ |
| 893 | if (wp->w_width == 0) |
| 894 | { |
| 895 | /* draw the vertical separator right of this window */ |
| 896 | draw_vsep_win(wp, 0); |
| 897 | wp->w_redr_type = 0; |
| 898 | return; |
| 899 | } |
| 900 | #endif |
| 901 | |
| 902 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 903 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 904 | #endif |
| 905 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 906 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 907 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 908 | * changes. */ |
| 909 | i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 910 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 911 | { |
| 912 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 913 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 914 | } |
| 915 | else |
| 916 | #endif |
| 917 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 918 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 919 | { |
| 920 | /* |
| 921 | * When there are both inserted/deleted lines and specific lines to be |
| 922 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 923 | * everything (only happens when redrawing is off for while). |
| 924 | */ |
| 925 | type = NOT_VALID; |
| 926 | } |
| 927 | else |
| 928 | { |
| 929 | /* |
| 930 | * Set mod_top to the first line that needs displaying because of |
| 931 | * changes. Set mod_bot to the first line after the changes. |
| 932 | */ |
| 933 | mod_top = wp->w_redraw_top; |
| 934 | if (wp->w_redraw_bot != 0) |
| 935 | mod_bot = wp->w_redraw_bot + 1; |
| 936 | else |
| 937 | mod_bot = 0; |
| 938 | wp->w_redraw_top = 0; /* reset for next time */ |
| 939 | wp->w_redraw_bot = 0; |
| 940 | if (buf->b_mod_set) |
| 941 | { |
| 942 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 943 | { |
| 944 | mod_top = buf->b_mod_top; |
| 945 | #ifdef FEAT_SYN_HL |
| 946 | /* Need to redraw lines above the change that may be included |
| 947 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 948 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 949 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 950 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 951 | if (mod_top < 1) |
| 952 | mod_top = 1; |
| 953 | } |
| 954 | #endif |
| 955 | } |
| 956 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 957 | mod_bot = buf->b_mod_bot; |
| 958 | |
| 959 | #ifdef FEAT_SEARCH_EXTRA |
| 960 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 961 | * change in one line may make the Search highlighting in a |
| 962 | * previous line invalid. Simple solution: redraw all visible |
| 963 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 964 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 965 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 966 | if (search_hl.rm.regprog != NULL |
| 967 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 968 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 969 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 970 | { |
| 971 | cur = wp->w_match_head; |
| 972 | while (cur != NULL) |
| 973 | { |
| 974 | if (cur->match.regprog != NULL |
| 975 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 976 | { |
| 977 | top_to_mod = TRUE; |
| 978 | break; |
| 979 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 980 | cur = cur->next; |
| 981 | } |
| 982 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 983 | #endif |
| 984 | } |
| 985 | #ifdef FEAT_FOLDING |
| 986 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 987 | { |
| 988 | linenr_T lnumt, lnumb; |
| 989 | |
| 990 | /* |
| 991 | * A change in a line can cause lines above it to become folded or |
| 992 | * unfolded. Find the top most buffer line that may be affected. |
| 993 | * If the line was previously folded and displayed, get the first |
| 994 | * line of that fold. If the line is folded now, get the first |
| 995 | * folded line. Use the minimum of these two. |
| 996 | */ |
| 997 | |
| 998 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 999 | * the line below it. If there is no valid entry, use w_topline. |
| 1000 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1001 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1002 | lnumt = wp->w_topline; |
| 1003 | lnumb = MAXLNUM; |
| 1004 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1005 | if (wp->w_lines[i].wl_valid) |
| 1006 | { |
| 1007 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1008 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1009 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1010 | { |
| 1011 | lnumb = wp->w_lines[i].wl_lnum; |
| 1012 | /* When there is a fold column it might need updating |
| 1013 | * in the next line ("J" just above an open fold). */ |
| 1014 | if (wp->w_p_fdc > 0) |
| 1015 | ++lnumb; |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1020 | if (mod_top > lnumt) |
| 1021 | mod_top = lnumt; |
| 1022 | |
| 1023 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1024 | --mod_bot; |
| 1025 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1026 | ++mod_bot; |
| 1027 | if (mod_bot < lnumb) |
| 1028 | mod_bot = lnumb; |
| 1029 | } |
| 1030 | #endif |
| 1031 | |
| 1032 | /* When a change starts above w_topline and the end is below |
| 1033 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1034 | * If the end of the change is above w_topline: do like no change was |
| 1035 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1036 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1037 | { |
| 1038 | if (mod_bot > wp->w_topline) |
| 1039 | mod_top = wp->w_topline; |
| 1040 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1041 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1042 | top_end = 1; |
| 1043 | #endif |
| 1044 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1045 | |
| 1046 | /* When line numbers are displayed need to redraw all lines below |
| 1047 | * inserted/deleted lines. */ |
| 1048 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1049 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | /* |
| 1053 | * When only displaying the lines at the top, set top_end. Used when |
| 1054 | * window has scrolled down for msg_scrolled. |
| 1055 | */ |
| 1056 | if (type == REDRAW_TOP) |
| 1057 | { |
| 1058 | j = 0; |
| 1059 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1060 | { |
| 1061 | j += wp->w_lines[i].wl_size; |
| 1062 | if (j >= wp->w_upd_rows) |
| 1063 | { |
| 1064 | top_end = j; |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | if (top_end == 0) |
| 1069 | /* not found (cannot happen?): redraw everything */ |
| 1070 | type = NOT_VALID; |
| 1071 | else |
| 1072 | /* top area defined, the rest is VALID */ |
| 1073 | type = VALID; |
| 1074 | } |
| 1075 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1076 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1077 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1078 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1079 | * called. */ |
| 1080 | if (screen_cleared) |
| 1081 | screen_cleared = MAYBE; |
| 1082 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1083 | /* |
| 1084 | * If there are no changes on the screen that require a complete redraw, |
| 1085 | * handle three cases: |
| 1086 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1087 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1088 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1089 | * w_lines[] that needs updating. |
| 1090 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1091 | if ((type == VALID || type == SOME_VALID |
| 1092 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1093 | #ifdef FEAT_DIFF |
| 1094 | && !wp->w_botfill && !wp->w_old_botfill |
| 1095 | #endif |
| 1096 | ) |
| 1097 | { |
| 1098 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1099 | { |
| 1100 | /* |
| 1101 | * w_topline is the first changed line, the scrolling will be done |
| 1102 | * further down. |
| 1103 | */ |
| 1104 | } |
| 1105 | else if (wp->w_lines[0].wl_valid |
| 1106 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1107 | #ifdef FEAT_DIFF |
| 1108 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1109 | && wp->w_topfill > wp->w_old_topfill) |
| 1110 | #endif |
| 1111 | )) |
| 1112 | { |
| 1113 | /* |
| 1114 | * New topline is above old topline: May scroll down. |
| 1115 | */ |
| 1116 | #ifdef FEAT_FOLDING |
| 1117 | if (hasAnyFolding(wp)) |
| 1118 | { |
| 1119 | linenr_T ln; |
| 1120 | |
| 1121 | /* count the number of lines we are off, counting a sequence |
| 1122 | * of folded lines as one */ |
| 1123 | j = 0; |
| 1124 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1125 | { |
| 1126 | ++j; |
| 1127 | if (j >= wp->w_height - 2) |
| 1128 | break; |
| 1129 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1130 | } |
| 1131 | } |
| 1132 | else |
| 1133 | #endif |
| 1134 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1135 | if (j < wp->w_height - 2) /* not too far off */ |
| 1136 | { |
| 1137 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1138 | #ifdef FEAT_DIFF |
| 1139 | /* insert extra lines for previously invisible filler lines */ |
| 1140 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1141 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1142 | - wp->w_old_topfill; |
| 1143 | #endif |
| 1144 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1145 | { |
| 1146 | /* |
| 1147 | * Try to insert the correct number of lines. |
| 1148 | * If not the last window, delete the lines at the bottom. |
| 1149 | * win_ins_lines may fail when the terminal can't do it. |
| 1150 | */ |
| 1151 | if (i > 0) |
| 1152 | check_for_delay(FALSE); |
| 1153 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1154 | { |
| 1155 | if (wp->w_lines_valid != 0) |
| 1156 | { |
| 1157 | /* Need to update rows that are new, stop at the |
| 1158 | * first one that scrolled down. */ |
| 1159 | top_end = i; |
| 1160 | #ifdef FEAT_VISUAL |
| 1161 | scrolled_down = TRUE; |
| 1162 | #endif |
| 1163 | |
| 1164 | /* Move the entries that were scrolled, disable |
| 1165 | * the entries for the lines to be redrawn. */ |
| 1166 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1167 | wp->w_lines_valid = wp->w_height; |
| 1168 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1169 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1170 | while (idx >= 0) |
| 1171 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1172 | } |
| 1173 | } |
| 1174 | else |
| 1175 | mid_start = 0; /* redraw all lines */ |
| 1176 | } |
| 1177 | else |
| 1178 | mid_start = 0; /* redraw all lines */ |
| 1179 | } |
| 1180 | else |
| 1181 | mid_start = 0; /* redraw all lines */ |
| 1182 | } |
| 1183 | else |
| 1184 | { |
| 1185 | /* |
| 1186 | * New topline is at or below old topline: May scroll up. |
| 1187 | * When topline didn't change, find first entry in w_lines[] that |
| 1188 | * needs updating. |
| 1189 | */ |
| 1190 | |
| 1191 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1192 | j = -1; |
| 1193 | row = 0; |
| 1194 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1195 | { |
| 1196 | if (wp->w_lines[i].wl_valid |
| 1197 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1198 | { |
| 1199 | j = i; |
| 1200 | break; |
| 1201 | } |
| 1202 | row += wp->w_lines[i].wl_size; |
| 1203 | } |
| 1204 | if (j == -1) |
| 1205 | { |
| 1206 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1207 | * lines */ |
| 1208 | mid_start = 0; |
| 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | /* |
| 1213 | * Try to delete the correct number of lines. |
| 1214 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1215 | */ |
| 1216 | #ifdef FEAT_DIFF |
| 1217 | /* If the topline didn't change, delete old filler lines, |
| 1218 | * otherwise delete filler lines of the new topline... */ |
| 1219 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1220 | row += wp->w_old_topfill; |
| 1221 | else |
| 1222 | row += diff_check_fill(wp, wp->w_topline); |
| 1223 | /* ... but don't delete new filler lines. */ |
| 1224 | row -= wp->w_topfill; |
| 1225 | #endif |
| 1226 | if (row > 0) |
| 1227 | { |
| 1228 | check_for_delay(FALSE); |
| 1229 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1230 | bot_start = wp->w_height - row; |
| 1231 | else |
| 1232 | mid_start = 0; /* redraw all lines */ |
| 1233 | } |
| 1234 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1235 | { |
| 1236 | /* |
| 1237 | * Skip the lines (below the deleted lines) that are still |
| 1238 | * valid and don't need redrawing. Copy their info |
| 1239 | * upwards, to compensate for the deleted lines. Set |
| 1240 | * bot_start to the first row that needs redrawing. |
| 1241 | */ |
| 1242 | bot_start = 0; |
| 1243 | idx = 0; |
| 1244 | for (;;) |
| 1245 | { |
| 1246 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1247 | /* stop at line that didn't fit, unless it is still |
| 1248 | * valid (no lines deleted) */ |
| 1249 | if (row > 0 && bot_start + row |
| 1250 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1251 | { |
| 1252 | wp->w_lines_valid = idx + 1; |
| 1253 | break; |
| 1254 | } |
| 1255 | bot_start += wp->w_lines[idx++].wl_size; |
| 1256 | |
| 1257 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1258 | if (++j >= wp->w_lines_valid) |
| 1259 | { |
| 1260 | wp->w_lines_valid = idx; |
| 1261 | break; |
| 1262 | } |
| 1263 | } |
| 1264 | #ifdef FEAT_DIFF |
| 1265 | /* Correct the first entry for filler lines at the top |
| 1266 | * when it won't get updated below. */ |
| 1267 | if (wp->w_p_diff && bot_start > 0) |
| 1268 | wp->w_lines[0].wl_size = |
| 1269 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1270 | + wp->w_topfill; |
| 1271 | #endif |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | /* When starting redraw in the first line, redraw all lines. When |
| 1277 | * there is only one window it's probably faster to clear the screen |
| 1278 | * first. */ |
| 1279 | if (mid_start == 0) |
| 1280 | { |
| 1281 | mid_end = wp->w_height; |
| 1282 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1283 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1284 | /* Clear the screen when it was not done by win_del_lines() or |
| 1285 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1286 | * then. */ |
| 1287 | if (screen_cleared != TRUE) |
| 1288 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1289 | #ifdef FEAT_WINDOWS |
| 1290 | /* The screen was cleared, redraw the tab pages line. */ |
| 1291 | if (redraw_tabline) |
| 1292 | draw_tabline(); |
| 1293 | #endif |
| 1294 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1295 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1296 | |
| 1297 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1298 | * cleared (only happens for the first window) or when screenclear() |
| 1299 | * was called directly above, "must_redraw" will have been set to |
| 1300 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1301 | if (screen_cleared == TRUE) |
| 1302 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1303 | } |
| 1304 | else |
| 1305 | { |
| 1306 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1307 | mid_start = 0; |
| 1308 | mid_end = wp->w_height; |
| 1309 | } |
| 1310 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1311 | if (type == SOME_VALID) |
| 1312 | { |
| 1313 | /* SOME_VALID: redraw all lines. */ |
| 1314 | mid_start = 0; |
| 1315 | mid_end = wp->w_height; |
| 1316 | type = NOT_VALID; |
| 1317 | } |
| 1318 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1319 | #ifdef FEAT_VISUAL |
| 1320 | /* check if we are updating or removing the inverted part */ |
| 1321 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1322 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1323 | { |
| 1324 | linenr_T from, to; |
| 1325 | |
| 1326 | if (VIsual_active) |
| 1327 | { |
| 1328 | if (VIsual_active |
| 1329 | && (VIsual_mode != wp->w_old_visual_mode |
| 1330 | || type == INVERTED_ALL)) |
| 1331 | { |
| 1332 | /* |
| 1333 | * If the type of Visual selection changed, redraw the whole |
| 1334 | * selection. Also when the ownership of the X selection is |
| 1335 | * gained or lost. |
| 1336 | */ |
| 1337 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1338 | { |
| 1339 | from = curwin->w_cursor.lnum; |
| 1340 | to = VIsual.lnum; |
| 1341 | } |
| 1342 | else |
| 1343 | { |
| 1344 | from = VIsual.lnum; |
| 1345 | to = curwin->w_cursor.lnum; |
| 1346 | } |
| 1347 | /* redraw more when the cursor moved as well */ |
| 1348 | if (wp->w_old_cursor_lnum < from) |
| 1349 | from = wp->w_old_cursor_lnum; |
| 1350 | if (wp->w_old_cursor_lnum > to) |
| 1351 | to = wp->w_old_cursor_lnum; |
| 1352 | if (wp->w_old_visual_lnum < from) |
| 1353 | from = wp->w_old_visual_lnum; |
| 1354 | if (wp->w_old_visual_lnum > to) |
| 1355 | to = wp->w_old_visual_lnum; |
| 1356 | } |
| 1357 | else |
| 1358 | { |
| 1359 | /* |
| 1360 | * Find the line numbers that need to be updated: The lines |
| 1361 | * between the old cursor position and the current cursor |
| 1362 | * position. Also check if the Visual position changed. |
| 1363 | */ |
| 1364 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1365 | { |
| 1366 | from = curwin->w_cursor.lnum; |
| 1367 | to = wp->w_old_cursor_lnum; |
| 1368 | } |
| 1369 | else |
| 1370 | { |
| 1371 | from = wp->w_old_cursor_lnum; |
| 1372 | to = curwin->w_cursor.lnum; |
| 1373 | if (from == 0) /* Visual mode just started */ |
| 1374 | from = to; |
| 1375 | } |
| 1376 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1377 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1378 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1379 | { |
| 1380 | if (wp->w_old_visual_lnum < from |
| 1381 | && wp->w_old_visual_lnum != 0) |
| 1382 | from = wp->w_old_visual_lnum; |
| 1383 | if (wp->w_old_visual_lnum > to) |
| 1384 | to = wp->w_old_visual_lnum; |
| 1385 | if (VIsual.lnum < from) |
| 1386 | from = VIsual.lnum; |
| 1387 | if (VIsual.lnum > to) |
| 1388 | to = VIsual.lnum; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | /* |
| 1393 | * If in block mode and changed column or curwin->w_curswant: |
| 1394 | * update all lines. |
| 1395 | * First compute the actual start and end column. |
| 1396 | */ |
| 1397 | if (VIsual_mode == Ctrl_V) |
| 1398 | { |
| 1399 | colnr_T fromc, toc; |
| 1400 | |
| 1401 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
| 1402 | ++toc; |
| 1403 | if (curwin->w_curswant == MAXCOL) |
| 1404 | toc = MAXCOL; |
| 1405 | |
| 1406 | if (fromc != wp->w_old_cursor_fcol |
| 1407 | || toc != wp->w_old_cursor_lcol) |
| 1408 | { |
| 1409 | if (from > VIsual.lnum) |
| 1410 | from = VIsual.lnum; |
| 1411 | if (to < VIsual.lnum) |
| 1412 | to = VIsual.lnum; |
| 1413 | } |
| 1414 | wp->w_old_cursor_fcol = fromc; |
| 1415 | wp->w_old_cursor_lcol = toc; |
| 1416 | } |
| 1417 | } |
| 1418 | else |
| 1419 | { |
| 1420 | /* Use the line numbers of the old Visual area. */ |
| 1421 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1422 | { |
| 1423 | from = wp->w_old_cursor_lnum; |
| 1424 | to = wp->w_old_visual_lnum; |
| 1425 | } |
| 1426 | else |
| 1427 | { |
| 1428 | from = wp->w_old_visual_lnum; |
| 1429 | to = wp->w_old_cursor_lnum; |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | /* |
| 1434 | * There is no need to update lines above the top of the window. |
| 1435 | */ |
| 1436 | if (from < wp->w_topline) |
| 1437 | from = wp->w_topline; |
| 1438 | |
| 1439 | /* |
| 1440 | * If we know the value of w_botline, use it to restrict the update to |
| 1441 | * the lines that are visible in the window. |
| 1442 | */ |
| 1443 | if (wp->w_valid & VALID_BOTLINE) |
| 1444 | { |
| 1445 | if (from >= wp->w_botline) |
| 1446 | from = wp->w_botline - 1; |
| 1447 | if (to >= wp->w_botline) |
| 1448 | to = wp->w_botline - 1; |
| 1449 | } |
| 1450 | |
| 1451 | /* |
| 1452 | * Find the minimal part to be updated. |
| 1453 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1454 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1455 | * top_end; need to redraw from top_end to the "to" line. |
| 1456 | * A middle mouse click with a Visual selection may change the text |
| 1457 | * above the Visual area and reset wl_valid, do count these for |
| 1458 | * mid_end (in srow). |
| 1459 | */ |
| 1460 | if (mid_start > 0) |
| 1461 | { |
| 1462 | lnum = wp->w_topline; |
| 1463 | idx = 0; |
| 1464 | srow = 0; |
| 1465 | if (scrolled_down) |
| 1466 | mid_start = top_end; |
| 1467 | else |
| 1468 | mid_start = 0; |
| 1469 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1470 | { |
| 1471 | if (wp->w_lines[idx].wl_valid) |
| 1472 | mid_start += wp->w_lines[idx].wl_size; |
| 1473 | else if (!scrolled_down) |
| 1474 | srow += wp->w_lines[idx].wl_size; |
| 1475 | ++idx; |
| 1476 | # ifdef FEAT_FOLDING |
| 1477 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1478 | lnum = wp->w_lines[idx].wl_lnum; |
| 1479 | else |
| 1480 | # endif |
| 1481 | ++lnum; |
| 1482 | } |
| 1483 | srow += mid_start; |
| 1484 | mid_end = wp->w_height; |
| 1485 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1486 | { |
| 1487 | if (wp->w_lines[idx].wl_valid |
| 1488 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1489 | { |
| 1490 | /* Only update until first row of this line */ |
| 1491 | mid_end = srow; |
| 1492 | break; |
| 1493 | } |
| 1494 | srow += wp->w_lines[idx].wl_size; |
| 1495 | } |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | if (VIsual_active && buf == curwin->w_buffer) |
| 1500 | { |
| 1501 | wp->w_old_visual_mode = VIsual_mode; |
| 1502 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1503 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1504 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1505 | wp->w_old_curswant = curwin->w_curswant; |
| 1506 | } |
| 1507 | else |
| 1508 | { |
| 1509 | wp->w_old_visual_mode = 0; |
| 1510 | wp->w_old_cursor_lnum = 0; |
| 1511 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1512 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1513 | } |
| 1514 | #endif /* FEAT_VISUAL */ |
| 1515 | |
| 1516 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1517 | /* reset got_int, otherwise regexp won't work */ |
| 1518 | save_got_int = got_int; |
| 1519 | got_int = 0; |
| 1520 | #endif |
| 1521 | #ifdef FEAT_FOLDING |
| 1522 | win_foldinfo.fi_level = 0; |
| 1523 | #endif |
| 1524 | |
| 1525 | /* |
| 1526 | * Update all the window rows. |
| 1527 | */ |
| 1528 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1529 | row = 0; |
| 1530 | srow = 0; |
| 1531 | lnum = wp->w_topline; /* first line shown in window */ |
| 1532 | for (;;) |
| 1533 | { |
| 1534 | /* stop updating when reached the end of the window (check for _past_ |
| 1535 | * the end of the window is at the end of the loop) */ |
| 1536 | if (row == wp->w_height) |
| 1537 | { |
| 1538 | didline = TRUE; |
| 1539 | break; |
| 1540 | } |
| 1541 | |
| 1542 | /* stop updating when hit the end of the file */ |
| 1543 | if (lnum > buf->b_ml.ml_line_count) |
| 1544 | { |
| 1545 | eof = TRUE; |
| 1546 | break; |
| 1547 | } |
| 1548 | |
| 1549 | /* Remember the starting row of the line that is going to be dealt |
| 1550 | * with. It is used further down when the line doesn't fit. */ |
| 1551 | srow = row; |
| 1552 | |
| 1553 | /* |
| 1554 | * Update a line when it is in an area that needs updating, when it |
| 1555 | * has changes or w_lines[idx] is invalid. |
| 1556 | * bot_start may be halfway a wrapped line after using |
| 1557 | * win_del_lines(), check if the current line includes it. |
| 1558 | * When syntax folding is being used, the saved syntax states will |
| 1559 | * already have been updated, we can't see where the syntax state is |
| 1560 | * the same again, just update until the end of the window. |
| 1561 | */ |
| 1562 | if (row < top_end |
| 1563 | || (row >= mid_start && row < mid_end) |
| 1564 | #ifdef FEAT_SEARCH_EXTRA |
| 1565 | || top_to_mod |
| 1566 | #endif |
| 1567 | || idx >= wp->w_lines_valid |
| 1568 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1569 | || (mod_top != 0 |
| 1570 | && (lnum == mod_top |
| 1571 | || (lnum >= mod_top |
| 1572 | && (lnum < mod_bot |
| 1573 | #ifdef FEAT_SYN_HL |
| 1574 | || did_update == DID_FOLD |
| 1575 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1576 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1577 | && ( |
| 1578 | # ifdef FEAT_FOLDING |
| 1579 | (foldmethodIsSyntax(wp) |
| 1580 | && hasAnyFolding(wp)) || |
| 1581 | # endif |
| 1582 | syntax_check_changed(lnum))) |
| 1583 | #endif |
| 1584 | ))))) |
| 1585 | { |
| 1586 | #ifdef FEAT_SEARCH_EXTRA |
| 1587 | if (lnum == mod_top) |
| 1588 | top_to_mod = FALSE; |
| 1589 | #endif |
| 1590 | |
| 1591 | /* |
| 1592 | * When at start of changed lines: May scroll following lines |
| 1593 | * up or down to minimize redrawing. |
| 1594 | * Don't do this when the change continues until the end. |
| 1595 | * Don't scroll when dollar_vcol is non-zero, keep the "$". |
| 1596 | */ |
| 1597 | if (lnum == mod_top |
| 1598 | && mod_bot != MAXLNUM |
| 1599 | && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) |
| 1600 | { |
| 1601 | int old_rows = 0; |
| 1602 | int new_rows = 0; |
| 1603 | int xtra_rows; |
| 1604 | linenr_T l; |
| 1605 | |
| 1606 | /* Count the old number of window rows, using w_lines[], which |
| 1607 | * should still contain the sizes for the lines as they are |
| 1608 | * currently displayed. */ |
| 1609 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1610 | { |
| 1611 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1612 | * lines are part of the changed area. */ |
| 1613 | if (wp->w_lines[i].wl_valid |
| 1614 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1615 | break; |
| 1616 | old_rows += wp->w_lines[i].wl_size; |
| 1617 | #ifdef FEAT_FOLDING |
| 1618 | if (wp->w_lines[i].wl_valid |
| 1619 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1620 | { |
| 1621 | /* Must have found the last valid entry above mod_bot. |
| 1622 | * Add following invalid entries. */ |
| 1623 | ++i; |
| 1624 | while (i < wp->w_lines_valid |
| 1625 | && !wp->w_lines[i].wl_valid) |
| 1626 | old_rows += wp->w_lines[i++].wl_size; |
| 1627 | break; |
| 1628 | } |
| 1629 | #endif |
| 1630 | } |
| 1631 | |
| 1632 | if (i >= wp->w_lines_valid) |
| 1633 | { |
| 1634 | /* We can't find a valid line below the changed lines, |
| 1635 | * need to redraw until the end of the window. |
| 1636 | * Inserting/deleting lines has no use. */ |
| 1637 | bot_start = 0; |
| 1638 | } |
| 1639 | else |
| 1640 | { |
| 1641 | /* Able to count old number of rows: Count new window |
| 1642 | * rows, and may insert/delete lines */ |
| 1643 | j = idx; |
| 1644 | for (l = lnum; l < mod_bot; ++l) |
| 1645 | { |
| 1646 | #ifdef FEAT_FOLDING |
| 1647 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1648 | ++new_rows; |
| 1649 | else |
| 1650 | #endif |
| 1651 | #ifdef FEAT_DIFF |
| 1652 | if (l == wp->w_topline) |
| 1653 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1654 | + wp->w_topfill; |
| 1655 | else |
| 1656 | #endif |
| 1657 | new_rows += plines_win(wp, l, TRUE); |
| 1658 | ++j; |
| 1659 | if (new_rows > wp->w_height - row - 2) |
| 1660 | { |
| 1661 | /* it's getting too much, must redraw the rest */ |
| 1662 | new_rows = 9999; |
| 1663 | break; |
| 1664 | } |
| 1665 | } |
| 1666 | xtra_rows = new_rows - old_rows; |
| 1667 | if (xtra_rows < 0) |
| 1668 | { |
| 1669 | /* May scroll text up. If there is not enough |
| 1670 | * remaining text or scrolling fails, must redraw the |
| 1671 | * rest. If scrolling works, must redraw the text |
| 1672 | * below the scrolled text. */ |
| 1673 | if (row - xtra_rows >= wp->w_height - 2) |
| 1674 | mod_bot = MAXLNUM; |
| 1675 | else |
| 1676 | { |
| 1677 | check_for_delay(FALSE); |
| 1678 | if (win_del_lines(wp, row, |
| 1679 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1680 | mod_bot = MAXLNUM; |
| 1681 | else |
| 1682 | bot_start = wp->w_height + xtra_rows; |
| 1683 | } |
| 1684 | } |
| 1685 | else if (xtra_rows > 0) |
| 1686 | { |
| 1687 | /* May scroll text down. If there is not enough |
| 1688 | * remaining text of scrolling fails, must redraw the |
| 1689 | * rest. */ |
| 1690 | if (row + xtra_rows >= wp->w_height - 2) |
| 1691 | mod_bot = MAXLNUM; |
| 1692 | else |
| 1693 | { |
| 1694 | check_for_delay(FALSE); |
| 1695 | if (win_ins_lines(wp, row + old_rows, |
| 1696 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1697 | mod_bot = MAXLNUM; |
| 1698 | else if (top_end > row + old_rows) |
| 1699 | /* Scrolled the part at the top that requires |
| 1700 | * updating down. */ |
| 1701 | top_end += xtra_rows; |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | /* When not updating the rest, may need to move w_lines[] |
| 1706 | * entries. */ |
| 1707 | if (mod_bot != MAXLNUM && i != j) |
| 1708 | { |
| 1709 | if (j < i) |
| 1710 | { |
| 1711 | int x = row + new_rows; |
| 1712 | |
| 1713 | /* move entries in w_lines[] upwards */ |
| 1714 | for (;;) |
| 1715 | { |
| 1716 | /* stop at last valid entry in w_lines[] */ |
| 1717 | if (i >= wp->w_lines_valid) |
| 1718 | { |
| 1719 | wp->w_lines_valid = j; |
| 1720 | break; |
| 1721 | } |
| 1722 | wp->w_lines[j] = wp->w_lines[i]; |
| 1723 | /* stop at a line that won't fit */ |
| 1724 | if (x + (int)wp->w_lines[j].wl_size |
| 1725 | > wp->w_height) |
| 1726 | { |
| 1727 | wp->w_lines_valid = j + 1; |
| 1728 | break; |
| 1729 | } |
| 1730 | x += wp->w_lines[j++].wl_size; |
| 1731 | ++i; |
| 1732 | } |
| 1733 | if (bot_start > x) |
| 1734 | bot_start = x; |
| 1735 | } |
| 1736 | else /* j > i */ |
| 1737 | { |
| 1738 | /* move entries in w_lines[] downwards */ |
| 1739 | j -= i; |
| 1740 | wp->w_lines_valid += j; |
| 1741 | if (wp->w_lines_valid > wp->w_height) |
| 1742 | wp->w_lines_valid = wp->w_height; |
| 1743 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1744 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1745 | |
| 1746 | /* The w_lines[] entries for inserted lines are |
| 1747 | * now invalid, but wl_size may be used above. |
| 1748 | * Reset to zero. */ |
| 1749 | while (i >= idx) |
| 1750 | { |
| 1751 | wp->w_lines[i].wl_size = 0; |
| 1752 | wp->w_lines[i--].wl_valid = FALSE; |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | #ifdef FEAT_FOLDING |
| 1760 | /* |
| 1761 | * When lines are folded, display one line for all of them. |
| 1762 | * Otherwise, display normally (can be several display lines when |
| 1763 | * 'wrap' is on). |
| 1764 | */ |
| 1765 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1766 | if (fold_count != 0) |
| 1767 | { |
| 1768 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1769 | ++row; |
| 1770 | --fold_count; |
| 1771 | wp->w_lines[idx].wl_folded = TRUE; |
| 1772 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1773 | # ifdef FEAT_SYN_HL |
| 1774 | did_update = DID_FOLD; |
| 1775 | # endif |
| 1776 | } |
| 1777 | else |
| 1778 | #endif |
| 1779 | if (idx < wp->w_lines_valid |
| 1780 | && wp->w_lines[idx].wl_valid |
| 1781 | && wp->w_lines[idx].wl_lnum == lnum |
| 1782 | && lnum > wp->w_topline |
| 1783 | && !(dy_flags & DY_LASTLINE) |
| 1784 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1785 | #ifdef FEAT_DIFF |
| 1786 | && diff_check_fill(wp, lnum) == 0 |
| 1787 | #endif |
| 1788 | ) |
| 1789 | { |
| 1790 | /* This line is not going to fit. Don't draw anything here, |
| 1791 | * will draw "@ " lines below. */ |
| 1792 | row = wp->w_height + 1; |
| 1793 | } |
| 1794 | else |
| 1795 | { |
| 1796 | #ifdef FEAT_SEARCH_EXTRA |
| 1797 | prepare_search_hl(wp, lnum); |
| 1798 | #endif |
| 1799 | #ifdef FEAT_SYN_HL |
| 1800 | /* Let the syntax stuff know we skipped a few lines. */ |
| 1801 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1802 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1803 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1804 | #endif |
| 1805 | |
| 1806 | /* |
| 1807 | * Display one line. |
| 1808 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 1809 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1810 | |
| 1811 | #ifdef FEAT_FOLDING |
| 1812 | wp->w_lines[idx].wl_folded = FALSE; |
| 1813 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 1814 | #endif |
| 1815 | #ifdef FEAT_SYN_HL |
| 1816 | did_update = DID_LINE; |
| 1817 | syntax_last_parsed = lnum; |
| 1818 | #endif |
| 1819 | } |
| 1820 | |
| 1821 | wp->w_lines[idx].wl_lnum = lnum; |
| 1822 | wp->w_lines[idx].wl_valid = TRUE; |
| 1823 | if (row > wp->w_height) /* past end of screen */ |
| 1824 | { |
| 1825 | /* we may need the size of that too long line later on */ |
| 1826 | if (dollar_vcol == 0) |
| 1827 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 1828 | ++idx; |
| 1829 | break; |
| 1830 | } |
| 1831 | if (dollar_vcol == 0) |
| 1832 | wp->w_lines[idx].wl_size = row - srow; |
| 1833 | ++idx; |
| 1834 | #ifdef FEAT_FOLDING |
| 1835 | lnum += fold_count + 1; |
| 1836 | #else |
| 1837 | ++lnum; |
| 1838 | #endif |
| 1839 | } |
| 1840 | else |
| 1841 | { |
| 1842 | /* This line does not need updating, advance to the next one */ |
| 1843 | row += wp->w_lines[idx++].wl_size; |
| 1844 | if (row > wp->w_height) /* past end of screen */ |
| 1845 | break; |
| 1846 | #ifdef FEAT_FOLDING |
| 1847 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 1848 | #else |
| 1849 | ++lnum; |
| 1850 | #endif |
| 1851 | #ifdef FEAT_SYN_HL |
| 1852 | did_update = DID_NONE; |
| 1853 | #endif |
| 1854 | } |
| 1855 | |
| 1856 | if (lnum > buf->b_ml.ml_line_count) |
| 1857 | { |
| 1858 | eof = TRUE; |
| 1859 | break; |
| 1860 | } |
| 1861 | } |
| 1862 | /* |
| 1863 | * End of loop over all window lines. |
| 1864 | */ |
| 1865 | |
| 1866 | |
| 1867 | if (idx > wp->w_lines_valid) |
| 1868 | wp->w_lines_valid = idx; |
| 1869 | |
| 1870 | #ifdef FEAT_SYN_HL |
| 1871 | /* |
| 1872 | * Let the syntax stuff know we stop parsing here. |
| 1873 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1874 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1875 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1876 | #endif |
| 1877 | |
| 1878 | /* |
| 1879 | * If we didn't hit the end of the file, and we didn't finish the last |
| 1880 | * line we were working on, then the line didn't fit. |
| 1881 | */ |
| 1882 | wp->w_empty_rows = 0; |
| 1883 | #ifdef FEAT_DIFF |
| 1884 | wp->w_filler_rows = 0; |
| 1885 | #endif |
| 1886 | if (!eof && !didline) |
| 1887 | { |
| 1888 | if (lnum == wp->w_topline) |
| 1889 | { |
| 1890 | /* |
| 1891 | * Single line that does not fit! |
| 1892 | * Don't overwrite it, it can be edited. |
| 1893 | */ |
| 1894 | wp->w_botline = lnum + 1; |
| 1895 | } |
| 1896 | #ifdef FEAT_DIFF |
| 1897 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 1898 | { |
| 1899 | /* Window ends in filler lines. */ |
| 1900 | wp->w_botline = lnum; |
| 1901 | wp->w_filler_rows = wp->w_height - srow; |
| 1902 | } |
| 1903 | #endif |
| 1904 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 1905 | { |
| 1906 | /* |
| 1907 | * Last line isn't finished: Display "@@@" at the end. |
| 1908 | */ |
| 1909 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 1910 | W_WINROW(wp) + wp->w_height, |
| 1911 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 1912 | '@', '@', hl_attr(HLF_AT)); |
| 1913 | set_empty_rows(wp, srow); |
| 1914 | wp->w_botline = lnum; |
| 1915 | } |
| 1916 | else |
| 1917 | { |
| 1918 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 1919 | wp->w_botline = lnum; |
| 1920 | } |
| 1921 | } |
| 1922 | else |
| 1923 | { |
| 1924 | #ifdef FEAT_VERTSPLIT |
| 1925 | draw_vsep_win(wp, row); |
| 1926 | #endif |
| 1927 | if (eof) /* we hit the end of the file */ |
| 1928 | { |
| 1929 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 1930 | #ifdef FEAT_DIFF |
| 1931 | j = diff_check_fill(wp, wp->w_botline); |
| 1932 | if (j > 0 && !wp->w_botfill) |
| 1933 | { |
| 1934 | /* |
| 1935 | * Display filler lines at the end of the file |
| 1936 | */ |
| 1937 | if (char2cells(fill_diff) > 1) |
| 1938 | i = '-'; |
| 1939 | else |
| 1940 | i = fill_diff; |
| 1941 | if (row + j > wp->w_height) |
| 1942 | j = wp->w_height - row; |
| 1943 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 1944 | row += j; |
| 1945 | } |
| 1946 | #endif |
| 1947 | } |
| 1948 | else if (dollar_vcol == 0) |
| 1949 | wp->w_botline = lnum; |
| 1950 | |
| 1951 | /* make sure the rest of the screen is blank */ |
| 1952 | /* put '~'s on rows that aren't part of the file. */ |
| 1953 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 1954 | } |
| 1955 | |
| 1956 | /* Reset the type of redrawing required, the window has been updated. */ |
| 1957 | wp->w_redr_type = 0; |
| 1958 | #ifdef FEAT_DIFF |
| 1959 | wp->w_old_topfill = wp->w_topfill; |
| 1960 | wp->w_old_botfill = wp->w_botfill; |
| 1961 | #endif |
| 1962 | |
| 1963 | if (dollar_vcol == 0) |
| 1964 | { |
| 1965 | /* |
| 1966 | * There is a trick with w_botline. If we invalidate it on each |
| 1967 | * change that might modify it, this will cause a lot of expensive |
| 1968 | * calls to plines() in update_topline() each time. Therefore the |
| 1969 | * value of w_botline is often approximated, and this value is used to |
| 1970 | * compute the value of w_topline. If the value of w_botline was |
| 1971 | * wrong, check that the value of w_topline is correct (cursor is on |
| 1972 | * the visible part of the text). If it's not, we need to redraw |
| 1973 | * again. Mostly this just means scrolling up a few lines, so it |
| 1974 | * doesn't look too bad. Only do this for the current window (where |
| 1975 | * changes are relevant). |
| 1976 | */ |
| 1977 | wp->w_valid |= VALID_BOTLINE; |
| 1978 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 1979 | { |
| 1980 | recursive = TRUE; |
| 1981 | curwin->w_valid &= ~VALID_TOPLINE; |
| 1982 | update_topline(); /* may invalidate w_botline again */ |
| 1983 | if (must_redraw != 0) |
| 1984 | { |
| 1985 | /* Don't update for changes in buffer again. */ |
| 1986 | i = curbuf->b_mod_set; |
| 1987 | curbuf->b_mod_set = FALSE; |
| 1988 | win_update(curwin); |
| 1989 | must_redraw = 0; |
| 1990 | curbuf->b_mod_set = i; |
| 1991 | } |
| 1992 | recursive = FALSE; |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1997 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 1998 | if (!got_int) |
| 1999 | got_int = save_got_int; |
| 2000 | #endif |
| 2001 | } |
| 2002 | |
| 2003 | #ifdef FEAT_SIGNS |
| 2004 | static int draw_signcolumn __ARGS((win_T *wp)); |
| 2005 | |
| 2006 | /* |
| 2007 | * Return TRUE when window "wp" has a column to draw signs in. |
| 2008 | */ |
| 2009 | static int |
| 2010 | draw_signcolumn(wp) |
| 2011 | win_T *wp; |
| 2012 | { |
| 2013 | return (wp->w_buffer->b_signlist != NULL |
| 2014 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 2015 | || netbeans_active() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2016 | # endif |
| 2017 | ); |
| 2018 | } |
| 2019 | #endif |
| 2020 | |
| 2021 | /* |
| 2022 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2023 | * as the filler character. |
| 2024 | */ |
| 2025 | static void |
| 2026 | win_draw_end(wp, c1, c2, row, endrow, hl) |
| 2027 | win_T *wp; |
| 2028 | int c1; |
| 2029 | int c2; |
| 2030 | int row; |
| 2031 | int endrow; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2032 | hlf_T hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2033 | { |
| 2034 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2035 | int n = 0; |
| 2036 | # define FDC_OFF n |
| 2037 | #else |
| 2038 | # define FDC_OFF 0 |
| 2039 | #endif |
| 2040 | |
| 2041 | #ifdef FEAT_RIGHTLEFT |
| 2042 | if (wp->w_p_rl) |
| 2043 | { |
| 2044 | /* No check for cmdline window: should never be right-left. */ |
| 2045 | # ifdef FEAT_FOLDING |
| 2046 | n = wp->w_p_fdc; |
| 2047 | |
| 2048 | if (n > 0) |
| 2049 | { |
| 2050 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2051 | if (n > W_WIDTH(wp)) |
| 2052 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2053 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2054 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2055 | ' ', ' ', hl_attr(HLF_FC)); |
| 2056 | } |
| 2057 | # endif |
| 2058 | # ifdef FEAT_SIGNS |
| 2059 | if (draw_signcolumn(wp)) |
| 2060 | { |
| 2061 | int nn = n + 2; |
| 2062 | |
| 2063 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2064 | if (nn > W_WIDTH(wp)) |
| 2065 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2066 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2067 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2068 | ' ', ' ', hl_attr(HLF_SC)); |
| 2069 | n = nn; |
| 2070 | } |
| 2071 | # endif |
| 2072 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2073 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2074 | c2, c2, hl_attr(hl)); |
| 2075 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2076 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2077 | c1, c2, hl_attr(hl)); |
| 2078 | } |
| 2079 | else |
| 2080 | #endif |
| 2081 | { |
| 2082 | #ifdef FEAT_CMDWIN |
| 2083 | if (cmdwin_type != 0 && wp == curwin) |
| 2084 | { |
| 2085 | /* draw the cmdline character in the leftmost column */ |
| 2086 | n = 1; |
| 2087 | if (n > wp->w_width) |
| 2088 | n = wp->w_width; |
| 2089 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2090 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2091 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2092 | } |
| 2093 | #endif |
| 2094 | #ifdef FEAT_FOLDING |
| 2095 | if (wp->w_p_fdc > 0) |
| 2096 | { |
| 2097 | int nn = n + wp->w_p_fdc; |
| 2098 | |
| 2099 | /* draw the fold column at the left */ |
| 2100 | if (nn > W_WIDTH(wp)) |
| 2101 | nn = W_WIDTH(wp); |
| 2102 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2103 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2104 | ' ', ' ', hl_attr(HLF_FC)); |
| 2105 | n = nn; |
| 2106 | } |
| 2107 | #endif |
| 2108 | #ifdef FEAT_SIGNS |
| 2109 | if (draw_signcolumn(wp)) |
| 2110 | { |
| 2111 | int nn = n + 2; |
| 2112 | |
| 2113 | /* draw the sign column after the fold column */ |
| 2114 | if (nn > W_WIDTH(wp)) |
| 2115 | nn = W_WIDTH(wp); |
| 2116 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2117 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2118 | ' ', ' ', hl_attr(HLF_SC)); |
| 2119 | n = nn; |
| 2120 | } |
| 2121 | #endif |
| 2122 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2123 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2124 | c1, c2, hl_attr(hl)); |
| 2125 | } |
| 2126 | set_empty_rows(wp, row); |
| 2127 | } |
| 2128 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2129 | #ifdef FEAT_SYN_HL |
| 2130 | static int advance_color_col __ARGS((int vcol, int **color_cols)); |
| 2131 | |
| 2132 | /* |
| 2133 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2134 | */ |
| 2135 | static int |
| 2136 | advance_color_col(vcol, color_cols) |
| 2137 | int vcol; |
| 2138 | int **color_cols; |
| 2139 | { |
| 2140 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2141 | ++*color_cols; |
| 2142 | return (**color_cols >= 0); |
| 2143 | } |
| 2144 | #endif |
| 2145 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2146 | #ifdef FEAT_FOLDING |
| 2147 | /* |
| 2148 | * Display one folded line. |
| 2149 | */ |
| 2150 | static void |
| 2151 | fold_line(wp, fold_count, foldinfo, lnum, row) |
| 2152 | win_T *wp; |
| 2153 | long fold_count; |
| 2154 | foldinfo_T *foldinfo; |
| 2155 | linenr_T lnum; |
| 2156 | int row; |
| 2157 | { |
| 2158 | char_u buf[51]; |
| 2159 | pos_T *top, *bot; |
| 2160 | linenr_T lnume = lnum + fold_count - 1; |
| 2161 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2162 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2163 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2164 | int col; |
| 2165 | int txtcol; |
| 2166 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2167 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2168 | |
| 2169 | /* Build the fold line: |
| 2170 | * 1. Add the cmdwin_type for the command-line window |
| 2171 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2172 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2173 | * 4. Compose the text |
| 2174 | * 5. Add the text |
| 2175 | * 6. set highlighting for the Visual area an other text |
| 2176 | */ |
| 2177 | col = 0; |
| 2178 | |
| 2179 | /* |
| 2180 | * 1. Add the cmdwin_type for the command-line window |
| 2181 | * Ignores 'rightleft', this window is never right-left. |
| 2182 | */ |
| 2183 | #ifdef FEAT_CMDWIN |
| 2184 | if (cmdwin_type != 0 && wp == curwin) |
| 2185 | { |
| 2186 | ScreenLines[off] = cmdwin_type; |
| 2187 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2188 | #ifdef FEAT_MBYTE |
| 2189 | if (enc_utf8) |
| 2190 | ScreenLinesUC[off] = 0; |
| 2191 | #endif |
| 2192 | ++col; |
| 2193 | } |
| 2194 | #endif |
| 2195 | |
| 2196 | /* |
| 2197 | * 2. Add the 'foldcolumn' |
| 2198 | */ |
| 2199 | fdc = wp->w_p_fdc; |
| 2200 | if (fdc > W_WIDTH(wp) - col) |
| 2201 | fdc = W_WIDTH(wp) - col; |
| 2202 | if (fdc > 0) |
| 2203 | { |
| 2204 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2205 | #ifdef FEAT_RIGHTLEFT |
| 2206 | if (wp->w_p_rl) |
| 2207 | { |
| 2208 | int i; |
| 2209 | |
| 2210 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2211 | hl_attr(HLF_FC)); |
| 2212 | /* reverse the fold column */ |
| 2213 | for (i = 0; i < fdc; ++i) |
| 2214 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2215 | } |
| 2216 | else |
| 2217 | #endif |
| 2218 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2219 | col += fdc; |
| 2220 | } |
| 2221 | |
| 2222 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2223 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2224 | for (ri = 0; ri < l; ++ri) \ |
| 2225 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2226 | else \ |
| 2227 | for (ri = 0; ri < l; ++ri) \ |
| 2228 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2229 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2230 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2231 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2232 | #endif |
| 2233 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2234 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2235 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2236 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2237 | |
| 2238 | #ifdef FEAT_SIGNS |
| 2239 | /* If signs are being displayed, add two spaces. */ |
| 2240 | if (draw_signcolumn(wp)) |
| 2241 | { |
| 2242 | len = W_WIDTH(wp) - col; |
| 2243 | if (len > 0) |
| 2244 | { |
| 2245 | if (len > 2) |
| 2246 | len = 2; |
| 2247 | # ifdef FEAT_RIGHTLEFT |
| 2248 | if (wp->w_p_rl) |
| 2249 | /* the line number isn't reversed */ |
| 2250 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2251 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2252 | else |
| 2253 | # endif |
| 2254 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2255 | col += len; |
| 2256 | } |
| 2257 | } |
| 2258 | #endif |
| 2259 | |
| 2260 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2261 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2262 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2263 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2264 | { |
| 2265 | len = W_WIDTH(wp) - col; |
| 2266 | if (len > 0) |
| 2267 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2268 | int w = number_width(wp); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2269 | long num; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2270 | |
| 2271 | if (len > w + 1) |
| 2272 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2273 | |
| 2274 | if (wp->w_p_nu) |
| 2275 | /* 'number' */ |
| 2276 | num = (long)lnum; |
| 2277 | else |
| 2278 | /* 'relativenumber', don't use negative numbers */ |
| 2279 | num = (long)abs((int)get_cursor_rel_lnum(wp, lnum)); |
| 2280 | |
| 2281 | sprintf((char *)buf, "%*ld ", w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2282 | #ifdef FEAT_RIGHTLEFT |
| 2283 | if (wp->w_p_rl) |
| 2284 | /* the line number isn't reversed */ |
| 2285 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2286 | hl_attr(HLF_FL)); |
| 2287 | else |
| 2288 | #endif |
| 2289 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2290 | col += len; |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | /* |
| 2295 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2296 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2297 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2298 | |
| 2299 | txtcol = col; /* remember where text starts */ |
| 2300 | |
| 2301 | /* |
| 2302 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2303 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2304 | * in columns number-col - window-width. |
| 2305 | */ |
| 2306 | #ifdef FEAT_MBYTE |
| 2307 | if (has_mbyte) |
| 2308 | { |
| 2309 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2310 | int u8c, u8cc[MAX_MCO]; |
| 2311 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2312 | int idx; |
| 2313 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2314 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2315 | # ifdef FEAT_ARABIC |
| 2316 | int prev_c = 0; /* previous Arabic character */ |
| 2317 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2318 | # endif |
| 2319 | |
| 2320 | # ifdef FEAT_RIGHTLEFT |
| 2321 | if (wp->w_p_rl) |
| 2322 | idx = off; |
| 2323 | else |
| 2324 | # endif |
| 2325 | idx = off + col; |
| 2326 | |
| 2327 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2328 | for (p = text; *p != NUL; ) |
| 2329 | { |
| 2330 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2331 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2332 | if (col + cells > W_WIDTH(wp) |
| 2333 | # ifdef FEAT_RIGHTLEFT |
| 2334 | - (wp->w_p_rl ? col : 0) |
| 2335 | # endif |
| 2336 | ) |
| 2337 | break; |
| 2338 | ScreenLines[idx] = *p; |
| 2339 | if (enc_utf8) |
| 2340 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2341 | u8c = utfc_ptr2char(p, u8cc); |
| 2342 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2343 | { |
| 2344 | ScreenLinesUC[idx] = 0; |
| 2345 | #ifdef FEAT_ARABIC |
| 2346 | prev_c = u8c; |
| 2347 | #endif |
| 2348 | } |
| 2349 | else |
| 2350 | { |
| 2351 | #ifdef FEAT_ARABIC |
| 2352 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2353 | { |
| 2354 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2355 | int pc, pc1, nc; |
| 2356 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2357 | int firstbyte = *p; |
| 2358 | |
| 2359 | /* The idea of what is the previous and next |
| 2360 | * character depends on 'rightleft'. */ |
| 2361 | if (wp->w_p_rl) |
| 2362 | { |
| 2363 | pc = prev_c; |
| 2364 | pc1 = prev_c1; |
| 2365 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2366 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2367 | } |
| 2368 | else |
| 2369 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2370 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2371 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2372 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2373 | } |
| 2374 | prev_c = u8c; |
| 2375 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2376 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2377 | pc, pc1, nc); |
| 2378 | ScreenLines[idx] = firstbyte; |
| 2379 | } |
| 2380 | else |
| 2381 | prev_c = u8c; |
| 2382 | #endif |
| 2383 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2384 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2385 | if (u8c >= 0x10000) |
| 2386 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2387 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2388 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2389 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2390 | for (i = 0; i < Screen_mco; ++i) |
| 2391 | { |
| 2392 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2393 | if (u8cc[i] == 0) |
| 2394 | break; |
| 2395 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2396 | } |
| 2397 | if (cells > 1) |
| 2398 | ScreenLines[idx + 1] = 0; |
| 2399 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2400 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2401 | /* double-byte single width character */ |
| 2402 | ScreenLines2[idx] = p[1]; |
| 2403 | else if (cells > 1) |
| 2404 | /* double-width character */ |
| 2405 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2406 | col += cells; |
| 2407 | idx += cells; |
| 2408 | p += c_len; |
| 2409 | } |
| 2410 | } |
| 2411 | else |
| 2412 | #endif |
| 2413 | { |
| 2414 | len = (int)STRLEN(text); |
| 2415 | if (len > W_WIDTH(wp) - col) |
| 2416 | len = W_WIDTH(wp) - col; |
| 2417 | if (len > 0) |
| 2418 | { |
| 2419 | #ifdef FEAT_RIGHTLEFT |
| 2420 | if (wp->w_p_rl) |
| 2421 | STRNCPY(current_ScreenLine, text, len); |
| 2422 | else |
| 2423 | #endif |
| 2424 | STRNCPY(current_ScreenLine + col, text, len); |
| 2425 | col += len; |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | /* Fill the rest of the line with the fold filler */ |
| 2430 | #ifdef FEAT_RIGHTLEFT |
| 2431 | if (wp->w_p_rl) |
| 2432 | col -= txtcol; |
| 2433 | #endif |
| 2434 | while (col < W_WIDTH(wp) |
| 2435 | #ifdef FEAT_RIGHTLEFT |
| 2436 | - (wp->w_p_rl ? txtcol : 0) |
| 2437 | #endif |
| 2438 | ) |
| 2439 | { |
| 2440 | #ifdef FEAT_MBYTE |
| 2441 | if (enc_utf8) |
| 2442 | { |
| 2443 | if (fill_fold >= 0x80) |
| 2444 | { |
| 2445 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2446 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2447 | } |
| 2448 | else |
| 2449 | ScreenLinesUC[off + col] = 0; |
| 2450 | } |
| 2451 | #endif |
| 2452 | ScreenLines[off + col++] = fill_fold; |
| 2453 | } |
| 2454 | |
| 2455 | if (text != buf) |
| 2456 | vim_free(text); |
| 2457 | |
| 2458 | /* |
| 2459 | * 6. set highlighting for the Visual area an other text. |
| 2460 | * If all folded lines are in the Visual area, highlight the line. |
| 2461 | */ |
| 2462 | #ifdef FEAT_VISUAL |
| 2463 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2464 | { |
| 2465 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2466 | { |
| 2467 | /* Visual is after curwin->w_cursor */ |
| 2468 | top = &curwin->w_cursor; |
| 2469 | bot = &VIsual; |
| 2470 | } |
| 2471 | else |
| 2472 | { |
| 2473 | /* Visual is before curwin->w_cursor */ |
| 2474 | top = &VIsual; |
| 2475 | bot = &curwin->w_cursor; |
| 2476 | } |
| 2477 | if (lnum >= top->lnum |
| 2478 | && lnume <= bot->lnum |
| 2479 | && (VIsual_mode != 'v' |
| 2480 | || ((lnum > top->lnum |
| 2481 | || (lnum == top->lnum |
| 2482 | && top->col == 0)) |
| 2483 | && (lnume < bot->lnum |
| 2484 | || (lnume == bot->lnum |
| 2485 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2486 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2487 | { |
| 2488 | if (VIsual_mode == Ctrl_V) |
| 2489 | { |
| 2490 | /* Visual block mode: highlight the chars part of the block */ |
| 2491 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2492 | { |
| 2493 | if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2494 | len = wp->w_old_cursor_lcol; |
| 2495 | else |
| 2496 | len = W_WIDTH(wp) - txtcol; |
| 2497 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2498 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2499 | } |
| 2500 | } |
| 2501 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2502 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2503 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2504 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2505 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | #endif |
| 2509 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2510 | #ifdef FEAT_SYN_HL |
| 2511 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2512 | if (wp->w_p_cuc) |
| 2513 | { |
| 2514 | txtcol += wp->w_virtcol; |
| 2515 | if (wp->w_p_wrap) |
| 2516 | txtcol -= wp->w_skipcol; |
| 2517 | else |
| 2518 | txtcol -= wp->w_leftcol; |
| 2519 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2520 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2521 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2522 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2523 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2524 | |
| 2525 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2526 | (int)W_WIDTH(wp), FALSE); |
| 2527 | |
| 2528 | /* |
| 2529 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2530 | * updated (saves a call to plines() later). |
| 2531 | */ |
| 2532 | if (wp == curwin |
| 2533 | && lnum <= curwin->w_cursor.lnum |
| 2534 | && lnume >= curwin->w_cursor.lnum) |
| 2535 | { |
| 2536 | curwin->w_cline_row = row; |
| 2537 | curwin->w_cline_height = 1; |
| 2538 | curwin->w_cline_folded = TRUE; |
| 2539 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | /* |
| 2544 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2545 | */ |
| 2546 | static void |
| 2547 | copy_text_attr(off, buf, len, attr) |
| 2548 | int off; |
| 2549 | char_u *buf; |
| 2550 | int len; |
| 2551 | int attr; |
| 2552 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2553 | int i; |
| 2554 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2555 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2556 | # ifdef FEAT_MBYTE |
| 2557 | if (enc_utf8) |
| 2558 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2559 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2560 | for (i = 0; i < len; ++i) |
| 2561 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | /* |
| 2565 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2566 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2567 | */ |
| 2568 | static void |
| 2569 | fill_foldcolumn(p, wp, closed, lnum) |
| 2570 | char_u *p; |
| 2571 | win_T *wp; |
| 2572 | int closed; /* TRUE of FALSE */ |
| 2573 | linenr_T lnum; /* current line number */ |
| 2574 | { |
| 2575 | int i = 0; |
| 2576 | int level; |
| 2577 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2578 | int empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2579 | |
| 2580 | /* Init to all spaces. */ |
| 2581 | copy_spaces(p, (size_t)wp->w_p_fdc); |
| 2582 | |
| 2583 | level = win_foldinfo.fi_level; |
| 2584 | if (level > 0) |
| 2585 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2586 | /* If there is only one column put more info in it. */ |
| 2587 | empty = (wp->w_p_fdc == 1) ? 0 : 1; |
| 2588 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2589 | /* If the column is too narrow, we start at the lowest level that |
| 2590 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2591 | first_level = level - wp->w_p_fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2592 | if (first_level < 1) |
| 2593 | first_level = 1; |
| 2594 | |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2595 | for (i = 0; i + empty < wp->w_p_fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2596 | { |
| 2597 | if (win_foldinfo.fi_lnum == lnum |
| 2598 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2599 | p[i] = '-'; |
| 2600 | else if (first_level == 1) |
| 2601 | p[i] = '|'; |
| 2602 | else if (first_level + i <= 9) |
| 2603 | p[i] = '0' + first_level + i; |
| 2604 | else |
| 2605 | p[i] = '>'; |
| 2606 | if (first_level + i == level) |
| 2607 | break; |
| 2608 | } |
| 2609 | } |
| 2610 | if (closed) |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2611 | p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2612 | } |
| 2613 | #endif /* FEAT_FOLDING */ |
| 2614 | |
| 2615 | /* |
| 2616 | * Display line "lnum" of window 'wp' on the screen. |
| 2617 | * Start at row "startrow", stop when "endrow" is reached. |
| 2618 | * wp->w_virtcol needs to be valid. |
| 2619 | * |
| 2620 | * Return the number of last row the line occupies. |
| 2621 | */ |
| 2622 | static int |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2623 | win_line(wp, lnum, startrow, endrow, nochange) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2624 | win_T *wp; |
| 2625 | linenr_T lnum; |
| 2626 | int startrow; |
| 2627 | int endrow; |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2628 | int nochange UNUSED; /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2629 | { |
| 2630 | int col; /* visual column on screen */ |
| 2631 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2632 | int c = 0; /* init for GCC */ |
| 2633 | long vcol = 0; /* virtual column (for tabs) */ |
| 2634 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2635 | char_u *line; /* current line */ |
| 2636 | char_u *ptr; /* current position in "line" */ |
| 2637 | int row; /* row in the window, excl w_winrow */ |
| 2638 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2639 | |
| 2640 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2641 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2642 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2643 | int c_extra = NUL; /* extra chars, all the same */ |
| 2644 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2645 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2646 | displaying lcs_eol at end-of-line */ |
| 2647 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2648 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2649 | |
| 2650 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2651 | int saved_n_extra = 0; |
| 2652 | char_u *saved_p_extra = NULL; |
| 2653 | int saved_c_extra = 0; |
| 2654 | int saved_char_attr = 0; |
| 2655 | |
| 2656 | int n_attr = 0; /* chars with special attr */ |
| 2657 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2658 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2659 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2660 | |
| 2661 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2662 | |
| 2663 | int fromcol, tocol; /* start/end of inverting */ |
| 2664 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2665 | int noinvcur = FALSE; /* don't invert the cursor */ |
| 2666 | #ifdef FEAT_VISUAL |
| 2667 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2668 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2669 | #endif |
| 2670 | pos_T pos; |
| 2671 | long v; |
| 2672 | |
| 2673 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2674 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2675 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2676 | in this line */ |
| 2677 | int attr = 0; /* attributes for area highlighting */ |
| 2678 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2679 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2680 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2681 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2682 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2683 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2684 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2685 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2686 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2687 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2688 | #endif |
| 2689 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2690 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2691 | # define SPWORDLEN 150 |
| 2692 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2693 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2694 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2695 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2696 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2697 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2698 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2699 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2700 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2701 | static int cap_col = -1; /* column to check for Cap word */ |
| 2702 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2703 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2704 | #endif |
| 2705 | int extra_check; /* has syntax or linebreak */ |
| 2706 | #ifdef FEAT_MBYTE |
| 2707 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2708 | int mb_l = 1; /* multi-byte byte length */ |
| 2709 | int mb_c = 0; /* decoded multi-byte character */ |
| 2710 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2711 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2712 | #endif |
| 2713 | #ifdef FEAT_DIFF |
| 2714 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2715 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2716 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2717 | int change_start = MAXCOL; /* first col of changed area */ |
| 2718 | int change_end = -1; /* last col of changed area */ |
| 2719 | #endif |
| 2720 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2721 | #ifdef FEAT_LINEBREAK |
| 2722 | int need_showbreak = FALSE; |
| 2723 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2724 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2725 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2726 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 2727 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2728 | #endif |
| 2729 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2730 | matchitem_T *cur; /* points to the match list */ |
| 2731 | match_T *shl; /* points to search_hl or a match */ |
| 2732 | int shl_flag; /* flag to indicate whether search_hl |
| 2733 | has been processed or not */ |
| 2734 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 2735 | equals startcol of search_hl or one |
| 2736 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2737 | #endif |
| 2738 | #ifdef FEAT_ARABIC |
| 2739 | int prev_c = 0; /* previous Arabic character */ |
| 2740 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2741 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2742 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 2743 | int did_line_attr = 0; |
| 2744 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2745 | |
| 2746 | /* draw_state: items that are drawn in sequence: */ |
| 2747 | #define WL_START 0 /* nothing done yet */ |
| 2748 | #ifdef FEAT_CMDWIN |
| 2749 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 2750 | #else |
| 2751 | # define WL_CMDLINE WL_START |
| 2752 | #endif |
| 2753 | #ifdef FEAT_FOLDING |
| 2754 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 2755 | #else |
| 2756 | # define WL_FOLD WL_CMDLINE |
| 2757 | #endif |
| 2758 | #ifdef FEAT_SIGNS |
| 2759 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 2760 | #else |
| 2761 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 2762 | #endif |
| 2763 | #define WL_NR WL_SIGN + 1 /* line number */ |
| 2764 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 2765 | # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ |
| 2766 | #else |
| 2767 | # define WL_SBR WL_NR |
| 2768 | #endif |
| 2769 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 2770 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 2771 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2772 | int feedback_col = 0; |
| 2773 | int feedback_old_attr = -1; |
| 2774 | #endif |
| 2775 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2776 | #ifdef FEAT_CONCEAL |
| 2777 | int syntax_flags = 0; |
| 2778 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 2779 | int first_conceal = (wp->w_p_conc != 3); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2780 | int is_concealing = FALSE; |
| 2781 | int boguscols = 0; /* nonexistent columns added to force |
| 2782 | wrapping */ |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 2783 | int vcol_off = 0; /* offset for concealed characters */ |
| 2784 | # define VCOL_HLC (vcol - vcol_off) |
| 2785 | #else |
| 2786 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2787 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2788 | |
| 2789 | if (startrow > endrow) /* past the end already! */ |
| 2790 | return startrow; |
| 2791 | |
| 2792 | row = startrow; |
| 2793 | screen_row = row + W_WINROW(wp); |
| 2794 | |
| 2795 | /* |
| 2796 | * To speed up the loop below, set extra_check when there is linebreak, |
| 2797 | * trailing white space and/or syntax processing to be done. |
| 2798 | */ |
| 2799 | #ifdef FEAT_LINEBREAK |
| 2800 | extra_check = wp->w_p_lbr; |
| 2801 | #else |
| 2802 | extra_check = 0; |
| 2803 | #endif |
| 2804 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2805 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2806 | { |
| 2807 | /* Prepare for syntax highlighting in this line. When there is an |
| 2808 | * error, stop syntax highlighting. */ |
| 2809 | save_did_emsg = did_emsg; |
| 2810 | did_emsg = FALSE; |
| 2811 | syntax_start(wp, lnum); |
| 2812 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2813 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2814 | else |
| 2815 | { |
| 2816 | did_emsg = save_did_emsg; |
| 2817 | has_syntax = TRUE; |
| 2818 | extra_check = TRUE; |
| 2819 | } |
| 2820 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2821 | |
| 2822 | /* Check for columns to display for 'colorcolumn'. */ |
| 2823 | color_cols = wp->w_p_cc_cols; |
| 2824 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 2825 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2826 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2827 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2828 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 2829 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2830 | && *wp->w_s->b_p_spl != NUL |
| 2831 | && wp->w_s->b_langp.ga_len > 0 |
| 2832 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2833 | { |
| 2834 | /* Prepare for spell checking. */ |
| 2835 | has_spell = TRUE; |
| 2836 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2837 | |
| 2838 | /* Get the start of the next line, so that words that wrap to the next |
| 2839 | * line are found too: "et<line-break>al.". |
| 2840 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 2841 | nextline[SPWORDLEN] = NUL; |
| 2842 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 2843 | { |
| 2844 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 2845 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 2846 | } |
| 2847 | |
| 2848 | /* When a word wrapped from the previous line the start of the current |
| 2849 | * line is valid. */ |
| 2850 | if (lnum == checked_lnum) |
| 2851 | cur_checked_col = checked_col; |
| 2852 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2853 | |
| 2854 | /* When there was a sentence end in the previous line may require a |
| 2855 | * word starting with capital in this line. In line 1 always check |
| 2856 | * the first word. */ |
| 2857 | if (lnum != capcol_lnum) |
| 2858 | cap_col = -1; |
| 2859 | if (lnum == 1) |
| 2860 | cap_col = 0; |
| 2861 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2862 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2863 | #endif |
| 2864 | |
| 2865 | /* |
| 2866 | * handle visual active in this window |
| 2867 | */ |
| 2868 | fromcol = -10; |
| 2869 | tocol = MAXCOL; |
| 2870 | #ifdef FEAT_VISUAL |
| 2871 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2872 | { |
| 2873 | /* Visual is after curwin->w_cursor */ |
| 2874 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2875 | { |
| 2876 | top = &curwin->w_cursor; |
| 2877 | bot = &VIsual; |
| 2878 | } |
| 2879 | else /* Visual is before curwin->w_cursor */ |
| 2880 | { |
| 2881 | top = &VIsual; |
| 2882 | bot = &curwin->w_cursor; |
| 2883 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2884 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2885 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 2886 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2887 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2888 | { |
| 2889 | fromcol = wp->w_old_cursor_fcol; |
| 2890 | tocol = wp->w_old_cursor_lcol; |
| 2891 | } |
| 2892 | } |
| 2893 | else /* non-block mode */ |
| 2894 | { |
| 2895 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 2896 | fromcol = 0; |
| 2897 | else if (lnum == top->lnum) |
| 2898 | { |
| 2899 | if (VIsual_mode == 'V') /* linewise */ |
| 2900 | fromcol = 0; |
| 2901 | else |
| 2902 | { |
| 2903 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 2904 | if (gchar_pos(top) == NUL) |
| 2905 | tocol = fromcol + 1; |
| 2906 | } |
| 2907 | } |
| 2908 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 2909 | { |
| 2910 | if (*p_sel == 'e' && bot->col == 0 |
| 2911 | #ifdef FEAT_VIRTUALEDIT |
| 2912 | && bot->coladd == 0 |
| 2913 | #endif |
| 2914 | ) |
| 2915 | { |
| 2916 | fromcol = -10; |
| 2917 | tocol = MAXCOL; |
| 2918 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2919 | else if (bot->col == MAXCOL) |
| 2920 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2921 | else |
| 2922 | { |
| 2923 | pos = *bot; |
| 2924 | if (*p_sel == 'e') |
| 2925 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2926 | else |
| 2927 | { |
| 2928 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 2929 | ++tocol; |
| 2930 | } |
| 2931 | } |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | #ifndef MSDOS |
| 2936 | /* Check if the character under the cursor should not be inverted */ |
| 2937 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
| 2938 | # ifdef FEAT_GUI |
| 2939 | && !gui.in_use |
| 2940 | # endif |
| 2941 | ) |
| 2942 | noinvcur = TRUE; |
| 2943 | #endif |
| 2944 | |
| 2945 | /* if inverting in this line set area_highlighting */ |
| 2946 | if (fromcol >= 0) |
| 2947 | { |
| 2948 | area_highlighting = TRUE; |
| 2949 | attr = hl_attr(HLF_V); |
| 2950 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
| 2951 | if (clip_star.available && !clip_star.owned && clip_isautosel()) |
| 2952 | attr = hl_attr(HLF_VNC); |
| 2953 | #endif |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2958 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2959 | */ |
| 2960 | else |
| 2961 | #endif /* FEAT_VISUAL */ |
| 2962 | if (highlight_match |
| 2963 | && wp == curwin |
| 2964 | && lnum >= curwin->w_cursor.lnum |
| 2965 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 2966 | { |
| 2967 | if (lnum == curwin->w_cursor.lnum) |
| 2968 | getvcol(curwin, &(curwin->w_cursor), |
| 2969 | (colnr_T *)&fromcol, NULL, NULL); |
| 2970 | else |
| 2971 | fromcol = 0; |
| 2972 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 2973 | { |
| 2974 | pos.lnum = lnum; |
| 2975 | pos.col = search_match_endcol; |
| 2976 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2977 | } |
| 2978 | else |
| 2979 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 2980 | /* do at least one character; happens when past end of line */ |
| 2981 | if (fromcol == tocol) |
| 2982 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2983 | area_highlighting = TRUE; |
| 2984 | attr = hl_attr(HLF_I); |
| 2985 | } |
| 2986 | |
| 2987 | #ifdef FEAT_DIFF |
| 2988 | filler_lines = diff_check(wp, lnum); |
| 2989 | if (filler_lines < 0) |
| 2990 | { |
| 2991 | if (filler_lines == -1) |
| 2992 | { |
| 2993 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 2994 | diff_hlf = HLF_ADD; /* added line */ |
| 2995 | else if (change_start == 0) |
| 2996 | diff_hlf = HLF_TXD; /* changed text */ |
| 2997 | else |
| 2998 | diff_hlf = HLF_CHD; /* changed line */ |
| 2999 | } |
| 3000 | else |
| 3001 | diff_hlf = HLF_ADD; /* added line */ |
| 3002 | filler_lines = 0; |
| 3003 | area_highlighting = TRUE; |
| 3004 | } |
| 3005 | if (lnum == wp->w_topline) |
| 3006 | filler_lines = wp->w_topfill; |
| 3007 | filler_todo = filler_lines; |
| 3008 | #endif |
| 3009 | |
| 3010 | #ifdef LINE_ATTR |
| 3011 | # ifdef FEAT_SIGNS |
| 3012 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3013 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3014 | if (v != 0) |
| 3015 | line_attr = sign_get_attr((int)v, TRUE); |
| 3016 | # endif |
| 3017 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3018 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3019 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3020 | line_attr = hl_attr(HLF_L); |
| 3021 | # endif |
| 3022 | if (line_attr != 0) |
| 3023 | area_highlighting = TRUE; |
| 3024 | #endif |
| 3025 | |
| 3026 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3027 | ptr = line; |
| 3028 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3029 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3030 | if (has_spell) |
| 3031 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3032 | /* For checking first word with a capital skip white space. */ |
| 3033 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3034 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3035 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3036 | /* To be able to spell-check over line boundaries copy the end of the |
| 3037 | * current line into nextline[]. Above the start of the next line was |
| 3038 | * copied to nextline[SPWORDLEN]. */ |
| 3039 | if (nextline[SPWORDLEN] == NUL) |
| 3040 | { |
| 3041 | /* No next line or it is empty. */ |
| 3042 | nextlinecol = MAXCOL; |
| 3043 | nextline_idx = 0; |
| 3044 | } |
| 3045 | else |
| 3046 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3047 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3048 | if (v < SPWORDLEN) |
| 3049 | { |
| 3050 | /* Short line, use it completely and append the start of the |
| 3051 | * next line. */ |
| 3052 | nextlinecol = 0; |
| 3053 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3054 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3055 | nextline_idx = v + 1; |
| 3056 | } |
| 3057 | else |
| 3058 | { |
| 3059 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3060 | nextlinecol = v - SPWORDLEN; |
| 3061 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3062 | nextline_idx = SPWORDLEN + 1; |
| 3063 | } |
| 3064 | } |
| 3065 | } |
| 3066 | #endif |
| 3067 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3068 | /* find start of trailing whitespace */ |
| 3069 | if (wp->w_p_list && lcs_trail) |
| 3070 | { |
| 3071 | trailcol = (colnr_T)STRLEN(ptr); |
| 3072 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3073 | --trailcol; |
| 3074 | trailcol += (colnr_T) (ptr - line); |
| 3075 | extra_check = TRUE; |
| 3076 | } |
| 3077 | |
| 3078 | /* |
| 3079 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3080 | * first character to be displayed. |
| 3081 | */ |
| 3082 | if (wp->w_p_wrap) |
| 3083 | v = wp->w_skipcol; |
| 3084 | else |
| 3085 | v = wp->w_leftcol; |
| 3086 | if (v > 0) |
| 3087 | { |
| 3088 | #ifdef FEAT_MBYTE |
| 3089 | char_u *prev_ptr = ptr; |
| 3090 | #endif |
| 3091 | while (vcol < v && *ptr != NUL) |
| 3092 | { |
| 3093 | c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); |
| 3094 | vcol += c; |
| 3095 | #ifdef FEAT_MBYTE |
| 3096 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3097 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3098 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3101 | #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
| 3102 | /* When: |
| 3103 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3104 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3105 | * - 'virtualedit' is set, or |
| 3106 | * - the visual mode is active, |
| 3107 | * the end of the line may be before the start of the displayed part. |
| 3108 | */ |
| 3109 | if (vcol < v && ( |
| 3110 | # ifdef FEAT_SYN_HL |
| 3111 | wp->w_p_cuc |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3112 | || draw_color_col |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3113 | # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
| 3114 | || |
| 3115 | # endif |
| 3116 | # endif |
| 3117 | # ifdef FEAT_VIRTUALEDIT |
| 3118 | virtual_active() |
| 3119 | # ifdef FEAT_VISUAL |
| 3120 | || |
| 3121 | # endif |
| 3122 | # endif |
| 3123 | # ifdef FEAT_VISUAL |
| 3124 | (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3125 | # endif |
| 3126 | )) |
| 3127 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3128 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3129 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3130 | #endif |
| 3131 | |
| 3132 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3133 | * that character but skip the first few screen characters. */ |
| 3134 | if (vcol > v) |
| 3135 | { |
| 3136 | vcol -= c; |
| 3137 | #ifdef FEAT_MBYTE |
| 3138 | ptr = prev_ptr; |
| 3139 | #else |
| 3140 | --ptr; |
| 3141 | #endif |
| 3142 | n_skip = v - vcol; |
| 3143 | } |
| 3144 | |
| 3145 | /* |
| 3146 | * Adjust for when the inverted text is before the screen, |
| 3147 | * and when the start of the inverted text is before the screen. |
| 3148 | */ |
| 3149 | if (tocol <= vcol) |
| 3150 | fromcol = 0; |
| 3151 | else if (fromcol >= 0 && fromcol < vcol) |
| 3152 | fromcol = vcol; |
| 3153 | |
| 3154 | #ifdef FEAT_LINEBREAK |
| 3155 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3156 | if (wp->w_p_wrap) |
| 3157 | need_showbreak = TRUE; |
| 3158 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3159 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3160 | /* When spell checking a word we need to figure out the start of the |
| 3161 | * word and if it's badly spelled or not. */ |
| 3162 | if (has_spell) |
| 3163 | { |
| 3164 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3165 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3166 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3167 | |
| 3168 | pos = wp->w_cursor; |
| 3169 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3170 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3171 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3172 | |
| 3173 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3174 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3175 | ptr = line + linecol; |
| 3176 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3177 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3178 | { |
| 3179 | /* no bad word found at line start, don't check until end of a |
| 3180 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3181 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3182 | word_end = (int)(spell_to_word_end(ptr, wp) |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3183 | - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3184 | } |
| 3185 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3186 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3187 | /* bad word found, use attributes until end of word */ |
| 3188 | word_end = wp->w_cursor.col + len + 1; |
| 3189 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3190 | /* Turn index into actual attributes. */ |
| 3191 | if (spell_hlf != HLF_COUNT) |
| 3192 | spell_attr = highlight_attr[spell_hlf]; |
| 3193 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3194 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3195 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3196 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3197 | /* Need to restart syntax highlighting for this line. */ |
| 3198 | if (has_syntax) |
| 3199 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3200 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3201 | } |
| 3202 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | /* |
| 3206 | * Correct highlighting for cursor that can't be disabled. |
| 3207 | * Avoids having to check this for each character. |
| 3208 | */ |
| 3209 | if (fromcol >= 0) |
| 3210 | { |
| 3211 | if (noinvcur) |
| 3212 | { |
| 3213 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3214 | { |
| 3215 | /* highlighting starts at cursor, let it start just after the |
| 3216 | * cursor */ |
| 3217 | fromcol_prev = fromcol; |
| 3218 | fromcol = -1; |
| 3219 | } |
| 3220 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3221 | /* restart highlighting after the cursor */ |
| 3222 | fromcol_prev = wp->w_virtcol; |
| 3223 | } |
| 3224 | if (fromcol >= tocol) |
| 3225 | fromcol = -1; |
| 3226 | } |
| 3227 | |
| 3228 | #ifdef FEAT_SEARCH_EXTRA |
| 3229 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3230 | * Handle highlighting the last used search pattern and matches. |
| 3231 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3232 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3233 | cur = wp->w_match_head; |
| 3234 | shl_flag = FALSE; |
| 3235 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3236 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3237 | if (shl_flag == FALSE) |
| 3238 | { |
| 3239 | shl = &search_hl; |
| 3240 | shl_flag = TRUE; |
| 3241 | } |
| 3242 | else |
| 3243 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3244 | shl->startcol = MAXCOL; |
| 3245 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3246 | shl->attr_cur = 0; |
| 3247 | if (shl->rm.regprog != NULL) |
| 3248 | { |
| 3249 | v = (long)(ptr - line); |
| 3250 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3251 | |
| 3252 | /* Need to get the line again, a multi-line regexp may have made it |
| 3253 | * invalid. */ |
| 3254 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3255 | ptr = line + v; |
| 3256 | |
| 3257 | if (shl->lnum != 0 && shl->lnum <= lnum) |
| 3258 | { |
| 3259 | if (shl->lnum == lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3260 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3261 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3262 | shl->startcol = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3263 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3264 | - shl->rm.startpos[0].lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3265 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3266 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3267 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3268 | /* Highlight one character for an empty match. */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3269 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3270 | { |
| 3271 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3272 | if (has_mbyte && line[shl->endcol] != NUL) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3273 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3274 | else |
| 3275 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3276 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3277 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3278 | if ((long)shl->startcol < v) /* match at leftcol */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3279 | { |
| 3280 | shl->attr_cur = shl->attr; |
| 3281 | search_attr = shl->attr; |
| 3282 | } |
| 3283 | area_highlighting = TRUE; |
| 3284 | } |
| 3285 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3286 | if (shl != &search_hl && cur != NULL) |
| 3287 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3288 | } |
| 3289 | #endif |
| 3290 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3291 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 3292 | /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
| 3293 | * active, because it's not clear what is selected then. */ |
| 3294 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3295 | { |
| 3296 | line_attr = hl_attr(HLF_CUL); |
| 3297 | area_highlighting = TRUE; |
| 3298 | } |
| 3299 | #endif |
| 3300 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3301 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3302 | col = 0; |
| 3303 | #ifdef FEAT_RIGHTLEFT |
| 3304 | if (wp->w_p_rl) |
| 3305 | { |
| 3306 | /* Rightleft window: process the text in the normal direction, but put |
| 3307 | * it in current_ScreenLine[] from right to left. Start at the |
| 3308 | * rightmost column of the window. */ |
| 3309 | col = W_WIDTH(wp) - 1; |
| 3310 | off += col; |
| 3311 | } |
| 3312 | #endif |
| 3313 | |
| 3314 | /* |
| 3315 | * Repeat for the whole displayed line. |
| 3316 | */ |
| 3317 | for (;;) |
| 3318 | { |
| 3319 | /* Skip this quickly when working on the text. */ |
| 3320 | if (draw_state != WL_LINE) |
| 3321 | { |
| 3322 | #ifdef FEAT_CMDWIN |
| 3323 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3324 | { |
| 3325 | draw_state = WL_CMDLINE; |
| 3326 | if (cmdwin_type != 0 && wp == curwin) |
| 3327 | { |
| 3328 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3329 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3330 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3331 | char_attr = hl_attr(HLF_AT); |
| 3332 | } |
| 3333 | } |
| 3334 | #endif |
| 3335 | |
| 3336 | #ifdef FEAT_FOLDING |
| 3337 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3338 | { |
| 3339 | draw_state = WL_FOLD; |
| 3340 | if (wp->w_p_fdc > 0) |
| 3341 | { |
| 3342 | /* Draw the 'foldcolumn'. */ |
| 3343 | fill_foldcolumn(extra, wp, FALSE, lnum); |
| 3344 | n_extra = wp->w_p_fdc; |
| 3345 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3346 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3347 | c_extra = NUL; |
| 3348 | char_attr = hl_attr(HLF_FC); |
| 3349 | } |
| 3350 | } |
| 3351 | #endif |
| 3352 | |
| 3353 | #ifdef FEAT_SIGNS |
| 3354 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3355 | { |
| 3356 | draw_state = WL_SIGN; |
| 3357 | /* Show the sign column when there are any signs in this |
| 3358 | * buffer or when using Netbeans. */ |
| 3359 | if (draw_signcolumn(wp) |
| 3360 | # ifdef FEAT_DIFF |
| 3361 | && filler_todo <= 0 |
| 3362 | # endif |
| 3363 | ) |
| 3364 | { |
| 3365 | int_u text_sign; |
| 3366 | # ifdef FEAT_SIGN_ICONS |
| 3367 | int_u icon_sign; |
| 3368 | # endif |
| 3369 | |
| 3370 | /* Draw two cells with the sign value or blank. */ |
| 3371 | c_extra = ' '; |
| 3372 | char_attr = hl_attr(HLF_SC); |
| 3373 | n_extra = 2; |
| 3374 | |
| 3375 | if (row == startrow) |
| 3376 | { |
| 3377 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3378 | SIGN_TEXT); |
| 3379 | # ifdef FEAT_SIGN_ICONS |
| 3380 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3381 | SIGN_ICON); |
| 3382 | if (gui.in_use && icon_sign != 0) |
| 3383 | { |
| 3384 | /* Use the image in this position. */ |
| 3385 | c_extra = SIGN_BYTE; |
| 3386 | # ifdef FEAT_NETBEANS_INTG |
| 3387 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3388 | c_extra = MULTISIGN_BYTE; |
| 3389 | # endif |
| 3390 | char_attr = icon_sign; |
| 3391 | } |
| 3392 | else |
| 3393 | # endif |
| 3394 | if (text_sign != 0) |
| 3395 | { |
| 3396 | p_extra = sign_get_text(text_sign); |
| 3397 | if (p_extra != NULL) |
| 3398 | { |
| 3399 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3400 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3401 | } |
| 3402 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3403 | } |
| 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | #endif |
| 3408 | |
| 3409 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3410 | { |
| 3411 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3412 | /* Display the absolute or relative line number. After the |
| 3413 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3414 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3415 | && (row == startrow |
| 3416 | #ifdef FEAT_DIFF |
| 3417 | + filler_lines |
| 3418 | #endif |
| 3419 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3420 | { |
| 3421 | /* Draw the line number (empty space after wrapping). */ |
| 3422 | if (row == startrow |
| 3423 | #ifdef FEAT_DIFF |
| 3424 | + filler_lines |
| 3425 | #endif |
| 3426 | ) |
| 3427 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3428 | long num; |
| 3429 | |
| 3430 | if (wp->w_p_nu) |
| 3431 | /* 'number' */ |
| 3432 | num = (long)lnum; |
| 3433 | else |
| 3434 | /* 'relativenumber', don't use negative numbers */ |
| 3435 | num = (long)abs((int)get_cursor_rel_lnum(wp, |
| 3436 | lnum)); |
| 3437 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3438 | sprintf((char *)extra, "%*ld ", |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3439 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3440 | if (wp->w_skipcol > 0) |
| 3441 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3442 | *p_extra = '-'; |
| 3443 | #ifdef FEAT_RIGHTLEFT |
| 3444 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3445 | rl_mirror(extra); |
| 3446 | #endif |
| 3447 | p_extra = extra; |
| 3448 | c_extra = NUL; |
| 3449 | } |
| 3450 | else |
| 3451 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3452 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3453 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3454 | #ifdef FEAT_SYN_HL |
| 3455 | /* When 'cursorline' is set highlight the line number of |
| 3456 | * the current line differently. */ |
| 3457 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3458 | char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); |
| 3459 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3464 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3465 | { |
| 3466 | draw_state = WL_SBR; |
| 3467 | # ifdef FEAT_DIFF |
| 3468 | if (filler_todo > 0) |
| 3469 | { |
| 3470 | /* Draw "deleted" diff line(s). */ |
| 3471 | if (char2cells(fill_diff) > 1) |
| 3472 | c_extra = '-'; |
| 3473 | else |
| 3474 | c_extra = fill_diff; |
| 3475 | # ifdef FEAT_RIGHTLEFT |
| 3476 | if (wp->w_p_rl) |
| 3477 | n_extra = col + 1; |
| 3478 | else |
| 3479 | # endif |
| 3480 | n_extra = W_WIDTH(wp) - col; |
| 3481 | char_attr = hl_attr(HLF_DED); |
| 3482 | } |
| 3483 | # endif |
| 3484 | # ifdef FEAT_LINEBREAK |
| 3485 | if (*p_sbr != NUL && need_showbreak) |
| 3486 | { |
| 3487 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3488 | p_extra = p_sbr; |
| 3489 | c_extra = NUL; |
| 3490 | n_extra = (int)STRLEN(p_sbr); |
| 3491 | char_attr = hl_attr(HLF_AT); |
| 3492 | need_showbreak = FALSE; |
| 3493 | /* Correct end of highlighted area for 'showbreak', |
| 3494 | * required when 'linebreak' is also set. */ |
| 3495 | if (tocol == vcol) |
| 3496 | tocol += n_extra; |
| 3497 | } |
| 3498 | # endif |
| 3499 | } |
| 3500 | #endif |
| 3501 | |
| 3502 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3503 | { |
| 3504 | draw_state = WL_LINE; |
| 3505 | if (saved_n_extra) |
| 3506 | { |
| 3507 | /* Continue item from end of wrapped line. */ |
| 3508 | n_extra = saved_n_extra; |
| 3509 | c_extra = saved_c_extra; |
| 3510 | p_extra = saved_p_extra; |
| 3511 | char_attr = saved_char_attr; |
| 3512 | } |
| 3513 | else |
| 3514 | char_attr = 0; |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3519 | if (dollar_vcol != 0 && wp == curwin |
| 3520 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3521 | #ifdef FEAT_DIFF |
| 3522 | && filler_todo <= 0 |
| 3523 | #endif |
| 3524 | ) |
| 3525 | { |
| 3526 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3527 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3528 | /* Pretend we have finished updating the window. Except when |
| 3529 | * 'cursorcolumn' is set. */ |
| 3530 | #ifdef FEAT_SYN_HL |
| 3531 | if (wp->w_p_cuc) |
| 3532 | row = wp->w_cline_row + wp->w_cline_height; |
| 3533 | else |
| 3534 | #endif |
| 3535 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3536 | break; |
| 3537 | } |
| 3538 | |
| 3539 | if (draw_state == WL_LINE && area_highlighting) |
| 3540 | { |
| 3541 | /* handle Visual or match highlighting in this line */ |
| 3542 | if (vcol == fromcol |
| 3543 | #ifdef FEAT_MBYTE |
| 3544 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3545 | && (*mb_ptr2cells)(ptr) > 1) |
| 3546 | #endif |
| 3547 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3548 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3549 | && vcol < tocol)) |
| 3550 | area_attr = attr; /* start highlighting */ |
| 3551 | else if (area_attr != 0 |
| 3552 | && (vcol == tocol |
| 3553 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3554 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3555 | |
| 3556 | #ifdef FEAT_SEARCH_EXTRA |
| 3557 | if (!n_extra) |
| 3558 | { |
| 3559 | /* |
| 3560 | * Check for start/end of search pattern match. |
| 3561 | * After end, check for start/end of next match. |
| 3562 | * When another match, have to check for start again. |
| 3563 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3564 | * Do this for 'search_hl' and the match list (ordered by |
| 3565 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3566 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3567 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3568 | cur = wp->w_match_head; |
| 3569 | shl_flag = FALSE; |
| 3570 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3571 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3572 | if (shl_flag == FALSE |
| 3573 | && ((cur != NULL |
| 3574 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3575 | || cur == NULL)) |
| 3576 | { |
| 3577 | shl = &search_hl; |
| 3578 | shl_flag = TRUE; |
| 3579 | } |
| 3580 | else |
| 3581 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3582 | while (shl->rm.regprog != NULL) |
| 3583 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3584 | if (shl->startcol != MAXCOL |
| 3585 | && v >= (long)shl->startcol |
| 3586 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3587 | { |
| 3588 | shl->attr_cur = shl->attr; |
| 3589 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3590 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3591 | { |
| 3592 | shl->attr_cur = 0; |
| 3593 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3594 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3595 | |
| 3596 | /* Need to get the line again, a multi-line regexp |
| 3597 | * may have made it invalid. */ |
| 3598 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3599 | ptr = line + v; |
| 3600 | |
| 3601 | if (shl->lnum == lnum) |
| 3602 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3603 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3604 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3605 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3606 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3607 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3608 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3609 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3610 | { |
| 3611 | /* highlight empty match, try again after |
| 3612 | * it */ |
| 3613 | #ifdef FEAT_MBYTE |
| 3614 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3615 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3616 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3617 | else |
| 3618 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3619 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | /* Loop to check if the match starts at the |
| 3623 | * current position */ |
| 3624 | continue; |
| 3625 | } |
| 3626 | } |
| 3627 | break; |
| 3628 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3629 | if (shl != &search_hl && cur != NULL) |
| 3630 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3631 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3632 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3633 | /* Use attributes from match with highest priority among |
| 3634 | * 'search_hl' and the match list. */ |
| 3635 | search_attr = search_hl.attr_cur; |
| 3636 | cur = wp->w_match_head; |
| 3637 | shl_flag = FALSE; |
| 3638 | while (cur != NULL || shl_flag == FALSE) |
| 3639 | { |
| 3640 | if (shl_flag == FALSE |
| 3641 | && ((cur != NULL |
| 3642 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3643 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3644 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3645 | shl = &search_hl; |
| 3646 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3647 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3648 | else |
| 3649 | shl = &cur->hl; |
| 3650 | if (shl->attr_cur != 0) |
| 3651 | search_attr = shl->attr_cur; |
| 3652 | if (shl != &search_hl && cur != NULL) |
| 3653 | cur = cur->next; |
| 3654 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3655 | } |
| 3656 | #endif |
| 3657 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3658 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3659 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3660 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3661 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 3662 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3663 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3664 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 3665 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3666 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3667 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3668 | } |
| 3669 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3670 | |
| 3671 | /* Decide which of the highlight attributes to use. */ |
| 3672 | attr_pri = TRUE; |
| 3673 | if (area_attr != 0) |
| 3674 | char_attr = area_attr; |
| 3675 | else if (search_attr != 0) |
| 3676 | char_attr = search_attr; |
| 3677 | #ifdef LINE_ATTR |
| 3678 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 3679 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 3680 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 3681 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 3682 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3683 | char_attr = line_attr; |
| 3684 | #endif |
| 3685 | else |
| 3686 | { |
| 3687 | attr_pri = FALSE; |
| 3688 | #ifdef FEAT_SYN_HL |
| 3689 | if (has_syntax) |
| 3690 | char_attr = syntax_attr; |
| 3691 | else |
| 3692 | #endif |
| 3693 | char_attr = 0; |
| 3694 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | /* |
| 3698 | * Get the next character to put on the screen. |
| 3699 | */ |
| 3700 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3701 | * The "p_extra" points to the extra stuff that is inserted to |
| 3702 | * represent special characters (non-printable stuff) and other |
| 3703 | * things. When all characters are the same, c_extra is used. |
| 3704 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 3705 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3706 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 3707 | */ |
| 3708 | if (n_extra > 0) |
| 3709 | { |
| 3710 | if (c_extra != NUL) |
| 3711 | { |
| 3712 | c = c_extra; |
| 3713 | #ifdef FEAT_MBYTE |
| 3714 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 3715 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3716 | { |
| 3717 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3718 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3719 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3720 | } |
| 3721 | else |
| 3722 | mb_utf8 = FALSE; |
| 3723 | #endif |
| 3724 | } |
| 3725 | else |
| 3726 | { |
| 3727 | c = *p_extra; |
| 3728 | #ifdef FEAT_MBYTE |
| 3729 | if (has_mbyte) |
| 3730 | { |
| 3731 | mb_c = c; |
| 3732 | if (enc_utf8) |
| 3733 | { |
| 3734 | /* If the UTF-8 character is more than one byte: |
| 3735 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3736 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3737 | mb_utf8 = FALSE; |
| 3738 | if (mb_l > n_extra) |
| 3739 | mb_l = 1; |
| 3740 | else if (mb_l > 1) |
| 3741 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3742 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3743 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3744 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3745 | } |
| 3746 | } |
| 3747 | else |
| 3748 | { |
| 3749 | /* if this is a DBCS character, put it in "mb_c" */ |
| 3750 | mb_l = MB_BYTE2LEN(c); |
| 3751 | if (mb_l >= n_extra) |
| 3752 | mb_l = 1; |
| 3753 | else if (mb_l > 1) |
| 3754 | mb_c = (c << 8) + p_extra[1]; |
| 3755 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3756 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3757 | mb_l = 1; |
| 3758 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3759 | /* If a double-width char doesn't fit display a '>' in the |
| 3760 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3761 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3762 | # ifdef FEAT_RIGHTLEFT |
| 3763 | wp->w_p_rl ? (col <= 0) : |
| 3764 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3765 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3766 | && (*mb_char2cells)(mb_c) == 2) |
| 3767 | { |
| 3768 | c = '>'; |
| 3769 | mb_c = c; |
| 3770 | mb_l = 1; |
| 3771 | mb_utf8 = FALSE; |
| 3772 | multi_attr = hl_attr(HLF_AT); |
| 3773 | /* put the pointer back to output the double-width |
| 3774 | * character at the start of the next line. */ |
| 3775 | ++n_extra; |
| 3776 | --p_extra; |
| 3777 | } |
| 3778 | else |
| 3779 | { |
| 3780 | n_extra -= mb_l - 1; |
| 3781 | p_extra += mb_l - 1; |
| 3782 | } |
| 3783 | } |
| 3784 | #endif |
| 3785 | ++p_extra; |
| 3786 | } |
| 3787 | --n_extra; |
| 3788 | } |
| 3789 | else |
| 3790 | { |
| 3791 | /* |
| 3792 | * Get a character from the line itself. |
| 3793 | */ |
| 3794 | c = *ptr; |
| 3795 | #ifdef FEAT_MBYTE |
| 3796 | if (has_mbyte) |
| 3797 | { |
| 3798 | mb_c = c; |
| 3799 | if (enc_utf8) |
| 3800 | { |
| 3801 | /* If the UTF-8 character is more than one byte: Decode it |
| 3802 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3803 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3804 | mb_utf8 = FALSE; |
| 3805 | if (mb_l > 1) |
| 3806 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3807 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3808 | /* Overlong encoded ASCII or ASCII with composing char |
| 3809 | * is displayed normally, except a NUL. */ |
| 3810 | if (mb_c < 0x80) |
| 3811 | c = mb_c; |
| 3812 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3813 | |
| 3814 | /* At start of the line we can have a composing char. |
| 3815 | * Draw it as a space with a composing char. */ |
| 3816 | if (utf_iscomposing(mb_c)) |
| 3817 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3818 | int i; |
| 3819 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3820 | for (i = Screen_mco - 1; i > 0; --i) |
| 3821 | u8cc[i] = u8cc[i - 1]; |
| 3822 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3823 | mb_c = ' '; |
| 3824 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | if ((mb_l == 1 && c >= 0x80) |
| 3828 | || (mb_l >= 1 && mb_c == 0) |
| 3829 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3830 | # ifdef UNICODE16 |
| 3831 | || mb_c >= 0x10000 |
| 3832 | # endif |
| 3833 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3834 | { |
| 3835 | /* |
| 3836 | * Illegal UTF-8 byte: display as <xx>. |
| 3837 | * Non-BMP character : display as ? or fullwidth ?. |
| 3838 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3839 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3840 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3841 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3842 | { |
| 3843 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3844 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3845 | if (wp->w_p_rl) /* reverse */ |
| 3846 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3847 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3848 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3849 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3850 | else if (utf_char2cells(mb_c) != 2) |
| 3851 | STRCPY(extra, "?"); |
| 3852 | else |
| 3853 | /* 0xff1f in UTF-8: full-width '?' */ |
| 3854 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3855 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3856 | |
| 3857 | p_extra = extra; |
| 3858 | c = *p_extra; |
| 3859 | mb_c = mb_ptr2char_adv(&p_extra); |
| 3860 | mb_utf8 = (c >= 0x80); |
| 3861 | n_extra = (int)STRLEN(p_extra); |
| 3862 | c_extra = NUL; |
| 3863 | if (area_attr == 0 && search_attr == 0) |
| 3864 | { |
| 3865 | n_attr = n_extra + 1; |
| 3866 | extra_attr = hl_attr(HLF_8); |
| 3867 | saved_attr2 = char_attr; /* save current attr */ |
| 3868 | } |
| 3869 | } |
| 3870 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3871 | mb_l = 1; |
| 3872 | #ifdef FEAT_ARABIC |
| 3873 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 3874 | { |
| 3875 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3876 | int pc, pc1, nc; |
| 3877 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3878 | |
| 3879 | /* The idea of what is the previous and next |
| 3880 | * character depends on 'rightleft'. */ |
| 3881 | if (wp->w_p_rl) |
| 3882 | { |
| 3883 | pc = prev_c; |
| 3884 | pc1 = prev_c1; |
| 3885 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3886 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3887 | } |
| 3888 | else |
| 3889 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3890 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3891 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3892 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3893 | } |
| 3894 | prev_c = mb_c; |
| 3895 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3896 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3897 | } |
| 3898 | else |
| 3899 | prev_c = mb_c; |
| 3900 | #endif |
| 3901 | } |
| 3902 | else /* enc_dbcs */ |
| 3903 | { |
| 3904 | mb_l = MB_BYTE2LEN(c); |
| 3905 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3906 | mb_l = 1; |
| 3907 | else if (mb_l > 1) |
| 3908 | { |
| 3909 | /* We assume a second byte below 32 is illegal. |
| 3910 | * Hopefully this is OK for all double-byte encodings! |
| 3911 | */ |
| 3912 | if (ptr[1] >= 32) |
| 3913 | mb_c = (c << 8) + ptr[1]; |
| 3914 | else |
| 3915 | { |
| 3916 | if (ptr[1] == NUL) |
| 3917 | { |
| 3918 | /* head byte at end of line */ |
| 3919 | mb_l = 1; |
| 3920 | transchar_nonprint(extra, c); |
| 3921 | } |
| 3922 | else |
| 3923 | { |
| 3924 | /* illegal tail byte */ |
| 3925 | mb_l = 2; |
| 3926 | STRCPY(extra, "XX"); |
| 3927 | } |
| 3928 | p_extra = extra; |
| 3929 | n_extra = (int)STRLEN(extra) - 1; |
| 3930 | c_extra = NUL; |
| 3931 | c = *p_extra++; |
| 3932 | if (area_attr == 0 && search_attr == 0) |
| 3933 | { |
| 3934 | n_attr = n_extra + 1; |
| 3935 | extra_attr = hl_attr(HLF_8); |
| 3936 | saved_attr2 = char_attr; /* save current attr */ |
| 3937 | } |
| 3938 | mb_c = c; |
| 3939 | } |
| 3940 | } |
| 3941 | } |
| 3942 | /* If a double-width char doesn't fit display a '>' in the |
| 3943 | * last column; the character is displayed at the start of the |
| 3944 | * next line. */ |
| 3945 | if (( |
| 3946 | # ifdef FEAT_RIGHTLEFT |
| 3947 | wp->w_p_rl ? (col <= 0) : |
| 3948 | # endif |
| 3949 | (col >= W_WIDTH(wp) - 1)) |
| 3950 | && (*mb_char2cells)(mb_c) == 2) |
| 3951 | { |
| 3952 | c = '>'; |
| 3953 | mb_c = c; |
| 3954 | mb_utf8 = FALSE; |
| 3955 | mb_l = 1; |
| 3956 | multi_attr = hl_attr(HLF_AT); |
| 3957 | /* Put pointer back so that the character will be |
| 3958 | * displayed at the start of the next line. */ |
| 3959 | --ptr; |
| 3960 | } |
| 3961 | else if (*ptr != NUL) |
| 3962 | ptr += mb_l - 1; |
| 3963 | |
| 3964 | /* If a double-width char doesn't fit at the left side display |
| 3965 | * a '<' in the first column. */ |
| 3966 | if (n_skip > 0 && mb_l > 1) |
| 3967 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3968 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3969 | c_extra = '<'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3970 | c = ' '; |
| 3971 | if (area_attr == 0 && search_attr == 0) |
| 3972 | { |
| 3973 | n_attr = n_extra + 1; |
| 3974 | extra_attr = hl_attr(HLF_AT); |
| 3975 | saved_attr2 = char_attr; /* save current attr */ |
| 3976 | } |
| 3977 | mb_c = c; |
| 3978 | mb_utf8 = FALSE; |
| 3979 | mb_l = 1; |
| 3980 | } |
| 3981 | |
| 3982 | } |
| 3983 | #endif |
| 3984 | ++ptr; |
| 3985 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3986 | /* 'list' : change char 160 to lcs_nbsp. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3987 | if (wp->w_p_list && (c == 160 |
| 3988 | #ifdef FEAT_MBYTE |
| 3989 | || (mb_utf8 && mb_c == 160) |
| 3990 | #endif |
| 3991 | ) && lcs_nbsp) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 3992 | { |
| 3993 | c = lcs_nbsp; |
| 3994 | if (area_attr == 0 && search_attr == 0) |
| 3995 | { |
| 3996 | n_attr = 1; |
| 3997 | extra_attr = hl_attr(HLF_8); |
| 3998 | saved_attr2 = char_attr; /* save current attr */ |
| 3999 | } |
| 4000 | #ifdef FEAT_MBYTE |
| 4001 | mb_c = c; |
| 4002 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4003 | { |
| 4004 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4005 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4006 | c = 0xc0; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4007 | } |
| 4008 | else |
| 4009 | mb_utf8 = FALSE; |
| 4010 | #endif |
| 4011 | } |
| 4012 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4013 | if (extra_check) |
| 4014 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4015 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4016 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4017 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4018 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4019 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4020 | /* Get syntax attribute, unless still at the start of the line |
| 4021 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4022 | v = (long)(ptr - line); |
| 4023 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4024 | { |
| 4025 | /* Get the syntax attribute for the character. If there |
| 4026 | * is an error, disable syntax highlighting. */ |
| 4027 | save_did_emsg = did_emsg; |
| 4028 | did_emsg = FALSE; |
| 4029 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4030 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4031 | # ifdef FEAT_CONCEAL |
| 4032 | &syntax_flags, |
| 4033 | # else |
| 4034 | NULL, |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4035 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4036 | # ifdef FEAT_SPELL |
| 4037 | has_spell ? &can_spell : |
| 4038 | # endif |
| 4039 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4040 | |
| 4041 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4042 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4043 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4044 | has_syntax = FALSE; |
| 4045 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4046 | else |
| 4047 | did_emsg = save_did_emsg; |
| 4048 | |
| 4049 | /* Need to get the line again, a multi-line regexp may |
| 4050 | * have made it invalid. */ |
| 4051 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4052 | ptr = line + v; |
| 4053 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4054 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4055 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4056 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4057 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4058 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4059 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4060 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4061 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4062 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4063 | * Only do this when there is no syntax highlighting, the |
| 4064 | * @Spell cluster is not used or the current syntax item |
| 4065 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4066 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4067 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4068 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4069 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4070 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4071 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4072 | # endif |
| 4073 | if (c != 0 && ( |
| 4074 | # ifdef FEAT_SYN_HL |
| 4075 | !has_syntax || |
| 4076 | # endif |
| 4077 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4078 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4079 | char_u *prev_ptr, *p; |
| 4080 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4081 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4082 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4083 | if (has_mbyte) |
| 4084 | { |
| 4085 | prev_ptr = ptr - mb_l; |
| 4086 | v -= mb_l - 1; |
| 4087 | } |
| 4088 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4089 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4090 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4091 | |
| 4092 | /* Use nextline[] if possible, it has the start of the |
| 4093 | * next line concatenated. */ |
| 4094 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4095 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4096 | else |
| 4097 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4098 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4099 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4100 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4101 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4102 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4103 | /* In Insert mode only highlight a word that |
| 4104 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4105 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4106 | && (State & INSERT) != 0 |
| 4107 | && wp->w_cursor.lnum == lnum |
| 4108 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4109 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4110 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4111 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4112 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4113 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4114 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4115 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4116 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4117 | && (p - nextline) + len > nextline_idx) |
| 4118 | { |
| 4119 | /* Remember that the good word continues at the |
| 4120 | * start of the next line. */ |
| 4121 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4122 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4123 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4124 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4125 | /* Turn index into actual attributes. */ |
| 4126 | if (spell_hlf != HLF_COUNT) |
| 4127 | spell_attr = highlight_attr[spell_hlf]; |
| 4128 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4129 | if (cap_col > 0) |
| 4130 | { |
| 4131 | if (p != prev_ptr |
| 4132 | && (p - nextline) + cap_col >= nextline_idx) |
| 4133 | { |
| 4134 | /* Remember that the word in the next line |
| 4135 | * must start with a capital. */ |
| 4136 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4137 | cap_col = (int)((p - nextline) + cap_col |
| 4138 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4139 | } |
| 4140 | else |
| 4141 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4142 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4143 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4144 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4145 | } |
| 4146 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4147 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4148 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4149 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4150 | else |
| 4151 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4152 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4153 | #endif |
| 4154 | #ifdef FEAT_LINEBREAK |
| 4155 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4156 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4157 | */ |
| 4158 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4159 | && !wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4160 | { |
| 4161 | n_extra = win_lbr_chartabsize(wp, ptr - ( |
| 4162 | # ifdef FEAT_MBYTE |
| 4163 | has_mbyte ? mb_l : |
| 4164 | # endif |
| 4165 | 1), (colnr_T)vcol, NULL) - 1; |
| 4166 | c_extra = ' '; |
| 4167 | if (vim_iswhite(c)) |
| 4168 | c = ' '; |
| 4169 | } |
| 4170 | #endif |
| 4171 | |
| 4172 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4173 | { |
| 4174 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4175 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4176 | { |
| 4177 | n_attr = 1; |
| 4178 | extra_attr = hl_attr(HLF_8); |
| 4179 | saved_attr2 = char_attr; /* save current attr */ |
| 4180 | } |
| 4181 | #ifdef FEAT_MBYTE |
| 4182 | mb_c = c; |
| 4183 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4184 | { |
| 4185 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4186 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4187 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4188 | } |
| 4189 | else |
| 4190 | mb_utf8 = FALSE; |
| 4191 | #endif |
| 4192 | } |
| 4193 | } |
| 4194 | |
| 4195 | /* |
| 4196 | * Handling of non-printable characters. |
| 4197 | */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4198 | if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4199 | { |
| 4200 | /* |
| 4201 | * when getting a character from the file, we may have to |
| 4202 | * turn it into something else on the way to putting it |
| 4203 | * into "ScreenLines". |
| 4204 | */ |
| 4205 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4206 | { |
| 4207 | /* tab amount depends on current column */ |
| 4208 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4209 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4210 | #ifdef FEAT_MBYTE |
| 4211 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4212 | #endif |
| 4213 | if (wp->w_p_list) |
| 4214 | { |
| 4215 | c = lcs_tab1; |
| 4216 | c_extra = lcs_tab2; |
| 4217 | n_attr = n_extra + 1; |
| 4218 | extra_attr = hl_attr(HLF_8); |
| 4219 | saved_attr2 = char_attr; /* save current attr */ |
| 4220 | #ifdef FEAT_MBYTE |
| 4221 | mb_c = c; |
| 4222 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4223 | { |
| 4224 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4225 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4226 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4227 | } |
| 4228 | #endif |
| 4229 | } |
| 4230 | else |
| 4231 | { |
| 4232 | c_extra = ' '; |
| 4233 | c = ' '; |
| 4234 | } |
| 4235 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4236 | else if (c == NUL |
| 4237 | && ((wp->w_p_list && lcs_eol > 0) |
| 4238 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4239 | && tocol > vcol |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4240 | #ifdef FEAT_VISUAL |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4241 | && VIsual_mode != Ctrl_V |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4242 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4243 | && ( |
| 4244 | # ifdef FEAT_RIGHTLEFT |
| 4245 | wp->w_p_rl ? (col >= 0) : |
| 4246 | # endif |
| 4247 | (col < W_WIDTH(wp))) |
| 4248 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4249 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4250 | && (colnr_T)vcol == wp->w_virtcol))) |
| 4251 | && lcs_eol_one >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4252 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4253 | /* Display a '$' after the line or highlight an extra |
| 4254 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4255 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4256 | /* For a diff line the highlighting continues after the |
| 4257 | * "$". */ |
| 4258 | if ( |
| 4259 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4260 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4261 | # ifdef LINE_ATTR |
| 4262 | && |
| 4263 | # endif |
| 4264 | # endif |
| 4265 | # ifdef LINE_ATTR |
| 4266 | line_attr == 0 |
| 4267 | # endif |
| 4268 | ) |
| 4269 | #endif |
| 4270 | { |
| 4271 | #ifdef FEAT_VIRTUALEDIT |
| 4272 | /* In virtualedit, visual selections may extend |
| 4273 | * beyond end of line. */ |
| 4274 | if (area_highlighting && virtual_active() |
| 4275 | && tocol != MAXCOL && vcol < tocol) |
| 4276 | n_extra = 0; |
| 4277 | else |
| 4278 | #endif |
| 4279 | { |
| 4280 | p_extra = at_end_str; |
| 4281 | n_extra = 1; |
| 4282 | c_extra = NUL; |
| 4283 | } |
| 4284 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4285 | if (wp->w_p_list) |
| 4286 | c = lcs_eol; |
| 4287 | else |
| 4288 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4289 | lcs_eol_one = -1; |
| 4290 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4291 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4292 | { |
| 4293 | extra_attr = hl_attr(HLF_AT); |
| 4294 | n_attr = 1; |
| 4295 | } |
| 4296 | #ifdef FEAT_MBYTE |
| 4297 | mb_c = c; |
| 4298 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4299 | { |
| 4300 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4301 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4302 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4303 | } |
| 4304 | else |
| 4305 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4306 | #endif |
| 4307 | } |
| 4308 | else if (c != NUL) |
| 4309 | { |
| 4310 | p_extra = transchar(c); |
| 4311 | #ifdef FEAT_RIGHTLEFT |
| 4312 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4313 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4314 | #endif |
| 4315 | n_extra = byte2cells(c) - 1; |
| 4316 | c_extra = NUL; |
| 4317 | c = *p_extra++; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4318 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4319 | { |
| 4320 | n_attr = n_extra + 1; |
| 4321 | extra_attr = hl_attr(HLF_8); |
| 4322 | saved_attr2 = char_attr; /* save current attr */ |
| 4323 | } |
| 4324 | #ifdef FEAT_MBYTE |
| 4325 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4326 | #endif |
| 4327 | } |
| 4328 | #ifdef FEAT_VIRTUALEDIT |
| 4329 | else if (VIsual_active |
| 4330 | && (VIsual_mode == Ctrl_V |
| 4331 | || VIsual_mode == 'v') |
| 4332 | && virtual_active() |
| 4333 | && tocol != MAXCOL |
| 4334 | && vcol < tocol |
| 4335 | && ( |
| 4336 | # ifdef FEAT_RIGHTLEFT |
| 4337 | wp->w_p_rl ? (col >= 0) : |
| 4338 | # endif |
| 4339 | (col < W_WIDTH(wp)))) |
| 4340 | { |
| 4341 | c = ' '; |
| 4342 | --ptr; /* put it back at the NUL */ |
| 4343 | } |
| 4344 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4345 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4346 | else if (( |
| 4347 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4348 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4349 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4350 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4351 | ) && ( |
| 4352 | # ifdef FEAT_RIGHTLEFT |
| 4353 | wp->w_p_rl ? (col >= 0) : |
| 4354 | # endif |
| 4355 | (col < W_WIDTH(wp)))) |
| 4356 | { |
| 4357 | /* Highlight until the right side of the window */ |
| 4358 | c = ' '; |
| 4359 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4360 | |
| 4361 | /* Remember we do the char for line highlighting. */ |
| 4362 | ++did_line_attr; |
| 4363 | |
| 4364 | /* don't do search HL for the rest of the line */ |
| 4365 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4366 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4367 | # ifdef FEAT_DIFF |
| 4368 | if (diff_hlf == HLF_TXD) |
| 4369 | { |
| 4370 | diff_hlf = HLF_CHD; |
| 4371 | if (attr == 0 || char_attr != attr) |
| 4372 | char_attr = hl_attr(diff_hlf); |
| 4373 | } |
| 4374 | # endif |
| 4375 | } |
| 4376 | #endif |
| 4377 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4378 | |
| 4379 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | a7781e0 | 2010-07-19 20:13:22 +0200 | [diff] [blame] | 4380 | if ( wp->w_p_conc > 0 |
| 4381 | && (lnum != wp->w_cursor.lnum || curwin != wp) |
| 4382 | && (syntax_flags & HL_CONCEAL) != 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4383 | { |
| 4384 | char_attr = conceal_attr; |
| 4385 | if (first_conceal |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4386 | && (syn_get_sub_char() != NUL || wp->w_p_conc == 1)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4387 | { |
| 4388 | if (syn_get_sub_char() != NUL) |
| 4389 | c = syn_get_sub_char(); |
| 4390 | else if (lcs_conceal != NUL) |
| 4391 | c = lcs_conceal; |
| 4392 | else |
| 4393 | c = ' '; |
| 4394 | |
| 4395 | first_conceal = FALSE; |
| 4396 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4397 | if (n_extra > 0) |
| 4398 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4399 | vcol += n_extra; |
| 4400 | if (wp->w_p_wrap && n_extra > 0) |
| 4401 | { |
| 4402 | # ifdef FEAT_RIGHTLEFT |
| 4403 | if (wp->w_p_rl) |
| 4404 | { |
| 4405 | col -= n_extra; |
| 4406 | boguscols -= n_extra; |
| 4407 | } |
| 4408 | else |
| 4409 | # endif |
| 4410 | { |
| 4411 | boguscols += n_extra; |
| 4412 | col += n_extra; |
| 4413 | } |
| 4414 | } |
| 4415 | n_extra = 0; |
| 4416 | n_attr = 0; |
| 4417 | } |
| 4418 | else if (n_skip == 0) |
| 4419 | { |
| 4420 | is_concealing = TRUE; |
| 4421 | n_skip = 1; |
| 4422 | } |
| 4423 | # ifdef FEAT_MBYTE |
| 4424 | mb_c = c; |
| 4425 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4426 | { |
| 4427 | mb_utf8 = TRUE; |
| 4428 | u8cc[0] = 0; |
| 4429 | c = 0xc0; |
| 4430 | } |
| 4431 | else |
| 4432 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4433 | # endif |
| 4434 | } |
| 4435 | else |
| 4436 | { |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4437 | first_conceal = (wp->w_p_conc != 3); |
| 4438 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4439 | } |
| 4440 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | /* Don't override visual selection highlighting. */ |
| 4444 | if (n_attr > 0 |
| 4445 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4446 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4447 | char_attr = extra_attr; |
| 4448 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4449 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4450 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4451 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4452 | * im_is_preediting() here. */ |
| 4453 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4454 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4455 | && (State & INSERT) |
| 4456 | && !p_imdisable |
| 4457 | && im_is_preediting() |
| 4458 | && draw_state == WL_LINE) |
| 4459 | { |
| 4460 | colnr_T tcol; |
| 4461 | |
| 4462 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4463 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4464 | else |
| 4465 | tcol = preedit_end_col; |
| 4466 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 4467 | { |
| 4468 | if (feedback_old_attr < 0) |
| 4469 | { |
| 4470 | feedback_col = 0; |
| 4471 | feedback_old_attr = char_attr; |
| 4472 | } |
| 4473 | char_attr = im_get_feedback_attr(feedback_col); |
| 4474 | if (char_attr < 0) |
| 4475 | char_attr = feedback_old_attr; |
| 4476 | feedback_col++; |
| 4477 | } |
| 4478 | else if (feedback_old_attr >= 0) |
| 4479 | { |
| 4480 | char_attr = feedback_old_attr; |
| 4481 | feedback_old_attr = -1; |
| 4482 | feedback_col = 0; |
| 4483 | } |
| 4484 | } |
| 4485 | #endif |
| 4486 | /* |
| 4487 | * Handle the case where we are in column 0 but not on the first |
| 4488 | * character of the line and the user wants us to show us a |
| 4489 | * special character (via 'listchars' option "precedes:<char>". |
| 4490 | */ |
| 4491 | if (lcs_prec_todo != NUL |
| 4492 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 4493 | #ifdef FEAT_DIFF |
| 4494 | && filler_todo <= 0 |
| 4495 | #endif |
| 4496 | && draw_state > WL_NR |
| 4497 | && c != NUL) |
| 4498 | { |
| 4499 | c = lcs_prec; |
| 4500 | lcs_prec_todo = NUL; |
| 4501 | #ifdef FEAT_MBYTE |
| 4502 | mb_c = c; |
| 4503 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4504 | { |
| 4505 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4506 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4507 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4508 | } |
| 4509 | else |
| 4510 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4511 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4512 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4513 | { |
| 4514 | saved_attr3 = char_attr; /* save current attr */ |
| 4515 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 4516 | n_attr3 = 1; |
| 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4521 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4522 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4523 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4524 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4525 | || did_line_attr == 1 |
| 4526 | #endif |
| 4527 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4528 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4529 | #ifdef FEAT_SEARCH_EXTRA |
| 4530 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4531 | |
| 4532 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 4533 | if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4534 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4535 | #endif |
| 4536 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4537 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4538 | * highlight match at end of line. If it's beyond the last |
| 4539 | * char on the screen, just overwrite that one (tricky!) Not |
| 4540 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4541 | #ifdef FEAT_SEARCH_EXTRA |
| 4542 | prevcol_hl_flag = FALSE; |
| 4543 | if (prevcol == (long)search_hl.startcol) |
| 4544 | prevcol_hl_flag = TRUE; |
| 4545 | else |
| 4546 | { |
| 4547 | cur = wp->w_match_head; |
| 4548 | while (cur != NULL) |
| 4549 | { |
| 4550 | if (prevcol == (long)cur->hl.startcol) |
| 4551 | { |
| 4552 | prevcol_hl_flag = TRUE; |
| 4553 | break; |
| 4554 | } |
| 4555 | cur = cur->next; |
| 4556 | } |
| 4557 | } |
| 4558 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4559 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4560 | && ((area_attr != 0 && vcol == fromcol |
| 4561 | #ifdef FEAT_VISUAL |
| 4562 | && (VIsual_mode != Ctrl_V |
| 4563 | || lnum == VIsual.lnum |
| 4564 | || lnum == curwin->w_cursor.lnum) |
| 4565 | #endif |
| 4566 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4567 | #ifdef FEAT_SEARCH_EXTRA |
| 4568 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4569 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4570 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4571 | && did_line_attr <= 1 |
| 4572 | # endif |
| 4573 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4574 | #endif |
| 4575 | )) |
| 4576 | { |
| 4577 | int n = 0; |
| 4578 | |
| 4579 | #ifdef FEAT_RIGHTLEFT |
| 4580 | if (wp->w_p_rl) |
| 4581 | { |
| 4582 | if (col < 0) |
| 4583 | n = 1; |
| 4584 | } |
| 4585 | else |
| 4586 | #endif |
| 4587 | { |
| 4588 | if (col >= W_WIDTH(wp)) |
| 4589 | n = -1; |
| 4590 | } |
| 4591 | if (n != 0) |
| 4592 | { |
| 4593 | /* At the window boundary, highlight the last character |
| 4594 | * instead (better than nothing). */ |
| 4595 | off += n; |
| 4596 | col += n; |
| 4597 | } |
| 4598 | else |
| 4599 | { |
| 4600 | /* Add a blank character to highlight. */ |
| 4601 | ScreenLines[off] = ' '; |
| 4602 | #ifdef FEAT_MBYTE |
| 4603 | if (enc_utf8) |
| 4604 | ScreenLinesUC[off] = 0; |
| 4605 | #endif |
| 4606 | } |
| 4607 | #ifdef FEAT_SEARCH_EXTRA |
| 4608 | if (area_attr == 0) |
| 4609 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4610 | /* Use attributes from match with highest priority among |
| 4611 | * 'search_hl' and the match list. */ |
| 4612 | char_attr = search_hl.attr; |
| 4613 | cur = wp->w_match_head; |
| 4614 | shl_flag = FALSE; |
| 4615 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4616 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4617 | if (shl_flag == FALSE |
| 4618 | && ((cur != NULL |
| 4619 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4620 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4621 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4622 | shl = &search_hl; |
| 4623 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4624 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4625 | else |
| 4626 | shl = &cur->hl; |
| 4627 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 4628 | char_attr = shl->attr; |
| 4629 | if (shl != &search_hl && cur != NULL) |
| 4630 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4631 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4632 | } |
| 4633 | #endif |
| 4634 | ScreenAttrs[off] = char_attr; |
| 4635 | #ifdef FEAT_RIGHTLEFT |
| 4636 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4637 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4638 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4639 | --off; |
| 4640 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4641 | else |
| 4642 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4643 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4644 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4645 | ++off; |
| 4646 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4647 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4648 | #ifdef FEAT_SYN_HL |
| 4649 | eol_hl_off = 1; |
| 4650 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4651 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4652 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4653 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4654 | /* |
| 4655 | * At end of the text line. |
| 4656 | */ |
| 4657 | if (c == NUL) |
| 4658 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4659 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4660 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 4661 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4662 | { |
| 4663 | /* highlight last char after line */ |
| 4664 | --col; |
| 4665 | --off; |
| 4666 | --vcol; |
| 4667 | } |
| 4668 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4669 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 4670 | if (wp->w_p_wrap) |
| 4671 | v = wp->w_skipcol; |
| 4672 | else |
| 4673 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4674 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4675 | /* check if line ends before left margin */ |
| 4676 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4677 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4678 | #ifdef FEAT_CONCEAL |
| 4679 | /* Get rid of the boguscols now, we want to draw until the right |
| 4680 | * edge for 'cursorcolumn'. */ |
| 4681 | col -= boguscols; |
| 4682 | boguscols = 0; |
| 4683 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4684 | |
| 4685 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4686 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4687 | |
| 4688 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4689 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 4690 | && (int)wp->w_virtcol < |
| 4691 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4692 | && lnum != wp->w_cursor.lnum) |
| 4693 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4694 | # ifdef FEAT_RIGHTLEFT |
| 4695 | && !wp->w_p_rl |
| 4696 | # endif |
| 4697 | ) |
| 4698 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4699 | int rightmost_vcol = 0; |
| 4700 | int i; |
| 4701 | |
| 4702 | if (wp->w_p_cuc) |
| 4703 | rightmost_vcol = wp->w_virtcol; |
| 4704 | if (draw_color_col) |
| 4705 | /* determine rightmost colorcolumn to possibly draw */ |
| 4706 | for (i = 0; color_cols[i] >= 0; ++i) |
| 4707 | if (rightmost_vcol < color_cols[i]) |
| 4708 | rightmost_vcol = color_cols[i]; |
| 4709 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4710 | while (col < W_WIDTH(wp)) |
| 4711 | { |
| 4712 | ScreenLines[off] = ' '; |
| 4713 | #ifdef FEAT_MBYTE |
| 4714 | if (enc_utf8) |
| 4715 | ScreenLinesUC[off] = 0; |
| 4716 | #endif |
| 4717 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 4718 | if (draw_color_col) |
| 4719 | draw_color_col = advance_color_col(VCOL_HLC, |
| 4720 | &color_cols); |
| 4721 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4722 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4723 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4724 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4725 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 4726 | else |
| 4727 | ScreenAttrs[off++] = 0; |
| 4728 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4729 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4730 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4731 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4732 | ++vcol; |
| 4733 | } |
| 4734 | } |
| 4735 | #endif |
| 4736 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4737 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 4738 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4739 | row++; |
| 4740 | |
| 4741 | /* |
| 4742 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 4743 | * updated (saves a call to plines() later). |
| 4744 | */ |
| 4745 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 4746 | { |
| 4747 | curwin->w_cline_row = startrow; |
| 4748 | curwin->w_cline_height = row - startrow; |
| 4749 | #ifdef FEAT_FOLDING |
| 4750 | curwin->w_cline_folded = FALSE; |
| 4751 | #endif |
| 4752 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 4753 | } |
| 4754 | |
| 4755 | break; |
| 4756 | } |
| 4757 | |
| 4758 | /* line continues beyond line end */ |
| 4759 | if (lcs_ext |
| 4760 | && !wp->w_p_wrap |
| 4761 | #ifdef FEAT_DIFF |
| 4762 | && filler_todo <= 0 |
| 4763 | #endif |
| 4764 | && ( |
| 4765 | #ifdef FEAT_RIGHTLEFT |
| 4766 | wp->w_p_rl ? col == 0 : |
| 4767 | #endif |
| 4768 | col == W_WIDTH(wp) - 1) |
| 4769 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 4770 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4771 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 4772 | { |
| 4773 | c = lcs_ext; |
| 4774 | char_attr = hl_attr(HLF_AT); |
| 4775 | #ifdef FEAT_MBYTE |
| 4776 | mb_c = c; |
| 4777 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4778 | { |
| 4779 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4780 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4781 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4782 | } |
| 4783 | else |
| 4784 | mb_utf8 = FALSE; |
| 4785 | #endif |
| 4786 | } |
| 4787 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4788 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4789 | /* advance to the next 'colorcolumn' */ |
| 4790 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4791 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4792 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4793 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4794 | * highlight the cursor position itself. |
| 4795 | * Also highlight the 'colorcolumn' if it is different than |
| 4796 | * 'cursorcolumn' */ |
| 4797 | vcol_save_attr = -1; |
| 4798 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4799 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4800 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4801 | && lnum != wp->w_cursor.lnum) |
| 4802 | { |
| 4803 | vcol_save_attr = char_attr; |
| 4804 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 4805 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 4806 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4807 | { |
| 4808 | vcol_save_attr = char_attr; |
| 4809 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 4810 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4811 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4812 | #endif |
| 4813 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4814 | /* |
| 4815 | * Store character to be displayed. |
| 4816 | * Skip characters that are left of the screen for 'nowrap'. |
| 4817 | */ |
| 4818 | vcol_prev = vcol; |
| 4819 | if (draw_state < WL_LINE || n_skip <= 0) |
| 4820 | { |
| 4821 | /* |
| 4822 | * Store the character. |
| 4823 | */ |
| 4824 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 4825 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 4826 | { |
| 4827 | /* A double-wide character is: put first halve in left cell. */ |
| 4828 | --off; |
| 4829 | --col; |
| 4830 | } |
| 4831 | #endif |
| 4832 | ScreenLines[off] = c; |
| 4833 | #ifdef FEAT_MBYTE |
| 4834 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 4835 | { |
| 4836 | if ((mb_c & 0xff00) == 0x8e00) |
| 4837 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4838 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 4839 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4840 | else if (enc_utf8) |
| 4841 | { |
| 4842 | if (mb_utf8) |
| 4843 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4844 | int i; |
| 4845 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4846 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4847 | if ((c & 0xff) == 0) |
| 4848 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4849 | for (i = 0; i < Screen_mco; ++i) |
| 4850 | { |
| 4851 | ScreenLinesC[i][off] = u8cc[i]; |
| 4852 | if (u8cc[i] == 0) |
| 4853 | break; |
| 4854 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4855 | } |
| 4856 | else |
| 4857 | ScreenLinesUC[off] = 0; |
| 4858 | } |
| 4859 | if (multi_attr) |
| 4860 | { |
| 4861 | ScreenAttrs[off] = multi_attr; |
| 4862 | multi_attr = 0; |
| 4863 | } |
| 4864 | else |
| 4865 | #endif |
| 4866 | ScreenAttrs[off] = char_attr; |
| 4867 | |
| 4868 | #ifdef FEAT_MBYTE |
| 4869 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4870 | { |
| 4871 | /* Need to fill two screen columns. */ |
| 4872 | ++off; |
| 4873 | ++col; |
| 4874 | if (enc_utf8) |
| 4875 | /* UTF-8: Put a 0 in the second screen char. */ |
| 4876 | ScreenLines[off] = 0; |
| 4877 | else |
| 4878 | /* DBCS: Put second byte in the second screen char. */ |
| 4879 | ScreenLines[off] = mb_c & 0xff; |
| 4880 | ++vcol; |
| 4881 | /* When "tocol" is halfway a character, set it to the end of |
| 4882 | * the character, otherwise highlighting won't stop. */ |
| 4883 | if (tocol == vcol) |
| 4884 | ++tocol; |
| 4885 | #ifdef FEAT_RIGHTLEFT |
| 4886 | if (wp->w_p_rl) |
| 4887 | { |
| 4888 | /* now it's time to backup one cell */ |
| 4889 | --off; |
| 4890 | --col; |
| 4891 | } |
| 4892 | #endif |
| 4893 | } |
| 4894 | #endif |
| 4895 | #ifdef FEAT_RIGHTLEFT |
| 4896 | if (wp->w_p_rl) |
| 4897 | { |
| 4898 | --off; |
| 4899 | --col; |
| 4900 | } |
| 4901 | else |
| 4902 | #endif |
| 4903 | { |
| 4904 | ++off; |
| 4905 | ++col; |
| 4906 | } |
| 4907 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4908 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4909 | else if (wp->w_p_conc > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4910 | { |
| 4911 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4912 | ++vcol_off; |
| 4913 | if (n_extra > 0) |
| 4914 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4915 | if (wp->w_p_wrap) |
| 4916 | { |
| 4917 | /* |
| 4918 | * Special voodoo required if 'wrap' is on. |
| 4919 | * |
| 4920 | * Advance the column indicator to force the line |
| 4921 | * drawing to wrap early. This will make the line |
| 4922 | * take up the same screen space when parts are concealed, |
| 4923 | * so that cursor line computations aren't messed up. |
| 4924 | * |
| 4925 | * To avoid the fictitious advance of 'col' causing |
| 4926 | * trailing junk to be written out of the screen line |
| 4927 | * we are building, 'boguscols' keeps track of the number |
| 4928 | * of bad columns we have advanced. |
| 4929 | */ |
| 4930 | if (n_extra > 0) |
| 4931 | { |
| 4932 | vcol += n_extra; |
| 4933 | # ifdef FEAT_RIGHTLEFT |
| 4934 | if (wp->w_p_rl) |
| 4935 | { |
| 4936 | col -= n_extra; |
| 4937 | boguscols -= n_extra; |
| 4938 | } |
| 4939 | else |
| 4940 | # endif |
| 4941 | { |
| 4942 | col += n_extra; |
| 4943 | boguscols += n_extra; |
| 4944 | } |
| 4945 | n_extra = 0; |
| 4946 | n_attr = 0; |
| 4947 | } |
| 4948 | |
| 4949 | |
| 4950 | # ifdef FEAT_MBYTE |
| 4951 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4952 | { |
| 4953 | /* Need to fill two screen columns. */ |
| 4954 | # ifdef FEAT_RIGHTLEFT |
| 4955 | if (wp->w_p_rl) |
| 4956 | { |
| 4957 | --boguscols; |
| 4958 | --col; |
| 4959 | } |
| 4960 | else |
| 4961 | # endif |
| 4962 | { |
| 4963 | ++boguscols; |
| 4964 | ++col; |
| 4965 | } |
| 4966 | } |
| 4967 | # endif |
| 4968 | |
| 4969 | # ifdef FEAT_RIGHTLEFT |
| 4970 | if (wp->w_p_rl) |
| 4971 | { |
| 4972 | --boguscols; |
| 4973 | --col; |
| 4974 | } |
| 4975 | else |
| 4976 | # endif |
| 4977 | { |
| 4978 | ++boguscols; |
| 4979 | ++col; |
| 4980 | } |
| 4981 | } |
| 4982 | else |
| 4983 | { |
| 4984 | if (n_extra > 0) |
| 4985 | { |
| 4986 | vcol += n_extra; |
| 4987 | n_extra = 0; |
| 4988 | n_attr = 0; |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | } |
| 4993 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4994 | else |
| 4995 | --n_skip; |
| 4996 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 4997 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 4998 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 4999 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5000 | #ifdef FEAT_DIFF |
| 5001 | && filler_todo <= 0 |
| 5002 | #endif |
| 5003 | ) |
| 5004 | ++vcol; |
| 5005 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5006 | #ifdef FEAT_SYN_HL |
| 5007 | if (vcol_save_attr >= 0) |
| 5008 | char_attr = vcol_save_attr; |
| 5009 | #endif |
| 5010 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5011 | /* restore attributes after "predeces" in 'listchars' */ |
| 5012 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5013 | char_attr = saved_attr3; |
| 5014 | |
| 5015 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5016 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5017 | char_attr = saved_attr2; |
| 5018 | |
| 5019 | /* |
| 5020 | * At end of screen line and there is more to come: Display the line |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5021 | * so far. If there is no more to display it is caught above. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5022 | */ |
| 5023 | if (( |
| 5024 | #ifdef FEAT_RIGHTLEFT |
| 5025 | wp->w_p_rl ? (col < 0) : |
| 5026 | #endif |
| 5027 | (col >= W_WIDTH(wp))) |
| 5028 | && (*ptr != NUL |
| 5029 | #ifdef FEAT_DIFF |
| 5030 | || filler_todo > 0 |
| 5031 | #endif |
| 5032 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
| 5033 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5034 | ) |
| 5035 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5036 | #ifdef FEAT_CONCEAL |
| 5037 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5038 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5039 | boguscols = 0; |
| 5040 | #else |
| 5041 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5042 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5043 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5044 | ++row; |
| 5045 | ++screen_row; |
| 5046 | |
| 5047 | /* When not wrapping and finished diff lines, or when displayed |
| 5048 | * '$' and highlighting until last column, break here. */ |
| 5049 | if ((!wp->w_p_wrap |
| 5050 | #ifdef FEAT_DIFF |
| 5051 | && filler_todo <= 0 |
| 5052 | #endif |
| 5053 | ) || lcs_eol_one == -1) |
| 5054 | break; |
| 5055 | |
| 5056 | /* When the window is too narrow draw all "@" lines. */ |
| 5057 | if (draw_state != WL_LINE |
| 5058 | #ifdef FEAT_DIFF |
| 5059 | && filler_todo <= 0 |
| 5060 | #endif |
| 5061 | ) |
| 5062 | { |
| 5063 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 5064 | #ifdef FEAT_VERTSPLIT |
| 5065 | draw_vsep_win(wp, row); |
| 5066 | #endif |
| 5067 | row = endrow; |
| 5068 | } |
| 5069 | |
| 5070 | /* When line got too long for screen break here. */ |
| 5071 | if (row == endrow) |
| 5072 | { |
| 5073 | ++row; |
| 5074 | break; |
| 5075 | } |
| 5076 | |
| 5077 | if (screen_cur_row == screen_row - 1 |
| 5078 | #ifdef FEAT_DIFF |
| 5079 | && filler_todo <= 0 |
| 5080 | #endif |
| 5081 | && W_WIDTH(wp) == Columns) |
| 5082 | { |
| 5083 | /* Remember that the line wraps, used for modeless copy. */ |
| 5084 | LineWraps[screen_row - 1] = TRUE; |
| 5085 | |
| 5086 | /* |
| 5087 | * Special trick to make copy/paste of wrapped lines work with |
| 5088 | * xterm/screen: write an extra character beyond the end of |
| 5089 | * the line. This will work with all terminal types |
| 5090 | * (regardless of the xn,am settings). |
| 5091 | * Only do this on a fast tty. |
| 5092 | * Only do this if the cursor is on the current line |
| 5093 | * (something has been written in it). |
| 5094 | * Don't do this for the GUI. |
| 5095 | * Don't do this for double-width characters. |
| 5096 | * Don't do this for a window not at the right screen border. |
| 5097 | */ |
| 5098 | if (p_tf |
| 5099 | #ifdef FEAT_GUI |
| 5100 | && !gui.in_use |
| 5101 | #endif |
| 5102 | #ifdef FEAT_MBYTE |
| 5103 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5104 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5105 | LineOffset[screen_row] + screen_Columns) |
| 5106 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5107 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5108 | + (int)Columns - 2, |
| 5109 | LineOffset[screen_row] + screen_Columns) |
| 5110 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5111 | #endif |
| 5112 | ) |
| 5113 | { |
| 5114 | /* First make sure we are at the end of the screen line, |
| 5115 | * then output the same character again to let the |
| 5116 | * terminal know about the wrap. If the terminal doesn't |
| 5117 | * auto-wrap, we overwrite the character. */ |
| 5118 | if (screen_cur_col != W_WIDTH(wp)) |
| 5119 | screen_char(LineOffset[screen_row - 1] |
| 5120 | + (unsigned)Columns - 1, |
| 5121 | screen_row - 1, (int)(Columns - 1)); |
| 5122 | |
| 5123 | #ifdef FEAT_MBYTE |
| 5124 | /* When there is a multi-byte character, just output a |
| 5125 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5126 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5127 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5128 | out_char(' '); |
| 5129 | else |
| 5130 | #endif |
| 5131 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5132 | + (Columns - 1)]); |
| 5133 | /* force a redraw of the first char on the next line */ |
| 5134 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5135 | screen_start(); /* don't know where cursor is now */ |
| 5136 | } |
| 5137 | } |
| 5138 | |
| 5139 | col = 0; |
| 5140 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5141 | #ifdef FEAT_RIGHTLEFT |
| 5142 | if (wp->w_p_rl) |
| 5143 | { |
| 5144 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5145 | off += col; |
| 5146 | } |
| 5147 | #endif |
| 5148 | |
| 5149 | /* reset the drawing state for the start of a wrapped line */ |
| 5150 | draw_state = WL_START; |
| 5151 | saved_n_extra = n_extra; |
| 5152 | saved_p_extra = p_extra; |
| 5153 | saved_c_extra = c_extra; |
| 5154 | saved_char_attr = char_attr; |
| 5155 | n_extra = 0; |
| 5156 | lcs_prec_todo = lcs_prec; |
| 5157 | #ifdef FEAT_LINEBREAK |
| 5158 | # ifdef FEAT_DIFF |
| 5159 | if (filler_todo <= 0) |
| 5160 | # endif |
| 5161 | need_showbreak = TRUE; |
| 5162 | #endif |
| 5163 | #ifdef FEAT_DIFF |
| 5164 | --filler_todo; |
| 5165 | /* When the filler lines are actually below the last line of the |
| 5166 | * file, don't draw the line itself, break here. */ |
| 5167 | if (filler_todo == 0 && wp->w_botfill) |
| 5168 | break; |
| 5169 | #endif |
| 5170 | } |
| 5171 | |
| 5172 | } /* for every character in the line */ |
| 5173 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5174 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5175 | /* After an empty line check first word for capital. */ |
| 5176 | if (*skipwhite(line) == NUL) |
| 5177 | { |
| 5178 | capcol_lnum = lnum + 1; |
| 5179 | cap_col = 0; |
| 5180 | } |
| 5181 | #endif |
| 5182 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5183 | return row; |
| 5184 | } |
| 5185 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5186 | #ifdef FEAT_MBYTE |
| 5187 | static int comp_char_differs __ARGS((int, int)); |
| 5188 | |
| 5189 | /* |
| 5190 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5191 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5192 | */ |
| 5193 | static int |
| 5194 | comp_char_differs(off_from, off_to) |
| 5195 | int off_from; |
| 5196 | int off_to; |
| 5197 | { |
| 5198 | int i; |
| 5199 | |
| 5200 | for (i = 0; i < Screen_mco; ++i) |
| 5201 | { |
| 5202 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5203 | return TRUE; |
| 5204 | if (ScreenLinesC[i][off_from] == 0) |
| 5205 | break; |
| 5206 | } |
| 5207 | return FALSE; |
| 5208 | } |
| 5209 | #endif |
| 5210 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5211 | /* |
| 5212 | * Check whether the given character needs redrawing: |
| 5213 | * - the (first byte of the) character is different |
| 5214 | * - the attributes are different |
| 5215 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5216 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5217 | */ |
| 5218 | static int |
| 5219 | char_needs_redraw(off_from, off_to, cols) |
| 5220 | int off_from; |
| 5221 | int off_to; |
| 5222 | int cols; |
| 5223 | { |
| 5224 | if (cols > 0 |
| 5225 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5226 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5227 | |
| 5228 | #ifdef FEAT_MBYTE |
| 5229 | || (enc_dbcs != 0 |
| 5230 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5231 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5232 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5233 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5234 | != ScreenLines[off_to + 1]))) |
| 5235 | || (enc_utf8 |
| 5236 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5237 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5238 | && comp_char_differs(off_from, off_to)) |
| 5239 | || (cols > 1 && ScreenLines[off_from + 1] |
| 5240 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5241 | #endif |
| 5242 | )) |
| 5243 | return TRUE; |
| 5244 | return FALSE; |
| 5245 | } |
| 5246 | |
| 5247 | /* |
| 5248 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5249 | * have actually changed. Handle insert/delete character. |
| 5250 | * "coloff" gives the first column on the screen for this line. |
| 5251 | * "endcol" gives the columns where valid characters are. |
| 5252 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5253 | * needs to be cleared, negative otherwise. |
| 5254 | * "rlflag" is TRUE in a rightleft window: |
| 5255 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5256 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5257 | */ |
| 5258 | static void |
| 5259 | screen_line(row, coloff, endcol, clear_width |
| 5260 | #ifdef FEAT_RIGHTLEFT |
| 5261 | , rlflag |
| 5262 | #endif |
| 5263 | ) |
| 5264 | int row; |
| 5265 | int coloff; |
| 5266 | int endcol; |
| 5267 | int clear_width; |
| 5268 | #ifdef FEAT_RIGHTLEFT |
| 5269 | int rlflag; |
| 5270 | #endif |
| 5271 | { |
| 5272 | unsigned off_from; |
| 5273 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5274 | #ifdef FEAT_MBYTE |
| 5275 | unsigned max_off_from; |
| 5276 | unsigned max_off_to; |
| 5277 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5278 | int col = 0; |
| 5279 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 5280 | int hl; |
| 5281 | #endif |
| 5282 | int force = FALSE; /* force update rest of the line */ |
| 5283 | int redraw_this /* bool: does character need redraw? */ |
| 5284 | #ifdef FEAT_GUI |
| 5285 | = TRUE /* For GUI when while-loop empty */ |
| 5286 | #endif |
| 5287 | ; |
| 5288 | int redraw_next; /* redraw_this for next character */ |
| 5289 | #ifdef FEAT_MBYTE |
| 5290 | int clear_next = FALSE; |
| 5291 | int char_cells; /* 1: normal char */ |
| 5292 | /* 2: occupies two display cells */ |
| 5293 | # define CHAR_CELLS char_cells |
| 5294 | #else |
| 5295 | # define CHAR_CELLS 1 |
| 5296 | #endif |
| 5297 | |
| 5298 | # ifdef FEAT_CLIPBOARD |
| 5299 | clip_may_clear_selection(row, row); |
| 5300 | # endif |
| 5301 | |
| 5302 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5303 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5304 | #ifdef FEAT_MBYTE |
| 5305 | max_off_from = off_from + screen_Columns; |
| 5306 | max_off_to = LineOffset[row] + screen_Columns; |
| 5307 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5308 | |
| 5309 | #ifdef FEAT_RIGHTLEFT |
| 5310 | if (rlflag) |
| 5311 | { |
| 5312 | /* Clear rest first, because it's left of the text. */ |
| 5313 | if (clear_width > 0) |
| 5314 | { |
| 5315 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5316 | && ScreenAttrs[off_to] == 0 |
| 5317 | # ifdef FEAT_MBYTE |
| 5318 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5319 | # endif |
| 5320 | ) |
| 5321 | { |
| 5322 | ++off_to; |
| 5323 | ++col; |
| 5324 | } |
| 5325 | if (col <= endcol) |
| 5326 | screen_fill(row, row + 1, col + coloff, |
| 5327 | endcol + coloff + 1, ' ', ' ', 0); |
| 5328 | } |
| 5329 | col = endcol + 1; |
| 5330 | off_to = LineOffset[row] + col + coloff; |
| 5331 | off_from += col; |
| 5332 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5333 | } |
| 5334 | #endif /* FEAT_RIGHTLEFT */ |
| 5335 | |
| 5336 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5337 | |
| 5338 | while (col < endcol) |
| 5339 | { |
| 5340 | #ifdef FEAT_MBYTE |
| 5341 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5342 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5343 | else |
| 5344 | char_cells = 1; |
| 5345 | #endif |
| 5346 | |
| 5347 | redraw_this = redraw_next; |
| 5348 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5349 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5350 | |
| 5351 | #ifdef FEAT_GUI |
| 5352 | /* If the next character was bold, then redraw the current character to |
| 5353 | * remove any pixels that might have spilt over into us. This only |
| 5354 | * happens in the GUI. |
| 5355 | */ |
| 5356 | if (redraw_next && gui.in_use) |
| 5357 | { |
| 5358 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5359 | if (hl > HL_ALL) |
| 5360 | hl = syn_attr2attr(hl); |
| 5361 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5362 | redraw_this = TRUE; |
| 5363 | } |
| 5364 | #endif |
| 5365 | |
| 5366 | if (redraw_this) |
| 5367 | { |
| 5368 | /* |
| 5369 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5370 | * Attributes for characters are stored at the position where the |
| 5371 | * cursor is when writing the highlighting code. The |
| 5372 | * start-highlighting code must be written with the cursor on the |
| 5373 | * first highlighted character. The stop-highlighting code must |
| 5374 | * be written with the cursor just after the last highlighted |
| 5375 | * character. |
| 5376 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5377 | * to clear the rest of the line, and force redrawing it |
| 5378 | * completely. |
| 5379 | */ |
| 5380 | if ( p_wiv |
| 5381 | && !force |
| 5382 | #ifdef FEAT_GUI |
| 5383 | && !gui.in_use |
| 5384 | #endif |
| 5385 | && ScreenAttrs[off_to] != 0 |
| 5386 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5387 | { |
| 5388 | /* |
| 5389 | * Need to remove highlighting attributes here. |
| 5390 | */ |
| 5391 | windgoto(row, col + coloff); |
| 5392 | out_str(T_CE); /* clear rest of this screen line */ |
| 5393 | screen_start(); /* don't know where cursor is now */ |
| 5394 | force = TRUE; /* force redraw of rest of the line */ |
| 5395 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5396 | |
| 5397 | /* |
| 5398 | * If the previous character was highlighted, need to stop |
| 5399 | * highlighting at this character. |
| 5400 | */ |
| 5401 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5402 | { |
| 5403 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5404 | term_windgoto(row, col + coloff); |
| 5405 | screen_stop_highlight(); |
| 5406 | } |
| 5407 | else |
| 5408 | screen_attr = 0; /* highlighting has stopped */ |
| 5409 | } |
| 5410 | #ifdef FEAT_MBYTE |
| 5411 | if (enc_dbcs != 0) |
| 5412 | { |
| 5413 | /* Check if overwriting a double-byte with a single-byte or |
| 5414 | * the other way around requires another character to be |
| 5415 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 5416 | * ScreenLinesUC[] is sufficient. */ |
| 5417 | if (char_cells == 1 |
| 5418 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5419 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5420 | { |
| 5421 | /* Writing a single-cell character over a double-cell |
| 5422 | * character: need to redraw the next cell. */ |
| 5423 | ScreenLines[off_to + 1] = 0; |
| 5424 | redraw_next = TRUE; |
| 5425 | } |
| 5426 | else if (char_cells == 2 |
| 5427 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5428 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5429 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5430 | { |
| 5431 | /* Writing the second half of a double-cell character over |
| 5432 | * a double-cell character: need to redraw the second |
| 5433 | * cell. */ |
| 5434 | ScreenLines[off_to + 2] = 0; |
| 5435 | redraw_next = TRUE; |
| 5436 | } |
| 5437 | |
| 5438 | if (enc_dbcs == DBCS_JPNU) |
| 5439 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 5440 | } |
| 5441 | /* When writing a single-width character over a double-width |
| 5442 | * character and at the end of the redrawn text, need to clear out |
| 5443 | * the right halve of the old character. |
| 5444 | * Also required when writing the right halve of a double-width |
| 5445 | * char over the left halve of an existing one. */ |
| 5446 | if (has_mbyte && col + char_cells == endcol |
| 5447 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5448 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5449 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5450 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5451 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5452 | clear_next = TRUE; |
| 5453 | #endif |
| 5454 | |
| 5455 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 5456 | #ifdef FEAT_MBYTE |
| 5457 | if (enc_utf8) |
| 5458 | { |
| 5459 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 5460 | if (ScreenLinesUC[off_from] != 0) |
| 5461 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5462 | int i; |
| 5463 | |
| 5464 | for (i = 0; i < Screen_mco; ++i) |
| 5465 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5466 | } |
| 5467 | } |
| 5468 | if (char_cells == 2) |
| 5469 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 5470 | #endif |
| 5471 | |
| 5472 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 5473 | /* The bold trick makes a single column of pixels appear in the |
| 5474 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5475 | * character should be redrawn too. This happens for our own GUI |
| 5476 | * and for some xterms. */ |
| 5477 | if ( |
| 5478 | # ifdef FEAT_GUI |
| 5479 | gui.in_use |
| 5480 | # endif |
| 5481 | # if defined(FEAT_GUI) && defined(UNIX) |
| 5482 | || |
| 5483 | # endif |
| 5484 | # ifdef UNIX |
| 5485 | term_is_xterm |
| 5486 | # endif |
| 5487 | ) |
| 5488 | { |
| 5489 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5490 | if (hl > HL_ALL) |
| 5491 | hl = syn_attr2attr(hl); |
| 5492 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5493 | redraw_next = TRUE; |
| 5494 | } |
| 5495 | #endif |
| 5496 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 5497 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5498 | /* For simplicity set the attributes of second half of a |
| 5499 | * double-wide character equal to the first half. */ |
| 5500 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5501 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5502 | |
| 5503 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5504 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5505 | else |
| 5506 | #endif |
| 5507 | screen_char(off_to, row, col + coloff); |
| 5508 | } |
| 5509 | else if ( p_wiv |
| 5510 | #ifdef FEAT_GUI |
| 5511 | && !gui.in_use |
| 5512 | #endif |
| 5513 | && col + coloff > 0) |
| 5514 | { |
| 5515 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 5516 | { |
| 5517 | /* |
| 5518 | * Don't output stop-highlight when moving the cursor, it will |
| 5519 | * stop the highlighting when it should continue. |
| 5520 | */ |
| 5521 | screen_attr = 0; |
| 5522 | } |
| 5523 | else if (screen_attr != 0) |
| 5524 | screen_stop_highlight(); |
| 5525 | } |
| 5526 | |
| 5527 | off_to += CHAR_CELLS; |
| 5528 | off_from += CHAR_CELLS; |
| 5529 | col += CHAR_CELLS; |
| 5530 | } |
| 5531 | |
| 5532 | #ifdef FEAT_MBYTE |
| 5533 | if (clear_next) |
| 5534 | { |
| 5535 | /* Clear the second half of a double-wide character of which the left |
| 5536 | * half was overwritten with a single-wide character. */ |
| 5537 | ScreenLines[off_to] = ' '; |
| 5538 | if (enc_utf8) |
| 5539 | ScreenLinesUC[off_to] = 0; |
| 5540 | screen_char(off_to, row, col + coloff); |
| 5541 | } |
| 5542 | #endif |
| 5543 | |
| 5544 | if (clear_width > 0 |
| 5545 | #ifdef FEAT_RIGHTLEFT |
| 5546 | && !rlflag |
| 5547 | #endif |
| 5548 | ) |
| 5549 | { |
| 5550 | #ifdef FEAT_GUI |
| 5551 | int startCol = col; |
| 5552 | #endif |
| 5553 | |
| 5554 | /* blank out the rest of the line */ |
| 5555 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 5556 | && ScreenAttrs[off_to] == 0 |
| 5557 | #ifdef FEAT_MBYTE |
| 5558 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5559 | #endif |
| 5560 | ) |
| 5561 | { |
| 5562 | ++off_to; |
| 5563 | ++col; |
| 5564 | } |
| 5565 | if (col < clear_width) |
| 5566 | { |
| 5567 | #ifdef FEAT_GUI |
| 5568 | /* |
| 5569 | * In the GUI, clearing the rest of the line may leave pixels |
| 5570 | * behind if the first character cleared was bold. Some bold |
| 5571 | * fonts spill over the left. In this case we redraw the previous |
| 5572 | * character too. If we didn't skip any blanks above, then we |
| 5573 | * only redraw if the character wasn't already redrawn anyway. |
| 5574 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5575 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5576 | { |
| 5577 | hl = ScreenAttrs[off_to]; |
| 5578 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5579 | { |
| 5580 | int prev_cells = 1; |
| 5581 | # ifdef FEAT_MBYTE |
| 5582 | if (enc_utf8) |
| 5583 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 5584 | * that its width is 2. */ |
| 5585 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 5586 | else if (enc_dbcs != 0) |
| 5587 | { |
| 5588 | /* find previous character by counting from first |
| 5589 | * column and get its width. */ |
| 5590 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5591 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5592 | |
| 5593 | while (off < off_to) |
| 5594 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5595 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5596 | off += prev_cells; |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | if (enc_dbcs != 0 && prev_cells > 1) |
| 5601 | screen_char_2(off_to - prev_cells, row, |
| 5602 | col + coloff - prev_cells); |
| 5603 | else |
| 5604 | # endif |
| 5605 | screen_char(off_to - prev_cells, row, |
| 5606 | col + coloff - prev_cells); |
| 5607 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5608 | } |
| 5609 | #endif |
| 5610 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 5611 | ' ', ' ', 0); |
| 5612 | #ifdef FEAT_VERTSPLIT |
| 5613 | off_to += clear_width - col; |
| 5614 | col = clear_width; |
| 5615 | #endif |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | if (clear_width > 0) |
| 5620 | { |
| 5621 | #ifdef FEAT_VERTSPLIT |
| 5622 | /* For a window that's left of another, draw the separator char. */ |
| 5623 | if (col + coloff < Columns) |
| 5624 | { |
| 5625 | int c; |
| 5626 | |
| 5627 | c = fillchar_vsep(&hl); |
| 5628 | if (ScreenLines[off_to] != c |
| 5629 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5630 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 5631 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5632 | # endif |
| 5633 | || ScreenAttrs[off_to] != hl) |
| 5634 | { |
| 5635 | ScreenLines[off_to] = c; |
| 5636 | ScreenAttrs[off_to] = hl; |
| 5637 | # ifdef FEAT_MBYTE |
| 5638 | if (enc_utf8) |
| 5639 | { |
| 5640 | if (c >= 0x80) |
| 5641 | { |
| 5642 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5643 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5644 | } |
| 5645 | else |
| 5646 | ScreenLinesUC[off_to] = 0; |
| 5647 | } |
| 5648 | # endif |
| 5649 | screen_char(off_to, row, col + coloff); |
| 5650 | } |
| 5651 | } |
| 5652 | else |
| 5653 | #endif |
| 5654 | LineWraps[row] = FALSE; |
| 5655 | } |
| 5656 | } |
| 5657 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5658 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5659 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5660 | * Mirror text "str" for right-left displaying. |
| 5661 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5662 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5663 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5664 | rl_mirror(str) |
| 5665 | char_u *str; |
| 5666 | { |
| 5667 | char_u *p1, *p2; |
| 5668 | int t; |
| 5669 | |
| 5670 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 5671 | { |
| 5672 | t = *p1; |
| 5673 | *p1 = *p2; |
| 5674 | *p2 = t; |
| 5675 | } |
| 5676 | } |
| 5677 | #endif |
| 5678 | |
| 5679 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5680 | /* |
| 5681 | * mark all status lines for redraw; used after first :cd |
| 5682 | */ |
| 5683 | void |
| 5684 | status_redraw_all() |
| 5685 | { |
| 5686 | win_T *wp; |
| 5687 | |
| 5688 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5689 | if (wp->w_status_height) |
| 5690 | { |
| 5691 | wp->w_redr_status = TRUE; |
| 5692 | redraw_later(VALID); |
| 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | /* |
| 5697 | * mark all status lines of the current buffer for redraw |
| 5698 | */ |
| 5699 | void |
| 5700 | status_redraw_curbuf() |
| 5701 | { |
| 5702 | win_T *wp; |
| 5703 | |
| 5704 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5705 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 5706 | { |
| 5707 | wp->w_redr_status = TRUE; |
| 5708 | redraw_later(VALID); |
| 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | /* |
| 5713 | * Redraw all status lines that need to be redrawn. |
| 5714 | */ |
| 5715 | void |
| 5716 | redraw_statuslines() |
| 5717 | { |
| 5718 | win_T *wp; |
| 5719 | |
| 5720 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5721 | if (wp->w_redr_status) |
| 5722 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 5723 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5724 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5725 | } |
| 5726 | #endif |
| 5727 | |
| 5728 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 5729 | /* |
| 5730 | * Redraw all status lines at the bottom of frame "frp". |
| 5731 | */ |
| 5732 | void |
| 5733 | win_redraw_last_status(frp) |
| 5734 | frame_T *frp; |
| 5735 | { |
| 5736 | if (frp->fr_layout == FR_LEAF) |
| 5737 | frp->fr_win->w_redr_status = TRUE; |
| 5738 | else if (frp->fr_layout == FR_ROW) |
| 5739 | { |
| 5740 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 5741 | win_redraw_last_status(frp); |
| 5742 | } |
| 5743 | else /* frp->fr_layout == FR_COL */ |
| 5744 | { |
| 5745 | frp = frp->fr_child; |
| 5746 | while (frp->fr_next != NULL) |
| 5747 | frp = frp->fr_next; |
| 5748 | win_redraw_last_status(frp); |
| 5749 | } |
| 5750 | } |
| 5751 | #endif |
| 5752 | |
| 5753 | #ifdef FEAT_VERTSPLIT |
| 5754 | /* |
| 5755 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 5756 | */ |
| 5757 | static void |
| 5758 | draw_vsep_win(wp, row) |
| 5759 | win_T *wp; |
| 5760 | int row; |
| 5761 | { |
| 5762 | int hl; |
| 5763 | int c; |
| 5764 | |
| 5765 | if (wp->w_vsep_width) |
| 5766 | { |
| 5767 | /* draw the vertical separator right of this window */ |
| 5768 | c = fillchar_vsep(&hl); |
| 5769 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 5770 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 5771 | c, ' ', hl); |
| 5772 | } |
| 5773 | } |
| 5774 | #endif |
| 5775 | |
| 5776 | #ifdef FEAT_WILDMENU |
| 5777 | static int status_match_len __ARGS((expand_T *xp, char_u *s)); |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5778 | 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] | 5779 | |
| 5780 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5781 | * Get the length of an item as it will be shown in the status line. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5782 | */ |
| 5783 | static int |
| 5784 | status_match_len(xp, s) |
| 5785 | expand_T *xp; |
| 5786 | char_u *s; |
| 5787 | { |
| 5788 | int len = 0; |
| 5789 | |
| 5790 | #ifdef FEAT_MENU |
| 5791 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 5792 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5793 | |
| 5794 | /* Check for menu separators - replace with '|'. */ |
| 5795 | if (emenu && menu_is_separator(s)) |
| 5796 | return 1; |
| 5797 | #endif |
| 5798 | |
| 5799 | while (*s != NUL) |
| 5800 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5801 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5802 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5803 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | return len; |
| 5807 | } |
| 5808 | |
| 5809 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5810 | * Return the number of characters that should be skipped in a status match. |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5811 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 5812 | */ |
| 5813 | static int |
| 5814 | skip_status_match_char(xp, s) |
| 5815 | expand_T *xp; |
| 5816 | char_u *s; |
| 5817 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5818 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5819 | #ifdef FEAT_MENU |
| 5820 | || ((xp->xp_context == EXPAND_MENUS |
| 5821 | || xp->xp_context == EXPAND_MENUNAMES) |
| 5822 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 5823 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5824 | ) |
| 5825 | { |
| 5826 | #ifndef BACKSLASH_IN_FILENAME |
| 5827 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 5828 | return 2; |
| 5829 | #endif |
| 5830 | return 1; |
| 5831 | } |
| 5832 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5836 | * Show wildchar matches in the status line. |
| 5837 | * Show at least the "match" item. |
| 5838 | * We start at item 'first_match' in the list and show all matches that fit. |
| 5839 | * |
| 5840 | * If inversion is possible we use it. Else '=' characters are used. |
| 5841 | */ |
| 5842 | void |
| 5843 | win_redr_status_matches(xp, num_matches, matches, match, showtail) |
| 5844 | expand_T *xp; |
| 5845 | int num_matches; |
| 5846 | char_u **matches; /* list of matches */ |
| 5847 | int match; |
| 5848 | int showtail; |
| 5849 | { |
| 5850 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 5851 | int row; |
| 5852 | char_u *buf; |
| 5853 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5854 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5855 | int fillchar; |
| 5856 | int attr; |
| 5857 | int i; |
| 5858 | int highlight = TRUE; |
| 5859 | char_u *selstart = NULL; |
| 5860 | int selstart_col = 0; |
| 5861 | char_u *selend = NULL; |
| 5862 | static int first_match = 0; |
| 5863 | int add_left = FALSE; |
| 5864 | char_u *s; |
| 5865 | #ifdef FEAT_MENU |
| 5866 | int emenu; |
| 5867 | #endif |
| 5868 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 5869 | int l; |
| 5870 | #endif |
| 5871 | |
| 5872 | if (matches == NULL) /* interrupted completion? */ |
| 5873 | return; |
| 5874 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5875 | #ifdef FEAT_MBYTE |
| 5876 | if (has_mbyte) |
| 5877 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 5878 | else |
| 5879 | #endif |
| 5880 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5881 | if (buf == NULL) |
| 5882 | return; |
| 5883 | |
| 5884 | if (match == -1) /* don't show match but original text */ |
| 5885 | { |
| 5886 | match = 0; |
| 5887 | highlight = FALSE; |
| 5888 | } |
| 5889 | /* count 1 for the ending ">" */ |
| 5890 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 5891 | if (match == 0) |
| 5892 | first_match = 0; |
| 5893 | else if (match < first_match) |
| 5894 | { |
| 5895 | /* jumping left, as far as we can go */ |
| 5896 | first_match = match; |
| 5897 | add_left = TRUE; |
| 5898 | } |
| 5899 | else |
| 5900 | { |
| 5901 | /* check if match fits on the screen */ |
| 5902 | for (i = first_match; i < match; ++i) |
| 5903 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5904 | if (first_match > 0) |
| 5905 | clen += 2; |
| 5906 | /* jumping right, put match at the left */ |
| 5907 | if ((long)clen > Columns) |
| 5908 | { |
| 5909 | first_match = match; |
| 5910 | /* if showing the last match, we can add some on the left */ |
| 5911 | clen = 2; |
| 5912 | for (i = match; i < num_matches; ++i) |
| 5913 | { |
| 5914 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 5915 | if ((long)clen >= Columns) |
| 5916 | break; |
| 5917 | } |
| 5918 | if (i == num_matches) |
| 5919 | add_left = TRUE; |
| 5920 | } |
| 5921 | } |
| 5922 | if (add_left) |
| 5923 | while (first_match > 0) |
| 5924 | { |
| 5925 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 5926 | if ((long)clen >= Columns) |
| 5927 | break; |
| 5928 | --first_match; |
| 5929 | } |
| 5930 | |
| 5931 | fillchar = fillchar_status(&attr, TRUE); |
| 5932 | |
| 5933 | if (first_match == 0) |
| 5934 | { |
| 5935 | *buf = NUL; |
| 5936 | len = 0; |
| 5937 | } |
| 5938 | else |
| 5939 | { |
| 5940 | STRCPY(buf, "< "); |
| 5941 | len = 2; |
| 5942 | } |
| 5943 | clen = len; |
| 5944 | |
| 5945 | i = first_match; |
| 5946 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 5947 | { |
| 5948 | if (i == match) |
| 5949 | { |
| 5950 | selstart = buf + len; |
| 5951 | selstart_col = clen; |
| 5952 | } |
| 5953 | |
| 5954 | s = L_MATCH(i); |
| 5955 | /* Check for menu separators - replace with '|' */ |
| 5956 | #ifdef FEAT_MENU |
| 5957 | emenu = (xp->xp_context == EXPAND_MENUS |
| 5958 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5959 | if (emenu && menu_is_separator(s)) |
| 5960 | { |
| 5961 | STRCPY(buf + len, transchar('|')); |
| 5962 | l = (int)STRLEN(buf + len); |
| 5963 | len += l; |
| 5964 | clen += l; |
| 5965 | } |
| 5966 | else |
| 5967 | #endif |
| 5968 | for ( ; *s != NUL; ++s) |
| 5969 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5970 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5971 | clen += ptr2cells(s); |
| 5972 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5973 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5974 | { |
| 5975 | STRNCPY(buf + len, s, l); |
| 5976 | s += l - 1; |
| 5977 | len += l; |
| 5978 | } |
| 5979 | else |
| 5980 | #endif |
| 5981 | { |
| 5982 | STRCPY(buf + len, transchar_byte(*s)); |
| 5983 | len += (int)STRLEN(buf + len); |
| 5984 | } |
| 5985 | } |
| 5986 | if (i == match) |
| 5987 | selend = buf + len; |
| 5988 | |
| 5989 | *(buf + len++) = ' '; |
| 5990 | *(buf + len++) = ' '; |
| 5991 | clen += 2; |
| 5992 | if (++i == num_matches) |
| 5993 | break; |
| 5994 | } |
| 5995 | |
| 5996 | if (i != num_matches) |
| 5997 | { |
| 5998 | *(buf + len++) = '>'; |
| 5999 | ++clen; |
| 6000 | } |
| 6001 | |
| 6002 | buf[len] = NUL; |
| 6003 | |
| 6004 | row = cmdline_row - 1; |
| 6005 | if (row >= 0) |
| 6006 | { |
| 6007 | if (wild_menu_showing == 0) |
| 6008 | { |
| 6009 | if (msg_scrolled > 0) |
| 6010 | { |
| 6011 | /* Put the wildmenu just above the command line. If there is |
| 6012 | * no room, scroll the screen one line up. */ |
| 6013 | if (cmdline_row == Rows - 1) |
| 6014 | { |
| 6015 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6016 | ++msg_scrolled; |
| 6017 | } |
| 6018 | else |
| 6019 | { |
| 6020 | ++cmdline_row; |
| 6021 | ++row; |
| 6022 | } |
| 6023 | wild_menu_showing = WM_SCROLLED; |
| 6024 | } |
| 6025 | else |
| 6026 | { |
| 6027 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6028 | * Set 'winminheight' to zero to avoid that the window is |
| 6029 | * resized. */ |
| 6030 | if (lastwin->w_status_height == 0) |
| 6031 | { |
| 6032 | save_p_ls = p_ls; |
| 6033 | save_p_wmh = p_wmh; |
| 6034 | p_ls = 2; |
| 6035 | p_wmh = 0; |
| 6036 | last_status(FALSE); |
| 6037 | } |
| 6038 | wild_menu_showing = WM_SHOWN; |
| 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | screen_puts(buf, row, 0, attr); |
| 6043 | if (selstart != NULL && highlight) |
| 6044 | { |
| 6045 | *selend = NUL; |
| 6046 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6047 | } |
| 6048 | |
| 6049 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6050 | } |
| 6051 | |
| 6052 | #ifdef FEAT_VERTSPLIT |
| 6053 | win_redraw_last_status(topframe); |
| 6054 | #else |
| 6055 | lastwin->w_redr_status = TRUE; |
| 6056 | #endif |
| 6057 | vim_free(buf); |
| 6058 | } |
| 6059 | #endif |
| 6060 | |
| 6061 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6062 | /* |
| 6063 | * Redraw the status line of window wp. |
| 6064 | * |
| 6065 | * If inversion is possible we use it. Else '=' characters are used. |
| 6066 | */ |
| 6067 | void |
| 6068 | win_redr_status(wp) |
| 6069 | win_T *wp; |
| 6070 | { |
| 6071 | int row; |
| 6072 | char_u *p; |
| 6073 | int len; |
| 6074 | int fillchar; |
| 6075 | int attr; |
| 6076 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6077 | static int busy = FALSE; |
| 6078 | |
| 6079 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6080 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6081 | if (busy) |
| 6082 | return; |
| 6083 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6084 | |
| 6085 | wp->w_redr_status = FALSE; |
| 6086 | if (wp->w_status_height == 0) |
| 6087 | { |
| 6088 | /* no status line, can only be last window */ |
| 6089 | redraw_cmdline = TRUE; |
| 6090 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6091 | else if (!redrawing() |
| 6092 | #ifdef FEAT_INS_EXPAND |
| 6093 | /* don't update status line when popup menu is visible and may be |
| 6094 | * drawn over it */ |
| 6095 | || pum_visible() |
| 6096 | #endif |
| 6097 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6098 | { |
| 6099 | /* Don't redraw right now, do it later. */ |
| 6100 | wp->w_redr_status = TRUE; |
| 6101 | } |
| 6102 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6103 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6104 | { |
| 6105 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6106 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6107 | } |
| 6108 | #endif |
| 6109 | else |
| 6110 | { |
| 6111 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6112 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6113 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6114 | p = NameBuff; |
| 6115 | len = (int)STRLEN(p); |
| 6116 | |
| 6117 | if (wp->w_buffer->b_help |
| 6118 | #ifdef FEAT_QUICKFIX |
| 6119 | || wp->w_p_pvw |
| 6120 | #endif |
| 6121 | || bufIsChanged(wp->w_buffer) |
| 6122 | || wp->w_buffer->b_p_ro) |
| 6123 | *(p + len++) = ' '; |
| 6124 | if (wp->w_buffer->b_help) |
| 6125 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6126 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6127 | len += (int)STRLEN(p + len); |
| 6128 | } |
| 6129 | #ifdef FEAT_QUICKFIX |
| 6130 | if (wp->w_p_pvw) |
| 6131 | { |
| 6132 | STRCPY(p + len, _("[Preview]")); |
| 6133 | len += (int)STRLEN(p + len); |
| 6134 | } |
| 6135 | #endif |
| 6136 | if (bufIsChanged(wp->w_buffer)) |
| 6137 | { |
| 6138 | STRCPY(p + len, "[+]"); |
| 6139 | len += 3; |
| 6140 | } |
| 6141 | if (wp->w_buffer->b_p_ro) |
| 6142 | { |
| 6143 | STRCPY(p + len, "[RO]"); |
| 6144 | len += 4; |
| 6145 | } |
| 6146 | |
| 6147 | #ifndef FEAT_VERTSPLIT |
| 6148 | this_ru_col = ru_col; |
| 6149 | if (this_ru_col < (Columns + 1) / 2) |
| 6150 | this_ru_col = (Columns + 1) / 2; |
| 6151 | #else |
| 6152 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6153 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6154 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6155 | if (this_ru_col <= 1) |
| 6156 | { |
| 6157 | p = (char_u *)"<"; /* No room for file name! */ |
| 6158 | len = 1; |
| 6159 | } |
| 6160 | else |
| 6161 | #endif |
| 6162 | #ifdef FEAT_MBYTE |
| 6163 | if (has_mbyte) |
| 6164 | { |
| 6165 | int clen = 0, i; |
| 6166 | |
| 6167 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6168 | clen = mb_string2cells(p, -1); |
| 6169 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6170 | /* Find first character that will fit. |
| 6171 | * Going from start to end is much faster for DBCS. */ |
| 6172 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6173 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6174 | clen -= (*mb_ptr2cells)(p + i); |
| 6175 | len = clen; |
| 6176 | if (i > 0) |
| 6177 | { |
| 6178 | p = p + i - 1; |
| 6179 | *p = '<'; |
| 6180 | ++len; |
| 6181 | } |
| 6182 | |
| 6183 | } |
| 6184 | else |
| 6185 | #endif |
| 6186 | if (len > this_ru_col - 1) |
| 6187 | { |
| 6188 | p += len - (this_ru_col - 1); |
| 6189 | *p = '<'; |
| 6190 | len = this_ru_col - 1; |
| 6191 | } |
| 6192 | |
| 6193 | row = W_WINROW(wp) + wp->w_height; |
| 6194 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6195 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6196 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6197 | |
| 6198 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 6199 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6200 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6201 | - 1 + W_WINCOL(wp)), attr); |
| 6202 | |
| 6203 | #ifdef FEAT_CMDL_INFO |
| 6204 | win_redr_ruler(wp, TRUE); |
| 6205 | #endif |
| 6206 | } |
| 6207 | |
| 6208 | #ifdef FEAT_VERTSPLIT |
| 6209 | /* |
| 6210 | * May need to draw the character below the vertical separator. |
| 6211 | */ |
| 6212 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6213 | { |
| 6214 | if (stl_connected(wp)) |
| 6215 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6216 | else |
| 6217 | fillchar = fillchar_vsep(&attr); |
| 6218 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6219 | attr); |
| 6220 | } |
| 6221 | #endif |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6222 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6225 | #ifdef FEAT_STL_OPT |
| 6226 | /* |
| 6227 | * Redraw the status line according to 'statusline' and take care of any |
| 6228 | * errors encountered. |
| 6229 | */ |
| 6230 | static void |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6231 | redraw_custom_statusline(wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6232 | win_T *wp; |
| 6233 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6234 | static int entered = FALSE; |
| 6235 | int save_called_emsg = called_emsg; |
| 6236 | |
| 6237 | /* When called recursively return. This can happen when the statusline |
| 6238 | * contains an expression that triggers a redraw. */ |
| 6239 | if (entered) |
| 6240 | return; |
| 6241 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6242 | |
| 6243 | called_emsg = FALSE; |
| 6244 | win_redr_custom(wp, FALSE); |
| 6245 | if (called_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6246 | { |
| 6247 | /* When there is an error disable the statusline, otherwise the |
| 6248 | * display is messed up with errors and a redraw triggers the problem |
| 6249 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6250 | set_string_option_direct((char_u *)"statusline", -1, |
| 6251 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6252 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6253 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6254 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6255 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6256 | } |
| 6257 | #endif |
| 6258 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6259 | # ifdef FEAT_VERTSPLIT |
| 6260 | /* |
| 6261 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6262 | * line of the window right of it. If not, then it's a vertical separator. |
| 6263 | * Only call if (wp->w_vsep_width != 0). |
| 6264 | */ |
| 6265 | int |
| 6266 | stl_connected(wp) |
| 6267 | win_T *wp; |
| 6268 | { |
| 6269 | frame_T *fr; |
| 6270 | |
| 6271 | fr = wp->w_frame; |
| 6272 | while (fr->fr_parent != NULL) |
| 6273 | { |
| 6274 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6275 | { |
| 6276 | if (fr->fr_next != NULL) |
| 6277 | break; |
| 6278 | } |
| 6279 | else |
| 6280 | { |
| 6281 | if (fr->fr_next != NULL) |
| 6282 | return TRUE; |
| 6283 | } |
| 6284 | fr = fr->fr_parent; |
| 6285 | } |
| 6286 | return FALSE; |
| 6287 | } |
| 6288 | # endif |
| 6289 | |
| 6290 | #endif /* FEAT_WINDOWS */ |
| 6291 | |
| 6292 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6293 | /* |
| 6294 | * Get the value to show for the language mappings, active 'keymap'. |
| 6295 | */ |
| 6296 | int |
| 6297 | get_keymap_str(wp, buf, len) |
| 6298 | win_T *wp; |
| 6299 | char_u *buf; /* buffer for the result */ |
| 6300 | int len; /* length of buffer */ |
| 6301 | { |
| 6302 | char_u *p; |
| 6303 | |
| 6304 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6305 | return FALSE; |
| 6306 | |
| 6307 | { |
| 6308 | #ifdef FEAT_EVAL |
| 6309 | buf_T *old_curbuf = curbuf; |
| 6310 | win_T *old_curwin = curwin; |
| 6311 | char_u *s; |
| 6312 | |
| 6313 | curbuf = wp->w_buffer; |
| 6314 | curwin = wp; |
| 6315 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6316 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6317 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6318 | --emsg_skip; |
| 6319 | curbuf = old_curbuf; |
| 6320 | curwin = old_curwin; |
| 6321 | if (p == NULL || *p == NUL) |
| 6322 | #endif |
| 6323 | { |
| 6324 | #ifdef FEAT_KEYMAP |
| 6325 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6326 | p = wp->w_buffer->b_p_keymap; |
| 6327 | else |
| 6328 | #endif |
| 6329 | p = (char_u *)"lang"; |
| 6330 | } |
| 6331 | if ((int)(STRLEN(p) + 3) < len) |
| 6332 | sprintf((char *)buf, "<%s>", p); |
| 6333 | else |
| 6334 | buf[0] = NUL; |
| 6335 | #ifdef FEAT_EVAL |
| 6336 | vim_free(s); |
| 6337 | #endif |
| 6338 | } |
| 6339 | return buf[0] != NUL; |
| 6340 | } |
| 6341 | #endif |
| 6342 | |
| 6343 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6344 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6345 | * Redraw the status line or ruler of window "wp". |
| 6346 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6347 | */ |
| 6348 | static void |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6349 | win_redr_custom(wp, draw_ruler) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6350 | win_T *wp; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6351 | int draw_ruler; /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6352 | { |
| 6353 | int attr; |
| 6354 | int curattr; |
| 6355 | int row; |
| 6356 | int col = 0; |
| 6357 | int maxwidth; |
| 6358 | int width; |
| 6359 | int n; |
| 6360 | int len; |
| 6361 | int fillchar; |
| 6362 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6363 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6364 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6365 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6366 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6367 | int use_sandbox = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6368 | |
| 6369 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6370 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6371 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6372 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6373 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6374 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6375 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6376 | attr = hl_attr(HLF_TPF); |
| 6377 | maxwidth = Columns; |
| 6378 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6379 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6380 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6381 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6382 | else |
| 6383 | { |
| 6384 | row = W_WINROW(wp) + wp->w_height; |
| 6385 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6386 | maxwidth = W_WIDTH(wp); |
| 6387 | |
| 6388 | if (draw_ruler) |
| 6389 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6390 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6391 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6392 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6393 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6394 | if (*++stl == '-') |
| 6395 | stl++; |
| 6396 | if (atoi((char *)stl)) |
| 6397 | while (VIM_ISDIGIT(*stl)) |
| 6398 | stl++; |
| 6399 | if (*stl++ != '(') |
| 6400 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6401 | } |
| 6402 | #ifdef FEAT_VERTSPLIT |
| 6403 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6404 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6405 | col = (W_WIDTH(wp) + 1) / 2; |
| 6406 | #else |
| 6407 | col = ru_col; |
| 6408 | if (col > (Columns + 1) / 2) |
| 6409 | col = (Columns + 1) / 2; |
| 6410 | #endif |
| 6411 | maxwidth = W_WIDTH(wp) - col; |
| 6412 | #ifdef FEAT_WINDOWS |
| 6413 | if (!wp->w_status_height) |
| 6414 | #endif |
| 6415 | { |
| 6416 | row = Rows - 1; |
| 6417 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6418 | fillchar = ' '; |
| 6419 | attr = 0; |
| 6420 | } |
| 6421 | |
| 6422 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6423 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6424 | # endif |
| 6425 | } |
| 6426 | else |
| 6427 | { |
| 6428 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6429 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6430 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6431 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6432 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6433 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 6434 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6435 | # endif |
| 6436 | } |
| 6437 | |
| 6438 | #ifdef FEAT_VERTSPLIT |
| 6439 | col += W_WINCOL(wp); |
| 6440 | #endif |
| 6441 | } |
| 6442 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6443 | if (maxwidth <= 0) |
| 6444 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6445 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6446 | /* Make a copy, because the statusline may include a function call that |
| 6447 | * might change the option value and free the memory. */ |
| 6448 | stl = vim_strsave(stl); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6449 | width = build_stl_str_hl(wp == NULL ? curwin : wp, |
| 6450 | buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6451 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6452 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6453 | vim_free(stl); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 6454 | len = (int)STRLEN(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6455 | |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 6456 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6457 | { |
| 6458 | #ifdef FEAT_MBYTE |
| 6459 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 6460 | #else |
| 6461 | buf[len++] = fillchar; |
| 6462 | #endif |
| 6463 | ++width; |
| 6464 | } |
| 6465 | buf[len] = NUL; |
| 6466 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6467 | /* |
| 6468 | * Draw each snippet with the specified highlighting. |
| 6469 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6470 | curattr = attr; |
| 6471 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6472 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6473 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6474 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6475 | screen_puts_len(p, len, row, col, curattr); |
| 6476 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6477 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6478 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6479 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6480 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6481 | else if (hltab[n].userhl < 0) |
| 6482 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6483 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6484 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6485 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6486 | #endif |
| 6487 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6488 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6489 | } |
| 6490 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6491 | |
| 6492 | if (wp == NULL) |
| 6493 | { |
| 6494 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 6495 | col = 0; |
| 6496 | len = 0; |
| 6497 | p = buf; |
| 6498 | fillchar = 0; |
| 6499 | for (n = 0; tabtab[n].start != NULL; n++) |
| 6500 | { |
| 6501 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 6502 | while (col < len) |
| 6503 | TabPageIdxs[col++] = fillchar; |
| 6504 | p = tabtab[n].start; |
| 6505 | fillchar = tabtab[n].userhl; |
| 6506 | } |
| 6507 | while (col < Columns) |
| 6508 | TabPageIdxs[col++] = fillchar; |
| 6509 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6510 | } |
| 6511 | |
| 6512 | #endif /* FEAT_STL_OPT */ |
| 6513 | |
| 6514 | /* |
| 6515 | * Output a single character directly to the screen and update ScreenLines. |
| 6516 | */ |
| 6517 | void |
| 6518 | screen_putchar(c, row, col, attr) |
| 6519 | int c; |
| 6520 | int row, col; |
| 6521 | int attr; |
| 6522 | { |
| 6523 | #ifdef FEAT_MBYTE |
| 6524 | char_u buf[MB_MAXBYTES + 1]; |
| 6525 | |
| 6526 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 6527 | #else |
| 6528 | char_u buf[2]; |
| 6529 | |
| 6530 | buf[0] = c; |
| 6531 | buf[1] = NUL; |
| 6532 | #endif |
| 6533 | screen_puts(buf, row, col, attr); |
| 6534 | } |
| 6535 | |
| 6536 | /* |
| 6537 | * Get a single character directly from ScreenLines into "bytes[]". |
| 6538 | * Also return its attribute in *attrp; |
| 6539 | */ |
| 6540 | void |
| 6541 | screen_getbytes(row, col, bytes, attrp) |
| 6542 | int row, col; |
| 6543 | char_u *bytes; |
| 6544 | int *attrp; |
| 6545 | { |
| 6546 | unsigned off; |
| 6547 | |
| 6548 | /* safety check */ |
| 6549 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 6550 | { |
| 6551 | off = LineOffset[row] + col; |
| 6552 | *attrp = ScreenAttrs[off]; |
| 6553 | bytes[0] = ScreenLines[off]; |
| 6554 | bytes[1] = NUL; |
| 6555 | |
| 6556 | #ifdef FEAT_MBYTE |
| 6557 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6558 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 6559 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6560 | { |
| 6561 | bytes[0] = ScreenLines[off]; |
| 6562 | bytes[1] = ScreenLines2[off]; |
| 6563 | bytes[2] = NUL; |
| 6564 | } |
| 6565 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 6566 | { |
| 6567 | bytes[1] = ScreenLines[off + 1]; |
| 6568 | bytes[2] = NUL; |
| 6569 | } |
| 6570 | #endif |
| 6571 | } |
| 6572 | } |
| 6573 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6574 | #ifdef FEAT_MBYTE |
| 6575 | static int screen_comp_differs __ARGS((int, int*)); |
| 6576 | |
| 6577 | /* |
| 6578 | * Return TRUE if composing characters for screen posn "off" differs from |
| 6579 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 6580 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6581 | */ |
| 6582 | static int |
| 6583 | screen_comp_differs(off, u8cc) |
| 6584 | int off; |
| 6585 | int *u8cc; |
| 6586 | { |
| 6587 | int i; |
| 6588 | |
| 6589 | for (i = 0; i < Screen_mco; ++i) |
| 6590 | { |
| 6591 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 6592 | return TRUE; |
| 6593 | if (u8cc[i] == 0) |
| 6594 | break; |
| 6595 | } |
| 6596 | return FALSE; |
| 6597 | } |
| 6598 | #endif |
| 6599 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6600 | /* |
| 6601 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 6602 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 6603 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 6604 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 6605 | */ |
| 6606 | void |
| 6607 | screen_puts(text, row, col, attr) |
| 6608 | char_u *text; |
| 6609 | int row; |
| 6610 | int col; |
| 6611 | int attr; |
| 6612 | { |
| 6613 | screen_puts_len(text, -1, row, col, attr); |
| 6614 | } |
| 6615 | |
| 6616 | /* |
| 6617 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 6618 | * a NUL. |
| 6619 | */ |
| 6620 | void |
| 6621 | screen_puts_len(text, len, row, col, attr) |
| 6622 | char_u *text; |
| 6623 | int len; |
| 6624 | int row; |
| 6625 | int col; |
| 6626 | int attr; |
| 6627 | { |
| 6628 | unsigned off; |
| 6629 | char_u *ptr = text; |
| 6630 | int c; |
| 6631 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6632 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6633 | int mbyte_blen = 1; |
| 6634 | int mbyte_cells = 1; |
| 6635 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6636 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6637 | int clear_next_cell = FALSE; |
| 6638 | # ifdef FEAT_ARABIC |
| 6639 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6640 | int pc, nc, nc1; |
| 6641 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6642 | # endif |
| 6643 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6644 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6645 | int force_redraw_this; |
| 6646 | int force_redraw_next = FALSE; |
| 6647 | #endif |
| 6648 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6649 | |
| 6650 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 6651 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6652 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6653 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6654 | #ifdef FEAT_MBYTE |
| 6655 | /* When drawing over the right halve of a double-wide char clear out the |
| 6656 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6657 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6658 | # ifdef FEAT_GUI |
| 6659 | && !gui.in_use |
| 6660 | # endif |
| 6661 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6662 | { |
| 6663 | ScreenLines[off - 1] = ' '; |
| 6664 | ScreenAttrs[off - 1] = 0; |
| 6665 | if (enc_utf8) |
| 6666 | { |
| 6667 | ScreenLinesUC[off - 1] = 0; |
| 6668 | ScreenLinesC[0][off - 1] = 0; |
| 6669 | } |
| 6670 | /* redraw the previous cell, make it empty */ |
| 6671 | screen_char(off - 1, row, col - 1); |
| 6672 | /* force the cell at "col" to be redrawn */ |
| 6673 | force_redraw_next = TRUE; |
| 6674 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6675 | #endif |
| 6676 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6677 | #ifdef FEAT_MBYTE |
| 6678 | max_off = LineOffset[row] + screen_Columns; |
| 6679 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 6680 | while (col < screen_Columns |
| 6681 | && (len < 0 || (int)(ptr - text) < len) |
| 6682 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6683 | { |
| 6684 | c = *ptr; |
| 6685 | #ifdef FEAT_MBYTE |
| 6686 | /* check if this is the first byte of a multibyte */ |
| 6687 | if (has_mbyte) |
| 6688 | { |
| 6689 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6690 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6691 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6692 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6693 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6694 | mbyte_cells = 1; |
| 6695 | else if (enc_dbcs != 0) |
| 6696 | mbyte_cells = mbyte_blen; |
| 6697 | else /* enc_utf8 */ |
| 6698 | { |
| 6699 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6700 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6701 | (int)((text + len) - ptr)); |
| 6702 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6703 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6704 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6705 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6706 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 6707 | if (u8c >= 0x10000) |
| 6708 | { |
| 6709 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 6710 | if (attr == 0) |
| 6711 | attr = hl_attr(HLF_8); |
| 6712 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6713 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6714 | # ifdef FEAT_ARABIC |
| 6715 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 6716 | { |
| 6717 | /* Do Arabic shaping. */ |
| 6718 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 6719 | { |
| 6720 | /* Past end of string to be displayed. */ |
| 6721 | nc = NUL; |
| 6722 | nc1 = NUL; |
| 6723 | } |
| 6724 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6725 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 6726 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 6727 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6728 | nc1 = pcc[0]; |
| 6729 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6730 | pc = prev_c; |
| 6731 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6732 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6733 | } |
| 6734 | else |
| 6735 | prev_c = u8c; |
| 6736 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 6737 | if (col + mbyte_cells > screen_Columns) |
| 6738 | { |
| 6739 | /* Only 1 cell left, but character requires 2 cells: |
| 6740 | * display a '>' in the last column to avoid wrapping. */ |
| 6741 | c = '>'; |
| 6742 | mbyte_cells = 1; |
| 6743 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6744 | } |
| 6745 | } |
| 6746 | #endif |
| 6747 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6748 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6749 | force_redraw_this = force_redraw_next; |
| 6750 | force_redraw_next = FALSE; |
| 6751 | #endif |
| 6752 | |
| 6753 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6754 | #ifdef FEAT_MBYTE |
| 6755 | || (mbyte_cells == 2 |
| 6756 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 6757 | || (enc_dbcs == DBCS_JPNU |
| 6758 | && c == 0x8e |
| 6759 | && ScreenLines2[off] != ptr[1]) |
| 6760 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 6761 | && (ScreenLinesUC[off] != |
| 6762 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 6763 | || (ScreenLinesUC[off] != 0 |
| 6764 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6765 | #endif |
| 6766 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6767 | || exmode_active; |
| 6768 | |
| 6769 | if (need_redraw |
| 6770 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6771 | || force_redraw_this |
| 6772 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6773 | ) |
| 6774 | { |
| 6775 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6776 | /* The bold trick makes a single row of pixels appear in the next |
| 6777 | * character. When a bold character is removed, the next |
| 6778 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6779 | * and for some xterms. */ |
| 6780 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6781 | # ifdef FEAT_GUI |
| 6782 | gui.in_use |
| 6783 | # endif |
| 6784 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6785 | || |
| 6786 | # endif |
| 6787 | # ifdef UNIX |
| 6788 | term_is_xterm |
| 6789 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6790 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6791 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6792 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6793 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6794 | if (n > HL_ALL) |
| 6795 | n = syn_attr2attr(n); |
| 6796 | if (n & HL_BOLD) |
| 6797 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6798 | } |
| 6799 | #endif |
| 6800 | #ifdef FEAT_MBYTE |
| 6801 | /* When at the end of the text and overwriting a two-cell |
| 6802 | * character with a one-cell character, need to clear the next |
| 6803 | * cell. Also when overwriting the left halve of a two-cell char |
| 6804 | * with the right halve of a two-cell char. Do this only once |
| 6805 | * (mb_off2cells() may return 2 on the right halve). */ |
| 6806 | if (clear_next_cell) |
| 6807 | clear_next_cell = FALSE; |
| 6808 | else if (has_mbyte |
| 6809 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 6810 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6811 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6812 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6813 | && (*mb_off2cells)(off, max_off) == 1 |
| 6814 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6815 | clear_next_cell = TRUE; |
| 6816 | |
| 6817 | /* Make sure we never leave a second byte of a double-byte behind, |
| 6818 | * it confuses mb_off2cells(). */ |
| 6819 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6820 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6821 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6822 | && (*mb_off2cells)(off, max_off) == 1 |
| 6823 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6824 | ScreenLines[off + mbyte_blen] = 0; |
| 6825 | #endif |
| 6826 | ScreenLines[off] = c; |
| 6827 | ScreenAttrs[off] = attr; |
| 6828 | #ifdef FEAT_MBYTE |
| 6829 | if (enc_utf8) |
| 6830 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6831 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6832 | ScreenLinesUC[off] = 0; |
| 6833 | else |
| 6834 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6835 | int i; |
| 6836 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6837 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6838 | for (i = 0; i < Screen_mco; ++i) |
| 6839 | { |
| 6840 | ScreenLinesC[i][off] = u8cc[i]; |
| 6841 | if (u8cc[i] == 0) |
| 6842 | break; |
| 6843 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6844 | } |
| 6845 | if (mbyte_cells == 2) |
| 6846 | { |
| 6847 | ScreenLines[off + 1] = 0; |
| 6848 | ScreenAttrs[off + 1] = attr; |
| 6849 | } |
| 6850 | screen_char(off, row, col); |
| 6851 | } |
| 6852 | else if (mbyte_cells == 2) |
| 6853 | { |
| 6854 | ScreenLines[off + 1] = ptr[1]; |
| 6855 | ScreenAttrs[off + 1] = attr; |
| 6856 | screen_char_2(off, row, col); |
| 6857 | } |
| 6858 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6859 | { |
| 6860 | ScreenLines2[off] = ptr[1]; |
| 6861 | screen_char(off, row, col); |
| 6862 | } |
| 6863 | else |
| 6864 | #endif |
| 6865 | screen_char(off, row, col); |
| 6866 | } |
| 6867 | #ifdef FEAT_MBYTE |
| 6868 | if (has_mbyte) |
| 6869 | { |
| 6870 | off += mbyte_cells; |
| 6871 | col += mbyte_cells; |
| 6872 | ptr += mbyte_blen; |
| 6873 | if (clear_next_cell) |
| 6874 | ptr = (char_u *)" "; |
| 6875 | } |
| 6876 | else |
| 6877 | #endif |
| 6878 | { |
| 6879 | ++off; |
| 6880 | ++col; |
| 6881 | ++ptr; |
| 6882 | } |
| 6883 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6884 | |
| 6885 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6886 | /* If we detected the next character needs to be redrawn, but the text |
| 6887 | * doesn't extend up to there, update the character here. */ |
| 6888 | if (force_redraw_next && col < screen_Columns) |
| 6889 | { |
| 6890 | # ifdef FEAT_MBYTE |
| 6891 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 6892 | screen_char_2(off, row, col); |
| 6893 | else |
| 6894 | # endif |
| 6895 | screen_char(off, row, col); |
| 6896 | } |
| 6897 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | #ifdef FEAT_SEARCH_EXTRA |
| 6901 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6902 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6903 | */ |
| 6904 | static void |
| 6905 | start_search_hl() |
| 6906 | { |
| 6907 | if (p_hls && !no_hlsearch) |
| 6908 | { |
| 6909 | last_pat_prog(&search_hl.rm); |
| 6910 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 6911 | # ifdef FEAT_RELTIME |
| 6912 | /* Set the time limit to 'redrawtime'. */ |
| 6913 | profile_setlimit(p_rdt, &search_hl.tm); |
| 6914 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6915 | } |
| 6916 | } |
| 6917 | |
| 6918 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6919 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6920 | */ |
| 6921 | static void |
| 6922 | end_search_hl() |
| 6923 | { |
| 6924 | if (search_hl.rm.regprog != NULL) |
| 6925 | { |
| 6926 | vim_free(search_hl.rm.regprog); |
| 6927 | search_hl.rm.regprog = NULL; |
| 6928 | } |
| 6929 | } |
| 6930 | |
| 6931 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 6932 | * Init for calling prepare_search_hl(). |
| 6933 | */ |
| 6934 | static void |
| 6935 | init_search_hl(wp) |
| 6936 | win_T *wp; |
| 6937 | { |
| 6938 | matchitem_T *cur; |
| 6939 | |
| 6940 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 6941 | * match */ |
| 6942 | cur = wp->w_match_head; |
| 6943 | while (cur != NULL) |
| 6944 | { |
| 6945 | cur->hl.rm = cur->match; |
| 6946 | if (cur->hlg_id == 0) |
| 6947 | cur->hl.attr = 0; |
| 6948 | else |
| 6949 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 6950 | cur->hl.buf = wp->w_buffer; |
| 6951 | cur->hl.lnum = 0; |
| 6952 | cur->hl.first_lnum = 0; |
| 6953 | # ifdef FEAT_RELTIME |
| 6954 | /* Set the time limit to 'redrawtime'. */ |
| 6955 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 6956 | # endif |
| 6957 | cur = cur->next; |
| 6958 | } |
| 6959 | search_hl.buf = wp->w_buffer; |
| 6960 | search_hl.lnum = 0; |
| 6961 | search_hl.first_lnum = 0; |
| 6962 | /* time limit is set at the toplevel, for all windows */ |
| 6963 | } |
| 6964 | |
| 6965 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6966 | * Advance to the match in window "wp" line "lnum" or past it. |
| 6967 | */ |
| 6968 | static void |
| 6969 | prepare_search_hl(wp, lnum) |
| 6970 | win_T *wp; |
| 6971 | linenr_T lnum; |
| 6972 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6973 | matchitem_T *cur; /* points to the match list */ |
| 6974 | match_T *shl; /* points to search_hl or a match */ |
| 6975 | int shl_flag; /* flag to indicate whether search_hl |
| 6976 | has been processed or not */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6977 | int n; |
| 6978 | |
| 6979 | /* |
| 6980 | * When using a multi-line pattern, start searching at the top |
| 6981 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6982 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6983 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6984 | cur = wp->w_match_head; |
| 6985 | shl_flag = FALSE; |
| 6986 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6987 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 6988 | if (shl_flag == FALSE) |
| 6989 | { |
| 6990 | shl = &search_hl; |
| 6991 | shl_flag = TRUE; |
| 6992 | } |
| 6993 | else |
| 6994 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6995 | if (shl->rm.regprog != NULL |
| 6996 | && shl->lnum == 0 |
| 6997 | && re_multiline(shl->rm.regprog)) |
| 6998 | { |
| 6999 | if (shl->first_lnum == 0) |
| 7000 | { |
| 7001 | # ifdef FEAT_FOLDING |
| 7002 | for (shl->first_lnum = lnum; |
| 7003 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7004 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7005 | NULL, NULL, TRUE, NULL)) |
| 7006 | break; |
| 7007 | # else |
| 7008 | shl->first_lnum = wp->w_topline; |
| 7009 | # endif |
| 7010 | } |
| 7011 | n = 0; |
| 7012 | while (shl->first_lnum < lnum && shl->rm.regprog != NULL) |
| 7013 | { |
| 7014 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); |
| 7015 | if (shl->lnum != 0) |
| 7016 | { |
| 7017 | shl->first_lnum = shl->lnum |
| 7018 | + shl->rm.endpos[0].lnum |
| 7019 | - shl->rm.startpos[0].lnum; |
| 7020 | n = shl->rm.endpos[0].col; |
| 7021 | } |
| 7022 | else |
| 7023 | { |
| 7024 | ++shl->first_lnum; |
| 7025 | n = 0; |
| 7026 | } |
| 7027 | } |
| 7028 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7029 | if (shl != &search_hl && cur != NULL) |
| 7030 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7031 | } |
| 7032 | } |
| 7033 | |
| 7034 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7035 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7036 | * Uses shl->buf. |
| 7037 | * Sets shl->lnum and shl->rm contents. |
| 7038 | * Note: Assumes a previous match is always before "lnum", unless |
| 7039 | * shl->lnum is zero. |
| 7040 | * Careful: Any pointers for buffer lines will become invalid. |
| 7041 | */ |
| 7042 | static void |
| 7043 | next_search_hl(win, shl, lnum, mincol) |
| 7044 | win_T *win; |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7045 | match_T *shl; /* points to search_hl or a match */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7046 | linenr_T lnum; |
| 7047 | colnr_T mincol; /* minimal column for a match */ |
| 7048 | { |
| 7049 | linenr_T l; |
| 7050 | colnr_T matchcol; |
| 7051 | long nmatched; |
| 7052 | |
| 7053 | if (shl->lnum != 0) |
| 7054 | { |
| 7055 | /* Check for three situations: |
| 7056 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7057 | * 2. If the previous match includes "mincol", use it. |
| 7058 | * 3. Continue after the previous match. |
| 7059 | */ |
| 7060 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7061 | if (lnum > l) |
| 7062 | shl->lnum = 0; |
| 7063 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7064 | return; |
| 7065 | } |
| 7066 | |
| 7067 | /* |
| 7068 | * Repeat searching for a match until one is found that includes "mincol" |
| 7069 | * or none is found in this line. |
| 7070 | */ |
| 7071 | called_emsg = FALSE; |
| 7072 | for (;;) |
| 7073 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7074 | #ifdef FEAT_RELTIME |
| 7075 | /* Stop searching after passing the time limit. */ |
| 7076 | if (profile_passed_limit(&(shl->tm))) |
| 7077 | { |
| 7078 | shl->lnum = 0; /* no match found in time */ |
| 7079 | break; |
| 7080 | } |
| 7081 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7082 | /* Three situations: |
| 7083 | * 1. No useful previous match: search from start of line. |
| 7084 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7085 | * Break the loop if this is beyond the end of the line. |
| 7086 | * 3. Vi compatible searching: continue at end of previous match. |
| 7087 | */ |
| 7088 | if (shl->lnum == 0) |
| 7089 | matchcol = 0; |
| 7090 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7091 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7092 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7093 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7094 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7095 | |
| 7096 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7097 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7098 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7099 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7100 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7101 | shl->lnum = 0; |
| 7102 | break; |
| 7103 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7104 | #ifdef FEAT_MBYTE |
| 7105 | if (has_mbyte) |
| 7106 | matchcol += mb_ptr2len(ml); |
| 7107 | else |
| 7108 | #endif |
| 7109 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7110 | } |
| 7111 | else |
| 7112 | matchcol = shl->rm.endpos[0].col; |
| 7113 | |
| 7114 | shl->lnum = lnum; |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7115 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
| 7116 | #ifdef FEAT_RELTIME |
| 7117 | &(shl->tm) |
| 7118 | #else |
| 7119 | NULL |
| 7120 | #endif |
| 7121 | ); |
Bram Moolenaar | c7040a5 | 2010-07-20 13:11:28 +0200 | [diff] [blame] | 7122 | if (called_emsg || got_int) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7123 | { |
| 7124 | /* Error while handling regexp: stop using this regexp. */ |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7125 | if (shl == &search_hl) |
| 7126 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7127 | /* don't free regprog in the match list, it's a copy */ |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7128 | vim_free(shl->rm.regprog); |
| 7129 | no_hlsearch = TRUE; |
| 7130 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7131 | shl->rm.regprog = NULL; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7132 | shl->lnum = 0; |
| 7133 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7134 | break; |
| 7135 | } |
| 7136 | if (nmatched == 0) |
| 7137 | { |
| 7138 | shl->lnum = 0; /* no match found */ |
| 7139 | break; |
| 7140 | } |
| 7141 | if (shl->rm.startpos[0].lnum > 0 |
| 7142 | || shl->rm.startpos[0].col >= mincol |
| 7143 | || nmatched > 1 |
| 7144 | || shl->rm.endpos[0].col > mincol) |
| 7145 | { |
| 7146 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7147 | break; /* useful match found */ |
| 7148 | } |
| 7149 | } |
| 7150 | } |
| 7151 | #endif |
| 7152 | |
| 7153 | static void |
| 7154 | screen_start_highlight(attr) |
| 7155 | int attr; |
| 7156 | { |
| 7157 | attrentry_T *aep = NULL; |
| 7158 | |
| 7159 | screen_attr = attr; |
| 7160 | if (full_screen |
| 7161 | #ifdef WIN3264 |
| 7162 | && termcap_active |
| 7163 | #endif |
| 7164 | ) |
| 7165 | { |
| 7166 | #ifdef FEAT_GUI |
| 7167 | if (gui.in_use) |
| 7168 | { |
| 7169 | char buf[20]; |
| 7170 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7171 | /* The GUI handles this internally. */ |
| 7172 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7173 | OUT_STR(buf); |
| 7174 | } |
| 7175 | else |
| 7176 | #endif |
| 7177 | { |
| 7178 | if (attr > HL_ALL) /* special HL attr. */ |
| 7179 | { |
| 7180 | if (t_colors > 1) |
| 7181 | aep = syn_cterm_attr2entry(attr); |
| 7182 | else |
| 7183 | aep = syn_term_attr2entry(attr); |
| 7184 | if (aep == NULL) /* did ":syntax clear" */ |
| 7185 | attr = 0; |
| 7186 | else |
| 7187 | attr = aep->ae_attr; |
| 7188 | } |
| 7189 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7190 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7191 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 7192 | && cterm_normal_fg_bold) |
| 7193 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7194 | * has a FG color defined, clear BOLD. */ |
| 7195 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7196 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7197 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7198 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7199 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7200 | out_str(T_US); |
| 7201 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7202 | out_str(T_CZH); |
| 7203 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7204 | out_str(T_MR); |
| 7205 | |
| 7206 | /* |
| 7207 | * Output the color or start string after bold etc., in case the |
| 7208 | * bold etc. override the color setting. |
| 7209 | */ |
| 7210 | if (aep != NULL) |
| 7211 | { |
| 7212 | if (t_colors > 1) |
| 7213 | { |
| 7214 | if (aep->ae_u.cterm.fg_color) |
| 7215 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7216 | if (aep->ae_u.cterm.bg_color) |
| 7217 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7218 | } |
| 7219 | else |
| 7220 | { |
| 7221 | if (aep->ae_u.term.start != NULL) |
| 7222 | out_str(aep->ae_u.term.start); |
| 7223 | } |
| 7224 | } |
| 7225 | } |
| 7226 | } |
| 7227 | } |
| 7228 | |
| 7229 | void |
| 7230 | screen_stop_highlight() |
| 7231 | { |
| 7232 | int do_ME = FALSE; /* output T_ME code */ |
| 7233 | |
| 7234 | if (screen_attr != 0 |
| 7235 | #ifdef WIN3264 |
| 7236 | && termcap_active |
| 7237 | #endif |
| 7238 | ) |
| 7239 | { |
| 7240 | #ifdef FEAT_GUI |
| 7241 | if (gui.in_use) |
| 7242 | { |
| 7243 | char buf[20]; |
| 7244 | |
| 7245 | /* use internal GUI code */ |
| 7246 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7247 | OUT_STR(buf); |
| 7248 | } |
| 7249 | else |
| 7250 | #endif |
| 7251 | { |
| 7252 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7253 | { |
| 7254 | attrentry_T *aep; |
| 7255 | |
| 7256 | if (t_colors > 1) |
| 7257 | { |
| 7258 | /* |
| 7259 | * Assume that t_me restores the original colors! |
| 7260 | */ |
| 7261 | aep = syn_cterm_attr2entry(screen_attr); |
| 7262 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 7263 | || aep->ae_u.cterm.bg_color)) |
| 7264 | do_ME = TRUE; |
| 7265 | } |
| 7266 | else |
| 7267 | { |
| 7268 | aep = syn_term_attr2entry(screen_attr); |
| 7269 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7270 | { |
| 7271 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7272 | do_ME = TRUE; |
| 7273 | else |
| 7274 | out_str(aep->ae_u.term.stop); |
| 7275 | } |
| 7276 | } |
| 7277 | if (aep == NULL) /* did ":syntax clear" */ |
| 7278 | screen_attr = 0; |
| 7279 | else |
| 7280 | screen_attr = aep->ae_attr; |
| 7281 | } |
| 7282 | |
| 7283 | /* |
| 7284 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 7285 | * same sequence several times. |
| 7286 | */ |
| 7287 | if (screen_attr & HL_STANDOUT) |
| 7288 | { |
| 7289 | if (STRCMP(T_SE, T_ME) == 0) |
| 7290 | do_ME = TRUE; |
| 7291 | else |
| 7292 | out_str(T_SE); |
| 7293 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7294 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7295 | { |
| 7296 | if (STRCMP(T_UE, T_ME) == 0) |
| 7297 | do_ME = TRUE; |
| 7298 | else |
| 7299 | out_str(T_UE); |
| 7300 | } |
| 7301 | if (screen_attr & HL_ITALIC) |
| 7302 | { |
| 7303 | if (STRCMP(T_CZR, T_ME) == 0) |
| 7304 | do_ME = TRUE; |
| 7305 | else |
| 7306 | out_str(T_CZR); |
| 7307 | } |
| 7308 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 7309 | out_str(T_ME); |
| 7310 | |
| 7311 | if (t_colors > 1) |
| 7312 | { |
| 7313 | /* set Normal cterm colors */ |
| 7314 | if (cterm_normal_fg_color != 0) |
| 7315 | term_fg_color(cterm_normal_fg_color - 1); |
| 7316 | if (cterm_normal_bg_color != 0) |
| 7317 | term_bg_color(cterm_normal_bg_color - 1); |
| 7318 | if (cterm_normal_fg_bold) |
| 7319 | out_str(T_MD); |
| 7320 | } |
| 7321 | } |
| 7322 | } |
| 7323 | screen_attr = 0; |
| 7324 | } |
| 7325 | |
| 7326 | /* |
| 7327 | * Reset the colors for a cterm. Used when leaving Vim. |
| 7328 | * The machine specific code may override this again. |
| 7329 | */ |
| 7330 | void |
| 7331 | reset_cterm_colors() |
| 7332 | { |
| 7333 | if (t_colors > 1) |
| 7334 | { |
| 7335 | /* set Normal cterm colors */ |
| 7336 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 7337 | { |
| 7338 | out_str(T_OP); |
| 7339 | screen_attr = -1; |
| 7340 | } |
| 7341 | if (cterm_normal_fg_bold) |
| 7342 | { |
| 7343 | out_str(T_ME); |
| 7344 | screen_attr = -1; |
| 7345 | } |
| 7346 | } |
| 7347 | } |
| 7348 | |
| 7349 | /* |
| 7350 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 7351 | * using the attributes from ScreenAttrs["off"]. |
| 7352 | */ |
| 7353 | static void |
| 7354 | screen_char(off, row, col) |
| 7355 | unsigned off; |
| 7356 | int row; |
| 7357 | int col; |
| 7358 | { |
| 7359 | int attr; |
| 7360 | |
| 7361 | /* Check for illegal values, just in case (could happen just after |
| 7362 | * resizing). */ |
| 7363 | if (row >= screen_Rows || col >= screen_Columns) |
| 7364 | return; |
| 7365 | |
| 7366 | /* Outputting the last character on the screen may scrollup the screen. |
| 7367 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 7368 | if (row == screen_Rows - 1 && col == screen_Columns - 1 |
| 7369 | #ifdef FEAT_RIGHTLEFT |
| 7370 | /* account for first command-line character in rightleft mode */ |
| 7371 | && !cmdmsg_rl |
| 7372 | #endif |
| 7373 | ) |
| 7374 | { |
| 7375 | ScreenAttrs[off] = (sattr_T)-1; |
| 7376 | return; |
| 7377 | } |
| 7378 | |
| 7379 | /* |
| 7380 | * Stop highlighting first, so it's easier to move the cursor. |
| 7381 | */ |
| 7382 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 7383 | if (screen_char_attr != 0) |
| 7384 | attr = screen_char_attr; |
| 7385 | else |
| 7386 | #endif |
| 7387 | attr = ScreenAttrs[off]; |
| 7388 | if (screen_attr != attr) |
| 7389 | screen_stop_highlight(); |
| 7390 | |
| 7391 | windgoto(row, col); |
| 7392 | |
| 7393 | if (screen_attr != attr) |
| 7394 | screen_start_highlight(attr); |
| 7395 | |
| 7396 | #ifdef FEAT_MBYTE |
| 7397 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7398 | { |
| 7399 | char_u buf[MB_MAXBYTES + 1]; |
| 7400 | |
| 7401 | /* Convert UTF-8 character to bytes and write it. */ |
| 7402 | |
| 7403 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 7404 | |
| 7405 | out_str(buf); |
| 7406 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 7407 | ++screen_cur_col; |
| 7408 | } |
| 7409 | else |
| 7410 | #endif |
| 7411 | { |
| 7412 | #ifdef FEAT_MBYTE |
| 7413 | out_flush_check(); |
| 7414 | #endif |
| 7415 | out_char(ScreenLines[off]); |
| 7416 | #ifdef FEAT_MBYTE |
| 7417 | /* double-byte character in single-width cell */ |
| 7418 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7419 | out_char(ScreenLines2[off]); |
| 7420 | #endif |
| 7421 | } |
| 7422 | |
| 7423 | screen_cur_col++; |
| 7424 | } |
| 7425 | |
| 7426 | #ifdef FEAT_MBYTE |
| 7427 | |
| 7428 | /* |
| 7429 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 7430 | * on the screen at position 'row' and 'col'. |
| 7431 | * The attributes of the first byte is used for all. This is required to |
| 7432 | * output the two bytes of a double-byte character with nothing in between. |
| 7433 | */ |
| 7434 | static void |
| 7435 | screen_char_2(off, row, col) |
| 7436 | unsigned off; |
| 7437 | int row; |
| 7438 | int col; |
| 7439 | { |
| 7440 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 7441 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 7442 | return; |
| 7443 | |
| 7444 | /* Outputting the last character on the screen may scrollup the screen. |
| 7445 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 7446 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 7447 | { |
| 7448 | ScreenAttrs[off] = (sattr_T)-1; |
| 7449 | return; |
| 7450 | } |
| 7451 | |
| 7452 | /* Output the first byte normally (positions the cursor), then write the |
| 7453 | * second byte directly. */ |
| 7454 | screen_char(off, row, col); |
| 7455 | out_char(ScreenLines[off + 1]); |
| 7456 | ++screen_cur_col; |
| 7457 | } |
| 7458 | #endif |
| 7459 | |
| 7460 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 7461 | /* |
| 7462 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 7463 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 7464 | */ |
| 7465 | void |
| 7466 | screen_draw_rectangle(row, col, height, width, invert) |
| 7467 | int row; |
| 7468 | int col; |
| 7469 | int height; |
| 7470 | int width; |
| 7471 | int invert; |
| 7472 | { |
| 7473 | int r, c; |
| 7474 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7475 | #ifdef FEAT_MBYTE |
| 7476 | int max_off; |
| 7477 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7478 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7479 | /* Can't use ScreenLines unless initialized */ |
| 7480 | if (ScreenLines == NULL) |
| 7481 | return; |
| 7482 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7483 | if (invert) |
| 7484 | screen_char_attr = HL_INVERSE; |
| 7485 | for (r = row; r < row + height; ++r) |
| 7486 | { |
| 7487 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7488 | #ifdef FEAT_MBYTE |
| 7489 | max_off = off + screen_Columns; |
| 7490 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7491 | for (c = col; c < col + width; ++c) |
| 7492 | { |
| 7493 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7494 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7495 | { |
| 7496 | screen_char_2(off + c, r, c); |
| 7497 | ++c; |
| 7498 | } |
| 7499 | else |
| 7500 | #endif |
| 7501 | { |
| 7502 | screen_char(off + c, r, c); |
| 7503 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7504 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7505 | ++c; |
| 7506 | #endif |
| 7507 | } |
| 7508 | } |
| 7509 | } |
| 7510 | screen_char_attr = 0; |
| 7511 | } |
| 7512 | #endif |
| 7513 | |
| 7514 | #ifdef FEAT_VERTSPLIT |
| 7515 | /* |
| 7516 | * Redraw the characters for a vertically split window. |
| 7517 | */ |
| 7518 | static void |
| 7519 | redraw_block(row, end, wp) |
| 7520 | int row; |
| 7521 | int end; |
| 7522 | win_T *wp; |
| 7523 | { |
| 7524 | int col; |
| 7525 | int width; |
| 7526 | |
| 7527 | # ifdef FEAT_CLIPBOARD |
| 7528 | clip_may_clear_selection(row, end - 1); |
| 7529 | # endif |
| 7530 | |
| 7531 | if (wp == NULL) |
| 7532 | { |
| 7533 | col = 0; |
| 7534 | width = Columns; |
| 7535 | } |
| 7536 | else |
| 7537 | { |
| 7538 | col = wp->w_wincol; |
| 7539 | width = wp->w_width; |
| 7540 | } |
| 7541 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 7542 | } |
| 7543 | #endif |
| 7544 | |
| 7545 | /* |
| 7546 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 7547 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 7548 | * Use attributes 'attr'. |
| 7549 | */ |
| 7550 | void |
| 7551 | screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) |
| 7552 | int start_row, end_row; |
| 7553 | int start_col, end_col; |
| 7554 | int c1, c2; |
| 7555 | int attr; |
| 7556 | { |
| 7557 | int row; |
| 7558 | int col; |
| 7559 | int off; |
| 7560 | int end_off; |
| 7561 | int did_delete; |
| 7562 | int c; |
| 7563 | int norm_term; |
| 7564 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7565 | int force_next = FALSE; |
| 7566 | #endif |
| 7567 | |
| 7568 | if (end_row > screen_Rows) /* safety check */ |
| 7569 | end_row = screen_Rows; |
| 7570 | if (end_col > screen_Columns) /* safety check */ |
| 7571 | end_col = screen_Columns; |
| 7572 | if (ScreenLines == NULL |
| 7573 | || start_row >= end_row |
| 7574 | || start_col >= end_col) /* nothing to do */ |
| 7575 | return; |
| 7576 | |
| 7577 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 7578 | norm_term = ( |
| 7579 | #ifdef FEAT_GUI |
| 7580 | !gui.in_use && |
| 7581 | #endif |
| 7582 | t_colors <= 1); |
| 7583 | for (row = start_row; row < end_row; ++row) |
| 7584 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7585 | #ifdef FEAT_MBYTE |
| 7586 | if (has_mbyte |
| 7587 | # ifdef FEAT_GUI |
| 7588 | && !gui.in_use |
| 7589 | # endif |
| 7590 | ) |
| 7591 | { |
| 7592 | /* When drawing over the right halve of a double-wide char clear |
| 7593 | * out the left halve. When drawing over the left halve of a |
| 7594 | * double wide-char clear out the right halve. Only needed in a |
| 7595 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7596 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 7597 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 7598 | if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 7599 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7600 | } |
| 7601 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7602 | /* |
| 7603 | * Try to use delete-line termcap code, when no attributes or in a |
| 7604 | * "normal" terminal, where a bold/italic space is just a |
| 7605 | * space. |
| 7606 | */ |
| 7607 | did_delete = FALSE; |
| 7608 | if (c2 == ' ' |
| 7609 | && end_col == Columns |
| 7610 | && can_clear(T_CE) |
| 7611 | && (attr == 0 |
| 7612 | || (norm_term |
| 7613 | && attr <= HL_ALL |
| 7614 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 7615 | { |
| 7616 | /* |
| 7617 | * check if we really need to clear something |
| 7618 | */ |
| 7619 | col = start_col; |
| 7620 | if (c1 != ' ') /* don't clear first char */ |
| 7621 | ++col; |
| 7622 | |
| 7623 | off = LineOffset[row] + col; |
| 7624 | end_off = LineOffset[row] + end_col; |
| 7625 | |
| 7626 | /* skip blanks (used often, keep it fast!) */ |
| 7627 | #ifdef FEAT_MBYTE |
| 7628 | if (enc_utf8) |
| 7629 | while (off < end_off && ScreenLines[off] == ' ' |
| 7630 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 7631 | ++off; |
| 7632 | else |
| 7633 | #endif |
| 7634 | while (off < end_off && ScreenLines[off] == ' ' |
| 7635 | && ScreenAttrs[off] == 0) |
| 7636 | ++off; |
| 7637 | if (off < end_off) /* something to be cleared */ |
| 7638 | { |
| 7639 | col = off - LineOffset[row]; |
| 7640 | screen_stop_highlight(); |
| 7641 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 7642 | out_str(T_CE); |
| 7643 | screen_start(); /* don't know where cursor is now */ |
| 7644 | col = end_col - col; |
| 7645 | while (col--) /* clear chars in ScreenLines */ |
| 7646 | { |
| 7647 | ScreenLines[off] = ' '; |
| 7648 | #ifdef FEAT_MBYTE |
| 7649 | if (enc_utf8) |
| 7650 | ScreenLinesUC[off] = 0; |
| 7651 | #endif |
| 7652 | ScreenAttrs[off] = 0; |
| 7653 | ++off; |
| 7654 | } |
| 7655 | } |
| 7656 | did_delete = TRUE; /* the chars are cleared now */ |
| 7657 | } |
| 7658 | |
| 7659 | off = LineOffset[row] + start_col; |
| 7660 | c = c1; |
| 7661 | for (col = start_col; col < end_col; ++col) |
| 7662 | { |
| 7663 | if (ScreenLines[off] != c |
| 7664 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7665 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 7666 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7667 | #endif |
| 7668 | || ScreenAttrs[off] != attr |
| 7669 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7670 | || force_next |
| 7671 | #endif |
| 7672 | ) |
| 7673 | { |
| 7674 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7675 | /* The bold trick may make a single row of pixels appear in |
| 7676 | * the next character. When a bold character is removed, the |
| 7677 | * next character should be redrawn too. This happens for our |
| 7678 | * own GUI and for some xterms. */ |
| 7679 | if ( |
| 7680 | # ifdef FEAT_GUI |
| 7681 | gui.in_use |
| 7682 | # endif |
| 7683 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7684 | || |
| 7685 | # endif |
| 7686 | # ifdef UNIX |
| 7687 | term_is_xterm |
| 7688 | # endif |
| 7689 | ) |
| 7690 | { |
| 7691 | if (ScreenLines[off] != ' ' |
| 7692 | && (ScreenAttrs[off] > HL_ALL |
| 7693 | || ScreenAttrs[off] & HL_BOLD)) |
| 7694 | force_next = TRUE; |
| 7695 | else |
| 7696 | force_next = FALSE; |
| 7697 | } |
| 7698 | #endif |
| 7699 | ScreenLines[off] = c; |
| 7700 | #ifdef FEAT_MBYTE |
| 7701 | if (enc_utf8) |
| 7702 | { |
| 7703 | if (c >= 0x80) |
| 7704 | { |
| 7705 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7706 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7707 | } |
| 7708 | else |
| 7709 | ScreenLinesUC[off] = 0; |
| 7710 | } |
| 7711 | #endif |
| 7712 | ScreenAttrs[off] = attr; |
| 7713 | if (!did_delete || c != ' ') |
| 7714 | screen_char(off, row, col); |
| 7715 | } |
| 7716 | ++off; |
| 7717 | if (col == start_col) |
| 7718 | { |
| 7719 | if (did_delete) |
| 7720 | break; |
| 7721 | c = c2; |
| 7722 | } |
| 7723 | } |
| 7724 | if (end_col == Columns) |
| 7725 | LineWraps[row] = FALSE; |
| 7726 | if (row == Rows - 1) /* overwritten the command line */ |
| 7727 | { |
| 7728 | redraw_cmdline = TRUE; |
| 7729 | if (c1 == ' ' && c2 == ' ') |
| 7730 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7731 | if (start_col == 0) |
| 7732 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7733 | } |
| 7734 | } |
| 7735 | } |
| 7736 | |
| 7737 | /* |
| 7738 | * Check if there should be a delay. Used before clearing or redrawing the |
| 7739 | * screen or the command line. |
| 7740 | */ |
| 7741 | void |
| 7742 | check_for_delay(check_msg_scroll) |
| 7743 | int check_msg_scroll; |
| 7744 | { |
| 7745 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 7746 | && !did_wait_return |
| 7747 | && emsg_silent == 0) |
| 7748 | { |
| 7749 | out_flush(); |
| 7750 | ui_delay(1000L, TRUE); |
| 7751 | emsg_on_display = FALSE; |
| 7752 | if (check_msg_scroll) |
| 7753 | msg_scroll = FALSE; |
| 7754 | } |
| 7755 | } |
| 7756 | |
| 7757 | /* |
| 7758 | * screen_valid - allocate screen buffers if size changed |
| 7759 | * If "clear" is TRUE: clear screen if it has been resized. |
| 7760 | * Returns TRUE if there is a valid screen to write to. |
| 7761 | * Returns FALSE when starting up and screen not initialized yet. |
| 7762 | */ |
| 7763 | int |
| 7764 | screen_valid(clear) |
| 7765 | int clear; |
| 7766 | { |
| 7767 | screenalloc(clear); /* allocate screen buffers if size changed */ |
| 7768 | return (ScreenLines != NULL); |
| 7769 | } |
| 7770 | |
| 7771 | /* |
| 7772 | * Resize the shell to Rows and Columns. |
| 7773 | * Allocate ScreenLines[] and associated items. |
| 7774 | * |
| 7775 | * There may be some time between setting Rows and Columns and (re)allocating |
| 7776 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 7777 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 7778 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 7779 | * final size of the shell is needed. |
| 7780 | */ |
| 7781 | void |
| 7782 | screenalloc(clear) |
| 7783 | int clear; |
| 7784 | { |
| 7785 | int new_row, old_row; |
| 7786 | #ifdef FEAT_GUI |
| 7787 | int old_Rows; |
| 7788 | #endif |
| 7789 | win_T *wp; |
| 7790 | int outofmem = FALSE; |
| 7791 | int len; |
| 7792 | schar_T *new_ScreenLines; |
| 7793 | #ifdef FEAT_MBYTE |
| 7794 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7795 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7796 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7797 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7798 | #endif |
| 7799 | sattr_T *new_ScreenAttrs; |
| 7800 | unsigned *new_LineOffset; |
| 7801 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7802 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7803 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7804 | tabpage_T *tp; |
| 7805 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7806 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7807 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 7808 | #ifdef FEAT_AUTOCMD |
| 7809 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7810 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 7811 | retry: |
| 7812 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7813 | /* |
| 7814 | * Allocation of the screen buffers is done only when the size changes and |
| 7815 | * when Rows and Columns have been set and we have started doing full |
| 7816 | * screen stuff. |
| 7817 | */ |
| 7818 | if ((ScreenLines != NULL |
| 7819 | && Rows == screen_Rows |
| 7820 | && Columns == screen_Columns |
| 7821 | #ifdef FEAT_MBYTE |
| 7822 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 7823 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7824 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7825 | #endif |
| 7826 | ) |
| 7827 | || Rows == 0 |
| 7828 | || Columns == 0 |
| 7829 | || (!full_screen && ScreenLines == NULL)) |
| 7830 | return; |
| 7831 | |
| 7832 | /* |
| 7833 | * It's possible that we produce an out-of-memory message below, which |
| 7834 | * will cause this function to be called again. To break the loop, just |
| 7835 | * return here. |
| 7836 | */ |
| 7837 | if (entered) |
| 7838 | return; |
| 7839 | entered = TRUE; |
| 7840 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 7841 | /* |
| 7842 | * Note that the window sizes are updated before reallocating the arrays, |
| 7843 | * thus we must not redraw here! |
| 7844 | */ |
| 7845 | ++RedrawingDisabled; |
| 7846 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7847 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 7848 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7849 | comp_col(); /* recompute columns for shown command and ruler */ |
| 7850 | |
| 7851 | /* |
| 7852 | * We're changing the size of the screen. |
| 7853 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 7854 | * - Move lines from the old arrays into the new arrays, clear extra |
| 7855 | * lines (unless the screen is going to be cleared). |
| 7856 | * - Free the old arrays. |
| 7857 | * |
| 7858 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 7859 | * Continuing with the old ScreenLines may result in a crash, because the |
| 7860 | * size is wrong. |
| 7861 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7862 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7863 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 7864 | #ifdef FEAT_AUTOCMD |
| 7865 | if (aucmd_win != NULL) |
| 7866 | win_free_lsize(aucmd_win); |
| 7867 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7868 | |
| 7869 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 7870 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 7871 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 7872 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7873 | if (enc_utf8) |
| 7874 | { |
| 7875 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 7876 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7877 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7878 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7879 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 7880 | } |
| 7881 | if (enc_dbcs == DBCS_JPNU) |
| 7882 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 7883 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 7884 | #endif |
| 7885 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 7886 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 7887 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 7888 | Rows * sizeof(unsigned)), FALSE); |
| 7889 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7890 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7891 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7892 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7893 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7894 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7895 | { |
| 7896 | if (win_alloc_lines(wp) == FAIL) |
| 7897 | { |
| 7898 | outofmem = TRUE; |
| 7899 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 7900 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7901 | #endif |
| 7902 | } |
| 7903 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 7904 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 7905 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 7906 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 7907 | outofmem = TRUE; |
| 7908 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 7909 | #ifdef FEAT_WINDOWS |
| 7910 | give_up: |
| 7911 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7912 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7913 | #ifdef FEAT_MBYTE |
| 7914 | for (i = 0; i < p_mco; ++i) |
| 7915 | if (new_ScreenLinesC[i] == NULL) |
| 7916 | break; |
| 7917 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7918 | if (new_ScreenLines == NULL |
| 7919 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7920 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7921 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 7922 | #endif |
| 7923 | || new_ScreenAttrs == NULL |
| 7924 | || new_LineOffset == NULL |
| 7925 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7926 | #ifdef FEAT_WINDOWS |
| 7927 | || new_TabPageIdxs == NULL |
| 7928 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7929 | || outofmem) |
| 7930 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7931 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7932 | { |
| 7933 | /* guess the size */ |
| 7934 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 7935 | |
| 7936 | /* Remember we did this to avoid getting outofmem messages over |
| 7937 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7938 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7939 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7940 | vim_free(new_ScreenLines); |
| 7941 | new_ScreenLines = NULL; |
| 7942 | #ifdef FEAT_MBYTE |
| 7943 | vim_free(new_ScreenLinesUC); |
| 7944 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7945 | for (i = 0; i < p_mco; ++i) |
| 7946 | { |
| 7947 | vim_free(new_ScreenLinesC[i]); |
| 7948 | new_ScreenLinesC[i] = NULL; |
| 7949 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7950 | vim_free(new_ScreenLines2); |
| 7951 | new_ScreenLines2 = NULL; |
| 7952 | #endif |
| 7953 | vim_free(new_ScreenAttrs); |
| 7954 | new_ScreenAttrs = NULL; |
| 7955 | vim_free(new_LineOffset); |
| 7956 | new_LineOffset = NULL; |
| 7957 | vim_free(new_LineWraps); |
| 7958 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7959 | #ifdef FEAT_WINDOWS |
| 7960 | vim_free(new_TabPageIdxs); |
| 7961 | new_TabPageIdxs = NULL; |
| 7962 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7963 | } |
| 7964 | else |
| 7965 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7966 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7967 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7968 | for (new_row = 0; new_row < Rows; ++new_row) |
| 7969 | { |
| 7970 | new_LineOffset[new_row] = new_row * Columns; |
| 7971 | new_LineWraps[new_row] = FALSE; |
| 7972 | |
| 7973 | /* |
| 7974 | * If the screen is not going to be cleared, copy as much as |
| 7975 | * possible from the old screen to the new one and clear the rest |
| 7976 | * (used when resizing the window at the "--more--" prompt or when |
| 7977 | * executing an external command, for the GUI). |
| 7978 | */ |
| 7979 | if (!clear) |
| 7980 | { |
| 7981 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 7982 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 7983 | #ifdef FEAT_MBYTE |
| 7984 | if (enc_utf8) |
| 7985 | { |
| 7986 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 7987 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7988 | for (i = 0; i < p_mco; ++i) |
| 7989 | (void)vim_memset(new_ScreenLinesC[i] |
| 7990 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7991 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 7992 | } |
| 7993 | if (enc_dbcs == DBCS_JPNU) |
| 7994 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 7995 | 0, (size_t)Columns * sizeof(schar_T)); |
| 7996 | #endif |
| 7997 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 7998 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 7999 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8000 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8001 | { |
| 8002 | if (screen_Columns < Columns) |
| 8003 | len = screen_Columns; |
| 8004 | else |
| 8005 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8006 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8007 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8008 | * may be invalid now. Also when p_mco changes. */ |
| 8009 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8010 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8011 | #endif |
| 8012 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8013 | ScreenLines + LineOffset[old_row], |
| 8014 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8015 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8016 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8017 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8018 | { |
| 8019 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8020 | ScreenLinesUC + LineOffset[old_row], |
| 8021 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8022 | for (i = 0; i < p_mco; ++i) |
| 8023 | mch_memmove(new_ScreenLinesC[i] |
| 8024 | + new_LineOffset[new_row], |
| 8025 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8026 | (size_t)len * sizeof(u8char_T)); |
| 8027 | } |
| 8028 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8029 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8030 | ScreenLines2 + LineOffset[old_row], |
| 8031 | (size_t)len * sizeof(schar_T)); |
| 8032 | #endif |
| 8033 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8034 | ScreenAttrs + LineOffset[old_row], |
| 8035 | (size_t)len * sizeof(sattr_T)); |
| 8036 | } |
| 8037 | } |
| 8038 | } |
| 8039 | /* Use the last line of the screen for the current line. */ |
| 8040 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8041 | } |
| 8042 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8043 | free_screenlines(); |
| 8044 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8045 | ScreenLines = new_ScreenLines; |
| 8046 | #ifdef FEAT_MBYTE |
| 8047 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8048 | for (i = 0; i < p_mco; ++i) |
| 8049 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8050 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8051 | ScreenLines2 = new_ScreenLines2; |
| 8052 | #endif |
| 8053 | ScreenAttrs = new_ScreenAttrs; |
| 8054 | LineOffset = new_LineOffset; |
| 8055 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8056 | #ifdef FEAT_WINDOWS |
| 8057 | TabPageIdxs = new_TabPageIdxs; |
| 8058 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8059 | |
| 8060 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8061 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8062 | #ifdef FEAT_GUI |
| 8063 | old_Rows = screen_Rows; |
| 8064 | #endif |
| 8065 | screen_Rows = Rows; |
| 8066 | screen_Columns = Columns; |
| 8067 | |
| 8068 | must_redraw = CLEAR; /* need to clear the screen later */ |
| 8069 | if (clear) |
| 8070 | screenclear2(); |
| 8071 | |
| 8072 | #ifdef FEAT_GUI |
| 8073 | else if (gui.in_use |
| 8074 | && !gui.starting |
| 8075 | && ScreenLines != NULL |
| 8076 | && old_Rows != Rows) |
| 8077 | { |
| 8078 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8079 | /* |
| 8080 | * Adjust the position of the cursor, for when executing an external |
| 8081 | * command. |
| 8082 | */ |
| 8083 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8084 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8085 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8086 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8087 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8088 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8089 | } |
| 8090 | #endif |
| 8091 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8092 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8093 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8094 | |
| 8095 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8096 | /* |
| 8097 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8098 | * in case applying autocommands always changes Rows or Columns. |
| 8099 | */ |
| 8100 | if (starting == 0 && ++retry_count <= 3) |
| 8101 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8102 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8103 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8104 | * jump back to check if we need to allocate the screen again. */ |
| 8105 | goto retry; |
| 8106 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8107 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8108 | } |
| 8109 | |
| 8110 | void |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8111 | free_screenlines() |
| 8112 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8113 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8114 | int i; |
| 8115 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8116 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8117 | for (i = 0; i < Screen_mco; ++i) |
| 8118 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8119 | vim_free(ScreenLines2); |
| 8120 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8121 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8122 | vim_free(ScreenAttrs); |
| 8123 | vim_free(LineOffset); |
| 8124 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8125 | #ifdef FEAT_WINDOWS |
| 8126 | vim_free(TabPageIdxs); |
| 8127 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8131 | screenclear() |
| 8132 | { |
| 8133 | check_for_delay(FALSE); |
| 8134 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8135 | screenclear2(); /* clear the screen */ |
| 8136 | } |
| 8137 | |
| 8138 | static void |
| 8139 | screenclear2() |
| 8140 | { |
| 8141 | int i; |
| 8142 | |
| 8143 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8144 | #ifdef FEAT_GUI |
| 8145 | || (gui.in_use && gui.starting) |
| 8146 | #endif |
| 8147 | ) |
| 8148 | return; |
| 8149 | |
| 8150 | #ifdef FEAT_GUI |
| 8151 | if (!gui.in_use) |
| 8152 | #endif |
| 8153 | screen_attr = -1; /* force setting the Normal colors */ |
| 8154 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8155 | |
| 8156 | #ifdef FEAT_CLIPBOARD |
| 8157 | /* disable selection without redrawing it */ |
| 8158 | clip_scroll_selection(9999); |
| 8159 | #endif |
| 8160 | |
| 8161 | /* blank out ScreenLines */ |
| 8162 | for (i = 0; i < Rows; ++i) |
| 8163 | { |
| 8164 | lineclear(LineOffset[i], (int)Columns); |
| 8165 | LineWraps[i] = FALSE; |
| 8166 | } |
| 8167 | |
| 8168 | if (can_clear(T_CL)) |
| 8169 | { |
| 8170 | out_str(T_CL); /* clear the display */ |
| 8171 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8172 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8173 | } |
| 8174 | else |
| 8175 | { |
| 8176 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8177 | for (i = 0; i < Rows; ++i) |
| 8178 | lineinvalid(LineOffset[i], (int)Columns); |
| 8179 | clear_cmdline = TRUE; |
| 8180 | } |
| 8181 | |
| 8182 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8183 | |
| 8184 | win_rest_invalid(firstwin); |
| 8185 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8186 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8187 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8188 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8189 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8190 | must_redraw = NOT_VALID; |
| 8191 | compute_cmdrow(); |
| 8192 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8193 | msg_col = 0; |
| 8194 | screen_start(); /* don't know where cursor is now */ |
| 8195 | msg_scrolled = 0; /* can't scroll back */ |
| 8196 | msg_didany = FALSE; |
| 8197 | msg_didout = FALSE; |
| 8198 | } |
| 8199 | |
| 8200 | /* |
| 8201 | * Clear one line in ScreenLines. |
| 8202 | */ |
| 8203 | static void |
| 8204 | lineclear(off, width) |
| 8205 | unsigned off; |
| 8206 | int width; |
| 8207 | { |
| 8208 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8209 | #ifdef FEAT_MBYTE |
| 8210 | if (enc_utf8) |
| 8211 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8212 | (size_t)width * sizeof(u8char_T)); |
| 8213 | #endif |
| 8214 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8215 | } |
| 8216 | |
| 8217 | /* |
| 8218 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8219 | * invalid value. |
| 8220 | */ |
| 8221 | static void |
| 8222 | lineinvalid(off, width) |
| 8223 | unsigned off; |
| 8224 | int width; |
| 8225 | { |
| 8226 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8227 | } |
| 8228 | |
| 8229 | #ifdef FEAT_VERTSPLIT |
| 8230 | /* |
| 8231 | * Copy part of a Screenline for vertically split window "wp". |
| 8232 | */ |
| 8233 | static void |
| 8234 | linecopy(to, from, wp) |
| 8235 | int to; |
| 8236 | int from; |
| 8237 | win_T *wp; |
| 8238 | { |
| 8239 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8240 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8241 | |
| 8242 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8243 | wp->w_width * sizeof(schar_T)); |
| 8244 | # ifdef FEAT_MBYTE |
| 8245 | if (enc_utf8) |
| 8246 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8247 | int i; |
| 8248 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8249 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8250 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8251 | for (i = 0; i < p_mco; ++i) |
| 8252 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8253 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8254 | } |
| 8255 | if (enc_dbcs == DBCS_JPNU) |
| 8256 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8257 | wp->w_width * sizeof(schar_T)); |
| 8258 | # endif |
| 8259 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8260 | wp->w_width * sizeof(sattr_T)); |
| 8261 | } |
| 8262 | #endif |
| 8263 | |
| 8264 | /* |
| 8265 | * Return TRUE if clearing with term string "p" would work. |
| 8266 | * It can't work when the string is empty or it won't set the right background. |
| 8267 | */ |
| 8268 | int |
| 8269 | can_clear(p) |
| 8270 | char_u *p; |
| 8271 | { |
| 8272 | return (*p != NUL && (t_colors <= 1 |
| 8273 | #ifdef FEAT_GUI |
| 8274 | || gui.in_use |
| 8275 | #endif |
| 8276 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 8277 | } |
| 8278 | |
| 8279 | /* |
| 8280 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 8281 | * something directly to the screen (shell commands) or a terminal control |
| 8282 | * code. |
| 8283 | */ |
| 8284 | void |
| 8285 | screen_start() |
| 8286 | { |
| 8287 | screen_cur_row = screen_cur_col = 9999; |
| 8288 | } |
| 8289 | |
| 8290 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8291 | * Move the cursor to position "row","col" in the screen. |
| 8292 | * This tries to find the most efficient way to move, minimizing the number of |
| 8293 | * characters sent to the terminal. |
| 8294 | */ |
| 8295 | void |
| 8296 | windgoto(row, col) |
| 8297 | int row; |
| 8298 | int col; |
| 8299 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8300 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8301 | int i; |
| 8302 | int plan; |
| 8303 | int cost; |
| 8304 | int wouldbe_col; |
| 8305 | int noinvcurs; |
| 8306 | char_u *bs; |
| 8307 | int goto_cost; |
| 8308 | int attr; |
| 8309 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8310 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8311 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 8312 | |
| 8313 | #define PLAN_LE 1 |
| 8314 | #define PLAN_CR 2 |
| 8315 | #define PLAN_NL 3 |
| 8316 | #define PLAN_WRITE 4 |
| 8317 | /* Can't use ScreenLines unless initialized */ |
| 8318 | if (ScreenLines == NULL) |
| 8319 | return; |
| 8320 | |
| 8321 | if (col != screen_cur_col || row != screen_cur_row) |
| 8322 | { |
| 8323 | /* Check for valid position. */ |
| 8324 | if (row < 0) /* window without text lines? */ |
| 8325 | row = 0; |
| 8326 | if (row >= screen_Rows) |
| 8327 | row = screen_Rows - 1; |
| 8328 | if (col >= screen_Columns) |
| 8329 | col = screen_Columns - 1; |
| 8330 | |
| 8331 | /* check if no cursor movement is allowed in highlight mode */ |
| 8332 | if (screen_attr && *T_MS == NUL) |
| 8333 | noinvcurs = HIGHL_COST; |
| 8334 | else |
| 8335 | noinvcurs = 0; |
| 8336 | goto_cost = GOTO_COST + noinvcurs; |
| 8337 | |
| 8338 | /* |
| 8339 | * Plan how to do the positioning: |
| 8340 | * 1. Use CR to move it to column 0, same row. |
| 8341 | * 2. Use T_LE to move it a few columns to the left. |
| 8342 | * 3. Use NL to move a few lines down, column 0. |
| 8343 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 8344 | * |
| 8345 | * Don't do this if the cursor went beyond the last column, the cursor |
| 8346 | * position is unknown then (some terminals wrap, some don't ) |
| 8347 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8348 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8349 | * characters to move the cursor to the right. |
| 8350 | */ |
| 8351 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 8352 | { |
| 8353 | /* |
| 8354 | * If the cursor is in the same row, bigger col, we can use CR |
| 8355 | * or T_LE. |
| 8356 | */ |
| 8357 | bs = NULL; /* init for GCC */ |
| 8358 | attr = screen_attr; |
| 8359 | if (row == screen_cur_row && col < screen_cur_col) |
| 8360 | { |
| 8361 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 8362 | if (*T_LE) |
| 8363 | bs = T_LE; /* "cursor left" */ |
| 8364 | else |
| 8365 | bs = T_BC; /* "backspace character (old) */ |
| 8366 | if (*bs) |
| 8367 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 8368 | else |
| 8369 | cost = 999; |
| 8370 | if (col + 1 < cost) /* using CR is less characters */ |
| 8371 | { |
| 8372 | plan = PLAN_CR; |
| 8373 | wouldbe_col = 0; |
| 8374 | cost = 1; /* CR is just one character */ |
| 8375 | } |
| 8376 | else |
| 8377 | { |
| 8378 | plan = PLAN_LE; |
| 8379 | wouldbe_col = col; |
| 8380 | } |
| 8381 | if (noinvcurs) /* will stop highlighting */ |
| 8382 | { |
| 8383 | cost += noinvcurs; |
| 8384 | attr = 0; |
| 8385 | } |
| 8386 | } |
| 8387 | |
| 8388 | /* |
| 8389 | * If the cursor is above where we want to be, we can use CR LF. |
| 8390 | */ |
| 8391 | else if (row > screen_cur_row) |
| 8392 | { |
| 8393 | plan = PLAN_NL; |
| 8394 | wouldbe_col = 0; |
| 8395 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 8396 | if (noinvcurs) /* will stop highlighting */ |
| 8397 | { |
| 8398 | cost += noinvcurs; |
| 8399 | attr = 0; |
| 8400 | } |
| 8401 | } |
| 8402 | |
| 8403 | /* |
| 8404 | * If the cursor is in the same row, smaller col, just use write. |
| 8405 | */ |
| 8406 | else |
| 8407 | { |
| 8408 | plan = PLAN_WRITE; |
| 8409 | wouldbe_col = screen_cur_col; |
| 8410 | cost = 0; |
| 8411 | } |
| 8412 | |
| 8413 | /* |
| 8414 | * Check if any characters that need to be written have the |
| 8415 | * correct attributes. Also avoid UTF-8 characters. |
| 8416 | */ |
| 8417 | i = col - wouldbe_col; |
| 8418 | if (i > 0) |
| 8419 | cost += i; |
| 8420 | if (cost < goto_cost && i > 0) |
| 8421 | { |
| 8422 | /* |
| 8423 | * Check if the attributes are correct without additionally |
| 8424 | * stopping highlighting. |
| 8425 | */ |
| 8426 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 8427 | while (i && *p++ == attr) |
| 8428 | --i; |
| 8429 | if (i != 0) |
| 8430 | { |
| 8431 | /* |
| 8432 | * Try if it works when highlighting is stopped here. |
| 8433 | */ |
| 8434 | if (*--p == 0) |
| 8435 | { |
| 8436 | cost += noinvcurs; |
| 8437 | while (i && *p++ == 0) |
| 8438 | --i; |
| 8439 | } |
| 8440 | if (i != 0) |
| 8441 | cost = 999; /* different attributes, don't do it */ |
| 8442 | } |
| 8443 | #ifdef FEAT_MBYTE |
| 8444 | if (enc_utf8) |
| 8445 | { |
| 8446 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 8447 | for (i = wouldbe_col; i < col; ++i) |
| 8448 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 8449 | { |
| 8450 | cost = 999; |
| 8451 | break; |
| 8452 | } |
| 8453 | } |
| 8454 | #endif |
| 8455 | } |
| 8456 | |
| 8457 | /* |
| 8458 | * We can do it without term_windgoto()! |
| 8459 | */ |
| 8460 | if (cost < goto_cost) |
| 8461 | { |
| 8462 | if (plan == PLAN_LE) |
| 8463 | { |
| 8464 | if (noinvcurs) |
| 8465 | screen_stop_highlight(); |
| 8466 | while (screen_cur_col > col) |
| 8467 | { |
| 8468 | out_str(bs); |
| 8469 | --screen_cur_col; |
| 8470 | } |
| 8471 | } |
| 8472 | else if (plan == PLAN_CR) |
| 8473 | { |
| 8474 | if (noinvcurs) |
| 8475 | screen_stop_highlight(); |
| 8476 | out_char('\r'); |
| 8477 | screen_cur_col = 0; |
| 8478 | } |
| 8479 | else if (plan == PLAN_NL) |
| 8480 | { |
| 8481 | if (noinvcurs) |
| 8482 | screen_stop_highlight(); |
| 8483 | while (screen_cur_row < row) |
| 8484 | { |
| 8485 | out_char('\n'); |
| 8486 | ++screen_cur_row; |
| 8487 | } |
| 8488 | screen_cur_col = 0; |
| 8489 | } |
| 8490 | |
| 8491 | i = col - screen_cur_col; |
| 8492 | if (i > 0) |
| 8493 | { |
| 8494 | /* |
| 8495 | * Use cursor-right if it's one character only. Avoids |
| 8496 | * removing a line of pixels from the last bold char, when |
| 8497 | * using the bold trick in the GUI. |
| 8498 | */ |
| 8499 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 8500 | { |
| 8501 | while (i-- > 0) |
| 8502 | out_char(*T_ND); |
| 8503 | } |
| 8504 | else |
| 8505 | { |
| 8506 | int off; |
| 8507 | |
| 8508 | off = LineOffset[row] + screen_cur_col; |
| 8509 | while (i-- > 0) |
| 8510 | { |
| 8511 | if (ScreenAttrs[off] != screen_attr) |
| 8512 | screen_stop_highlight(); |
| 8513 | #ifdef FEAT_MBYTE |
| 8514 | out_flush_check(); |
| 8515 | #endif |
| 8516 | out_char(ScreenLines[off]); |
| 8517 | #ifdef FEAT_MBYTE |
| 8518 | if (enc_dbcs == DBCS_JPNU |
| 8519 | && ScreenLines[off] == 0x8e) |
| 8520 | out_char(ScreenLines2[off]); |
| 8521 | #endif |
| 8522 | ++off; |
| 8523 | } |
| 8524 | } |
| 8525 | } |
| 8526 | } |
| 8527 | } |
| 8528 | else |
| 8529 | cost = 999; |
| 8530 | |
| 8531 | if (cost >= goto_cost) |
| 8532 | { |
| 8533 | if (noinvcurs) |
| 8534 | screen_stop_highlight(); |
| 8535 | if (row == screen_cur_row && (col > screen_cur_col) && |
| 8536 | *T_CRI != NUL) |
| 8537 | term_cursor_right(col - screen_cur_col); |
| 8538 | else |
| 8539 | term_windgoto(row, col); |
| 8540 | } |
| 8541 | screen_cur_row = row; |
| 8542 | screen_cur_col = col; |
| 8543 | } |
| 8544 | } |
| 8545 | |
| 8546 | /* |
| 8547 | * Set cursor to its position in the current window. |
| 8548 | */ |
| 8549 | void |
| 8550 | setcursor() |
| 8551 | { |
| 8552 | if (redrawing()) |
| 8553 | { |
| 8554 | validate_cursor(); |
| 8555 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 8556 | W_WINCOL(curwin) + ( |
| 8557 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 8558 | /* With 'rightleft' set and the cursor on a double-wide |
| 8559 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8560 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 8561 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 8562 | (has_mbyte |
| 8563 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 8564 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8565 | # endif |
| 8566 | 1)) : |
| 8567 | #endif |
| 8568 | curwin->w_wcol)); |
| 8569 | } |
| 8570 | } |
| 8571 | |
| 8572 | |
| 8573 | /* |
| 8574 | * insert 'line_count' lines at 'row' in window 'wp' |
| 8575 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 8576 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 8577 | * scrolling. |
| 8578 | * Returns FAIL if the lines are not inserted, OK for success. |
| 8579 | */ |
| 8580 | int |
| 8581 | win_ins_lines(wp, row, line_count, invalid, mayclear) |
| 8582 | win_T *wp; |
| 8583 | int row; |
| 8584 | int line_count; |
| 8585 | int invalid; |
| 8586 | int mayclear; |
| 8587 | { |
| 8588 | int did_delete; |
| 8589 | int nextrow; |
| 8590 | int lastrow; |
| 8591 | int retval; |
| 8592 | |
| 8593 | if (invalid) |
| 8594 | wp->w_lines_valid = 0; |
| 8595 | |
| 8596 | if (wp->w_height < 5) |
| 8597 | return FAIL; |
| 8598 | |
| 8599 | if (line_count > wp->w_height - row) |
| 8600 | line_count = wp->w_height - row; |
| 8601 | |
| 8602 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 8603 | if (retval != MAYBE) |
| 8604 | return retval; |
| 8605 | |
| 8606 | /* |
| 8607 | * If there is a next window or a status line, we first try to delete the |
| 8608 | * lines at the bottom to avoid messing what is after the window. |
| 8609 | * If this fails and there are following windows, don't do anything to avoid |
| 8610 | * messing up those windows, better just redraw. |
| 8611 | */ |
| 8612 | did_delete = FALSE; |
| 8613 | #ifdef FEAT_WINDOWS |
| 8614 | if (wp->w_next != NULL || wp->w_status_height) |
| 8615 | { |
| 8616 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8617 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 8618 | did_delete = TRUE; |
| 8619 | else if (wp->w_next) |
| 8620 | return FAIL; |
| 8621 | } |
| 8622 | #endif |
| 8623 | /* |
| 8624 | * if no lines deleted, blank the lines that will end up below the window |
| 8625 | */ |
| 8626 | if (!did_delete) |
| 8627 | { |
| 8628 | #ifdef FEAT_WINDOWS |
| 8629 | wp->w_redr_status = TRUE; |
| 8630 | #endif |
| 8631 | redraw_cmdline = TRUE; |
| 8632 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 8633 | lastrow = nextrow + line_count; |
| 8634 | if (lastrow > Rows) |
| 8635 | lastrow = Rows; |
| 8636 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 8637 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8638 | ' ', ' ', 0); |
| 8639 | } |
| 8640 | |
| 8641 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 8642 | == FAIL) |
| 8643 | { |
| 8644 | /* deletion will have messed up other windows */ |
| 8645 | if (did_delete) |
| 8646 | { |
| 8647 | #ifdef FEAT_WINDOWS |
| 8648 | wp->w_redr_status = TRUE; |
| 8649 | #endif |
| 8650 | win_rest_invalid(W_NEXT(wp)); |
| 8651 | } |
| 8652 | return FAIL; |
| 8653 | } |
| 8654 | |
| 8655 | return OK; |
| 8656 | } |
| 8657 | |
| 8658 | /* |
| 8659 | * delete "line_count" window lines at "row" in window "wp" |
| 8660 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 8661 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 8662 | * scrolling |
| 8663 | * Return OK for success, FAIL if the lines are not deleted. |
| 8664 | */ |
| 8665 | int |
| 8666 | win_del_lines(wp, row, line_count, invalid, mayclear) |
| 8667 | win_T *wp; |
| 8668 | int row; |
| 8669 | int line_count; |
| 8670 | int invalid; |
| 8671 | int mayclear; |
| 8672 | { |
| 8673 | int retval; |
| 8674 | |
| 8675 | if (invalid) |
| 8676 | wp->w_lines_valid = 0; |
| 8677 | |
| 8678 | if (line_count > wp->w_height - row) |
| 8679 | line_count = wp->w_height - row; |
| 8680 | |
| 8681 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 8682 | if (retval != MAYBE) |
| 8683 | return retval; |
| 8684 | |
| 8685 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 8686 | (int)Rows, FALSE, NULL) == FAIL) |
| 8687 | return FAIL; |
| 8688 | |
| 8689 | #ifdef FEAT_WINDOWS |
| 8690 | /* |
| 8691 | * If there are windows or status lines below, try to put them at the |
| 8692 | * correct place. If we can't do that, they have to be redrawn. |
| 8693 | */ |
| 8694 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 8695 | { |
| 8696 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8697 | line_count, (int)Rows, NULL) == FAIL) |
| 8698 | { |
| 8699 | wp->w_redr_status = TRUE; |
| 8700 | win_rest_invalid(wp->w_next); |
| 8701 | } |
| 8702 | } |
| 8703 | /* |
| 8704 | * If this is the last window and there is no status line, redraw the |
| 8705 | * command line later. |
| 8706 | */ |
| 8707 | else |
| 8708 | #endif |
| 8709 | redraw_cmdline = TRUE; |
| 8710 | return OK; |
| 8711 | } |
| 8712 | |
| 8713 | /* |
| 8714 | * Common code for win_ins_lines() and win_del_lines(). |
| 8715 | * Returns OK or FAIL when the work has been done. |
| 8716 | * Returns MAYBE when not finished yet. |
| 8717 | */ |
| 8718 | static int |
| 8719 | win_do_lines(wp, row, line_count, mayclear, del) |
| 8720 | win_T *wp; |
| 8721 | int row; |
| 8722 | int line_count; |
| 8723 | int mayclear; |
| 8724 | int del; |
| 8725 | { |
| 8726 | int retval; |
| 8727 | |
| 8728 | if (!redrawing() || line_count <= 0) |
| 8729 | return FAIL; |
| 8730 | |
| 8731 | /* only a few lines left: redraw is faster */ |
| 8732 | if (mayclear && Rows - line_count < 5 |
| 8733 | #ifdef FEAT_VERTSPLIT |
| 8734 | && wp->w_width == Columns |
| 8735 | #endif |
| 8736 | ) |
| 8737 | { |
| 8738 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 8739 | return FAIL; |
| 8740 | } |
| 8741 | |
| 8742 | /* |
| 8743 | * Delete all remaining lines |
| 8744 | */ |
| 8745 | if (row + line_count >= wp->w_height) |
| 8746 | { |
| 8747 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 8748 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8749 | ' ', ' ', 0); |
| 8750 | return OK; |
| 8751 | } |
| 8752 | |
| 8753 | /* |
| 8754 | * when scrolling, the message on the command line should be cleared, |
| 8755 | * otherwise it will stay there forever. |
| 8756 | */ |
| 8757 | clear_cmdline = TRUE; |
| 8758 | |
| 8759 | /* |
| 8760 | * If the terminal can set a scroll region, use that. |
| 8761 | * Always do this in a vertically split window. This will redraw from |
| 8762 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 8763 | * win_line(). |
| 8764 | * Don't use a scroll region when we are going to redraw the text, writing |
| 8765 | * a character in the lower right corner of the scroll region causes a |
| 8766 | * scroll-up in the DJGPP version. |
| 8767 | */ |
| 8768 | if (scroll_region |
| 8769 | #ifdef FEAT_VERTSPLIT |
| 8770 | || W_WIDTH(wp) != Columns |
| 8771 | #endif |
| 8772 | ) |
| 8773 | { |
| 8774 | #ifdef FEAT_VERTSPLIT |
| 8775 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8776 | #endif |
| 8777 | scroll_region_set(wp, row); |
| 8778 | if (del) |
| 8779 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 8780 | wp->w_height - row, FALSE, wp); |
| 8781 | else |
| 8782 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 8783 | wp->w_height - row, wp); |
| 8784 | #ifdef FEAT_VERTSPLIT |
| 8785 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8786 | #endif |
| 8787 | scroll_region_reset(); |
| 8788 | return retval; |
| 8789 | } |
| 8790 | |
| 8791 | #ifdef FEAT_WINDOWS |
| 8792 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 8793 | return FAIL; |
| 8794 | #endif |
| 8795 | |
| 8796 | return MAYBE; |
| 8797 | } |
| 8798 | |
| 8799 | /* |
| 8800 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 8801 | */ |
| 8802 | static void |
| 8803 | win_rest_invalid(wp) |
| 8804 | win_T *wp; |
| 8805 | { |
| 8806 | #ifdef FEAT_WINDOWS |
| 8807 | while (wp != NULL) |
| 8808 | #else |
| 8809 | if (wp != NULL) |
| 8810 | #endif |
| 8811 | { |
| 8812 | redraw_win_later(wp, NOT_VALID); |
| 8813 | #ifdef FEAT_WINDOWS |
| 8814 | wp->w_redr_status = TRUE; |
| 8815 | wp = wp->w_next; |
| 8816 | #endif |
| 8817 | } |
| 8818 | redraw_cmdline = TRUE; |
| 8819 | } |
| 8820 | |
| 8821 | /* |
| 8822 | * The rest of the routines in this file perform screen manipulations. The |
| 8823 | * given operation is performed physically on the screen. The corresponding |
| 8824 | * change is also made to the internal screen image. In this way, the editor |
| 8825 | * anticipates the effect of editing changes on the appearance of the screen. |
| 8826 | * That way, when we call screenupdate a complete redraw isn't usually |
| 8827 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 8828 | * screen changes, and in the meantime, everything still works. |
| 8829 | */ |
| 8830 | |
| 8831 | /* |
| 8832 | * types for inserting or deleting lines |
| 8833 | */ |
| 8834 | #define USE_T_CAL 1 |
| 8835 | #define USE_T_CDL 2 |
| 8836 | #define USE_T_AL 3 |
| 8837 | #define USE_T_CE 4 |
| 8838 | #define USE_T_DL 5 |
| 8839 | #define USE_T_SR 6 |
| 8840 | #define USE_NL 7 |
| 8841 | #define USE_T_CD 8 |
| 8842 | #define USE_REDRAW 9 |
| 8843 | |
| 8844 | /* |
| 8845 | * insert lines on the screen and update ScreenLines[] |
| 8846 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 8847 | * When scrolling region used 'off' is the offset from the top for the region. |
| 8848 | * 'row' and 'end' are relative to the start of the region. |
| 8849 | * |
| 8850 | * return FAIL for failure, OK for success. |
| 8851 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 8852 | int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8853 | screen_ins_lines(off, row, line_count, end, wp) |
| 8854 | int off; |
| 8855 | int row; |
| 8856 | int line_count; |
| 8857 | int end; |
| 8858 | win_T *wp; /* NULL or window to use width from */ |
| 8859 | { |
| 8860 | int i; |
| 8861 | int j; |
| 8862 | unsigned temp; |
| 8863 | int cursor_row; |
| 8864 | int type; |
| 8865 | int result_empty; |
| 8866 | int can_ce = can_clear(T_CE); |
| 8867 | |
| 8868 | /* |
| 8869 | * FAIL if |
| 8870 | * - there is no valid screen |
| 8871 | * - the screen has to be redrawn completely |
| 8872 | * - the line count is less than one |
| 8873 | * - the line count is more than 'ttyscroll' |
| 8874 | */ |
| 8875 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 8876 | return FAIL; |
| 8877 | |
| 8878 | /* |
| 8879 | * There are seven ways to insert lines: |
| 8880 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 8881 | * characters from ScreenLines[]. |
| 8882 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 8883 | * the insert is just empty lines |
| 8884 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 8885 | * present or line_count > 1. It looks better if we do all the inserts |
| 8886 | * at once. |
| 8887 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 8888 | * insert is just empty lines and T_CE is not present or line_count > |
| 8889 | * 1. |
| 8890 | * 4. Use T_AL (insert line) if it exists. |
| 8891 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 8892 | * just empty lines. |
| 8893 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 8894 | * just empty lines. |
| 8895 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 8896 | * the 'da' flag is not set or we have clear line capability. |
| 8897 | * 8. redraw the characters from ScreenLines[]. |
| 8898 | * |
| 8899 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 8900 | * the scrollbar for the window. It does have insert line, use that if it |
| 8901 | * exists. |
| 8902 | */ |
| 8903 | result_empty = (row + line_count >= end); |
| 8904 | #ifdef FEAT_VERTSPLIT |
| 8905 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 8906 | type = USE_REDRAW; |
| 8907 | else |
| 8908 | #endif |
| 8909 | if (can_clear(T_CD) && result_empty) |
| 8910 | type = USE_T_CD; |
| 8911 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 8912 | type = USE_T_CAL; |
| 8913 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 8914 | type = USE_T_CDL; |
| 8915 | else if (*T_AL != NUL) |
| 8916 | type = USE_T_AL; |
| 8917 | else if (can_ce && result_empty) |
| 8918 | type = USE_T_CE; |
| 8919 | else if (*T_DL != NUL && result_empty) |
| 8920 | type = USE_T_DL; |
| 8921 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 8922 | type = USE_T_SR; |
| 8923 | else |
| 8924 | return FAIL; |
| 8925 | |
| 8926 | /* |
| 8927 | * For clearing the lines screen_del_lines() is used. This will also take |
| 8928 | * care of t_db if necessary. |
| 8929 | */ |
| 8930 | if (type == USE_T_CD || type == USE_T_CDL || |
| 8931 | type == USE_T_CE || type == USE_T_DL) |
| 8932 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 8933 | |
| 8934 | /* |
| 8935 | * If text is retained below the screen, first clear or delete as many |
| 8936 | * lines at the bottom of the window as are about to be inserted so that |
| 8937 | * the deleted lines won't later surface during a screen_del_lines. |
| 8938 | */ |
| 8939 | if (*T_DB) |
| 8940 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 8941 | |
| 8942 | #ifdef FEAT_CLIPBOARD |
| 8943 | /* Remove a modeless selection when inserting lines halfway the screen |
| 8944 | * or not the full width of the screen. */ |
| 8945 | if (off + row > 0 |
| 8946 | # ifdef FEAT_VERTSPLIT |
| 8947 | || (wp != NULL && wp->w_width != Columns) |
| 8948 | # endif |
| 8949 | ) |
| 8950 | clip_clear_selection(); |
| 8951 | else |
| 8952 | clip_scroll_selection(-line_count); |
| 8953 | #endif |
| 8954 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8955 | #ifdef FEAT_GUI |
| 8956 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 8957 | * scrolling is actually carried out. */ |
| 8958 | gui_dont_update_cursor(); |
| 8959 | #endif |
| 8960 | |
| 8961 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 8962 | cursor_row = row; |
| 8963 | else |
| 8964 | cursor_row = row + off; |
| 8965 | |
| 8966 | /* |
| 8967 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 8968 | * Clear the inserted lines in ScreenLines[]. |
| 8969 | */ |
| 8970 | row += off; |
| 8971 | end += off; |
| 8972 | for (i = 0; i < line_count; ++i) |
| 8973 | { |
| 8974 | #ifdef FEAT_VERTSPLIT |
| 8975 | if (wp != NULL && wp->w_width != Columns) |
| 8976 | { |
| 8977 | /* need to copy part of a line */ |
| 8978 | j = end - 1 - i; |
| 8979 | while ((j -= line_count) >= row) |
| 8980 | linecopy(j + line_count, j, wp); |
| 8981 | j += line_count; |
| 8982 | if (can_clear((char_u *)" ")) |
| 8983 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8984 | else |
| 8985 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 8986 | LineWraps[j] = FALSE; |
| 8987 | } |
| 8988 | else |
| 8989 | #endif |
| 8990 | { |
| 8991 | j = end - 1 - i; |
| 8992 | temp = LineOffset[j]; |
| 8993 | while ((j -= line_count) >= row) |
| 8994 | { |
| 8995 | LineOffset[j + line_count] = LineOffset[j]; |
| 8996 | LineWraps[j + line_count] = LineWraps[j]; |
| 8997 | } |
| 8998 | LineOffset[j + line_count] = temp; |
| 8999 | LineWraps[j + line_count] = FALSE; |
| 9000 | if (can_clear((char_u *)" ")) |
| 9001 | lineclear(temp, (int)Columns); |
| 9002 | else |
| 9003 | lineinvalid(temp, (int)Columns); |
| 9004 | } |
| 9005 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9006 | |
| 9007 | screen_stop_highlight(); |
| 9008 | windgoto(cursor_row, 0); |
| 9009 | |
| 9010 | #ifdef FEAT_VERTSPLIT |
| 9011 | /* redraw the characters */ |
| 9012 | if (type == USE_REDRAW) |
| 9013 | redraw_block(row, end, wp); |
| 9014 | else |
| 9015 | #endif |
| 9016 | if (type == USE_T_CAL) |
| 9017 | { |
| 9018 | term_append_lines(line_count); |
| 9019 | screen_start(); /* don't know where cursor is now */ |
| 9020 | } |
| 9021 | else |
| 9022 | { |
| 9023 | for (i = 0; i < line_count; i++) |
| 9024 | { |
| 9025 | if (type == USE_T_AL) |
| 9026 | { |
| 9027 | if (i && cursor_row != 0) |
| 9028 | windgoto(cursor_row, 0); |
| 9029 | out_str(T_AL); |
| 9030 | } |
| 9031 | else /* type == USE_T_SR */ |
| 9032 | out_str(T_SR); |
| 9033 | screen_start(); /* don't know where cursor is now */ |
| 9034 | } |
| 9035 | } |
| 9036 | |
| 9037 | /* |
| 9038 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9039 | * have been scrolled down into the region. |
| 9040 | */ |
| 9041 | if (type == USE_T_SR && *T_DA) |
| 9042 | { |
| 9043 | for (i = 0; i < line_count; ++i) |
| 9044 | { |
| 9045 | windgoto(off + i, 0); |
| 9046 | out_str(T_CE); |
| 9047 | screen_start(); /* don't know where cursor is now */ |
| 9048 | } |
| 9049 | } |
| 9050 | |
| 9051 | #ifdef FEAT_GUI |
| 9052 | gui_can_update_cursor(); |
| 9053 | if (gui.in_use) |
| 9054 | out_flush(); /* always flush after a scroll */ |
| 9055 | #endif |
| 9056 | return OK; |
| 9057 | } |
| 9058 | |
| 9059 | /* |
| 9060 | * delete lines on the screen and update ScreenLines[] |
| 9061 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9062 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9063 | * 'row' and 'end' are relative to the start of the region. |
| 9064 | * |
| 9065 | * Return OK for success, FAIL if the lines are not deleted. |
| 9066 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9067 | int |
| 9068 | screen_del_lines(off, row, line_count, end, force, wp) |
| 9069 | int off; |
| 9070 | int row; |
| 9071 | int line_count; |
| 9072 | int end; |
| 9073 | int force; /* even when line_count > p_ttyscroll */ |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 9074 | win_T *wp UNUSED; /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9075 | { |
| 9076 | int j; |
| 9077 | int i; |
| 9078 | unsigned temp; |
| 9079 | int cursor_row; |
| 9080 | int cursor_end; |
| 9081 | int result_empty; /* result is empty until end of region */ |
| 9082 | int can_delete; /* deleting line codes can be used */ |
| 9083 | int type; |
| 9084 | |
| 9085 | /* |
| 9086 | * FAIL if |
| 9087 | * - there is no valid screen |
| 9088 | * - the screen has to be redrawn completely |
| 9089 | * - the line count is less than one |
| 9090 | * - the line count is more than 'ttyscroll' |
| 9091 | */ |
| 9092 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9093 | (!force && line_count > p_ttyscroll)) |
| 9094 | return FAIL; |
| 9095 | |
| 9096 | /* |
| 9097 | * Check if the rest of the current region will become empty. |
| 9098 | */ |
| 9099 | result_empty = row + line_count >= end; |
| 9100 | |
| 9101 | /* |
| 9102 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9103 | * available. |
| 9104 | */ |
| 9105 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9106 | |
| 9107 | /* |
| 9108 | * There are six ways to delete lines: |
| 9109 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9110 | * characters from ScreenLines[]. |
| 9111 | * 1. Use T_CD if it exists and the result is empty. |
| 9112 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9113 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9114 | * none of the other ways work. |
| 9115 | * 4. Use T_CE (erase line) if the result is empty. |
| 9116 | * 5. Use T_DL (delete line) if it exists. |
| 9117 | * 6. redraw the characters from ScreenLines[]. |
| 9118 | */ |
| 9119 | #ifdef FEAT_VERTSPLIT |
| 9120 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9121 | type = USE_REDRAW; |
| 9122 | else |
| 9123 | #endif |
| 9124 | if (can_clear(T_CD) && result_empty) |
| 9125 | type = USE_T_CD; |
| 9126 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9127 | /* |
| 9128 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9129 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9130 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9131 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9132 | * the trick... |
| 9133 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9134 | * (Olaf Seibert) |
| 9135 | */ |
| 9136 | else if (row == 0 && T_DB == empty_option |
| 9137 | && (line_count == 1 || *T_CDL == NUL)) |
| 9138 | #else |
| 9139 | else if (row == 0 && ( |
| 9140 | #ifndef AMIGA |
| 9141 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9142 | * up, so use delete-line command */ |
| 9143 | line_count == 1 || |
| 9144 | #endif |
| 9145 | *T_CDL == NUL)) |
| 9146 | #endif |
| 9147 | type = USE_NL; |
| 9148 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9149 | type = USE_T_CDL; |
| 9150 | else if (can_clear(T_CE) && result_empty |
| 9151 | #ifdef FEAT_VERTSPLIT |
| 9152 | && (wp == NULL || wp->w_width == Columns) |
| 9153 | #endif |
| 9154 | ) |
| 9155 | type = USE_T_CE; |
| 9156 | else if (*T_DL != NUL && can_delete) |
| 9157 | type = USE_T_DL; |
| 9158 | else if (*T_CDL != NUL && can_delete) |
| 9159 | type = USE_T_CDL; |
| 9160 | else |
| 9161 | return FAIL; |
| 9162 | |
| 9163 | #ifdef FEAT_CLIPBOARD |
| 9164 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9165 | * not the full width of the screen. */ |
| 9166 | if (off + row > 0 |
| 9167 | # ifdef FEAT_VERTSPLIT |
| 9168 | || (wp != NULL && wp->w_width != Columns) |
| 9169 | # endif |
| 9170 | ) |
| 9171 | clip_clear_selection(); |
| 9172 | else |
| 9173 | clip_scroll_selection(line_count); |
| 9174 | #endif |
| 9175 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9176 | #ifdef FEAT_GUI |
| 9177 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9178 | * scrolling is actually carried out. */ |
| 9179 | gui_dont_update_cursor(); |
| 9180 | #endif |
| 9181 | |
| 9182 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9183 | { |
| 9184 | cursor_row = row; |
| 9185 | cursor_end = end; |
| 9186 | } |
| 9187 | else |
| 9188 | { |
| 9189 | cursor_row = row + off; |
| 9190 | cursor_end = end + off; |
| 9191 | } |
| 9192 | |
| 9193 | /* |
| 9194 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9195 | * Clear the inserted lines in ScreenLines[]. |
| 9196 | */ |
| 9197 | row += off; |
| 9198 | end += off; |
| 9199 | for (i = 0; i < line_count; ++i) |
| 9200 | { |
| 9201 | #ifdef FEAT_VERTSPLIT |
| 9202 | if (wp != NULL && wp->w_width != Columns) |
| 9203 | { |
| 9204 | /* need to copy part of a line */ |
| 9205 | j = row + i; |
| 9206 | while ((j += line_count) <= end - 1) |
| 9207 | linecopy(j - line_count, j, wp); |
| 9208 | j -= line_count; |
| 9209 | if (can_clear((char_u *)" ")) |
| 9210 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9211 | else |
| 9212 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9213 | LineWraps[j] = FALSE; |
| 9214 | } |
| 9215 | else |
| 9216 | #endif |
| 9217 | { |
| 9218 | /* whole width, moving the line pointers is faster */ |
| 9219 | j = row + i; |
| 9220 | temp = LineOffset[j]; |
| 9221 | while ((j += line_count) <= end - 1) |
| 9222 | { |
| 9223 | LineOffset[j - line_count] = LineOffset[j]; |
| 9224 | LineWraps[j - line_count] = LineWraps[j]; |
| 9225 | } |
| 9226 | LineOffset[j - line_count] = temp; |
| 9227 | LineWraps[j - line_count] = FALSE; |
| 9228 | if (can_clear((char_u *)" ")) |
| 9229 | lineclear(temp, (int)Columns); |
| 9230 | else |
| 9231 | lineinvalid(temp, (int)Columns); |
| 9232 | } |
| 9233 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9234 | |
| 9235 | screen_stop_highlight(); |
| 9236 | |
| 9237 | #ifdef FEAT_VERTSPLIT |
| 9238 | /* redraw the characters */ |
| 9239 | if (type == USE_REDRAW) |
| 9240 | redraw_block(row, end, wp); |
| 9241 | else |
| 9242 | #endif |
| 9243 | if (type == USE_T_CD) /* delete the lines */ |
| 9244 | { |
| 9245 | windgoto(cursor_row, 0); |
| 9246 | out_str(T_CD); |
| 9247 | screen_start(); /* don't know where cursor is now */ |
| 9248 | } |
| 9249 | else if (type == USE_T_CDL) |
| 9250 | { |
| 9251 | windgoto(cursor_row, 0); |
| 9252 | term_delete_lines(line_count); |
| 9253 | screen_start(); /* don't know where cursor is now */ |
| 9254 | } |
| 9255 | /* |
| 9256 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9257 | * the whole screen (scroll region) up by outputting newlines on the |
| 9258 | * last line. |
| 9259 | */ |
| 9260 | else if (type == USE_NL) |
| 9261 | { |
| 9262 | windgoto(cursor_end - 1, 0); |
| 9263 | for (i = line_count; --i >= 0; ) |
| 9264 | out_char('\n'); /* cursor will remain on same line */ |
| 9265 | } |
| 9266 | else |
| 9267 | { |
| 9268 | for (i = line_count; --i >= 0; ) |
| 9269 | { |
| 9270 | if (type == USE_T_DL) |
| 9271 | { |
| 9272 | windgoto(cursor_row, 0); |
| 9273 | out_str(T_DL); /* delete a line */ |
| 9274 | } |
| 9275 | else /* type == USE_T_CE */ |
| 9276 | { |
| 9277 | windgoto(cursor_row + i, 0); |
| 9278 | out_str(T_CE); /* erase a line */ |
| 9279 | } |
| 9280 | screen_start(); /* don't know where cursor is now */ |
| 9281 | } |
| 9282 | } |
| 9283 | |
| 9284 | /* |
| 9285 | * If the 'db' flag is set, we need to clear the lines that have been |
| 9286 | * scrolled up at the bottom of the region. |
| 9287 | */ |
| 9288 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 9289 | { |
| 9290 | for (i = line_count; i > 0; --i) |
| 9291 | { |
| 9292 | windgoto(cursor_end - i, 0); |
| 9293 | out_str(T_CE); /* erase a line */ |
| 9294 | screen_start(); /* don't know where cursor is now */ |
| 9295 | } |
| 9296 | } |
| 9297 | |
| 9298 | #ifdef FEAT_GUI |
| 9299 | gui_can_update_cursor(); |
| 9300 | if (gui.in_use) |
| 9301 | out_flush(); /* always flush after a scroll */ |
| 9302 | #endif |
| 9303 | |
| 9304 | return OK; |
| 9305 | } |
| 9306 | |
| 9307 | /* |
| 9308 | * show the current mode and ruler |
| 9309 | * |
| 9310 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 9311 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 9312 | * cleared only if a mode is shown. |
| 9313 | * Return the length of the message (0 if no message). |
| 9314 | */ |
| 9315 | int |
| 9316 | showmode() |
| 9317 | { |
| 9318 | int need_clear; |
| 9319 | int length = 0; |
| 9320 | int do_mode; |
| 9321 | int attr; |
| 9322 | int nwr_save; |
| 9323 | #ifdef FEAT_INS_EXPAND |
| 9324 | int sub_attr; |
| 9325 | #endif |
| 9326 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 9327 | do_mode = ((p_smd && msg_silent == 0) |
| 9328 | && ((State & INSERT) |
| 9329 | || restart_edit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9330 | #ifdef FEAT_VISUAL |
| 9331 | || VIsual_active |
| 9332 | #endif |
| 9333 | )); |
| 9334 | if (do_mode || Recording) |
| 9335 | { |
| 9336 | /* |
| 9337 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 9338 | * Call char_avail() only when we are going to show something, because |
| 9339 | * it takes a bit of time. |
| 9340 | */ |
| 9341 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 9342 | { |
| 9343 | redraw_cmdline = TRUE; /* show mode later */ |
| 9344 | return 0; |
| 9345 | } |
| 9346 | |
| 9347 | nwr_save = need_wait_return; |
| 9348 | |
| 9349 | /* wait a bit before overwriting an important message */ |
| 9350 | check_for_delay(FALSE); |
| 9351 | |
| 9352 | /* if the cmdline is more than one line high, erase top lines */ |
| 9353 | need_clear = clear_cmdline; |
| 9354 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 9355 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 9356 | |
| 9357 | /* Position on the last line in the window, column 0 */ |
| 9358 | msg_pos_mode(); |
| 9359 | cursor_off(); |
| 9360 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 9361 | if (do_mode) |
| 9362 | { |
| 9363 | MSG_PUTS_ATTR("--", attr); |
| 9364 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9365 | # if 0 /* old version, changed by SungHyun Nam July 2008 */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9366 | if (xic != NULL && im_get_status() && !p_imdisable |
| 9367 | && curbuf->b_p_iminsert == B_IMODE_IM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9368 | # else |
| 9369 | if ( |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 9370 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9371 | preedit_get_status() |
| 9372 | # else |
| 9373 | im_get_status() |
| 9374 | # endif |
| 9375 | ) |
| 9376 | # endif |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 9377 | # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9378 | MSG_PUTS_ATTR(" IM", attr); |
| 9379 | # else |
| 9380 | MSG_PUTS_ATTR(" XIM", attr); |
| 9381 | # endif |
| 9382 | #endif |
| 9383 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 9384 | if (gui.in_use) |
| 9385 | { |
| 9386 | if (hangul_input_state_get()) |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9387 | MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9388 | } |
| 9389 | #endif |
| 9390 | #ifdef FEAT_INS_EXPAND |
| 9391 | if (edit_submode != NULL) /* CTRL-X in Insert mode */ |
| 9392 | { |
| 9393 | /* These messages can get long, avoid a wrap in a narrow |
| 9394 | * window. Prefer showing edit_submode_extra. */ |
| 9395 | length = (Rows - msg_row) * Columns - 3; |
| 9396 | if (edit_submode_extra != NULL) |
| 9397 | length -= vim_strsize(edit_submode_extra); |
| 9398 | if (length > 0) |
| 9399 | { |
| 9400 | if (edit_submode_pre != NULL) |
| 9401 | length -= vim_strsize(edit_submode_pre); |
| 9402 | if (length - vim_strsize(edit_submode) > 0) |
| 9403 | { |
| 9404 | if (edit_submode_pre != NULL) |
| 9405 | msg_puts_attr(edit_submode_pre, attr); |
| 9406 | msg_puts_attr(edit_submode, attr); |
| 9407 | } |
| 9408 | if (edit_submode_extra != NULL) |
| 9409 | { |
| 9410 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 9411 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 9412 | sub_attr = hl_attr(edit_submode_highl); |
| 9413 | else |
| 9414 | sub_attr = attr; |
| 9415 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 9416 | } |
| 9417 | } |
| 9418 | length = 0; |
| 9419 | } |
| 9420 | else |
| 9421 | #endif |
| 9422 | { |
| 9423 | #ifdef FEAT_VREPLACE |
| 9424 | if (State & VREPLACE_FLAG) |
| 9425 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 9426 | else |
| 9427 | #endif |
| 9428 | if (State & REPLACE_FLAG) |
| 9429 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 9430 | else if (State & INSERT) |
| 9431 | { |
| 9432 | #ifdef FEAT_RIGHTLEFT |
| 9433 | if (p_ri) |
| 9434 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 9435 | #endif |
| 9436 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 9437 | } |
| 9438 | else if (restart_edit == 'I') |
| 9439 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 9440 | else if (restart_edit == 'R') |
| 9441 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 9442 | else if (restart_edit == 'V') |
| 9443 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 9444 | #ifdef FEAT_RIGHTLEFT |
| 9445 | if (p_hkmap) |
| 9446 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 9447 | # ifdef FEAT_FKMAP |
| 9448 | if (p_fkmap) |
| 9449 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 9450 | # endif |
| 9451 | #endif |
| 9452 | #ifdef FEAT_KEYMAP |
| 9453 | if (State & LANGMAP) |
| 9454 | { |
| 9455 | # ifdef FEAT_ARABIC |
| 9456 | if (curwin->w_p_arab) |
| 9457 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 9458 | else |
| 9459 | # endif |
| 9460 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 9461 | } |
| 9462 | #endif |
| 9463 | if ((State & INSERT) && p_paste) |
| 9464 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 9465 | |
| 9466 | #ifdef FEAT_VISUAL |
| 9467 | if (VIsual_active) |
| 9468 | { |
| 9469 | char *p; |
| 9470 | |
| 9471 | /* Don't concatenate separate words to avoid translation |
| 9472 | * problems. */ |
| 9473 | switch ((VIsual_select ? 4 : 0) |
| 9474 | + (VIsual_mode == Ctrl_V) * 2 |
| 9475 | + (VIsual_mode == 'V')) |
| 9476 | { |
| 9477 | case 0: p = N_(" VISUAL"); break; |
| 9478 | case 1: p = N_(" VISUAL LINE"); break; |
| 9479 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 9480 | case 4: p = N_(" SELECT"); break; |
| 9481 | case 5: p = N_(" SELECT LINE"); break; |
| 9482 | default: p = N_(" SELECT BLOCK"); break; |
| 9483 | } |
| 9484 | MSG_PUTS_ATTR(_(p), attr); |
| 9485 | } |
| 9486 | #endif |
| 9487 | MSG_PUTS_ATTR(" --", attr); |
| 9488 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9489 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9490 | need_clear = TRUE; |
| 9491 | } |
| 9492 | if (Recording |
| 9493 | #ifdef FEAT_INS_EXPAND |
| 9494 | && edit_submode == NULL /* otherwise it gets too long */ |
| 9495 | #endif |
| 9496 | ) |
| 9497 | { |
| 9498 | MSG_PUTS_ATTR(_("recording"), attr); |
| 9499 | need_clear = TRUE; |
| 9500 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9501 | |
| 9502 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9503 | if (need_clear || clear_cmdline) |
| 9504 | msg_clr_eos(); |
| 9505 | msg_didout = FALSE; /* overwrite this message */ |
| 9506 | length = msg_col; |
| 9507 | msg_col = 0; |
| 9508 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 9509 | } |
| 9510 | else if (clear_cmdline && msg_silent == 0) |
| 9511 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 9512 | msg_clr_cmdline(); |
| 9513 | |
| 9514 | #ifdef FEAT_CMDL_INFO |
| 9515 | # ifdef FEAT_VISUAL |
| 9516 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 9517 | if (VIsual_active) |
| 9518 | clear_showcmd(); |
| 9519 | # endif |
| 9520 | |
| 9521 | /* If the last window has no status line, the ruler is after the mode |
| 9522 | * message and must be redrawn */ |
| 9523 | if (redrawing() |
| 9524 | # ifdef FEAT_WINDOWS |
| 9525 | && lastwin->w_status_height == 0 |
| 9526 | # endif |
| 9527 | ) |
| 9528 | win_redr_ruler(lastwin, TRUE); |
| 9529 | #endif |
| 9530 | redraw_cmdline = FALSE; |
| 9531 | clear_cmdline = FALSE; |
| 9532 | |
| 9533 | return length; |
| 9534 | } |
| 9535 | |
| 9536 | /* |
| 9537 | * Position for a mode message. |
| 9538 | */ |
| 9539 | static void |
| 9540 | msg_pos_mode() |
| 9541 | { |
| 9542 | msg_col = 0; |
| 9543 | msg_row = Rows - 1; |
| 9544 | } |
| 9545 | |
| 9546 | /* |
| 9547 | * Delete mode message. Used when ESC is typed which is expected to end |
| 9548 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9549 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9550 | */ |
| 9551 | void |
| 9552 | unshowmode(force) |
| 9553 | int force; |
| 9554 | { |
| 9555 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 9556 | * Don't delete it right now, when not redrawing or inside a mapping. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9557 | */ |
| 9558 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 9559 | redraw_cmdline = TRUE; /* delete mode later */ |
| 9560 | else |
| 9561 | { |
| 9562 | msg_pos_mode(); |
| 9563 | if (Recording) |
| 9564 | MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); |
| 9565 | msg_clr_eos(); |
| 9566 | } |
| 9567 | } |
| 9568 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9569 | #if defined(FEAT_WINDOWS) |
| 9570 | /* |
| 9571 | * Draw the tab pages line at the top of the Vim window. |
| 9572 | */ |
| 9573 | static void |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9574 | draw_tabline() |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9575 | { |
| 9576 | int tabcount = 0; |
| 9577 | tabpage_T *tp; |
| 9578 | int tabwidth; |
| 9579 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9580 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9581 | int attr; |
| 9582 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9583 | win_T *cwp; |
| 9584 | int wincount; |
| 9585 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9586 | int c; |
| 9587 | int len; |
| 9588 | int attr_sel = hl_attr(HLF_TPS); |
| 9589 | int attr_nosel = hl_attr(HLF_TP); |
| 9590 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9591 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9592 | int room; |
| 9593 | int use_sep_chars = (t_colors < 8 |
| 9594 | #ifdef FEAT_GUI |
| 9595 | && !gui.in_use |
| 9596 | #endif |
| 9597 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9598 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9599 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9600 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9601 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 9602 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9603 | if (gui_use_tabline()) |
| 9604 | { |
| 9605 | gui_update_tabline(); |
| 9606 | return; |
| 9607 | } |
| 9608 | #endif |
| 9609 | |
| 9610 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9611 | return; |
| 9612 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9613 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9614 | |
| 9615 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 9616 | for (scol = 0; scol < Columns; ++scol) |
| 9617 | TabPageIdxs[scol] = 0; |
| 9618 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9619 | /* Use the 'tabline' option if it's set. */ |
| 9620 | if (*p_tal != NUL) |
| 9621 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9622 | int save_called_emsg = called_emsg; |
| 9623 | |
| 9624 | /* Check for an error. If there is one we would loop in redrawing the |
| 9625 | * screen. Avoid that by making 'tabline' empty. */ |
| 9626 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9627 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9628 | if (called_emsg) |
| 9629 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 9630 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9631 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9632 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9633 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9634 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9635 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9636 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 9637 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9638 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9639 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 9640 | if (tabwidth < 6) |
| 9641 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9642 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9643 | attr = attr_nosel; |
| 9644 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9645 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9646 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 9647 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9648 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9649 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9650 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9651 | if (tp->tp_topframe == topframe) |
| 9652 | attr = attr_sel; |
| 9653 | if (use_sep_chars && col > 0) |
| 9654 | screen_putchar('|', 0, col++, attr); |
| 9655 | |
| 9656 | if (tp->tp_topframe != topframe) |
| 9657 | attr = attr_nosel; |
| 9658 | |
| 9659 | screen_putchar(' ', 0, col++, attr); |
| 9660 | |
| 9661 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9662 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9663 | cwp = curwin; |
| 9664 | wp = firstwin; |
| 9665 | } |
| 9666 | else |
| 9667 | { |
| 9668 | cwp = tp->tp_curwin; |
| 9669 | wp = tp->tp_firstwin; |
| 9670 | } |
| 9671 | |
| 9672 | modified = FALSE; |
| 9673 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 9674 | if (bufIsChanged(wp->w_buffer)) |
| 9675 | modified = TRUE; |
| 9676 | if (modified || wincount > 1) |
| 9677 | { |
| 9678 | if (wincount > 1) |
| 9679 | { |
| 9680 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9681 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9682 | if (col + len >= Columns - 3) |
| 9683 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9684 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9685 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9686 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9687 | #else |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9688 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9689 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9690 | ); |
| 9691 | col += len; |
| 9692 | } |
| 9693 | if (modified) |
| 9694 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 9695 | screen_putchar(' ', 0, col++, attr); |
| 9696 | } |
| 9697 | |
| 9698 | room = scol - col + tabwidth - 1; |
| 9699 | if (room > 0) |
| 9700 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9701 | /* Get buffer name in NameBuff[] */ |
| 9702 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 9703 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9704 | len = vim_strsize(NameBuff); |
| 9705 | p = NameBuff; |
| 9706 | #ifdef FEAT_MBYTE |
| 9707 | if (has_mbyte) |
| 9708 | while (len > room) |
| 9709 | { |
| 9710 | len -= ptr2cells(p); |
| 9711 | mb_ptr_adv(p); |
| 9712 | } |
| 9713 | else |
| 9714 | #endif |
| 9715 | if (len > room) |
| 9716 | { |
| 9717 | p += len - room; |
| 9718 | len = room; |
| 9719 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9720 | if (len > Columns - col - 1) |
| 9721 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9722 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9723 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9724 | col += len; |
| 9725 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9726 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9727 | |
| 9728 | /* Store the tab page number in TabPageIdxs[], so that |
| 9729 | * jump_to_mouse() knows where each one is. */ |
| 9730 | ++tabcount; |
| 9731 | while (scol < col) |
| 9732 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9733 | } |
| 9734 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9735 | if (use_sep_chars) |
| 9736 | c = '_'; |
| 9737 | else |
| 9738 | c = ' '; |
| 9739 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9740 | |
| 9741 | /* Put an "X" for closing the current tab if there are several. */ |
| 9742 | if (first_tabpage->tp_next != NULL) |
| 9743 | { |
| 9744 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 9745 | TabPageIdxs[Columns - 1] = -999; |
| 9746 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9747 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 9748 | |
| 9749 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 9750 | * set. */ |
| 9751 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9752 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9753 | |
| 9754 | /* |
| 9755 | * Get buffer name for "buf" into NameBuff[]. |
| 9756 | * Takes care of special buffer names and translates special characters. |
| 9757 | */ |
| 9758 | void |
| 9759 | get_trans_bufname(buf) |
| 9760 | buf_T *buf; |
| 9761 | { |
| 9762 | if (buf_spname(buf) != NULL) |
| 9763 | STRCPY(NameBuff, buf_spname(buf)); |
| 9764 | else |
| 9765 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 9766 | trans_characters(NameBuff, MAXPATHL); |
| 9767 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9768 | #endif |
| 9769 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9770 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 9771 | /* |
| 9772 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 9773 | */ |
| 9774 | static int |
| 9775 | fillchar_status(attr, is_curwin) |
| 9776 | int *attr; |
| 9777 | int is_curwin; |
| 9778 | { |
| 9779 | int fill; |
| 9780 | if (is_curwin) |
| 9781 | { |
| 9782 | *attr = hl_attr(HLF_S); |
| 9783 | fill = fill_stl; |
| 9784 | } |
| 9785 | else |
| 9786 | { |
| 9787 | *attr = hl_attr(HLF_SNC); |
| 9788 | fill = fill_stlnc; |
| 9789 | } |
| 9790 | /* Use fill when there is highlighting, and highlighting of current |
| 9791 | * window differs, or the fillchars differ, or this is not the |
| 9792 | * current window */ |
| 9793 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 9794 | || !is_curwin || firstwin == lastwin) |
| 9795 | || (fill_stl != fill_stlnc))) |
| 9796 | return fill; |
| 9797 | if (is_curwin) |
| 9798 | return '^'; |
| 9799 | return '='; |
| 9800 | } |
| 9801 | #endif |
| 9802 | |
| 9803 | #ifdef FEAT_VERTSPLIT |
| 9804 | /* |
| 9805 | * Get the character to use in a separator between vertically split windows. |
| 9806 | * Get its attributes in "*attr". |
| 9807 | */ |
| 9808 | static int |
| 9809 | fillchar_vsep(attr) |
| 9810 | int *attr; |
| 9811 | { |
| 9812 | *attr = hl_attr(HLF_C); |
| 9813 | if (*attr == 0 && fill_vert == ' ') |
| 9814 | return '|'; |
| 9815 | else |
| 9816 | return fill_vert; |
| 9817 | } |
| 9818 | #endif |
| 9819 | |
| 9820 | /* |
| 9821 | * Return TRUE if redrawing should currently be done. |
| 9822 | */ |
| 9823 | int |
| 9824 | redrawing() |
| 9825 | { |
| 9826 | return (!RedrawingDisabled |
| 9827 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 9828 | } |
| 9829 | |
| 9830 | /* |
| 9831 | * Return TRUE if printing messages should currently be done. |
| 9832 | */ |
| 9833 | int |
| 9834 | messaging() |
| 9835 | { |
| 9836 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 9837 | } |
| 9838 | |
| 9839 | /* |
| 9840 | * Show current status info in ruler and various other places |
| 9841 | * If always is FALSE, only show ruler if position has changed. |
| 9842 | */ |
| 9843 | void |
| 9844 | showruler(always) |
| 9845 | int always; |
| 9846 | { |
| 9847 | if (!always && !redrawing()) |
| 9848 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9849 | #ifdef FEAT_INS_EXPAND |
| 9850 | if (pum_visible()) |
| 9851 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9852 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9853 | /* Don't redraw right now, do it later. */ |
| 9854 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9855 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9856 | return; |
| 9857 | } |
| 9858 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9859 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 9860 | 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] | 9861 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 9862 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9863 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9864 | else |
| 9865 | #endif |
| 9866 | #ifdef FEAT_CMDL_INFO |
| 9867 | win_redr_ruler(curwin, always); |
| 9868 | #endif |
| 9869 | |
| 9870 | #ifdef FEAT_TITLE |
| 9871 | if (need_maketitle |
| 9872 | # ifdef FEAT_STL_OPT |
| 9873 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 9874 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 9875 | # endif |
| 9876 | ) |
| 9877 | maketitle(); |
| 9878 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 9879 | #ifdef FEAT_WINDOWS |
| 9880 | /* Redraw the tab pages line if needed. */ |
| 9881 | if (redraw_tabline) |
| 9882 | draw_tabline(); |
| 9883 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9884 | } |
| 9885 | |
| 9886 | #ifdef FEAT_CMDL_INFO |
| 9887 | static void |
| 9888 | win_redr_ruler(wp, always) |
| 9889 | win_T *wp; |
| 9890 | int always; |
| 9891 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 9892 | #define RULER_BUF_LEN 70 |
| 9893 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9894 | int row; |
| 9895 | int fillchar; |
| 9896 | int attr; |
| 9897 | int empty_line = FALSE; |
| 9898 | colnr_T virtcol; |
| 9899 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 9900 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9901 | int o; |
| 9902 | #ifdef FEAT_VERTSPLIT |
| 9903 | int this_ru_col; |
| 9904 | int off = 0; |
| 9905 | int width = Columns; |
| 9906 | # define WITH_OFF(x) x |
| 9907 | # define WITH_WIDTH(x) x |
| 9908 | #else |
| 9909 | # define WITH_OFF(x) 0 |
| 9910 | # define WITH_WIDTH(x) Columns |
| 9911 | # define this_ru_col ru_col |
| 9912 | #endif |
| 9913 | |
| 9914 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 9915 | if (!p_ru) |
| 9916 | return; |
| 9917 | |
| 9918 | /* |
| 9919 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 9920 | * after deleting lines, before cursor.lnum is corrected. |
| 9921 | */ |
| 9922 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 9923 | return; |
| 9924 | |
| 9925 | #ifdef FEAT_INS_EXPAND |
| 9926 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 9927 | * the (long) mode message. */ |
| 9928 | # ifdef FEAT_WINDOWS |
| 9929 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 9930 | # endif |
| 9931 | if (edit_submode != NULL) |
| 9932 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 9933 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 9934 | if (pum_visible()) |
| 9935 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9936 | #endif |
| 9937 | |
| 9938 | #ifdef FEAT_STL_OPT |
| 9939 | if (*p_ruf) |
| 9940 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9941 | int save_called_emsg = called_emsg; |
| 9942 | |
| 9943 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9944 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9945 | if (called_emsg) |
| 9946 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 9947 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9948 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9949 | return; |
| 9950 | } |
| 9951 | #endif |
| 9952 | |
| 9953 | /* |
| 9954 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 9955 | */ |
| 9956 | if (!(State & INSERT) |
| 9957 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 9958 | empty_line = TRUE; |
| 9959 | |
| 9960 | /* |
| 9961 | * Only draw the ruler when something changed. |
| 9962 | */ |
| 9963 | validate_virtcol_win(wp); |
| 9964 | if ( redraw_cmdline |
| 9965 | || always |
| 9966 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 9967 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 9968 | || wp->w_virtcol != wp->w_ru_virtcol |
| 9969 | #ifdef FEAT_VIRTUALEDIT |
| 9970 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 9971 | #endif |
| 9972 | || wp->w_topline != wp->w_ru_topline |
| 9973 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 9974 | #ifdef FEAT_DIFF |
| 9975 | || wp->w_topfill != wp->w_ru_topfill |
| 9976 | #endif |
| 9977 | || empty_line != wp->w_ru_empty) |
| 9978 | { |
| 9979 | cursor_off(); |
| 9980 | #ifdef FEAT_WINDOWS |
| 9981 | if (wp->w_status_height) |
| 9982 | { |
| 9983 | row = W_WINROW(wp) + wp->w_height; |
| 9984 | fillchar = fillchar_status(&attr, wp == curwin); |
| 9985 | # ifdef FEAT_VERTSPLIT |
| 9986 | off = W_WINCOL(wp); |
| 9987 | width = W_WIDTH(wp); |
| 9988 | # endif |
| 9989 | } |
| 9990 | else |
| 9991 | #endif |
| 9992 | { |
| 9993 | row = Rows - 1; |
| 9994 | fillchar = ' '; |
| 9995 | attr = 0; |
| 9996 | #ifdef FEAT_VERTSPLIT |
| 9997 | width = Columns; |
| 9998 | off = 0; |
| 9999 | #endif |
| 10000 | } |
| 10001 | |
| 10002 | /* In list mode virtcol needs to be recomputed */ |
| 10003 | virtcol = wp->w_virtcol; |
| 10004 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10005 | { |
| 10006 | wp->w_p_list = FALSE; |
| 10007 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10008 | wp->w_p_list = TRUE; |
| 10009 | } |
| 10010 | |
| 10011 | /* |
| 10012 | * Some sprintfs return the length, some return a pointer. |
| 10013 | * To avoid portability problems we use strlen() here. |
| 10014 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10015 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10016 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10017 | ? 0L |
| 10018 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10019 | len = STRLEN(buffer); |
| 10020 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10021 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10022 | (int)virtcol + 1); |
| 10023 | |
| 10024 | /* |
| 10025 | * Add a "50%" if there is room for it. |
| 10026 | * On the last line, don't print in the last column (scrolls the |
| 10027 | * screen up on some terminals). |
| 10028 | */ |
| 10029 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10030 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10031 | o = i + vim_strsize(buffer + i + 1); |
| 10032 | #ifdef FEAT_WINDOWS |
| 10033 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10034 | #endif |
| 10035 | ++o; |
| 10036 | #ifdef FEAT_VERTSPLIT |
| 10037 | this_ru_col = ru_col - (Columns - width); |
| 10038 | if (this_ru_col < 0) |
| 10039 | this_ru_col = 0; |
| 10040 | #endif |
| 10041 | /* Never use more than half the window/screen width, leave the other |
| 10042 | * half for the filename. */ |
| 10043 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10044 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10045 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10046 | { |
| 10047 | while (this_ru_col + o < WITH_WIDTH(width)) |
| 10048 | { |
| 10049 | #ifdef FEAT_MBYTE |
| 10050 | if (has_mbyte) |
| 10051 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10052 | else |
| 10053 | #endif |
| 10054 | buffer[i++] = fillchar; |
| 10055 | ++o; |
| 10056 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10057 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10058 | } |
| 10059 | /* Truncate at window boundary. */ |
| 10060 | #ifdef FEAT_MBYTE |
| 10061 | if (has_mbyte) |
| 10062 | { |
| 10063 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10064 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10065 | { |
| 10066 | o += (*mb_ptr2cells)(buffer + i); |
| 10067 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10068 | { |
| 10069 | buffer[i] = NUL; |
| 10070 | break; |
| 10071 | } |
| 10072 | } |
| 10073 | } |
| 10074 | else |
| 10075 | #endif |
| 10076 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10077 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10078 | |
| 10079 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10080 | i = redraw_cmdline; |
| 10081 | screen_fill(row, row + 1, |
| 10082 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10083 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10084 | fillchar, fillchar, attr); |
| 10085 | /* don't redraw the cmdline because of showing the ruler */ |
| 10086 | redraw_cmdline = i; |
| 10087 | wp->w_ru_cursor = wp->w_cursor; |
| 10088 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10089 | wp->w_ru_empty = empty_line; |
| 10090 | wp->w_ru_topline = wp->w_topline; |
| 10091 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10092 | #ifdef FEAT_DIFF |
| 10093 | wp->w_ru_topfill = wp->w_topfill; |
| 10094 | #endif |
| 10095 | } |
| 10096 | } |
| 10097 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10098 | |
| 10099 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10100 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10101 | * Return the width of the 'number' and 'relativenumber' column. |
| 10102 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10103 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10104 | */ |
| 10105 | int |
| 10106 | number_width(wp) |
| 10107 | win_T *wp; |
| 10108 | { |
| 10109 | int n; |
| 10110 | linenr_T lnum; |
| 10111 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10112 | if (wp->w_p_nu) |
| 10113 | /* 'number' */ |
| 10114 | lnum = wp->w_buffer->b_ml.ml_line_count; |
| 10115 | else |
| 10116 | /* 'relativenumber' */ |
| 10117 | lnum = wp->w_height; |
| 10118 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10119 | if (lnum == wp->w_nrwidth_line_count) |
| 10120 | return wp->w_nrwidth_width; |
| 10121 | wp->w_nrwidth_line_count = lnum; |
| 10122 | |
| 10123 | n = 0; |
| 10124 | do |
| 10125 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10126 | lnum /= 10; |
| 10127 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10128 | } while (lnum > 0); |
| 10129 | |
| 10130 | /* 'numberwidth' gives the minimal width plus one */ |
| 10131 | if (n < wp->w_p_nuw - 1) |
| 10132 | n = wp->w_p_nuw - 1; |
| 10133 | |
| 10134 | wp->w_nrwidth_width = n; |
| 10135 | return n; |
| 10136 | } |
| 10137 | #endif |