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 | |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 92 | #define MB_FILLER_CHAR '<' /* character used when a double-width character |
| 93 | * doesn't fit. */ |
| 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | /* |
| 96 | * The attributes that are actually active for writing to the screen. |
| 97 | */ |
| 98 | static int screen_attr = 0; |
| 99 | |
| 100 | /* |
| 101 | * Positioning the cursor is reduced by remembering the last position. |
| 102 | * Mostly used by windgoto() and screen_char(). |
| 103 | */ |
| 104 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 105 | |
| 106 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | #ifdef FEAT_FOLDING |
| 111 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
| 112 | #endif |
| 113 | |
| 114 | /* |
| 115 | * Buffer for one screen line (characters and attributes). |
| 116 | */ |
| 117 | static schar_T *current_ScreenLine; |
| 118 | |
| 119 | static void win_update __ARGS((win_T *wp)); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 120 | 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] | 121 | #ifdef FEAT_FOLDING |
| 122 | static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); |
| 123 | static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); |
| 124 | static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); |
| 125 | #endif |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 126 | 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] | 127 | static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
| 128 | #ifdef FEAT_RIGHTLEFT |
| 129 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); |
| 130 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 131 | #else |
| 132 | static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); |
| 133 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 134 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 135 | #ifdef FEAT_VERTSPLIT |
| 136 | static void draw_vsep_win __ARGS((win_T *wp, int row)); |
| 137 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 138 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 139 | static void redraw_custom_statusline __ARGS((win_T *wp)); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 140 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 141 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 142 | #define SEARCH_HL_PRIORITY 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | static void start_search_hl __ARGS((void)); |
| 144 | static void end_search_hl __ARGS((void)); |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 145 | static void init_search_hl __ARGS((win_T *wp)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 146 | static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
| 147 | static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); |
| 148 | #endif |
| 149 | static void screen_start_highlight __ARGS((int attr)); |
| 150 | static void screen_char __ARGS((unsigned off, int row, int col)); |
| 151 | #ifdef FEAT_MBYTE |
| 152 | static void screen_char_2 __ARGS((unsigned off, int row, int col)); |
| 153 | #endif |
| 154 | static void screenclear2 __ARGS((void)); |
| 155 | static void lineclear __ARGS((unsigned off, int width)); |
| 156 | static void lineinvalid __ARGS((unsigned off, int width)); |
| 157 | #ifdef FEAT_VERTSPLIT |
| 158 | static void linecopy __ARGS((int to, int from, win_T *wp)); |
| 159 | static void redraw_block __ARGS((int row, int end, win_T *wp)); |
| 160 | #endif |
| 161 | static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); |
| 162 | static void win_rest_invalid __ARGS((win_T *wp)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 163 | static void msg_pos_mode __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 164 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 165 | static void draw_tabline __ARGS((void)); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 166 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 167 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 168 | static int fillchar_status __ARGS((int *attr, int is_curwin)); |
| 169 | #endif |
| 170 | #ifdef FEAT_VERTSPLIT |
| 171 | static int fillchar_vsep __ARGS((int *attr)); |
| 172 | #endif |
| 173 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 174 | static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 175 | #endif |
| 176 | #ifdef FEAT_CMDL_INFO |
| 177 | static void win_redr_ruler __ARGS((win_T *wp, int always)); |
| 178 | #endif |
| 179 | |
| 180 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 181 | /* Ugly global: overrule attribute used by screen_char() */ |
| 182 | static int screen_char_attr = 0; |
| 183 | #endif |
| 184 | |
| 185 | /* |
| 186 | * Redraw the current window later, with update_screen(type). |
| 187 | * Set must_redraw only if not already set to a higher value. |
| 188 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 189 | */ |
| 190 | void |
| 191 | redraw_later(type) |
| 192 | int type; |
| 193 | { |
| 194 | redraw_win_later(curwin, type); |
| 195 | } |
| 196 | |
| 197 | void |
| 198 | redraw_win_later(wp, type) |
| 199 | win_T *wp; |
| 200 | int type; |
| 201 | { |
| 202 | if (wp->w_redr_type < type) |
| 203 | { |
| 204 | wp->w_redr_type = type; |
| 205 | if (type >= NOT_VALID) |
| 206 | wp->w_lines_valid = 0; |
| 207 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 208 | must_redraw = type; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 214 | * after executing a shell command that messes up the screen. |
| 215 | */ |
| 216 | void |
| 217 | redraw_later_clear() |
| 218 | { |
| 219 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 220 | #ifdef FEAT_GUI |
| 221 | if (gui.in_use) |
| 222 | /* Use a code that will reset gui.highlight_mask in |
| 223 | * gui_stop_highlight(). */ |
| 224 | screen_attr = HL_ALL + 1; |
| 225 | else |
| 226 | #endif |
| 227 | /* Use attributes that is very unlikely to appear in text. */ |
| 228 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Mark all windows to be redrawn later. |
| 233 | */ |
| 234 | void |
| 235 | redraw_all_later(type) |
| 236 | int type; |
| 237 | { |
| 238 | win_T *wp; |
| 239 | |
| 240 | FOR_ALL_WINDOWS(wp) |
| 241 | { |
| 242 | redraw_win_later(wp, type); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 247 | * 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] | 248 | */ |
| 249 | void |
| 250 | redraw_curbuf_later(type) |
| 251 | int type; |
| 252 | { |
| 253 | redraw_buf_later(curbuf, type); |
| 254 | } |
| 255 | |
| 256 | void |
| 257 | redraw_buf_later(buf, type) |
| 258 | buf_T *buf; |
| 259 | int type; |
| 260 | { |
| 261 | win_T *wp; |
| 262 | |
| 263 | FOR_ALL_WINDOWS(wp) |
| 264 | { |
| 265 | if (wp->w_buffer == buf) |
| 266 | redraw_win_later(wp, type); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Changed something in the current window, at buffer line "lnum", that |
| 272 | * requires that line and possibly other lines to be redrawn. |
| 273 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 274 | * Used to remove the "$" from a change command. |
| 275 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 276 | * may become invalid and the whole window will have to be redrawn. |
| 277 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 278 | void |
| 279 | redrawWinline(lnum, invalid) |
| 280 | linenr_T lnum; |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 281 | int invalid UNUSED; /* window line height is invalid now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 282 | { |
| 283 | #ifdef FEAT_FOLDING |
| 284 | int i; |
| 285 | #endif |
| 286 | |
| 287 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 288 | curwin->w_redraw_top = lnum; |
| 289 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 290 | curwin->w_redraw_bot = lnum; |
| 291 | redraw_later(VALID); |
| 292 | |
| 293 | #ifdef FEAT_FOLDING |
| 294 | if (invalid) |
| 295 | { |
| 296 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 297 | i = find_wl_entry(curwin, lnum); |
| 298 | if (i >= 0) |
| 299 | curwin->w_lines[i].wl_valid = FALSE; |
| 300 | } |
| 301 | #endif |
| 302 | } |
| 303 | |
Bram Moolenaar | 9d6650f | 2010-06-06 23:04:47 +0200 | [diff] [blame] | 304 | #if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \ |
Bram Moolenaar | fd3e5dc | 2010-05-30 19:00:15 +0200 | [diff] [blame] | 305 | (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 306 | /* |
| 307 | * update all windows that are editing the current buffer |
| 308 | */ |
| 309 | void |
| 310 | update_curbuf(type) |
| 311 | int type; |
| 312 | { |
| 313 | redraw_curbuf_later(type); |
| 314 | update_screen(type); |
| 315 | } |
Bram Moolenaar | fd3e5dc | 2010-05-30 19:00:15 +0200 | [diff] [blame] | 316 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 317 | |
| 318 | /* |
| 319 | * update_screen() |
| 320 | * |
| 321 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 322 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 323 | */ |
| 324 | void |
| 325 | update_screen(type) |
| 326 | int type; |
| 327 | { |
| 328 | win_T *wp; |
| 329 | static int did_intro = FALSE; |
| 330 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 331 | int did_one; |
| 332 | #endif |
| 333 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 334 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 335 | if (!screen_valid(TRUE)) |
| 336 | return; |
| 337 | |
| 338 | if (must_redraw) |
| 339 | { |
| 340 | if (type < must_redraw) /* use maximal type */ |
| 341 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 342 | |
| 343 | /* must_redraw is reset here, so that when we run into some weird |
| 344 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 345 | * scrolling), or update_topline() in win_update() will cause a |
| 346 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 347 | must_redraw = 0; |
| 348 | } |
| 349 | |
| 350 | /* Need to update w_lines[]. */ |
| 351 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 352 | type = NOT_VALID; |
| 353 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 354 | /* Postpone the redrawing when it's not needed and when being called |
| 355 | * recursively. */ |
| 356 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 357 | { |
| 358 | redraw_later(type); /* remember type for next time */ |
| 359 | must_redraw = type; |
| 360 | if (type > INVERTED_ALL) |
| 361 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | updating_screen = TRUE; |
| 366 | #ifdef FEAT_SYN_HL |
| 367 | ++display_tick; /* let syntax code know we're in a next round of |
| 368 | * display updating */ |
| 369 | #endif |
| 370 | |
| 371 | /* |
| 372 | * if the screen was scrolled up when displaying a message, scroll it down |
| 373 | */ |
| 374 | if (msg_scrolled) |
| 375 | { |
| 376 | clear_cmdline = TRUE; |
| 377 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 378 | type = CLEAR; |
| 379 | else if (type != CLEAR) |
| 380 | { |
| 381 | check_for_delay(FALSE); |
| 382 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 383 | type = CLEAR; |
| 384 | FOR_ALL_WINDOWS(wp) |
| 385 | { |
| 386 | if (W_WINROW(wp) < msg_scrolled) |
| 387 | { |
| 388 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 389 | && wp->w_redr_type < REDRAW_TOP |
| 390 | && wp->w_lines_valid > 0 |
| 391 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 392 | { |
| 393 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 394 | wp->w_redr_type = REDRAW_TOP; |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | wp->w_redr_type = NOT_VALID; |
| 399 | #ifdef FEAT_WINDOWS |
| 400 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 401 | <= msg_scrolled) |
| 402 | wp->w_redr_status = TRUE; |
| 403 | #endif |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 408 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 409 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 410 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 411 | } |
| 412 | msg_scrolled = 0; |
| 413 | need_wait_return = FALSE; |
| 414 | } |
| 415 | |
| 416 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 417 | compute_cmdrow(); |
| 418 | |
| 419 | /* Check for changed highlighting */ |
| 420 | if (need_highlight_changed) |
| 421 | highlight_changed(); |
| 422 | |
| 423 | if (type == CLEAR) /* first clear screen */ |
| 424 | { |
| 425 | screenclear(); /* will reset clear_cmdline */ |
| 426 | type = NOT_VALID; |
| 427 | } |
| 428 | |
| 429 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 430 | check_for_delay(FALSE); |
| 431 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 432 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 433 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 434 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 435 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 436 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 437 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 438 | curwin->w_redr_type = NOT_VALID; |
| 439 | #endif |
| 440 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 441 | /* |
| 442 | * Only start redrawing if there is really something to do. |
| 443 | */ |
| 444 | if (type == INVERTED) |
| 445 | update_curswant(); |
| 446 | if (curwin->w_redr_type < type |
| 447 | && !((type == VALID |
| 448 | && curwin->w_lines[0].wl_valid |
| 449 | #ifdef FEAT_DIFF |
| 450 | && curwin->w_topfill == curwin->w_old_topfill |
| 451 | && curwin->w_botfill == curwin->w_old_botfill |
| 452 | #endif |
| 453 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
| 454 | #ifdef FEAT_VISUAL |
| 455 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 456 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 457 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 458 | && curwin->w_old_visual_mode == VIsual_mode |
| 459 | && (curwin->w_valid & VALID_VIRTCOL) |
| 460 | && curwin->w_old_curswant == curwin->w_curswant) |
| 461 | #endif |
| 462 | )) |
| 463 | curwin->w_redr_type = type; |
| 464 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 465 | #ifdef FEAT_WINDOWS |
| 466 | /* Redraw the tab pages line if needed. */ |
| 467 | if (redraw_tabline || type >= NOT_VALID) |
| 468 | draw_tabline(); |
| 469 | #endif |
| 470 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 471 | #ifdef FEAT_SYN_HL |
| 472 | /* |
| 473 | * Correct stored syntax highlighting info for changes in each displayed |
| 474 | * buffer. Each buffer must only be done once. |
| 475 | */ |
| 476 | FOR_ALL_WINDOWS(wp) |
| 477 | { |
| 478 | if (wp->w_buffer->b_mod_set) |
| 479 | { |
| 480 | # ifdef FEAT_WINDOWS |
| 481 | win_T *wwp; |
| 482 | |
| 483 | /* Check if we already did this buffer. */ |
| 484 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 485 | if (wwp->w_buffer == wp->w_buffer) |
| 486 | break; |
| 487 | # endif |
| 488 | if ( |
| 489 | # ifdef FEAT_WINDOWS |
| 490 | wwp == wp && |
| 491 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 492 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 493 | syn_stack_apply_changes(wp->w_buffer); |
| 494 | } |
| 495 | } |
| 496 | #endif |
| 497 | |
| 498 | /* |
| 499 | * Go from top to bottom through the windows, redrawing the ones that need |
| 500 | * it. |
| 501 | */ |
| 502 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 503 | did_one = FALSE; |
| 504 | #endif |
| 505 | #ifdef FEAT_SEARCH_EXTRA |
| 506 | search_hl.rm.regprog = NULL; |
| 507 | #endif |
| 508 | FOR_ALL_WINDOWS(wp) |
| 509 | { |
| 510 | if (wp->w_redr_type != 0) |
| 511 | { |
| 512 | cursor_off(); |
| 513 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 514 | if (!did_one) |
| 515 | { |
| 516 | did_one = TRUE; |
| 517 | # ifdef FEAT_SEARCH_EXTRA |
| 518 | start_search_hl(); |
| 519 | # endif |
| 520 | # ifdef FEAT_CLIPBOARD |
| 521 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 522 | if (clip_star.available && clip_isautosel_star()) |
| 523 | clip_update_selection(&clip_star); |
| 524 | if (clip_plus.available && clip_isautosel_plus()) |
| 525 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 526 | # endif |
| 527 | #ifdef FEAT_GUI |
| 528 | /* Remove the cursor before starting to do anything, because |
| 529 | * scrolling may make it difficult to redraw the text under |
| 530 | * it. */ |
| 531 | if (gui.in_use) |
| 532 | gui_undraw_cursor(); |
| 533 | #endif |
| 534 | } |
| 535 | #endif |
| 536 | win_update(wp); |
| 537 | } |
| 538 | |
| 539 | #ifdef FEAT_WINDOWS |
| 540 | /* redraw status line after the window to minimize cursor movement */ |
| 541 | if (wp->w_redr_status) |
| 542 | { |
| 543 | cursor_off(); |
| 544 | win_redr_status(wp); |
| 545 | } |
| 546 | #endif |
| 547 | } |
| 548 | #if defined(FEAT_SEARCH_EXTRA) |
| 549 | end_search_hl(); |
| 550 | #endif |
| 551 | |
| 552 | #ifdef FEAT_WINDOWS |
| 553 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 554 | * than going through all buffers (there could be many buffers). */ |
| 555 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 556 | wp->w_buffer->b_mod_set = FALSE; |
| 557 | #else |
| 558 | curbuf->b_mod_set = FALSE; |
| 559 | #endif |
| 560 | |
| 561 | updating_screen = FALSE; |
| 562 | #ifdef FEAT_GUI |
| 563 | gui_may_resize_shell(); |
| 564 | #endif |
| 565 | |
| 566 | /* Clear or redraw the command line. Done last, because scrolling may |
| 567 | * mess up the command line. */ |
| 568 | if (clear_cmdline || redraw_cmdline) |
| 569 | showmode(); |
| 570 | |
| 571 | /* May put up an introductory message when not editing a file */ |
| 572 | if (!did_intro && bufempty() |
| 573 | && curbuf->b_fname == NULL |
| 574 | #ifdef FEAT_WINDOWS |
| 575 | && firstwin->w_next == NULL |
| 576 | #endif |
| 577 | && vim_strchr(p_shm, SHM_INTRO) == NULL) |
| 578 | intro_message(FALSE); |
| 579 | did_intro = TRUE; |
| 580 | |
| 581 | #ifdef FEAT_GUI |
| 582 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 583 | * done. */ |
| 584 | if (gui.in_use) |
| 585 | { |
| 586 | out_flush(); /* required before updating the cursor */ |
| 587 | if (did_one) |
| 588 | gui_update_cursor(FALSE, FALSE); |
| 589 | gui_update_scrollbars(FALSE); |
| 590 | } |
| 591 | #endif |
| 592 | } |
| 593 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 594 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 595 | /* |
| 596 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 597 | * to the 'concealcursor' option. |
| 598 | */ |
| 599 | int |
| 600 | conceal_cursor_line(wp) |
| 601 | win_T *wp; |
| 602 | { |
| 603 | int c; |
| 604 | |
| 605 | if (*wp->w_p_cocu == NUL) |
| 606 | return FALSE; |
| 607 | if (get_real_state() & VISUAL) |
| 608 | c = 'v'; |
| 609 | else if (State & INSERT) |
| 610 | c = 'i'; |
| 611 | else if (State & NORMAL) |
| 612 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 613 | else if (State & CMDLINE) |
| 614 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 615 | else |
| 616 | return FALSE; |
| 617 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 618 | } |
| 619 | |
| 620 | /* |
| 621 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 622 | */ |
| 623 | void |
Bram Moolenaar | 8e46927 | 2010-07-28 19:38:16 +0200 | [diff] [blame] | 624 | conceal_check_cursur_line() |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 625 | { |
| 626 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 627 | { |
| 628 | need_cursor_line_redraw = TRUE; |
| 629 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 630 | * without concealing. */ |
| 631 | curs_columns(TRUE); |
| 632 | } |
| 633 | } |
| 634 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 635 | void |
| 636 | update_single_line(wp, lnum) |
| 637 | win_T *wp; |
| 638 | linenr_T lnum; |
| 639 | { |
| 640 | int row; |
| 641 | int j; |
| 642 | |
| 643 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 644 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 645 | { |
| 646 | # ifdef FEAT_GUI |
| 647 | /* Remove the cursor before starting to do anything, because scrolling |
| 648 | * may make it difficult to redraw the text under it. */ |
| 649 | if (gui.in_use) |
| 650 | gui_undraw_cursor(); |
| 651 | # endif |
| 652 | row = 0; |
| 653 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 654 | { |
| 655 | if (lnum == wp->w_lines[j].wl_lnum) |
| 656 | { |
| 657 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 658 | # ifdef FEAT_SEARCH_EXTRA |
| 659 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 660 | start_search_hl(); |
| 661 | prepare_search_hl(wp, lnum); |
| 662 | # endif |
| 663 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 664 | # if defined(FEAT_SEARCH_EXTRA) |
| 665 | end_search_hl(); |
| 666 | # endif |
| 667 | break; |
| 668 | } |
| 669 | row += wp->w_lines[j].wl_size; |
| 670 | } |
| 671 | # ifdef FEAT_GUI |
| 672 | /* Redraw the cursor */ |
| 673 | if (gui.in_use) |
| 674 | { |
| 675 | out_flush(); /* required before updating the cursor */ |
| 676 | gui_update_cursor(FALSE, FALSE); |
| 677 | } |
| 678 | # endif |
| 679 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 680 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 681 | } |
| 682 | #endif |
| 683 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 684 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
| 685 | static void update_prepare __ARGS((void)); |
| 686 | static void update_finish __ARGS((void)); |
| 687 | |
| 688 | /* |
| 689 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 690 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 691 | */ |
| 692 | static void |
| 693 | update_prepare() |
| 694 | { |
| 695 | cursor_off(); |
| 696 | updating_screen = TRUE; |
| 697 | #ifdef FEAT_GUI |
| 698 | /* Remove the cursor before starting to do anything, because scrolling may |
| 699 | * make it difficult to redraw the text under it. */ |
| 700 | if (gui.in_use) |
| 701 | gui_undraw_cursor(); |
| 702 | #endif |
| 703 | #ifdef FEAT_SEARCH_EXTRA |
| 704 | start_search_hl(); |
| 705 | #endif |
| 706 | } |
| 707 | |
| 708 | /* |
| 709 | * Finish updating one or more windows. |
| 710 | */ |
| 711 | static void |
| 712 | update_finish() |
| 713 | { |
| 714 | if (redraw_cmdline) |
| 715 | showmode(); |
| 716 | |
| 717 | # ifdef FEAT_SEARCH_EXTRA |
| 718 | end_search_hl(); |
| 719 | # endif |
| 720 | |
| 721 | updating_screen = FALSE; |
| 722 | |
| 723 | # ifdef FEAT_GUI |
| 724 | gui_may_resize_shell(); |
| 725 | |
| 726 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 727 | * done. */ |
| 728 | if (gui.in_use) |
| 729 | { |
| 730 | out_flush(); /* required before updating the cursor */ |
| 731 | gui_update_cursor(FALSE, FALSE); |
| 732 | gui_update_scrollbars(FALSE); |
| 733 | } |
| 734 | # endif |
| 735 | } |
| 736 | #endif |
| 737 | |
| 738 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 739 | void |
| 740 | update_debug_sign(buf, lnum) |
| 741 | buf_T *buf; |
| 742 | linenr_T lnum; |
| 743 | { |
| 744 | win_T *wp; |
| 745 | int doit = FALSE; |
| 746 | |
| 747 | # ifdef FEAT_FOLDING |
| 748 | win_foldinfo.fi_level = 0; |
| 749 | # endif |
| 750 | |
| 751 | /* update/delete a specific mark */ |
| 752 | FOR_ALL_WINDOWS(wp) |
| 753 | { |
| 754 | if (buf != NULL && lnum > 0) |
| 755 | { |
| 756 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 757 | && lnum < wp->w_botline) |
| 758 | { |
| 759 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 760 | wp->w_redraw_top = lnum; |
| 761 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 762 | wp->w_redraw_bot = lnum; |
| 763 | redraw_win_later(wp, VALID); |
| 764 | } |
| 765 | } |
| 766 | else |
| 767 | redraw_win_later(wp, VALID); |
| 768 | if (wp->w_redr_type != 0) |
| 769 | doit = TRUE; |
| 770 | } |
| 771 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 772 | /* Return when there is nothing to do, screen updating is already |
| 773 | * happening (recursive call) or still starting up. */ |
| 774 | if (!doit || updating_screen |
| 775 | #ifdef FEAT_GUI |
| 776 | || gui.starting |
| 777 | #endif |
| 778 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 779 | return; |
| 780 | |
| 781 | /* update all windows that need updating */ |
| 782 | update_prepare(); |
| 783 | |
| 784 | # ifdef FEAT_WINDOWS |
| 785 | for (wp = firstwin; wp; wp = wp->w_next) |
| 786 | { |
| 787 | if (wp->w_redr_type != 0) |
| 788 | win_update(wp); |
| 789 | if (wp->w_redr_status) |
| 790 | win_redr_status(wp); |
| 791 | } |
| 792 | # else |
| 793 | if (curwin->w_redr_type != 0) |
| 794 | win_update(curwin); |
| 795 | # endif |
| 796 | |
| 797 | update_finish(); |
| 798 | } |
| 799 | #endif |
| 800 | |
| 801 | |
| 802 | #if defined(FEAT_GUI) || defined(PROTO) |
| 803 | /* |
| 804 | * Update a single window, its status line and maybe the command line msg. |
| 805 | * Used for the GUI scrollbar. |
| 806 | */ |
| 807 | void |
| 808 | updateWindow(wp) |
| 809 | win_T *wp; |
| 810 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 811 | /* return if already busy updating */ |
| 812 | if (updating_screen) |
| 813 | return; |
| 814 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 815 | update_prepare(); |
| 816 | |
| 817 | #ifdef FEAT_CLIPBOARD |
| 818 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 819 | if (clip_star.available && clip_isautosel_star()) |
| 820 | clip_update_selection(&clip_star); |
| 821 | if (clip_plus.available && clip_isautosel_plus()) |
| 822 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 823 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 824 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 825 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 826 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 827 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 828 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 829 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 830 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 831 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 832 | if (wp->w_redr_status |
| 833 | # ifdef FEAT_CMDL_INFO |
| 834 | || p_ru |
| 835 | # endif |
| 836 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 837 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 838 | # endif |
| 839 | ) |
| 840 | win_redr_status(wp); |
| 841 | #endif |
| 842 | |
| 843 | update_finish(); |
| 844 | } |
| 845 | #endif |
| 846 | |
| 847 | /* |
| 848 | * Update a single window. |
| 849 | * |
| 850 | * This may cause the windows below it also to be redrawn (when clearing the |
| 851 | * screen or scrolling lines). |
| 852 | * |
| 853 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 854 | * implies the one below it. |
| 855 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 856 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 857 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 858 | * INVERTED redraw the changed part of the Visual area |
| 859 | * INVERTED_ALL redraw the whole Visual area |
| 860 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 861 | * 2. update lines at the top when scrolled down |
| 862 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 863 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 864 | * b_mod_top and b_mod_bot. |
| 865 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 866 | * wp->w_redraw_top and wp->w_redr_bot. |
| 867 | * - continue redrawing when syntax status is invalid. |
| 868 | * 4. if scrolled up, update lines at the bottom. |
| 869 | * This results in three areas that may need updating: |
| 870 | * top: from first row to top_end (when scrolled down) |
| 871 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 872 | * bot: from bot_start to last row (when scrolled up) |
| 873 | */ |
| 874 | static void |
| 875 | win_update(wp) |
| 876 | win_T *wp; |
| 877 | { |
| 878 | buf_T *buf = wp->w_buffer; |
| 879 | int type; |
| 880 | int top_end = 0; /* Below last row of the top area that needs |
| 881 | updating. 0 when no top area updating. */ |
| 882 | int mid_start = 999;/* first row of the mid area that needs |
| 883 | updating. 999 when no mid area updating. */ |
| 884 | int mid_end = 0; /* Below last row of the mid area that needs |
| 885 | updating. 0 when no mid area updating. */ |
| 886 | int bot_start = 999;/* first row of the bot area that needs |
| 887 | updating. 999 when no bot area updating */ |
| 888 | #ifdef FEAT_VISUAL |
| 889 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 890 | w_topline got smaller a bit */ |
| 891 | #endif |
| 892 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 893 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 894 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 895 | #endif |
| 896 | |
| 897 | int row; /* current window row to display */ |
| 898 | linenr_T lnum; /* current buffer lnum to display */ |
| 899 | int idx; /* current index in w_lines[] */ |
| 900 | int srow; /* starting row of the current line */ |
| 901 | |
| 902 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 903 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 904 | int i; |
| 905 | long j; |
| 906 | static int recursive = FALSE; /* being called recursively */ |
| 907 | int old_botline = wp->w_botline; |
| 908 | #ifdef FEAT_FOLDING |
| 909 | long fold_count; |
| 910 | #endif |
| 911 | #ifdef FEAT_SYN_HL |
| 912 | /* remember what happened to the previous line, to know if |
| 913 | * check_visual_highlight() can be used */ |
| 914 | #define DID_NONE 1 /* didn't update a line */ |
| 915 | #define DID_LINE 2 /* updated a normal line */ |
| 916 | #define DID_FOLD 3 /* updated a folded line */ |
| 917 | int did_update = DID_NONE; |
| 918 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 919 | #endif |
| 920 | linenr_T mod_top = 0; |
| 921 | linenr_T mod_bot = 0; |
| 922 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 923 | int save_got_int; |
| 924 | #endif |
| 925 | |
| 926 | type = wp->w_redr_type; |
| 927 | |
| 928 | if (type == NOT_VALID) |
| 929 | { |
| 930 | #ifdef FEAT_WINDOWS |
| 931 | wp->w_redr_status = TRUE; |
| 932 | #endif |
| 933 | wp->w_lines_valid = 0; |
| 934 | } |
| 935 | |
| 936 | /* Window is zero-height: nothing to draw. */ |
| 937 | if (wp->w_height == 0) |
| 938 | { |
| 939 | wp->w_redr_type = 0; |
| 940 | return; |
| 941 | } |
| 942 | |
| 943 | #ifdef FEAT_VERTSPLIT |
| 944 | /* Window is zero-width: Only need to draw the separator. */ |
| 945 | if (wp->w_width == 0) |
| 946 | { |
| 947 | /* draw the vertical separator right of this window */ |
| 948 | draw_vsep_win(wp, 0); |
| 949 | wp->w_redr_type = 0; |
| 950 | return; |
| 951 | } |
| 952 | #endif |
| 953 | |
| 954 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 955 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 956 | #endif |
| 957 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 958 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 959 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 960 | * changes. */ |
| 961 | 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] | 962 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 963 | { |
| 964 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 965 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 966 | } |
| 967 | else |
| 968 | #endif |
| 969 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 970 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 971 | { |
| 972 | /* |
| 973 | * When there are both inserted/deleted lines and specific lines to be |
| 974 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 975 | * everything (only happens when redrawing is off for while). |
| 976 | */ |
| 977 | type = NOT_VALID; |
| 978 | } |
| 979 | else |
| 980 | { |
| 981 | /* |
| 982 | * Set mod_top to the first line that needs displaying because of |
| 983 | * changes. Set mod_bot to the first line after the changes. |
| 984 | */ |
| 985 | mod_top = wp->w_redraw_top; |
| 986 | if (wp->w_redraw_bot != 0) |
| 987 | mod_bot = wp->w_redraw_bot + 1; |
| 988 | else |
| 989 | mod_bot = 0; |
| 990 | wp->w_redraw_top = 0; /* reset for next time */ |
| 991 | wp->w_redraw_bot = 0; |
| 992 | if (buf->b_mod_set) |
| 993 | { |
| 994 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 995 | { |
| 996 | mod_top = buf->b_mod_top; |
| 997 | #ifdef FEAT_SYN_HL |
| 998 | /* Need to redraw lines above the change that may be included |
| 999 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1000 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1001 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1002 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1003 | if (mod_top < 1) |
| 1004 | mod_top = 1; |
| 1005 | } |
| 1006 | #endif |
| 1007 | } |
| 1008 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1009 | mod_bot = buf->b_mod_bot; |
| 1010 | |
| 1011 | #ifdef FEAT_SEARCH_EXTRA |
| 1012 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1013 | * change in one line may make the Search highlighting in a |
| 1014 | * previous line invalid. Simple solution: redraw all visible |
| 1015 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1016 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1017 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1018 | if (search_hl.rm.regprog != NULL |
| 1019 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1020 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1021 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1022 | { |
| 1023 | cur = wp->w_match_head; |
| 1024 | while (cur != NULL) |
| 1025 | { |
| 1026 | if (cur->match.regprog != NULL |
| 1027 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1028 | { |
| 1029 | top_to_mod = TRUE; |
| 1030 | break; |
| 1031 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1032 | cur = cur->next; |
| 1033 | } |
| 1034 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1035 | #endif |
| 1036 | } |
| 1037 | #ifdef FEAT_FOLDING |
| 1038 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1039 | { |
| 1040 | linenr_T lnumt, lnumb; |
| 1041 | |
| 1042 | /* |
| 1043 | * A change in a line can cause lines above it to become folded or |
| 1044 | * unfolded. Find the top most buffer line that may be affected. |
| 1045 | * If the line was previously folded and displayed, get the first |
| 1046 | * line of that fold. If the line is folded now, get the first |
| 1047 | * folded line. Use the minimum of these two. |
| 1048 | */ |
| 1049 | |
| 1050 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1051 | * the line below it. If there is no valid entry, use w_topline. |
| 1052 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1053 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1054 | lnumt = wp->w_topline; |
| 1055 | lnumb = MAXLNUM; |
| 1056 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1057 | if (wp->w_lines[i].wl_valid) |
| 1058 | { |
| 1059 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1060 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1061 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1062 | { |
| 1063 | lnumb = wp->w_lines[i].wl_lnum; |
| 1064 | /* When there is a fold column it might need updating |
| 1065 | * in the next line ("J" just above an open fold). */ |
| 1066 | if (wp->w_p_fdc > 0) |
| 1067 | ++lnumb; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1072 | if (mod_top > lnumt) |
| 1073 | mod_top = lnumt; |
| 1074 | |
| 1075 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1076 | --mod_bot; |
| 1077 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1078 | ++mod_bot; |
| 1079 | if (mod_bot < lnumb) |
| 1080 | mod_bot = lnumb; |
| 1081 | } |
| 1082 | #endif |
| 1083 | |
| 1084 | /* When a change starts above w_topline and the end is below |
| 1085 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1086 | * If the end of the change is above w_topline: do like no change was |
| 1087 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1088 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1089 | { |
| 1090 | if (mod_bot > wp->w_topline) |
| 1091 | mod_top = wp->w_topline; |
| 1092 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1093 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1094 | top_end = 1; |
| 1095 | #endif |
| 1096 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* When line numbers are displayed need to redraw all lines below |
| 1099 | * inserted/deleted lines. */ |
| 1100 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1101 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /* |
| 1105 | * When only displaying the lines at the top, set top_end. Used when |
| 1106 | * window has scrolled down for msg_scrolled. |
| 1107 | */ |
| 1108 | if (type == REDRAW_TOP) |
| 1109 | { |
| 1110 | j = 0; |
| 1111 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1112 | { |
| 1113 | j += wp->w_lines[i].wl_size; |
| 1114 | if (j >= wp->w_upd_rows) |
| 1115 | { |
| 1116 | top_end = j; |
| 1117 | break; |
| 1118 | } |
| 1119 | } |
| 1120 | if (top_end == 0) |
| 1121 | /* not found (cannot happen?): redraw everything */ |
| 1122 | type = NOT_VALID; |
| 1123 | else |
| 1124 | /* top area defined, the rest is VALID */ |
| 1125 | type = VALID; |
| 1126 | } |
| 1127 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1128 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1129 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1130 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1131 | * called. */ |
| 1132 | if (screen_cleared) |
| 1133 | screen_cleared = MAYBE; |
| 1134 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1135 | /* |
| 1136 | * If there are no changes on the screen that require a complete redraw, |
| 1137 | * handle three cases: |
| 1138 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1139 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1140 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1141 | * w_lines[] that needs updating. |
| 1142 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1143 | if ((type == VALID || type == SOME_VALID |
| 1144 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1145 | #ifdef FEAT_DIFF |
| 1146 | && !wp->w_botfill && !wp->w_old_botfill |
| 1147 | #endif |
| 1148 | ) |
| 1149 | { |
| 1150 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1151 | { |
| 1152 | /* |
| 1153 | * w_topline is the first changed line, the scrolling will be done |
| 1154 | * further down. |
| 1155 | */ |
| 1156 | } |
| 1157 | else if (wp->w_lines[0].wl_valid |
| 1158 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1159 | #ifdef FEAT_DIFF |
| 1160 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1161 | && wp->w_topfill > wp->w_old_topfill) |
| 1162 | #endif |
| 1163 | )) |
| 1164 | { |
| 1165 | /* |
| 1166 | * New topline is above old topline: May scroll down. |
| 1167 | */ |
| 1168 | #ifdef FEAT_FOLDING |
| 1169 | if (hasAnyFolding(wp)) |
| 1170 | { |
| 1171 | linenr_T ln; |
| 1172 | |
| 1173 | /* count the number of lines we are off, counting a sequence |
| 1174 | * of folded lines as one */ |
| 1175 | j = 0; |
| 1176 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1177 | { |
| 1178 | ++j; |
| 1179 | if (j >= wp->w_height - 2) |
| 1180 | break; |
| 1181 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1182 | } |
| 1183 | } |
| 1184 | else |
| 1185 | #endif |
| 1186 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1187 | if (j < wp->w_height - 2) /* not too far off */ |
| 1188 | { |
| 1189 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1190 | #ifdef FEAT_DIFF |
| 1191 | /* insert extra lines for previously invisible filler lines */ |
| 1192 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1193 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1194 | - wp->w_old_topfill; |
| 1195 | #endif |
| 1196 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1197 | { |
| 1198 | /* |
| 1199 | * Try to insert the correct number of lines. |
| 1200 | * If not the last window, delete the lines at the bottom. |
| 1201 | * win_ins_lines may fail when the terminal can't do it. |
| 1202 | */ |
| 1203 | if (i > 0) |
| 1204 | check_for_delay(FALSE); |
| 1205 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1206 | { |
| 1207 | if (wp->w_lines_valid != 0) |
| 1208 | { |
| 1209 | /* Need to update rows that are new, stop at the |
| 1210 | * first one that scrolled down. */ |
| 1211 | top_end = i; |
| 1212 | #ifdef FEAT_VISUAL |
| 1213 | scrolled_down = TRUE; |
| 1214 | #endif |
| 1215 | |
| 1216 | /* Move the entries that were scrolled, disable |
| 1217 | * the entries for the lines to be redrawn. */ |
| 1218 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1219 | wp->w_lines_valid = wp->w_height; |
| 1220 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1221 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1222 | while (idx >= 0) |
| 1223 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1224 | } |
| 1225 | } |
| 1226 | else |
| 1227 | mid_start = 0; /* redraw all lines */ |
| 1228 | } |
| 1229 | else |
| 1230 | mid_start = 0; /* redraw all lines */ |
| 1231 | } |
| 1232 | else |
| 1233 | mid_start = 0; /* redraw all lines */ |
| 1234 | } |
| 1235 | else |
| 1236 | { |
| 1237 | /* |
| 1238 | * New topline is at or below old topline: May scroll up. |
| 1239 | * When topline didn't change, find first entry in w_lines[] that |
| 1240 | * needs updating. |
| 1241 | */ |
| 1242 | |
| 1243 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1244 | j = -1; |
| 1245 | row = 0; |
| 1246 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1247 | { |
| 1248 | if (wp->w_lines[i].wl_valid |
| 1249 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1250 | { |
| 1251 | j = i; |
| 1252 | break; |
| 1253 | } |
| 1254 | row += wp->w_lines[i].wl_size; |
| 1255 | } |
| 1256 | if (j == -1) |
| 1257 | { |
| 1258 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1259 | * lines */ |
| 1260 | mid_start = 0; |
| 1261 | } |
| 1262 | else |
| 1263 | { |
| 1264 | /* |
| 1265 | * Try to delete the correct number of lines. |
| 1266 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1267 | */ |
| 1268 | #ifdef FEAT_DIFF |
| 1269 | /* If the topline didn't change, delete old filler lines, |
| 1270 | * otherwise delete filler lines of the new topline... */ |
| 1271 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1272 | row += wp->w_old_topfill; |
| 1273 | else |
| 1274 | row += diff_check_fill(wp, wp->w_topline); |
| 1275 | /* ... but don't delete new filler lines. */ |
| 1276 | row -= wp->w_topfill; |
| 1277 | #endif |
| 1278 | if (row > 0) |
| 1279 | { |
| 1280 | check_for_delay(FALSE); |
| 1281 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1282 | bot_start = wp->w_height - row; |
| 1283 | else |
| 1284 | mid_start = 0; /* redraw all lines */ |
| 1285 | } |
| 1286 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1287 | { |
| 1288 | /* |
| 1289 | * Skip the lines (below the deleted lines) that are still |
| 1290 | * valid and don't need redrawing. Copy their info |
| 1291 | * upwards, to compensate for the deleted lines. Set |
| 1292 | * bot_start to the first row that needs redrawing. |
| 1293 | */ |
| 1294 | bot_start = 0; |
| 1295 | idx = 0; |
| 1296 | for (;;) |
| 1297 | { |
| 1298 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1299 | /* stop at line that didn't fit, unless it is still |
| 1300 | * valid (no lines deleted) */ |
| 1301 | if (row > 0 && bot_start + row |
| 1302 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1303 | { |
| 1304 | wp->w_lines_valid = idx + 1; |
| 1305 | break; |
| 1306 | } |
| 1307 | bot_start += wp->w_lines[idx++].wl_size; |
| 1308 | |
| 1309 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1310 | if (++j >= wp->w_lines_valid) |
| 1311 | { |
| 1312 | wp->w_lines_valid = idx; |
| 1313 | break; |
| 1314 | } |
| 1315 | } |
| 1316 | #ifdef FEAT_DIFF |
| 1317 | /* Correct the first entry for filler lines at the top |
| 1318 | * when it won't get updated below. */ |
| 1319 | if (wp->w_p_diff && bot_start > 0) |
| 1320 | wp->w_lines[0].wl_size = |
| 1321 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1322 | + wp->w_topfill; |
| 1323 | #endif |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | /* When starting redraw in the first line, redraw all lines. When |
| 1329 | * there is only one window it's probably faster to clear the screen |
| 1330 | * first. */ |
| 1331 | if (mid_start == 0) |
| 1332 | { |
| 1333 | mid_end = wp->w_height; |
| 1334 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1335 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1336 | /* Clear the screen when it was not done by win_del_lines() or |
| 1337 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1338 | * then. */ |
| 1339 | if (screen_cleared != TRUE) |
| 1340 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1341 | #ifdef FEAT_WINDOWS |
| 1342 | /* The screen was cleared, redraw the tab pages line. */ |
| 1343 | if (redraw_tabline) |
| 1344 | draw_tabline(); |
| 1345 | #endif |
| 1346 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1347 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1348 | |
| 1349 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1350 | * cleared (only happens for the first window) or when screenclear() |
| 1351 | * was called directly above, "must_redraw" will have been set to |
| 1352 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1353 | if (screen_cleared == TRUE) |
| 1354 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1355 | } |
| 1356 | else |
| 1357 | { |
| 1358 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1359 | mid_start = 0; |
| 1360 | mid_end = wp->w_height; |
| 1361 | } |
| 1362 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1363 | if (type == SOME_VALID) |
| 1364 | { |
| 1365 | /* SOME_VALID: redraw all lines. */ |
| 1366 | mid_start = 0; |
| 1367 | mid_end = wp->w_height; |
| 1368 | type = NOT_VALID; |
| 1369 | } |
| 1370 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1371 | #ifdef FEAT_VISUAL |
| 1372 | /* check if we are updating or removing the inverted part */ |
| 1373 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1374 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1375 | { |
| 1376 | linenr_T from, to; |
| 1377 | |
| 1378 | if (VIsual_active) |
| 1379 | { |
| 1380 | if (VIsual_active |
| 1381 | && (VIsual_mode != wp->w_old_visual_mode |
| 1382 | || type == INVERTED_ALL)) |
| 1383 | { |
| 1384 | /* |
| 1385 | * If the type of Visual selection changed, redraw the whole |
| 1386 | * selection. Also when the ownership of the X selection is |
| 1387 | * gained or lost. |
| 1388 | */ |
| 1389 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1390 | { |
| 1391 | from = curwin->w_cursor.lnum; |
| 1392 | to = VIsual.lnum; |
| 1393 | } |
| 1394 | else |
| 1395 | { |
| 1396 | from = VIsual.lnum; |
| 1397 | to = curwin->w_cursor.lnum; |
| 1398 | } |
| 1399 | /* redraw more when the cursor moved as well */ |
| 1400 | if (wp->w_old_cursor_lnum < from) |
| 1401 | from = wp->w_old_cursor_lnum; |
| 1402 | if (wp->w_old_cursor_lnum > to) |
| 1403 | to = wp->w_old_cursor_lnum; |
| 1404 | if (wp->w_old_visual_lnum < from) |
| 1405 | from = wp->w_old_visual_lnum; |
| 1406 | if (wp->w_old_visual_lnum > to) |
| 1407 | to = wp->w_old_visual_lnum; |
| 1408 | } |
| 1409 | else |
| 1410 | { |
| 1411 | /* |
| 1412 | * Find the line numbers that need to be updated: The lines |
| 1413 | * between the old cursor position and the current cursor |
| 1414 | * position. Also check if the Visual position changed. |
| 1415 | */ |
| 1416 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1417 | { |
| 1418 | from = curwin->w_cursor.lnum; |
| 1419 | to = wp->w_old_cursor_lnum; |
| 1420 | } |
| 1421 | else |
| 1422 | { |
| 1423 | from = wp->w_old_cursor_lnum; |
| 1424 | to = curwin->w_cursor.lnum; |
| 1425 | if (from == 0) /* Visual mode just started */ |
| 1426 | from = to; |
| 1427 | } |
| 1428 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1429 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1430 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1431 | { |
| 1432 | if (wp->w_old_visual_lnum < from |
| 1433 | && wp->w_old_visual_lnum != 0) |
| 1434 | from = wp->w_old_visual_lnum; |
| 1435 | if (wp->w_old_visual_lnum > to) |
| 1436 | to = wp->w_old_visual_lnum; |
| 1437 | if (VIsual.lnum < from) |
| 1438 | from = VIsual.lnum; |
| 1439 | if (VIsual.lnum > to) |
| 1440 | to = VIsual.lnum; |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | /* |
| 1445 | * If in block mode and changed column or curwin->w_curswant: |
| 1446 | * update all lines. |
| 1447 | * First compute the actual start and end column. |
| 1448 | */ |
| 1449 | if (VIsual_mode == Ctrl_V) |
| 1450 | { |
| 1451 | colnr_T fromc, toc; |
| 1452 | |
| 1453 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
| 1454 | ++toc; |
| 1455 | if (curwin->w_curswant == MAXCOL) |
| 1456 | toc = MAXCOL; |
| 1457 | |
| 1458 | if (fromc != wp->w_old_cursor_fcol |
| 1459 | || toc != wp->w_old_cursor_lcol) |
| 1460 | { |
| 1461 | if (from > VIsual.lnum) |
| 1462 | from = VIsual.lnum; |
| 1463 | if (to < VIsual.lnum) |
| 1464 | to = VIsual.lnum; |
| 1465 | } |
| 1466 | wp->w_old_cursor_fcol = fromc; |
| 1467 | wp->w_old_cursor_lcol = toc; |
| 1468 | } |
| 1469 | } |
| 1470 | else |
| 1471 | { |
| 1472 | /* Use the line numbers of the old Visual area. */ |
| 1473 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1474 | { |
| 1475 | from = wp->w_old_cursor_lnum; |
| 1476 | to = wp->w_old_visual_lnum; |
| 1477 | } |
| 1478 | else |
| 1479 | { |
| 1480 | from = wp->w_old_visual_lnum; |
| 1481 | to = wp->w_old_cursor_lnum; |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | /* |
| 1486 | * There is no need to update lines above the top of the window. |
| 1487 | */ |
| 1488 | if (from < wp->w_topline) |
| 1489 | from = wp->w_topline; |
| 1490 | |
| 1491 | /* |
| 1492 | * If we know the value of w_botline, use it to restrict the update to |
| 1493 | * the lines that are visible in the window. |
| 1494 | */ |
| 1495 | if (wp->w_valid & VALID_BOTLINE) |
| 1496 | { |
| 1497 | if (from >= wp->w_botline) |
| 1498 | from = wp->w_botline - 1; |
| 1499 | if (to >= wp->w_botline) |
| 1500 | to = wp->w_botline - 1; |
| 1501 | } |
| 1502 | |
| 1503 | /* |
| 1504 | * Find the minimal part to be updated. |
| 1505 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1506 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1507 | * top_end; need to redraw from top_end to the "to" line. |
| 1508 | * A middle mouse click with a Visual selection may change the text |
| 1509 | * above the Visual area and reset wl_valid, do count these for |
| 1510 | * mid_end (in srow). |
| 1511 | */ |
| 1512 | if (mid_start > 0) |
| 1513 | { |
| 1514 | lnum = wp->w_topline; |
| 1515 | idx = 0; |
| 1516 | srow = 0; |
| 1517 | if (scrolled_down) |
| 1518 | mid_start = top_end; |
| 1519 | else |
| 1520 | mid_start = 0; |
| 1521 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1522 | { |
| 1523 | if (wp->w_lines[idx].wl_valid) |
| 1524 | mid_start += wp->w_lines[idx].wl_size; |
| 1525 | else if (!scrolled_down) |
| 1526 | srow += wp->w_lines[idx].wl_size; |
| 1527 | ++idx; |
| 1528 | # ifdef FEAT_FOLDING |
| 1529 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1530 | lnum = wp->w_lines[idx].wl_lnum; |
| 1531 | else |
| 1532 | # endif |
| 1533 | ++lnum; |
| 1534 | } |
| 1535 | srow += mid_start; |
| 1536 | mid_end = wp->w_height; |
| 1537 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1538 | { |
| 1539 | if (wp->w_lines[idx].wl_valid |
| 1540 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1541 | { |
| 1542 | /* Only update until first row of this line */ |
| 1543 | mid_end = srow; |
| 1544 | break; |
| 1545 | } |
| 1546 | srow += wp->w_lines[idx].wl_size; |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | if (VIsual_active && buf == curwin->w_buffer) |
| 1552 | { |
| 1553 | wp->w_old_visual_mode = VIsual_mode; |
| 1554 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1555 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1556 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1557 | wp->w_old_curswant = curwin->w_curswant; |
| 1558 | } |
| 1559 | else |
| 1560 | { |
| 1561 | wp->w_old_visual_mode = 0; |
| 1562 | wp->w_old_cursor_lnum = 0; |
| 1563 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1564 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1565 | } |
| 1566 | #endif /* FEAT_VISUAL */ |
| 1567 | |
| 1568 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1569 | /* reset got_int, otherwise regexp won't work */ |
| 1570 | save_got_int = got_int; |
| 1571 | got_int = 0; |
| 1572 | #endif |
| 1573 | #ifdef FEAT_FOLDING |
| 1574 | win_foldinfo.fi_level = 0; |
| 1575 | #endif |
| 1576 | |
| 1577 | /* |
| 1578 | * Update all the window rows. |
| 1579 | */ |
| 1580 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1581 | row = 0; |
| 1582 | srow = 0; |
| 1583 | lnum = wp->w_topline; /* first line shown in window */ |
| 1584 | for (;;) |
| 1585 | { |
| 1586 | /* stop updating when reached the end of the window (check for _past_ |
| 1587 | * the end of the window is at the end of the loop) */ |
| 1588 | if (row == wp->w_height) |
| 1589 | { |
| 1590 | didline = TRUE; |
| 1591 | break; |
| 1592 | } |
| 1593 | |
| 1594 | /* stop updating when hit the end of the file */ |
| 1595 | if (lnum > buf->b_ml.ml_line_count) |
| 1596 | { |
| 1597 | eof = TRUE; |
| 1598 | break; |
| 1599 | } |
| 1600 | |
| 1601 | /* Remember the starting row of the line that is going to be dealt |
| 1602 | * with. It is used further down when the line doesn't fit. */ |
| 1603 | srow = row; |
| 1604 | |
| 1605 | /* |
| 1606 | * Update a line when it is in an area that needs updating, when it |
| 1607 | * has changes or w_lines[idx] is invalid. |
| 1608 | * bot_start may be halfway a wrapped line after using |
| 1609 | * win_del_lines(), check if the current line includes it. |
| 1610 | * When syntax folding is being used, the saved syntax states will |
| 1611 | * already have been updated, we can't see where the syntax state is |
| 1612 | * the same again, just update until the end of the window. |
| 1613 | */ |
| 1614 | if (row < top_end |
| 1615 | || (row >= mid_start && row < mid_end) |
| 1616 | #ifdef FEAT_SEARCH_EXTRA |
| 1617 | || top_to_mod |
| 1618 | #endif |
| 1619 | || idx >= wp->w_lines_valid |
| 1620 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1621 | || (mod_top != 0 |
| 1622 | && (lnum == mod_top |
| 1623 | || (lnum >= mod_top |
| 1624 | && (lnum < mod_bot |
| 1625 | #ifdef FEAT_SYN_HL |
| 1626 | || did_update == DID_FOLD |
| 1627 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1628 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1629 | && ( |
| 1630 | # ifdef FEAT_FOLDING |
| 1631 | (foldmethodIsSyntax(wp) |
| 1632 | && hasAnyFolding(wp)) || |
| 1633 | # endif |
| 1634 | syntax_check_changed(lnum))) |
| 1635 | #endif |
| 1636 | ))))) |
| 1637 | { |
| 1638 | #ifdef FEAT_SEARCH_EXTRA |
| 1639 | if (lnum == mod_top) |
| 1640 | top_to_mod = FALSE; |
| 1641 | #endif |
| 1642 | |
| 1643 | /* |
| 1644 | * When at start of changed lines: May scroll following lines |
| 1645 | * up or down to minimize redrawing. |
| 1646 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1647 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1648 | */ |
| 1649 | if (lnum == mod_top |
| 1650 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1651 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1652 | { |
| 1653 | int old_rows = 0; |
| 1654 | int new_rows = 0; |
| 1655 | int xtra_rows; |
| 1656 | linenr_T l; |
| 1657 | |
| 1658 | /* Count the old number of window rows, using w_lines[], which |
| 1659 | * should still contain the sizes for the lines as they are |
| 1660 | * currently displayed. */ |
| 1661 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1662 | { |
| 1663 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1664 | * lines are part of the changed area. */ |
| 1665 | if (wp->w_lines[i].wl_valid |
| 1666 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1667 | break; |
| 1668 | old_rows += wp->w_lines[i].wl_size; |
| 1669 | #ifdef FEAT_FOLDING |
| 1670 | if (wp->w_lines[i].wl_valid |
| 1671 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1672 | { |
| 1673 | /* Must have found the last valid entry above mod_bot. |
| 1674 | * Add following invalid entries. */ |
| 1675 | ++i; |
| 1676 | while (i < wp->w_lines_valid |
| 1677 | && !wp->w_lines[i].wl_valid) |
| 1678 | old_rows += wp->w_lines[i++].wl_size; |
| 1679 | break; |
| 1680 | } |
| 1681 | #endif |
| 1682 | } |
| 1683 | |
| 1684 | if (i >= wp->w_lines_valid) |
| 1685 | { |
| 1686 | /* We can't find a valid line below the changed lines, |
| 1687 | * need to redraw until the end of the window. |
| 1688 | * Inserting/deleting lines has no use. */ |
| 1689 | bot_start = 0; |
| 1690 | } |
| 1691 | else |
| 1692 | { |
| 1693 | /* Able to count old number of rows: Count new window |
| 1694 | * rows, and may insert/delete lines */ |
| 1695 | j = idx; |
| 1696 | for (l = lnum; l < mod_bot; ++l) |
| 1697 | { |
| 1698 | #ifdef FEAT_FOLDING |
| 1699 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1700 | ++new_rows; |
| 1701 | else |
| 1702 | #endif |
| 1703 | #ifdef FEAT_DIFF |
| 1704 | if (l == wp->w_topline) |
| 1705 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1706 | + wp->w_topfill; |
| 1707 | else |
| 1708 | #endif |
| 1709 | new_rows += plines_win(wp, l, TRUE); |
| 1710 | ++j; |
| 1711 | if (new_rows > wp->w_height - row - 2) |
| 1712 | { |
| 1713 | /* it's getting too much, must redraw the rest */ |
| 1714 | new_rows = 9999; |
| 1715 | break; |
| 1716 | } |
| 1717 | } |
| 1718 | xtra_rows = new_rows - old_rows; |
| 1719 | if (xtra_rows < 0) |
| 1720 | { |
| 1721 | /* May scroll text up. If there is not enough |
| 1722 | * remaining text or scrolling fails, must redraw the |
| 1723 | * rest. If scrolling works, must redraw the text |
| 1724 | * below the scrolled text. */ |
| 1725 | if (row - xtra_rows >= wp->w_height - 2) |
| 1726 | mod_bot = MAXLNUM; |
| 1727 | else |
| 1728 | { |
| 1729 | check_for_delay(FALSE); |
| 1730 | if (win_del_lines(wp, row, |
| 1731 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1732 | mod_bot = MAXLNUM; |
| 1733 | else |
| 1734 | bot_start = wp->w_height + xtra_rows; |
| 1735 | } |
| 1736 | } |
| 1737 | else if (xtra_rows > 0) |
| 1738 | { |
| 1739 | /* May scroll text down. If there is not enough |
| 1740 | * remaining text of scrolling fails, must redraw the |
| 1741 | * rest. */ |
| 1742 | if (row + xtra_rows >= wp->w_height - 2) |
| 1743 | mod_bot = MAXLNUM; |
| 1744 | else |
| 1745 | { |
| 1746 | check_for_delay(FALSE); |
| 1747 | if (win_ins_lines(wp, row + old_rows, |
| 1748 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1749 | mod_bot = MAXLNUM; |
| 1750 | else if (top_end > row + old_rows) |
| 1751 | /* Scrolled the part at the top that requires |
| 1752 | * updating down. */ |
| 1753 | top_end += xtra_rows; |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | /* When not updating the rest, may need to move w_lines[] |
| 1758 | * entries. */ |
| 1759 | if (mod_bot != MAXLNUM && i != j) |
| 1760 | { |
| 1761 | if (j < i) |
| 1762 | { |
| 1763 | int x = row + new_rows; |
| 1764 | |
| 1765 | /* move entries in w_lines[] upwards */ |
| 1766 | for (;;) |
| 1767 | { |
| 1768 | /* stop at last valid entry in w_lines[] */ |
| 1769 | if (i >= wp->w_lines_valid) |
| 1770 | { |
| 1771 | wp->w_lines_valid = j; |
| 1772 | break; |
| 1773 | } |
| 1774 | wp->w_lines[j] = wp->w_lines[i]; |
| 1775 | /* stop at a line that won't fit */ |
| 1776 | if (x + (int)wp->w_lines[j].wl_size |
| 1777 | > wp->w_height) |
| 1778 | { |
| 1779 | wp->w_lines_valid = j + 1; |
| 1780 | break; |
| 1781 | } |
| 1782 | x += wp->w_lines[j++].wl_size; |
| 1783 | ++i; |
| 1784 | } |
| 1785 | if (bot_start > x) |
| 1786 | bot_start = x; |
| 1787 | } |
| 1788 | else /* j > i */ |
| 1789 | { |
| 1790 | /* move entries in w_lines[] downwards */ |
| 1791 | j -= i; |
| 1792 | wp->w_lines_valid += j; |
| 1793 | if (wp->w_lines_valid > wp->w_height) |
| 1794 | wp->w_lines_valid = wp->w_height; |
| 1795 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1796 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1797 | |
| 1798 | /* The w_lines[] entries for inserted lines are |
| 1799 | * now invalid, but wl_size may be used above. |
| 1800 | * Reset to zero. */ |
| 1801 | while (i >= idx) |
| 1802 | { |
| 1803 | wp->w_lines[i].wl_size = 0; |
| 1804 | wp->w_lines[i--].wl_valid = FALSE; |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | #ifdef FEAT_FOLDING |
| 1812 | /* |
| 1813 | * When lines are folded, display one line for all of them. |
| 1814 | * Otherwise, display normally (can be several display lines when |
| 1815 | * 'wrap' is on). |
| 1816 | */ |
| 1817 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1818 | if (fold_count != 0) |
| 1819 | { |
| 1820 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1821 | ++row; |
| 1822 | --fold_count; |
| 1823 | wp->w_lines[idx].wl_folded = TRUE; |
| 1824 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1825 | # ifdef FEAT_SYN_HL |
| 1826 | did_update = DID_FOLD; |
| 1827 | # endif |
| 1828 | } |
| 1829 | else |
| 1830 | #endif |
| 1831 | if (idx < wp->w_lines_valid |
| 1832 | && wp->w_lines[idx].wl_valid |
| 1833 | && wp->w_lines[idx].wl_lnum == lnum |
| 1834 | && lnum > wp->w_topline |
| 1835 | && !(dy_flags & DY_LASTLINE) |
| 1836 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1837 | #ifdef FEAT_DIFF |
| 1838 | && diff_check_fill(wp, lnum) == 0 |
| 1839 | #endif |
| 1840 | ) |
| 1841 | { |
| 1842 | /* This line is not going to fit. Don't draw anything here, |
| 1843 | * will draw "@ " lines below. */ |
| 1844 | row = wp->w_height + 1; |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | #ifdef FEAT_SEARCH_EXTRA |
| 1849 | prepare_search_hl(wp, lnum); |
| 1850 | #endif |
| 1851 | #ifdef FEAT_SYN_HL |
| 1852 | /* Let the syntax stuff know we skipped a few lines. */ |
| 1853 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1854 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1855 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1856 | #endif |
| 1857 | |
| 1858 | /* |
| 1859 | * Display one line. |
| 1860 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 1861 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1862 | |
| 1863 | #ifdef FEAT_FOLDING |
| 1864 | wp->w_lines[idx].wl_folded = FALSE; |
| 1865 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 1866 | #endif |
| 1867 | #ifdef FEAT_SYN_HL |
| 1868 | did_update = DID_LINE; |
| 1869 | syntax_last_parsed = lnum; |
| 1870 | #endif |
| 1871 | } |
| 1872 | |
| 1873 | wp->w_lines[idx].wl_lnum = lnum; |
| 1874 | wp->w_lines[idx].wl_valid = TRUE; |
| 1875 | if (row > wp->w_height) /* past end of screen */ |
| 1876 | { |
| 1877 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1878 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1879 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 1880 | ++idx; |
| 1881 | break; |
| 1882 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1883 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1884 | wp->w_lines[idx].wl_size = row - srow; |
| 1885 | ++idx; |
| 1886 | #ifdef FEAT_FOLDING |
| 1887 | lnum += fold_count + 1; |
| 1888 | #else |
| 1889 | ++lnum; |
| 1890 | #endif |
| 1891 | } |
| 1892 | else |
| 1893 | { |
| 1894 | /* This line does not need updating, advance to the next one */ |
| 1895 | row += wp->w_lines[idx++].wl_size; |
| 1896 | if (row > wp->w_height) /* past end of screen */ |
| 1897 | break; |
| 1898 | #ifdef FEAT_FOLDING |
| 1899 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 1900 | #else |
| 1901 | ++lnum; |
| 1902 | #endif |
| 1903 | #ifdef FEAT_SYN_HL |
| 1904 | did_update = DID_NONE; |
| 1905 | #endif |
| 1906 | } |
| 1907 | |
| 1908 | if (lnum > buf->b_ml.ml_line_count) |
| 1909 | { |
| 1910 | eof = TRUE; |
| 1911 | break; |
| 1912 | } |
| 1913 | } |
| 1914 | /* |
| 1915 | * End of loop over all window lines. |
| 1916 | */ |
| 1917 | |
| 1918 | |
| 1919 | if (idx > wp->w_lines_valid) |
| 1920 | wp->w_lines_valid = idx; |
| 1921 | |
| 1922 | #ifdef FEAT_SYN_HL |
| 1923 | /* |
| 1924 | * Let the syntax stuff know we stop parsing here. |
| 1925 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1926 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1927 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1928 | #endif |
| 1929 | |
| 1930 | /* |
| 1931 | * If we didn't hit the end of the file, and we didn't finish the last |
| 1932 | * line we were working on, then the line didn't fit. |
| 1933 | */ |
| 1934 | wp->w_empty_rows = 0; |
| 1935 | #ifdef FEAT_DIFF |
| 1936 | wp->w_filler_rows = 0; |
| 1937 | #endif |
| 1938 | if (!eof && !didline) |
| 1939 | { |
| 1940 | if (lnum == wp->w_topline) |
| 1941 | { |
| 1942 | /* |
| 1943 | * Single line that does not fit! |
| 1944 | * Don't overwrite it, it can be edited. |
| 1945 | */ |
| 1946 | wp->w_botline = lnum + 1; |
| 1947 | } |
| 1948 | #ifdef FEAT_DIFF |
| 1949 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 1950 | { |
| 1951 | /* Window ends in filler lines. */ |
| 1952 | wp->w_botline = lnum; |
| 1953 | wp->w_filler_rows = wp->w_height - srow; |
| 1954 | } |
| 1955 | #endif |
| 1956 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 1957 | { |
| 1958 | /* |
| 1959 | * Last line isn't finished: Display "@@@" at the end. |
| 1960 | */ |
| 1961 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 1962 | W_WINROW(wp) + wp->w_height, |
| 1963 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 1964 | '@', '@', hl_attr(HLF_AT)); |
| 1965 | set_empty_rows(wp, srow); |
| 1966 | wp->w_botline = lnum; |
| 1967 | } |
| 1968 | else |
| 1969 | { |
| 1970 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 1971 | wp->w_botline = lnum; |
| 1972 | } |
| 1973 | } |
| 1974 | else |
| 1975 | { |
| 1976 | #ifdef FEAT_VERTSPLIT |
| 1977 | draw_vsep_win(wp, row); |
| 1978 | #endif |
| 1979 | if (eof) /* we hit the end of the file */ |
| 1980 | { |
| 1981 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 1982 | #ifdef FEAT_DIFF |
| 1983 | j = diff_check_fill(wp, wp->w_botline); |
| 1984 | if (j > 0 && !wp->w_botfill) |
| 1985 | { |
| 1986 | /* |
| 1987 | * Display filler lines at the end of the file |
| 1988 | */ |
| 1989 | if (char2cells(fill_diff) > 1) |
| 1990 | i = '-'; |
| 1991 | else |
| 1992 | i = fill_diff; |
| 1993 | if (row + j > wp->w_height) |
| 1994 | j = wp->w_height - row; |
| 1995 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 1996 | row += j; |
| 1997 | } |
| 1998 | #endif |
| 1999 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2000 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2001 | wp->w_botline = lnum; |
| 2002 | |
| 2003 | /* make sure the rest of the screen is blank */ |
| 2004 | /* put '~'s on rows that aren't part of the file. */ |
| 2005 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 2006 | } |
| 2007 | |
| 2008 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2009 | wp->w_redr_type = 0; |
| 2010 | #ifdef FEAT_DIFF |
| 2011 | wp->w_old_topfill = wp->w_topfill; |
| 2012 | wp->w_old_botfill = wp->w_botfill; |
| 2013 | #endif |
| 2014 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2015 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2016 | { |
| 2017 | /* |
| 2018 | * There is a trick with w_botline. If we invalidate it on each |
| 2019 | * change that might modify it, this will cause a lot of expensive |
| 2020 | * calls to plines() in update_topline() each time. Therefore the |
| 2021 | * value of w_botline is often approximated, and this value is used to |
| 2022 | * compute the value of w_topline. If the value of w_botline was |
| 2023 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2024 | * the visible part of the text). If it's not, we need to redraw |
| 2025 | * again. Mostly this just means scrolling up a few lines, so it |
| 2026 | * doesn't look too bad. Only do this for the current window (where |
| 2027 | * changes are relevant). |
| 2028 | */ |
| 2029 | wp->w_valid |= VALID_BOTLINE; |
| 2030 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2031 | { |
| 2032 | recursive = TRUE; |
| 2033 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2034 | update_topline(); /* may invalidate w_botline again */ |
| 2035 | if (must_redraw != 0) |
| 2036 | { |
| 2037 | /* Don't update for changes in buffer again. */ |
| 2038 | i = curbuf->b_mod_set; |
| 2039 | curbuf->b_mod_set = FALSE; |
| 2040 | win_update(curwin); |
| 2041 | must_redraw = 0; |
| 2042 | curbuf->b_mod_set = i; |
| 2043 | } |
| 2044 | recursive = FALSE; |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2049 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2050 | if (!got_int) |
| 2051 | got_int = save_got_int; |
| 2052 | #endif |
| 2053 | } |
| 2054 | |
| 2055 | #ifdef FEAT_SIGNS |
| 2056 | static int draw_signcolumn __ARGS((win_T *wp)); |
| 2057 | |
| 2058 | /* |
| 2059 | * Return TRUE when window "wp" has a column to draw signs in. |
| 2060 | */ |
| 2061 | static int |
| 2062 | draw_signcolumn(wp) |
| 2063 | win_T *wp; |
| 2064 | { |
| 2065 | return (wp->w_buffer->b_signlist != NULL |
| 2066 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 2067 | || netbeans_active() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2068 | # endif |
| 2069 | ); |
| 2070 | } |
| 2071 | #endif |
| 2072 | |
| 2073 | /* |
| 2074 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2075 | * as the filler character. |
| 2076 | */ |
| 2077 | static void |
| 2078 | win_draw_end(wp, c1, c2, row, endrow, hl) |
| 2079 | win_T *wp; |
| 2080 | int c1; |
| 2081 | int c2; |
| 2082 | int row; |
| 2083 | int endrow; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2084 | hlf_T hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2085 | { |
| 2086 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2087 | int n = 0; |
| 2088 | # define FDC_OFF n |
| 2089 | #else |
| 2090 | # define FDC_OFF 0 |
| 2091 | #endif |
| 2092 | |
| 2093 | #ifdef FEAT_RIGHTLEFT |
| 2094 | if (wp->w_p_rl) |
| 2095 | { |
| 2096 | /* No check for cmdline window: should never be right-left. */ |
| 2097 | # ifdef FEAT_FOLDING |
| 2098 | n = wp->w_p_fdc; |
| 2099 | |
| 2100 | if (n > 0) |
| 2101 | { |
| 2102 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2103 | if (n > W_WIDTH(wp)) |
| 2104 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2105 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2106 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2107 | ' ', ' ', hl_attr(HLF_FC)); |
| 2108 | } |
| 2109 | # endif |
| 2110 | # ifdef FEAT_SIGNS |
| 2111 | if (draw_signcolumn(wp)) |
| 2112 | { |
| 2113 | int nn = n + 2; |
| 2114 | |
| 2115 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2116 | if (nn > W_WIDTH(wp)) |
| 2117 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2118 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2119 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2120 | ' ', ' ', hl_attr(HLF_SC)); |
| 2121 | n = nn; |
| 2122 | } |
| 2123 | # endif |
| 2124 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2125 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2126 | c2, c2, hl_attr(hl)); |
| 2127 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2128 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2129 | c1, c2, hl_attr(hl)); |
| 2130 | } |
| 2131 | else |
| 2132 | #endif |
| 2133 | { |
| 2134 | #ifdef FEAT_CMDWIN |
| 2135 | if (cmdwin_type != 0 && wp == curwin) |
| 2136 | { |
| 2137 | /* draw the cmdline character in the leftmost column */ |
| 2138 | n = 1; |
| 2139 | if (n > wp->w_width) |
| 2140 | n = wp->w_width; |
| 2141 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2142 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2143 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2144 | } |
| 2145 | #endif |
| 2146 | #ifdef FEAT_FOLDING |
| 2147 | if (wp->w_p_fdc > 0) |
| 2148 | { |
| 2149 | int nn = n + wp->w_p_fdc; |
| 2150 | |
| 2151 | /* draw the fold column at the left */ |
| 2152 | if (nn > W_WIDTH(wp)) |
| 2153 | nn = W_WIDTH(wp); |
| 2154 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2155 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2156 | ' ', ' ', hl_attr(HLF_FC)); |
| 2157 | n = nn; |
| 2158 | } |
| 2159 | #endif |
| 2160 | #ifdef FEAT_SIGNS |
| 2161 | if (draw_signcolumn(wp)) |
| 2162 | { |
| 2163 | int nn = n + 2; |
| 2164 | |
| 2165 | /* draw the sign column after the fold column */ |
| 2166 | if (nn > W_WIDTH(wp)) |
| 2167 | nn = W_WIDTH(wp); |
| 2168 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2169 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2170 | ' ', ' ', hl_attr(HLF_SC)); |
| 2171 | n = nn; |
| 2172 | } |
| 2173 | #endif |
| 2174 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2175 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2176 | c1, c2, hl_attr(hl)); |
| 2177 | } |
| 2178 | set_empty_rows(wp, row); |
| 2179 | } |
| 2180 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2181 | #ifdef FEAT_SYN_HL |
| 2182 | static int advance_color_col __ARGS((int vcol, int **color_cols)); |
| 2183 | |
| 2184 | /* |
| 2185 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2186 | */ |
| 2187 | static int |
| 2188 | advance_color_col(vcol, color_cols) |
| 2189 | int vcol; |
| 2190 | int **color_cols; |
| 2191 | { |
| 2192 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2193 | ++*color_cols; |
| 2194 | return (**color_cols >= 0); |
| 2195 | } |
| 2196 | #endif |
| 2197 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2198 | #ifdef FEAT_FOLDING |
| 2199 | /* |
| 2200 | * Display one folded line. |
| 2201 | */ |
| 2202 | static void |
| 2203 | fold_line(wp, fold_count, foldinfo, lnum, row) |
| 2204 | win_T *wp; |
| 2205 | long fold_count; |
| 2206 | foldinfo_T *foldinfo; |
| 2207 | linenr_T lnum; |
| 2208 | int row; |
| 2209 | { |
| 2210 | char_u buf[51]; |
| 2211 | pos_T *top, *bot; |
| 2212 | linenr_T lnume = lnum + fold_count - 1; |
| 2213 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2214 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2215 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2216 | int col; |
| 2217 | int txtcol; |
| 2218 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2219 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2220 | |
| 2221 | /* Build the fold line: |
| 2222 | * 1. Add the cmdwin_type for the command-line window |
| 2223 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2224 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2225 | * 4. Compose the text |
| 2226 | * 5. Add the text |
| 2227 | * 6. set highlighting for the Visual area an other text |
| 2228 | */ |
| 2229 | col = 0; |
| 2230 | |
| 2231 | /* |
| 2232 | * 1. Add the cmdwin_type for the command-line window |
| 2233 | * Ignores 'rightleft', this window is never right-left. |
| 2234 | */ |
| 2235 | #ifdef FEAT_CMDWIN |
| 2236 | if (cmdwin_type != 0 && wp == curwin) |
| 2237 | { |
| 2238 | ScreenLines[off] = cmdwin_type; |
| 2239 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2240 | #ifdef FEAT_MBYTE |
| 2241 | if (enc_utf8) |
| 2242 | ScreenLinesUC[off] = 0; |
| 2243 | #endif |
| 2244 | ++col; |
| 2245 | } |
| 2246 | #endif |
| 2247 | |
| 2248 | /* |
| 2249 | * 2. Add the 'foldcolumn' |
| 2250 | */ |
| 2251 | fdc = wp->w_p_fdc; |
| 2252 | if (fdc > W_WIDTH(wp) - col) |
| 2253 | fdc = W_WIDTH(wp) - col; |
| 2254 | if (fdc > 0) |
| 2255 | { |
| 2256 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2257 | #ifdef FEAT_RIGHTLEFT |
| 2258 | if (wp->w_p_rl) |
| 2259 | { |
| 2260 | int i; |
| 2261 | |
| 2262 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2263 | hl_attr(HLF_FC)); |
| 2264 | /* reverse the fold column */ |
| 2265 | for (i = 0; i < fdc; ++i) |
| 2266 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2267 | } |
| 2268 | else |
| 2269 | #endif |
| 2270 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2271 | col += fdc; |
| 2272 | } |
| 2273 | |
| 2274 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2275 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2276 | for (ri = 0; ri < l; ++ri) \ |
| 2277 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2278 | else \ |
| 2279 | for (ri = 0; ri < l; ++ri) \ |
| 2280 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2281 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2282 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2283 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2284 | #endif |
| 2285 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2286 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2287 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2288 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2289 | |
| 2290 | #ifdef FEAT_SIGNS |
| 2291 | /* If signs are being displayed, add two spaces. */ |
| 2292 | if (draw_signcolumn(wp)) |
| 2293 | { |
| 2294 | len = W_WIDTH(wp) - col; |
| 2295 | if (len > 0) |
| 2296 | { |
| 2297 | if (len > 2) |
| 2298 | len = 2; |
| 2299 | # ifdef FEAT_RIGHTLEFT |
| 2300 | if (wp->w_p_rl) |
| 2301 | /* the line number isn't reversed */ |
| 2302 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2303 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2304 | else |
| 2305 | # endif |
| 2306 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2307 | col += len; |
| 2308 | } |
| 2309 | } |
| 2310 | #endif |
| 2311 | |
| 2312 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2313 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2314 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2315 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2316 | { |
| 2317 | len = W_WIDTH(wp) - col; |
| 2318 | if (len > 0) |
| 2319 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2320 | int w = number_width(wp); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2321 | long num; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2322 | |
| 2323 | if (len > w + 1) |
| 2324 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2325 | |
| 2326 | if (wp->w_p_nu) |
| 2327 | /* 'number' */ |
| 2328 | num = (long)lnum; |
| 2329 | else |
| 2330 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2331 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2332 | |
| 2333 | sprintf((char *)buf, "%*ld ", w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2334 | #ifdef FEAT_RIGHTLEFT |
| 2335 | if (wp->w_p_rl) |
| 2336 | /* the line number isn't reversed */ |
| 2337 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2338 | hl_attr(HLF_FL)); |
| 2339 | else |
| 2340 | #endif |
| 2341 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2342 | col += len; |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | /* |
| 2347 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2348 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2349 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2350 | |
| 2351 | txtcol = col; /* remember where text starts */ |
| 2352 | |
| 2353 | /* |
| 2354 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2355 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2356 | * in columns number-col - window-width. |
| 2357 | */ |
| 2358 | #ifdef FEAT_MBYTE |
| 2359 | if (has_mbyte) |
| 2360 | { |
| 2361 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2362 | int u8c, u8cc[MAX_MCO]; |
| 2363 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2364 | int idx; |
| 2365 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2366 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2367 | # ifdef FEAT_ARABIC |
| 2368 | int prev_c = 0; /* previous Arabic character */ |
| 2369 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2370 | # endif |
| 2371 | |
| 2372 | # ifdef FEAT_RIGHTLEFT |
| 2373 | if (wp->w_p_rl) |
| 2374 | idx = off; |
| 2375 | else |
| 2376 | # endif |
| 2377 | idx = off + col; |
| 2378 | |
| 2379 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2380 | for (p = text; *p != NUL; ) |
| 2381 | { |
| 2382 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2383 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2384 | if (col + cells > W_WIDTH(wp) |
| 2385 | # ifdef FEAT_RIGHTLEFT |
| 2386 | - (wp->w_p_rl ? col : 0) |
| 2387 | # endif |
| 2388 | ) |
| 2389 | break; |
| 2390 | ScreenLines[idx] = *p; |
| 2391 | if (enc_utf8) |
| 2392 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2393 | u8c = utfc_ptr2char(p, u8cc); |
| 2394 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2395 | { |
| 2396 | ScreenLinesUC[idx] = 0; |
| 2397 | #ifdef FEAT_ARABIC |
| 2398 | prev_c = u8c; |
| 2399 | #endif |
| 2400 | } |
| 2401 | else |
| 2402 | { |
| 2403 | #ifdef FEAT_ARABIC |
| 2404 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2405 | { |
| 2406 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2407 | int pc, pc1, nc; |
| 2408 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2409 | int firstbyte = *p; |
| 2410 | |
| 2411 | /* The idea of what is the previous and next |
| 2412 | * character depends on 'rightleft'. */ |
| 2413 | if (wp->w_p_rl) |
| 2414 | { |
| 2415 | pc = prev_c; |
| 2416 | pc1 = prev_c1; |
| 2417 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2418 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2419 | } |
| 2420 | else |
| 2421 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2422 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2423 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2424 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2425 | } |
| 2426 | prev_c = u8c; |
| 2427 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2428 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2429 | pc, pc1, nc); |
| 2430 | ScreenLines[idx] = firstbyte; |
| 2431 | } |
| 2432 | else |
| 2433 | prev_c = u8c; |
| 2434 | #endif |
| 2435 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2436 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2437 | if (u8c >= 0x10000) |
| 2438 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2439 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2440 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2441 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2442 | for (i = 0; i < Screen_mco; ++i) |
| 2443 | { |
| 2444 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2445 | if (u8cc[i] == 0) |
| 2446 | break; |
| 2447 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2448 | } |
| 2449 | if (cells > 1) |
| 2450 | ScreenLines[idx + 1] = 0; |
| 2451 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2452 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2453 | /* double-byte single width character */ |
| 2454 | ScreenLines2[idx] = p[1]; |
| 2455 | else if (cells > 1) |
| 2456 | /* double-width character */ |
| 2457 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2458 | col += cells; |
| 2459 | idx += cells; |
| 2460 | p += c_len; |
| 2461 | } |
| 2462 | } |
| 2463 | else |
| 2464 | #endif |
| 2465 | { |
| 2466 | len = (int)STRLEN(text); |
| 2467 | if (len > W_WIDTH(wp) - col) |
| 2468 | len = W_WIDTH(wp) - col; |
| 2469 | if (len > 0) |
| 2470 | { |
| 2471 | #ifdef FEAT_RIGHTLEFT |
| 2472 | if (wp->w_p_rl) |
| 2473 | STRNCPY(current_ScreenLine, text, len); |
| 2474 | else |
| 2475 | #endif |
| 2476 | STRNCPY(current_ScreenLine + col, text, len); |
| 2477 | col += len; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | /* Fill the rest of the line with the fold filler */ |
| 2482 | #ifdef FEAT_RIGHTLEFT |
| 2483 | if (wp->w_p_rl) |
| 2484 | col -= txtcol; |
| 2485 | #endif |
| 2486 | while (col < W_WIDTH(wp) |
| 2487 | #ifdef FEAT_RIGHTLEFT |
| 2488 | - (wp->w_p_rl ? txtcol : 0) |
| 2489 | #endif |
| 2490 | ) |
| 2491 | { |
| 2492 | #ifdef FEAT_MBYTE |
| 2493 | if (enc_utf8) |
| 2494 | { |
| 2495 | if (fill_fold >= 0x80) |
| 2496 | { |
| 2497 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2498 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2499 | } |
| 2500 | else |
| 2501 | ScreenLinesUC[off + col] = 0; |
| 2502 | } |
| 2503 | #endif |
| 2504 | ScreenLines[off + col++] = fill_fold; |
| 2505 | } |
| 2506 | |
| 2507 | if (text != buf) |
| 2508 | vim_free(text); |
| 2509 | |
| 2510 | /* |
| 2511 | * 6. set highlighting for the Visual area an other text. |
| 2512 | * If all folded lines are in the Visual area, highlight the line. |
| 2513 | */ |
| 2514 | #ifdef FEAT_VISUAL |
| 2515 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2516 | { |
| 2517 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2518 | { |
| 2519 | /* Visual is after curwin->w_cursor */ |
| 2520 | top = &curwin->w_cursor; |
| 2521 | bot = &VIsual; |
| 2522 | } |
| 2523 | else |
| 2524 | { |
| 2525 | /* Visual is before curwin->w_cursor */ |
| 2526 | top = &VIsual; |
| 2527 | bot = &curwin->w_cursor; |
| 2528 | } |
| 2529 | if (lnum >= top->lnum |
| 2530 | && lnume <= bot->lnum |
| 2531 | && (VIsual_mode != 'v' |
| 2532 | || ((lnum > top->lnum |
| 2533 | || (lnum == top->lnum |
| 2534 | && top->col == 0)) |
| 2535 | && (lnume < bot->lnum |
| 2536 | || (lnume == bot->lnum |
| 2537 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2538 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2539 | { |
| 2540 | if (VIsual_mode == Ctrl_V) |
| 2541 | { |
| 2542 | /* Visual block mode: highlight the chars part of the block */ |
| 2543 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2544 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2545 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2546 | && wp->w_old_cursor_lcol + txtcol |
| 2547 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2548 | len = wp->w_old_cursor_lcol; |
| 2549 | else |
| 2550 | len = W_WIDTH(wp) - txtcol; |
| 2551 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2552 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2556 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2557 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2558 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2559 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | #endif |
| 2563 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2564 | #ifdef FEAT_SYN_HL |
| 2565 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2566 | if (wp->w_p_cuc) |
| 2567 | { |
| 2568 | txtcol += wp->w_virtcol; |
| 2569 | if (wp->w_p_wrap) |
| 2570 | txtcol -= wp->w_skipcol; |
| 2571 | else |
| 2572 | txtcol -= wp->w_leftcol; |
| 2573 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2574 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2575 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2576 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2577 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2578 | |
| 2579 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2580 | (int)W_WIDTH(wp), FALSE); |
| 2581 | |
| 2582 | /* |
| 2583 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2584 | * updated (saves a call to plines() later). |
| 2585 | */ |
| 2586 | if (wp == curwin |
| 2587 | && lnum <= curwin->w_cursor.lnum |
| 2588 | && lnume >= curwin->w_cursor.lnum) |
| 2589 | { |
| 2590 | curwin->w_cline_row = row; |
| 2591 | curwin->w_cline_height = 1; |
| 2592 | curwin->w_cline_folded = TRUE; |
| 2593 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | /* |
| 2598 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2599 | */ |
| 2600 | static void |
| 2601 | copy_text_attr(off, buf, len, attr) |
| 2602 | int off; |
| 2603 | char_u *buf; |
| 2604 | int len; |
| 2605 | int attr; |
| 2606 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2607 | int i; |
| 2608 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2609 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2610 | # ifdef FEAT_MBYTE |
| 2611 | if (enc_utf8) |
| 2612 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2613 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2614 | for (i = 0; i < len; ++i) |
| 2615 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | /* |
| 2619 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2620 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2621 | */ |
| 2622 | static void |
| 2623 | fill_foldcolumn(p, wp, closed, lnum) |
| 2624 | char_u *p; |
| 2625 | win_T *wp; |
| 2626 | int closed; /* TRUE of FALSE */ |
| 2627 | linenr_T lnum; /* current line number */ |
| 2628 | { |
| 2629 | int i = 0; |
| 2630 | int level; |
| 2631 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2632 | int empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2633 | |
| 2634 | /* Init to all spaces. */ |
| 2635 | copy_spaces(p, (size_t)wp->w_p_fdc); |
| 2636 | |
| 2637 | level = win_foldinfo.fi_level; |
| 2638 | if (level > 0) |
| 2639 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2640 | /* If there is only one column put more info in it. */ |
| 2641 | empty = (wp->w_p_fdc == 1) ? 0 : 1; |
| 2642 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2643 | /* If the column is too narrow, we start at the lowest level that |
| 2644 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2645 | first_level = level - wp->w_p_fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2646 | if (first_level < 1) |
| 2647 | first_level = 1; |
| 2648 | |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2649 | for (i = 0; i + empty < wp->w_p_fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2650 | { |
| 2651 | if (win_foldinfo.fi_lnum == lnum |
| 2652 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2653 | p[i] = '-'; |
| 2654 | else if (first_level == 1) |
| 2655 | p[i] = '|'; |
| 2656 | else if (first_level + i <= 9) |
| 2657 | p[i] = '0' + first_level + i; |
| 2658 | else |
| 2659 | p[i] = '>'; |
| 2660 | if (first_level + i == level) |
| 2661 | break; |
| 2662 | } |
| 2663 | } |
| 2664 | if (closed) |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2665 | p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2666 | } |
| 2667 | #endif /* FEAT_FOLDING */ |
| 2668 | |
| 2669 | /* |
| 2670 | * Display line "lnum" of window 'wp' on the screen. |
| 2671 | * Start at row "startrow", stop when "endrow" is reached. |
| 2672 | * wp->w_virtcol needs to be valid. |
| 2673 | * |
| 2674 | * Return the number of last row the line occupies. |
| 2675 | */ |
| 2676 | static int |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2677 | win_line(wp, lnum, startrow, endrow, nochange) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2678 | win_T *wp; |
| 2679 | linenr_T lnum; |
| 2680 | int startrow; |
| 2681 | int endrow; |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2682 | int nochange UNUSED; /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2683 | { |
| 2684 | int col; /* visual column on screen */ |
| 2685 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2686 | int c = 0; /* init for GCC */ |
| 2687 | long vcol = 0; /* virtual column (for tabs) */ |
| 2688 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2689 | char_u *line; /* current line */ |
| 2690 | char_u *ptr; /* current position in "line" */ |
| 2691 | int row; /* row in the window, excl w_winrow */ |
| 2692 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2693 | |
| 2694 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2695 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2696 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2697 | int c_extra = NUL; /* extra chars, all the same */ |
| 2698 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2699 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2700 | displaying lcs_eol at end-of-line */ |
| 2701 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2702 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2703 | |
| 2704 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2705 | int saved_n_extra = 0; |
| 2706 | char_u *saved_p_extra = NULL; |
| 2707 | int saved_c_extra = 0; |
| 2708 | int saved_char_attr = 0; |
| 2709 | |
| 2710 | int n_attr = 0; /* chars with special attr */ |
| 2711 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2712 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2713 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2714 | |
| 2715 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2716 | |
| 2717 | int fromcol, tocol; /* start/end of inverting */ |
| 2718 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2719 | int noinvcur = FALSE; /* don't invert the cursor */ |
| 2720 | #ifdef FEAT_VISUAL |
| 2721 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2722 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2723 | #endif |
| 2724 | pos_T pos; |
| 2725 | long v; |
| 2726 | |
| 2727 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2728 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2729 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2730 | in this line */ |
| 2731 | int attr = 0; /* attributes for area highlighting */ |
| 2732 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2733 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2734 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2735 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2736 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2737 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2738 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2739 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2740 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2741 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2742 | #endif |
| 2743 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2744 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2745 | # define SPWORDLEN 150 |
| 2746 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2747 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2748 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2749 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2750 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2751 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2752 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2753 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2754 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2755 | static int cap_col = -1; /* column to check for Cap word */ |
| 2756 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2757 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2758 | #endif |
| 2759 | int extra_check; /* has syntax or linebreak */ |
| 2760 | #ifdef FEAT_MBYTE |
| 2761 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2762 | int mb_l = 1; /* multi-byte byte length */ |
| 2763 | int mb_c = 0; /* decoded multi-byte character */ |
| 2764 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2765 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2766 | #endif |
| 2767 | #ifdef FEAT_DIFF |
| 2768 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2769 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2770 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2771 | int change_start = MAXCOL; /* first col of changed area */ |
| 2772 | int change_end = -1; /* last col of changed area */ |
| 2773 | #endif |
| 2774 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2775 | #ifdef FEAT_LINEBREAK |
| 2776 | int need_showbreak = FALSE; |
| 2777 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2778 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2779 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2780 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 2781 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2782 | #endif |
| 2783 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2784 | matchitem_T *cur; /* points to the match list */ |
| 2785 | match_T *shl; /* points to search_hl or a match */ |
| 2786 | int shl_flag; /* flag to indicate whether search_hl |
| 2787 | has been processed or not */ |
| 2788 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 2789 | equals startcol of search_hl or one |
| 2790 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2791 | #endif |
| 2792 | #ifdef FEAT_ARABIC |
| 2793 | int prev_c = 0; /* previous Arabic character */ |
| 2794 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2795 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2796 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 2797 | int did_line_attr = 0; |
| 2798 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2799 | |
| 2800 | /* draw_state: items that are drawn in sequence: */ |
| 2801 | #define WL_START 0 /* nothing done yet */ |
| 2802 | #ifdef FEAT_CMDWIN |
| 2803 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 2804 | #else |
| 2805 | # define WL_CMDLINE WL_START |
| 2806 | #endif |
| 2807 | #ifdef FEAT_FOLDING |
| 2808 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 2809 | #else |
| 2810 | # define WL_FOLD WL_CMDLINE |
| 2811 | #endif |
| 2812 | #ifdef FEAT_SIGNS |
| 2813 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 2814 | #else |
| 2815 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 2816 | #endif |
| 2817 | #define WL_NR WL_SIGN + 1 /* line number */ |
| 2818 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 2819 | # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ |
| 2820 | #else |
| 2821 | # define WL_SBR WL_NR |
| 2822 | #endif |
| 2823 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 2824 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 2825 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2826 | int feedback_col = 0; |
| 2827 | int feedback_old_attr = -1; |
| 2828 | #endif |
| 2829 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2830 | #ifdef FEAT_CONCEAL |
| 2831 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 2832 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 2833 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2834 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2835 | int is_concealing = FALSE; |
| 2836 | int boguscols = 0; /* nonexistent columns added to force |
| 2837 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 2838 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 2839 | int did_wcol = FALSE; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 2840 | # define VCOL_HLC (vcol - vcol_off) |
| 2841 | #else |
| 2842 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2843 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2844 | |
| 2845 | if (startrow > endrow) /* past the end already! */ |
| 2846 | return startrow; |
| 2847 | |
| 2848 | row = startrow; |
| 2849 | screen_row = row + W_WINROW(wp); |
| 2850 | |
| 2851 | /* |
| 2852 | * To speed up the loop below, set extra_check when there is linebreak, |
| 2853 | * trailing white space and/or syntax processing to be done. |
| 2854 | */ |
| 2855 | #ifdef FEAT_LINEBREAK |
| 2856 | extra_check = wp->w_p_lbr; |
| 2857 | #else |
| 2858 | extra_check = 0; |
| 2859 | #endif |
| 2860 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2861 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2862 | { |
| 2863 | /* Prepare for syntax highlighting in this line. When there is an |
| 2864 | * error, stop syntax highlighting. */ |
| 2865 | save_did_emsg = did_emsg; |
| 2866 | did_emsg = FALSE; |
| 2867 | syntax_start(wp, lnum); |
| 2868 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2869 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2870 | else |
| 2871 | { |
| 2872 | did_emsg = save_did_emsg; |
| 2873 | has_syntax = TRUE; |
| 2874 | extra_check = TRUE; |
| 2875 | } |
| 2876 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2877 | |
| 2878 | /* Check for columns to display for 'colorcolumn'. */ |
| 2879 | color_cols = wp->w_p_cc_cols; |
| 2880 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 2881 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2882 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2883 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2884 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 2885 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2886 | && *wp->w_s->b_p_spl != NUL |
| 2887 | && wp->w_s->b_langp.ga_len > 0 |
| 2888 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2889 | { |
| 2890 | /* Prepare for spell checking. */ |
| 2891 | has_spell = TRUE; |
| 2892 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2893 | |
| 2894 | /* Get the start of the next line, so that words that wrap to the next |
| 2895 | * line are found too: "et<line-break>al.". |
| 2896 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 2897 | nextline[SPWORDLEN] = NUL; |
| 2898 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 2899 | { |
| 2900 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 2901 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 2902 | } |
| 2903 | |
| 2904 | /* When a word wrapped from the previous line the start of the current |
| 2905 | * line is valid. */ |
| 2906 | if (lnum == checked_lnum) |
| 2907 | cur_checked_col = checked_col; |
| 2908 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2909 | |
| 2910 | /* When there was a sentence end in the previous line may require a |
| 2911 | * word starting with capital in this line. In line 1 always check |
| 2912 | * the first word. */ |
| 2913 | if (lnum != capcol_lnum) |
| 2914 | cap_col = -1; |
| 2915 | if (lnum == 1) |
| 2916 | cap_col = 0; |
| 2917 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2918 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2919 | #endif |
| 2920 | |
| 2921 | /* |
| 2922 | * handle visual active in this window |
| 2923 | */ |
| 2924 | fromcol = -10; |
| 2925 | tocol = MAXCOL; |
| 2926 | #ifdef FEAT_VISUAL |
| 2927 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2928 | { |
| 2929 | /* Visual is after curwin->w_cursor */ |
| 2930 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2931 | { |
| 2932 | top = &curwin->w_cursor; |
| 2933 | bot = &VIsual; |
| 2934 | } |
| 2935 | else /* Visual is before curwin->w_cursor */ |
| 2936 | { |
| 2937 | top = &VIsual; |
| 2938 | bot = &curwin->w_cursor; |
| 2939 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2940 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2941 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 2942 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2943 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2944 | { |
| 2945 | fromcol = wp->w_old_cursor_fcol; |
| 2946 | tocol = wp->w_old_cursor_lcol; |
| 2947 | } |
| 2948 | } |
| 2949 | else /* non-block mode */ |
| 2950 | { |
| 2951 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 2952 | fromcol = 0; |
| 2953 | else if (lnum == top->lnum) |
| 2954 | { |
| 2955 | if (VIsual_mode == 'V') /* linewise */ |
| 2956 | fromcol = 0; |
| 2957 | else |
| 2958 | { |
| 2959 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 2960 | if (gchar_pos(top) == NUL) |
| 2961 | tocol = fromcol + 1; |
| 2962 | } |
| 2963 | } |
| 2964 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 2965 | { |
| 2966 | if (*p_sel == 'e' && bot->col == 0 |
| 2967 | #ifdef FEAT_VIRTUALEDIT |
| 2968 | && bot->coladd == 0 |
| 2969 | #endif |
| 2970 | ) |
| 2971 | { |
| 2972 | fromcol = -10; |
| 2973 | tocol = MAXCOL; |
| 2974 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2975 | else if (bot->col == MAXCOL) |
| 2976 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2977 | else |
| 2978 | { |
| 2979 | pos = *bot; |
| 2980 | if (*p_sel == 'e') |
| 2981 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 2982 | else |
| 2983 | { |
| 2984 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 2985 | ++tocol; |
| 2986 | } |
| 2987 | } |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | #ifndef MSDOS |
| 2992 | /* Check if the character under the cursor should not be inverted */ |
| 2993 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
| 2994 | # ifdef FEAT_GUI |
| 2995 | && !gui.in_use |
| 2996 | # endif |
| 2997 | ) |
| 2998 | noinvcur = TRUE; |
| 2999 | #endif |
| 3000 | |
| 3001 | /* if inverting in this line set area_highlighting */ |
| 3002 | if (fromcol >= 0) |
| 3003 | { |
| 3004 | area_highlighting = TRUE; |
| 3005 | attr = hl_attr(HLF_V); |
| 3006 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3007 | if ((clip_star.available && !clip_star.owned |
| 3008 | && clip_isautosel_star()) |
| 3009 | || (clip_plus.available && !clip_plus.owned |
| 3010 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3011 | attr = hl_attr(HLF_VNC); |
| 3012 | #endif |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3017 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3018 | */ |
| 3019 | else |
| 3020 | #endif /* FEAT_VISUAL */ |
| 3021 | if (highlight_match |
| 3022 | && wp == curwin |
| 3023 | && lnum >= curwin->w_cursor.lnum |
| 3024 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3025 | { |
| 3026 | if (lnum == curwin->w_cursor.lnum) |
| 3027 | getvcol(curwin, &(curwin->w_cursor), |
| 3028 | (colnr_T *)&fromcol, NULL, NULL); |
| 3029 | else |
| 3030 | fromcol = 0; |
| 3031 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3032 | { |
| 3033 | pos.lnum = lnum; |
| 3034 | pos.col = search_match_endcol; |
| 3035 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3036 | } |
| 3037 | else |
| 3038 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3039 | /* do at least one character; happens when past end of line */ |
| 3040 | if (fromcol == tocol) |
| 3041 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3042 | area_highlighting = TRUE; |
| 3043 | attr = hl_attr(HLF_I); |
| 3044 | } |
| 3045 | |
| 3046 | #ifdef FEAT_DIFF |
| 3047 | filler_lines = diff_check(wp, lnum); |
| 3048 | if (filler_lines < 0) |
| 3049 | { |
| 3050 | if (filler_lines == -1) |
| 3051 | { |
| 3052 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3053 | diff_hlf = HLF_ADD; /* added line */ |
| 3054 | else if (change_start == 0) |
| 3055 | diff_hlf = HLF_TXD; /* changed text */ |
| 3056 | else |
| 3057 | diff_hlf = HLF_CHD; /* changed line */ |
| 3058 | } |
| 3059 | else |
| 3060 | diff_hlf = HLF_ADD; /* added line */ |
| 3061 | filler_lines = 0; |
| 3062 | area_highlighting = TRUE; |
| 3063 | } |
| 3064 | if (lnum == wp->w_topline) |
| 3065 | filler_lines = wp->w_topfill; |
| 3066 | filler_todo = filler_lines; |
| 3067 | #endif |
| 3068 | |
| 3069 | #ifdef LINE_ATTR |
| 3070 | # ifdef FEAT_SIGNS |
| 3071 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3072 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3073 | if (v != 0) |
| 3074 | line_attr = sign_get_attr((int)v, TRUE); |
| 3075 | # endif |
| 3076 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3077 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3078 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3079 | line_attr = hl_attr(HLF_L); |
| 3080 | # endif |
| 3081 | if (line_attr != 0) |
| 3082 | area_highlighting = TRUE; |
| 3083 | #endif |
| 3084 | |
| 3085 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3086 | ptr = line; |
| 3087 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3088 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3089 | if (has_spell) |
| 3090 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3091 | /* For checking first word with a capital skip white space. */ |
| 3092 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3093 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3094 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3095 | /* To be able to spell-check over line boundaries copy the end of the |
| 3096 | * current line into nextline[]. Above the start of the next line was |
| 3097 | * copied to nextline[SPWORDLEN]. */ |
| 3098 | if (nextline[SPWORDLEN] == NUL) |
| 3099 | { |
| 3100 | /* No next line or it is empty. */ |
| 3101 | nextlinecol = MAXCOL; |
| 3102 | nextline_idx = 0; |
| 3103 | } |
| 3104 | else |
| 3105 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3106 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3107 | if (v < SPWORDLEN) |
| 3108 | { |
| 3109 | /* Short line, use it completely and append the start of the |
| 3110 | * next line. */ |
| 3111 | nextlinecol = 0; |
| 3112 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3113 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3114 | nextline_idx = v + 1; |
| 3115 | } |
| 3116 | else |
| 3117 | { |
| 3118 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3119 | nextlinecol = v - SPWORDLEN; |
| 3120 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3121 | nextline_idx = SPWORDLEN + 1; |
| 3122 | } |
| 3123 | } |
| 3124 | } |
| 3125 | #endif |
| 3126 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3127 | /* find start of trailing whitespace */ |
| 3128 | if (wp->w_p_list && lcs_trail) |
| 3129 | { |
| 3130 | trailcol = (colnr_T)STRLEN(ptr); |
| 3131 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3132 | --trailcol; |
| 3133 | trailcol += (colnr_T) (ptr - line); |
| 3134 | extra_check = TRUE; |
| 3135 | } |
| 3136 | |
| 3137 | /* |
| 3138 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3139 | * first character to be displayed. |
| 3140 | */ |
| 3141 | if (wp->w_p_wrap) |
| 3142 | v = wp->w_skipcol; |
| 3143 | else |
| 3144 | v = wp->w_leftcol; |
| 3145 | if (v > 0) |
| 3146 | { |
| 3147 | #ifdef FEAT_MBYTE |
| 3148 | char_u *prev_ptr = ptr; |
| 3149 | #endif |
| 3150 | while (vcol < v && *ptr != NUL) |
| 3151 | { |
| 3152 | c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); |
| 3153 | vcol += c; |
| 3154 | #ifdef FEAT_MBYTE |
| 3155 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3156 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3157 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3160 | #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
| 3161 | /* When: |
| 3162 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3163 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3164 | * - 'virtualedit' is set, or |
| 3165 | * - the visual mode is active, |
| 3166 | * the end of the line may be before the start of the displayed part. |
| 3167 | */ |
| 3168 | if (vcol < v && ( |
| 3169 | # ifdef FEAT_SYN_HL |
| 3170 | wp->w_p_cuc |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3171 | || draw_color_col |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3172 | # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
| 3173 | || |
| 3174 | # endif |
| 3175 | # endif |
| 3176 | # ifdef FEAT_VIRTUALEDIT |
| 3177 | virtual_active() |
| 3178 | # ifdef FEAT_VISUAL |
| 3179 | || |
| 3180 | # endif |
| 3181 | # endif |
| 3182 | # ifdef FEAT_VISUAL |
| 3183 | (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3184 | # endif |
| 3185 | )) |
| 3186 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3187 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3188 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3189 | #endif |
| 3190 | |
| 3191 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3192 | * that character but skip the first few screen characters. */ |
| 3193 | if (vcol > v) |
| 3194 | { |
| 3195 | vcol -= c; |
| 3196 | #ifdef FEAT_MBYTE |
| 3197 | ptr = prev_ptr; |
| 3198 | #else |
| 3199 | --ptr; |
| 3200 | #endif |
| 3201 | n_skip = v - vcol; |
| 3202 | } |
| 3203 | |
| 3204 | /* |
| 3205 | * Adjust for when the inverted text is before the screen, |
| 3206 | * and when the start of the inverted text is before the screen. |
| 3207 | */ |
| 3208 | if (tocol <= vcol) |
| 3209 | fromcol = 0; |
| 3210 | else if (fromcol >= 0 && fromcol < vcol) |
| 3211 | fromcol = vcol; |
| 3212 | |
| 3213 | #ifdef FEAT_LINEBREAK |
| 3214 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3215 | if (wp->w_p_wrap) |
| 3216 | need_showbreak = TRUE; |
| 3217 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3218 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3219 | /* When spell checking a word we need to figure out the start of the |
| 3220 | * word and if it's badly spelled or not. */ |
| 3221 | if (has_spell) |
| 3222 | { |
| 3223 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3224 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3225 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3226 | |
| 3227 | pos = wp->w_cursor; |
| 3228 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3229 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3230 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3231 | |
| 3232 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3233 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3234 | ptr = line + linecol; |
| 3235 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3236 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3237 | { |
| 3238 | /* no bad word found at line start, don't check until end of a |
| 3239 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3240 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3241 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3242 | } |
| 3243 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3244 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3245 | /* bad word found, use attributes until end of word */ |
| 3246 | word_end = wp->w_cursor.col + len + 1; |
| 3247 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3248 | /* Turn index into actual attributes. */ |
| 3249 | if (spell_hlf != HLF_COUNT) |
| 3250 | spell_attr = highlight_attr[spell_hlf]; |
| 3251 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3252 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3253 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3254 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3255 | /* Need to restart syntax highlighting for this line. */ |
| 3256 | if (has_syntax) |
| 3257 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3258 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3259 | } |
| 3260 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | /* |
| 3264 | * Correct highlighting for cursor that can't be disabled. |
| 3265 | * Avoids having to check this for each character. |
| 3266 | */ |
| 3267 | if (fromcol >= 0) |
| 3268 | { |
| 3269 | if (noinvcur) |
| 3270 | { |
| 3271 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3272 | { |
| 3273 | /* highlighting starts at cursor, let it start just after the |
| 3274 | * cursor */ |
| 3275 | fromcol_prev = fromcol; |
| 3276 | fromcol = -1; |
| 3277 | } |
| 3278 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3279 | /* restart highlighting after the cursor */ |
| 3280 | fromcol_prev = wp->w_virtcol; |
| 3281 | } |
| 3282 | if (fromcol >= tocol) |
| 3283 | fromcol = -1; |
| 3284 | } |
| 3285 | |
| 3286 | #ifdef FEAT_SEARCH_EXTRA |
| 3287 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3288 | * Handle highlighting the last used search pattern and matches. |
| 3289 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3290 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3291 | cur = wp->w_match_head; |
| 3292 | shl_flag = FALSE; |
| 3293 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3294 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3295 | if (shl_flag == FALSE) |
| 3296 | { |
| 3297 | shl = &search_hl; |
| 3298 | shl_flag = TRUE; |
| 3299 | } |
| 3300 | else |
| 3301 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3302 | shl->startcol = MAXCOL; |
| 3303 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3304 | shl->attr_cur = 0; |
| 3305 | if (shl->rm.regprog != NULL) |
| 3306 | { |
| 3307 | v = (long)(ptr - line); |
| 3308 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3309 | |
| 3310 | /* Need to get the line again, a multi-line regexp may have made it |
| 3311 | * invalid. */ |
| 3312 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3313 | ptr = line + v; |
| 3314 | |
| 3315 | if (shl->lnum != 0 && shl->lnum <= lnum) |
| 3316 | { |
| 3317 | if (shl->lnum == lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3318 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3319 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3320 | shl->startcol = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3321 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3322 | - shl->rm.startpos[0].lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3323 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3324 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3325 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3326 | /* Highlight one character for an empty match. */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3327 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3328 | { |
| 3329 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3330 | if (has_mbyte && line[shl->endcol] != NUL) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3331 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3332 | else |
| 3333 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3334 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3335 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3336 | if ((long)shl->startcol < v) /* match at leftcol */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3337 | { |
| 3338 | shl->attr_cur = shl->attr; |
| 3339 | search_attr = shl->attr; |
| 3340 | } |
| 3341 | area_highlighting = TRUE; |
| 3342 | } |
| 3343 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3344 | if (shl != &search_hl && cur != NULL) |
| 3345 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3346 | } |
| 3347 | #endif |
| 3348 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3349 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame] | 3350 | /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
| 3351 | * active, because it's not clear what is selected then. */ |
| 3352 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3353 | { |
| 3354 | line_attr = hl_attr(HLF_CUL); |
| 3355 | area_highlighting = TRUE; |
| 3356 | } |
| 3357 | #endif |
| 3358 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3359 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3360 | col = 0; |
| 3361 | #ifdef FEAT_RIGHTLEFT |
| 3362 | if (wp->w_p_rl) |
| 3363 | { |
| 3364 | /* Rightleft window: process the text in the normal direction, but put |
| 3365 | * it in current_ScreenLine[] from right to left. Start at the |
| 3366 | * rightmost column of the window. */ |
| 3367 | col = W_WIDTH(wp) - 1; |
| 3368 | off += col; |
| 3369 | } |
| 3370 | #endif |
| 3371 | |
| 3372 | /* |
| 3373 | * Repeat for the whole displayed line. |
| 3374 | */ |
| 3375 | for (;;) |
| 3376 | { |
| 3377 | /* Skip this quickly when working on the text. */ |
| 3378 | if (draw_state != WL_LINE) |
| 3379 | { |
| 3380 | #ifdef FEAT_CMDWIN |
| 3381 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3382 | { |
| 3383 | draw_state = WL_CMDLINE; |
| 3384 | if (cmdwin_type != 0 && wp == curwin) |
| 3385 | { |
| 3386 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3387 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3388 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3389 | char_attr = hl_attr(HLF_AT); |
| 3390 | } |
| 3391 | } |
| 3392 | #endif |
| 3393 | |
| 3394 | #ifdef FEAT_FOLDING |
| 3395 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3396 | { |
| 3397 | draw_state = WL_FOLD; |
| 3398 | if (wp->w_p_fdc > 0) |
| 3399 | { |
| 3400 | /* Draw the 'foldcolumn'. */ |
| 3401 | fill_foldcolumn(extra, wp, FALSE, lnum); |
| 3402 | n_extra = wp->w_p_fdc; |
| 3403 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3404 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3405 | c_extra = NUL; |
| 3406 | char_attr = hl_attr(HLF_FC); |
| 3407 | } |
| 3408 | } |
| 3409 | #endif |
| 3410 | |
| 3411 | #ifdef FEAT_SIGNS |
| 3412 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3413 | { |
| 3414 | draw_state = WL_SIGN; |
| 3415 | /* Show the sign column when there are any signs in this |
| 3416 | * buffer or when using Netbeans. */ |
| 3417 | if (draw_signcolumn(wp) |
| 3418 | # ifdef FEAT_DIFF |
| 3419 | && filler_todo <= 0 |
| 3420 | # endif |
| 3421 | ) |
| 3422 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3423 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3424 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3425 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3426 | # endif |
| 3427 | |
| 3428 | /* Draw two cells with the sign value or blank. */ |
| 3429 | c_extra = ' '; |
| 3430 | char_attr = hl_attr(HLF_SC); |
| 3431 | n_extra = 2; |
| 3432 | |
| 3433 | if (row == startrow) |
| 3434 | { |
| 3435 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3436 | SIGN_TEXT); |
| 3437 | # ifdef FEAT_SIGN_ICONS |
| 3438 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3439 | SIGN_ICON); |
| 3440 | if (gui.in_use && icon_sign != 0) |
| 3441 | { |
| 3442 | /* Use the image in this position. */ |
| 3443 | c_extra = SIGN_BYTE; |
| 3444 | # ifdef FEAT_NETBEANS_INTG |
| 3445 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3446 | c_extra = MULTISIGN_BYTE; |
| 3447 | # endif |
| 3448 | char_attr = icon_sign; |
| 3449 | } |
| 3450 | else |
| 3451 | # endif |
| 3452 | if (text_sign != 0) |
| 3453 | { |
| 3454 | p_extra = sign_get_text(text_sign); |
| 3455 | if (p_extra != NULL) |
| 3456 | { |
| 3457 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3458 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3459 | } |
| 3460 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3461 | } |
| 3462 | } |
| 3463 | } |
| 3464 | } |
| 3465 | #endif |
| 3466 | |
| 3467 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3468 | { |
| 3469 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3470 | /* Display the absolute or relative line number. After the |
| 3471 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3472 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3473 | && (row == startrow |
| 3474 | #ifdef FEAT_DIFF |
| 3475 | + filler_lines |
| 3476 | #endif |
| 3477 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3478 | { |
| 3479 | /* Draw the line number (empty space after wrapping). */ |
| 3480 | if (row == startrow |
| 3481 | #ifdef FEAT_DIFF |
| 3482 | + filler_lines |
| 3483 | #endif |
| 3484 | ) |
| 3485 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3486 | long num; |
| 3487 | |
| 3488 | if (wp->w_p_nu) |
| 3489 | /* 'number' */ |
| 3490 | num = (long)lnum; |
| 3491 | else |
| 3492 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3493 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3494 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3495 | sprintf((char *)extra, "%*ld ", |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3496 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3497 | if (wp->w_skipcol > 0) |
| 3498 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3499 | *p_extra = '-'; |
| 3500 | #ifdef FEAT_RIGHTLEFT |
| 3501 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3502 | rl_mirror(extra); |
| 3503 | #endif |
| 3504 | p_extra = extra; |
| 3505 | c_extra = NUL; |
| 3506 | } |
| 3507 | else |
| 3508 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3509 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3510 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3511 | #ifdef FEAT_SYN_HL |
| 3512 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3513 | * the current line differently. |
| 3514 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3515 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3516 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3517 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3518 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3523 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3524 | { |
| 3525 | draw_state = WL_SBR; |
| 3526 | # ifdef FEAT_DIFF |
| 3527 | if (filler_todo > 0) |
| 3528 | { |
| 3529 | /* Draw "deleted" diff line(s). */ |
| 3530 | if (char2cells(fill_diff) > 1) |
| 3531 | c_extra = '-'; |
| 3532 | else |
| 3533 | c_extra = fill_diff; |
| 3534 | # ifdef FEAT_RIGHTLEFT |
| 3535 | if (wp->w_p_rl) |
| 3536 | n_extra = col + 1; |
| 3537 | else |
| 3538 | # endif |
| 3539 | n_extra = W_WIDTH(wp) - col; |
| 3540 | char_attr = hl_attr(HLF_DED); |
| 3541 | } |
| 3542 | # endif |
| 3543 | # ifdef FEAT_LINEBREAK |
| 3544 | if (*p_sbr != NUL && need_showbreak) |
| 3545 | { |
| 3546 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3547 | p_extra = p_sbr; |
| 3548 | c_extra = NUL; |
| 3549 | n_extra = (int)STRLEN(p_sbr); |
| 3550 | char_attr = hl_attr(HLF_AT); |
| 3551 | need_showbreak = FALSE; |
| 3552 | /* Correct end of highlighted area for 'showbreak', |
| 3553 | * required when 'linebreak' is also set. */ |
| 3554 | if (tocol == vcol) |
| 3555 | tocol += n_extra; |
| 3556 | } |
| 3557 | # endif |
| 3558 | } |
| 3559 | #endif |
| 3560 | |
| 3561 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3562 | { |
| 3563 | draw_state = WL_LINE; |
| 3564 | if (saved_n_extra) |
| 3565 | { |
| 3566 | /* Continue item from end of wrapped line. */ |
| 3567 | n_extra = saved_n_extra; |
| 3568 | c_extra = saved_c_extra; |
| 3569 | p_extra = saved_p_extra; |
| 3570 | char_attr = saved_char_attr; |
| 3571 | } |
| 3572 | else |
| 3573 | char_attr = 0; |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3578 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3579 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3580 | #ifdef FEAT_DIFF |
| 3581 | && filler_todo <= 0 |
| 3582 | #endif |
| 3583 | ) |
| 3584 | { |
| 3585 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3586 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3587 | /* Pretend we have finished updating the window. Except when |
| 3588 | * 'cursorcolumn' is set. */ |
| 3589 | #ifdef FEAT_SYN_HL |
| 3590 | if (wp->w_p_cuc) |
| 3591 | row = wp->w_cline_row + wp->w_cline_height; |
| 3592 | else |
| 3593 | #endif |
| 3594 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
| 3597 | |
| 3598 | if (draw_state == WL_LINE && area_highlighting) |
| 3599 | { |
| 3600 | /* handle Visual or match highlighting in this line */ |
| 3601 | if (vcol == fromcol |
| 3602 | #ifdef FEAT_MBYTE |
| 3603 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3604 | && (*mb_ptr2cells)(ptr) > 1) |
| 3605 | #endif |
| 3606 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3607 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3608 | && vcol < tocol)) |
| 3609 | area_attr = attr; /* start highlighting */ |
| 3610 | else if (area_attr != 0 |
| 3611 | && (vcol == tocol |
| 3612 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3613 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3614 | |
| 3615 | #ifdef FEAT_SEARCH_EXTRA |
| 3616 | if (!n_extra) |
| 3617 | { |
| 3618 | /* |
| 3619 | * Check for start/end of search pattern match. |
| 3620 | * After end, check for start/end of next match. |
| 3621 | * When another match, have to check for start again. |
| 3622 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3623 | * Do this for 'search_hl' and the match list (ordered by |
| 3624 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3625 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3626 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3627 | cur = wp->w_match_head; |
| 3628 | shl_flag = FALSE; |
| 3629 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3630 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3631 | if (shl_flag == FALSE |
| 3632 | && ((cur != NULL |
| 3633 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3634 | || cur == NULL)) |
| 3635 | { |
| 3636 | shl = &search_hl; |
| 3637 | shl_flag = TRUE; |
| 3638 | } |
| 3639 | else |
| 3640 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3641 | while (shl->rm.regprog != NULL) |
| 3642 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3643 | if (shl->startcol != MAXCOL |
| 3644 | && v >= (long)shl->startcol |
| 3645 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3646 | { |
| 3647 | shl->attr_cur = shl->attr; |
| 3648 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3649 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3650 | { |
| 3651 | shl->attr_cur = 0; |
| 3652 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3653 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3654 | |
| 3655 | /* Need to get the line again, a multi-line regexp |
| 3656 | * may have made it invalid. */ |
| 3657 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3658 | ptr = line + v; |
| 3659 | |
| 3660 | if (shl->lnum == lnum) |
| 3661 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3662 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3663 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3664 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3665 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3666 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3667 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3668 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3669 | { |
| 3670 | /* highlight empty match, try again after |
| 3671 | * it */ |
| 3672 | #ifdef FEAT_MBYTE |
| 3673 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3674 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3675 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3676 | else |
| 3677 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3678 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | /* Loop to check if the match starts at the |
| 3682 | * current position */ |
| 3683 | continue; |
| 3684 | } |
| 3685 | } |
| 3686 | break; |
| 3687 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3688 | if (shl != &search_hl && cur != NULL) |
| 3689 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3690 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3691 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3692 | /* Use attributes from match with highest priority among |
| 3693 | * 'search_hl' and the match list. */ |
| 3694 | search_attr = search_hl.attr_cur; |
| 3695 | cur = wp->w_match_head; |
| 3696 | shl_flag = FALSE; |
| 3697 | while (cur != NULL || shl_flag == FALSE) |
| 3698 | { |
| 3699 | if (shl_flag == FALSE |
| 3700 | && ((cur != NULL |
| 3701 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3702 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3703 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3704 | shl = &search_hl; |
| 3705 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3706 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3707 | else |
| 3708 | shl = &cur->hl; |
| 3709 | if (shl->attr_cur != 0) |
| 3710 | search_attr = shl->attr_cur; |
| 3711 | if (shl != &search_hl && cur != NULL) |
| 3712 | cur = cur->next; |
| 3713 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3714 | } |
| 3715 | #endif |
| 3716 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3717 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3718 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3719 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3720 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 3721 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3722 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3723 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 3724 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3725 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3726 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3727 | } |
| 3728 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3729 | |
| 3730 | /* Decide which of the highlight attributes to use. */ |
| 3731 | attr_pri = TRUE; |
| 3732 | if (area_attr != 0) |
| 3733 | char_attr = area_attr; |
| 3734 | else if (search_attr != 0) |
| 3735 | char_attr = search_attr; |
| 3736 | #ifdef LINE_ATTR |
| 3737 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 3738 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 3739 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 3740 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 3741 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3742 | char_attr = line_attr; |
| 3743 | #endif |
| 3744 | else |
| 3745 | { |
| 3746 | attr_pri = FALSE; |
| 3747 | #ifdef FEAT_SYN_HL |
| 3748 | if (has_syntax) |
| 3749 | char_attr = syntax_attr; |
| 3750 | else |
| 3751 | #endif |
| 3752 | char_attr = 0; |
| 3753 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | /* |
| 3757 | * Get the next character to put on the screen. |
| 3758 | */ |
| 3759 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3760 | * The "p_extra" points to the extra stuff that is inserted to |
| 3761 | * represent special characters (non-printable stuff) and other |
| 3762 | * things. When all characters are the same, c_extra is used. |
| 3763 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 3764 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3765 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 3766 | */ |
| 3767 | if (n_extra > 0) |
| 3768 | { |
| 3769 | if (c_extra != NUL) |
| 3770 | { |
| 3771 | c = c_extra; |
| 3772 | #ifdef FEAT_MBYTE |
| 3773 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 3774 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3775 | { |
| 3776 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3777 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3778 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3779 | } |
| 3780 | else |
| 3781 | mb_utf8 = FALSE; |
| 3782 | #endif |
| 3783 | } |
| 3784 | else |
| 3785 | { |
| 3786 | c = *p_extra; |
| 3787 | #ifdef FEAT_MBYTE |
| 3788 | if (has_mbyte) |
| 3789 | { |
| 3790 | mb_c = c; |
| 3791 | if (enc_utf8) |
| 3792 | { |
| 3793 | /* If the UTF-8 character is more than one byte: |
| 3794 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3795 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3796 | mb_utf8 = FALSE; |
| 3797 | if (mb_l > n_extra) |
| 3798 | mb_l = 1; |
| 3799 | else if (mb_l > 1) |
| 3800 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3801 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3802 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3803 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | else |
| 3807 | { |
| 3808 | /* if this is a DBCS character, put it in "mb_c" */ |
| 3809 | mb_l = MB_BYTE2LEN(c); |
| 3810 | if (mb_l >= n_extra) |
| 3811 | mb_l = 1; |
| 3812 | else if (mb_l > 1) |
| 3813 | mb_c = (c << 8) + p_extra[1]; |
| 3814 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3815 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3816 | mb_l = 1; |
| 3817 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3818 | /* If a double-width char doesn't fit display a '>' in the |
| 3819 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3820 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3821 | # ifdef FEAT_RIGHTLEFT |
| 3822 | wp->w_p_rl ? (col <= 0) : |
| 3823 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3824 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3825 | && (*mb_char2cells)(mb_c) == 2) |
| 3826 | { |
| 3827 | c = '>'; |
| 3828 | mb_c = c; |
| 3829 | mb_l = 1; |
| 3830 | mb_utf8 = FALSE; |
| 3831 | multi_attr = hl_attr(HLF_AT); |
| 3832 | /* put the pointer back to output the double-width |
| 3833 | * character at the start of the next line. */ |
| 3834 | ++n_extra; |
| 3835 | --p_extra; |
| 3836 | } |
| 3837 | else |
| 3838 | { |
| 3839 | n_extra -= mb_l - 1; |
| 3840 | p_extra += mb_l - 1; |
| 3841 | } |
| 3842 | } |
| 3843 | #endif |
| 3844 | ++p_extra; |
| 3845 | } |
| 3846 | --n_extra; |
| 3847 | } |
| 3848 | else |
| 3849 | { |
| 3850 | /* |
| 3851 | * Get a character from the line itself. |
| 3852 | */ |
| 3853 | c = *ptr; |
| 3854 | #ifdef FEAT_MBYTE |
| 3855 | if (has_mbyte) |
| 3856 | { |
| 3857 | mb_c = c; |
| 3858 | if (enc_utf8) |
| 3859 | { |
| 3860 | /* If the UTF-8 character is more than one byte: Decode it |
| 3861 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3862 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3863 | mb_utf8 = FALSE; |
| 3864 | if (mb_l > 1) |
| 3865 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3866 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3867 | /* Overlong encoded ASCII or ASCII with composing char |
| 3868 | * is displayed normally, except a NUL. */ |
| 3869 | if (mb_c < 0x80) |
| 3870 | c = mb_c; |
| 3871 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3872 | |
| 3873 | /* At start of the line we can have a composing char. |
| 3874 | * Draw it as a space with a composing char. */ |
| 3875 | if (utf_iscomposing(mb_c)) |
| 3876 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3877 | int i; |
| 3878 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3879 | for (i = Screen_mco - 1; i > 0; --i) |
| 3880 | u8cc[i] = u8cc[i - 1]; |
| 3881 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3882 | mb_c = ' '; |
| 3883 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | if ((mb_l == 1 && c >= 0x80) |
| 3887 | || (mb_l >= 1 && mb_c == 0) |
| 3888 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3889 | # ifdef UNICODE16 |
| 3890 | || mb_c >= 0x10000 |
| 3891 | # endif |
| 3892 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3893 | { |
| 3894 | /* |
| 3895 | * Illegal UTF-8 byte: display as <xx>. |
| 3896 | * Non-BMP character : display as ? or fullwidth ?. |
| 3897 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3898 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3899 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3900 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3901 | { |
| 3902 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3903 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3904 | if (wp->w_p_rl) /* reverse */ |
| 3905 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3906 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3907 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3908 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3909 | else if (utf_char2cells(mb_c) != 2) |
| 3910 | STRCPY(extra, "?"); |
| 3911 | else |
| 3912 | /* 0xff1f in UTF-8: full-width '?' */ |
| 3913 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3914 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3915 | |
| 3916 | p_extra = extra; |
| 3917 | c = *p_extra; |
| 3918 | mb_c = mb_ptr2char_adv(&p_extra); |
| 3919 | mb_utf8 = (c >= 0x80); |
| 3920 | n_extra = (int)STRLEN(p_extra); |
| 3921 | c_extra = NUL; |
| 3922 | if (area_attr == 0 && search_attr == 0) |
| 3923 | { |
| 3924 | n_attr = n_extra + 1; |
| 3925 | extra_attr = hl_attr(HLF_8); |
| 3926 | saved_attr2 = char_attr; /* save current attr */ |
| 3927 | } |
| 3928 | } |
| 3929 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3930 | mb_l = 1; |
| 3931 | #ifdef FEAT_ARABIC |
| 3932 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 3933 | { |
| 3934 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3935 | int pc, pc1, nc; |
| 3936 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3937 | |
| 3938 | /* The idea of what is the previous and next |
| 3939 | * character depends on 'rightleft'. */ |
| 3940 | if (wp->w_p_rl) |
| 3941 | { |
| 3942 | pc = prev_c; |
| 3943 | pc1 = prev_c1; |
| 3944 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3945 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3946 | } |
| 3947 | else |
| 3948 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3949 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3950 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3951 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3952 | } |
| 3953 | prev_c = mb_c; |
| 3954 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3955 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3956 | } |
| 3957 | else |
| 3958 | prev_c = mb_c; |
| 3959 | #endif |
| 3960 | } |
| 3961 | else /* enc_dbcs */ |
| 3962 | { |
| 3963 | mb_l = MB_BYTE2LEN(c); |
| 3964 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3965 | mb_l = 1; |
| 3966 | else if (mb_l > 1) |
| 3967 | { |
| 3968 | /* We assume a second byte below 32 is illegal. |
| 3969 | * Hopefully this is OK for all double-byte encodings! |
| 3970 | */ |
| 3971 | if (ptr[1] >= 32) |
| 3972 | mb_c = (c << 8) + ptr[1]; |
| 3973 | else |
| 3974 | { |
| 3975 | if (ptr[1] == NUL) |
| 3976 | { |
| 3977 | /* head byte at end of line */ |
| 3978 | mb_l = 1; |
| 3979 | transchar_nonprint(extra, c); |
| 3980 | } |
| 3981 | else |
| 3982 | { |
| 3983 | /* illegal tail byte */ |
| 3984 | mb_l = 2; |
| 3985 | STRCPY(extra, "XX"); |
| 3986 | } |
| 3987 | p_extra = extra; |
| 3988 | n_extra = (int)STRLEN(extra) - 1; |
| 3989 | c_extra = NUL; |
| 3990 | c = *p_extra++; |
| 3991 | if (area_attr == 0 && search_attr == 0) |
| 3992 | { |
| 3993 | n_attr = n_extra + 1; |
| 3994 | extra_attr = hl_attr(HLF_8); |
| 3995 | saved_attr2 = char_attr; /* save current attr */ |
| 3996 | } |
| 3997 | mb_c = c; |
| 3998 | } |
| 3999 | } |
| 4000 | } |
| 4001 | /* If a double-width char doesn't fit display a '>' in the |
| 4002 | * last column; the character is displayed at the start of the |
| 4003 | * next line. */ |
| 4004 | if (( |
| 4005 | # ifdef FEAT_RIGHTLEFT |
| 4006 | wp->w_p_rl ? (col <= 0) : |
| 4007 | # endif |
| 4008 | (col >= W_WIDTH(wp) - 1)) |
| 4009 | && (*mb_char2cells)(mb_c) == 2) |
| 4010 | { |
| 4011 | c = '>'; |
| 4012 | mb_c = c; |
| 4013 | mb_utf8 = FALSE; |
| 4014 | mb_l = 1; |
| 4015 | multi_attr = hl_attr(HLF_AT); |
| 4016 | /* Put pointer back so that the character will be |
| 4017 | * displayed at the start of the next line. */ |
| 4018 | --ptr; |
| 4019 | } |
| 4020 | else if (*ptr != NUL) |
| 4021 | ptr += mb_l - 1; |
| 4022 | |
| 4023 | /* If a double-width char doesn't fit at the left side display |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4024 | * a '<' in the first column. Don't do this for unprintable |
| 4025 | * charactes. */ |
| 4026 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4027 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4028 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4029 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4030 | c = ' '; |
| 4031 | if (area_attr == 0 && search_attr == 0) |
| 4032 | { |
| 4033 | n_attr = n_extra + 1; |
| 4034 | extra_attr = hl_attr(HLF_AT); |
| 4035 | saved_attr2 = char_attr; /* save current attr */ |
| 4036 | } |
| 4037 | mb_c = c; |
| 4038 | mb_utf8 = FALSE; |
| 4039 | mb_l = 1; |
| 4040 | } |
| 4041 | |
| 4042 | } |
| 4043 | #endif |
| 4044 | ++ptr; |
| 4045 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4046 | /* 'list' : change char 160 to lcs_nbsp. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4047 | if (wp->w_p_list && (c == 160 |
| 4048 | #ifdef FEAT_MBYTE |
| 4049 | || (mb_utf8 && mb_c == 160) |
| 4050 | #endif |
| 4051 | ) && lcs_nbsp) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4052 | { |
| 4053 | c = lcs_nbsp; |
| 4054 | if (area_attr == 0 && search_attr == 0) |
| 4055 | { |
| 4056 | n_attr = 1; |
| 4057 | extra_attr = hl_attr(HLF_8); |
| 4058 | saved_attr2 = char_attr; /* save current attr */ |
| 4059 | } |
| 4060 | #ifdef FEAT_MBYTE |
| 4061 | mb_c = c; |
| 4062 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4063 | { |
| 4064 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4065 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4066 | c = 0xc0; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4067 | } |
| 4068 | else |
| 4069 | mb_utf8 = FALSE; |
| 4070 | #endif |
| 4071 | } |
| 4072 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4073 | if (extra_check) |
| 4074 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4075 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4076 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4077 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4078 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4079 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4080 | /* Get syntax attribute, unless still at the start of the line |
| 4081 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4082 | v = (long)(ptr - line); |
| 4083 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4084 | { |
| 4085 | /* Get the syntax attribute for the character. If there |
| 4086 | * is an error, disable syntax highlighting. */ |
| 4087 | save_did_emsg = did_emsg; |
| 4088 | did_emsg = FALSE; |
| 4089 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4090 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4091 | # ifdef FEAT_SPELL |
| 4092 | has_spell ? &can_spell : |
| 4093 | # endif |
| 4094 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4095 | |
| 4096 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4097 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4098 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4099 | has_syntax = FALSE; |
| 4100 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4101 | else |
| 4102 | did_emsg = save_did_emsg; |
| 4103 | |
| 4104 | /* Need to get the line again, a multi-line regexp may |
| 4105 | * have made it invalid. */ |
| 4106 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4107 | ptr = line + v; |
| 4108 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4109 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4110 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4111 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4112 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4113 | # ifdef FEAT_CONCEAL |
| 4114 | /* no concealing past the end of the line, it interferes |
| 4115 | * with line highlighting */ |
| 4116 | if (c == NUL) |
| 4117 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4118 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4119 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4120 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4121 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4122 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4123 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4124 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4125 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4126 | * Only do this when there is no syntax highlighting, the |
| 4127 | * @Spell cluster is not used or the current syntax item |
| 4128 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4129 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4130 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4131 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4132 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4133 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4134 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4135 | # endif |
| 4136 | if (c != 0 && ( |
| 4137 | # ifdef FEAT_SYN_HL |
| 4138 | !has_syntax || |
| 4139 | # endif |
| 4140 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4141 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4142 | char_u *prev_ptr, *p; |
| 4143 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4144 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4145 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4146 | if (has_mbyte) |
| 4147 | { |
| 4148 | prev_ptr = ptr - mb_l; |
| 4149 | v -= mb_l - 1; |
| 4150 | } |
| 4151 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4152 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4153 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4154 | |
| 4155 | /* Use nextline[] if possible, it has the start of the |
| 4156 | * next line concatenated. */ |
| 4157 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4158 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4159 | else |
| 4160 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4161 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4162 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4163 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4164 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4165 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4166 | /* In Insert mode only highlight a word that |
| 4167 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4168 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4169 | && (State & INSERT) != 0 |
| 4170 | && wp->w_cursor.lnum == lnum |
| 4171 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4172 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4173 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4174 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4175 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4176 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4177 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4178 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4179 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4180 | && (p - nextline) + len > nextline_idx) |
| 4181 | { |
| 4182 | /* Remember that the good word continues at the |
| 4183 | * start of the next line. */ |
| 4184 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4185 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4186 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4187 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4188 | /* Turn index into actual attributes. */ |
| 4189 | if (spell_hlf != HLF_COUNT) |
| 4190 | spell_attr = highlight_attr[spell_hlf]; |
| 4191 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4192 | if (cap_col > 0) |
| 4193 | { |
| 4194 | if (p != prev_ptr |
| 4195 | && (p - nextline) + cap_col >= nextline_idx) |
| 4196 | { |
| 4197 | /* Remember that the word in the next line |
| 4198 | * must start with a capital. */ |
| 4199 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4200 | cap_col = (int)((p - nextline) + cap_col |
| 4201 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4202 | } |
| 4203 | else |
| 4204 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4205 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4206 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4207 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4208 | } |
| 4209 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4210 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4211 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4212 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4213 | else |
| 4214 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4215 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4216 | #endif |
| 4217 | #ifdef FEAT_LINEBREAK |
| 4218 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4219 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4220 | */ |
| 4221 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4222 | && !wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4223 | { |
| 4224 | n_extra = win_lbr_chartabsize(wp, ptr - ( |
| 4225 | # ifdef FEAT_MBYTE |
| 4226 | has_mbyte ? mb_l : |
| 4227 | # endif |
| 4228 | 1), (colnr_T)vcol, NULL) - 1; |
| 4229 | c_extra = ' '; |
| 4230 | if (vim_iswhite(c)) |
| 4231 | c = ' '; |
| 4232 | } |
| 4233 | #endif |
| 4234 | |
| 4235 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4236 | { |
| 4237 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4238 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4239 | { |
| 4240 | n_attr = 1; |
| 4241 | extra_attr = hl_attr(HLF_8); |
| 4242 | saved_attr2 = char_attr; /* save current attr */ |
| 4243 | } |
| 4244 | #ifdef FEAT_MBYTE |
| 4245 | mb_c = c; |
| 4246 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4247 | { |
| 4248 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4249 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4250 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4251 | } |
| 4252 | else |
| 4253 | mb_utf8 = FALSE; |
| 4254 | #endif |
| 4255 | } |
| 4256 | } |
| 4257 | |
| 4258 | /* |
| 4259 | * Handling of non-printable characters. |
| 4260 | */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4261 | if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4262 | { |
| 4263 | /* |
| 4264 | * when getting a character from the file, we may have to |
| 4265 | * turn it into something else on the way to putting it |
| 4266 | * into "ScreenLines". |
| 4267 | */ |
| 4268 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4269 | { |
| 4270 | /* tab amount depends on current column */ |
| 4271 | n_extra = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | 8a20b0f | 2011-08-10 14:32:39 +0200 | [diff] [blame] | 4272 | - VCOL_HLC % (int)wp->w_buffer->b_p_ts - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4273 | #ifdef FEAT_MBYTE |
| 4274 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4275 | #endif |
| 4276 | if (wp->w_p_list) |
| 4277 | { |
| 4278 | c = lcs_tab1; |
| 4279 | c_extra = lcs_tab2; |
| 4280 | n_attr = n_extra + 1; |
| 4281 | extra_attr = hl_attr(HLF_8); |
| 4282 | saved_attr2 = char_attr; /* save current attr */ |
| 4283 | #ifdef FEAT_MBYTE |
| 4284 | mb_c = c; |
| 4285 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4286 | { |
| 4287 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4288 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4289 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4290 | } |
| 4291 | #endif |
| 4292 | } |
| 4293 | else |
| 4294 | { |
| 4295 | c_extra = ' '; |
| 4296 | c = ' '; |
| 4297 | } |
| 4298 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4299 | else if (c == NUL |
| 4300 | && ((wp->w_p_list && lcs_eol > 0) |
| 4301 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4302 | && tocol > vcol |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4303 | #ifdef FEAT_VISUAL |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4304 | && VIsual_mode != Ctrl_V |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4305 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4306 | && ( |
| 4307 | # ifdef FEAT_RIGHTLEFT |
| 4308 | wp->w_p_rl ? (col >= 0) : |
| 4309 | # endif |
| 4310 | (col < W_WIDTH(wp))) |
| 4311 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4312 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4313 | && (colnr_T)vcol == wp->w_virtcol))) |
| 4314 | && lcs_eol_one >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4315 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4316 | /* Display a '$' after the line or highlight an extra |
| 4317 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4318 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4319 | /* For a diff line the highlighting continues after the |
| 4320 | * "$". */ |
| 4321 | if ( |
| 4322 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4323 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4324 | # ifdef LINE_ATTR |
| 4325 | && |
| 4326 | # endif |
| 4327 | # endif |
| 4328 | # ifdef LINE_ATTR |
| 4329 | line_attr == 0 |
| 4330 | # endif |
| 4331 | ) |
| 4332 | #endif |
| 4333 | { |
| 4334 | #ifdef FEAT_VIRTUALEDIT |
| 4335 | /* In virtualedit, visual selections may extend |
| 4336 | * beyond end of line. */ |
| 4337 | if (area_highlighting && virtual_active() |
| 4338 | && tocol != MAXCOL && vcol < tocol) |
| 4339 | n_extra = 0; |
| 4340 | else |
| 4341 | #endif |
| 4342 | { |
| 4343 | p_extra = at_end_str; |
| 4344 | n_extra = 1; |
| 4345 | c_extra = NUL; |
| 4346 | } |
| 4347 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4348 | if (wp->w_p_list) |
| 4349 | c = lcs_eol; |
| 4350 | else |
| 4351 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4352 | lcs_eol_one = -1; |
| 4353 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4354 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4355 | { |
| 4356 | extra_attr = hl_attr(HLF_AT); |
| 4357 | n_attr = 1; |
| 4358 | } |
| 4359 | #ifdef FEAT_MBYTE |
| 4360 | mb_c = c; |
| 4361 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4362 | { |
| 4363 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4364 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4365 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4366 | } |
| 4367 | else |
| 4368 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4369 | #endif |
| 4370 | } |
| 4371 | else if (c != NUL) |
| 4372 | { |
| 4373 | p_extra = transchar(c); |
| 4374 | #ifdef FEAT_RIGHTLEFT |
| 4375 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4376 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4377 | #endif |
| 4378 | n_extra = byte2cells(c) - 1; |
| 4379 | c_extra = NUL; |
| 4380 | c = *p_extra++; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4381 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4382 | { |
| 4383 | n_attr = n_extra + 1; |
| 4384 | extra_attr = hl_attr(HLF_8); |
| 4385 | saved_attr2 = char_attr; /* save current attr */ |
| 4386 | } |
| 4387 | #ifdef FEAT_MBYTE |
| 4388 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4389 | #endif |
| 4390 | } |
| 4391 | #ifdef FEAT_VIRTUALEDIT |
| 4392 | else if (VIsual_active |
| 4393 | && (VIsual_mode == Ctrl_V |
| 4394 | || VIsual_mode == 'v') |
| 4395 | && virtual_active() |
| 4396 | && tocol != MAXCOL |
| 4397 | && vcol < tocol |
| 4398 | && ( |
| 4399 | # ifdef FEAT_RIGHTLEFT |
| 4400 | wp->w_p_rl ? (col >= 0) : |
| 4401 | # endif |
| 4402 | (col < W_WIDTH(wp)))) |
| 4403 | { |
| 4404 | c = ' '; |
| 4405 | --ptr; /* put it back at the NUL */ |
| 4406 | } |
| 4407 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4408 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4409 | else if (( |
| 4410 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4411 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4412 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4413 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4414 | ) && ( |
| 4415 | # ifdef FEAT_RIGHTLEFT |
| 4416 | wp->w_p_rl ? (col >= 0) : |
| 4417 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4418 | (col |
| 4419 | # ifdef FEAT_CONCEAL |
| 4420 | - boguscols |
| 4421 | # endif |
| 4422 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4423 | { |
| 4424 | /* Highlight until the right side of the window */ |
| 4425 | c = ' '; |
| 4426 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4427 | |
| 4428 | /* Remember we do the char for line highlighting. */ |
| 4429 | ++did_line_attr; |
| 4430 | |
| 4431 | /* don't do search HL for the rest of the line */ |
| 4432 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4433 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4434 | # ifdef FEAT_DIFF |
| 4435 | if (diff_hlf == HLF_TXD) |
| 4436 | { |
| 4437 | diff_hlf = HLF_CHD; |
| 4438 | if (attr == 0 || char_attr != attr) |
| 4439 | char_attr = hl_attr(diff_hlf); |
| 4440 | } |
| 4441 | # endif |
| 4442 | } |
| 4443 | #endif |
| 4444 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4445 | |
| 4446 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4447 | if ( wp->w_p_cole > 0 |
| 4448 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
| 4449 | conceal_cursor_line(wp)) |
Bram Moolenaar | f70e3d6 | 2010-07-24 13:15:07 +0200 | [diff] [blame] | 4450 | && (syntax_flags & HL_CONCEAL) != 0 |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4451 | && !(lnum_in_visual_area |
| 4452 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4453 | { |
| 4454 | char_attr = conceal_attr; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4455 | if (prev_syntax_id != syntax_seqnr |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4456 | && (syn_get_sub_char() != NUL || wp->w_p_cole == 1) |
| 4457 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4458 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4459 | /* First time at this concealed item: display one |
| 4460 | * character. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4461 | if (syn_get_sub_char() != NUL) |
| 4462 | c = syn_get_sub_char(); |
| 4463 | else if (lcs_conceal != NUL) |
| 4464 | c = lcs_conceal; |
| 4465 | else |
| 4466 | c = ' '; |
| 4467 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4468 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4469 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4470 | if (n_extra > 0) |
| 4471 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4472 | vcol += n_extra; |
| 4473 | if (wp->w_p_wrap && n_extra > 0) |
| 4474 | { |
| 4475 | # ifdef FEAT_RIGHTLEFT |
| 4476 | if (wp->w_p_rl) |
| 4477 | { |
| 4478 | col -= n_extra; |
| 4479 | boguscols -= n_extra; |
| 4480 | } |
| 4481 | else |
| 4482 | # endif |
| 4483 | { |
| 4484 | boguscols += n_extra; |
| 4485 | col += n_extra; |
| 4486 | } |
| 4487 | } |
| 4488 | n_extra = 0; |
| 4489 | n_attr = 0; |
| 4490 | } |
| 4491 | else if (n_skip == 0) |
| 4492 | { |
| 4493 | is_concealing = TRUE; |
| 4494 | n_skip = 1; |
| 4495 | } |
| 4496 | # ifdef FEAT_MBYTE |
| 4497 | mb_c = c; |
| 4498 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4499 | { |
| 4500 | mb_utf8 = TRUE; |
| 4501 | u8cc[0] = 0; |
| 4502 | c = 0xc0; |
| 4503 | } |
| 4504 | else |
| 4505 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4506 | # endif |
| 4507 | } |
| 4508 | else |
| 4509 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4510 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4511 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4512 | } |
| 4513 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4516 | #ifdef FEAT_CONCEAL |
| 4517 | /* In the cursor line and we may be concealing characters: correct |
| 4518 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 4519 | if (!did_wcol && draw_state == WL_LINE |
| 4520 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4521 | && conceal_cursor_line(wp) |
| 4522 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 4523 | { |
| 4524 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 4525 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4526 | did_wcol = TRUE; |
| 4527 | } |
| 4528 | #endif |
| 4529 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4530 | /* Don't override visual selection highlighting. */ |
| 4531 | if (n_attr > 0 |
| 4532 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4533 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4534 | char_attr = extra_attr; |
| 4535 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4536 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4537 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4538 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4539 | * im_is_preediting() here. */ |
| 4540 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4541 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4542 | && (State & INSERT) |
| 4543 | && !p_imdisable |
| 4544 | && im_is_preediting() |
| 4545 | && draw_state == WL_LINE) |
| 4546 | { |
| 4547 | colnr_T tcol; |
| 4548 | |
| 4549 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4550 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4551 | else |
| 4552 | tcol = preedit_end_col; |
| 4553 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 4554 | { |
| 4555 | if (feedback_old_attr < 0) |
| 4556 | { |
| 4557 | feedback_col = 0; |
| 4558 | feedback_old_attr = char_attr; |
| 4559 | } |
| 4560 | char_attr = im_get_feedback_attr(feedback_col); |
| 4561 | if (char_attr < 0) |
| 4562 | char_attr = feedback_old_attr; |
| 4563 | feedback_col++; |
| 4564 | } |
| 4565 | else if (feedback_old_attr >= 0) |
| 4566 | { |
| 4567 | char_attr = feedback_old_attr; |
| 4568 | feedback_old_attr = -1; |
| 4569 | feedback_col = 0; |
| 4570 | } |
| 4571 | } |
| 4572 | #endif |
| 4573 | /* |
| 4574 | * Handle the case where we are in column 0 but not on the first |
| 4575 | * character of the line and the user wants us to show us a |
| 4576 | * special character (via 'listchars' option "precedes:<char>". |
| 4577 | */ |
| 4578 | if (lcs_prec_todo != NUL |
| 4579 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 4580 | #ifdef FEAT_DIFF |
| 4581 | && filler_todo <= 0 |
| 4582 | #endif |
| 4583 | && draw_state > WL_NR |
| 4584 | && c != NUL) |
| 4585 | { |
| 4586 | c = lcs_prec; |
| 4587 | lcs_prec_todo = NUL; |
| 4588 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4589 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4590 | { |
| 4591 | /* Double-width character being overwritten by the "precedes" |
| 4592 | * character, need to fill up half the character. */ |
| 4593 | c_extra = MB_FILLER_CHAR; |
| 4594 | n_extra = 1; |
| 4595 | n_attr = 2; |
| 4596 | extra_attr = hl_attr(HLF_AT); |
| 4597 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4598 | mb_c = c; |
| 4599 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4600 | { |
| 4601 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4602 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4603 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4604 | } |
| 4605 | else |
| 4606 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4607 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4608 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4609 | { |
| 4610 | saved_attr3 = char_attr; /* save current attr */ |
| 4611 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 4612 | n_attr3 = 1; |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4617 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4618 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4619 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4620 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4621 | || did_line_attr == 1 |
| 4622 | #endif |
| 4623 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4624 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4625 | #ifdef FEAT_SEARCH_EXTRA |
| 4626 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4627 | |
| 4628 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 4629 | 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] | 4630 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4631 | #endif |
| 4632 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4633 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4634 | * highlight match at end of line. If it's beyond the last |
| 4635 | * char on the screen, just overwrite that one (tricky!) Not |
| 4636 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4637 | #ifdef FEAT_SEARCH_EXTRA |
| 4638 | prevcol_hl_flag = FALSE; |
| 4639 | if (prevcol == (long)search_hl.startcol) |
| 4640 | prevcol_hl_flag = TRUE; |
| 4641 | else |
| 4642 | { |
| 4643 | cur = wp->w_match_head; |
| 4644 | while (cur != NULL) |
| 4645 | { |
| 4646 | if (prevcol == (long)cur->hl.startcol) |
| 4647 | { |
| 4648 | prevcol_hl_flag = TRUE; |
| 4649 | break; |
| 4650 | } |
| 4651 | cur = cur->next; |
| 4652 | } |
| 4653 | } |
| 4654 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4655 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4656 | && ((area_attr != 0 && vcol == fromcol |
| 4657 | #ifdef FEAT_VISUAL |
| 4658 | && (VIsual_mode != Ctrl_V |
| 4659 | || lnum == VIsual.lnum |
| 4660 | || lnum == curwin->w_cursor.lnum) |
| 4661 | #endif |
| 4662 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4663 | #ifdef FEAT_SEARCH_EXTRA |
| 4664 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4665 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4666 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4667 | && did_line_attr <= 1 |
| 4668 | # endif |
| 4669 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4670 | #endif |
| 4671 | )) |
| 4672 | { |
| 4673 | int n = 0; |
| 4674 | |
| 4675 | #ifdef FEAT_RIGHTLEFT |
| 4676 | if (wp->w_p_rl) |
| 4677 | { |
| 4678 | if (col < 0) |
| 4679 | n = 1; |
| 4680 | } |
| 4681 | else |
| 4682 | #endif |
| 4683 | { |
| 4684 | if (col >= W_WIDTH(wp)) |
| 4685 | n = -1; |
| 4686 | } |
| 4687 | if (n != 0) |
| 4688 | { |
| 4689 | /* At the window boundary, highlight the last character |
| 4690 | * instead (better than nothing). */ |
| 4691 | off += n; |
| 4692 | col += n; |
| 4693 | } |
| 4694 | else |
| 4695 | { |
| 4696 | /* Add a blank character to highlight. */ |
| 4697 | ScreenLines[off] = ' '; |
| 4698 | #ifdef FEAT_MBYTE |
| 4699 | if (enc_utf8) |
| 4700 | ScreenLinesUC[off] = 0; |
| 4701 | #endif |
| 4702 | } |
| 4703 | #ifdef FEAT_SEARCH_EXTRA |
| 4704 | if (area_attr == 0) |
| 4705 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4706 | /* Use attributes from match with highest priority among |
| 4707 | * 'search_hl' and the match list. */ |
| 4708 | char_attr = search_hl.attr; |
| 4709 | cur = wp->w_match_head; |
| 4710 | shl_flag = FALSE; |
| 4711 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4712 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4713 | if (shl_flag == FALSE |
| 4714 | && ((cur != NULL |
| 4715 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4716 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4717 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4718 | shl = &search_hl; |
| 4719 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4720 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4721 | else |
| 4722 | shl = &cur->hl; |
| 4723 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 4724 | char_attr = shl->attr; |
| 4725 | if (shl != &search_hl && cur != NULL) |
| 4726 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4727 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4728 | } |
| 4729 | #endif |
| 4730 | ScreenAttrs[off] = char_attr; |
| 4731 | #ifdef FEAT_RIGHTLEFT |
| 4732 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4733 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4734 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4735 | --off; |
| 4736 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4737 | else |
| 4738 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4739 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4740 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4741 | ++off; |
| 4742 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4743 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4744 | #ifdef FEAT_SYN_HL |
| 4745 | eol_hl_off = 1; |
| 4746 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4747 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4748 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4749 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4750 | /* |
| 4751 | * At end of the text line. |
| 4752 | */ |
| 4753 | if (c == NUL) |
| 4754 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4755 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4756 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 4757 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4758 | { |
| 4759 | /* highlight last char after line */ |
| 4760 | --col; |
| 4761 | --off; |
| 4762 | --vcol; |
| 4763 | } |
| 4764 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4765 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 4766 | if (wp->w_p_wrap) |
| 4767 | v = wp->w_skipcol; |
| 4768 | else |
| 4769 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4770 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4771 | /* check if line ends before left margin */ |
| 4772 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4773 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4774 | #ifdef FEAT_CONCEAL |
| 4775 | /* Get rid of the boguscols now, we want to draw until the right |
| 4776 | * edge for 'cursorcolumn'. */ |
| 4777 | col -= boguscols; |
| 4778 | boguscols = 0; |
| 4779 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4780 | |
| 4781 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4782 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4783 | |
| 4784 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4785 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 4786 | && (int)wp->w_virtcol < |
| 4787 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4788 | && lnum != wp->w_cursor.lnum) |
| 4789 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4790 | # ifdef FEAT_RIGHTLEFT |
| 4791 | && !wp->w_p_rl |
| 4792 | # endif |
| 4793 | ) |
| 4794 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4795 | int rightmost_vcol = 0; |
| 4796 | int i; |
| 4797 | |
| 4798 | if (wp->w_p_cuc) |
| 4799 | rightmost_vcol = wp->w_virtcol; |
| 4800 | if (draw_color_col) |
| 4801 | /* determine rightmost colorcolumn to possibly draw */ |
| 4802 | for (i = 0; color_cols[i] >= 0; ++i) |
| 4803 | if (rightmost_vcol < color_cols[i]) |
| 4804 | rightmost_vcol = color_cols[i]; |
| 4805 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4806 | while (col < W_WIDTH(wp)) |
| 4807 | { |
| 4808 | ScreenLines[off] = ' '; |
| 4809 | #ifdef FEAT_MBYTE |
| 4810 | if (enc_utf8) |
| 4811 | ScreenLinesUC[off] = 0; |
| 4812 | #endif |
| 4813 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 4814 | if (draw_color_col) |
| 4815 | draw_color_col = advance_color_col(VCOL_HLC, |
| 4816 | &color_cols); |
| 4817 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4818 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4819 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4820 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4821 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 4822 | else |
| 4823 | ScreenAttrs[off++] = 0; |
| 4824 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4825 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4826 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4827 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4828 | ++vcol; |
| 4829 | } |
| 4830 | } |
| 4831 | #endif |
| 4832 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4833 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 4834 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4835 | row++; |
| 4836 | |
| 4837 | /* |
| 4838 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 4839 | * updated (saves a call to plines() later). |
| 4840 | */ |
| 4841 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 4842 | { |
| 4843 | curwin->w_cline_row = startrow; |
| 4844 | curwin->w_cline_height = row - startrow; |
| 4845 | #ifdef FEAT_FOLDING |
| 4846 | curwin->w_cline_folded = FALSE; |
| 4847 | #endif |
| 4848 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 4849 | } |
| 4850 | |
| 4851 | break; |
| 4852 | } |
| 4853 | |
| 4854 | /* line continues beyond line end */ |
| 4855 | if (lcs_ext |
| 4856 | && !wp->w_p_wrap |
| 4857 | #ifdef FEAT_DIFF |
| 4858 | && filler_todo <= 0 |
| 4859 | #endif |
| 4860 | && ( |
| 4861 | #ifdef FEAT_RIGHTLEFT |
| 4862 | wp->w_p_rl ? col == 0 : |
| 4863 | #endif |
| 4864 | col == W_WIDTH(wp) - 1) |
| 4865 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 4866 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4867 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 4868 | { |
| 4869 | c = lcs_ext; |
| 4870 | char_attr = hl_attr(HLF_AT); |
| 4871 | #ifdef FEAT_MBYTE |
| 4872 | mb_c = c; |
| 4873 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4874 | { |
| 4875 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4876 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4877 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4878 | } |
| 4879 | else |
| 4880 | mb_utf8 = FALSE; |
| 4881 | #endif |
| 4882 | } |
| 4883 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4884 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4885 | /* advance to the next 'colorcolumn' */ |
| 4886 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4887 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4888 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4889 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4890 | * highlight the cursor position itself. |
| 4891 | * Also highlight the 'colorcolumn' if it is different than |
| 4892 | * 'cursorcolumn' */ |
| 4893 | vcol_save_attr = -1; |
| 4894 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4895 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4896 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4897 | && lnum != wp->w_cursor.lnum) |
| 4898 | { |
| 4899 | vcol_save_attr = char_attr; |
| 4900 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 4901 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 4902 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4903 | { |
| 4904 | vcol_save_attr = char_attr; |
| 4905 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 4906 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4907 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4908 | #endif |
| 4909 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4910 | /* |
| 4911 | * Store character to be displayed. |
| 4912 | * Skip characters that are left of the screen for 'nowrap'. |
| 4913 | */ |
| 4914 | vcol_prev = vcol; |
| 4915 | if (draw_state < WL_LINE || n_skip <= 0) |
| 4916 | { |
| 4917 | /* |
| 4918 | * Store the character. |
| 4919 | */ |
| 4920 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 4921 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 4922 | { |
| 4923 | /* A double-wide character is: put first halve in left cell. */ |
| 4924 | --off; |
| 4925 | --col; |
| 4926 | } |
| 4927 | #endif |
| 4928 | ScreenLines[off] = c; |
| 4929 | #ifdef FEAT_MBYTE |
| 4930 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 4931 | { |
| 4932 | if ((mb_c & 0xff00) == 0x8e00) |
| 4933 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4934 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 4935 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4936 | else if (enc_utf8) |
| 4937 | { |
| 4938 | if (mb_utf8) |
| 4939 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4940 | int i; |
| 4941 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4942 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4943 | if ((c & 0xff) == 0) |
| 4944 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4945 | for (i = 0; i < Screen_mco; ++i) |
| 4946 | { |
| 4947 | ScreenLinesC[i][off] = u8cc[i]; |
| 4948 | if (u8cc[i] == 0) |
| 4949 | break; |
| 4950 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4951 | } |
| 4952 | else |
| 4953 | ScreenLinesUC[off] = 0; |
| 4954 | } |
| 4955 | if (multi_attr) |
| 4956 | { |
| 4957 | ScreenAttrs[off] = multi_attr; |
| 4958 | multi_attr = 0; |
| 4959 | } |
| 4960 | else |
| 4961 | #endif |
| 4962 | ScreenAttrs[off] = char_attr; |
| 4963 | |
| 4964 | #ifdef FEAT_MBYTE |
| 4965 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4966 | { |
| 4967 | /* Need to fill two screen columns. */ |
| 4968 | ++off; |
| 4969 | ++col; |
| 4970 | if (enc_utf8) |
| 4971 | /* UTF-8: Put a 0 in the second screen char. */ |
| 4972 | ScreenLines[off] = 0; |
| 4973 | else |
| 4974 | /* DBCS: Put second byte in the second screen char. */ |
| 4975 | ScreenLines[off] = mb_c & 0xff; |
| 4976 | ++vcol; |
| 4977 | /* When "tocol" is halfway a character, set it to the end of |
| 4978 | * the character, otherwise highlighting won't stop. */ |
| 4979 | if (tocol == vcol) |
| 4980 | ++tocol; |
| 4981 | #ifdef FEAT_RIGHTLEFT |
| 4982 | if (wp->w_p_rl) |
| 4983 | { |
| 4984 | /* now it's time to backup one cell */ |
| 4985 | --off; |
| 4986 | --col; |
| 4987 | } |
| 4988 | #endif |
| 4989 | } |
| 4990 | #endif |
| 4991 | #ifdef FEAT_RIGHTLEFT |
| 4992 | if (wp->w_p_rl) |
| 4993 | { |
| 4994 | --off; |
| 4995 | --col; |
| 4996 | } |
| 4997 | else |
| 4998 | #endif |
| 4999 | { |
| 5000 | ++off; |
| 5001 | ++col; |
| 5002 | } |
| 5003 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5004 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5005 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5006 | { |
| 5007 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5008 | ++vcol_off; |
| 5009 | if (n_extra > 0) |
| 5010 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5011 | if (wp->w_p_wrap) |
| 5012 | { |
| 5013 | /* |
| 5014 | * Special voodoo required if 'wrap' is on. |
| 5015 | * |
| 5016 | * Advance the column indicator to force the line |
| 5017 | * drawing to wrap early. This will make the line |
| 5018 | * take up the same screen space when parts are concealed, |
| 5019 | * so that cursor line computations aren't messed up. |
| 5020 | * |
| 5021 | * To avoid the fictitious advance of 'col' causing |
| 5022 | * trailing junk to be written out of the screen line |
| 5023 | * we are building, 'boguscols' keeps track of the number |
| 5024 | * of bad columns we have advanced. |
| 5025 | */ |
| 5026 | if (n_extra > 0) |
| 5027 | { |
| 5028 | vcol += n_extra; |
| 5029 | # ifdef FEAT_RIGHTLEFT |
| 5030 | if (wp->w_p_rl) |
| 5031 | { |
| 5032 | col -= n_extra; |
| 5033 | boguscols -= n_extra; |
| 5034 | } |
| 5035 | else |
| 5036 | # endif |
| 5037 | { |
| 5038 | col += n_extra; |
| 5039 | boguscols += n_extra; |
| 5040 | } |
| 5041 | n_extra = 0; |
| 5042 | n_attr = 0; |
| 5043 | } |
| 5044 | |
| 5045 | |
| 5046 | # ifdef FEAT_MBYTE |
| 5047 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5048 | { |
| 5049 | /* Need to fill two screen columns. */ |
| 5050 | # ifdef FEAT_RIGHTLEFT |
| 5051 | if (wp->w_p_rl) |
| 5052 | { |
| 5053 | --boguscols; |
| 5054 | --col; |
| 5055 | } |
| 5056 | else |
| 5057 | # endif |
| 5058 | { |
| 5059 | ++boguscols; |
| 5060 | ++col; |
| 5061 | } |
| 5062 | } |
| 5063 | # endif |
| 5064 | |
| 5065 | # ifdef FEAT_RIGHTLEFT |
| 5066 | if (wp->w_p_rl) |
| 5067 | { |
| 5068 | --boguscols; |
| 5069 | --col; |
| 5070 | } |
| 5071 | else |
| 5072 | # endif |
| 5073 | { |
| 5074 | ++boguscols; |
| 5075 | ++col; |
| 5076 | } |
| 5077 | } |
| 5078 | else |
| 5079 | { |
| 5080 | if (n_extra > 0) |
| 5081 | { |
| 5082 | vcol += n_extra; |
| 5083 | n_extra = 0; |
| 5084 | n_attr = 0; |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | } |
| 5089 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5090 | else |
| 5091 | --n_skip; |
| 5092 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5093 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5094 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5095 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5096 | #ifdef FEAT_DIFF |
| 5097 | && filler_todo <= 0 |
| 5098 | #endif |
| 5099 | ) |
| 5100 | ++vcol; |
| 5101 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5102 | #ifdef FEAT_SYN_HL |
| 5103 | if (vcol_save_attr >= 0) |
| 5104 | char_attr = vcol_save_attr; |
| 5105 | #endif |
| 5106 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5107 | /* restore attributes after "predeces" in 'listchars' */ |
| 5108 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5109 | char_attr = saved_attr3; |
| 5110 | |
| 5111 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5112 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5113 | char_attr = saved_attr2; |
| 5114 | |
| 5115 | /* |
| 5116 | * 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] | 5117 | * 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] | 5118 | */ |
| 5119 | if (( |
| 5120 | #ifdef FEAT_RIGHTLEFT |
| 5121 | wp->w_p_rl ? (col < 0) : |
| 5122 | #endif |
| 5123 | (col >= W_WIDTH(wp))) |
| 5124 | && (*ptr != NUL |
| 5125 | #ifdef FEAT_DIFF |
| 5126 | || filler_todo > 0 |
| 5127 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5128 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5129 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5130 | ) |
| 5131 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5132 | #ifdef FEAT_CONCEAL |
| 5133 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5134 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5135 | boguscols = 0; |
| 5136 | #else |
| 5137 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5138 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5139 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5140 | ++row; |
| 5141 | ++screen_row; |
| 5142 | |
| 5143 | /* When not wrapping and finished diff lines, or when displayed |
| 5144 | * '$' and highlighting until last column, break here. */ |
| 5145 | if ((!wp->w_p_wrap |
| 5146 | #ifdef FEAT_DIFF |
| 5147 | && filler_todo <= 0 |
| 5148 | #endif |
| 5149 | ) || lcs_eol_one == -1) |
| 5150 | break; |
| 5151 | |
| 5152 | /* When the window is too narrow draw all "@" lines. */ |
| 5153 | if (draw_state != WL_LINE |
| 5154 | #ifdef FEAT_DIFF |
| 5155 | && filler_todo <= 0 |
| 5156 | #endif |
| 5157 | ) |
| 5158 | { |
| 5159 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 5160 | #ifdef FEAT_VERTSPLIT |
| 5161 | draw_vsep_win(wp, row); |
| 5162 | #endif |
| 5163 | row = endrow; |
| 5164 | } |
| 5165 | |
| 5166 | /* When line got too long for screen break here. */ |
| 5167 | if (row == endrow) |
| 5168 | { |
| 5169 | ++row; |
| 5170 | break; |
| 5171 | } |
| 5172 | |
| 5173 | if (screen_cur_row == screen_row - 1 |
| 5174 | #ifdef FEAT_DIFF |
| 5175 | && filler_todo <= 0 |
| 5176 | #endif |
| 5177 | && W_WIDTH(wp) == Columns) |
| 5178 | { |
| 5179 | /* Remember that the line wraps, used for modeless copy. */ |
| 5180 | LineWraps[screen_row - 1] = TRUE; |
| 5181 | |
| 5182 | /* |
| 5183 | * Special trick to make copy/paste of wrapped lines work with |
| 5184 | * xterm/screen: write an extra character beyond the end of |
| 5185 | * the line. This will work with all terminal types |
| 5186 | * (regardless of the xn,am settings). |
| 5187 | * Only do this on a fast tty. |
| 5188 | * Only do this if the cursor is on the current line |
| 5189 | * (something has been written in it). |
| 5190 | * Don't do this for the GUI. |
| 5191 | * Don't do this for double-width characters. |
| 5192 | * Don't do this for a window not at the right screen border. |
| 5193 | */ |
| 5194 | if (p_tf |
| 5195 | #ifdef FEAT_GUI |
| 5196 | && !gui.in_use |
| 5197 | #endif |
| 5198 | #ifdef FEAT_MBYTE |
| 5199 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5200 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5201 | LineOffset[screen_row] + screen_Columns) |
| 5202 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5203 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5204 | + (int)Columns - 2, |
| 5205 | LineOffset[screen_row] + screen_Columns) |
| 5206 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5207 | #endif |
| 5208 | ) |
| 5209 | { |
| 5210 | /* First make sure we are at the end of the screen line, |
| 5211 | * then output the same character again to let the |
| 5212 | * terminal know about the wrap. If the terminal doesn't |
| 5213 | * auto-wrap, we overwrite the character. */ |
| 5214 | if (screen_cur_col != W_WIDTH(wp)) |
| 5215 | screen_char(LineOffset[screen_row - 1] |
| 5216 | + (unsigned)Columns - 1, |
| 5217 | screen_row - 1, (int)(Columns - 1)); |
| 5218 | |
| 5219 | #ifdef FEAT_MBYTE |
| 5220 | /* When there is a multi-byte character, just output a |
| 5221 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5222 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5223 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5224 | out_char(' '); |
| 5225 | else |
| 5226 | #endif |
| 5227 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5228 | + (Columns - 1)]); |
| 5229 | /* force a redraw of the first char on the next line */ |
| 5230 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5231 | screen_start(); /* don't know where cursor is now */ |
| 5232 | } |
| 5233 | } |
| 5234 | |
| 5235 | col = 0; |
| 5236 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5237 | #ifdef FEAT_RIGHTLEFT |
| 5238 | if (wp->w_p_rl) |
| 5239 | { |
| 5240 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5241 | off += col; |
| 5242 | } |
| 5243 | #endif |
| 5244 | |
| 5245 | /* reset the drawing state for the start of a wrapped line */ |
| 5246 | draw_state = WL_START; |
| 5247 | saved_n_extra = n_extra; |
| 5248 | saved_p_extra = p_extra; |
| 5249 | saved_c_extra = c_extra; |
| 5250 | saved_char_attr = char_attr; |
| 5251 | n_extra = 0; |
| 5252 | lcs_prec_todo = lcs_prec; |
| 5253 | #ifdef FEAT_LINEBREAK |
| 5254 | # ifdef FEAT_DIFF |
| 5255 | if (filler_todo <= 0) |
| 5256 | # endif |
| 5257 | need_showbreak = TRUE; |
| 5258 | #endif |
| 5259 | #ifdef FEAT_DIFF |
| 5260 | --filler_todo; |
| 5261 | /* When the filler lines are actually below the last line of the |
| 5262 | * file, don't draw the line itself, break here. */ |
| 5263 | if (filler_todo == 0 && wp->w_botfill) |
| 5264 | break; |
| 5265 | #endif |
| 5266 | } |
| 5267 | |
| 5268 | } /* for every character in the line */ |
| 5269 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5270 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5271 | /* After an empty line check first word for capital. */ |
| 5272 | if (*skipwhite(line) == NUL) |
| 5273 | { |
| 5274 | capcol_lnum = lnum + 1; |
| 5275 | cap_col = 0; |
| 5276 | } |
| 5277 | #endif |
| 5278 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5279 | return row; |
| 5280 | } |
| 5281 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5282 | #ifdef FEAT_MBYTE |
| 5283 | static int comp_char_differs __ARGS((int, int)); |
| 5284 | |
| 5285 | /* |
| 5286 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5287 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5288 | */ |
| 5289 | static int |
| 5290 | comp_char_differs(off_from, off_to) |
| 5291 | int off_from; |
| 5292 | int off_to; |
| 5293 | { |
| 5294 | int i; |
| 5295 | |
| 5296 | for (i = 0; i < Screen_mco; ++i) |
| 5297 | { |
| 5298 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5299 | return TRUE; |
| 5300 | if (ScreenLinesC[i][off_from] == 0) |
| 5301 | break; |
| 5302 | } |
| 5303 | return FALSE; |
| 5304 | } |
| 5305 | #endif |
| 5306 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5307 | /* |
| 5308 | * Check whether the given character needs redrawing: |
| 5309 | * - the (first byte of the) character is different |
| 5310 | * - the attributes are different |
| 5311 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5312 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5313 | */ |
| 5314 | static int |
| 5315 | char_needs_redraw(off_from, off_to, cols) |
| 5316 | int off_from; |
| 5317 | int off_to; |
| 5318 | int cols; |
| 5319 | { |
| 5320 | if (cols > 0 |
| 5321 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5322 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5323 | |
| 5324 | #ifdef FEAT_MBYTE |
| 5325 | || (enc_dbcs != 0 |
| 5326 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5327 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5328 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5329 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5330 | != ScreenLines[off_to + 1]))) |
| 5331 | || (enc_utf8 |
| 5332 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5333 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5334 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5335 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5336 | && ScreenLines[off_from + 1] |
| 5337 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5338 | #endif |
| 5339 | )) |
| 5340 | return TRUE; |
| 5341 | return FALSE; |
| 5342 | } |
| 5343 | |
| 5344 | /* |
| 5345 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5346 | * have actually changed. Handle insert/delete character. |
| 5347 | * "coloff" gives the first column on the screen for this line. |
| 5348 | * "endcol" gives the columns where valid characters are. |
| 5349 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5350 | * needs to be cleared, negative otherwise. |
| 5351 | * "rlflag" is TRUE in a rightleft window: |
| 5352 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5353 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5354 | */ |
| 5355 | static void |
| 5356 | screen_line(row, coloff, endcol, clear_width |
| 5357 | #ifdef FEAT_RIGHTLEFT |
| 5358 | , rlflag |
| 5359 | #endif |
| 5360 | ) |
| 5361 | int row; |
| 5362 | int coloff; |
| 5363 | int endcol; |
| 5364 | int clear_width; |
| 5365 | #ifdef FEAT_RIGHTLEFT |
| 5366 | int rlflag; |
| 5367 | #endif |
| 5368 | { |
| 5369 | unsigned off_from; |
| 5370 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5371 | #ifdef FEAT_MBYTE |
| 5372 | unsigned max_off_from; |
| 5373 | unsigned max_off_to; |
| 5374 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5375 | int col = 0; |
| 5376 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 5377 | int hl; |
| 5378 | #endif |
| 5379 | int force = FALSE; /* force update rest of the line */ |
| 5380 | int redraw_this /* bool: does character need redraw? */ |
| 5381 | #ifdef FEAT_GUI |
| 5382 | = TRUE /* For GUI when while-loop empty */ |
| 5383 | #endif |
| 5384 | ; |
| 5385 | int redraw_next; /* redraw_this for next character */ |
| 5386 | #ifdef FEAT_MBYTE |
| 5387 | int clear_next = FALSE; |
| 5388 | int char_cells; /* 1: normal char */ |
| 5389 | /* 2: occupies two display cells */ |
| 5390 | # define CHAR_CELLS char_cells |
| 5391 | #else |
| 5392 | # define CHAR_CELLS 1 |
| 5393 | #endif |
| 5394 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5395 | /* Check for illegal row and col, just in case. */ |
| 5396 | if (row >= Rows) |
| 5397 | row = Rows - 1; |
| 5398 | if (endcol > Columns) |
| 5399 | endcol = Columns; |
| 5400 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5401 | # ifdef FEAT_CLIPBOARD |
| 5402 | clip_may_clear_selection(row, row); |
| 5403 | # endif |
| 5404 | |
| 5405 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5406 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5407 | #ifdef FEAT_MBYTE |
| 5408 | max_off_from = off_from + screen_Columns; |
| 5409 | max_off_to = LineOffset[row] + screen_Columns; |
| 5410 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5411 | |
| 5412 | #ifdef FEAT_RIGHTLEFT |
| 5413 | if (rlflag) |
| 5414 | { |
| 5415 | /* Clear rest first, because it's left of the text. */ |
| 5416 | if (clear_width > 0) |
| 5417 | { |
| 5418 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5419 | && ScreenAttrs[off_to] == 0 |
| 5420 | # ifdef FEAT_MBYTE |
| 5421 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5422 | # endif |
| 5423 | ) |
| 5424 | { |
| 5425 | ++off_to; |
| 5426 | ++col; |
| 5427 | } |
| 5428 | if (col <= endcol) |
| 5429 | screen_fill(row, row + 1, col + coloff, |
| 5430 | endcol + coloff + 1, ' ', ' ', 0); |
| 5431 | } |
| 5432 | col = endcol + 1; |
| 5433 | off_to = LineOffset[row] + col + coloff; |
| 5434 | off_from += col; |
| 5435 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5436 | } |
| 5437 | #endif /* FEAT_RIGHTLEFT */ |
| 5438 | |
| 5439 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5440 | |
| 5441 | while (col < endcol) |
| 5442 | { |
| 5443 | #ifdef FEAT_MBYTE |
| 5444 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5445 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5446 | else |
| 5447 | char_cells = 1; |
| 5448 | #endif |
| 5449 | |
| 5450 | redraw_this = redraw_next; |
| 5451 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5452 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5453 | |
| 5454 | #ifdef FEAT_GUI |
| 5455 | /* If the next character was bold, then redraw the current character to |
| 5456 | * remove any pixels that might have spilt over into us. This only |
| 5457 | * happens in the GUI. |
| 5458 | */ |
| 5459 | if (redraw_next && gui.in_use) |
| 5460 | { |
| 5461 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5462 | if (hl > HL_ALL) |
| 5463 | hl = syn_attr2attr(hl); |
| 5464 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5465 | redraw_this = TRUE; |
| 5466 | } |
| 5467 | #endif |
| 5468 | |
| 5469 | if (redraw_this) |
| 5470 | { |
| 5471 | /* |
| 5472 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5473 | * Attributes for characters are stored at the position where the |
| 5474 | * cursor is when writing the highlighting code. The |
| 5475 | * start-highlighting code must be written with the cursor on the |
| 5476 | * first highlighted character. The stop-highlighting code must |
| 5477 | * be written with the cursor just after the last highlighted |
| 5478 | * character. |
| 5479 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5480 | * to clear the rest of the line, and force redrawing it |
| 5481 | * completely. |
| 5482 | */ |
| 5483 | if ( p_wiv |
| 5484 | && !force |
| 5485 | #ifdef FEAT_GUI |
| 5486 | && !gui.in_use |
| 5487 | #endif |
| 5488 | && ScreenAttrs[off_to] != 0 |
| 5489 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5490 | { |
| 5491 | /* |
| 5492 | * Need to remove highlighting attributes here. |
| 5493 | */ |
| 5494 | windgoto(row, col + coloff); |
| 5495 | out_str(T_CE); /* clear rest of this screen line */ |
| 5496 | screen_start(); /* don't know where cursor is now */ |
| 5497 | force = TRUE; /* force redraw of rest of the line */ |
| 5498 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5499 | |
| 5500 | /* |
| 5501 | * If the previous character was highlighted, need to stop |
| 5502 | * highlighting at this character. |
| 5503 | */ |
| 5504 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5505 | { |
| 5506 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5507 | term_windgoto(row, col + coloff); |
| 5508 | screen_stop_highlight(); |
| 5509 | } |
| 5510 | else |
| 5511 | screen_attr = 0; /* highlighting has stopped */ |
| 5512 | } |
| 5513 | #ifdef FEAT_MBYTE |
| 5514 | if (enc_dbcs != 0) |
| 5515 | { |
| 5516 | /* Check if overwriting a double-byte with a single-byte or |
| 5517 | * the other way around requires another character to be |
| 5518 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 5519 | * ScreenLinesUC[] is sufficient. */ |
| 5520 | if (char_cells == 1 |
| 5521 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5522 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5523 | { |
| 5524 | /* Writing a single-cell character over a double-cell |
| 5525 | * character: need to redraw the next cell. */ |
| 5526 | ScreenLines[off_to + 1] = 0; |
| 5527 | redraw_next = TRUE; |
| 5528 | } |
| 5529 | else if (char_cells == 2 |
| 5530 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5531 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5532 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5533 | { |
| 5534 | /* Writing the second half of a double-cell character over |
| 5535 | * a double-cell character: need to redraw the second |
| 5536 | * cell. */ |
| 5537 | ScreenLines[off_to + 2] = 0; |
| 5538 | redraw_next = TRUE; |
| 5539 | } |
| 5540 | |
| 5541 | if (enc_dbcs == DBCS_JPNU) |
| 5542 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 5543 | } |
| 5544 | /* When writing a single-width character over a double-width |
| 5545 | * character and at the end of the redrawn text, need to clear out |
| 5546 | * the right halve of the old character. |
| 5547 | * Also required when writing the right halve of a double-width |
| 5548 | * char over the left halve of an existing one. */ |
| 5549 | if (has_mbyte && col + char_cells == endcol |
| 5550 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5551 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5552 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5553 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5554 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5555 | clear_next = TRUE; |
| 5556 | #endif |
| 5557 | |
| 5558 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 5559 | #ifdef FEAT_MBYTE |
| 5560 | if (enc_utf8) |
| 5561 | { |
| 5562 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 5563 | if (ScreenLinesUC[off_from] != 0) |
| 5564 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5565 | int i; |
| 5566 | |
| 5567 | for (i = 0; i < Screen_mco; ++i) |
| 5568 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5569 | } |
| 5570 | } |
| 5571 | if (char_cells == 2) |
| 5572 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 5573 | #endif |
| 5574 | |
| 5575 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 5576 | /* The bold trick makes a single column of pixels appear in the |
| 5577 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5578 | * character should be redrawn too. This happens for our own GUI |
| 5579 | * and for some xterms. */ |
| 5580 | if ( |
| 5581 | # ifdef FEAT_GUI |
| 5582 | gui.in_use |
| 5583 | # endif |
| 5584 | # if defined(FEAT_GUI) && defined(UNIX) |
| 5585 | || |
| 5586 | # endif |
| 5587 | # ifdef UNIX |
| 5588 | term_is_xterm |
| 5589 | # endif |
| 5590 | ) |
| 5591 | { |
| 5592 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5593 | if (hl > HL_ALL) |
| 5594 | hl = syn_attr2attr(hl); |
| 5595 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5596 | redraw_next = TRUE; |
| 5597 | } |
| 5598 | #endif |
| 5599 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 5600 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5601 | /* For simplicity set the attributes of second half of a |
| 5602 | * double-wide character equal to the first half. */ |
| 5603 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5604 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5605 | |
| 5606 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5607 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5608 | else |
| 5609 | #endif |
| 5610 | screen_char(off_to, row, col + coloff); |
| 5611 | } |
| 5612 | else if ( p_wiv |
| 5613 | #ifdef FEAT_GUI |
| 5614 | && !gui.in_use |
| 5615 | #endif |
| 5616 | && col + coloff > 0) |
| 5617 | { |
| 5618 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 5619 | { |
| 5620 | /* |
| 5621 | * Don't output stop-highlight when moving the cursor, it will |
| 5622 | * stop the highlighting when it should continue. |
| 5623 | */ |
| 5624 | screen_attr = 0; |
| 5625 | } |
| 5626 | else if (screen_attr != 0) |
| 5627 | screen_stop_highlight(); |
| 5628 | } |
| 5629 | |
| 5630 | off_to += CHAR_CELLS; |
| 5631 | off_from += CHAR_CELLS; |
| 5632 | col += CHAR_CELLS; |
| 5633 | } |
| 5634 | |
| 5635 | #ifdef FEAT_MBYTE |
| 5636 | if (clear_next) |
| 5637 | { |
| 5638 | /* Clear the second half of a double-wide character of which the left |
| 5639 | * half was overwritten with a single-wide character. */ |
| 5640 | ScreenLines[off_to] = ' '; |
| 5641 | if (enc_utf8) |
| 5642 | ScreenLinesUC[off_to] = 0; |
| 5643 | screen_char(off_to, row, col + coloff); |
| 5644 | } |
| 5645 | #endif |
| 5646 | |
| 5647 | if (clear_width > 0 |
| 5648 | #ifdef FEAT_RIGHTLEFT |
| 5649 | && !rlflag |
| 5650 | #endif |
| 5651 | ) |
| 5652 | { |
| 5653 | #ifdef FEAT_GUI |
| 5654 | int startCol = col; |
| 5655 | #endif |
| 5656 | |
| 5657 | /* blank out the rest of the line */ |
| 5658 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 5659 | && ScreenAttrs[off_to] == 0 |
| 5660 | #ifdef FEAT_MBYTE |
| 5661 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5662 | #endif |
| 5663 | ) |
| 5664 | { |
| 5665 | ++off_to; |
| 5666 | ++col; |
| 5667 | } |
| 5668 | if (col < clear_width) |
| 5669 | { |
| 5670 | #ifdef FEAT_GUI |
| 5671 | /* |
| 5672 | * In the GUI, clearing the rest of the line may leave pixels |
| 5673 | * behind if the first character cleared was bold. Some bold |
| 5674 | * fonts spill over the left. In this case we redraw the previous |
| 5675 | * character too. If we didn't skip any blanks above, then we |
| 5676 | * only redraw if the character wasn't already redrawn anyway. |
| 5677 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5678 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5679 | { |
| 5680 | hl = ScreenAttrs[off_to]; |
| 5681 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5682 | { |
| 5683 | int prev_cells = 1; |
| 5684 | # ifdef FEAT_MBYTE |
| 5685 | if (enc_utf8) |
| 5686 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 5687 | * that its width is 2. */ |
| 5688 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 5689 | else if (enc_dbcs != 0) |
| 5690 | { |
| 5691 | /* find previous character by counting from first |
| 5692 | * column and get its width. */ |
| 5693 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5694 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5695 | |
| 5696 | while (off < off_to) |
| 5697 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5698 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5699 | off += prev_cells; |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | if (enc_dbcs != 0 && prev_cells > 1) |
| 5704 | screen_char_2(off_to - prev_cells, row, |
| 5705 | col + coloff - prev_cells); |
| 5706 | else |
| 5707 | # endif |
| 5708 | screen_char(off_to - prev_cells, row, |
| 5709 | col + coloff - prev_cells); |
| 5710 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5711 | } |
| 5712 | #endif |
| 5713 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 5714 | ' ', ' ', 0); |
| 5715 | #ifdef FEAT_VERTSPLIT |
| 5716 | off_to += clear_width - col; |
| 5717 | col = clear_width; |
| 5718 | #endif |
| 5719 | } |
| 5720 | } |
| 5721 | |
| 5722 | if (clear_width > 0) |
| 5723 | { |
| 5724 | #ifdef FEAT_VERTSPLIT |
| 5725 | /* For a window that's left of another, draw the separator char. */ |
| 5726 | if (col + coloff < Columns) |
| 5727 | { |
| 5728 | int c; |
| 5729 | |
| 5730 | c = fillchar_vsep(&hl); |
| 5731 | if (ScreenLines[off_to] != c |
| 5732 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5733 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 5734 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5735 | # endif |
| 5736 | || ScreenAttrs[off_to] != hl) |
| 5737 | { |
| 5738 | ScreenLines[off_to] = c; |
| 5739 | ScreenAttrs[off_to] = hl; |
| 5740 | # ifdef FEAT_MBYTE |
| 5741 | if (enc_utf8) |
| 5742 | { |
| 5743 | if (c >= 0x80) |
| 5744 | { |
| 5745 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5746 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5747 | } |
| 5748 | else |
| 5749 | ScreenLinesUC[off_to] = 0; |
| 5750 | } |
| 5751 | # endif |
| 5752 | screen_char(off_to, row, col + coloff); |
| 5753 | } |
| 5754 | } |
| 5755 | else |
| 5756 | #endif |
| 5757 | LineWraps[row] = FALSE; |
| 5758 | } |
| 5759 | } |
| 5760 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5761 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5762 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5763 | * Mirror text "str" for right-left displaying. |
| 5764 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5765 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5766 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5767 | rl_mirror(str) |
| 5768 | char_u *str; |
| 5769 | { |
| 5770 | char_u *p1, *p2; |
| 5771 | int t; |
| 5772 | |
| 5773 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 5774 | { |
| 5775 | t = *p1; |
| 5776 | *p1 = *p2; |
| 5777 | *p2 = t; |
| 5778 | } |
| 5779 | } |
| 5780 | #endif |
| 5781 | |
| 5782 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5783 | /* |
| 5784 | * mark all status lines for redraw; used after first :cd |
| 5785 | */ |
| 5786 | void |
| 5787 | status_redraw_all() |
| 5788 | { |
| 5789 | win_T *wp; |
| 5790 | |
| 5791 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5792 | if (wp->w_status_height) |
| 5793 | { |
| 5794 | wp->w_redr_status = TRUE; |
| 5795 | redraw_later(VALID); |
| 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | /* |
| 5800 | * mark all status lines of the current buffer for redraw |
| 5801 | */ |
| 5802 | void |
| 5803 | status_redraw_curbuf() |
| 5804 | { |
| 5805 | win_T *wp; |
| 5806 | |
| 5807 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5808 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 5809 | { |
| 5810 | wp->w_redr_status = TRUE; |
| 5811 | redraw_later(VALID); |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | /* |
| 5816 | * Redraw all status lines that need to be redrawn. |
| 5817 | */ |
| 5818 | void |
| 5819 | redraw_statuslines() |
| 5820 | { |
| 5821 | win_T *wp; |
| 5822 | |
| 5823 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5824 | if (wp->w_redr_status) |
| 5825 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 5826 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5827 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5828 | } |
| 5829 | #endif |
| 5830 | |
| 5831 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 5832 | /* |
| 5833 | * Redraw all status lines at the bottom of frame "frp". |
| 5834 | */ |
| 5835 | void |
| 5836 | win_redraw_last_status(frp) |
| 5837 | frame_T *frp; |
| 5838 | { |
| 5839 | if (frp->fr_layout == FR_LEAF) |
| 5840 | frp->fr_win->w_redr_status = TRUE; |
| 5841 | else if (frp->fr_layout == FR_ROW) |
| 5842 | { |
| 5843 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 5844 | win_redraw_last_status(frp); |
| 5845 | } |
| 5846 | else /* frp->fr_layout == FR_COL */ |
| 5847 | { |
| 5848 | frp = frp->fr_child; |
| 5849 | while (frp->fr_next != NULL) |
| 5850 | frp = frp->fr_next; |
| 5851 | win_redraw_last_status(frp); |
| 5852 | } |
| 5853 | } |
| 5854 | #endif |
| 5855 | |
| 5856 | #ifdef FEAT_VERTSPLIT |
| 5857 | /* |
| 5858 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 5859 | */ |
| 5860 | static void |
| 5861 | draw_vsep_win(wp, row) |
| 5862 | win_T *wp; |
| 5863 | int row; |
| 5864 | { |
| 5865 | int hl; |
| 5866 | int c; |
| 5867 | |
| 5868 | if (wp->w_vsep_width) |
| 5869 | { |
| 5870 | /* draw the vertical separator right of this window */ |
| 5871 | c = fillchar_vsep(&hl); |
| 5872 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 5873 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 5874 | c, ' ', hl); |
| 5875 | } |
| 5876 | } |
| 5877 | #endif |
| 5878 | |
| 5879 | #ifdef FEAT_WILDMENU |
| 5880 | static int status_match_len __ARGS((expand_T *xp, char_u *s)); |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5881 | 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] | 5882 | |
| 5883 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5884 | * 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] | 5885 | */ |
| 5886 | static int |
| 5887 | status_match_len(xp, s) |
| 5888 | expand_T *xp; |
| 5889 | char_u *s; |
| 5890 | { |
| 5891 | int len = 0; |
| 5892 | |
| 5893 | #ifdef FEAT_MENU |
| 5894 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 5895 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5896 | |
| 5897 | /* Check for menu separators - replace with '|'. */ |
| 5898 | if (emenu && menu_is_separator(s)) |
| 5899 | return 1; |
| 5900 | #endif |
| 5901 | |
| 5902 | while (*s != NUL) |
| 5903 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5904 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5905 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5906 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5907 | } |
| 5908 | |
| 5909 | return len; |
| 5910 | } |
| 5911 | |
| 5912 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5913 | * 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] | 5914 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 5915 | */ |
| 5916 | static int |
| 5917 | skip_status_match_char(xp, s) |
| 5918 | expand_T *xp; |
| 5919 | char_u *s; |
| 5920 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5921 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5922 | #ifdef FEAT_MENU |
| 5923 | || ((xp->xp_context == EXPAND_MENUS |
| 5924 | || xp->xp_context == EXPAND_MENUNAMES) |
| 5925 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 5926 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5927 | ) |
| 5928 | { |
| 5929 | #ifndef BACKSLASH_IN_FILENAME |
| 5930 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 5931 | return 2; |
| 5932 | #endif |
| 5933 | return 1; |
| 5934 | } |
| 5935 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5936 | } |
| 5937 | |
| 5938 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5939 | * Show wildchar matches in the status line. |
| 5940 | * Show at least the "match" item. |
| 5941 | * We start at item 'first_match' in the list and show all matches that fit. |
| 5942 | * |
| 5943 | * If inversion is possible we use it. Else '=' characters are used. |
| 5944 | */ |
| 5945 | void |
| 5946 | win_redr_status_matches(xp, num_matches, matches, match, showtail) |
| 5947 | expand_T *xp; |
| 5948 | int num_matches; |
| 5949 | char_u **matches; /* list of matches */ |
| 5950 | int match; |
| 5951 | int showtail; |
| 5952 | { |
| 5953 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 5954 | int row; |
| 5955 | char_u *buf; |
| 5956 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5957 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5958 | int fillchar; |
| 5959 | int attr; |
| 5960 | int i; |
| 5961 | int highlight = TRUE; |
| 5962 | char_u *selstart = NULL; |
| 5963 | int selstart_col = 0; |
| 5964 | char_u *selend = NULL; |
| 5965 | static int first_match = 0; |
| 5966 | int add_left = FALSE; |
| 5967 | char_u *s; |
| 5968 | #ifdef FEAT_MENU |
| 5969 | int emenu; |
| 5970 | #endif |
| 5971 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 5972 | int l; |
| 5973 | #endif |
| 5974 | |
| 5975 | if (matches == NULL) /* interrupted completion? */ |
| 5976 | return; |
| 5977 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5978 | #ifdef FEAT_MBYTE |
| 5979 | if (has_mbyte) |
| 5980 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 5981 | else |
| 5982 | #endif |
| 5983 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5984 | if (buf == NULL) |
| 5985 | return; |
| 5986 | |
| 5987 | if (match == -1) /* don't show match but original text */ |
| 5988 | { |
| 5989 | match = 0; |
| 5990 | highlight = FALSE; |
| 5991 | } |
| 5992 | /* count 1 for the ending ">" */ |
| 5993 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 5994 | if (match == 0) |
| 5995 | first_match = 0; |
| 5996 | else if (match < first_match) |
| 5997 | { |
| 5998 | /* jumping left, as far as we can go */ |
| 5999 | first_match = match; |
| 6000 | add_left = TRUE; |
| 6001 | } |
| 6002 | else |
| 6003 | { |
| 6004 | /* check if match fits on the screen */ |
| 6005 | for (i = first_match; i < match; ++i) |
| 6006 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6007 | if (first_match > 0) |
| 6008 | clen += 2; |
| 6009 | /* jumping right, put match at the left */ |
| 6010 | if ((long)clen > Columns) |
| 6011 | { |
| 6012 | first_match = match; |
| 6013 | /* if showing the last match, we can add some on the left */ |
| 6014 | clen = 2; |
| 6015 | for (i = match; i < num_matches; ++i) |
| 6016 | { |
| 6017 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6018 | if ((long)clen >= Columns) |
| 6019 | break; |
| 6020 | } |
| 6021 | if (i == num_matches) |
| 6022 | add_left = TRUE; |
| 6023 | } |
| 6024 | } |
| 6025 | if (add_left) |
| 6026 | while (first_match > 0) |
| 6027 | { |
| 6028 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6029 | if ((long)clen >= Columns) |
| 6030 | break; |
| 6031 | --first_match; |
| 6032 | } |
| 6033 | |
| 6034 | fillchar = fillchar_status(&attr, TRUE); |
| 6035 | |
| 6036 | if (first_match == 0) |
| 6037 | { |
| 6038 | *buf = NUL; |
| 6039 | len = 0; |
| 6040 | } |
| 6041 | else |
| 6042 | { |
| 6043 | STRCPY(buf, "< "); |
| 6044 | len = 2; |
| 6045 | } |
| 6046 | clen = len; |
| 6047 | |
| 6048 | i = first_match; |
| 6049 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6050 | { |
| 6051 | if (i == match) |
| 6052 | { |
| 6053 | selstart = buf + len; |
| 6054 | selstart_col = clen; |
| 6055 | } |
| 6056 | |
| 6057 | s = L_MATCH(i); |
| 6058 | /* Check for menu separators - replace with '|' */ |
| 6059 | #ifdef FEAT_MENU |
| 6060 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6061 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6062 | if (emenu && menu_is_separator(s)) |
| 6063 | { |
| 6064 | STRCPY(buf + len, transchar('|')); |
| 6065 | l = (int)STRLEN(buf + len); |
| 6066 | len += l; |
| 6067 | clen += l; |
| 6068 | } |
| 6069 | else |
| 6070 | #endif |
| 6071 | for ( ; *s != NUL; ++s) |
| 6072 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6073 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6074 | clen += ptr2cells(s); |
| 6075 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6076 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6077 | { |
| 6078 | STRNCPY(buf + len, s, l); |
| 6079 | s += l - 1; |
| 6080 | len += l; |
| 6081 | } |
| 6082 | else |
| 6083 | #endif |
| 6084 | { |
| 6085 | STRCPY(buf + len, transchar_byte(*s)); |
| 6086 | len += (int)STRLEN(buf + len); |
| 6087 | } |
| 6088 | } |
| 6089 | if (i == match) |
| 6090 | selend = buf + len; |
| 6091 | |
| 6092 | *(buf + len++) = ' '; |
| 6093 | *(buf + len++) = ' '; |
| 6094 | clen += 2; |
| 6095 | if (++i == num_matches) |
| 6096 | break; |
| 6097 | } |
| 6098 | |
| 6099 | if (i != num_matches) |
| 6100 | { |
| 6101 | *(buf + len++) = '>'; |
| 6102 | ++clen; |
| 6103 | } |
| 6104 | |
| 6105 | buf[len] = NUL; |
| 6106 | |
| 6107 | row = cmdline_row - 1; |
| 6108 | if (row >= 0) |
| 6109 | { |
| 6110 | if (wild_menu_showing == 0) |
| 6111 | { |
| 6112 | if (msg_scrolled > 0) |
| 6113 | { |
| 6114 | /* Put the wildmenu just above the command line. If there is |
| 6115 | * no room, scroll the screen one line up. */ |
| 6116 | if (cmdline_row == Rows - 1) |
| 6117 | { |
| 6118 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6119 | ++msg_scrolled; |
| 6120 | } |
| 6121 | else |
| 6122 | { |
| 6123 | ++cmdline_row; |
| 6124 | ++row; |
| 6125 | } |
| 6126 | wild_menu_showing = WM_SCROLLED; |
| 6127 | } |
| 6128 | else |
| 6129 | { |
| 6130 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6131 | * Set 'winminheight' to zero to avoid that the window is |
| 6132 | * resized. */ |
| 6133 | if (lastwin->w_status_height == 0) |
| 6134 | { |
| 6135 | save_p_ls = p_ls; |
| 6136 | save_p_wmh = p_wmh; |
| 6137 | p_ls = 2; |
| 6138 | p_wmh = 0; |
| 6139 | last_status(FALSE); |
| 6140 | } |
| 6141 | wild_menu_showing = WM_SHOWN; |
| 6142 | } |
| 6143 | } |
| 6144 | |
| 6145 | screen_puts(buf, row, 0, attr); |
| 6146 | if (selstart != NULL && highlight) |
| 6147 | { |
| 6148 | *selend = NUL; |
| 6149 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6150 | } |
| 6151 | |
| 6152 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6153 | } |
| 6154 | |
| 6155 | #ifdef FEAT_VERTSPLIT |
| 6156 | win_redraw_last_status(topframe); |
| 6157 | #else |
| 6158 | lastwin->w_redr_status = TRUE; |
| 6159 | #endif |
| 6160 | vim_free(buf); |
| 6161 | } |
| 6162 | #endif |
| 6163 | |
| 6164 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6165 | /* |
| 6166 | * Redraw the status line of window wp. |
| 6167 | * |
| 6168 | * If inversion is possible we use it. Else '=' characters are used. |
| 6169 | */ |
| 6170 | void |
| 6171 | win_redr_status(wp) |
| 6172 | win_T *wp; |
| 6173 | { |
| 6174 | int row; |
| 6175 | char_u *p; |
| 6176 | int len; |
| 6177 | int fillchar; |
| 6178 | int attr; |
| 6179 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6180 | static int busy = FALSE; |
| 6181 | |
| 6182 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6183 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6184 | if (busy) |
| 6185 | return; |
| 6186 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6187 | |
| 6188 | wp->w_redr_status = FALSE; |
| 6189 | if (wp->w_status_height == 0) |
| 6190 | { |
| 6191 | /* no status line, can only be last window */ |
| 6192 | redraw_cmdline = TRUE; |
| 6193 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6194 | else if (!redrawing() |
| 6195 | #ifdef FEAT_INS_EXPAND |
| 6196 | /* don't update status line when popup menu is visible and may be |
| 6197 | * drawn over it */ |
| 6198 | || pum_visible() |
| 6199 | #endif |
| 6200 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6201 | { |
| 6202 | /* Don't redraw right now, do it later. */ |
| 6203 | wp->w_redr_status = TRUE; |
| 6204 | } |
| 6205 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6206 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6207 | { |
| 6208 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6209 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6210 | } |
| 6211 | #endif |
| 6212 | else |
| 6213 | { |
| 6214 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6215 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6216 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6217 | p = NameBuff; |
| 6218 | len = (int)STRLEN(p); |
| 6219 | |
| 6220 | if (wp->w_buffer->b_help |
| 6221 | #ifdef FEAT_QUICKFIX |
| 6222 | || wp->w_p_pvw |
| 6223 | #endif |
| 6224 | || bufIsChanged(wp->w_buffer) |
| 6225 | || wp->w_buffer->b_p_ro) |
| 6226 | *(p + len++) = ' '; |
| 6227 | if (wp->w_buffer->b_help) |
| 6228 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6229 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6230 | len += (int)STRLEN(p + len); |
| 6231 | } |
| 6232 | #ifdef FEAT_QUICKFIX |
| 6233 | if (wp->w_p_pvw) |
| 6234 | { |
| 6235 | STRCPY(p + len, _("[Preview]")); |
| 6236 | len += (int)STRLEN(p + len); |
| 6237 | } |
| 6238 | #endif |
| 6239 | if (bufIsChanged(wp->w_buffer)) |
| 6240 | { |
| 6241 | STRCPY(p + len, "[+]"); |
| 6242 | len += 3; |
| 6243 | } |
| 6244 | if (wp->w_buffer->b_p_ro) |
| 6245 | { |
| 6246 | STRCPY(p + len, "[RO]"); |
| 6247 | len += 4; |
| 6248 | } |
| 6249 | |
| 6250 | #ifndef FEAT_VERTSPLIT |
| 6251 | this_ru_col = ru_col; |
| 6252 | if (this_ru_col < (Columns + 1) / 2) |
| 6253 | this_ru_col = (Columns + 1) / 2; |
| 6254 | #else |
| 6255 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6256 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6257 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6258 | if (this_ru_col <= 1) |
| 6259 | { |
| 6260 | p = (char_u *)"<"; /* No room for file name! */ |
| 6261 | len = 1; |
| 6262 | } |
| 6263 | else |
| 6264 | #endif |
| 6265 | #ifdef FEAT_MBYTE |
| 6266 | if (has_mbyte) |
| 6267 | { |
| 6268 | int clen = 0, i; |
| 6269 | |
| 6270 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6271 | clen = mb_string2cells(p, -1); |
| 6272 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6273 | /* Find first character that will fit. |
| 6274 | * Going from start to end is much faster for DBCS. */ |
| 6275 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6276 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6277 | clen -= (*mb_ptr2cells)(p + i); |
| 6278 | len = clen; |
| 6279 | if (i > 0) |
| 6280 | { |
| 6281 | p = p + i - 1; |
| 6282 | *p = '<'; |
| 6283 | ++len; |
| 6284 | } |
| 6285 | |
| 6286 | } |
| 6287 | else |
| 6288 | #endif |
| 6289 | if (len > this_ru_col - 1) |
| 6290 | { |
| 6291 | p += len - (this_ru_col - 1); |
| 6292 | *p = '<'; |
| 6293 | len = this_ru_col - 1; |
| 6294 | } |
| 6295 | |
| 6296 | row = W_WINROW(wp) + wp->w_height; |
| 6297 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6298 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6299 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6300 | |
| 6301 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 6302 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6303 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6304 | - 1 + W_WINCOL(wp)), attr); |
| 6305 | |
| 6306 | #ifdef FEAT_CMDL_INFO |
| 6307 | win_redr_ruler(wp, TRUE); |
| 6308 | #endif |
| 6309 | } |
| 6310 | |
| 6311 | #ifdef FEAT_VERTSPLIT |
| 6312 | /* |
| 6313 | * May need to draw the character below the vertical separator. |
| 6314 | */ |
| 6315 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6316 | { |
| 6317 | if (stl_connected(wp)) |
| 6318 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6319 | else |
| 6320 | fillchar = fillchar_vsep(&attr); |
| 6321 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6322 | attr); |
| 6323 | } |
| 6324 | #endif |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6325 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6328 | #ifdef FEAT_STL_OPT |
| 6329 | /* |
| 6330 | * Redraw the status line according to 'statusline' and take care of any |
| 6331 | * errors encountered. |
| 6332 | */ |
| 6333 | static void |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6334 | redraw_custom_statusline(wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6335 | win_T *wp; |
| 6336 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6337 | static int entered = FALSE; |
| 6338 | int save_called_emsg = called_emsg; |
| 6339 | |
| 6340 | /* When called recursively return. This can happen when the statusline |
| 6341 | * contains an expression that triggers a redraw. */ |
| 6342 | if (entered) |
| 6343 | return; |
| 6344 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6345 | |
| 6346 | called_emsg = FALSE; |
| 6347 | win_redr_custom(wp, FALSE); |
| 6348 | if (called_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6349 | { |
| 6350 | /* When there is an error disable the statusline, otherwise the |
| 6351 | * display is messed up with errors and a redraw triggers the problem |
| 6352 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6353 | set_string_option_direct((char_u *)"statusline", -1, |
| 6354 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6355 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6356 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6357 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6358 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6359 | } |
| 6360 | #endif |
| 6361 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6362 | # ifdef FEAT_VERTSPLIT |
| 6363 | /* |
| 6364 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6365 | * line of the window right of it. If not, then it's a vertical separator. |
| 6366 | * Only call if (wp->w_vsep_width != 0). |
| 6367 | */ |
| 6368 | int |
| 6369 | stl_connected(wp) |
| 6370 | win_T *wp; |
| 6371 | { |
| 6372 | frame_T *fr; |
| 6373 | |
| 6374 | fr = wp->w_frame; |
| 6375 | while (fr->fr_parent != NULL) |
| 6376 | { |
| 6377 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6378 | { |
| 6379 | if (fr->fr_next != NULL) |
| 6380 | break; |
| 6381 | } |
| 6382 | else |
| 6383 | { |
| 6384 | if (fr->fr_next != NULL) |
| 6385 | return TRUE; |
| 6386 | } |
| 6387 | fr = fr->fr_parent; |
| 6388 | } |
| 6389 | return FALSE; |
| 6390 | } |
| 6391 | # endif |
| 6392 | |
| 6393 | #endif /* FEAT_WINDOWS */ |
| 6394 | |
| 6395 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6396 | /* |
| 6397 | * Get the value to show for the language mappings, active 'keymap'. |
| 6398 | */ |
| 6399 | int |
| 6400 | get_keymap_str(wp, buf, len) |
| 6401 | win_T *wp; |
| 6402 | char_u *buf; /* buffer for the result */ |
| 6403 | int len; /* length of buffer */ |
| 6404 | { |
| 6405 | char_u *p; |
| 6406 | |
| 6407 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6408 | return FALSE; |
| 6409 | |
| 6410 | { |
| 6411 | #ifdef FEAT_EVAL |
| 6412 | buf_T *old_curbuf = curbuf; |
| 6413 | win_T *old_curwin = curwin; |
| 6414 | char_u *s; |
| 6415 | |
| 6416 | curbuf = wp->w_buffer; |
| 6417 | curwin = wp; |
| 6418 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6419 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6420 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6421 | --emsg_skip; |
| 6422 | curbuf = old_curbuf; |
| 6423 | curwin = old_curwin; |
| 6424 | if (p == NULL || *p == NUL) |
| 6425 | #endif |
| 6426 | { |
| 6427 | #ifdef FEAT_KEYMAP |
| 6428 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6429 | p = wp->w_buffer->b_p_keymap; |
| 6430 | else |
| 6431 | #endif |
| 6432 | p = (char_u *)"lang"; |
| 6433 | } |
| 6434 | if ((int)(STRLEN(p) + 3) < len) |
| 6435 | sprintf((char *)buf, "<%s>", p); |
| 6436 | else |
| 6437 | buf[0] = NUL; |
| 6438 | #ifdef FEAT_EVAL |
| 6439 | vim_free(s); |
| 6440 | #endif |
| 6441 | } |
| 6442 | return buf[0] != NUL; |
| 6443 | } |
| 6444 | #endif |
| 6445 | |
| 6446 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6447 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6448 | * Redraw the status line or ruler of window "wp". |
| 6449 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6450 | */ |
| 6451 | static void |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6452 | win_redr_custom(wp, draw_ruler) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6453 | win_T *wp; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6454 | int draw_ruler; /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6455 | { |
| 6456 | int attr; |
| 6457 | int curattr; |
| 6458 | int row; |
| 6459 | int col = 0; |
| 6460 | int maxwidth; |
| 6461 | int width; |
| 6462 | int n; |
| 6463 | int len; |
| 6464 | int fillchar; |
| 6465 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6466 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6467 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6468 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6469 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6470 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6471 | win_T *ewp; |
| 6472 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6473 | |
| 6474 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6475 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6476 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6477 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6478 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6479 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6480 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6481 | attr = hl_attr(HLF_TPF); |
| 6482 | maxwidth = Columns; |
| 6483 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6484 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6485 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6486 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6487 | else |
| 6488 | { |
| 6489 | row = W_WINROW(wp) + wp->w_height; |
| 6490 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6491 | maxwidth = W_WIDTH(wp); |
| 6492 | |
| 6493 | if (draw_ruler) |
| 6494 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6495 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6496 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6497 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6498 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6499 | if (*++stl == '-') |
| 6500 | stl++; |
| 6501 | if (atoi((char *)stl)) |
| 6502 | while (VIM_ISDIGIT(*stl)) |
| 6503 | stl++; |
| 6504 | if (*stl++ != '(') |
| 6505 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6506 | } |
| 6507 | #ifdef FEAT_VERTSPLIT |
| 6508 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6509 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6510 | col = (W_WIDTH(wp) + 1) / 2; |
| 6511 | #else |
| 6512 | col = ru_col; |
| 6513 | if (col > (Columns + 1) / 2) |
| 6514 | col = (Columns + 1) / 2; |
| 6515 | #endif |
| 6516 | maxwidth = W_WIDTH(wp) - col; |
| 6517 | #ifdef FEAT_WINDOWS |
| 6518 | if (!wp->w_status_height) |
| 6519 | #endif |
| 6520 | { |
| 6521 | row = Rows - 1; |
| 6522 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6523 | fillchar = ' '; |
| 6524 | attr = 0; |
| 6525 | } |
| 6526 | |
| 6527 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6528 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6529 | # endif |
| 6530 | } |
| 6531 | else |
| 6532 | { |
| 6533 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6534 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6535 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6536 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6537 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6538 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 6539 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6540 | # endif |
| 6541 | } |
| 6542 | |
| 6543 | #ifdef FEAT_VERTSPLIT |
| 6544 | col += W_WINCOL(wp); |
| 6545 | #endif |
| 6546 | } |
| 6547 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6548 | if (maxwidth <= 0) |
| 6549 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6550 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6551 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 6552 | * the cursor away and back. */ |
| 6553 | ewp = wp == NULL ? curwin : wp; |
| 6554 | p_crb_save = ewp->w_p_crb; |
| 6555 | ewp->w_p_crb = FALSE; |
| 6556 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6557 | /* Make a copy, because the statusline may include a function call that |
| 6558 | * might change the option value and free the memory. */ |
| 6559 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6560 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6561 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6562 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6563 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6564 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6565 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 6566 | /* Make all characters printable. */ |
| 6567 | p = transstr(buf); |
| 6568 | if (p != NULL) |
| 6569 | { |
| 6570 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 6571 | vim_free(p); |
| 6572 | } |
| 6573 | |
| 6574 | /* fill up with "fillchar" */ |
| 6575 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 6576 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6577 | { |
| 6578 | #ifdef FEAT_MBYTE |
| 6579 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 6580 | #else |
| 6581 | buf[len++] = fillchar; |
| 6582 | #endif |
| 6583 | ++width; |
| 6584 | } |
| 6585 | buf[len] = NUL; |
| 6586 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6587 | /* |
| 6588 | * Draw each snippet with the specified highlighting. |
| 6589 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6590 | curattr = attr; |
| 6591 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6592 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6593 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6594 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6595 | screen_puts_len(p, len, row, col, curattr); |
| 6596 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6597 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6598 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6599 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6600 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6601 | else if (hltab[n].userhl < 0) |
| 6602 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6603 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6604 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6605 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6606 | #endif |
| 6607 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6608 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6609 | } |
| 6610 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6611 | |
| 6612 | if (wp == NULL) |
| 6613 | { |
| 6614 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 6615 | col = 0; |
| 6616 | len = 0; |
| 6617 | p = buf; |
| 6618 | fillchar = 0; |
| 6619 | for (n = 0; tabtab[n].start != NULL; n++) |
| 6620 | { |
| 6621 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 6622 | while (col < len) |
| 6623 | TabPageIdxs[col++] = fillchar; |
| 6624 | p = tabtab[n].start; |
| 6625 | fillchar = tabtab[n].userhl; |
| 6626 | } |
| 6627 | while (col < Columns) |
| 6628 | TabPageIdxs[col++] = fillchar; |
| 6629 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6630 | } |
| 6631 | |
| 6632 | #endif /* FEAT_STL_OPT */ |
| 6633 | |
| 6634 | /* |
| 6635 | * Output a single character directly to the screen and update ScreenLines. |
| 6636 | */ |
| 6637 | void |
| 6638 | screen_putchar(c, row, col, attr) |
| 6639 | int c; |
| 6640 | int row, col; |
| 6641 | int attr; |
| 6642 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6643 | char_u buf[MB_MAXBYTES + 1]; |
| 6644 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 6645 | #ifdef FEAT_MBYTE |
| 6646 | if (has_mbyte) |
| 6647 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 6648 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6649 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 6650 | { |
| 6651 | buf[0] = c; |
| 6652 | buf[1] = NUL; |
| 6653 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6654 | screen_puts(buf, row, col, attr); |
| 6655 | } |
| 6656 | |
| 6657 | /* |
| 6658 | * Get a single character directly from ScreenLines into "bytes[]". |
| 6659 | * Also return its attribute in *attrp; |
| 6660 | */ |
| 6661 | void |
| 6662 | screen_getbytes(row, col, bytes, attrp) |
| 6663 | int row, col; |
| 6664 | char_u *bytes; |
| 6665 | int *attrp; |
| 6666 | { |
| 6667 | unsigned off; |
| 6668 | |
| 6669 | /* safety check */ |
| 6670 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 6671 | { |
| 6672 | off = LineOffset[row] + col; |
| 6673 | *attrp = ScreenAttrs[off]; |
| 6674 | bytes[0] = ScreenLines[off]; |
| 6675 | bytes[1] = NUL; |
| 6676 | |
| 6677 | #ifdef FEAT_MBYTE |
| 6678 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6679 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 6680 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6681 | { |
| 6682 | bytes[0] = ScreenLines[off]; |
| 6683 | bytes[1] = ScreenLines2[off]; |
| 6684 | bytes[2] = NUL; |
| 6685 | } |
| 6686 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 6687 | { |
| 6688 | bytes[1] = ScreenLines[off + 1]; |
| 6689 | bytes[2] = NUL; |
| 6690 | } |
| 6691 | #endif |
| 6692 | } |
| 6693 | } |
| 6694 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6695 | #ifdef FEAT_MBYTE |
| 6696 | static int screen_comp_differs __ARGS((int, int*)); |
| 6697 | |
| 6698 | /* |
| 6699 | * Return TRUE if composing characters for screen posn "off" differs from |
| 6700 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 6701 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6702 | */ |
| 6703 | static int |
| 6704 | screen_comp_differs(off, u8cc) |
| 6705 | int off; |
| 6706 | int *u8cc; |
| 6707 | { |
| 6708 | int i; |
| 6709 | |
| 6710 | for (i = 0; i < Screen_mco; ++i) |
| 6711 | { |
| 6712 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 6713 | return TRUE; |
| 6714 | if (u8cc[i] == 0) |
| 6715 | break; |
| 6716 | } |
| 6717 | return FALSE; |
| 6718 | } |
| 6719 | #endif |
| 6720 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6721 | /* |
| 6722 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 6723 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 6724 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 6725 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 6726 | */ |
| 6727 | void |
| 6728 | screen_puts(text, row, col, attr) |
| 6729 | char_u *text; |
| 6730 | int row; |
| 6731 | int col; |
| 6732 | int attr; |
| 6733 | { |
| 6734 | screen_puts_len(text, -1, row, col, attr); |
| 6735 | } |
| 6736 | |
| 6737 | /* |
| 6738 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 6739 | * a NUL. |
| 6740 | */ |
| 6741 | void |
| 6742 | screen_puts_len(text, len, row, col, attr) |
| 6743 | char_u *text; |
| 6744 | int len; |
| 6745 | int row; |
| 6746 | int col; |
| 6747 | int attr; |
| 6748 | { |
| 6749 | unsigned off; |
| 6750 | char_u *ptr = text; |
| 6751 | int c; |
| 6752 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6753 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6754 | int mbyte_blen = 1; |
| 6755 | int mbyte_cells = 1; |
| 6756 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6757 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6758 | int clear_next_cell = FALSE; |
| 6759 | # ifdef FEAT_ARABIC |
| 6760 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6761 | int pc, nc, nc1; |
| 6762 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6763 | # endif |
| 6764 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6765 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6766 | int force_redraw_this; |
| 6767 | int force_redraw_next = FALSE; |
| 6768 | #endif |
| 6769 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6770 | |
| 6771 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 6772 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6773 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6774 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6775 | #ifdef FEAT_MBYTE |
| 6776 | /* When drawing over the right halve of a double-wide char clear out the |
| 6777 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6778 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6779 | # ifdef FEAT_GUI |
| 6780 | && !gui.in_use |
| 6781 | # endif |
| 6782 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6783 | { |
| 6784 | ScreenLines[off - 1] = ' '; |
| 6785 | ScreenAttrs[off - 1] = 0; |
| 6786 | if (enc_utf8) |
| 6787 | { |
| 6788 | ScreenLinesUC[off - 1] = 0; |
| 6789 | ScreenLinesC[0][off - 1] = 0; |
| 6790 | } |
| 6791 | /* redraw the previous cell, make it empty */ |
| 6792 | screen_char(off - 1, row, col - 1); |
| 6793 | /* force the cell at "col" to be redrawn */ |
| 6794 | force_redraw_next = TRUE; |
| 6795 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6796 | #endif |
| 6797 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6798 | #ifdef FEAT_MBYTE |
| 6799 | max_off = LineOffset[row] + screen_Columns; |
| 6800 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 6801 | while (col < screen_Columns |
| 6802 | && (len < 0 || (int)(ptr - text) < len) |
| 6803 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6804 | { |
| 6805 | c = *ptr; |
| 6806 | #ifdef FEAT_MBYTE |
| 6807 | /* check if this is the first byte of a multibyte */ |
| 6808 | if (has_mbyte) |
| 6809 | { |
| 6810 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6811 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6812 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6813 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6814 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6815 | mbyte_cells = 1; |
| 6816 | else if (enc_dbcs != 0) |
| 6817 | mbyte_cells = mbyte_blen; |
| 6818 | else /* enc_utf8 */ |
| 6819 | { |
| 6820 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6821 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6822 | (int)((text + len) - ptr)); |
| 6823 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6824 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6825 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6826 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6827 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 6828 | if (u8c >= 0x10000) |
| 6829 | { |
| 6830 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 6831 | if (attr == 0) |
| 6832 | attr = hl_attr(HLF_8); |
| 6833 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6834 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6835 | # ifdef FEAT_ARABIC |
| 6836 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 6837 | { |
| 6838 | /* Do Arabic shaping. */ |
| 6839 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 6840 | { |
| 6841 | /* Past end of string to be displayed. */ |
| 6842 | nc = NUL; |
| 6843 | nc1 = NUL; |
| 6844 | } |
| 6845 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6846 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 6847 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 6848 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6849 | nc1 = pcc[0]; |
| 6850 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6851 | pc = prev_c; |
| 6852 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6853 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6854 | } |
| 6855 | else |
| 6856 | prev_c = u8c; |
| 6857 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 6858 | if (col + mbyte_cells > screen_Columns) |
| 6859 | { |
| 6860 | /* Only 1 cell left, but character requires 2 cells: |
| 6861 | * display a '>' in the last column to avoid wrapping. */ |
| 6862 | c = '>'; |
| 6863 | mbyte_cells = 1; |
| 6864 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6865 | } |
| 6866 | } |
| 6867 | #endif |
| 6868 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6869 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6870 | force_redraw_this = force_redraw_next; |
| 6871 | force_redraw_next = FALSE; |
| 6872 | #endif |
| 6873 | |
| 6874 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6875 | #ifdef FEAT_MBYTE |
| 6876 | || (mbyte_cells == 2 |
| 6877 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 6878 | || (enc_dbcs == DBCS_JPNU |
| 6879 | && c == 0x8e |
| 6880 | && ScreenLines2[off] != ptr[1]) |
| 6881 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 6882 | && (ScreenLinesUC[off] != |
| 6883 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 6884 | || (ScreenLinesUC[off] != 0 |
| 6885 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6886 | #endif |
| 6887 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6888 | || exmode_active; |
| 6889 | |
| 6890 | if (need_redraw |
| 6891 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6892 | || force_redraw_this |
| 6893 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6894 | ) |
| 6895 | { |
| 6896 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6897 | /* The bold trick makes a single row of pixels appear in the next |
| 6898 | * character. When a bold character is removed, the next |
| 6899 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6900 | * and for some xterms. */ |
| 6901 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6902 | # ifdef FEAT_GUI |
| 6903 | gui.in_use |
| 6904 | # endif |
| 6905 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6906 | || |
| 6907 | # endif |
| 6908 | # ifdef UNIX |
| 6909 | term_is_xterm |
| 6910 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6911 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6912 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6913 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6914 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6915 | if (n > HL_ALL) |
| 6916 | n = syn_attr2attr(n); |
| 6917 | if (n & HL_BOLD) |
| 6918 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6919 | } |
| 6920 | #endif |
| 6921 | #ifdef FEAT_MBYTE |
| 6922 | /* When at the end of the text and overwriting a two-cell |
| 6923 | * character with a one-cell character, need to clear the next |
| 6924 | * cell. Also when overwriting the left halve of a two-cell char |
| 6925 | * with the right halve of a two-cell char. Do this only once |
| 6926 | * (mb_off2cells() may return 2 on the right halve). */ |
| 6927 | if (clear_next_cell) |
| 6928 | clear_next_cell = FALSE; |
| 6929 | else if (has_mbyte |
| 6930 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 6931 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6932 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6933 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6934 | && (*mb_off2cells)(off, max_off) == 1 |
| 6935 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6936 | clear_next_cell = TRUE; |
| 6937 | |
| 6938 | /* Make sure we never leave a second byte of a double-byte behind, |
| 6939 | * it confuses mb_off2cells(). */ |
| 6940 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6941 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6942 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6943 | && (*mb_off2cells)(off, max_off) == 1 |
| 6944 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6945 | ScreenLines[off + mbyte_blen] = 0; |
| 6946 | #endif |
| 6947 | ScreenLines[off] = c; |
| 6948 | ScreenAttrs[off] = attr; |
| 6949 | #ifdef FEAT_MBYTE |
| 6950 | if (enc_utf8) |
| 6951 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6952 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6953 | ScreenLinesUC[off] = 0; |
| 6954 | else |
| 6955 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6956 | int i; |
| 6957 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6958 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6959 | for (i = 0; i < Screen_mco; ++i) |
| 6960 | { |
| 6961 | ScreenLinesC[i][off] = u8cc[i]; |
| 6962 | if (u8cc[i] == 0) |
| 6963 | break; |
| 6964 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6965 | } |
| 6966 | if (mbyte_cells == 2) |
| 6967 | { |
| 6968 | ScreenLines[off + 1] = 0; |
| 6969 | ScreenAttrs[off + 1] = attr; |
| 6970 | } |
| 6971 | screen_char(off, row, col); |
| 6972 | } |
| 6973 | else if (mbyte_cells == 2) |
| 6974 | { |
| 6975 | ScreenLines[off + 1] = ptr[1]; |
| 6976 | ScreenAttrs[off + 1] = attr; |
| 6977 | screen_char_2(off, row, col); |
| 6978 | } |
| 6979 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6980 | { |
| 6981 | ScreenLines2[off] = ptr[1]; |
| 6982 | screen_char(off, row, col); |
| 6983 | } |
| 6984 | else |
| 6985 | #endif |
| 6986 | screen_char(off, row, col); |
| 6987 | } |
| 6988 | #ifdef FEAT_MBYTE |
| 6989 | if (has_mbyte) |
| 6990 | { |
| 6991 | off += mbyte_cells; |
| 6992 | col += mbyte_cells; |
| 6993 | ptr += mbyte_blen; |
| 6994 | if (clear_next_cell) |
| 6995 | ptr = (char_u *)" "; |
| 6996 | } |
| 6997 | else |
| 6998 | #endif |
| 6999 | { |
| 7000 | ++off; |
| 7001 | ++col; |
| 7002 | ++ptr; |
| 7003 | } |
| 7004 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7005 | |
| 7006 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7007 | /* If we detected the next character needs to be redrawn, but the text |
| 7008 | * doesn't extend up to there, update the character here. */ |
| 7009 | if (force_redraw_next && col < screen_Columns) |
| 7010 | { |
| 7011 | # ifdef FEAT_MBYTE |
| 7012 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7013 | screen_char_2(off, row, col); |
| 7014 | else |
| 7015 | # endif |
| 7016 | screen_char(off, row, col); |
| 7017 | } |
| 7018 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7019 | } |
| 7020 | |
| 7021 | #ifdef FEAT_SEARCH_EXTRA |
| 7022 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7023 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7024 | */ |
| 7025 | static void |
| 7026 | start_search_hl() |
| 7027 | { |
| 7028 | if (p_hls && !no_hlsearch) |
| 7029 | { |
| 7030 | last_pat_prog(&search_hl.rm); |
| 7031 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7032 | # ifdef FEAT_RELTIME |
| 7033 | /* Set the time limit to 'redrawtime'. */ |
| 7034 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7035 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7036 | } |
| 7037 | } |
| 7038 | |
| 7039 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7040 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7041 | */ |
| 7042 | static void |
| 7043 | end_search_hl() |
| 7044 | { |
| 7045 | if (search_hl.rm.regprog != NULL) |
| 7046 | { |
| 7047 | vim_free(search_hl.rm.regprog); |
| 7048 | search_hl.rm.regprog = NULL; |
| 7049 | } |
| 7050 | } |
| 7051 | |
| 7052 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7053 | * Init for calling prepare_search_hl(). |
| 7054 | */ |
| 7055 | static void |
| 7056 | init_search_hl(wp) |
| 7057 | win_T *wp; |
| 7058 | { |
| 7059 | matchitem_T *cur; |
| 7060 | |
| 7061 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7062 | * match */ |
| 7063 | cur = wp->w_match_head; |
| 7064 | while (cur != NULL) |
| 7065 | { |
| 7066 | cur->hl.rm = cur->match; |
| 7067 | if (cur->hlg_id == 0) |
| 7068 | cur->hl.attr = 0; |
| 7069 | else |
| 7070 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7071 | cur->hl.buf = wp->w_buffer; |
| 7072 | cur->hl.lnum = 0; |
| 7073 | cur->hl.first_lnum = 0; |
| 7074 | # ifdef FEAT_RELTIME |
| 7075 | /* Set the time limit to 'redrawtime'. */ |
| 7076 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7077 | # endif |
| 7078 | cur = cur->next; |
| 7079 | } |
| 7080 | search_hl.buf = wp->w_buffer; |
| 7081 | search_hl.lnum = 0; |
| 7082 | search_hl.first_lnum = 0; |
| 7083 | /* time limit is set at the toplevel, for all windows */ |
| 7084 | } |
| 7085 | |
| 7086 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7087 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7088 | */ |
| 7089 | static void |
| 7090 | prepare_search_hl(wp, lnum) |
| 7091 | win_T *wp; |
| 7092 | linenr_T lnum; |
| 7093 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7094 | matchitem_T *cur; /* points to the match list */ |
| 7095 | match_T *shl; /* points to search_hl or a match */ |
| 7096 | int shl_flag; /* flag to indicate whether search_hl |
| 7097 | has been processed or not */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7098 | int n; |
| 7099 | |
| 7100 | /* |
| 7101 | * When using a multi-line pattern, start searching at the top |
| 7102 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7103 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7104 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7105 | cur = wp->w_match_head; |
| 7106 | shl_flag = FALSE; |
| 7107 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7108 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7109 | if (shl_flag == FALSE) |
| 7110 | { |
| 7111 | shl = &search_hl; |
| 7112 | shl_flag = TRUE; |
| 7113 | } |
| 7114 | else |
| 7115 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7116 | if (shl->rm.regprog != NULL |
| 7117 | && shl->lnum == 0 |
| 7118 | && re_multiline(shl->rm.regprog)) |
| 7119 | { |
| 7120 | if (shl->first_lnum == 0) |
| 7121 | { |
| 7122 | # ifdef FEAT_FOLDING |
| 7123 | for (shl->first_lnum = lnum; |
| 7124 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7125 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7126 | NULL, NULL, TRUE, NULL)) |
| 7127 | break; |
| 7128 | # else |
| 7129 | shl->first_lnum = wp->w_topline; |
| 7130 | # endif |
| 7131 | } |
| 7132 | n = 0; |
| 7133 | while (shl->first_lnum < lnum && shl->rm.regprog != NULL) |
| 7134 | { |
| 7135 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); |
| 7136 | if (shl->lnum != 0) |
| 7137 | { |
| 7138 | shl->first_lnum = shl->lnum |
| 7139 | + shl->rm.endpos[0].lnum |
| 7140 | - shl->rm.startpos[0].lnum; |
| 7141 | n = shl->rm.endpos[0].col; |
| 7142 | } |
| 7143 | else |
| 7144 | { |
| 7145 | ++shl->first_lnum; |
| 7146 | n = 0; |
| 7147 | } |
| 7148 | } |
| 7149 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7150 | if (shl != &search_hl && cur != NULL) |
| 7151 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7152 | } |
| 7153 | } |
| 7154 | |
| 7155 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7156 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7157 | * Uses shl->buf. |
| 7158 | * Sets shl->lnum and shl->rm contents. |
| 7159 | * Note: Assumes a previous match is always before "lnum", unless |
| 7160 | * shl->lnum is zero. |
| 7161 | * Careful: Any pointers for buffer lines will become invalid. |
| 7162 | */ |
| 7163 | static void |
| 7164 | next_search_hl(win, shl, lnum, mincol) |
| 7165 | win_T *win; |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7166 | match_T *shl; /* points to search_hl or a match */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7167 | linenr_T lnum; |
| 7168 | colnr_T mincol; /* minimal column for a match */ |
| 7169 | { |
| 7170 | linenr_T l; |
| 7171 | colnr_T matchcol; |
| 7172 | long nmatched; |
| 7173 | |
| 7174 | if (shl->lnum != 0) |
| 7175 | { |
| 7176 | /* Check for three situations: |
| 7177 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7178 | * 2. If the previous match includes "mincol", use it. |
| 7179 | * 3. Continue after the previous match. |
| 7180 | */ |
| 7181 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7182 | if (lnum > l) |
| 7183 | shl->lnum = 0; |
| 7184 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7185 | return; |
| 7186 | } |
| 7187 | |
| 7188 | /* |
| 7189 | * Repeat searching for a match until one is found that includes "mincol" |
| 7190 | * or none is found in this line. |
| 7191 | */ |
| 7192 | called_emsg = FALSE; |
| 7193 | for (;;) |
| 7194 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7195 | #ifdef FEAT_RELTIME |
| 7196 | /* Stop searching after passing the time limit. */ |
| 7197 | if (profile_passed_limit(&(shl->tm))) |
| 7198 | { |
| 7199 | shl->lnum = 0; /* no match found in time */ |
| 7200 | break; |
| 7201 | } |
| 7202 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7203 | /* Three situations: |
| 7204 | * 1. No useful previous match: search from start of line. |
| 7205 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7206 | * Break the loop if this is beyond the end of the line. |
| 7207 | * 3. Vi compatible searching: continue at end of previous match. |
| 7208 | */ |
| 7209 | if (shl->lnum == 0) |
| 7210 | matchcol = 0; |
| 7211 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7212 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7213 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7214 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7215 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7216 | |
| 7217 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7218 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7219 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7220 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7221 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7222 | shl->lnum = 0; |
| 7223 | break; |
| 7224 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7225 | #ifdef FEAT_MBYTE |
| 7226 | if (has_mbyte) |
| 7227 | matchcol += mb_ptr2len(ml); |
| 7228 | else |
| 7229 | #endif |
| 7230 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7231 | } |
| 7232 | else |
| 7233 | matchcol = shl->rm.endpos[0].col; |
| 7234 | |
| 7235 | shl->lnum = lnum; |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7236 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
| 7237 | #ifdef FEAT_RELTIME |
| 7238 | &(shl->tm) |
| 7239 | #else |
| 7240 | NULL |
| 7241 | #endif |
| 7242 | ); |
Bram Moolenaar | c7040a5 | 2010-07-20 13:11:28 +0200 | [diff] [blame] | 7243 | if (called_emsg || got_int) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7244 | { |
| 7245 | /* Error while handling regexp: stop using this regexp. */ |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7246 | if (shl == &search_hl) |
| 7247 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7248 | /* don't free regprog in the match list, it's a copy */ |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7249 | vim_free(shl->rm.regprog); |
| 7250 | no_hlsearch = TRUE; |
| 7251 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7252 | shl->rm.regprog = NULL; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7253 | shl->lnum = 0; |
| 7254 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7255 | break; |
| 7256 | } |
| 7257 | if (nmatched == 0) |
| 7258 | { |
| 7259 | shl->lnum = 0; /* no match found */ |
| 7260 | break; |
| 7261 | } |
| 7262 | if (shl->rm.startpos[0].lnum > 0 |
| 7263 | || shl->rm.startpos[0].col >= mincol |
| 7264 | || nmatched > 1 |
| 7265 | || shl->rm.endpos[0].col > mincol) |
| 7266 | { |
| 7267 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7268 | break; /* useful match found */ |
| 7269 | } |
| 7270 | } |
| 7271 | } |
| 7272 | #endif |
| 7273 | |
| 7274 | static void |
| 7275 | screen_start_highlight(attr) |
| 7276 | int attr; |
| 7277 | { |
| 7278 | attrentry_T *aep = NULL; |
| 7279 | |
| 7280 | screen_attr = attr; |
| 7281 | if (full_screen |
| 7282 | #ifdef WIN3264 |
| 7283 | && termcap_active |
| 7284 | #endif |
| 7285 | ) |
| 7286 | { |
| 7287 | #ifdef FEAT_GUI |
| 7288 | if (gui.in_use) |
| 7289 | { |
| 7290 | char buf[20]; |
| 7291 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7292 | /* The GUI handles this internally. */ |
| 7293 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7294 | OUT_STR(buf); |
| 7295 | } |
| 7296 | else |
| 7297 | #endif |
| 7298 | { |
| 7299 | if (attr > HL_ALL) /* special HL attr. */ |
| 7300 | { |
| 7301 | if (t_colors > 1) |
| 7302 | aep = syn_cterm_attr2entry(attr); |
| 7303 | else |
| 7304 | aep = syn_term_attr2entry(attr); |
| 7305 | if (aep == NULL) /* did ":syntax clear" */ |
| 7306 | attr = 0; |
| 7307 | else |
| 7308 | attr = aep->ae_attr; |
| 7309 | } |
| 7310 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7311 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7312 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 7313 | && cterm_normal_fg_bold) |
| 7314 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7315 | * has a FG color defined, clear BOLD. */ |
| 7316 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7317 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7318 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7319 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7320 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7321 | out_str(T_US); |
| 7322 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7323 | out_str(T_CZH); |
| 7324 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7325 | out_str(T_MR); |
| 7326 | |
| 7327 | /* |
| 7328 | * Output the color or start string after bold etc., in case the |
| 7329 | * bold etc. override the color setting. |
| 7330 | */ |
| 7331 | if (aep != NULL) |
| 7332 | { |
| 7333 | if (t_colors > 1) |
| 7334 | { |
| 7335 | if (aep->ae_u.cterm.fg_color) |
| 7336 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7337 | if (aep->ae_u.cterm.bg_color) |
| 7338 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7339 | } |
| 7340 | else |
| 7341 | { |
| 7342 | if (aep->ae_u.term.start != NULL) |
| 7343 | out_str(aep->ae_u.term.start); |
| 7344 | } |
| 7345 | } |
| 7346 | } |
| 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | void |
| 7351 | screen_stop_highlight() |
| 7352 | { |
| 7353 | int do_ME = FALSE; /* output T_ME code */ |
| 7354 | |
| 7355 | if (screen_attr != 0 |
| 7356 | #ifdef WIN3264 |
| 7357 | && termcap_active |
| 7358 | #endif |
| 7359 | ) |
| 7360 | { |
| 7361 | #ifdef FEAT_GUI |
| 7362 | if (gui.in_use) |
| 7363 | { |
| 7364 | char buf[20]; |
| 7365 | |
| 7366 | /* use internal GUI code */ |
| 7367 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7368 | OUT_STR(buf); |
| 7369 | } |
| 7370 | else |
| 7371 | #endif |
| 7372 | { |
| 7373 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7374 | { |
| 7375 | attrentry_T *aep; |
| 7376 | |
| 7377 | if (t_colors > 1) |
| 7378 | { |
| 7379 | /* |
| 7380 | * Assume that t_me restores the original colors! |
| 7381 | */ |
| 7382 | aep = syn_cterm_attr2entry(screen_attr); |
| 7383 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 7384 | || aep->ae_u.cterm.bg_color)) |
| 7385 | do_ME = TRUE; |
| 7386 | } |
| 7387 | else |
| 7388 | { |
| 7389 | aep = syn_term_attr2entry(screen_attr); |
| 7390 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7391 | { |
| 7392 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7393 | do_ME = TRUE; |
| 7394 | else |
| 7395 | out_str(aep->ae_u.term.stop); |
| 7396 | } |
| 7397 | } |
| 7398 | if (aep == NULL) /* did ":syntax clear" */ |
| 7399 | screen_attr = 0; |
| 7400 | else |
| 7401 | screen_attr = aep->ae_attr; |
| 7402 | } |
| 7403 | |
| 7404 | /* |
| 7405 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 7406 | * same sequence several times. |
| 7407 | */ |
| 7408 | if (screen_attr & HL_STANDOUT) |
| 7409 | { |
| 7410 | if (STRCMP(T_SE, T_ME) == 0) |
| 7411 | do_ME = TRUE; |
| 7412 | else |
| 7413 | out_str(T_SE); |
| 7414 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7415 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7416 | { |
| 7417 | if (STRCMP(T_UE, T_ME) == 0) |
| 7418 | do_ME = TRUE; |
| 7419 | else |
| 7420 | out_str(T_UE); |
| 7421 | } |
| 7422 | if (screen_attr & HL_ITALIC) |
| 7423 | { |
| 7424 | if (STRCMP(T_CZR, T_ME) == 0) |
| 7425 | do_ME = TRUE; |
| 7426 | else |
| 7427 | out_str(T_CZR); |
| 7428 | } |
| 7429 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 7430 | out_str(T_ME); |
| 7431 | |
| 7432 | if (t_colors > 1) |
| 7433 | { |
| 7434 | /* set Normal cterm colors */ |
| 7435 | if (cterm_normal_fg_color != 0) |
| 7436 | term_fg_color(cterm_normal_fg_color - 1); |
| 7437 | if (cterm_normal_bg_color != 0) |
| 7438 | term_bg_color(cterm_normal_bg_color - 1); |
| 7439 | if (cterm_normal_fg_bold) |
| 7440 | out_str(T_MD); |
| 7441 | } |
| 7442 | } |
| 7443 | } |
| 7444 | screen_attr = 0; |
| 7445 | } |
| 7446 | |
| 7447 | /* |
| 7448 | * Reset the colors for a cterm. Used when leaving Vim. |
| 7449 | * The machine specific code may override this again. |
| 7450 | */ |
| 7451 | void |
| 7452 | reset_cterm_colors() |
| 7453 | { |
| 7454 | if (t_colors > 1) |
| 7455 | { |
| 7456 | /* set Normal cterm colors */ |
| 7457 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 7458 | { |
| 7459 | out_str(T_OP); |
| 7460 | screen_attr = -1; |
| 7461 | } |
| 7462 | if (cterm_normal_fg_bold) |
| 7463 | { |
| 7464 | out_str(T_ME); |
| 7465 | screen_attr = -1; |
| 7466 | } |
| 7467 | } |
| 7468 | } |
| 7469 | |
| 7470 | /* |
| 7471 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 7472 | * using the attributes from ScreenAttrs["off"]. |
| 7473 | */ |
| 7474 | static void |
| 7475 | screen_char(off, row, col) |
| 7476 | unsigned off; |
| 7477 | int row; |
| 7478 | int col; |
| 7479 | { |
| 7480 | int attr; |
| 7481 | |
| 7482 | /* Check for illegal values, just in case (could happen just after |
| 7483 | * resizing). */ |
| 7484 | if (row >= screen_Rows || col >= screen_Columns) |
| 7485 | return; |
| 7486 | |
| 7487 | /* Outputting the last character on the screen may scrollup the screen. |
| 7488 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 7489 | if (row == screen_Rows - 1 && col == screen_Columns - 1 |
| 7490 | #ifdef FEAT_RIGHTLEFT |
| 7491 | /* account for first command-line character in rightleft mode */ |
| 7492 | && !cmdmsg_rl |
| 7493 | #endif |
| 7494 | ) |
| 7495 | { |
| 7496 | ScreenAttrs[off] = (sattr_T)-1; |
| 7497 | return; |
| 7498 | } |
| 7499 | |
| 7500 | /* |
| 7501 | * Stop highlighting first, so it's easier to move the cursor. |
| 7502 | */ |
| 7503 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 7504 | if (screen_char_attr != 0) |
| 7505 | attr = screen_char_attr; |
| 7506 | else |
| 7507 | #endif |
| 7508 | attr = ScreenAttrs[off]; |
| 7509 | if (screen_attr != attr) |
| 7510 | screen_stop_highlight(); |
| 7511 | |
| 7512 | windgoto(row, col); |
| 7513 | |
| 7514 | if (screen_attr != attr) |
| 7515 | screen_start_highlight(attr); |
| 7516 | |
| 7517 | #ifdef FEAT_MBYTE |
| 7518 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7519 | { |
| 7520 | char_u buf[MB_MAXBYTES + 1]; |
| 7521 | |
| 7522 | /* Convert UTF-8 character to bytes and write it. */ |
| 7523 | |
| 7524 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 7525 | |
| 7526 | out_str(buf); |
| 7527 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 7528 | ++screen_cur_col; |
| 7529 | } |
| 7530 | else |
| 7531 | #endif |
| 7532 | { |
| 7533 | #ifdef FEAT_MBYTE |
| 7534 | out_flush_check(); |
| 7535 | #endif |
| 7536 | out_char(ScreenLines[off]); |
| 7537 | #ifdef FEAT_MBYTE |
| 7538 | /* double-byte character in single-width cell */ |
| 7539 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7540 | out_char(ScreenLines2[off]); |
| 7541 | #endif |
| 7542 | } |
| 7543 | |
| 7544 | screen_cur_col++; |
| 7545 | } |
| 7546 | |
| 7547 | #ifdef FEAT_MBYTE |
| 7548 | |
| 7549 | /* |
| 7550 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 7551 | * on the screen at position 'row' and 'col'. |
| 7552 | * The attributes of the first byte is used for all. This is required to |
| 7553 | * output the two bytes of a double-byte character with nothing in between. |
| 7554 | */ |
| 7555 | static void |
| 7556 | screen_char_2(off, row, col) |
| 7557 | unsigned off; |
| 7558 | int row; |
| 7559 | int col; |
| 7560 | { |
| 7561 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 7562 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 7563 | return; |
| 7564 | |
| 7565 | /* Outputting the last character on the screen may scrollup the screen. |
| 7566 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 7567 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 7568 | { |
| 7569 | ScreenAttrs[off] = (sattr_T)-1; |
| 7570 | return; |
| 7571 | } |
| 7572 | |
| 7573 | /* Output the first byte normally (positions the cursor), then write the |
| 7574 | * second byte directly. */ |
| 7575 | screen_char(off, row, col); |
| 7576 | out_char(ScreenLines[off + 1]); |
| 7577 | ++screen_cur_col; |
| 7578 | } |
| 7579 | #endif |
| 7580 | |
| 7581 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 7582 | /* |
| 7583 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 7584 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 7585 | */ |
| 7586 | void |
| 7587 | screen_draw_rectangle(row, col, height, width, invert) |
| 7588 | int row; |
| 7589 | int col; |
| 7590 | int height; |
| 7591 | int width; |
| 7592 | int invert; |
| 7593 | { |
| 7594 | int r, c; |
| 7595 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7596 | #ifdef FEAT_MBYTE |
| 7597 | int max_off; |
| 7598 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7599 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7600 | /* Can't use ScreenLines unless initialized */ |
| 7601 | if (ScreenLines == NULL) |
| 7602 | return; |
| 7603 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7604 | if (invert) |
| 7605 | screen_char_attr = HL_INVERSE; |
| 7606 | for (r = row; r < row + height; ++r) |
| 7607 | { |
| 7608 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7609 | #ifdef FEAT_MBYTE |
| 7610 | max_off = off + screen_Columns; |
| 7611 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7612 | for (c = col; c < col + width; ++c) |
| 7613 | { |
| 7614 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7615 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7616 | { |
| 7617 | screen_char_2(off + c, r, c); |
| 7618 | ++c; |
| 7619 | } |
| 7620 | else |
| 7621 | #endif |
| 7622 | { |
| 7623 | screen_char(off + c, r, c); |
| 7624 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7625 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7626 | ++c; |
| 7627 | #endif |
| 7628 | } |
| 7629 | } |
| 7630 | } |
| 7631 | screen_char_attr = 0; |
| 7632 | } |
| 7633 | #endif |
| 7634 | |
| 7635 | #ifdef FEAT_VERTSPLIT |
| 7636 | /* |
| 7637 | * Redraw the characters for a vertically split window. |
| 7638 | */ |
| 7639 | static void |
| 7640 | redraw_block(row, end, wp) |
| 7641 | int row; |
| 7642 | int end; |
| 7643 | win_T *wp; |
| 7644 | { |
| 7645 | int col; |
| 7646 | int width; |
| 7647 | |
| 7648 | # ifdef FEAT_CLIPBOARD |
| 7649 | clip_may_clear_selection(row, end - 1); |
| 7650 | # endif |
| 7651 | |
| 7652 | if (wp == NULL) |
| 7653 | { |
| 7654 | col = 0; |
| 7655 | width = Columns; |
| 7656 | } |
| 7657 | else |
| 7658 | { |
| 7659 | col = wp->w_wincol; |
| 7660 | width = wp->w_width; |
| 7661 | } |
| 7662 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 7663 | } |
| 7664 | #endif |
| 7665 | |
| 7666 | /* |
| 7667 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 7668 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 7669 | * Use attributes 'attr'. |
| 7670 | */ |
| 7671 | void |
| 7672 | screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) |
| 7673 | int start_row, end_row; |
| 7674 | int start_col, end_col; |
| 7675 | int c1, c2; |
| 7676 | int attr; |
| 7677 | { |
| 7678 | int row; |
| 7679 | int col; |
| 7680 | int off; |
| 7681 | int end_off; |
| 7682 | int did_delete; |
| 7683 | int c; |
| 7684 | int norm_term; |
| 7685 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7686 | int force_next = FALSE; |
| 7687 | #endif |
| 7688 | |
| 7689 | if (end_row > screen_Rows) /* safety check */ |
| 7690 | end_row = screen_Rows; |
| 7691 | if (end_col > screen_Columns) /* safety check */ |
| 7692 | end_col = screen_Columns; |
| 7693 | if (ScreenLines == NULL |
| 7694 | || start_row >= end_row |
| 7695 | || start_col >= end_col) /* nothing to do */ |
| 7696 | return; |
| 7697 | |
| 7698 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 7699 | norm_term = ( |
| 7700 | #ifdef FEAT_GUI |
| 7701 | !gui.in_use && |
| 7702 | #endif |
| 7703 | t_colors <= 1); |
| 7704 | for (row = start_row; row < end_row; ++row) |
| 7705 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7706 | #ifdef FEAT_MBYTE |
| 7707 | if (has_mbyte |
| 7708 | # ifdef FEAT_GUI |
| 7709 | && !gui.in_use |
| 7710 | # endif |
| 7711 | ) |
| 7712 | { |
| 7713 | /* When drawing over the right halve of a double-wide char clear |
| 7714 | * out the left halve. When drawing over the left halve of a |
| 7715 | * double wide-char clear out the right halve. Only needed in a |
| 7716 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7717 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 7718 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 7719 | 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] | 7720 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7721 | } |
| 7722 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7723 | /* |
| 7724 | * Try to use delete-line termcap code, when no attributes or in a |
| 7725 | * "normal" terminal, where a bold/italic space is just a |
| 7726 | * space. |
| 7727 | */ |
| 7728 | did_delete = FALSE; |
| 7729 | if (c2 == ' ' |
| 7730 | && end_col == Columns |
| 7731 | && can_clear(T_CE) |
| 7732 | && (attr == 0 |
| 7733 | || (norm_term |
| 7734 | && attr <= HL_ALL |
| 7735 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 7736 | { |
| 7737 | /* |
| 7738 | * check if we really need to clear something |
| 7739 | */ |
| 7740 | col = start_col; |
| 7741 | if (c1 != ' ') /* don't clear first char */ |
| 7742 | ++col; |
| 7743 | |
| 7744 | off = LineOffset[row] + col; |
| 7745 | end_off = LineOffset[row] + end_col; |
| 7746 | |
| 7747 | /* skip blanks (used often, keep it fast!) */ |
| 7748 | #ifdef FEAT_MBYTE |
| 7749 | if (enc_utf8) |
| 7750 | while (off < end_off && ScreenLines[off] == ' ' |
| 7751 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 7752 | ++off; |
| 7753 | else |
| 7754 | #endif |
| 7755 | while (off < end_off && ScreenLines[off] == ' ' |
| 7756 | && ScreenAttrs[off] == 0) |
| 7757 | ++off; |
| 7758 | if (off < end_off) /* something to be cleared */ |
| 7759 | { |
| 7760 | col = off - LineOffset[row]; |
| 7761 | screen_stop_highlight(); |
| 7762 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 7763 | out_str(T_CE); |
| 7764 | screen_start(); /* don't know where cursor is now */ |
| 7765 | col = end_col - col; |
| 7766 | while (col--) /* clear chars in ScreenLines */ |
| 7767 | { |
| 7768 | ScreenLines[off] = ' '; |
| 7769 | #ifdef FEAT_MBYTE |
| 7770 | if (enc_utf8) |
| 7771 | ScreenLinesUC[off] = 0; |
| 7772 | #endif |
| 7773 | ScreenAttrs[off] = 0; |
| 7774 | ++off; |
| 7775 | } |
| 7776 | } |
| 7777 | did_delete = TRUE; /* the chars are cleared now */ |
| 7778 | } |
| 7779 | |
| 7780 | off = LineOffset[row] + start_col; |
| 7781 | c = c1; |
| 7782 | for (col = start_col; col < end_col; ++col) |
| 7783 | { |
| 7784 | if (ScreenLines[off] != c |
| 7785 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7786 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 7787 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7788 | #endif |
| 7789 | || ScreenAttrs[off] != attr |
| 7790 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7791 | || force_next |
| 7792 | #endif |
| 7793 | ) |
| 7794 | { |
| 7795 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7796 | /* The bold trick may make a single row of pixels appear in |
| 7797 | * the next character. When a bold character is removed, the |
| 7798 | * next character should be redrawn too. This happens for our |
| 7799 | * own GUI and for some xterms. */ |
| 7800 | if ( |
| 7801 | # ifdef FEAT_GUI |
| 7802 | gui.in_use |
| 7803 | # endif |
| 7804 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7805 | || |
| 7806 | # endif |
| 7807 | # ifdef UNIX |
| 7808 | term_is_xterm |
| 7809 | # endif |
| 7810 | ) |
| 7811 | { |
| 7812 | if (ScreenLines[off] != ' ' |
| 7813 | && (ScreenAttrs[off] > HL_ALL |
| 7814 | || ScreenAttrs[off] & HL_BOLD)) |
| 7815 | force_next = TRUE; |
| 7816 | else |
| 7817 | force_next = FALSE; |
| 7818 | } |
| 7819 | #endif |
| 7820 | ScreenLines[off] = c; |
| 7821 | #ifdef FEAT_MBYTE |
| 7822 | if (enc_utf8) |
| 7823 | { |
| 7824 | if (c >= 0x80) |
| 7825 | { |
| 7826 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7827 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7828 | } |
| 7829 | else |
| 7830 | ScreenLinesUC[off] = 0; |
| 7831 | } |
| 7832 | #endif |
| 7833 | ScreenAttrs[off] = attr; |
| 7834 | if (!did_delete || c != ' ') |
| 7835 | screen_char(off, row, col); |
| 7836 | } |
| 7837 | ++off; |
| 7838 | if (col == start_col) |
| 7839 | { |
| 7840 | if (did_delete) |
| 7841 | break; |
| 7842 | c = c2; |
| 7843 | } |
| 7844 | } |
| 7845 | if (end_col == Columns) |
| 7846 | LineWraps[row] = FALSE; |
| 7847 | if (row == Rows - 1) /* overwritten the command line */ |
| 7848 | { |
| 7849 | redraw_cmdline = TRUE; |
| 7850 | if (c1 == ' ' && c2 == ' ') |
| 7851 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7852 | if (start_col == 0) |
| 7853 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7854 | } |
| 7855 | } |
| 7856 | } |
| 7857 | |
| 7858 | /* |
| 7859 | * Check if there should be a delay. Used before clearing or redrawing the |
| 7860 | * screen or the command line. |
| 7861 | */ |
| 7862 | void |
| 7863 | check_for_delay(check_msg_scroll) |
| 7864 | int check_msg_scroll; |
| 7865 | { |
| 7866 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 7867 | && !did_wait_return |
| 7868 | && emsg_silent == 0) |
| 7869 | { |
| 7870 | out_flush(); |
| 7871 | ui_delay(1000L, TRUE); |
| 7872 | emsg_on_display = FALSE; |
| 7873 | if (check_msg_scroll) |
| 7874 | msg_scroll = FALSE; |
| 7875 | } |
| 7876 | } |
| 7877 | |
| 7878 | /* |
| 7879 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7880 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7881 | * Returns TRUE if there is a valid screen to write to. |
| 7882 | * Returns FALSE when starting up and screen not initialized yet. |
| 7883 | */ |
| 7884 | int |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7885 | screen_valid(doclear) |
| 7886 | int doclear; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7887 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7888 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7889 | return (ScreenLines != NULL); |
| 7890 | } |
| 7891 | |
| 7892 | /* |
| 7893 | * Resize the shell to Rows and Columns. |
| 7894 | * Allocate ScreenLines[] and associated items. |
| 7895 | * |
| 7896 | * There may be some time between setting Rows and Columns and (re)allocating |
| 7897 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 7898 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 7899 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 7900 | * final size of the shell is needed. |
| 7901 | */ |
| 7902 | void |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7903 | screenalloc(doclear) |
| 7904 | int doclear; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7905 | { |
| 7906 | int new_row, old_row; |
| 7907 | #ifdef FEAT_GUI |
| 7908 | int old_Rows; |
| 7909 | #endif |
| 7910 | win_T *wp; |
| 7911 | int outofmem = FALSE; |
| 7912 | int len; |
| 7913 | schar_T *new_ScreenLines; |
| 7914 | #ifdef FEAT_MBYTE |
| 7915 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7916 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7917 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7918 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7919 | #endif |
| 7920 | sattr_T *new_ScreenAttrs; |
| 7921 | unsigned *new_LineOffset; |
| 7922 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7923 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7924 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7925 | tabpage_T *tp; |
| 7926 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7927 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7928 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 7929 | #ifdef FEAT_AUTOCMD |
| 7930 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7931 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 7932 | retry: |
| 7933 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7934 | /* |
| 7935 | * Allocation of the screen buffers is done only when the size changes and |
| 7936 | * when Rows and Columns have been set and we have started doing full |
| 7937 | * screen stuff. |
| 7938 | */ |
| 7939 | if ((ScreenLines != NULL |
| 7940 | && Rows == screen_Rows |
| 7941 | && Columns == screen_Columns |
| 7942 | #ifdef FEAT_MBYTE |
| 7943 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 7944 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7945 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7946 | #endif |
| 7947 | ) |
| 7948 | || Rows == 0 |
| 7949 | || Columns == 0 |
| 7950 | || (!full_screen && ScreenLines == NULL)) |
| 7951 | return; |
| 7952 | |
| 7953 | /* |
| 7954 | * It's possible that we produce an out-of-memory message below, which |
| 7955 | * will cause this function to be called again. To break the loop, just |
| 7956 | * return here. |
| 7957 | */ |
| 7958 | if (entered) |
| 7959 | return; |
| 7960 | entered = TRUE; |
| 7961 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 7962 | /* |
| 7963 | * Note that the window sizes are updated before reallocating the arrays, |
| 7964 | * thus we must not redraw here! |
| 7965 | */ |
| 7966 | ++RedrawingDisabled; |
| 7967 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7968 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 7969 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7970 | comp_col(); /* recompute columns for shown command and ruler */ |
| 7971 | |
| 7972 | /* |
| 7973 | * We're changing the size of the screen. |
| 7974 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 7975 | * - Move lines from the old arrays into the new arrays, clear extra |
| 7976 | * lines (unless the screen is going to be cleared). |
| 7977 | * - Free the old arrays. |
| 7978 | * |
| 7979 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 7980 | * Continuing with the old ScreenLines may result in a crash, because the |
| 7981 | * size is wrong. |
| 7982 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7983 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7984 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 7985 | #ifdef FEAT_AUTOCMD |
| 7986 | if (aucmd_win != NULL) |
| 7987 | win_free_lsize(aucmd_win); |
| 7988 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7989 | |
| 7990 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 7991 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 7992 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 7993 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7994 | if (enc_utf8) |
| 7995 | { |
| 7996 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 7997 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7998 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7999 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8000 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8001 | } |
| 8002 | if (enc_dbcs == DBCS_JPNU) |
| 8003 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8004 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8005 | #endif |
| 8006 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8007 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8008 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8009 | Rows * sizeof(unsigned)), FALSE); |
| 8010 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8011 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8012 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8013 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8014 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8015 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8016 | { |
| 8017 | if (win_alloc_lines(wp) == FAIL) |
| 8018 | { |
| 8019 | outofmem = TRUE; |
| 8020 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8021 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8022 | #endif |
| 8023 | } |
| 8024 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8025 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8026 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8027 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8028 | outofmem = TRUE; |
| 8029 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8030 | #ifdef FEAT_WINDOWS |
| 8031 | give_up: |
| 8032 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8033 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8034 | #ifdef FEAT_MBYTE |
| 8035 | for (i = 0; i < p_mco; ++i) |
| 8036 | if (new_ScreenLinesC[i] == NULL) |
| 8037 | break; |
| 8038 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8039 | if (new_ScreenLines == NULL |
| 8040 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8041 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8042 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8043 | #endif |
| 8044 | || new_ScreenAttrs == NULL |
| 8045 | || new_LineOffset == NULL |
| 8046 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8047 | #ifdef FEAT_WINDOWS |
| 8048 | || new_TabPageIdxs == NULL |
| 8049 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8050 | || outofmem) |
| 8051 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8052 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8053 | { |
| 8054 | /* guess the size */ |
| 8055 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8056 | |
| 8057 | /* Remember we did this to avoid getting outofmem messages over |
| 8058 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8059 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8060 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8061 | vim_free(new_ScreenLines); |
| 8062 | new_ScreenLines = NULL; |
| 8063 | #ifdef FEAT_MBYTE |
| 8064 | vim_free(new_ScreenLinesUC); |
| 8065 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8066 | for (i = 0; i < p_mco; ++i) |
| 8067 | { |
| 8068 | vim_free(new_ScreenLinesC[i]); |
| 8069 | new_ScreenLinesC[i] = NULL; |
| 8070 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8071 | vim_free(new_ScreenLines2); |
| 8072 | new_ScreenLines2 = NULL; |
| 8073 | #endif |
| 8074 | vim_free(new_ScreenAttrs); |
| 8075 | new_ScreenAttrs = NULL; |
| 8076 | vim_free(new_LineOffset); |
| 8077 | new_LineOffset = NULL; |
| 8078 | vim_free(new_LineWraps); |
| 8079 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8080 | #ifdef FEAT_WINDOWS |
| 8081 | vim_free(new_TabPageIdxs); |
| 8082 | new_TabPageIdxs = NULL; |
| 8083 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8084 | } |
| 8085 | else |
| 8086 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8087 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8088 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8089 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8090 | { |
| 8091 | new_LineOffset[new_row] = new_row * Columns; |
| 8092 | new_LineWraps[new_row] = FALSE; |
| 8093 | |
| 8094 | /* |
| 8095 | * If the screen is not going to be cleared, copy as much as |
| 8096 | * possible from the old screen to the new one and clear the rest |
| 8097 | * (used when resizing the window at the "--more--" prompt or when |
| 8098 | * executing an external command, for the GUI). |
| 8099 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8100 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8101 | { |
| 8102 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8103 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8104 | #ifdef FEAT_MBYTE |
| 8105 | if (enc_utf8) |
| 8106 | { |
| 8107 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8108 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8109 | for (i = 0; i < p_mco; ++i) |
| 8110 | (void)vim_memset(new_ScreenLinesC[i] |
| 8111 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8112 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8113 | } |
| 8114 | if (enc_dbcs == DBCS_JPNU) |
| 8115 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8116 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8117 | #endif |
| 8118 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8119 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8120 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8121 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8122 | { |
| 8123 | if (screen_Columns < Columns) |
| 8124 | len = screen_Columns; |
| 8125 | else |
| 8126 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8127 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8128 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8129 | * may be invalid now. Also when p_mco changes. */ |
| 8130 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8131 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8132 | #endif |
| 8133 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8134 | ScreenLines + LineOffset[old_row], |
| 8135 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8136 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8137 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8138 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8139 | { |
| 8140 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8141 | ScreenLinesUC + LineOffset[old_row], |
| 8142 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8143 | for (i = 0; i < p_mco; ++i) |
| 8144 | mch_memmove(new_ScreenLinesC[i] |
| 8145 | + new_LineOffset[new_row], |
| 8146 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8147 | (size_t)len * sizeof(u8char_T)); |
| 8148 | } |
| 8149 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8150 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8151 | ScreenLines2 + LineOffset[old_row], |
| 8152 | (size_t)len * sizeof(schar_T)); |
| 8153 | #endif |
| 8154 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8155 | ScreenAttrs + LineOffset[old_row], |
| 8156 | (size_t)len * sizeof(sattr_T)); |
| 8157 | } |
| 8158 | } |
| 8159 | } |
| 8160 | /* Use the last line of the screen for the current line. */ |
| 8161 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8162 | } |
| 8163 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8164 | free_screenlines(); |
| 8165 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8166 | ScreenLines = new_ScreenLines; |
| 8167 | #ifdef FEAT_MBYTE |
| 8168 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8169 | for (i = 0; i < p_mco; ++i) |
| 8170 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8171 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8172 | ScreenLines2 = new_ScreenLines2; |
| 8173 | #endif |
| 8174 | ScreenAttrs = new_ScreenAttrs; |
| 8175 | LineOffset = new_LineOffset; |
| 8176 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8177 | #ifdef FEAT_WINDOWS |
| 8178 | TabPageIdxs = new_TabPageIdxs; |
| 8179 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8180 | |
| 8181 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8182 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8183 | #ifdef FEAT_GUI |
| 8184 | old_Rows = screen_Rows; |
| 8185 | #endif |
| 8186 | screen_Rows = Rows; |
| 8187 | screen_Columns = Columns; |
| 8188 | |
| 8189 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8190 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8191 | screenclear2(); |
| 8192 | |
| 8193 | #ifdef FEAT_GUI |
| 8194 | else if (gui.in_use |
| 8195 | && !gui.starting |
| 8196 | && ScreenLines != NULL |
| 8197 | && old_Rows != Rows) |
| 8198 | { |
| 8199 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8200 | /* |
| 8201 | * Adjust the position of the cursor, for when executing an external |
| 8202 | * command. |
| 8203 | */ |
| 8204 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8205 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8206 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8207 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8208 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8209 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8210 | } |
| 8211 | #endif |
| 8212 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8213 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8214 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8215 | |
| 8216 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8217 | /* |
| 8218 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8219 | * in case applying autocommands always changes Rows or Columns. |
| 8220 | */ |
| 8221 | if (starting == 0 && ++retry_count <= 3) |
| 8222 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8223 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8224 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8225 | * jump back to check if we need to allocate the screen again. */ |
| 8226 | goto retry; |
| 8227 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8228 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8229 | } |
| 8230 | |
| 8231 | void |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8232 | free_screenlines() |
| 8233 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8234 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8235 | int i; |
| 8236 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8237 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8238 | for (i = 0; i < Screen_mco; ++i) |
| 8239 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8240 | vim_free(ScreenLines2); |
| 8241 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8242 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8243 | vim_free(ScreenAttrs); |
| 8244 | vim_free(LineOffset); |
| 8245 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8246 | #ifdef FEAT_WINDOWS |
| 8247 | vim_free(TabPageIdxs); |
| 8248 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8249 | } |
| 8250 | |
| 8251 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8252 | screenclear() |
| 8253 | { |
| 8254 | check_for_delay(FALSE); |
| 8255 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8256 | screenclear2(); /* clear the screen */ |
| 8257 | } |
| 8258 | |
| 8259 | static void |
| 8260 | screenclear2() |
| 8261 | { |
| 8262 | int i; |
| 8263 | |
| 8264 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8265 | #ifdef FEAT_GUI |
| 8266 | || (gui.in_use && gui.starting) |
| 8267 | #endif |
| 8268 | ) |
| 8269 | return; |
| 8270 | |
| 8271 | #ifdef FEAT_GUI |
| 8272 | if (!gui.in_use) |
| 8273 | #endif |
| 8274 | screen_attr = -1; /* force setting the Normal colors */ |
| 8275 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8276 | |
| 8277 | #ifdef FEAT_CLIPBOARD |
| 8278 | /* disable selection without redrawing it */ |
| 8279 | clip_scroll_selection(9999); |
| 8280 | #endif |
| 8281 | |
| 8282 | /* blank out ScreenLines */ |
| 8283 | for (i = 0; i < Rows; ++i) |
| 8284 | { |
| 8285 | lineclear(LineOffset[i], (int)Columns); |
| 8286 | LineWraps[i] = FALSE; |
| 8287 | } |
| 8288 | |
| 8289 | if (can_clear(T_CL)) |
| 8290 | { |
| 8291 | out_str(T_CL); /* clear the display */ |
| 8292 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8293 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8294 | } |
| 8295 | else |
| 8296 | { |
| 8297 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8298 | for (i = 0; i < Rows; ++i) |
| 8299 | lineinvalid(LineOffset[i], (int)Columns); |
| 8300 | clear_cmdline = TRUE; |
| 8301 | } |
| 8302 | |
| 8303 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8304 | |
| 8305 | win_rest_invalid(firstwin); |
| 8306 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8307 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8308 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8309 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8310 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8311 | must_redraw = NOT_VALID; |
| 8312 | compute_cmdrow(); |
| 8313 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8314 | msg_col = 0; |
| 8315 | screen_start(); /* don't know where cursor is now */ |
| 8316 | msg_scrolled = 0; /* can't scroll back */ |
| 8317 | msg_didany = FALSE; |
| 8318 | msg_didout = FALSE; |
| 8319 | } |
| 8320 | |
| 8321 | /* |
| 8322 | * Clear one line in ScreenLines. |
| 8323 | */ |
| 8324 | static void |
| 8325 | lineclear(off, width) |
| 8326 | unsigned off; |
| 8327 | int width; |
| 8328 | { |
| 8329 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8330 | #ifdef FEAT_MBYTE |
| 8331 | if (enc_utf8) |
| 8332 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8333 | (size_t)width * sizeof(u8char_T)); |
| 8334 | #endif |
| 8335 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8336 | } |
| 8337 | |
| 8338 | /* |
| 8339 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8340 | * invalid value. |
| 8341 | */ |
| 8342 | static void |
| 8343 | lineinvalid(off, width) |
| 8344 | unsigned off; |
| 8345 | int width; |
| 8346 | { |
| 8347 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8348 | } |
| 8349 | |
| 8350 | #ifdef FEAT_VERTSPLIT |
| 8351 | /* |
| 8352 | * Copy part of a Screenline for vertically split window "wp". |
| 8353 | */ |
| 8354 | static void |
| 8355 | linecopy(to, from, wp) |
| 8356 | int to; |
| 8357 | int from; |
| 8358 | win_T *wp; |
| 8359 | { |
| 8360 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8361 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8362 | |
| 8363 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8364 | wp->w_width * sizeof(schar_T)); |
| 8365 | # ifdef FEAT_MBYTE |
| 8366 | if (enc_utf8) |
| 8367 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8368 | int i; |
| 8369 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8370 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8371 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8372 | for (i = 0; i < p_mco; ++i) |
| 8373 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8374 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8375 | } |
| 8376 | if (enc_dbcs == DBCS_JPNU) |
| 8377 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8378 | wp->w_width * sizeof(schar_T)); |
| 8379 | # endif |
| 8380 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8381 | wp->w_width * sizeof(sattr_T)); |
| 8382 | } |
| 8383 | #endif |
| 8384 | |
| 8385 | /* |
| 8386 | * Return TRUE if clearing with term string "p" would work. |
| 8387 | * It can't work when the string is empty or it won't set the right background. |
| 8388 | */ |
| 8389 | int |
| 8390 | can_clear(p) |
| 8391 | char_u *p; |
| 8392 | { |
| 8393 | return (*p != NUL && (t_colors <= 1 |
| 8394 | #ifdef FEAT_GUI |
| 8395 | || gui.in_use |
| 8396 | #endif |
| 8397 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 8398 | } |
| 8399 | |
| 8400 | /* |
| 8401 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 8402 | * something directly to the screen (shell commands) or a terminal control |
| 8403 | * code. |
| 8404 | */ |
| 8405 | void |
| 8406 | screen_start() |
| 8407 | { |
| 8408 | screen_cur_row = screen_cur_col = 9999; |
| 8409 | } |
| 8410 | |
| 8411 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8412 | * Move the cursor to position "row","col" in the screen. |
| 8413 | * This tries to find the most efficient way to move, minimizing the number of |
| 8414 | * characters sent to the terminal. |
| 8415 | */ |
| 8416 | void |
| 8417 | windgoto(row, col) |
| 8418 | int row; |
| 8419 | int col; |
| 8420 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8421 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8422 | int i; |
| 8423 | int plan; |
| 8424 | int cost; |
| 8425 | int wouldbe_col; |
| 8426 | int noinvcurs; |
| 8427 | char_u *bs; |
| 8428 | int goto_cost; |
| 8429 | int attr; |
| 8430 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8431 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8432 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 8433 | |
| 8434 | #define PLAN_LE 1 |
| 8435 | #define PLAN_CR 2 |
| 8436 | #define PLAN_NL 3 |
| 8437 | #define PLAN_WRITE 4 |
| 8438 | /* Can't use ScreenLines unless initialized */ |
| 8439 | if (ScreenLines == NULL) |
| 8440 | return; |
| 8441 | |
| 8442 | if (col != screen_cur_col || row != screen_cur_row) |
| 8443 | { |
| 8444 | /* Check for valid position. */ |
| 8445 | if (row < 0) /* window without text lines? */ |
| 8446 | row = 0; |
| 8447 | if (row >= screen_Rows) |
| 8448 | row = screen_Rows - 1; |
| 8449 | if (col >= screen_Columns) |
| 8450 | col = screen_Columns - 1; |
| 8451 | |
| 8452 | /* check if no cursor movement is allowed in highlight mode */ |
| 8453 | if (screen_attr && *T_MS == NUL) |
| 8454 | noinvcurs = HIGHL_COST; |
| 8455 | else |
| 8456 | noinvcurs = 0; |
| 8457 | goto_cost = GOTO_COST + noinvcurs; |
| 8458 | |
| 8459 | /* |
| 8460 | * Plan how to do the positioning: |
| 8461 | * 1. Use CR to move it to column 0, same row. |
| 8462 | * 2. Use T_LE to move it a few columns to the left. |
| 8463 | * 3. Use NL to move a few lines down, column 0. |
| 8464 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 8465 | * |
| 8466 | * Don't do this if the cursor went beyond the last column, the cursor |
| 8467 | * position is unknown then (some terminals wrap, some don't ) |
| 8468 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8469 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8470 | * characters to move the cursor to the right. |
| 8471 | */ |
| 8472 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 8473 | { |
| 8474 | /* |
| 8475 | * If the cursor is in the same row, bigger col, we can use CR |
| 8476 | * or T_LE. |
| 8477 | */ |
| 8478 | bs = NULL; /* init for GCC */ |
| 8479 | attr = screen_attr; |
| 8480 | if (row == screen_cur_row && col < screen_cur_col) |
| 8481 | { |
| 8482 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 8483 | if (*T_LE) |
| 8484 | bs = T_LE; /* "cursor left" */ |
| 8485 | else |
| 8486 | bs = T_BC; /* "backspace character (old) */ |
| 8487 | if (*bs) |
| 8488 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 8489 | else |
| 8490 | cost = 999; |
| 8491 | if (col + 1 < cost) /* using CR is less characters */ |
| 8492 | { |
| 8493 | plan = PLAN_CR; |
| 8494 | wouldbe_col = 0; |
| 8495 | cost = 1; /* CR is just one character */ |
| 8496 | } |
| 8497 | else |
| 8498 | { |
| 8499 | plan = PLAN_LE; |
| 8500 | wouldbe_col = col; |
| 8501 | } |
| 8502 | if (noinvcurs) /* will stop highlighting */ |
| 8503 | { |
| 8504 | cost += noinvcurs; |
| 8505 | attr = 0; |
| 8506 | } |
| 8507 | } |
| 8508 | |
| 8509 | /* |
| 8510 | * If the cursor is above where we want to be, we can use CR LF. |
| 8511 | */ |
| 8512 | else if (row > screen_cur_row) |
| 8513 | { |
| 8514 | plan = PLAN_NL; |
| 8515 | wouldbe_col = 0; |
| 8516 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 8517 | if (noinvcurs) /* will stop highlighting */ |
| 8518 | { |
| 8519 | cost += noinvcurs; |
| 8520 | attr = 0; |
| 8521 | } |
| 8522 | } |
| 8523 | |
| 8524 | /* |
| 8525 | * If the cursor is in the same row, smaller col, just use write. |
| 8526 | */ |
| 8527 | else |
| 8528 | { |
| 8529 | plan = PLAN_WRITE; |
| 8530 | wouldbe_col = screen_cur_col; |
| 8531 | cost = 0; |
| 8532 | } |
| 8533 | |
| 8534 | /* |
| 8535 | * Check if any characters that need to be written have the |
| 8536 | * correct attributes. Also avoid UTF-8 characters. |
| 8537 | */ |
| 8538 | i = col - wouldbe_col; |
| 8539 | if (i > 0) |
| 8540 | cost += i; |
| 8541 | if (cost < goto_cost && i > 0) |
| 8542 | { |
| 8543 | /* |
| 8544 | * Check if the attributes are correct without additionally |
| 8545 | * stopping highlighting. |
| 8546 | */ |
| 8547 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 8548 | while (i && *p++ == attr) |
| 8549 | --i; |
| 8550 | if (i != 0) |
| 8551 | { |
| 8552 | /* |
| 8553 | * Try if it works when highlighting is stopped here. |
| 8554 | */ |
| 8555 | if (*--p == 0) |
| 8556 | { |
| 8557 | cost += noinvcurs; |
| 8558 | while (i && *p++ == 0) |
| 8559 | --i; |
| 8560 | } |
| 8561 | if (i != 0) |
| 8562 | cost = 999; /* different attributes, don't do it */ |
| 8563 | } |
| 8564 | #ifdef FEAT_MBYTE |
| 8565 | if (enc_utf8) |
| 8566 | { |
| 8567 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 8568 | for (i = wouldbe_col; i < col; ++i) |
| 8569 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 8570 | { |
| 8571 | cost = 999; |
| 8572 | break; |
| 8573 | } |
| 8574 | } |
| 8575 | #endif |
| 8576 | } |
| 8577 | |
| 8578 | /* |
| 8579 | * We can do it without term_windgoto()! |
| 8580 | */ |
| 8581 | if (cost < goto_cost) |
| 8582 | { |
| 8583 | if (plan == PLAN_LE) |
| 8584 | { |
| 8585 | if (noinvcurs) |
| 8586 | screen_stop_highlight(); |
| 8587 | while (screen_cur_col > col) |
| 8588 | { |
| 8589 | out_str(bs); |
| 8590 | --screen_cur_col; |
| 8591 | } |
| 8592 | } |
| 8593 | else if (plan == PLAN_CR) |
| 8594 | { |
| 8595 | if (noinvcurs) |
| 8596 | screen_stop_highlight(); |
| 8597 | out_char('\r'); |
| 8598 | screen_cur_col = 0; |
| 8599 | } |
| 8600 | else if (plan == PLAN_NL) |
| 8601 | { |
| 8602 | if (noinvcurs) |
| 8603 | screen_stop_highlight(); |
| 8604 | while (screen_cur_row < row) |
| 8605 | { |
| 8606 | out_char('\n'); |
| 8607 | ++screen_cur_row; |
| 8608 | } |
| 8609 | screen_cur_col = 0; |
| 8610 | } |
| 8611 | |
| 8612 | i = col - screen_cur_col; |
| 8613 | if (i > 0) |
| 8614 | { |
| 8615 | /* |
| 8616 | * Use cursor-right if it's one character only. Avoids |
| 8617 | * removing a line of pixels from the last bold char, when |
| 8618 | * using the bold trick in the GUI. |
| 8619 | */ |
| 8620 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 8621 | { |
| 8622 | while (i-- > 0) |
| 8623 | out_char(*T_ND); |
| 8624 | } |
| 8625 | else |
| 8626 | { |
| 8627 | int off; |
| 8628 | |
| 8629 | off = LineOffset[row] + screen_cur_col; |
| 8630 | while (i-- > 0) |
| 8631 | { |
| 8632 | if (ScreenAttrs[off] != screen_attr) |
| 8633 | screen_stop_highlight(); |
| 8634 | #ifdef FEAT_MBYTE |
| 8635 | out_flush_check(); |
| 8636 | #endif |
| 8637 | out_char(ScreenLines[off]); |
| 8638 | #ifdef FEAT_MBYTE |
| 8639 | if (enc_dbcs == DBCS_JPNU |
| 8640 | && ScreenLines[off] == 0x8e) |
| 8641 | out_char(ScreenLines2[off]); |
| 8642 | #endif |
| 8643 | ++off; |
| 8644 | } |
| 8645 | } |
| 8646 | } |
| 8647 | } |
| 8648 | } |
| 8649 | else |
| 8650 | cost = 999; |
| 8651 | |
| 8652 | if (cost >= goto_cost) |
| 8653 | { |
| 8654 | if (noinvcurs) |
| 8655 | screen_stop_highlight(); |
| 8656 | if (row == screen_cur_row && (col > screen_cur_col) && |
| 8657 | *T_CRI != NUL) |
| 8658 | term_cursor_right(col - screen_cur_col); |
| 8659 | else |
| 8660 | term_windgoto(row, col); |
| 8661 | } |
| 8662 | screen_cur_row = row; |
| 8663 | screen_cur_col = col; |
| 8664 | } |
| 8665 | } |
| 8666 | |
| 8667 | /* |
| 8668 | * Set cursor to its position in the current window. |
| 8669 | */ |
| 8670 | void |
| 8671 | setcursor() |
| 8672 | { |
| 8673 | if (redrawing()) |
| 8674 | { |
| 8675 | validate_cursor(); |
| 8676 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 8677 | W_WINCOL(curwin) + ( |
| 8678 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 8679 | /* With 'rightleft' set and the cursor on a double-wide |
| 8680 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8681 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 8682 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 8683 | (has_mbyte |
| 8684 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 8685 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8686 | # endif |
| 8687 | 1)) : |
| 8688 | #endif |
| 8689 | curwin->w_wcol)); |
| 8690 | } |
| 8691 | } |
| 8692 | |
| 8693 | |
| 8694 | /* |
| 8695 | * insert 'line_count' lines at 'row' in window 'wp' |
| 8696 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 8697 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 8698 | * scrolling. |
| 8699 | * Returns FAIL if the lines are not inserted, OK for success. |
| 8700 | */ |
| 8701 | int |
| 8702 | win_ins_lines(wp, row, line_count, invalid, mayclear) |
| 8703 | win_T *wp; |
| 8704 | int row; |
| 8705 | int line_count; |
| 8706 | int invalid; |
| 8707 | int mayclear; |
| 8708 | { |
| 8709 | int did_delete; |
| 8710 | int nextrow; |
| 8711 | int lastrow; |
| 8712 | int retval; |
| 8713 | |
| 8714 | if (invalid) |
| 8715 | wp->w_lines_valid = 0; |
| 8716 | |
| 8717 | if (wp->w_height < 5) |
| 8718 | return FAIL; |
| 8719 | |
| 8720 | if (line_count > wp->w_height - row) |
| 8721 | line_count = wp->w_height - row; |
| 8722 | |
| 8723 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 8724 | if (retval != MAYBE) |
| 8725 | return retval; |
| 8726 | |
| 8727 | /* |
| 8728 | * If there is a next window or a status line, we first try to delete the |
| 8729 | * lines at the bottom to avoid messing what is after the window. |
| 8730 | * If this fails and there are following windows, don't do anything to avoid |
| 8731 | * messing up those windows, better just redraw. |
| 8732 | */ |
| 8733 | did_delete = FALSE; |
| 8734 | #ifdef FEAT_WINDOWS |
| 8735 | if (wp->w_next != NULL || wp->w_status_height) |
| 8736 | { |
| 8737 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8738 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 8739 | did_delete = TRUE; |
| 8740 | else if (wp->w_next) |
| 8741 | return FAIL; |
| 8742 | } |
| 8743 | #endif |
| 8744 | /* |
| 8745 | * if no lines deleted, blank the lines that will end up below the window |
| 8746 | */ |
| 8747 | if (!did_delete) |
| 8748 | { |
| 8749 | #ifdef FEAT_WINDOWS |
| 8750 | wp->w_redr_status = TRUE; |
| 8751 | #endif |
| 8752 | redraw_cmdline = TRUE; |
| 8753 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 8754 | lastrow = nextrow + line_count; |
| 8755 | if (lastrow > Rows) |
| 8756 | lastrow = Rows; |
| 8757 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 8758 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8759 | ' ', ' ', 0); |
| 8760 | } |
| 8761 | |
| 8762 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 8763 | == FAIL) |
| 8764 | { |
| 8765 | /* deletion will have messed up other windows */ |
| 8766 | if (did_delete) |
| 8767 | { |
| 8768 | #ifdef FEAT_WINDOWS |
| 8769 | wp->w_redr_status = TRUE; |
| 8770 | #endif |
| 8771 | win_rest_invalid(W_NEXT(wp)); |
| 8772 | } |
| 8773 | return FAIL; |
| 8774 | } |
| 8775 | |
| 8776 | return OK; |
| 8777 | } |
| 8778 | |
| 8779 | /* |
| 8780 | * delete "line_count" window lines at "row" in window "wp" |
| 8781 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 8782 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 8783 | * scrolling |
| 8784 | * Return OK for success, FAIL if the lines are not deleted. |
| 8785 | */ |
| 8786 | int |
| 8787 | win_del_lines(wp, row, line_count, invalid, mayclear) |
| 8788 | win_T *wp; |
| 8789 | int row; |
| 8790 | int line_count; |
| 8791 | int invalid; |
| 8792 | int mayclear; |
| 8793 | { |
| 8794 | int retval; |
| 8795 | |
| 8796 | if (invalid) |
| 8797 | wp->w_lines_valid = 0; |
| 8798 | |
| 8799 | if (line_count > wp->w_height - row) |
| 8800 | line_count = wp->w_height - row; |
| 8801 | |
| 8802 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 8803 | if (retval != MAYBE) |
| 8804 | return retval; |
| 8805 | |
| 8806 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 8807 | (int)Rows, FALSE, NULL) == FAIL) |
| 8808 | return FAIL; |
| 8809 | |
| 8810 | #ifdef FEAT_WINDOWS |
| 8811 | /* |
| 8812 | * If there are windows or status lines below, try to put them at the |
| 8813 | * correct place. If we can't do that, they have to be redrawn. |
| 8814 | */ |
| 8815 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 8816 | { |
| 8817 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8818 | line_count, (int)Rows, NULL) == FAIL) |
| 8819 | { |
| 8820 | wp->w_redr_status = TRUE; |
| 8821 | win_rest_invalid(wp->w_next); |
| 8822 | } |
| 8823 | } |
| 8824 | /* |
| 8825 | * If this is the last window and there is no status line, redraw the |
| 8826 | * command line later. |
| 8827 | */ |
| 8828 | else |
| 8829 | #endif |
| 8830 | redraw_cmdline = TRUE; |
| 8831 | return OK; |
| 8832 | } |
| 8833 | |
| 8834 | /* |
| 8835 | * Common code for win_ins_lines() and win_del_lines(). |
| 8836 | * Returns OK or FAIL when the work has been done. |
| 8837 | * Returns MAYBE when not finished yet. |
| 8838 | */ |
| 8839 | static int |
| 8840 | win_do_lines(wp, row, line_count, mayclear, del) |
| 8841 | win_T *wp; |
| 8842 | int row; |
| 8843 | int line_count; |
| 8844 | int mayclear; |
| 8845 | int del; |
| 8846 | { |
| 8847 | int retval; |
| 8848 | |
| 8849 | if (!redrawing() || line_count <= 0) |
| 8850 | return FAIL; |
| 8851 | |
| 8852 | /* only a few lines left: redraw is faster */ |
| 8853 | if (mayclear && Rows - line_count < 5 |
| 8854 | #ifdef FEAT_VERTSPLIT |
| 8855 | && wp->w_width == Columns |
| 8856 | #endif |
| 8857 | ) |
| 8858 | { |
| 8859 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 8860 | return FAIL; |
| 8861 | } |
| 8862 | |
| 8863 | /* |
| 8864 | * Delete all remaining lines |
| 8865 | */ |
| 8866 | if (row + line_count >= wp->w_height) |
| 8867 | { |
| 8868 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 8869 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8870 | ' ', ' ', 0); |
| 8871 | return OK; |
| 8872 | } |
| 8873 | |
| 8874 | /* |
| 8875 | * when scrolling, the message on the command line should be cleared, |
| 8876 | * otherwise it will stay there forever. |
| 8877 | */ |
| 8878 | clear_cmdline = TRUE; |
| 8879 | |
| 8880 | /* |
| 8881 | * If the terminal can set a scroll region, use that. |
| 8882 | * Always do this in a vertically split window. This will redraw from |
| 8883 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 8884 | * win_line(). |
| 8885 | * Don't use a scroll region when we are going to redraw the text, writing |
| 8886 | * a character in the lower right corner of the scroll region causes a |
| 8887 | * scroll-up in the DJGPP version. |
| 8888 | */ |
| 8889 | if (scroll_region |
| 8890 | #ifdef FEAT_VERTSPLIT |
| 8891 | || W_WIDTH(wp) != Columns |
| 8892 | #endif |
| 8893 | ) |
| 8894 | { |
| 8895 | #ifdef FEAT_VERTSPLIT |
| 8896 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8897 | #endif |
| 8898 | scroll_region_set(wp, row); |
| 8899 | if (del) |
| 8900 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 8901 | wp->w_height - row, FALSE, wp); |
| 8902 | else |
| 8903 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 8904 | wp->w_height - row, wp); |
| 8905 | #ifdef FEAT_VERTSPLIT |
| 8906 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8907 | #endif |
| 8908 | scroll_region_reset(); |
| 8909 | return retval; |
| 8910 | } |
| 8911 | |
| 8912 | #ifdef FEAT_WINDOWS |
| 8913 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 8914 | return FAIL; |
| 8915 | #endif |
| 8916 | |
| 8917 | return MAYBE; |
| 8918 | } |
| 8919 | |
| 8920 | /* |
| 8921 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 8922 | */ |
| 8923 | static void |
| 8924 | win_rest_invalid(wp) |
| 8925 | win_T *wp; |
| 8926 | { |
| 8927 | #ifdef FEAT_WINDOWS |
| 8928 | while (wp != NULL) |
| 8929 | #else |
| 8930 | if (wp != NULL) |
| 8931 | #endif |
| 8932 | { |
| 8933 | redraw_win_later(wp, NOT_VALID); |
| 8934 | #ifdef FEAT_WINDOWS |
| 8935 | wp->w_redr_status = TRUE; |
| 8936 | wp = wp->w_next; |
| 8937 | #endif |
| 8938 | } |
| 8939 | redraw_cmdline = TRUE; |
| 8940 | } |
| 8941 | |
| 8942 | /* |
| 8943 | * The rest of the routines in this file perform screen manipulations. The |
| 8944 | * given operation is performed physically on the screen. The corresponding |
| 8945 | * change is also made to the internal screen image. In this way, the editor |
| 8946 | * anticipates the effect of editing changes on the appearance of the screen. |
| 8947 | * That way, when we call screenupdate a complete redraw isn't usually |
| 8948 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 8949 | * screen changes, and in the meantime, everything still works. |
| 8950 | */ |
| 8951 | |
| 8952 | /* |
| 8953 | * types for inserting or deleting lines |
| 8954 | */ |
| 8955 | #define USE_T_CAL 1 |
| 8956 | #define USE_T_CDL 2 |
| 8957 | #define USE_T_AL 3 |
| 8958 | #define USE_T_CE 4 |
| 8959 | #define USE_T_DL 5 |
| 8960 | #define USE_T_SR 6 |
| 8961 | #define USE_NL 7 |
| 8962 | #define USE_T_CD 8 |
| 8963 | #define USE_REDRAW 9 |
| 8964 | |
| 8965 | /* |
| 8966 | * insert lines on the screen and update ScreenLines[] |
| 8967 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 8968 | * When scrolling region used 'off' is the offset from the top for the region. |
| 8969 | * 'row' and 'end' are relative to the start of the region. |
| 8970 | * |
| 8971 | * return FAIL for failure, OK for success. |
| 8972 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 8973 | int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8974 | screen_ins_lines(off, row, line_count, end, wp) |
| 8975 | int off; |
| 8976 | int row; |
| 8977 | int line_count; |
| 8978 | int end; |
| 8979 | win_T *wp; /* NULL or window to use width from */ |
| 8980 | { |
| 8981 | int i; |
| 8982 | int j; |
| 8983 | unsigned temp; |
| 8984 | int cursor_row; |
| 8985 | int type; |
| 8986 | int result_empty; |
| 8987 | int can_ce = can_clear(T_CE); |
| 8988 | |
| 8989 | /* |
| 8990 | * FAIL if |
| 8991 | * - there is no valid screen |
| 8992 | * - the screen has to be redrawn completely |
| 8993 | * - the line count is less than one |
| 8994 | * - the line count is more than 'ttyscroll' |
| 8995 | */ |
| 8996 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 8997 | return FAIL; |
| 8998 | |
| 8999 | /* |
| 9000 | * There are seven ways to insert lines: |
| 9001 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9002 | * characters from ScreenLines[]. |
| 9003 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9004 | * the insert is just empty lines |
| 9005 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9006 | * present or line_count > 1. It looks better if we do all the inserts |
| 9007 | * at once. |
| 9008 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9009 | * insert is just empty lines and T_CE is not present or line_count > |
| 9010 | * 1. |
| 9011 | * 4. Use T_AL (insert line) if it exists. |
| 9012 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9013 | * just empty lines. |
| 9014 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9015 | * just empty lines. |
| 9016 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9017 | * the 'da' flag is not set or we have clear line capability. |
| 9018 | * 8. redraw the characters from ScreenLines[]. |
| 9019 | * |
| 9020 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9021 | * the scrollbar for the window. It does have insert line, use that if it |
| 9022 | * exists. |
| 9023 | */ |
| 9024 | result_empty = (row + line_count >= end); |
| 9025 | #ifdef FEAT_VERTSPLIT |
| 9026 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9027 | type = USE_REDRAW; |
| 9028 | else |
| 9029 | #endif |
| 9030 | if (can_clear(T_CD) && result_empty) |
| 9031 | type = USE_T_CD; |
| 9032 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9033 | type = USE_T_CAL; |
| 9034 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9035 | type = USE_T_CDL; |
| 9036 | else if (*T_AL != NUL) |
| 9037 | type = USE_T_AL; |
| 9038 | else if (can_ce && result_empty) |
| 9039 | type = USE_T_CE; |
| 9040 | else if (*T_DL != NUL && result_empty) |
| 9041 | type = USE_T_DL; |
| 9042 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9043 | type = USE_T_SR; |
| 9044 | else |
| 9045 | return FAIL; |
| 9046 | |
| 9047 | /* |
| 9048 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9049 | * care of t_db if necessary. |
| 9050 | */ |
| 9051 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9052 | type == USE_T_CE || type == USE_T_DL) |
| 9053 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9054 | |
| 9055 | /* |
| 9056 | * If text is retained below the screen, first clear or delete as many |
| 9057 | * lines at the bottom of the window as are about to be inserted so that |
| 9058 | * the deleted lines won't later surface during a screen_del_lines. |
| 9059 | */ |
| 9060 | if (*T_DB) |
| 9061 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9062 | |
| 9063 | #ifdef FEAT_CLIPBOARD |
| 9064 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9065 | * or not the full width of the screen. */ |
| 9066 | if (off + row > 0 |
| 9067 | # ifdef FEAT_VERTSPLIT |
| 9068 | || (wp != NULL && wp->w_width != Columns) |
| 9069 | # endif |
| 9070 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9071 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9072 | else |
| 9073 | clip_scroll_selection(-line_count); |
| 9074 | #endif |
| 9075 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9076 | #ifdef FEAT_GUI |
| 9077 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9078 | * scrolling is actually carried out. */ |
| 9079 | gui_dont_update_cursor(); |
| 9080 | #endif |
| 9081 | |
| 9082 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9083 | cursor_row = row; |
| 9084 | else |
| 9085 | cursor_row = row + off; |
| 9086 | |
| 9087 | /* |
| 9088 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9089 | * Clear the inserted lines in ScreenLines[]. |
| 9090 | */ |
| 9091 | row += off; |
| 9092 | end += off; |
| 9093 | for (i = 0; i < line_count; ++i) |
| 9094 | { |
| 9095 | #ifdef FEAT_VERTSPLIT |
| 9096 | if (wp != NULL && wp->w_width != Columns) |
| 9097 | { |
| 9098 | /* need to copy part of a line */ |
| 9099 | j = end - 1 - i; |
| 9100 | while ((j -= line_count) >= row) |
| 9101 | linecopy(j + line_count, j, wp); |
| 9102 | j += line_count; |
| 9103 | if (can_clear((char_u *)" ")) |
| 9104 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9105 | else |
| 9106 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9107 | LineWraps[j] = FALSE; |
| 9108 | } |
| 9109 | else |
| 9110 | #endif |
| 9111 | { |
| 9112 | j = end - 1 - i; |
| 9113 | temp = LineOffset[j]; |
| 9114 | while ((j -= line_count) >= row) |
| 9115 | { |
| 9116 | LineOffset[j + line_count] = LineOffset[j]; |
| 9117 | LineWraps[j + line_count] = LineWraps[j]; |
| 9118 | } |
| 9119 | LineOffset[j + line_count] = temp; |
| 9120 | LineWraps[j + line_count] = FALSE; |
| 9121 | if (can_clear((char_u *)" ")) |
| 9122 | lineclear(temp, (int)Columns); |
| 9123 | else |
| 9124 | lineinvalid(temp, (int)Columns); |
| 9125 | } |
| 9126 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9127 | |
| 9128 | screen_stop_highlight(); |
| 9129 | windgoto(cursor_row, 0); |
| 9130 | |
| 9131 | #ifdef FEAT_VERTSPLIT |
| 9132 | /* redraw the characters */ |
| 9133 | if (type == USE_REDRAW) |
| 9134 | redraw_block(row, end, wp); |
| 9135 | else |
| 9136 | #endif |
| 9137 | if (type == USE_T_CAL) |
| 9138 | { |
| 9139 | term_append_lines(line_count); |
| 9140 | screen_start(); /* don't know where cursor is now */ |
| 9141 | } |
| 9142 | else |
| 9143 | { |
| 9144 | for (i = 0; i < line_count; i++) |
| 9145 | { |
| 9146 | if (type == USE_T_AL) |
| 9147 | { |
| 9148 | if (i && cursor_row != 0) |
| 9149 | windgoto(cursor_row, 0); |
| 9150 | out_str(T_AL); |
| 9151 | } |
| 9152 | else /* type == USE_T_SR */ |
| 9153 | out_str(T_SR); |
| 9154 | screen_start(); /* don't know where cursor is now */ |
| 9155 | } |
| 9156 | } |
| 9157 | |
| 9158 | /* |
| 9159 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9160 | * have been scrolled down into the region. |
| 9161 | */ |
| 9162 | if (type == USE_T_SR && *T_DA) |
| 9163 | { |
| 9164 | for (i = 0; i < line_count; ++i) |
| 9165 | { |
| 9166 | windgoto(off + i, 0); |
| 9167 | out_str(T_CE); |
| 9168 | screen_start(); /* don't know where cursor is now */ |
| 9169 | } |
| 9170 | } |
| 9171 | |
| 9172 | #ifdef FEAT_GUI |
| 9173 | gui_can_update_cursor(); |
| 9174 | if (gui.in_use) |
| 9175 | out_flush(); /* always flush after a scroll */ |
| 9176 | #endif |
| 9177 | return OK; |
| 9178 | } |
| 9179 | |
| 9180 | /* |
| 9181 | * delete lines on the screen and update ScreenLines[] |
| 9182 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9183 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9184 | * 'row' and 'end' are relative to the start of the region. |
| 9185 | * |
| 9186 | * Return OK for success, FAIL if the lines are not deleted. |
| 9187 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9188 | int |
| 9189 | screen_del_lines(off, row, line_count, end, force, wp) |
| 9190 | int off; |
| 9191 | int row; |
| 9192 | int line_count; |
| 9193 | int end; |
| 9194 | int force; /* even when line_count > p_ttyscroll */ |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 9195 | win_T *wp UNUSED; /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9196 | { |
| 9197 | int j; |
| 9198 | int i; |
| 9199 | unsigned temp; |
| 9200 | int cursor_row; |
| 9201 | int cursor_end; |
| 9202 | int result_empty; /* result is empty until end of region */ |
| 9203 | int can_delete; /* deleting line codes can be used */ |
| 9204 | int type; |
| 9205 | |
| 9206 | /* |
| 9207 | * FAIL if |
| 9208 | * - there is no valid screen |
| 9209 | * - the screen has to be redrawn completely |
| 9210 | * - the line count is less than one |
| 9211 | * - the line count is more than 'ttyscroll' |
| 9212 | */ |
| 9213 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9214 | (!force && line_count > p_ttyscroll)) |
| 9215 | return FAIL; |
| 9216 | |
| 9217 | /* |
| 9218 | * Check if the rest of the current region will become empty. |
| 9219 | */ |
| 9220 | result_empty = row + line_count >= end; |
| 9221 | |
| 9222 | /* |
| 9223 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9224 | * available. |
| 9225 | */ |
| 9226 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9227 | |
| 9228 | /* |
| 9229 | * There are six ways to delete lines: |
| 9230 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9231 | * characters from ScreenLines[]. |
| 9232 | * 1. Use T_CD if it exists and the result is empty. |
| 9233 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9234 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9235 | * none of the other ways work. |
| 9236 | * 4. Use T_CE (erase line) if the result is empty. |
| 9237 | * 5. Use T_DL (delete line) if it exists. |
| 9238 | * 6. redraw the characters from ScreenLines[]. |
| 9239 | */ |
| 9240 | #ifdef FEAT_VERTSPLIT |
| 9241 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9242 | type = USE_REDRAW; |
| 9243 | else |
| 9244 | #endif |
| 9245 | if (can_clear(T_CD) && result_empty) |
| 9246 | type = USE_T_CD; |
| 9247 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9248 | /* |
| 9249 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9250 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9251 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9252 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9253 | * the trick... |
| 9254 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9255 | * (Olaf Seibert) |
| 9256 | */ |
| 9257 | else if (row == 0 && T_DB == empty_option |
| 9258 | && (line_count == 1 || *T_CDL == NUL)) |
| 9259 | #else |
| 9260 | else if (row == 0 && ( |
| 9261 | #ifndef AMIGA |
| 9262 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9263 | * up, so use delete-line command */ |
| 9264 | line_count == 1 || |
| 9265 | #endif |
| 9266 | *T_CDL == NUL)) |
| 9267 | #endif |
| 9268 | type = USE_NL; |
| 9269 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9270 | type = USE_T_CDL; |
| 9271 | else if (can_clear(T_CE) && result_empty |
| 9272 | #ifdef FEAT_VERTSPLIT |
| 9273 | && (wp == NULL || wp->w_width == Columns) |
| 9274 | #endif |
| 9275 | ) |
| 9276 | type = USE_T_CE; |
| 9277 | else if (*T_DL != NUL && can_delete) |
| 9278 | type = USE_T_DL; |
| 9279 | else if (*T_CDL != NUL && can_delete) |
| 9280 | type = USE_T_CDL; |
| 9281 | else |
| 9282 | return FAIL; |
| 9283 | |
| 9284 | #ifdef FEAT_CLIPBOARD |
| 9285 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9286 | * not the full width of the screen. */ |
| 9287 | if (off + row > 0 |
| 9288 | # ifdef FEAT_VERTSPLIT |
| 9289 | || (wp != NULL && wp->w_width != Columns) |
| 9290 | # endif |
| 9291 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9292 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9293 | else |
| 9294 | clip_scroll_selection(line_count); |
| 9295 | #endif |
| 9296 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9297 | #ifdef FEAT_GUI |
| 9298 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9299 | * scrolling is actually carried out. */ |
| 9300 | gui_dont_update_cursor(); |
| 9301 | #endif |
| 9302 | |
| 9303 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9304 | { |
| 9305 | cursor_row = row; |
| 9306 | cursor_end = end; |
| 9307 | } |
| 9308 | else |
| 9309 | { |
| 9310 | cursor_row = row + off; |
| 9311 | cursor_end = end + off; |
| 9312 | } |
| 9313 | |
| 9314 | /* |
| 9315 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9316 | * Clear the inserted lines in ScreenLines[]. |
| 9317 | */ |
| 9318 | row += off; |
| 9319 | end += off; |
| 9320 | for (i = 0; i < line_count; ++i) |
| 9321 | { |
| 9322 | #ifdef FEAT_VERTSPLIT |
| 9323 | if (wp != NULL && wp->w_width != Columns) |
| 9324 | { |
| 9325 | /* need to copy part of a line */ |
| 9326 | j = row + i; |
| 9327 | while ((j += line_count) <= end - 1) |
| 9328 | linecopy(j - line_count, j, wp); |
| 9329 | j -= line_count; |
| 9330 | if (can_clear((char_u *)" ")) |
| 9331 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9332 | else |
| 9333 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9334 | LineWraps[j] = FALSE; |
| 9335 | } |
| 9336 | else |
| 9337 | #endif |
| 9338 | { |
| 9339 | /* whole width, moving the line pointers is faster */ |
| 9340 | j = row + i; |
| 9341 | temp = LineOffset[j]; |
| 9342 | while ((j += line_count) <= end - 1) |
| 9343 | { |
| 9344 | LineOffset[j - line_count] = LineOffset[j]; |
| 9345 | LineWraps[j - line_count] = LineWraps[j]; |
| 9346 | } |
| 9347 | LineOffset[j - line_count] = temp; |
| 9348 | LineWraps[j - line_count] = FALSE; |
| 9349 | if (can_clear((char_u *)" ")) |
| 9350 | lineclear(temp, (int)Columns); |
| 9351 | else |
| 9352 | lineinvalid(temp, (int)Columns); |
| 9353 | } |
| 9354 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9355 | |
| 9356 | screen_stop_highlight(); |
| 9357 | |
| 9358 | #ifdef FEAT_VERTSPLIT |
| 9359 | /* redraw the characters */ |
| 9360 | if (type == USE_REDRAW) |
| 9361 | redraw_block(row, end, wp); |
| 9362 | else |
| 9363 | #endif |
| 9364 | if (type == USE_T_CD) /* delete the lines */ |
| 9365 | { |
| 9366 | windgoto(cursor_row, 0); |
| 9367 | out_str(T_CD); |
| 9368 | screen_start(); /* don't know where cursor is now */ |
| 9369 | } |
| 9370 | else if (type == USE_T_CDL) |
| 9371 | { |
| 9372 | windgoto(cursor_row, 0); |
| 9373 | term_delete_lines(line_count); |
| 9374 | screen_start(); /* don't know where cursor is now */ |
| 9375 | } |
| 9376 | /* |
| 9377 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9378 | * the whole screen (scroll region) up by outputting newlines on the |
| 9379 | * last line. |
| 9380 | */ |
| 9381 | else if (type == USE_NL) |
| 9382 | { |
| 9383 | windgoto(cursor_end - 1, 0); |
| 9384 | for (i = line_count; --i >= 0; ) |
| 9385 | out_char('\n'); /* cursor will remain on same line */ |
| 9386 | } |
| 9387 | else |
| 9388 | { |
| 9389 | for (i = line_count; --i >= 0; ) |
| 9390 | { |
| 9391 | if (type == USE_T_DL) |
| 9392 | { |
| 9393 | windgoto(cursor_row, 0); |
| 9394 | out_str(T_DL); /* delete a line */ |
| 9395 | } |
| 9396 | else /* type == USE_T_CE */ |
| 9397 | { |
| 9398 | windgoto(cursor_row + i, 0); |
| 9399 | out_str(T_CE); /* erase a line */ |
| 9400 | } |
| 9401 | screen_start(); /* don't know where cursor is now */ |
| 9402 | } |
| 9403 | } |
| 9404 | |
| 9405 | /* |
| 9406 | * If the 'db' flag is set, we need to clear the lines that have been |
| 9407 | * scrolled up at the bottom of the region. |
| 9408 | */ |
| 9409 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 9410 | { |
| 9411 | for (i = line_count; i > 0; --i) |
| 9412 | { |
| 9413 | windgoto(cursor_end - i, 0); |
| 9414 | out_str(T_CE); /* erase a line */ |
| 9415 | screen_start(); /* don't know where cursor is now */ |
| 9416 | } |
| 9417 | } |
| 9418 | |
| 9419 | #ifdef FEAT_GUI |
| 9420 | gui_can_update_cursor(); |
| 9421 | if (gui.in_use) |
| 9422 | out_flush(); /* always flush after a scroll */ |
| 9423 | #endif |
| 9424 | |
| 9425 | return OK; |
| 9426 | } |
| 9427 | |
| 9428 | /* |
| 9429 | * show the current mode and ruler |
| 9430 | * |
| 9431 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 9432 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 9433 | * cleared only if a mode is shown. |
| 9434 | * Return the length of the message (0 if no message). |
| 9435 | */ |
| 9436 | int |
| 9437 | showmode() |
| 9438 | { |
| 9439 | int need_clear; |
| 9440 | int length = 0; |
| 9441 | int do_mode; |
| 9442 | int attr; |
| 9443 | int nwr_save; |
| 9444 | #ifdef FEAT_INS_EXPAND |
| 9445 | int sub_attr; |
| 9446 | #endif |
| 9447 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 9448 | do_mode = ((p_smd && msg_silent == 0) |
| 9449 | && ((State & INSERT) |
| 9450 | || restart_edit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9451 | #ifdef FEAT_VISUAL |
| 9452 | || VIsual_active |
| 9453 | #endif |
| 9454 | )); |
| 9455 | if (do_mode || Recording) |
| 9456 | { |
| 9457 | /* |
| 9458 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 9459 | * Call char_avail() only when we are going to show something, because |
| 9460 | * it takes a bit of time. |
| 9461 | */ |
| 9462 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 9463 | { |
| 9464 | redraw_cmdline = TRUE; /* show mode later */ |
| 9465 | return 0; |
| 9466 | } |
| 9467 | |
| 9468 | nwr_save = need_wait_return; |
| 9469 | |
| 9470 | /* wait a bit before overwriting an important message */ |
| 9471 | check_for_delay(FALSE); |
| 9472 | |
| 9473 | /* if the cmdline is more than one line high, erase top lines */ |
| 9474 | need_clear = clear_cmdline; |
| 9475 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 9476 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 9477 | |
| 9478 | /* Position on the last line in the window, column 0 */ |
| 9479 | msg_pos_mode(); |
| 9480 | cursor_off(); |
| 9481 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 9482 | if (do_mode) |
| 9483 | { |
| 9484 | MSG_PUTS_ATTR("--", attr); |
| 9485 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9486 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9487 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9488 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9489 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9490 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9491 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9492 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 9493 | # 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] | 9494 | MSG_PUTS_ATTR(" IM", attr); |
| 9495 | # else |
| 9496 | MSG_PUTS_ATTR(" XIM", attr); |
| 9497 | # endif |
| 9498 | #endif |
| 9499 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 9500 | if (gui.in_use) |
| 9501 | { |
| 9502 | if (hangul_input_state_get()) |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9503 | MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9504 | } |
| 9505 | #endif |
| 9506 | #ifdef FEAT_INS_EXPAND |
| 9507 | if (edit_submode != NULL) /* CTRL-X in Insert mode */ |
| 9508 | { |
| 9509 | /* These messages can get long, avoid a wrap in a narrow |
| 9510 | * window. Prefer showing edit_submode_extra. */ |
| 9511 | length = (Rows - msg_row) * Columns - 3; |
| 9512 | if (edit_submode_extra != NULL) |
| 9513 | length -= vim_strsize(edit_submode_extra); |
| 9514 | if (length > 0) |
| 9515 | { |
| 9516 | if (edit_submode_pre != NULL) |
| 9517 | length -= vim_strsize(edit_submode_pre); |
| 9518 | if (length - vim_strsize(edit_submode) > 0) |
| 9519 | { |
| 9520 | if (edit_submode_pre != NULL) |
| 9521 | msg_puts_attr(edit_submode_pre, attr); |
| 9522 | msg_puts_attr(edit_submode, attr); |
| 9523 | } |
| 9524 | if (edit_submode_extra != NULL) |
| 9525 | { |
| 9526 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 9527 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 9528 | sub_attr = hl_attr(edit_submode_highl); |
| 9529 | else |
| 9530 | sub_attr = attr; |
| 9531 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 9532 | } |
| 9533 | } |
| 9534 | length = 0; |
| 9535 | } |
| 9536 | else |
| 9537 | #endif |
| 9538 | { |
| 9539 | #ifdef FEAT_VREPLACE |
| 9540 | if (State & VREPLACE_FLAG) |
| 9541 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 9542 | else |
| 9543 | #endif |
| 9544 | if (State & REPLACE_FLAG) |
| 9545 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 9546 | else if (State & INSERT) |
| 9547 | { |
| 9548 | #ifdef FEAT_RIGHTLEFT |
| 9549 | if (p_ri) |
| 9550 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 9551 | #endif |
| 9552 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 9553 | } |
| 9554 | else if (restart_edit == 'I') |
| 9555 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 9556 | else if (restart_edit == 'R') |
| 9557 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 9558 | else if (restart_edit == 'V') |
| 9559 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 9560 | #ifdef FEAT_RIGHTLEFT |
| 9561 | if (p_hkmap) |
| 9562 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 9563 | # ifdef FEAT_FKMAP |
| 9564 | if (p_fkmap) |
| 9565 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 9566 | # endif |
| 9567 | #endif |
| 9568 | #ifdef FEAT_KEYMAP |
| 9569 | if (State & LANGMAP) |
| 9570 | { |
| 9571 | # ifdef FEAT_ARABIC |
| 9572 | if (curwin->w_p_arab) |
| 9573 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 9574 | else |
| 9575 | # endif |
| 9576 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 9577 | } |
| 9578 | #endif |
| 9579 | if ((State & INSERT) && p_paste) |
| 9580 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 9581 | |
| 9582 | #ifdef FEAT_VISUAL |
| 9583 | if (VIsual_active) |
| 9584 | { |
| 9585 | char *p; |
| 9586 | |
| 9587 | /* Don't concatenate separate words to avoid translation |
| 9588 | * problems. */ |
| 9589 | switch ((VIsual_select ? 4 : 0) |
| 9590 | + (VIsual_mode == Ctrl_V) * 2 |
| 9591 | + (VIsual_mode == 'V')) |
| 9592 | { |
| 9593 | case 0: p = N_(" VISUAL"); break; |
| 9594 | case 1: p = N_(" VISUAL LINE"); break; |
| 9595 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 9596 | case 4: p = N_(" SELECT"); break; |
| 9597 | case 5: p = N_(" SELECT LINE"); break; |
| 9598 | default: p = N_(" SELECT BLOCK"); break; |
| 9599 | } |
| 9600 | MSG_PUTS_ATTR(_(p), attr); |
| 9601 | } |
| 9602 | #endif |
| 9603 | MSG_PUTS_ATTR(" --", attr); |
| 9604 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9605 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9606 | need_clear = TRUE; |
| 9607 | } |
| 9608 | if (Recording |
| 9609 | #ifdef FEAT_INS_EXPAND |
| 9610 | && edit_submode == NULL /* otherwise it gets too long */ |
| 9611 | #endif |
| 9612 | ) |
| 9613 | { |
| 9614 | MSG_PUTS_ATTR(_("recording"), attr); |
| 9615 | need_clear = TRUE; |
| 9616 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9617 | |
| 9618 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9619 | if (need_clear || clear_cmdline) |
| 9620 | msg_clr_eos(); |
| 9621 | msg_didout = FALSE; /* overwrite this message */ |
| 9622 | length = msg_col; |
| 9623 | msg_col = 0; |
| 9624 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 9625 | } |
| 9626 | else if (clear_cmdline && msg_silent == 0) |
| 9627 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 9628 | msg_clr_cmdline(); |
| 9629 | |
| 9630 | #ifdef FEAT_CMDL_INFO |
| 9631 | # ifdef FEAT_VISUAL |
| 9632 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 9633 | if (VIsual_active) |
| 9634 | clear_showcmd(); |
| 9635 | # endif |
| 9636 | |
| 9637 | /* If the last window has no status line, the ruler is after the mode |
| 9638 | * message and must be redrawn */ |
| 9639 | if (redrawing() |
| 9640 | # ifdef FEAT_WINDOWS |
| 9641 | && lastwin->w_status_height == 0 |
| 9642 | # endif |
| 9643 | ) |
| 9644 | win_redr_ruler(lastwin, TRUE); |
| 9645 | #endif |
| 9646 | redraw_cmdline = FALSE; |
| 9647 | clear_cmdline = FALSE; |
| 9648 | |
| 9649 | return length; |
| 9650 | } |
| 9651 | |
| 9652 | /* |
| 9653 | * Position for a mode message. |
| 9654 | */ |
| 9655 | static void |
| 9656 | msg_pos_mode() |
| 9657 | { |
| 9658 | msg_col = 0; |
| 9659 | msg_row = Rows - 1; |
| 9660 | } |
| 9661 | |
| 9662 | /* |
| 9663 | * Delete mode message. Used when ESC is typed which is expected to end |
| 9664 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9665 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9666 | */ |
| 9667 | void |
| 9668 | unshowmode(force) |
| 9669 | int force; |
| 9670 | { |
| 9671 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 9672 | * 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] | 9673 | */ |
| 9674 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 9675 | redraw_cmdline = TRUE; /* delete mode later */ |
| 9676 | else |
| 9677 | { |
| 9678 | msg_pos_mode(); |
| 9679 | if (Recording) |
| 9680 | MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); |
| 9681 | msg_clr_eos(); |
| 9682 | } |
| 9683 | } |
| 9684 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9685 | #if defined(FEAT_WINDOWS) |
| 9686 | /* |
| 9687 | * Draw the tab pages line at the top of the Vim window. |
| 9688 | */ |
| 9689 | static void |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9690 | draw_tabline() |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9691 | { |
| 9692 | int tabcount = 0; |
| 9693 | tabpage_T *tp; |
| 9694 | int tabwidth; |
| 9695 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9696 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9697 | int attr; |
| 9698 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9699 | win_T *cwp; |
| 9700 | int wincount; |
| 9701 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9702 | int c; |
| 9703 | int len; |
| 9704 | int attr_sel = hl_attr(HLF_TPS); |
| 9705 | int attr_nosel = hl_attr(HLF_TP); |
| 9706 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9707 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9708 | int room; |
| 9709 | int use_sep_chars = (t_colors < 8 |
| 9710 | #ifdef FEAT_GUI |
| 9711 | && !gui.in_use |
| 9712 | #endif |
| 9713 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9714 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9715 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9716 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9717 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 9718 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9719 | if (gui_use_tabline()) |
| 9720 | { |
| 9721 | gui_update_tabline(); |
| 9722 | return; |
| 9723 | } |
| 9724 | #endif |
| 9725 | |
| 9726 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9727 | return; |
| 9728 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9729 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9730 | |
| 9731 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 9732 | for (scol = 0; scol < Columns; ++scol) |
| 9733 | TabPageIdxs[scol] = 0; |
| 9734 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9735 | /* Use the 'tabline' option if it's set. */ |
| 9736 | if (*p_tal != NUL) |
| 9737 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9738 | int save_called_emsg = called_emsg; |
| 9739 | |
| 9740 | /* Check for an error. If there is one we would loop in redrawing the |
| 9741 | * screen. Avoid that by making 'tabline' empty. */ |
| 9742 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9743 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9744 | if (called_emsg) |
| 9745 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 9746 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9747 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9748 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9749 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9750 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9751 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9752 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 9753 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9754 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9755 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 9756 | if (tabwidth < 6) |
| 9757 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9758 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9759 | attr = attr_nosel; |
| 9760 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9761 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9762 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 9763 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9764 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9765 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9766 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9767 | if (tp->tp_topframe == topframe) |
| 9768 | attr = attr_sel; |
| 9769 | if (use_sep_chars && col > 0) |
| 9770 | screen_putchar('|', 0, col++, attr); |
| 9771 | |
| 9772 | if (tp->tp_topframe != topframe) |
| 9773 | attr = attr_nosel; |
| 9774 | |
| 9775 | screen_putchar(' ', 0, col++, attr); |
| 9776 | |
| 9777 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9778 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9779 | cwp = curwin; |
| 9780 | wp = firstwin; |
| 9781 | } |
| 9782 | else |
| 9783 | { |
| 9784 | cwp = tp->tp_curwin; |
| 9785 | wp = tp->tp_firstwin; |
| 9786 | } |
| 9787 | |
| 9788 | modified = FALSE; |
| 9789 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 9790 | if (bufIsChanged(wp->w_buffer)) |
| 9791 | modified = TRUE; |
| 9792 | if (modified || wincount > 1) |
| 9793 | { |
| 9794 | if (wincount > 1) |
| 9795 | { |
| 9796 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9797 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9798 | if (col + len >= Columns - 3) |
| 9799 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9800 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9801 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9802 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9803 | #else |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9804 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9805 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9806 | ); |
| 9807 | col += len; |
| 9808 | } |
| 9809 | if (modified) |
| 9810 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 9811 | screen_putchar(' ', 0, col++, attr); |
| 9812 | } |
| 9813 | |
| 9814 | room = scol - col + tabwidth - 1; |
| 9815 | if (room > 0) |
| 9816 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9817 | /* Get buffer name in NameBuff[] */ |
| 9818 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 9819 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9820 | len = vim_strsize(NameBuff); |
| 9821 | p = NameBuff; |
| 9822 | #ifdef FEAT_MBYTE |
| 9823 | if (has_mbyte) |
| 9824 | while (len > room) |
| 9825 | { |
| 9826 | len -= ptr2cells(p); |
| 9827 | mb_ptr_adv(p); |
| 9828 | } |
| 9829 | else |
| 9830 | #endif |
| 9831 | if (len > room) |
| 9832 | { |
| 9833 | p += len - room; |
| 9834 | len = room; |
| 9835 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9836 | if (len > Columns - col - 1) |
| 9837 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9838 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9839 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9840 | col += len; |
| 9841 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9842 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9843 | |
| 9844 | /* Store the tab page number in TabPageIdxs[], so that |
| 9845 | * jump_to_mouse() knows where each one is. */ |
| 9846 | ++tabcount; |
| 9847 | while (scol < col) |
| 9848 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9849 | } |
| 9850 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9851 | if (use_sep_chars) |
| 9852 | c = '_'; |
| 9853 | else |
| 9854 | c = ' '; |
| 9855 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9856 | |
| 9857 | /* Put an "X" for closing the current tab if there are several. */ |
| 9858 | if (first_tabpage->tp_next != NULL) |
| 9859 | { |
| 9860 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 9861 | TabPageIdxs[Columns - 1] = -999; |
| 9862 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9863 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 9864 | |
| 9865 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 9866 | * set. */ |
| 9867 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9868 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9869 | |
| 9870 | /* |
| 9871 | * Get buffer name for "buf" into NameBuff[]. |
| 9872 | * Takes care of special buffer names and translates special characters. |
| 9873 | */ |
| 9874 | void |
| 9875 | get_trans_bufname(buf) |
| 9876 | buf_T *buf; |
| 9877 | { |
| 9878 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 9879 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9880 | else |
| 9881 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 9882 | trans_characters(NameBuff, MAXPATHL); |
| 9883 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9884 | #endif |
| 9885 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9886 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 9887 | /* |
| 9888 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 9889 | */ |
| 9890 | static int |
| 9891 | fillchar_status(attr, is_curwin) |
| 9892 | int *attr; |
| 9893 | int is_curwin; |
| 9894 | { |
| 9895 | int fill; |
| 9896 | if (is_curwin) |
| 9897 | { |
| 9898 | *attr = hl_attr(HLF_S); |
| 9899 | fill = fill_stl; |
| 9900 | } |
| 9901 | else |
| 9902 | { |
| 9903 | *attr = hl_attr(HLF_SNC); |
| 9904 | fill = fill_stlnc; |
| 9905 | } |
| 9906 | /* Use fill when there is highlighting, and highlighting of current |
| 9907 | * window differs, or the fillchars differ, or this is not the |
| 9908 | * current window */ |
| 9909 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 9910 | || !is_curwin || firstwin == lastwin) |
| 9911 | || (fill_stl != fill_stlnc))) |
| 9912 | return fill; |
| 9913 | if (is_curwin) |
| 9914 | return '^'; |
| 9915 | return '='; |
| 9916 | } |
| 9917 | #endif |
| 9918 | |
| 9919 | #ifdef FEAT_VERTSPLIT |
| 9920 | /* |
| 9921 | * Get the character to use in a separator between vertically split windows. |
| 9922 | * Get its attributes in "*attr". |
| 9923 | */ |
| 9924 | static int |
| 9925 | fillchar_vsep(attr) |
| 9926 | int *attr; |
| 9927 | { |
| 9928 | *attr = hl_attr(HLF_C); |
| 9929 | if (*attr == 0 && fill_vert == ' ') |
| 9930 | return '|'; |
| 9931 | else |
| 9932 | return fill_vert; |
| 9933 | } |
| 9934 | #endif |
| 9935 | |
| 9936 | /* |
| 9937 | * Return TRUE if redrawing should currently be done. |
| 9938 | */ |
| 9939 | int |
| 9940 | redrawing() |
| 9941 | { |
| 9942 | return (!RedrawingDisabled |
| 9943 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 9944 | } |
| 9945 | |
| 9946 | /* |
| 9947 | * Return TRUE if printing messages should currently be done. |
| 9948 | */ |
| 9949 | int |
| 9950 | messaging() |
| 9951 | { |
| 9952 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 9953 | } |
| 9954 | |
| 9955 | /* |
| 9956 | * Show current status info in ruler and various other places |
| 9957 | * If always is FALSE, only show ruler if position has changed. |
| 9958 | */ |
| 9959 | void |
| 9960 | showruler(always) |
| 9961 | int always; |
| 9962 | { |
| 9963 | if (!always && !redrawing()) |
| 9964 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9965 | #ifdef FEAT_INS_EXPAND |
| 9966 | if (pum_visible()) |
| 9967 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9968 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9969 | /* Don't redraw right now, do it later. */ |
| 9970 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 9971 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 9972 | return; |
| 9973 | } |
| 9974 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9975 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 9976 | 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] | 9977 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 9978 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9979 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9980 | else |
| 9981 | #endif |
| 9982 | #ifdef FEAT_CMDL_INFO |
| 9983 | win_redr_ruler(curwin, always); |
| 9984 | #endif |
| 9985 | |
| 9986 | #ifdef FEAT_TITLE |
| 9987 | if (need_maketitle |
| 9988 | # ifdef FEAT_STL_OPT |
| 9989 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 9990 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 9991 | # endif |
| 9992 | ) |
| 9993 | maketitle(); |
| 9994 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 9995 | #ifdef FEAT_WINDOWS |
| 9996 | /* Redraw the tab pages line if needed. */ |
| 9997 | if (redraw_tabline) |
| 9998 | draw_tabline(); |
| 9999 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10000 | } |
| 10001 | |
| 10002 | #ifdef FEAT_CMDL_INFO |
| 10003 | static void |
| 10004 | win_redr_ruler(wp, always) |
| 10005 | win_T *wp; |
| 10006 | int always; |
| 10007 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10008 | #define RULER_BUF_LEN 70 |
| 10009 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10010 | int row; |
| 10011 | int fillchar; |
| 10012 | int attr; |
| 10013 | int empty_line = FALSE; |
| 10014 | colnr_T virtcol; |
| 10015 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10016 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10017 | int o; |
| 10018 | #ifdef FEAT_VERTSPLIT |
| 10019 | int this_ru_col; |
| 10020 | int off = 0; |
| 10021 | int width = Columns; |
| 10022 | # define WITH_OFF(x) x |
| 10023 | # define WITH_WIDTH(x) x |
| 10024 | #else |
| 10025 | # define WITH_OFF(x) 0 |
| 10026 | # define WITH_WIDTH(x) Columns |
| 10027 | # define this_ru_col ru_col |
| 10028 | #endif |
| 10029 | |
| 10030 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10031 | if (!p_ru) |
| 10032 | return; |
| 10033 | |
| 10034 | /* |
| 10035 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10036 | * after deleting lines, before cursor.lnum is corrected. |
| 10037 | */ |
| 10038 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10039 | return; |
| 10040 | |
| 10041 | #ifdef FEAT_INS_EXPAND |
| 10042 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10043 | * the (long) mode message. */ |
| 10044 | # ifdef FEAT_WINDOWS |
| 10045 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10046 | # endif |
| 10047 | if (edit_submode != NULL) |
| 10048 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10049 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10050 | if (pum_visible()) |
| 10051 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10052 | #endif |
| 10053 | |
| 10054 | #ifdef FEAT_STL_OPT |
| 10055 | if (*p_ruf) |
| 10056 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10057 | int save_called_emsg = called_emsg; |
| 10058 | |
| 10059 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10060 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10061 | if (called_emsg) |
| 10062 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10063 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10064 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10065 | return; |
| 10066 | } |
| 10067 | #endif |
| 10068 | |
| 10069 | /* |
| 10070 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10071 | */ |
| 10072 | if (!(State & INSERT) |
| 10073 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10074 | empty_line = TRUE; |
| 10075 | |
| 10076 | /* |
| 10077 | * Only draw the ruler when something changed. |
| 10078 | */ |
| 10079 | validate_virtcol_win(wp); |
| 10080 | if ( redraw_cmdline |
| 10081 | || always |
| 10082 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10083 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10084 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10085 | #ifdef FEAT_VIRTUALEDIT |
| 10086 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10087 | #endif |
| 10088 | || wp->w_topline != wp->w_ru_topline |
| 10089 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10090 | #ifdef FEAT_DIFF |
| 10091 | || wp->w_topfill != wp->w_ru_topfill |
| 10092 | #endif |
| 10093 | || empty_line != wp->w_ru_empty) |
| 10094 | { |
| 10095 | cursor_off(); |
| 10096 | #ifdef FEAT_WINDOWS |
| 10097 | if (wp->w_status_height) |
| 10098 | { |
| 10099 | row = W_WINROW(wp) + wp->w_height; |
| 10100 | fillchar = fillchar_status(&attr, wp == curwin); |
| 10101 | # ifdef FEAT_VERTSPLIT |
| 10102 | off = W_WINCOL(wp); |
| 10103 | width = W_WIDTH(wp); |
| 10104 | # endif |
| 10105 | } |
| 10106 | else |
| 10107 | #endif |
| 10108 | { |
| 10109 | row = Rows - 1; |
| 10110 | fillchar = ' '; |
| 10111 | attr = 0; |
| 10112 | #ifdef FEAT_VERTSPLIT |
| 10113 | width = Columns; |
| 10114 | off = 0; |
| 10115 | #endif |
| 10116 | } |
| 10117 | |
| 10118 | /* In list mode virtcol needs to be recomputed */ |
| 10119 | virtcol = wp->w_virtcol; |
| 10120 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10121 | { |
| 10122 | wp->w_p_list = FALSE; |
| 10123 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10124 | wp->w_p_list = TRUE; |
| 10125 | } |
| 10126 | |
| 10127 | /* |
| 10128 | * Some sprintfs return the length, some return a pointer. |
| 10129 | * To avoid portability problems we use strlen() here. |
| 10130 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10131 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10132 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10133 | ? 0L |
| 10134 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10135 | len = STRLEN(buffer); |
| 10136 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10137 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10138 | (int)virtcol + 1); |
| 10139 | |
| 10140 | /* |
| 10141 | * Add a "50%" if there is room for it. |
| 10142 | * On the last line, don't print in the last column (scrolls the |
| 10143 | * screen up on some terminals). |
| 10144 | */ |
| 10145 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10146 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10147 | o = i + vim_strsize(buffer + i + 1); |
| 10148 | #ifdef FEAT_WINDOWS |
| 10149 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10150 | #endif |
| 10151 | ++o; |
| 10152 | #ifdef FEAT_VERTSPLIT |
| 10153 | this_ru_col = ru_col - (Columns - width); |
| 10154 | if (this_ru_col < 0) |
| 10155 | this_ru_col = 0; |
| 10156 | #endif |
| 10157 | /* Never use more than half the window/screen width, leave the other |
| 10158 | * half for the filename. */ |
| 10159 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10160 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10161 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10162 | { |
| 10163 | while (this_ru_col + o < WITH_WIDTH(width)) |
| 10164 | { |
| 10165 | #ifdef FEAT_MBYTE |
| 10166 | if (has_mbyte) |
| 10167 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10168 | else |
| 10169 | #endif |
| 10170 | buffer[i++] = fillchar; |
| 10171 | ++o; |
| 10172 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10173 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10174 | } |
| 10175 | /* Truncate at window boundary. */ |
| 10176 | #ifdef FEAT_MBYTE |
| 10177 | if (has_mbyte) |
| 10178 | { |
| 10179 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10180 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10181 | { |
| 10182 | o += (*mb_ptr2cells)(buffer + i); |
| 10183 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10184 | { |
| 10185 | buffer[i] = NUL; |
| 10186 | break; |
| 10187 | } |
| 10188 | } |
| 10189 | } |
| 10190 | else |
| 10191 | #endif |
| 10192 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10193 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10194 | |
| 10195 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10196 | i = redraw_cmdline; |
| 10197 | screen_fill(row, row + 1, |
| 10198 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10199 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10200 | fillchar, fillchar, attr); |
| 10201 | /* don't redraw the cmdline because of showing the ruler */ |
| 10202 | redraw_cmdline = i; |
| 10203 | wp->w_ru_cursor = wp->w_cursor; |
| 10204 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10205 | wp->w_ru_empty = empty_line; |
| 10206 | wp->w_ru_topline = wp->w_topline; |
| 10207 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10208 | #ifdef FEAT_DIFF |
| 10209 | wp->w_ru_topfill = wp->w_topfill; |
| 10210 | #endif |
| 10211 | } |
| 10212 | } |
| 10213 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10214 | |
| 10215 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10216 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10217 | * Return the width of the 'number' and 'relativenumber' column. |
| 10218 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10219 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10220 | */ |
| 10221 | int |
| 10222 | number_width(wp) |
| 10223 | win_T *wp; |
| 10224 | { |
| 10225 | int n; |
| 10226 | linenr_T lnum; |
| 10227 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10228 | if (wp->w_p_nu) |
| 10229 | /* 'number' */ |
| 10230 | lnum = wp->w_buffer->b_ml.ml_line_count; |
| 10231 | else |
| 10232 | /* 'relativenumber' */ |
| 10233 | lnum = wp->w_height; |
| 10234 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10235 | if (lnum == wp->w_nrwidth_line_count) |
| 10236 | return wp->w_nrwidth_width; |
| 10237 | wp->w_nrwidth_line_count = lnum; |
| 10238 | |
| 10239 | n = 0; |
| 10240 | do |
| 10241 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10242 | lnum /= 10; |
| 10243 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10244 | } while (lnum > 0); |
| 10245 | |
| 10246 | /* 'numberwidth' gives the minimal width plus one */ |
| 10247 | if (n < wp->w_p_nuw - 1) |
| 10248 | n = wp->w_p_nuw - 1; |
| 10249 | |
| 10250 | wp->w_nrwidth_width = n; |
| 10251 | return n; |
| 10252 | } |
| 10253 | #endif |