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 |
Bram Moolenaar | 51971b3 | 2013-02-13 12:16:05 +0100 | [diff] [blame] | 551 | #ifdef FEAT_INS_EXPAND |
| 552 | /* May need to redraw the popup menu. */ |
| 553 | if (pum_visible()) |
| 554 | pum_redraw(); |
| 555 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 556 | |
| 557 | #ifdef FEAT_WINDOWS |
| 558 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 559 | * than going through all buffers (there could be many buffers). */ |
| 560 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 561 | wp->w_buffer->b_mod_set = FALSE; |
| 562 | #else |
| 563 | curbuf->b_mod_set = FALSE; |
| 564 | #endif |
| 565 | |
| 566 | updating_screen = FALSE; |
| 567 | #ifdef FEAT_GUI |
| 568 | gui_may_resize_shell(); |
| 569 | #endif |
| 570 | |
| 571 | /* Clear or redraw the command line. Done last, because scrolling may |
| 572 | * mess up the command line. */ |
| 573 | if (clear_cmdline || redraw_cmdline) |
| 574 | showmode(); |
| 575 | |
| 576 | /* May put up an introductory message when not editing a file */ |
| 577 | if (!did_intro && bufempty() |
| 578 | && curbuf->b_fname == NULL |
| 579 | #ifdef FEAT_WINDOWS |
| 580 | && firstwin->w_next == NULL |
| 581 | #endif |
| 582 | && vim_strchr(p_shm, SHM_INTRO) == NULL) |
| 583 | intro_message(FALSE); |
| 584 | did_intro = TRUE; |
| 585 | |
| 586 | #ifdef FEAT_GUI |
| 587 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 588 | * done. */ |
| 589 | if (gui.in_use) |
| 590 | { |
| 591 | out_flush(); /* required before updating the cursor */ |
| 592 | if (did_one) |
| 593 | gui_update_cursor(FALSE, FALSE); |
| 594 | gui_update_scrollbars(FALSE); |
| 595 | } |
| 596 | #endif |
| 597 | } |
| 598 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 599 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 600 | /* |
| 601 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 602 | * to the 'concealcursor' option. |
| 603 | */ |
| 604 | int |
| 605 | conceal_cursor_line(wp) |
| 606 | win_T *wp; |
| 607 | { |
| 608 | int c; |
| 609 | |
| 610 | if (*wp->w_p_cocu == NUL) |
| 611 | return FALSE; |
| 612 | if (get_real_state() & VISUAL) |
| 613 | c = 'v'; |
| 614 | else if (State & INSERT) |
| 615 | c = 'i'; |
| 616 | else if (State & NORMAL) |
| 617 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 618 | else if (State & CMDLINE) |
| 619 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 620 | else |
| 621 | return FALSE; |
| 622 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 627 | */ |
| 628 | void |
Bram Moolenaar | 8e46927 | 2010-07-28 19:38:16 +0200 | [diff] [blame] | 629 | conceal_check_cursur_line() |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 630 | { |
| 631 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 632 | { |
| 633 | need_cursor_line_redraw = TRUE; |
| 634 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 635 | * without concealing. */ |
| 636 | curs_columns(TRUE); |
| 637 | } |
| 638 | } |
| 639 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 640 | void |
| 641 | update_single_line(wp, lnum) |
| 642 | win_T *wp; |
| 643 | linenr_T lnum; |
| 644 | { |
| 645 | int row; |
| 646 | int j; |
| 647 | |
| 648 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 649 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 650 | { |
| 651 | # ifdef FEAT_GUI |
| 652 | /* Remove the cursor before starting to do anything, because scrolling |
| 653 | * may make it difficult to redraw the text under it. */ |
| 654 | if (gui.in_use) |
| 655 | gui_undraw_cursor(); |
| 656 | # endif |
| 657 | row = 0; |
| 658 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 659 | { |
| 660 | if (lnum == wp->w_lines[j].wl_lnum) |
| 661 | { |
| 662 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 663 | # ifdef FEAT_SEARCH_EXTRA |
| 664 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 665 | start_search_hl(); |
| 666 | prepare_search_hl(wp, lnum); |
| 667 | # endif |
| 668 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 669 | # if defined(FEAT_SEARCH_EXTRA) |
| 670 | end_search_hl(); |
| 671 | # endif |
| 672 | break; |
| 673 | } |
| 674 | row += wp->w_lines[j].wl_size; |
| 675 | } |
| 676 | # ifdef FEAT_GUI |
| 677 | /* Redraw the cursor */ |
| 678 | if (gui.in_use) |
| 679 | { |
| 680 | out_flush(); /* required before updating the cursor */ |
| 681 | gui_update_cursor(FALSE, FALSE); |
| 682 | } |
| 683 | # endif |
| 684 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 685 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 686 | } |
| 687 | #endif |
| 688 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 689 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
| 690 | static void update_prepare __ARGS((void)); |
| 691 | static void update_finish __ARGS((void)); |
| 692 | |
| 693 | /* |
| 694 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 695 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 696 | */ |
| 697 | static void |
| 698 | update_prepare() |
| 699 | { |
| 700 | cursor_off(); |
| 701 | updating_screen = TRUE; |
| 702 | #ifdef FEAT_GUI |
| 703 | /* Remove the cursor before starting to do anything, because scrolling may |
| 704 | * make it difficult to redraw the text under it. */ |
| 705 | if (gui.in_use) |
| 706 | gui_undraw_cursor(); |
| 707 | #endif |
| 708 | #ifdef FEAT_SEARCH_EXTRA |
| 709 | start_search_hl(); |
| 710 | #endif |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | * Finish updating one or more windows. |
| 715 | */ |
| 716 | static void |
| 717 | update_finish() |
| 718 | { |
| 719 | if (redraw_cmdline) |
| 720 | showmode(); |
| 721 | |
| 722 | # ifdef FEAT_SEARCH_EXTRA |
| 723 | end_search_hl(); |
| 724 | # endif |
| 725 | |
| 726 | updating_screen = FALSE; |
| 727 | |
| 728 | # ifdef FEAT_GUI |
| 729 | gui_may_resize_shell(); |
| 730 | |
| 731 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 732 | * done. */ |
| 733 | if (gui.in_use) |
| 734 | { |
| 735 | out_flush(); /* required before updating the cursor */ |
| 736 | gui_update_cursor(FALSE, FALSE); |
| 737 | gui_update_scrollbars(FALSE); |
| 738 | } |
| 739 | # endif |
| 740 | } |
| 741 | #endif |
| 742 | |
| 743 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 744 | void |
| 745 | update_debug_sign(buf, lnum) |
| 746 | buf_T *buf; |
| 747 | linenr_T lnum; |
| 748 | { |
| 749 | win_T *wp; |
| 750 | int doit = FALSE; |
| 751 | |
| 752 | # ifdef FEAT_FOLDING |
| 753 | win_foldinfo.fi_level = 0; |
| 754 | # endif |
| 755 | |
| 756 | /* update/delete a specific mark */ |
| 757 | FOR_ALL_WINDOWS(wp) |
| 758 | { |
| 759 | if (buf != NULL && lnum > 0) |
| 760 | { |
| 761 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 762 | && lnum < wp->w_botline) |
| 763 | { |
| 764 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 765 | wp->w_redraw_top = lnum; |
| 766 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 767 | wp->w_redraw_bot = lnum; |
| 768 | redraw_win_later(wp, VALID); |
| 769 | } |
| 770 | } |
| 771 | else |
| 772 | redraw_win_later(wp, VALID); |
| 773 | if (wp->w_redr_type != 0) |
| 774 | doit = TRUE; |
| 775 | } |
| 776 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 777 | /* Return when there is nothing to do, screen updating is already |
| 778 | * happening (recursive call) or still starting up. */ |
| 779 | if (!doit || updating_screen |
| 780 | #ifdef FEAT_GUI |
| 781 | || gui.starting |
| 782 | #endif |
| 783 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 784 | return; |
| 785 | |
| 786 | /* update all windows that need updating */ |
| 787 | update_prepare(); |
| 788 | |
| 789 | # ifdef FEAT_WINDOWS |
| 790 | for (wp = firstwin; wp; wp = wp->w_next) |
| 791 | { |
| 792 | if (wp->w_redr_type != 0) |
| 793 | win_update(wp); |
| 794 | if (wp->w_redr_status) |
| 795 | win_redr_status(wp); |
| 796 | } |
| 797 | # else |
| 798 | if (curwin->w_redr_type != 0) |
| 799 | win_update(curwin); |
| 800 | # endif |
| 801 | |
| 802 | update_finish(); |
| 803 | } |
| 804 | #endif |
| 805 | |
| 806 | |
| 807 | #if defined(FEAT_GUI) || defined(PROTO) |
| 808 | /* |
| 809 | * Update a single window, its status line and maybe the command line msg. |
| 810 | * Used for the GUI scrollbar. |
| 811 | */ |
| 812 | void |
| 813 | updateWindow(wp) |
| 814 | win_T *wp; |
| 815 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 816 | /* return if already busy updating */ |
| 817 | if (updating_screen) |
| 818 | return; |
| 819 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 820 | update_prepare(); |
| 821 | |
| 822 | #ifdef FEAT_CLIPBOARD |
| 823 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 824 | if (clip_star.available && clip_isautosel_star()) |
| 825 | clip_update_selection(&clip_star); |
| 826 | if (clip_plus.available && clip_isautosel_plus()) |
| 827 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 828 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 829 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 830 | win_update(wp); |
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 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 833 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 834 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 835 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 836 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 837 | if (wp->w_redr_status |
| 838 | # ifdef FEAT_CMDL_INFO |
| 839 | || p_ru |
| 840 | # endif |
| 841 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 842 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 843 | # endif |
| 844 | ) |
| 845 | win_redr_status(wp); |
| 846 | #endif |
| 847 | |
| 848 | update_finish(); |
| 849 | } |
| 850 | #endif |
| 851 | |
| 852 | /* |
| 853 | * Update a single window. |
| 854 | * |
| 855 | * This may cause the windows below it also to be redrawn (when clearing the |
| 856 | * screen or scrolling lines). |
| 857 | * |
| 858 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 859 | * implies the one below it. |
| 860 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 861 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 862 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 863 | * INVERTED redraw the changed part of the Visual area |
| 864 | * INVERTED_ALL redraw the whole Visual area |
| 865 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 866 | * 2. update lines at the top when scrolled down |
| 867 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 868 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 869 | * b_mod_top and b_mod_bot. |
| 870 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 871 | * wp->w_redraw_top and wp->w_redr_bot. |
| 872 | * - continue redrawing when syntax status is invalid. |
| 873 | * 4. if scrolled up, update lines at the bottom. |
| 874 | * This results in three areas that may need updating: |
| 875 | * top: from first row to top_end (when scrolled down) |
| 876 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 877 | * bot: from bot_start to last row (when scrolled up) |
| 878 | */ |
| 879 | static void |
| 880 | win_update(wp) |
| 881 | win_T *wp; |
| 882 | { |
| 883 | buf_T *buf = wp->w_buffer; |
| 884 | int type; |
| 885 | int top_end = 0; /* Below last row of the top area that needs |
| 886 | updating. 0 when no top area updating. */ |
| 887 | int mid_start = 999;/* first row of the mid area that needs |
| 888 | updating. 999 when no mid area updating. */ |
| 889 | int mid_end = 0; /* Below last row of the mid area that needs |
| 890 | updating. 0 when no mid area updating. */ |
| 891 | int bot_start = 999;/* first row of the bot area that needs |
| 892 | updating. 999 when no bot area updating */ |
| 893 | #ifdef FEAT_VISUAL |
| 894 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 895 | w_topline got smaller a bit */ |
| 896 | #endif |
| 897 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 898 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 899 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 900 | #endif |
| 901 | |
| 902 | int row; /* current window row to display */ |
| 903 | linenr_T lnum; /* current buffer lnum to display */ |
| 904 | int idx; /* current index in w_lines[] */ |
| 905 | int srow; /* starting row of the current line */ |
| 906 | |
| 907 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 908 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 909 | int i; |
| 910 | long j; |
| 911 | static int recursive = FALSE; /* being called recursively */ |
| 912 | int old_botline = wp->w_botline; |
| 913 | #ifdef FEAT_FOLDING |
| 914 | long fold_count; |
| 915 | #endif |
| 916 | #ifdef FEAT_SYN_HL |
| 917 | /* remember what happened to the previous line, to know if |
| 918 | * check_visual_highlight() can be used */ |
| 919 | #define DID_NONE 1 /* didn't update a line */ |
| 920 | #define DID_LINE 2 /* updated a normal line */ |
| 921 | #define DID_FOLD 3 /* updated a folded line */ |
| 922 | int did_update = DID_NONE; |
| 923 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 924 | #endif |
| 925 | linenr_T mod_top = 0; |
| 926 | linenr_T mod_bot = 0; |
| 927 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 928 | int save_got_int; |
| 929 | #endif |
| 930 | |
| 931 | type = wp->w_redr_type; |
| 932 | |
| 933 | if (type == NOT_VALID) |
| 934 | { |
| 935 | #ifdef FEAT_WINDOWS |
| 936 | wp->w_redr_status = TRUE; |
| 937 | #endif |
| 938 | wp->w_lines_valid = 0; |
| 939 | } |
| 940 | |
| 941 | /* Window is zero-height: nothing to draw. */ |
| 942 | if (wp->w_height == 0) |
| 943 | { |
| 944 | wp->w_redr_type = 0; |
| 945 | return; |
| 946 | } |
| 947 | |
| 948 | #ifdef FEAT_VERTSPLIT |
| 949 | /* Window is zero-width: Only need to draw the separator. */ |
| 950 | if (wp->w_width == 0) |
| 951 | { |
| 952 | /* draw the vertical separator right of this window */ |
| 953 | draw_vsep_win(wp, 0); |
| 954 | wp->w_redr_type = 0; |
| 955 | return; |
| 956 | } |
| 957 | #endif |
| 958 | |
| 959 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 960 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 961 | #endif |
| 962 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 963 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 964 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 965 | * changes. */ |
| 966 | 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] | 967 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 968 | { |
| 969 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 970 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 971 | } |
| 972 | else |
| 973 | #endif |
| 974 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 975 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 976 | { |
| 977 | /* |
| 978 | * When there are both inserted/deleted lines and specific lines to be |
| 979 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 980 | * everything (only happens when redrawing is off for while). |
| 981 | */ |
| 982 | type = NOT_VALID; |
| 983 | } |
| 984 | else |
| 985 | { |
| 986 | /* |
| 987 | * Set mod_top to the first line that needs displaying because of |
| 988 | * changes. Set mod_bot to the first line after the changes. |
| 989 | */ |
| 990 | mod_top = wp->w_redraw_top; |
| 991 | if (wp->w_redraw_bot != 0) |
| 992 | mod_bot = wp->w_redraw_bot + 1; |
| 993 | else |
| 994 | mod_bot = 0; |
| 995 | wp->w_redraw_top = 0; /* reset for next time */ |
| 996 | wp->w_redraw_bot = 0; |
| 997 | if (buf->b_mod_set) |
| 998 | { |
| 999 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1000 | { |
| 1001 | mod_top = buf->b_mod_top; |
| 1002 | #ifdef FEAT_SYN_HL |
| 1003 | /* Need to redraw lines above the change that may be included |
| 1004 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1005 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1006 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1007 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1008 | if (mod_top < 1) |
| 1009 | mod_top = 1; |
| 1010 | } |
| 1011 | #endif |
| 1012 | } |
| 1013 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1014 | mod_bot = buf->b_mod_bot; |
| 1015 | |
| 1016 | #ifdef FEAT_SEARCH_EXTRA |
| 1017 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1018 | * change in one line may make the Search highlighting in a |
| 1019 | * previous line invalid. Simple solution: redraw all visible |
| 1020 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1021 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1022 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1023 | if (search_hl.rm.regprog != NULL |
| 1024 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1025 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1026 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1027 | { |
| 1028 | cur = wp->w_match_head; |
| 1029 | while (cur != NULL) |
| 1030 | { |
| 1031 | if (cur->match.regprog != NULL |
| 1032 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1033 | { |
| 1034 | top_to_mod = TRUE; |
| 1035 | break; |
| 1036 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1037 | cur = cur->next; |
| 1038 | } |
| 1039 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1040 | #endif |
| 1041 | } |
| 1042 | #ifdef FEAT_FOLDING |
| 1043 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1044 | { |
| 1045 | linenr_T lnumt, lnumb; |
| 1046 | |
| 1047 | /* |
| 1048 | * A change in a line can cause lines above it to become folded or |
| 1049 | * unfolded. Find the top most buffer line that may be affected. |
| 1050 | * If the line was previously folded and displayed, get the first |
| 1051 | * line of that fold. If the line is folded now, get the first |
| 1052 | * folded line. Use the minimum of these two. |
| 1053 | */ |
| 1054 | |
| 1055 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1056 | * the line below it. If there is no valid entry, use w_topline. |
| 1057 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1058 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1059 | lnumt = wp->w_topline; |
| 1060 | lnumb = MAXLNUM; |
| 1061 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1062 | if (wp->w_lines[i].wl_valid) |
| 1063 | { |
| 1064 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1065 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1066 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1067 | { |
| 1068 | lnumb = wp->w_lines[i].wl_lnum; |
| 1069 | /* When there is a fold column it might need updating |
| 1070 | * in the next line ("J" just above an open fold). */ |
| 1071 | if (wp->w_p_fdc > 0) |
| 1072 | ++lnumb; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1077 | if (mod_top > lnumt) |
| 1078 | mod_top = lnumt; |
| 1079 | |
| 1080 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1081 | --mod_bot; |
| 1082 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1083 | ++mod_bot; |
| 1084 | if (mod_bot < lnumb) |
| 1085 | mod_bot = lnumb; |
| 1086 | } |
| 1087 | #endif |
| 1088 | |
| 1089 | /* When a change starts above w_topline and the end is below |
| 1090 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1091 | * If the end of the change is above w_topline: do like no change was |
| 1092 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1093 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1094 | { |
| 1095 | if (mod_bot > wp->w_topline) |
| 1096 | mod_top = wp->w_topline; |
| 1097 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1098 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1099 | top_end = 1; |
| 1100 | #endif |
| 1101 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1102 | |
| 1103 | /* When line numbers are displayed need to redraw all lines below |
| 1104 | * inserted/deleted lines. */ |
| 1105 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1106 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /* |
| 1110 | * When only displaying the lines at the top, set top_end. Used when |
| 1111 | * window has scrolled down for msg_scrolled. |
| 1112 | */ |
| 1113 | if (type == REDRAW_TOP) |
| 1114 | { |
| 1115 | j = 0; |
| 1116 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1117 | { |
| 1118 | j += wp->w_lines[i].wl_size; |
| 1119 | if (j >= wp->w_upd_rows) |
| 1120 | { |
| 1121 | top_end = j; |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
| 1125 | if (top_end == 0) |
| 1126 | /* not found (cannot happen?): redraw everything */ |
| 1127 | type = NOT_VALID; |
| 1128 | else |
| 1129 | /* top area defined, the rest is VALID */ |
| 1130 | type = VALID; |
| 1131 | } |
| 1132 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1133 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1134 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1135 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1136 | * called. */ |
| 1137 | if (screen_cleared) |
| 1138 | screen_cleared = MAYBE; |
| 1139 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1140 | /* |
| 1141 | * If there are no changes on the screen that require a complete redraw, |
| 1142 | * handle three cases: |
| 1143 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1144 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1145 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1146 | * w_lines[] that needs updating. |
| 1147 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1148 | if ((type == VALID || type == SOME_VALID |
| 1149 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1150 | #ifdef FEAT_DIFF |
| 1151 | && !wp->w_botfill && !wp->w_old_botfill |
| 1152 | #endif |
| 1153 | ) |
| 1154 | { |
| 1155 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1156 | { |
| 1157 | /* |
| 1158 | * w_topline is the first changed line, the scrolling will be done |
| 1159 | * further down. |
| 1160 | */ |
| 1161 | } |
| 1162 | else if (wp->w_lines[0].wl_valid |
| 1163 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1164 | #ifdef FEAT_DIFF |
| 1165 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1166 | && wp->w_topfill > wp->w_old_topfill) |
| 1167 | #endif |
| 1168 | )) |
| 1169 | { |
| 1170 | /* |
| 1171 | * New topline is above old topline: May scroll down. |
| 1172 | */ |
| 1173 | #ifdef FEAT_FOLDING |
| 1174 | if (hasAnyFolding(wp)) |
| 1175 | { |
| 1176 | linenr_T ln; |
| 1177 | |
| 1178 | /* count the number of lines we are off, counting a sequence |
| 1179 | * of folded lines as one */ |
| 1180 | j = 0; |
| 1181 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1182 | { |
| 1183 | ++j; |
| 1184 | if (j >= wp->w_height - 2) |
| 1185 | break; |
| 1186 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1187 | } |
| 1188 | } |
| 1189 | else |
| 1190 | #endif |
| 1191 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1192 | if (j < wp->w_height - 2) /* not too far off */ |
| 1193 | { |
| 1194 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1195 | #ifdef FEAT_DIFF |
| 1196 | /* insert extra lines for previously invisible filler lines */ |
| 1197 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1198 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1199 | - wp->w_old_topfill; |
| 1200 | #endif |
| 1201 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1202 | { |
| 1203 | /* |
| 1204 | * Try to insert the correct number of lines. |
| 1205 | * If not the last window, delete the lines at the bottom. |
| 1206 | * win_ins_lines may fail when the terminal can't do it. |
| 1207 | */ |
| 1208 | if (i > 0) |
| 1209 | check_for_delay(FALSE); |
| 1210 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1211 | { |
| 1212 | if (wp->w_lines_valid != 0) |
| 1213 | { |
| 1214 | /* Need to update rows that are new, stop at the |
| 1215 | * first one that scrolled down. */ |
| 1216 | top_end = i; |
| 1217 | #ifdef FEAT_VISUAL |
| 1218 | scrolled_down = TRUE; |
| 1219 | #endif |
| 1220 | |
| 1221 | /* Move the entries that were scrolled, disable |
| 1222 | * the entries for the lines to be redrawn. */ |
| 1223 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1224 | wp->w_lines_valid = wp->w_height; |
| 1225 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1226 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1227 | while (idx >= 0) |
| 1228 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1229 | } |
| 1230 | } |
| 1231 | else |
| 1232 | mid_start = 0; /* redraw all lines */ |
| 1233 | } |
| 1234 | else |
| 1235 | mid_start = 0; /* redraw all lines */ |
| 1236 | } |
| 1237 | else |
| 1238 | mid_start = 0; /* redraw all lines */ |
| 1239 | } |
| 1240 | else |
| 1241 | { |
| 1242 | /* |
| 1243 | * New topline is at or below old topline: May scroll up. |
| 1244 | * When topline didn't change, find first entry in w_lines[] that |
| 1245 | * needs updating. |
| 1246 | */ |
| 1247 | |
| 1248 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1249 | j = -1; |
| 1250 | row = 0; |
| 1251 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1252 | { |
| 1253 | if (wp->w_lines[i].wl_valid |
| 1254 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1255 | { |
| 1256 | j = i; |
| 1257 | break; |
| 1258 | } |
| 1259 | row += wp->w_lines[i].wl_size; |
| 1260 | } |
| 1261 | if (j == -1) |
| 1262 | { |
| 1263 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1264 | * lines */ |
| 1265 | mid_start = 0; |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | /* |
| 1270 | * Try to delete the correct number of lines. |
| 1271 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1272 | */ |
| 1273 | #ifdef FEAT_DIFF |
| 1274 | /* If the topline didn't change, delete old filler lines, |
| 1275 | * otherwise delete filler lines of the new topline... */ |
| 1276 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1277 | row += wp->w_old_topfill; |
| 1278 | else |
| 1279 | row += diff_check_fill(wp, wp->w_topline); |
| 1280 | /* ... but don't delete new filler lines. */ |
| 1281 | row -= wp->w_topfill; |
| 1282 | #endif |
| 1283 | if (row > 0) |
| 1284 | { |
| 1285 | check_for_delay(FALSE); |
| 1286 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1287 | bot_start = wp->w_height - row; |
| 1288 | else |
| 1289 | mid_start = 0; /* redraw all lines */ |
| 1290 | } |
| 1291 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1292 | { |
| 1293 | /* |
| 1294 | * Skip the lines (below the deleted lines) that are still |
| 1295 | * valid and don't need redrawing. Copy their info |
| 1296 | * upwards, to compensate for the deleted lines. Set |
| 1297 | * bot_start to the first row that needs redrawing. |
| 1298 | */ |
| 1299 | bot_start = 0; |
| 1300 | idx = 0; |
| 1301 | for (;;) |
| 1302 | { |
| 1303 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1304 | /* stop at line that didn't fit, unless it is still |
| 1305 | * valid (no lines deleted) */ |
| 1306 | if (row > 0 && bot_start + row |
| 1307 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1308 | { |
| 1309 | wp->w_lines_valid = idx + 1; |
| 1310 | break; |
| 1311 | } |
| 1312 | bot_start += wp->w_lines[idx++].wl_size; |
| 1313 | |
| 1314 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1315 | if (++j >= wp->w_lines_valid) |
| 1316 | { |
| 1317 | wp->w_lines_valid = idx; |
| 1318 | break; |
| 1319 | } |
| 1320 | } |
| 1321 | #ifdef FEAT_DIFF |
| 1322 | /* Correct the first entry for filler lines at the top |
| 1323 | * when it won't get updated below. */ |
| 1324 | if (wp->w_p_diff && bot_start > 0) |
| 1325 | wp->w_lines[0].wl_size = |
| 1326 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1327 | + wp->w_topfill; |
| 1328 | #endif |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | /* When starting redraw in the first line, redraw all lines. When |
| 1334 | * there is only one window it's probably faster to clear the screen |
| 1335 | * first. */ |
| 1336 | if (mid_start == 0) |
| 1337 | { |
| 1338 | mid_end = wp->w_height; |
| 1339 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1340 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1341 | /* Clear the screen when it was not done by win_del_lines() or |
| 1342 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1343 | * then. */ |
| 1344 | if (screen_cleared != TRUE) |
| 1345 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1346 | #ifdef FEAT_WINDOWS |
| 1347 | /* The screen was cleared, redraw the tab pages line. */ |
| 1348 | if (redraw_tabline) |
| 1349 | draw_tabline(); |
| 1350 | #endif |
| 1351 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1352 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1353 | |
| 1354 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1355 | * cleared (only happens for the first window) or when screenclear() |
| 1356 | * was called directly above, "must_redraw" will have been set to |
| 1357 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1358 | if (screen_cleared == TRUE) |
| 1359 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1360 | } |
| 1361 | else |
| 1362 | { |
| 1363 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1364 | mid_start = 0; |
| 1365 | mid_end = wp->w_height; |
| 1366 | } |
| 1367 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1368 | if (type == SOME_VALID) |
| 1369 | { |
| 1370 | /* SOME_VALID: redraw all lines. */ |
| 1371 | mid_start = 0; |
| 1372 | mid_end = wp->w_height; |
| 1373 | type = NOT_VALID; |
| 1374 | } |
| 1375 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1376 | #ifdef FEAT_VISUAL |
| 1377 | /* check if we are updating or removing the inverted part */ |
| 1378 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1379 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1380 | { |
| 1381 | linenr_T from, to; |
| 1382 | |
| 1383 | if (VIsual_active) |
| 1384 | { |
| 1385 | if (VIsual_active |
| 1386 | && (VIsual_mode != wp->w_old_visual_mode |
| 1387 | || type == INVERTED_ALL)) |
| 1388 | { |
| 1389 | /* |
| 1390 | * If the type of Visual selection changed, redraw the whole |
| 1391 | * selection. Also when the ownership of the X selection is |
| 1392 | * gained or lost. |
| 1393 | */ |
| 1394 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1395 | { |
| 1396 | from = curwin->w_cursor.lnum; |
| 1397 | to = VIsual.lnum; |
| 1398 | } |
| 1399 | else |
| 1400 | { |
| 1401 | from = VIsual.lnum; |
| 1402 | to = curwin->w_cursor.lnum; |
| 1403 | } |
| 1404 | /* redraw more when the cursor moved as well */ |
| 1405 | if (wp->w_old_cursor_lnum < from) |
| 1406 | from = wp->w_old_cursor_lnum; |
| 1407 | if (wp->w_old_cursor_lnum > to) |
| 1408 | to = wp->w_old_cursor_lnum; |
| 1409 | if (wp->w_old_visual_lnum < from) |
| 1410 | from = wp->w_old_visual_lnum; |
| 1411 | if (wp->w_old_visual_lnum > to) |
| 1412 | to = wp->w_old_visual_lnum; |
| 1413 | } |
| 1414 | else |
| 1415 | { |
| 1416 | /* |
| 1417 | * Find the line numbers that need to be updated: The lines |
| 1418 | * between the old cursor position and the current cursor |
| 1419 | * position. Also check if the Visual position changed. |
| 1420 | */ |
| 1421 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1422 | { |
| 1423 | from = curwin->w_cursor.lnum; |
| 1424 | to = wp->w_old_cursor_lnum; |
| 1425 | } |
| 1426 | else |
| 1427 | { |
| 1428 | from = wp->w_old_cursor_lnum; |
| 1429 | to = curwin->w_cursor.lnum; |
| 1430 | if (from == 0) /* Visual mode just started */ |
| 1431 | from = to; |
| 1432 | } |
| 1433 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1434 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1435 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1436 | { |
| 1437 | if (wp->w_old_visual_lnum < from |
| 1438 | && wp->w_old_visual_lnum != 0) |
| 1439 | from = wp->w_old_visual_lnum; |
| 1440 | if (wp->w_old_visual_lnum > to) |
| 1441 | to = wp->w_old_visual_lnum; |
| 1442 | if (VIsual.lnum < from) |
| 1443 | from = VIsual.lnum; |
| 1444 | if (VIsual.lnum > to) |
| 1445 | to = VIsual.lnum; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | /* |
| 1450 | * If in block mode and changed column or curwin->w_curswant: |
| 1451 | * update all lines. |
| 1452 | * First compute the actual start and end column. |
| 1453 | */ |
| 1454 | if (VIsual_mode == Ctrl_V) |
| 1455 | { |
| 1456 | colnr_T fromc, toc; |
| 1457 | |
| 1458 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
| 1459 | ++toc; |
| 1460 | if (curwin->w_curswant == MAXCOL) |
| 1461 | toc = MAXCOL; |
| 1462 | |
| 1463 | if (fromc != wp->w_old_cursor_fcol |
| 1464 | || toc != wp->w_old_cursor_lcol) |
| 1465 | { |
| 1466 | if (from > VIsual.lnum) |
| 1467 | from = VIsual.lnum; |
| 1468 | if (to < VIsual.lnum) |
| 1469 | to = VIsual.lnum; |
| 1470 | } |
| 1471 | wp->w_old_cursor_fcol = fromc; |
| 1472 | wp->w_old_cursor_lcol = toc; |
| 1473 | } |
| 1474 | } |
| 1475 | else |
| 1476 | { |
| 1477 | /* Use the line numbers of the old Visual area. */ |
| 1478 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1479 | { |
| 1480 | from = wp->w_old_cursor_lnum; |
| 1481 | to = wp->w_old_visual_lnum; |
| 1482 | } |
| 1483 | else |
| 1484 | { |
| 1485 | from = wp->w_old_visual_lnum; |
| 1486 | to = wp->w_old_cursor_lnum; |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | /* |
| 1491 | * There is no need to update lines above the top of the window. |
| 1492 | */ |
| 1493 | if (from < wp->w_topline) |
| 1494 | from = wp->w_topline; |
| 1495 | |
| 1496 | /* |
| 1497 | * If we know the value of w_botline, use it to restrict the update to |
| 1498 | * the lines that are visible in the window. |
| 1499 | */ |
| 1500 | if (wp->w_valid & VALID_BOTLINE) |
| 1501 | { |
| 1502 | if (from >= wp->w_botline) |
| 1503 | from = wp->w_botline - 1; |
| 1504 | if (to >= wp->w_botline) |
| 1505 | to = wp->w_botline - 1; |
| 1506 | } |
| 1507 | |
| 1508 | /* |
| 1509 | * Find the minimal part to be updated. |
| 1510 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1511 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1512 | * top_end; need to redraw from top_end to the "to" line. |
| 1513 | * A middle mouse click with a Visual selection may change the text |
| 1514 | * above the Visual area and reset wl_valid, do count these for |
| 1515 | * mid_end (in srow). |
| 1516 | */ |
| 1517 | if (mid_start > 0) |
| 1518 | { |
| 1519 | lnum = wp->w_topline; |
| 1520 | idx = 0; |
| 1521 | srow = 0; |
| 1522 | if (scrolled_down) |
| 1523 | mid_start = top_end; |
| 1524 | else |
| 1525 | mid_start = 0; |
| 1526 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1527 | { |
| 1528 | if (wp->w_lines[idx].wl_valid) |
| 1529 | mid_start += wp->w_lines[idx].wl_size; |
| 1530 | else if (!scrolled_down) |
| 1531 | srow += wp->w_lines[idx].wl_size; |
| 1532 | ++idx; |
| 1533 | # ifdef FEAT_FOLDING |
| 1534 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1535 | lnum = wp->w_lines[idx].wl_lnum; |
| 1536 | else |
| 1537 | # endif |
| 1538 | ++lnum; |
| 1539 | } |
| 1540 | srow += mid_start; |
| 1541 | mid_end = wp->w_height; |
| 1542 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1543 | { |
| 1544 | if (wp->w_lines[idx].wl_valid |
| 1545 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1546 | { |
| 1547 | /* Only update until first row of this line */ |
| 1548 | mid_end = srow; |
| 1549 | break; |
| 1550 | } |
| 1551 | srow += wp->w_lines[idx].wl_size; |
| 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | if (VIsual_active && buf == curwin->w_buffer) |
| 1557 | { |
| 1558 | wp->w_old_visual_mode = VIsual_mode; |
| 1559 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1560 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1561 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1562 | wp->w_old_curswant = curwin->w_curswant; |
| 1563 | } |
| 1564 | else |
| 1565 | { |
| 1566 | wp->w_old_visual_mode = 0; |
| 1567 | wp->w_old_cursor_lnum = 0; |
| 1568 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1569 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1570 | } |
| 1571 | #endif /* FEAT_VISUAL */ |
| 1572 | |
| 1573 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1574 | /* reset got_int, otherwise regexp won't work */ |
| 1575 | save_got_int = got_int; |
| 1576 | got_int = 0; |
| 1577 | #endif |
| 1578 | #ifdef FEAT_FOLDING |
| 1579 | win_foldinfo.fi_level = 0; |
| 1580 | #endif |
| 1581 | |
| 1582 | /* |
| 1583 | * Update all the window rows. |
| 1584 | */ |
| 1585 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1586 | row = 0; |
| 1587 | srow = 0; |
| 1588 | lnum = wp->w_topline; /* first line shown in window */ |
| 1589 | for (;;) |
| 1590 | { |
| 1591 | /* stop updating when reached the end of the window (check for _past_ |
| 1592 | * the end of the window is at the end of the loop) */ |
| 1593 | if (row == wp->w_height) |
| 1594 | { |
| 1595 | didline = TRUE; |
| 1596 | break; |
| 1597 | } |
| 1598 | |
| 1599 | /* stop updating when hit the end of the file */ |
| 1600 | if (lnum > buf->b_ml.ml_line_count) |
| 1601 | { |
| 1602 | eof = TRUE; |
| 1603 | break; |
| 1604 | } |
| 1605 | |
| 1606 | /* Remember the starting row of the line that is going to be dealt |
| 1607 | * with. It is used further down when the line doesn't fit. */ |
| 1608 | srow = row; |
| 1609 | |
| 1610 | /* |
| 1611 | * Update a line when it is in an area that needs updating, when it |
| 1612 | * has changes or w_lines[idx] is invalid. |
| 1613 | * bot_start may be halfway a wrapped line after using |
| 1614 | * win_del_lines(), check if the current line includes it. |
| 1615 | * When syntax folding is being used, the saved syntax states will |
| 1616 | * already have been updated, we can't see where the syntax state is |
| 1617 | * the same again, just update until the end of the window. |
| 1618 | */ |
| 1619 | if (row < top_end |
| 1620 | || (row >= mid_start && row < mid_end) |
| 1621 | #ifdef FEAT_SEARCH_EXTRA |
| 1622 | || top_to_mod |
| 1623 | #endif |
| 1624 | || idx >= wp->w_lines_valid |
| 1625 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1626 | || (mod_top != 0 |
| 1627 | && (lnum == mod_top |
| 1628 | || (lnum >= mod_top |
| 1629 | && (lnum < mod_bot |
| 1630 | #ifdef FEAT_SYN_HL |
| 1631 | || did_update == DID_FOLD |
| 1632 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1633 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1634 | && ( |
| 1635 | # ifdef FEAT_FOLDING |
| 1636 | (foldmethodIsSyntax(wp) |
| 1637 | && hasAnyFolding(wp)) || |
| 1638 | # endif |
| 1639 | syntax_check_changed(lnum))) |
| 1640 | #endif |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1641 | #ifdef FEAT_SEARCH_EXTRA |
| 1642 | /* match in fixed position might need redraw */ |
| 1643 | || wp->w_match_head != NULL |
| 1644 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1645 | ))))) |
| 1646 | { |
| 1647 | #ifdef FEAT_SEARCH_EXTRA |
| 1648 | if (lnum == mod_top) |
| 1649 | top_to_mod = FALSE; |
| 1650 | #endif |
| 1651 | |
| 1652 | /* |
| 1653 | * When at start of changed lines: May scroll following lines |
| 1654 | * up or down to minimize redrawing. |
| 1655 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1656 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1657 | */ |
| 1658 | if (lnum == mod_top |
| 1659 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1660 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1661 | { |
| 1662 | int old_rows = 0; |
| 1663 | int new_rows = 0; |
| 1664 | int xtra_rows; |
| 1665 | linenr_T l; |
| 1666 | |
| 1667 | /* Count the old number of window rows, using w_lines[], which |
| 1668 | * should still contain the sizes for the lines as they are |
| 1669 | * currently displayed. */ |
| 1670 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1671 | { |
| 1672 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1673 | * lines are part of the changed area. */ |
| 1674 | if (wp->w_lines[i].wl_valid |
| 1675 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1676 | break; |
| 1677 | old_rows += wp->w_lines[i].wl_size; |
| 1678 | #ifdef FEAT_FOLDING |
| 1679 | if (wp->w_lines[i].wl_valid |
| 1680 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1681 | { |
| 1682 | /* Must have found the last valid entry above mod_bot. |
| 1683 | * Add following invalid entries. */ |
| 1684 | ++i; |
| 1685 | while (i < wp->w_lines_valid |
| 1686 | && !wp->w_lines[i].wl_valid) |
| 1687 | old_rows += wp->w_lines[i++].wl_size; |
| 1688 | break; |
| 1689 | } |
| 1690 | #endif |
| 1691 | } |
| 1692 | |
| 1693 | if (i >= wp->w_lines_valid) |
| 1694 | { |
| 1695 | /* We can't find a valid line below the changed lines, |
| 1696 | * need to redraw until the end of the window. |
| 1697 | * Inserting/deleting lines has no use. */ |
| 1698 | bot_start = 0; |
| 1699 | } |
| 1700 | else |
| 1701 | { |
| 1702 | /* Able to count old number of rows: Count new window |
| 1703 | * rows, and may insert/delete lines */ |
| 1704 | j = idx; |
| 1705 | for (l = lnum; l < mod_bot; ++l) |
| 1706 | { |
| 1707 | #ifdef FEAT_FOLDING |
| 1708 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1709 | ++new_rows; |
| 1710 | else |
| 1711 | #endif |
| 1712 | #ifdef FEAT_DIFF |
| 1713 | if (l == wp->w_topline) |
| 1714 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1715 | + wp->w_topfill; |
| 1716 | else |
| 1717 | #endif |
| 1718 | new_rows += plines_win(wp, l, TRUE); |
| 1719 | ++j; |
| 1720 | if (new_rows > wp->w_height - row - 2) |
| 1721 | { |
| 1722 | /* it's getting too much, must redraw the rest */ |
| 1723 | new_rows = 9999; |
| 1724 | break; |
| 1725 | } |
| 1726 | } |
| 1727 | xtra_rows = new_rows - old_rows; |
| 1728 | if (xtra_rows < 0) |
| 1729 | { |
| 1730 | /* May scroll text up. If there is not enough |
| 1731 | * remaining text or scrolling fails, must redraw the |
| 1732 | * rest. If scrolling works, must redraw the text |
| 1733 | * below the scrolled text. */ |
| 1734 | if (row - xtra_rows >= wp->w_height - 2) |
| 1735 | mod_bot = MAXLNUM; |
| 1736 | else |
| 1737 | { |
| 1738 | check_for_delay(FALSE); |
| 1739 | if (win_del_lines(wp, row, |
| 1740 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1741 | mod_bot = MAXLNUM; |
| 1742 | else |
| 1743 | bot_start = wp->w_height + xtra_rows; |
| 1744 | } |
| 1745 | } |
| 1746 | else if (xtra_rows > 0) |
| 1747 | { |
| 1748 | /* May scroll text down. If there is not enough |
| 1749 | * remaining text of scrolling fails, must redraw the |
| 1750 | * rest. */ |
| 1751 | if (row + xtra_rows >= wp->w_height - 2) |
| 1752 | mod_bot = MAXLNUM; |
| 1753 | else |
| 1754 | { |
| 1755 | check_for_delay(FALSE); |
| 1756 | if (win_ins_lines(wp, row + old_rows, |
| 1757 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1758 | mod_bot = MAXLNUM; |
| 1759 | else if (top_end > row + old_rows) |
| 1760 | /* Scrolled the part at the top that requires |
| 1761 | * updating down. */ |
| 1762 | top_end += xtra_rows; |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | /* When not updating the rest, may need to move w_lines[] |
| 1767 | * entries. */ |
| 1768 | if (mod_bot != MAXLNUM && i != j) |
| 1769 | { |
| 1770 | if (j < i) |
| 1771 | { |
| 1772 | int x = row + new_rows; |
| 1773 | |
| 1774 | /* move entries in w_lines[] upwards */ |
| 1775 | for (;;) |
| 1776 | { |
| 1777 | /* stop at last valid entry in w_lines[] */ |
| 1778 | if (i >= wp->w_lines_valid) |
| 1779 | { |
| 1780 | wp->w_lines_valid = j; |
| 1781 | break; |
| 1782 | } |
| 1783 | wp->w_lines[j] = wp->w_lines[i]; |
| 1784 | /* stop at a line that won't fit */ |
| 1785 | if (x + (int)wp->w_lines[j].wl_size |
| 1786 | > wp->w_height) |
| 1787 | { |
| 1788 | wp->w_lines_valid = j + 1; |
| 1789 | break; |
| 1790 | } |
| 1791 | x += wp->w_lines[j++].wl_size; |
| 1792 | ++i; |
| 1793 | } |
| 1794 | if (bot_start > x) |
| 1795 | bot_start = x; |
| 1796 | } |
| 1797 | else /* j > i */ |
| 1798 | { |
| 1799 | /* move entries in w_lines[] downwards */ |
| 1800 | j -= i; |
| 1801 | wp->w_lines_valid += j; |
| 1802 | if (wp->w_lines_valid > wp->w_height) |
| 1803 | wp->w_lines_valid = wp->w_height; |
| 1804 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1805 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1806 | |
| 1807 | /* The w_lines[] entries for inserted lines are |
| 1808 | * now invalid, but wl_size may be used above. |
| 1809 | * Reset to zero. */ |
| 1810 | while (i >= idx) |
| 1811 | { |
| 1812 | wp->w_lines[i].wl_size = 0; |
| 1813 | wp->w_lines[i--].wl_valid = FALSE; |
| 1814 | } |
| 1815 | } |
| 1816 | } |
| 1817 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | #ifdef FEAT_FOLDING |
| 1821 | /* |
| 1822 | * When lines are folded, display one line for all of them. |
| 1823 | * Otherwise, display normally (can be several display lines when |
| 1824 | * 'wrap' is on). |
| 1825 | */ |
| 1826 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1827 | if (fold_count != 0) |
| 1828 | { |
| 1829 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1830 | ++row; |
| 1831 | --fold_count; |
| 1832 | wp->w_lines[idx].wl_folded = TRUE; |
| 1833 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1834 | # ifdef FEAT_SYN_HL |
| 1835 | did_update = DID_FOLD; |
| 1836 | # endif |
| 1837 | } |
| 1838 | else |
| 1839 | #endif |
| 1840 | if (idx < wp->w_lines_valid |
| 1841 | && wp->w_lines[idx].wl_valid |
| 1842 | && wp->w_lines[idx].wl_lnum == lnum |
| 1843 | && lnum > wp->w_topline |
| 1844 | && !(dy_flags & DY_LASTLINE) |
| 1845 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1846 | #ifdef FEAT_DIFF |
| 1847 | && diff_check_fill(wp, lnum) == 0 |
| 1848 | #endif |
| 1849 | ) |
| 1850 | { |
| 1851 | /* This line is not going to fit. Don't draw anything here, |
| 1852 | * will draw "@ " lines below. */ |
| 1853 | row = wp->w_height + 1; |
| 1854 | } |
| 1855 | else |
| 1856 | { |
| 1857 | #ifdef FEAT_SEARCH_EXTRA |
| 1858 | prepare_search_hl(wp, lnum); |
| 1859 | #endif |
| 1860 | #ifdef FEAT_SYN_HL |
| 1861 | /* Let the syntax stuff know we skipped a few lines. */ |
| 1862 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1863 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1864 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1865 | #endif |
| 1866 | |
| 1867 | /* |
| 1868 | * Display one line. |
| 1869 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 1870 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1871 | |
| 1872 | #ifdef FEAT_FOLDING |
| 1873 | wp->w_lines[idx].wl_folded = FALSE; |
| 1874 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 1875 | #endif |
| 1876 | #ifdef FEAT_SYN_HL |
| 1877 | did_update = DID_LINE; |
| 1878 | syntax_last_parsed = lnum; |
| 1879 | #endif |
| 1880 | } |
| 1881 | |
| 1882 | wp->w_lines[idx].wl_lnum = lnum; |
| 1883 | wp->w_lines[idx].wl_valid = TRUE; |
| 1884 | if (row > wp->w_height) /* past end of screen */ |
| 1885 | { |
| 1886 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1887 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1888 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 1889 | ++idx; |
| 1890 | break; |
| 1891 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1892 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1893 | wp->w_lines[idx].wl_size = row - srow; |
| 1894 | ++idx; |
| 1895 | #ifdef FEAT_FOLDING |
| 1896 | lnum += fold_count + 1; |
| 1897 | #else |
| 1898 | ++lnum; |
| 1899 | #endif |
| 1900 | } |
| 1901 | else |
| 1902 | { |
| 1903 | /* This line does not need updating, advance to the next one */ |
| 1904 | row += wp->w_lines[idx++].wl_size; |
| 1905 | if (row > wp->w_height) /* past end of screen */ |
| 1906 | break; |
| 1907 | #ifdef FEAT_FOLDING |
| 1908 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 1909 | #else |
| 1910 | ++lnum; |
| 1911 | #endif |
| 1912 | #ifdef FEAT_SYN_HL |
| 1913 | did_update = DID_NONE; |
| 1914 | #endif |
| 1915 | } |
| 1916 | |
| 1917 | if (lnum > buf->b_ml.ml_line_count) |
| 1918 | { |
| 1919 | eof = TRUE; |
| 1920 | break; |
| 1921 | } |
| 1922 | } |
| 1923 | /* |
| 1924 | * End of loop over all window lines. |
| 1925 | */ |
| 1926 | |
| 1927 | |
| 1928 | if (idx > wp->w_lines_valid) |
| 1929 | wp->w_lines_valid = idx; |
| 1930 | |
| 1931 | #ifdef FEAT_SYN_HL |
| 1932 | /* |
| 1933 | * Let the syntax stuff know we stop parsing here. |
| 1934 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1935 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1936 | syntax_end_parsing(syntax_last_parsed + 1); |
| 1937 | #endif |
| 1938 | |
| 1939 | /* |
| 1940 | * If we didn't hit the end of the file, and we didn't finish the last |
| 1941 | * line we were working on, then the line didn't fit. |
| 1942 | */ |
| 1943 | wp->w_empty_rows = 0; |
| 1944 | #ifdef FEAT_DIFF |
| 1945 | wp->w_filler_rows = 0; |
| 1946 | #endif |
| 1947 | if (!eof && !didline) |
| 1948 | { |
| 1949 | if (lnum == wp->w_topline) |
| 1950 | { |
| 1951 | /* |
| 1952 | * Single line that does not fit! |
| 1953 | * Don't overwrite it, it can be edited. |
| 1954 | */ |
| 1955 | wp->w_botline = lnum + 1; |
| 1956 | } |
| 1957 | #ifdef FEAT_DIFF |
| 1958 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 1959 | { |
| 1960 | /* Window ends in filler lines. */ |
| 1961 | wp->w_botline = lnum; |
| 1962 | wp->w_filler_rows = wp->w_height - srow; |
| 1963 | } |
| 1964 | #endif |
| 1965 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 1966 | { |
| 1967 | /* |
| 1968 | * Last line isn't finished: Display "@@@" at the end. |
| 1969 | */ |
| 1970 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 1971 | W_WINROW(wp) + wp->w_height, |
| 1972 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 1973 | '@', '@', hl_attr(HLF_AT)); |
| 1974 | set_empty_rows(wp, srow); |
| 1975 | wp->w_botline = lnum; |
| 1976 | } |
| 1977 | else |
| 1978 | { |
| 1979 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 1980 | wp->w_botline = lnum; |
| 1981 | } |
| 1982 | } |
| 1983 | else |
| 1984 | { |
| 1985 | #ifdef FEAT_VERTSPLIT |
| 1986 | draw_vsep_win(wp, row); |
| 1987 | #endif |
| 1988 | if (eof) /* we hit the end of the file */ |
| 1989 | { |
| 1990 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 1991 | #ifdef FEAT_DIFF |
| 1992 | j = diff_check_fill(wp, wp->w_botline); |
| 1993 | if (j > 0 && !wp->w_botfill) |
| 1994 | { |
| 1995 | /* |
| 1996 | * Display filler lines at the end of the file |
| 1997 | */ |
| 1998 | if (char2cells(fill_diff) > 1) |
| 1999 | i = '-'; |
| 2000 | else |
| 2001 | i = fill_diff; |
| 2002 | if (row + j > wp->w_height) |
| 2003 | j = wp->w_height - row; |
| 2004 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 2005 | row += j; |
| 2006 | } |
| 2007 | #endif |
| 2008 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2009 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2010 | wp->w_botline = lnum; |
| 2011 | |
| 2012 | /* make sure the rest of the screen is blank */ |
| 2013 | /* put '~'s on rows that aren't part of the file. */ |
| 2014 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 2015 | } |
| 2016 | |
| 2017 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2018 | wp->w_redr_type = 0; |
| 2019 | #ifdef FEAT_DIFF |
| 2020 | wp->w_old_topfill = wp->w_topfill; |
| 2021 | wp->w_old_botfill = wp->w_botfill; |
| 2022 | #endif |
| 2023 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2024 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2025 | { |
| 2026 | /* |
| 2027 | * There is a trick with w_botline. If we invalidate it on each |
| 2028 | * change that might modify it, this will cause a lot of expensive |
| 2029 | * calls to plines() in update_topline() each time. Therefore the |
| 2030 | * value of w_botline is often approximated, and this value is used to |
| 2031 | * compute the value of w_topline. If the value of w_botline was |
| 2032 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2033 | * the visible part of the text). If it's not, we need to redraw |
| 2034 | * again. Mostly this just means scrolling up a few lines, so it |
| 2035 | * doesn't look too bad. Only do this for the current window (where |
| 2036 | * changes are relevant). |
| 2037 | */ |
| 2038 | wp->w_valid |= VALID_BOTLINE; |
| 2039 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2040 | { |
| 2041 | recursive = TRUE; |
| 2042 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2043 | update_topline(); /* may invalidate w_botline again */ |
| 2044 | if (must_redraw != 0) |
| 2045 | { |
| 2046 | /* Don't update for changes in buffer again. */ |
| 2047 | i = curbuf->b_mod_set; |
| 2048 | curbuf->b_mod_set = FALSE; |
| 2049 | win_update(curwin); |
| 2050 | must_redraw = 0; |
| 2051 | curbuf->b_mod_set = i; |
| 2052 | } |
| 2053 | recursive = FALSE; |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2058 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2059 | if (!got_int) |
| 2060 | got_int = save_got_int; |
| 2061 | #endif |
| 2062 | } |
| 2063 | |
| 2064 | #ifdef FEAT_SIGNS |
| 2065 | static int draw_signcolumn __ARGS((win_T *wp)); |
| 2066 | |
| 2067 | /* |
| 2068 | * Return TRUE when window "wp" has a column to draw signs in. |
| 2069 | */ |
| 2070 | static int |
| 2071 | draw_signcolumn(wp) |
| 2072 | win_T *wp; |
| 2073 | { |
| 2074 | return (wp->w_buffer->b_signlist != NULL |
| 2075 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 2076 | || netbeans_active() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2077 | # endif |
| 2078 | ); |
| 2079 | } |
| 2080 | #endif |
| 2081 | |
| 2082 | /* |
| 2083 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2084 | * as the filler character. |
| 2085 | */ |
| 2086 | static void |
| 2087 | win_draw_end(wp, c1, c2, row, endrow, hl) |
| 2088 | win_T *wp; |
| 2089 | int c1; |
| 2090 | int c2; |
| 2091 | int row; |
| 2092 | int endrow; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2093 | hlf_T hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2094 | { |
| 2095 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2096 | int n = 0; |
| 2097 | # define FDC_OFF n |
| 2098 | #else |
| 2099 | # define FDC_OFF 0 |
| 2100 | #endif |
| 2101 | |
| 2102 | #ifdef FEAT_RIGHTLEFT |
| 2103 | if (wp->w_p_rl) |
| 2104 | { |
| 2105 | /* No check for cmdline window: should never be right-left. */ |
| 2106 | # ifdef FEAT_FOLDING |
| 2107 | n = wp->w_p_fdc; |
| 2108 | |
| 2109 | if (n > 0) |
| 2110 | { |
| 2111 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2112 | if (n > W_WIDTH(wp)) |
| 2113 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2114 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2115 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2116 | ' ', ' ', hl_attr(HLF_FC)); |
| 2117 | } |
| 2118 | # endif |
| 2119 | # ifdef FEAT_SIGNS |
| 2120 | if (draw_signcolumn(wp)) |
| 2121 | { |
| 2122 | int nn = n + 2; |
| 2123 | |
| 2124 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2125 | if (nn > W_WIDTH(wp)) |
| 2126 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2127 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2128 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2129 | ' ', ' ', hl_attr(HLF_SC)); |
| 2130 | n = nn; |
| 2131 | } |
| 2132 | # endif |
| 2133 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2134 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2135 | c2, c2, hl_attr(hl)); |
| 2136 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2137 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2138 | c1, c2, hl_attr(hl)); |
| 2139 | } |
| 2140 | else |
| 2141 | #endif |
| 2142 | { |
| 2143 | #ifdef FEAT_CMDWIN |
| 2144 | if (cmdwin_type != 0 && wp == curwin) |
| 2145 | { |
| 2146 | /* draw the cmdline character in the leftmost column */ |
| 2147 | n = 1; |
| 2148 | if (n > wp->w_width) |
| 2149 | n = wp->w_width; |
| 2150 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2151 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2152 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2153 | } |
| 2154 | #endif |
| 2155 | #ifdef FEAT_FOLDING |
| 2156 | if (wp->w_p_fdc > 0) |
| 2157 | { |
| 2158 | int nn = n + wp->w_p_fdc; |
| 2159 | |
| 2160 | /* draw the fold column at the left */ |
| 2161 | if (nn > W_WIDTH(wp)) |
| 2162 | nn = W_WIDTH(wp); |
| 2163 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2164 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2165 | ' ', ' ', hl_attr(HLF_FC)); |
| 2166 | n = nn; |
| 2167 | } |
| 2168 | #endif |
| 2169 | #ifdef FEAT_SIGNS |
| 2170 | if (draw_signcolumn(wp)) |
| 2171 | { |
| 2172 | int nn = n + 2; |
| 2173 | |
| 2174 | /* draw the sign column after the fold column */ |
| 2175 | if (nn > W_WIDTH(wp)) |
| 2176 | nn = W_WIDTH(wp); |
| 2177 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2178 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2179 | ' ', ' ', hl_attr(HLF_SC)); |
| 2180 | n = nn; |
| 2181 | } |
| 2182 | #endif |
| 2183 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2184 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2185 | c1, c2, hl_attr(hl)); |
| 2186 | } |
| 2187 | set_empty_rows(wp, row); |
| 2188 | } |
| 2189 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2190 | #ifdef FEAT_SYN_HL |
| 2191 | static int advance_color_col __ARGS((int vcol, int **color_cols)); |
| 2192 | |
| 2193 | /* |
| 2194 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2195 | */ |
| 2196 | static int |
| 2197 | advance_color_col(vcol, color_cols) |
| 2198 | int vcol; |
| 2199 | int **color_cols; |
| 2200 | { |
| 2201 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2202 | ++*color_cols; |
| 2203 | return (**color_cols >= 0); |
| 2204 | } |
| 2205 | #endif |
| 2206 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2207 | #ifdef FEAT_FOLDING |
| 2208 | /* |
| 2209 | * Display one folded line. |
| 2210 | */ |
| 2211 | static void |
| 2212 | fold_line(wp, fold_count, foldinfo, lnum, row) |
| 2213 | win_T *wp; |
| 2214 | long fold_count; |
| 2215 | foldinfo_T *foldinfo; |
| 2216 | linenr_T lnum; |
| 2217 | int row; |
| 2218 | { |
| 2219 | char_u buf[51]; |
| 2220 | pos_T *top, *bot; |
| 2221 | linenr_T lnume = lnum + fold_count - 1; |
| 2222 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2223 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2224 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2225 | int col; |
| 2226 | int txtcol; |
| 2227 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2228 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2229 | |
| 2230 | /* Build the fold line: |
| 2231 | * 1. Add the cmdwin_type for the command-line window |
| 2232 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2233 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2234 | * 4. Compose the text |
| 2235 | * 5. Add the text |
| 2236 | * 6. set highlighting for the Visual area an other text |
| 2237 | */ |
| 2238 | col = 0; |
| 2239 | |
| 2240 | /* |
| 2241 | * 1. Add the cmdwin_type for the command-line window |
| 2242 | * Ignores 'rightleft', this window is never right-left. |
| 2243 | */ |
| 2244 | #ifdef FEAT_CMDWIN |
| 2245 | if (cmdwin_type != 0 && wp == curwin) |
| 2246 | { |
| 2247 | ScreenLines[off] = cmdwin_type; |
| 2248 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2249 | #ifdef FEAT_MBYTE |
| 2250 | if (enc_utf8) |
| 2251 | ScreenLinesUC[off] = 0; |
| 2252 | #endif |
| 2253 | ++col; |
| 2254 | } |
| 2255 | #endif |
| 2256 | |
| 2257 | /* |
| 2258 | * 2. Add the 'foldcolumn' |
| 2259 | */ |
| 2260 | fdc = wp->w_p_fdc; |
| 2261 | if (fdc > W_WIDTH(wp) - col) |
| 2262 | fdc = W_WIDTH(wp) - col; |
| 2263 | if (fdc > 0) |
| 2264 | { |
| 2265 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2266 | #ifdef FEAT_RIGHTLEFT |
| 2267 | if (wp->w_p_rl) |
| 2268 | { |
| 2269 | int i; |
| 2270 | |
| 2271 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2272 | hl_attr(HLF_FC)); |
| 2273 | /* reverse the fold column */ |
| 2274 | for (i = 0; i < fdc; ++i) |
| 2275 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2276 | } |
| 2277 | else |
| 2278 | #endif |
| 2279 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2280 | col += fdc; |
| 2281 | } |
| 2282 | |
| 2283 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2284 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2285 | for (ri = 0; ri < l; ++ri) \ |
| 2286 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2287 | else \ |
| 2288 | for (ri = 0; ri < l; ++ri) \ |
| 2289 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2290 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2291 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2292 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2293 | #endif |
| 2294 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2295 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2296 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2297 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2298 | |
| 2299 | #ifdef FEAT_SIGNS |
| 2300 | /* If signs are being displayed, add two spaces. */ |
| 2301 | if (draw_signcolumn(wp)) |
| 2302 | { |
| 2303 | len = W_WIDTH(wp) - col; |
| 2304 | if (len > 0) |
| 2305 | { |
| 2306 | if (len > 2) |
| 2307 | len = 2; |
| 2308 | # ifdef FEAT_RIGHTLEFT |
| 2309 | if (wp->w_p_rl) |
| 2310 | /* the line number isn't reversed */ |
| 2311 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2312 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2313 | else |
| 2314 | # endif |
| 2315 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2316 | col += len; |
| 2317 | } |
| 2318 | } |
| 2319 | #endif |
| 2320 | |
| 2321 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2322 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2323 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2324 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2325 | { |
| 2326 | len = W_WIDTH(wp) - col; |
| 2327 | if (len > 0) |
| 2328 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2329 | int w = number_width(wp); |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2330 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2331 | char *fmt = "%*ld "; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2332 | |
| 2333 | if (len > w + 1) |
| 2334 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2335 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2336 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 2337 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2338 | num = (long)lnum; |
| 2339 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2340 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2341 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2342 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2343 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2344 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2345 | /* 'number' + 'relativenumber': cursor line shows absolute |
| 2346 | * line number */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2347 | num = lnum; |
| 2348 | fmt = "%-*ld "; |
| 2349 | } |
| 2350 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2351 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2352 | sprintf((char *)buf, fmt, w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2353 | #ifdef FEAT_RIGHTLEFT |
| 2354 | if (wp->w_p_rl) |
| 2355 | /* the line number isn't reversed */ |
| 2356 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2357 | hl_attr(HLF_FL)); |
| 2358 | else |
| 2359 | #endif |
| 2360 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2361 | col += len; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | /* |
| 2366 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2367 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2368 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2369 | |
| 2370 | txtcol = col; /* remember where text starts */ |
| 2371 | |
| 2372 | /* |
| 2373 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2374 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2375 | * in columns number-col - window-width. |
| 2376 | */ |
| 2377 | #ifdef FEAT_MBYTE |
| 2378 | if (has_mbyte) |
| 2379 | { |
| 2380 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2381 | int u8c, u8cc[MAX_MCO]; |
| 2382 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2383 | int idx; |
| 2384 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2385 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2386 | # ifdef FEAT_ARABIC |
| 2387 | int prev_c = 0; /* previous Arabic character */ |
| 2388 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2389 | # endif |
| 2390 | |
| 2391 | # ifdef FEAT_RIGHTLEFT |
| 2392 | if (wp->w_p_rl) |
| 2393 | idx = off; |
| 2394 | else |
| 2395 | # endif |
| 2396 | idx = off + col; |
| 2397 | |
| 2398 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2399 | for (p = text; *p != NUL; ) |
| 2400 | { |
| 2401 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2402 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2403 | if (col + cells > W_WIDTH(wp) |
| 2404 | # ifdef FEAT_RIGHTLEFT |
| 2405 | - (wp->w_p_rl ? col : 0) |
| 2406 | # endif |
| 2407 | ) |
| 2408 | break; |
| 2409 | ScreenLines[idx] = *p; |
| 2410 | if (enc_utf8) |
| 2411 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2412 | u8c = utfc_ptr2char(p, u8cc); |
| 2413 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2414 | { |
| 2415 | ScreenLinesUC[idx] = 0; |
| 2416 | #ifdef FEAT_ARABIC |
| 2417 | prev_c = u8c; |
| 2418 | #endif |
| 2419 | } |
| 2420 | else |
| 2421 | { |
| 2422 | #ifdef FEAT_ARABIC |
| 2423 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2424 | { |
| 2425 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2426 | int pc, pc1, nc; |
| 2427 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2428 | int firstbyte = *p; |
| 2429 | |
| 2430 | /* The idea of what is the previous and next |
| 2431 | * character depends on 'rightleft'. */ |
| 2432 | if (wp->w_p_rl) |
| 2433 | { |
| 2434 | pc = prev_c; |
| 2435 | pc1 = prev_c1; |
| 2436 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2437 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2438 | } |
| 2439 | else |
| 2440 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2441 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2442 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2443 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2444 | } |
| 2445 | prev_c = u8c; |
| 2446 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2447 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2448 | pc, pc1, nc); |
| 2449 | ScreenLines[idx] = firstbyte; |
| 2450 | } |
| 2451 | else |
| 2452 | prev_c = u8c; |
| 2453 | #endif |
| 2454 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2455 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2456 | if (u8c >= 0x10000) |
| 2457 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2458 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2459 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2460 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2461 | for (i = 0; i < Screen_mco; ++i) |
| 2462 | { |
| 2463 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2464 | if (u8cc[i] == 0) |
| 2465 | break; |
| 2466 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2467 | } |
| 2468 | if (cells > 1) |
| 2469 | ScreenLines[idx + 1] = 0; |
| 2470 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2471 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2472 | /* double-byte single width character */ |
| 2473 | ScreenLines2[idx] = p[1]; |
| 2474 | else if (cells > 1) |
| 2475 | /* double-width character */ |
| 2476 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2477 | col += cells; |
| 2478 | idx += cells; |
| 2479 | p += c_len; |
| 2480 | } |
| 2481 | } |
| 2482 | else |
| 2483 | #endif |
| 2484 | { |
| 2485 | len = (int)STRLEN(text); |
| 2486 | if (len > W_WIDTH(wp) - col) |
| 2487 | len = W_WIDTH(wp) - col; |
| 2488 | if (len > 0) |
| 2489 | { |
| 2490 | #ifdef FEAT_RIGHTLEFT |
| 2491 | if (wp->w_p_rl) |
| 2492 | STRNCPY(current_ScreenLine, text, len); |
| 2493 | else |
| 2494 | #endif |
| 2495 | STRNCPY(current_ScreenLine + col, text, len); |
| 2496 | col += len; |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | /* Fill the rest of the line with the fold filler */ |
| 2501 | #ifdef FEAT_RIGHTLEFT |
| 2502 | if (wp->w_p_rl) |
| 2503 | col -= txtcol; |
| 2504 | #endif |
| 2505 | while (col < W_WIDTH(wp) |
| 2506 | #ifdef FEAT_RIGHTLEFT |
| 2507 | - (wp->w_p_rl ? txtcol : 0) |
| 2508 | #endif |
| 2509 | ) |
| 2510 | { |
| 2511 | #ifdef FEAT_MBYTE |
| 2512 | if (enc_utf8) |
| 2513 | { |
| 2514 | if (fill_fold >= 0x80) |
| 2515 | { |
| 2516 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2517 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2518 | } |
| 2519 | else |
| 2520 | ScreenLinesUC[off + col] = 0; |
| 2521 | } |
| 2522 | #endif |
| 2523 | ScreenLines[off + col++] = fill_fold; |
| 2524 | } |
| 2525 | |
| 2526 | if (text != buf) |
| 2527 | vim_free(text); |
| 2528 | |
| 2529 | /* |
| 2530 | * 6. set highlighting for the Visual area an other text. |
| 2531 | * If all folded lines are in the Visual area, highlight the line. |
| 2532 | */ |
| 2533 | #ifdef FEAT_VISUAL |
| 2534 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2535 | { |
| 2536 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2537 | { |
| 2538 | /* Visual is after curwin->w_cursor */ |
| 2539 | top = &curwin->w_cursor; |
| 2540 | bot = &VIsual; |
| 2541 | } |
| 2542 | else |
| 2543 | { |
| 2544 | /* Visual is before curwin->w_cursor */ |
| 2545 | top = &VIsual; |
| 2546 | bot = &curwin->w_cursor; |
| 2547 | } |
| 2548 | if (lnum >= top->lnum |
| 2549 | && lnume <= bot->lnum |
| 2550 | && (VIsual_mode != 'v' |
| 2551 | || ((lnum > top->lnum |
| 2552 | || (lnum == top->lnum |
| 2553 | && top->col == 0)) |
| 2554 | && (lnume < bot->lnum |
| 2555 | || (lnume == bot->lnum |
| 2556 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2557 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2558 | { |
| 2559 | if (VIsual_mode == Ctrl_V) |
| 2560 | { |
| 2561 | /* Visual block mode: highlight the chars part of the block */ |
| 2562 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2563 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2564 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2565 | && wp->w_old_cursor_lcol + txtcol |
| 2566 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2567 | len = wp->w_old_cursor_lcol; |
| 2568 | else |
| 2569 | len = W_WIDTH(wp) - txtcol; |
| 2570 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2571 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2575 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2576 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2577 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2578 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | #endif |
| 2582 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2583 | #ifdef FEAT_SYN_HL |
| 2584 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2585 | if (wp->w_p_cuc) |
| 2586 | { |
| 2587 | txtcol += wp->w_virtcol; |
| 2588 | if (wp->w_p_wrap) |
| 2589 | txtcol -= wp->w_skipcol; |
| 2590 | else |
| 2591 | txtcol -= wp->w_leftcol; |
| 2592 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2593 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2594 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2595 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2596 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2597 | |
| 2598 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2599 | (int)W_WIDTH(wp), FALSE); |
| 2600 | |
| 2601 | /* |
| 2602 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2603 | * updated (saves a call to plines() later). |
| 2604 | */ |
| 2605 | if (wp == curwin |
| 2606 | && lnum <= curwin->w_cursor.lnum |
| 2607 | && lnume >= curwin->w_cursor.lnum) |
| 2608 | { |
| 2609 | curwin->w_cline_row = row; |
| 2610 | curwin->w_cline_height = 1; |
| 2611 | curwin->w_cline_folded = TRUE; |
| 2612 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | /* |
| 2617 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2618 | */ |
| 2619 | static void |
| 2620 | copy_text_attr(off, buf, len, attr) |
| 2621 | int off; |
| 2622 | char_u *buf; |
| 2623 | int len; |
| 2624 | int attr; |
| 2625 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2626 | int i; |
| 2627 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2628 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2629 | # ifdef FEAT_MBYTE |
| 2630 | if (enc_utf8) |
| 2631 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2632 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2633 | for (i = 0; i < len; ++i) |
| 2634 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | /* |
| 2638 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2639 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2640 | */ |
| 2641 | static void |
| 2642 | fill_foldcolumn(p, wp, closed, lnum) |
| 2643 | char_u *p; |
| 2644 | win_T *wp; |
| 2645 | int closed; /* TRUE of FALSE */ |
| 2646 | linenr_T lnum; /* current line number */ |
| 2647 | { |
| 2648 | int i = 0; |
| 2649 | int level; |
| 2650 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2651 | int empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2652 | |
| 2653 | /* Init to all spaces. */ |
| 2654 | copy_spaces(p, (size_t)wp->w_p_fdc); |
| 2655 | |
| 2656 | level = win_foldinfo.fi_level; |
| 2657 | if (level > 0) |
| 2658 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2659 | /* If there is only one column put more info in it. */ |
| 2660 | empty = (wp->w_p_fdc == 1) ? 0 : 1; |
| 2661 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2662 | /* If the column is too narrow, we start at the lowest level that |
| 2663 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2664 | first_level = level - wp->w_p_fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2665 | if (first_level < 1) |
| 2666 | first_level = 1; |
| 2667 | |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2668 | for (i = 0; i + empty < wp->w_p_fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2669 | { |
| 2670 | if (win_foldinfo.fi_lnum == lnum |
| 2671 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2672 | p[i] = '-'; |
| 2673 | else if (first_level == 1) |
| 2674 | p[i] = '|'; |
| 2675 | else if (first_level + i <= 9) |
| 2676 | p[i] = '0' + first_level + i; |
| 2677 | else |
| 2678 | p[i] = '>'; |
| 2679 | if (first_level + i == level) |
| 2680 | break; |
| 2681 | } |
| 2682 | } |
| 2683 | if (closed) |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2684 | p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2685 | } |
| 2686 | #endif /* FEAT_FOLDING */ |
| 2687 | |
| 2688 | /* |
| 2689 | * Display line "lnum" of window 'wp' on the screen. |
| 2690 | * Start at row "startrow", stop when "endrow" is reached. |
| 2691 | * wp->w_virtcol needs to be valid. |
| 2692 | * |
| 2693 | * Return the number of last row the line occupies. |
| 2694 | */ |
| 2695 | static int |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2696 | win_line(wp, lnum, startrow, endrow, nochange) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2697 | win_T *wp; |
| 2698 | linenr_T lnum; |
| 2699 | int startrow; |
| 2700 | int endrow; |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2701 | int nochange UNUSED; /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2702 | { |
| 2703 | int col; /* visual column on screen */ |
| 2704 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2705 | int c = 0; /* init for GCC */ |
| 2706 | long vcol = 0; /* virtual column (for tabs) */ |
| 2707 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2708 | char_u *line; /* current line */ |
| 2709 | char_u *ptr; /* current position in "line" */ |
| 2710 | int row; /* row in the window, excl w_winrow */ |
| 2711 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2712 | |
| 2713 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2714 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2715 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2716 | int c_extra = NUL; /* extra chars, all the same */ |
| 2717 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2718 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2719 | displaying lcs_eol at end-of-line */ |
| 2720 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2721 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2722 | |
| 2723 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2724 | int saved_n_extra = 0; |
| 2725 | char_u *saved_p_extra = NULL; |
| 2726 | int saved_c_extra = 0; |
| 2727 | int saved_char_attr = 0; |
| 2728 | |
| 2729 | int n_attr = 0; /* chars with special attr */ |
| 2730 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2731 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2732 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2733 | |
| 2734 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2735 | |
| 2736 | int fromcol, tocol; /* start/end of inverting */ |
| 2737 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2738 | int noinvcur = FALSE; /* don't invert the cursor */ |
| 2739 | #ifdef FEAT_VISUAL |
| 2740 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2741 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2742 | #endif |
| 2743 | pos_T pos; |
| 2744 | long v; |
| 2745 | |
| 2746 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2747 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2748 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2749 | in this line */ |
| 2750 | int attr = 0; /* attributes for area highlighting */ |
| 2751 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2752 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2753 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2754 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2755 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2756 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2757 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2758 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2759 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2760 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2761 | #endif |
| 2762 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2763 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2764 | # define SPWORDLEN 150 |
| 2765 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2766 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2767 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2768 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2769 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2770 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2771 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2772 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2773 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2774 | static int cap_col = -1; /* column to check for Cap word */ |
| 2775 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2776 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2777 | #endif |
| 2778 | int extra_check; /* has syntax or linebreak */ |
| 2779 | #ifdef FEAT_MBYTE |
| 2780 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2781 | int mb_l = 1; /* multi-byte byte length */ |
| 2782 | int mb_c = 0; /* decoded multi-byte character */ |
| 2783 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2784 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2785 | #endif |
| 2786 | #ifdef FEAT_DIFF |
| 2787 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2788 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2789 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2790 | int change_start = MAXCOL; /* first col of changed area */ |
| 2791 | int change_end = -1; /* last col of changed area */ |
| 2792 | #endif |
| 2793 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2794 | #ifdef FEAT_LINEBREAK |
| 2795 | int need_showbreak = FALSE; |
| 2796 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2797 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2798 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2799 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 2800 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2801 | #endif |
| 2802 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2803 | matchitem_T *cur; /* points to the match list */ |
| 2804 | match_T *shl; /* points to search_hl or a match */ |
| 2805 | int shl_flag; /* flag to indicate whether search_hl |
| 2806 | has been processed or not */ |
| 2807 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 2808 | equals startcol of search_hl or one |
| 2809 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2810 | #endif |
| 2811 | #ifdef FEAT_ARABIC |
| 2812 | int prev_c = 0; /* previous Arabic character */ |
| 2813 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2814 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2815 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 2816 | int did_line_attr = 0; |
| 2817 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2818 | |
| 2819 | /* draw_state: items that are drawn in sequence: */ |
| 2820 | #define WL_START 0 /* nothing done yet */ |
| 2821 | #ifdef FEAT_CMDWIN |
| 2822 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 2823 | #else |
| 2824 | # define WL_CMDLINE WL_START |
| 2825 | #endif |
| 2826 | #ifdef FEAT_FOLDING |
| 2827 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 2828 | #else |
| 2829 | # define WL_FOLD WL_CMDLINE |
| 2830 | #endif |
| 2831 | #ifdef FEAT_SIGNS |
| 2832 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 2833 | #else |
| 2834 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 2835 | #endif |
| 2836 | #define WL_NR WL_SIGN + 1 /* line number */ |
| 2837 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 2838 | # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ |
| 2839 | #else |
| 2840 | # define WL_SBR WL_NR |
| 2841 | #endif |
| 2842 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 2843 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 2844 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2845 | int feedback_col = 0; |
| 2846 | int feedback_old_attr = -1; |
| 2847 | #endif |
| 2848 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2849 | #ifdef FEAT_CONCEAL |
| 2850 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 2851 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 2852 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2853 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2854 | int is_concealing = FALSE; |
| 2855 | int boguscols = 0; /* nonexistent columns added to force |
| 2856 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 2857 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 2858 | int did_wcol = FALSE; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 2859 | # define VCOL_HLC (vcol - vcol_off) |
| 2860 | #else |
| 2861 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2862 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2863 | |
| 2864 | if (startrow > endrow) /* past the end already! */ |
| 2865 | return startrow; |
| 2866 | |
| 2867 | row = startrow; |
| 2868 | screen_row = row + W_WINROW(wp); |
| 2869 | |
| 2870 | /* |
| 2871 | * To speed up the loop below, set extra_check when there is linebreak, |
| 2872 | * trailing white space and/or syntax processing to be done. |
| 2873 | */ |
| 2874 | #ifdef FEAT_LINEBREAK |
| 2875 | extra_check = wp->w_p_lbr; |
| 2876 | #else |
| 2877 | extra_check = 0; |
| 2878 | #endif |
| 2879 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2880 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2881 | { |
| 2882 | /* Prepare for syntax highlighting in this line. When there is an |
| 2883 | * error, stop syntax highlighting. */ |
| 2884 | save_did_emsg = did_emsg; |
| 2885 | did_emsg = FALSE; |
| 2886 | syntax_start(wp, lnum); |
| 2887 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2888 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2889 | else |
| 2890 | { |
| 2891 | did_emsg = save_did_emsg; |
| 2892 | has_syntax = TRUE; |
| 2893 | extra_check = TRUE; |
| 2894 | } |
| 2895 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2896 | |
| 2897 | /* Check for columns to display for 'colorcolumn'. */ |
| 2898 | color_cols = wp->w_p_cc_cols; |
| 2899 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 2900 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2901 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2902 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2903 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 2904 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2905 | && *wp->w_s->b_p_spl != NUL |
| 2906 | && wp->w_s->b_langp.ga_len > 0 |
| 2907 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2908 | { |
| 2909 | /* Prepare for spell checking. */ |
| 2910 | has_spell = TRUE; |
| 2911 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2912 | |
| 2913 | /* Get the start of the next line, so that words that wrap to the next |
| 2914 | * line are found too: "et<line-break>al.". |
| 2915 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 2916 | nextline[SPWORDLEN] = NUL; |
| 2917 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 2918 | { |
| 2919 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 2920 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 2921 | } |
| 2922 | |
| 2923 | /* When a word wrapped from the previous line the start of the current |
| 2924 | * line is valid. */ |
| 2925 | if (lnum == checked_lnum) |
| 2926 | cur_checked_col = checked_col; |
| 2927 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2928 | |
| 2929 | /* When there was a sentence end in the previous line may require a |
| 2930 | * word starting with capital in this line. In line 1 always check |
| 2931 | * the first word. */ |
| 2932 | if (lnum != capcol_lnum) |
| 2933 | cap_col = -1; |
| 2934 | if (lnum == 1) |
| 2935 | cap_col = 0; |
| 2936 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2937 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2938 | #endif |
| 2939 | |
| 2940 | /* |
| 2941 | * handle visual active in this window |
| 2942 | */ |
| 2943 | fromcol = -10; |
| 2944 | tocol = MAXCOL; |
| 2945 | #ifdef FEAT_VISUAL |
| 2946 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2947 | { |
| 2948 | /* Visual is after curwin->w_cursor */ |
| 2949 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2950 | { |
| 2951 | top = &curwin->w_cursor; |
| 2952 | bot = &VIsual; |
| 2953 | } |
| 2954 | else /* Visual is before curwin->w_cursor */ |
| 2955 | { |
| 2956 | top = &VIsual; |
| 2957 | bot = &curwin->w_cursor; |
| 2958 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2959 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2960 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 2961 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2962 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2963 | { |
| 2964 | fromcol = wp->w_old_cursor_fcol; |
| 2965 | tocol = wp->w_old_cursor_lcol; |
| 2966 | } |
| 2967 | } |
| 2968 | else /* non-block mode */ |
| 2969 | { |
| 2970 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 2971 | fromcol = 0; |
| 2972 | else if (lnum == top->lnum) |
| 2973 | { |
| 2974 | if (VIsual_mode == 'V') /* linewise */ |
| 2975 | fromcol = 0; |
| 2976 | else |
| 2977 | { |
| 2978 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 2979 | if (gchar_pos(top) == NUL) |
| 2980 | tocol = fromcol + 1; |
| 2981 | } |
| 2982 | } |
| 2983 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 2984 | { |
| 2985 | if (*p_sel == 'e' && bot->col == 0 |
| 2986 | #ifdef FEAT_VIRTUALEDIT |
| 2987 | && bot->coladd == 0 |
| 2988 | #endif |
| 2989 | ) |
| 2990 | { |
| 2991 | fromcol = -10; |
| 2992 | tocol = MAXCOL; |
| 2993 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2994 | else if (bot->col == MAXCOL) |
| 2995 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2996 | else |
| 2997 | { |
| 2998 | pos = *bot; |
| 2999 | if (*p_sel == 'e') |
| 3000 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3001 | else |
| 3002 | { |
| 3003 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 3004 | ++tocol; |
| 3005 | } |
| 3006 | } |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | #ifndef MSDOS |
| 3011 | /* Check if the character under the cursor should not be inverted */ |
| 3012 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
| 3013 | # ifdef FEAT_GUI |
| 3014 | && !gui.in_use |
| 3015 | # endif |
| 3016 | ) |
| 3017 | noinvcur = TRUE; |
| 3018 | #endif |
| 3019 | |
| 3020 | /* if inverting in this line set area_highlighting */ |
| 3021 | if (fromcol >= 0) |
| 3022 | { |
| 3023 | area_highlighting = TRUE; |
| 3024 | attr = hl_attr(HLF_V); |
| 3025 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3026 | if ((clip_star.available && !clip_star.owned |
| 3027 | && clip_isautosel_star()) |
| 3028 | || (clip_plus.available && !clip_plus.owned |
| 3029 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3030 | attr = hl_attr(HLF_VNC); |
| 3031 | #endif |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3036 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3037 | */ |
| 3038 | else |
| 3039 | #endif /* FEAT_VISUAL */ |
| 3040 | if (highlight_match |
| 3041 | && wp == curwin |
| 3042 | && lnum >= curwin->w_cursor.lnum |
| 3043 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3044 | { |
| 3045 | if (lnum == curwin->w_cursor.lnum) |
| 3046 | getvcol(curwin, &(curwin->w_cursor), |
| 3047 | (colnr_T *)&fromcol, NULL, NULL); |
| 3048 | else |
| 3049 | fromcol = 0; |
| 3050 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3051 | { |
| 3052 | pos.lnum = lnum; |
| 3053 | pos.col = search_match_endcol; |
| 3054 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3055 | } |
| 3056 | else |
| 3057 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3058 | /* do at least one character; happens when past end of line */ |
| 3059 | if (fromcol == tocol) |
| 3060 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3061 | area_highlighting = TRUE; |
| 3062 | attr = hl_attr(HLF_I); |
| 3063 | } |
| 3064 | |
| 3065 | #ifdef FEAT_DIFF |
| 3066 | filler_lines = diff_check(wp, lnum); |
| 3067 | if (filler_lines < 0) |
| 3068 | { |
| 3069 | if (filler_lines == -1) |
| 3070 | { |
| 3071 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3072 | diff_hlf = HLF_ADD; /* added line */ |
| 3073 | else if (change_start == 0) |
| 3074 | diff_hlf = HLF_TXD; /* changed text */ |
| 3075 | else |
| 3076 | diff_hlf = HLF_CHD; /* changed line */ |
| 3077 | } |
| 3078 | else |
| 3079 | diff_hlf = HLF_ADD; /* added line */ |
| 3080 | filler_lines = 0; |
| 3081 | area_highlighting = TRUE; |
| 3082 | } |
| 3083 | if (lnum == wp->w_topline) |
| 3084 | filler_lines = wp->w_topfill; |
| 3085 | filler_todo = filler_lines; |
| 3086 | #endif |
| 3087 | |
| 3088 | #ifdef LINE_ATTR |
| 3089 | # ifdef FEAT_SIGNS |
| 3090 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3091 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3092 | if (v != 0) |
| 3093 | line_attr = sign_get_attr((int)v, TRUE); |
| 3094 | # endif |
| 3095 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3096 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3097 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3098 | line_attr = hl_attr(HLF_L); |
| 3099 | # endif |
| 3100 | if (line_attr != 0) |
| 3101 | area_highlighting = TRUE; |
| 3102 | #endif |
| 3103 | |
| 3104 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3105 | ptr = line; |
| 3106 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3107 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3108 | if (has_spell) |
| 3109 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3110 | /* For checking first word with a capital skip white space. */ |
| 3111 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3112 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3113 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3114 | /* To be able to spell-check over line boundaries copy the end of the |
| 3115 | * current line into nextline[]. Above the start of the next line was |
| 3116 | * copied to nextline[SPWORDLEN]. */ |
| 3117 | if (nextline[SPWORDLEN] == NUL) |
| 3118 | { |
| 3119 | /* No next line or it is empty. */ |
| 3120 | nextlinecol = MAXCOL; |
| 3121 | nextline_idx = 0; |
| 3122 | } |
| 3123 | else |
| 3124 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3125 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3126 | if (v < SPWORDLEN) |
| 3127 | { |
| 3128 | /* Short line, use it completely and append the start of the |
| 3129 | * next line. */ |
| 3130 | nextlinecol = 0; |
| 3131 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3132 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3133 | nextline_idx = v + 1; |
| 3134 | } |
| 3135 | else |
| 3136 | { |
| 3137 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3138 | nextlinecol = v - SPWORDLEN; |
| 3139 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3140 | nextline_idx = SPWORDLEN + 1; |
| 3141 | } |
| 3142 | } |
| 3143 | } |
| 3144 | #endif |
| 3145 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3146 | /* find start of trailing whitespace */ |
| 3147 | if (wp->w_p_list && lcs_trail) |
| 3148 | { |
| 3149 | trailcol = (colnr_T)STRLEN(ptr); |
| 3150 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3151 | --trailcol; |
| 3152 | trailcol += (colnr_T) (ptr - line); |
| 3153 | extra_check = TRUE; |
| 3154 | } |
| 3155 | |
| 3156 | /* |
| 3157 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3158 | * first character to be displayed. |
| 3159 | */ |
| 3160 | if (wp->w_p_wrap) |
| 3161 | v = wp->w_skipcol; |
| 3162 | else |
| 3163 | v = wp->w_leftcol; |
| 3164 | if (v > 0) |
| 3165 | { |
| 3166 | #ifdef FEAT_MBYTE |
| 3167 | char_u *prev_ptr = ptr; |
| 3168 | #endif |
| 3169 | while (vcol < v && *ptr != NUL) |
| 3170 | { |
| 3171 | c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); |
| 3172 | vcol += c; |
| 3173 | #ifdef FEAT_MBYTE |
| 3174 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3175 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3176 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3179 | #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
| 3180 | /* When: |
| 3181 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3182 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3183 | * - 'virtualedit' is set, or |
| 3184 | * - the visual mode is active, |
| 3185 | * the end of the line may be before the start of the displayed part. |
| 3186 | */ |
| 3187 | if (vcol < v && ( |
| 3188 | # ifdef FEAT_SYN_HL |
| 3189 | wp->w_p_cuc |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3190 | || draw_color_col |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3191 | # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
| 3192 | || |
| 3193 | # endif |
| 3194 | # endif |
| 3195 | # ifdef FEAT_VIRTUALEDIT |
| 3196 | virtual_active() |
| 3197 | # ifdef FEAT_VISUAL |
| 3198 | || |
| 3199 | # endif |
| 3200 | # endif |
| 3201 | # ifdef FEAT_VISUAL |
| 3202 | (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3203 | # endif |
| 3204 | )) |
| 3205 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3206 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3207 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3208 | #endif |
| 3209 | |
| 3210 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3211 | * that character but skip the first few screen characters. */ |
| 3212 | if (vcol > v) |
| 3213 | { |
| 3214 | vcol -= c; |
| 3215 | #ifdef FEAT_MBYTE |
| 3216 | ptr = prev_ptr; |
| 3217 | #else |
| 3218 | --ptr; |
| 3219 | #endif |
| 3220 | n_skip = v - vcol; |
| 3221 | } |
| 3222 | |
| 3223 | /* |
| 3224 | * Adjust for when the inverted text is before the screen, |
| 3225 | * and when the start of the inverted text is before the screen. |
| 3226 | */ |
| 3227 | if (tocol <= vcol) |
| 3228 | fromcol = 0; |
| 3229 | else if (fromcol >= 0 && fromcol < vcol) |
| 3230 | fromcol = vcol; |
| 3231 | |
| 3232 | #ifdef FEAT_LINEBREAK |
| 3233 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3234 | if (wp->w_p_wrap) |
| 3235 | need_showbreak = TRUE; |
| 3236 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3237 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3238 | /* When spell checking a word we need to figure out the start of the |
| 3239 | * word and if it's badly spelled or not. */ |
| 3240 | if (has_spell) |
| 3241 | { |
| 3242 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3243 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3244 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3245 | |
| 3246 | pos = wp->w_cursor; |
| 3247 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3248 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3249 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3250 | |
| 3251 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3252 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3253 | ptr = line + linecol; |
| 3254 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3255 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3256 | { |
| 3257 | /* no bad word found at line start, don't check until end of a |
| 3258 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3259 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3260 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3261 | } |
| 3262 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3263 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3264 | /* bad word found, use attributes until end of word */ |
| 3265 | word_end = wp->w_cursor.col + len + 1; |
| 3266 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3267 | /* Turn index into actual attributes. */ |
| 3268 | if (spell_hlf != HLF_COUNT) |
| 3269 | spell_attr = highlight_attr[spell_hlf]; |
| 3270 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3271 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3272 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3273 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3274 | /* Need to restart syntax highlighting for this line. */ |
| 3275 | if (has_syntax) |
| 3276 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3277 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3278 | } |
| 3279 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | /* |
| 3283 | * Correct highlighting for cursor that can't be disabled. |
| 3284 | * Avoids having to check this for each character. |
| 3285 | */ |
| 3286 | if (fromcol >= 0) |
| 3287 | { |
| 3288 | if (noinvcur) |
| 3289 | { |
| 3290 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3291 | { |
| 3292 | /* highlighting starts at cursor, let it start just after the |
| 3293 | * cursor */ |
| 3294 | fromcol_prev = fromcol; |
| 3295 | fromcol = -1; |
| 3296 | } |
| 3297 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3298 | /* restart highlighting after the cursor */ |
| 3299 | fromcol_prev = wp->w_virtcol; |
| 3300 | } |
| 3301 | if (fromcol >= tocol) |
| 3302 | fromcol = -1; |
| 3303 | } |
| 3304 | |
| 3305 | #ifdef FEAT_SEARCH_EXTRA |
| 3306 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3307 | * Handle highlighting the last used search pattern and matches. |
| 3308 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3309 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3310 | cur = wp->w_match_head; |
| 3311 | shl_flag = FALSE; |
| 3312 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3313 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3314 | if (shl_flag == FALSE) |
| 3315 | { |
| 3316 | shl = &search_hl; |
| 3317 | shl_flag = TRUE; |
| 3318 | } |
| 3319 | else |
| 3320 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3321 | shl->startcol = MAXCOL; |
| 3322 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3323 | shl->attr_cur = 0; |
| 3324 | if (shl->rm.regprog != NULL) |
| 3325 | { |
| 3326 | v = (long)(ptr - line); |
| 3327 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3328 | |
| 3329 | /* Need to get the line again, a multi-line regexp may have made it |
| 3330 | * invalid. */ |
| 3331 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3332 | ptr = line + v; |
| 3333 | |
| 3334 | if (shl->lnum != 0 && shl->lnum <= lnum) |
| 3335 | { |
| 3336 | if (shl->lnum == lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3337 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3338 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3339 | shl->startcol = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3340 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3341 | - shl->rm.startpos[0].lnum) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3342 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3343 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3344 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3345 | /* Highlight one character for an empty match. */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3346 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3347 | { |
| 3348 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3349 | if (has_mbyte && line[shl->endcol] != NUL) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3350 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3351 | else |
| 3352 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3353 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3354 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3355 | if ((long)shl->startcol < v) /* match at leftcol */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3356 | { |
| 3357 | shl->attr_cur = shl->attr; |
| 3358 | search_attr = shl->attr; |
| 3359 | } |
| 3360 | area_highlighting = TRUE; |
| 3361 | } |
| 3362 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3363 | if (shl != &search_hl && cur != NULL) |
| 3364 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3365 | } |
| 3366 | #endif |
| 3367 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3368 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3369 | /* Cursor line highlighting for 'cursorline' in the current window. Not |
| 3370 | * when Visual mode is active, because it's not clear what is selected |
| 3371 | * then. */ |
| 3372 | if (wp->w_p_cul && wp == curwin && lnum == wp->w_cursor.lnum |
| 3373 | && !VIsual_active) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3374 | { |
| 3375 | line_attr = hl_attr(HLF_CUL); |
| 3376 | area_highlighting = TRUE; |
| 3377 | } |
| 3378 | #endif |
| 3379 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3380 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3381 | col = 0; |
| 3382 | #ifdef FEAT_RIGHTLEFT |
| 3383 | if (wp->w_p_rl) |
| 3384 | { |
| 3385 | /* Rightleft window: process the text in the normal direction, but put |
| 3386 | * it in current_ScreenLine[] from right to left. Start at the |
| 3387 | * rightmost column of the window. */ |
| 3388 | col = W_WIDTH(wp) - 1; |
| 3389 | off += col; |
| 3390 | } |
| 3391 | #endif |
| 3392 | |
| 3393 | /* |
| 3394 | * Repeat for the whole displayed line. |
| 3395 | */ |
| 3396 | for (;;) |
| 3397 | { |
| 3398 | /* Skip this quickly when working on the text. */ |
| 3399 | if (draw_state != WL_LINE) |
| 3400 | { |
| 3401 | #ifdef FEAT_CMDWIN |
| 3402 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3403 | { |
| 3404 | draw_state = WL_CMDLINE; |
| 3405 | if (cmdwin_type != 0 && wp == curwin) |
| 3406 | { |
| 3407 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3408 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3409 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3410 | char_attr = hl_attr(HLF_AT); |
| 3411 | } |
| 3412 | } |
| 3413 | #endif |
| 3414 | |
| 3415 | #ifdef FEAT_FOLDING |
| 3416 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3417 | { |
| 3418 | draw_state = WL_FOLD; |
| 3419 | if (wp->w_p_fdc > 0) |
| 3420 | { |
| 3421 | /* Draw the 'foldcolumn'. */ |
| 3422 | fill_foldcolumn(extra, wp, FALSE, lnum); |
| 3423 | n_extra = wp->w_p_fdc; |
| 3424 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3425 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3426 | c_extra = NUL; |
| 3427 | char_attr = hl_attr(HLF_FC); |
| 3428 | } |
| 3429 | } |
| 3430 | #endif |
| 3431 | |
| 3432 | #ifdef FEAT_SIGNS |
| 3433 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3434 | { |
| 3435 | draw_state = WL_SIGN; |
| 3436 | /* Show the sign column when there are any signs in this |
| 3437 | * buffer or when using Netbeans. */ |
| 3438 | if (draw_signcolumn(wp) |
| 3439 | # ifdef FEAT_DIFF |
| 3440 | && filler_todo <= 0 |
| 3441 | # endif |
| 3442 | ) |
| 3443 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3444 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3445 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3446 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3447 | # endif |
| 3448 | |
| 3449 | /* Draw two cells with the sign value or blank. */ |
| 3450 | c_extra = ' '; |
| 3451 | char_attr = hl_attr(HLF_SC); |
| 3452 | n_extra = 2; |
| 3453 | |
| 3454 | if (row == startrow) |
| 3455 | { |
| 3456 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3457 | SIGN_TEXT); |
| 3458 | # ifdef FEAT_SIGN_ICONS |
| 3459 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3460 | SIGN_ICON); |
| 3461 | if (gui.in_use && icon_sign != 0) |
| 3462 | { |
| 3463 | /* Use the image in this position. */ |
| 3464 | c_extra = SIGN_BYTE; |
| 3465 | # ifdef FEAT_NETBEANS_INTG |
| 3466 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3467 | c_extra = MULTISIGN_BYTE; |
| 3468 | # endif |
| 3469 | char_attr = icon_sign; |
| 3470 | } |
| 3471 | else |
| 3472 | # endif |
| 3473 | if (text_sign != 0) |
| 3474 | { |
| 3475 | p_extra = sign_get_text(text_sign); |
| 3476 | if (p_extra != NULL) |
| 3477 | { |
| 3478 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3479 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3480 | } |
| 3481 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3482 | } |
| 3483 | } |
| 3484 | } |
| 3485 | } |
| 3486 | #endif |
| 3487 | |
| 3488 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3489 | { |
| 3490 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3491 | /* Display the absolute or relative line number. After the |
| 3492 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3493 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3494 | && (row == startrow |
| 3495 | #ifdef FEAT_DIFF |
| 3496 | + filler_lines |
| 3497 | #endif |
| 3498 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3499 | { |
| 3500 | /* Draw the line number (empty space after wrapping). */ |
| 3501 | if (row == startrow |
| 3502 | #ifdef FEAT_DIFF |
| 3503 | + filler_lines |
| 3504 | #endif |
| 3505 | ) |
| 3506 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3507 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3508 | char *fmt = "%*ld "; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3509 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3510 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 3511 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3512 | num = (long)lnum; |
| 3513 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3514 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3515 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3516 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3517 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3518 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3519 | /* 'number' + 'relativenumber' */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3520 | num = lnum; |
| 3521 | fmt = "%-*ld "; |
| 3522 | } |
| 3523 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3524 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3525 | sprintf((char *)extra, fmt, |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3526 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3527 | if (wp->w_skipcol > 0) |
| 3528 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3529 | *p_extra = '-'; |
| 3530 | #ifdef FEAT_RIGHTLEFT |
| 3531 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3532 | rl_mirror(extra); |
| 3533 | #endif |
| 3534 | p_extra = extra; |
| 3535 | c_extra = NUL; |
| 3536 | } |
| 3537 | else |
| 3538 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3539 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3540 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3541 | #ifdef FEAT_SYN_HL |
| 3542 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3543 | * the current line differently. |
| 3544 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3545 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3546 | if (((wp->w_p_cul && wp == curwin) || wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3547 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3548 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3549 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3550 | } |
| 3551 | } |
| 3552 | |
| 3553 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3554 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3555 | { |
| 3556 | draw_state = WL_SBR; |
| 3557 | # ifdef FEAT_DIFF |
| 3558 | if (filler_todo > 0) |
| 3559 | { |
| 3560 | /* Draw "deleted" diff line(s). */ |
| 3561 | if (char2cells(fill_diff) > 1) |
| 3562 | c_extra = '-'; |
| 3563 | else |
| 3564 | c_extra = fill_diff; |
| 3565 | # ifdef FEAT_RIGHTLEFT |
| 3566 | if (wp->w_p_rl) |
| 3567 | n_extra = col + 1; |
| 3568 | else |
| 3569 | # endif |
| 3570 | n_extra = W_WIDTH(wp) - col; |
| 3571 | char_attr = hl_attr(HLF_DED); |
| 3572 | } |
| 3573 | # endif |
| 3574 | # ifdef FEAT_LINEBREAK |
| 3575 | if (*p_sbr != NUL && need_showbreak) |
| 3576 | { |
| 3577 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3578 | p_extra = p_sbr; |
| 3579 | c_extra = NUL; |
| 3580 | n_extra = (int)STRLEN(p_sbr); |
| 3581 | char_attr = hl_attr(HLF_AT); |
| 3582 | need_showbreak = FALSE; |
| 3583 | /* Correct end of highlighted area for 'showbreak', |
| 3584 | * required when 'linebreak' is also set. */ |
| 3585 | if (tocol == vcol) |
| 3586 | tocol += n_extra; |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3587 | #ifdef FEAT_SYN_HL |
| 3588 | /* combine 'showbreak' with 'cursorline' */ |
| 3589 | if (wp->w_p_cul && wp == curwin |
| 3590 | && lnum == wp->w_cursor.lnum) |
| 3591 | char_attr = hl_combine_attr(char_attr, HLF_CLN); |
| 3592 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3593 | } |
| 3594 | # endif |
| 3595 | } |
| 3596 | #endif |
| 3597 | |
| 3598 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3599 | { |
| 3600 | draw_state = WL_LINE; |
| 3601 | if (saved_n_extra) |
| 3602 | { |
| 3603 | /* Continue item from end of wrapped line. */ |
| 3604 | n_extra = saved_n_extra; |
| 3605 | c_extra = saved_c_extra; |
| 3606 | p_extra = saved_p_extra; |
| 3607 | char_attr = saved_char_attr; |
| 3608 | } |
| 3609 | else |
| 3610 | char_attr = 0; |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3615 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3616 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3617 | #ifdef FEAT_DIFF |
| 3618 | && filler_todo <= 0 |
| 3619 | #endif |
| 3620 | ) |
| 3621 | { |
| 3622 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3623 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3624 | /* Pretend we have finished updating the window. Except when |
| 3625 | * 'cursorcolumn' is set. */ |
| 3626 | #ifdef FEAT_SYN_HL |
| 3627 | if (wp->w_p_cuc) |
| 3628 | row = wp->w_cline_row + wp->w_cline_height; |
| 3629 | else |
| 3630 | #endif |
| 3631 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3632 | break; |
| 3633 | } |
| 3634 | |
| 3635 | if (draw_state == WL_LINE && area_highlighting) |
| 3636 | { |
| 3637 | /* handle Visual or match highlighting in this line */ |
| 3638 | if (vcol == fromcol |
| 3639 | #ifdef FEAT_MBYTE |
| 3640 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3641 | && (*mb_ptr2cells)(ptr) > 1) |
| 3642 | #endif |
| 3643 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3644 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3645 | && vcol < tocol)) |
| 3646 | area_attr = attr; /* start highlighting */ |
| 3647 | else if (area_attr != 0 |
| 3648 | && (vcol == tocol |
| 3649 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3650 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3651 | |
| 3652 | #ifdef FEAT_SEARCH_EXTRA |
| 3653 | if (!n_extra) |
| 3654 | { |
| 3655 | /* |
| 3656 | * Check for start/end of search pattern match. |
| 3657 | * After end, check for start/end of next match. |
| 3658 | * When another match, have to check for start again. |
| 3659 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3660 | * Do this for 'search_hl' and the match list (ordered by |
| 3661 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3662 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3663 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3664 | cur = wp->w_match_head; |
| 3665 | shl_flag = FALSE; |
| 3666 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3667 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3668 | if (shl_flag == FALSE |
| 3669 | && ((cur != NULL |
| 3670 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3671 | || cur == NULL)) |
| 3672 | { |
| 3673 | shl = &search_hl; |
| 3674 | shl_flag = TRUE; |
| 3675 | } |
| 3676 | else |
| 3677 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3678 | while (shl->rm.regprog != NULL) |
| 3679 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3680 | if (shl->startcol != MAXCOL |
| 3681 | && v >= (long)shl->startcol |
| 3682 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3683 | { |
| 3684 | shl->attr_cur = shl->attr; |
| 3685 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3686 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3687 | { |
| 3688 | shl->attr_cur = 0; |
| 3689 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3690 | next_search_hl(wp, shl, lnum, (colnr_T)v); |
| 3691 | |
| 3692 | /* Need to get the line again, a multi-line regexp |
| 3693 | * may have made it invalid. */ |
| 3694 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3695 | ptr = line + v; |
| 3696 | |
| 3697 | if (shl->lnum == lnum) |
| 3698 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3699 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3700 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3701 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3702 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3703 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3704 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3705 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3706 | { |
| 3707 | /* highlight empty match, try again after |
| 3708 | * it */ |
| 3709 | #ifdef FEAT_MBYTE |
| 3710 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3711 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3712 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3713 | else |
| 3714 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3715 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | /* Loop to check if the match starts at the |
| 3719 | * current position */ |
| 3720 | continue; |
| 3721 | } |
| 3722 | } |
| 3723 | break; |
| 3724 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3725 | if (shl != &search_hl && cur != NULL) |
| 3726 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3727 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3728 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3729 | /* Use attributes from match with highest priority among |
| 3730 | * 'search_hl' and the match list. */ |
| 3731 | search_attr = search_hl.attr_cur; |
| 3732 | cur = wp->w_match_head; |
| 3733 | shl_flag = FALSE; |
| 3734 | while (cur != NULL || shl_flag == FALSE) |
| 3735 | { |
| 3736 | if (shl_flag == FALSE |
| 3737 | && ((cur != NULL |
| 3738 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3739 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3740 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3741 | shl = &search_hl; |
| 3742 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3743 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3744 | else |
| 3745 | shl = &cur->hl; |
| 3746 | if (shl->attr_cur != 0) |
| 3747 | search_attr = shl->attr_cur; |
| 3748 | if (shl != &search_hl && cur != NULL) |
| 3749 | cur = cur->next; |
| 3750 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3751 | } |
| 3752 | #endif |
| 3753 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3754 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3755 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3756 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3757 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 3758 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3759 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 3760 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 3761 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3762 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3763 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3764 | } |
| 3765 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3766 | |
| 3767 | /* Decide which of the highlight attributes to use. */ |
| 3768 | attr_pri = TRUE; |
| 3769 | if (area_attr != 0) |
| 3770 | char_attr = area_attr; |
| 3771 | else if (search_attr != 0) |
| 3772 | char_attr = search_attr; |
| 3773 | #ifdef LINE_ATTR |
| 3774 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 3775 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 3776 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 3777 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 3778 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3779 | char_attr = line_attr; |
| 3780 | #endif |
| 3781 | else |
| 3782 | { |
| 3783 | attr_pri = FALSE; |
| 3784 | #ifdef FEAT_SYN_HL |
| 3785 | if (has_syntax) |
| 3786 | char_attr = syntax_attr; |
| 3787 | else |
| 3788 | #endif |
| 3789 | char_attr = 0; |
| 3790 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | /* |
| 3794 | * Get the next character to put on the screen. |
| 3795 | */ |
| 3796 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3797 | * The "p_extra" points to the extra stuff that is inserted to |
| 3798 | * represent special characters (non-printable stuff) and other |
| 3799 | * things. When all characters are the same, c_extra is used. |
| 3800 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 3801 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3802 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 3803 | */ |
| 3804 | if (n_extra > 0) |
| 3805 | { |
| 3806 | if (c_extra != NUL) |
| 3807 | { |
| 3808 | c = c_extra; |
| 3809 | #ifdef FEAT_MBYTE |
| 3810 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 3811 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 3812 | { |
| 3813 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3814 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3815 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3816 | } |
| 3817 | else |
| 3818 | mb_utf8 = FALSE; |
| 3819 | #endif |
| 3820 | } |
| 3821 | else |
| 3822 | { |
| 3823 | c = *p_extra; |
| 3824 | #ifdef FEAT_MBYTE |
| 3825 | if (has_mbyte) |
| 3826 | { |
| 3827 | mb_c = c; |
| 3828 | if (enc_utf8) |
| 3829 | { |
| 3830 | /* If the UTF-8 character is more than one byte: |
| 3831 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3832 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3833 | mb_utf8 = FALSE; |
| 3834 | if (mb_l > n_extra) |
| 3835 | mb_l = 1; |
| 3836 | else if (mb_l > 1) |
| 3837 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3838 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3839 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3840 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | else |
| 3844 | { |
| 3845 | /* if this is a DBCS character, put it in "mb_c" */ |
| 3846 | mb_l = MB_BYTE2LEN(c); |
| 3847 | if (mb_l >= n_extra) |
| 3848 | mb_l = 1; |
| 3849 | else if (mb_l > 1) |
| 3850 | mb_c = (c << 8) + p_extra[1]; |
| 3851 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3852 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3853 | mb_l = 1; |
| 3854 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3855 | /* If a double-width char doesn't fit display a '>' in the |
| 3856 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3857 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3858 | # ifdef FEAT_RIGHTLEFT |
| 3859 | wp->w_p_rl ? (col <= 0) : |
| 3860 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3861 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3862 | && (*mb_char2cells)(mb_c) == 2) |
| 3863 | { |
| 3864 | c = '>'; |
| 3865 | mb_c = c; |
| 3866 | mb_l = 1; |
| 3867 | mb_utf8 = FALSE; |
| 3868 | multi_attr = hl_attr(HLF_AT); |
| 3869 | /* put the pointer back to output the double-width |
| 3870 | * character at the start of the next line. */ |
| 3871 | ++n_extra; |
| 3872 | --p_extra; |
| 3873 | } |
| 3874 | else |
| 3875 | { |
| 3876 | n_extra -= mb_l - 1; |
| 3877 | p_extra += mb_l - 1; |
| 3878 | } |
| 3879 | } |
| 3880 | #endif |
| 3881 | ++p_extra; |
| 3882 | } |
| 3883 | --n_extra; |
| 3884 | } |
| 3885 | else |
| 3886 | { |
| 3887 | /* |
| 3888 | * Get a character from the line itself. |
| 3889 | */ |
| 3890 | c = *ptr; |
| 3891 | #ifdef FEAT_MBYTE |
| 3892 | if (has_mbyte) |
| 3893 | { |
| 3894 | mb_c = c; |
| 3895 | if (enc_utf8) |
| 3896 | { |
| 3897 | /* If the UTF-8 character is more than one byte: Decode it |
| 3898 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3899 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3900 | mb_utf8 = FALSE; |
| 3901 | if (mb_l > 1) |
| 3902 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3903 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3904 | /* Overlong encoded ASCII or ASCII with composing char |
| 3905 | * is displayed normally, except a NUL. */ |
| 3906 | if (mb_c < 0x80) |
| 3907 | c = mb_c; |
| 3908 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3909 | |
| 3910 | /* At start of the line we can have a composing char. |
| 3911 | * Draw it as a space with a composing char. */ |
| 3912 | if (utf_iscomposing(mb_c)) |
| 3913 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3914 | int i; |
| 3915 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3916 | for (i = Screen_mco - 1; i > 0; --i) |
| 3917 | u8cc[i] = u8cc[i - 1]; |
| 3918 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 3919 | mb_c = ' '; |
| 3920 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | if ((mb_l == 1 && c >= 0x80) |
| 3924 | || (mb_l >= 1 && mb_c == 0) |
| 3925 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3926 | # ifdef UNICODE16 |
| 3927 | || mb_c >= 0x10000 |
| 3928 | # endif |
| 3929 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3930 | { |
| 3931 | /* |
| 3932 | * Illegal UTF-8 byte: display as <xx>. |
| 3933 | * Non-BMP character : display as ? or fullwidth ?. |
| 3934 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3935 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3936 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3937 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3938 | { |
| 3939 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3940 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3941 | if (wp->w_p_rl) /* reverse */ |
| 3942 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3943 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3944 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3945 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3946 | else if (utf_char2cells(mb_c) != 2) |
| 3947 | STRCPY(extra, "?"); |
| 3948 | else |
| 3949 | /* 0xff1f in UTF-8: full-width '?' */ |
| 3950 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 3951 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3952 | |
| 3953 | p_extra = extra; |
| 3954 | c = *p_extra; |
| 3955 | mb_c = mb_ptr2char_adv(&p_extra); |
| 3956 | mb_utf8 = (c >= 0x80); |
| 3957 | n_extra = (int)STRLEN(p_extra); |
| 3958 | c_extra = NUL; |
| 3959 | if (area_attr == 0 && search_attr == 0) |
| 3960 | { |
| 3961 | n_attr = n_extra + 1; |
| 3962 | extra_attr = hl_attr(HLF_8); |
| 3963 | saved_attr2 = char_attr; /* save current attr */ |
| 3964 | } |
| 3965 | } |
| 3966 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 3967 | mb_l = 1; |
| 3968 | #ifdef FEAT_ARABIC |
| 3969 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 3970 | { |
| 3971 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3972 | int pc, pc1, nc; |
| 3973 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3974 | |
| 3975 | /* The idea of what is the previous and next |
| 3976 | * character depends on 'rightleft'. */ |
| 3977 | if (wp->w_p_rl) |
| 3978 | { |
| 3979 | pc = prev_c; |
| 3980 | pc1 = prev_c1; |
| 3981 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3982 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3983 | } |
| 3984 | else |
| 3985 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3986 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3987 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3988 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3989 | } |
| 3990 | prev_c = mb_c; |
| 3991 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3992 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3993 | } |
| 3994 | else |
| 3995 | prev_c = mb_c; |
| 3996 | #endif |
| 3997 | } |
| 3998 | else /* enc_dbcs */ |
| 3999 | { |
| 4000 | mb_l = MB_BYTE2LEN(c); |
| 4001 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4002 | mb_l = 1; |
| 4003 | else if (mb_l > 1) |
| 4004 | { |
| 4005 | /* We assume a second byte below 32 is illegal. |
| 4006 | * Hopefully this is OK for all double-byte encodings! |
| 4007 | */ |
| 4008 | if (ptr[1] >= 32) |
| 4009 | mb_c = (c << 8) + ptr[1]; |
| 4010 | else |
| 4011 | { |
| 4012 | if (ptr[1] == NUL) |
| 4013 | { |
| 4014 | /* head byte at end of line */ |
| 4015 | mb_l = 1; |
| 4016 | transchar_nonprint(extra, c); |
| 4017 | } |
| 4018 | else |
| 4019 | { |
| 4020 | /* illegal tail byte */ |
| 4021 | mb_l = 2; |
| 4022 | STRCPY(extra, "XX"); |
| 4023 | } |
| 4024 | p_extra = extra; |
| 4025 | n_extra = (int)STRLEN(extra) - 1; |
| 4026 | c_extra = NUL; |
| 4027 | c = *p_extra++; |
| 4028 | if (area_attr == 0 && search_attr == 0) |
| 4029 | { |
| 4030 | n_attr = n_extra + 1; |
| 4031 | extra_attr = hl_attr(HLF_8); |
| 4032 | saved_attr2 = char_attr; /* save current attr */ |
| 4033 | } |
| 4034 | mb_c = c; |
| 4035 | } |
| 4036 | } |
| 4037 | } |
| 4038 | /* If a double-width char doesn't fit display a '>' in the |
| 4039 | * last column; the character is displayed at the start of the |
| 4040 | * next line. */ |
| 4041 | if (( |
| 4042 | # ifdef FEAT_RIGHTLEFT |
| 4043 | wp->w_p_rl ? (col <= 0) : |
| 4044 | # endif |
| 4045 | (col >= W_WIDTH(wp) - 1)) |
| 4046 | && (*mb_char2cells)(mb_c) == 2) |
| 4047 | { |
| 4048 | c = '>'; |
| 4049 | mb_c = c; |
| 4050 | mb_utf8 = FALSE; |
| 4051 | mb_l = 1; |
| 4052 | multi_attr = hl_attr(HLF_AT); |
| 4053 | /* Put pointer back so that the character will be |
| 4054 | * displayed at the start of the next line. */ |
| 4055 | --ptr; |
| 4056 | } |
| 4057 | else if (*ptr != NUL) |
| 4058 | ptr += mb_l - 1; |
| 4059 | |
| 4060 | /* 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] | 4061 | * a '<' in the first column. Don't do this for unprintable |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4062 | * characters. */ |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4063 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4064 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4065 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4066 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4067 | c = ' '; |
| 4068 | if (area_attr == 0 && search_attr == 0) |
| 4069 | { |
| 4070 | n_attr = n_extra + 1; |
| 4071 | extra_attr = hl_attr(HLF_AT); |
| 4072 | saved_attr2 = char_attr; /* save current attr */ |
| 4073 | } |
| 4074 | mb_c = c; |
| 4075 | mb_utf8 = FALSE; |
| 4076 | mb_l = 1; |
| 4077 | } |
| 4078 | |
| 4079 | } |
| 4080 | #endif |
| 4081 | ++ptr; |
| 4082 | |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4083 | /* 'list' : change char 160 to lcs_nbsp. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4084 | if (wp->w_p_list && (c == 160 |
| 4085 | #ifdef FEAT_MBYTE |
| 4086 | || (mb_utf8 && mb_c == 160) |
| 4087 | #endif |
| 4088 | ) && lcs_nbsp) |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4089 | { |
| 4090 | c = lcs_nbsp; |
| 4091 | if (area_attr == 0 && search_attr == 0) |
| 4092 | { |
| 4093 | n_attr = 1; |
| 4094 | extra_attr = hl_attr(HLF_8); |
| 4095 | saved_attr2 = char_attr; /* save current attr */ |
| 4096 | } |
| 4097 | #ifdef FEAT_MBYTE |
| 4098 | mb_c = c; |
| 4099 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4100 | { |
| 4101 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4102 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4103 | c = 0xc0; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 4104 | } |
| 4105 | else |
| 4106 | mb_utf8 = FALSE; |
| 4107 | #endif |
| 4108 | } |
| 4109 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4110 | if (extra_check) |
| 4111 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4112 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4113 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4114 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4115 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4116 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4117 | /* Get syntax attribute, unless still at the start of the line |
| 4118 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4119 | v = (long)(ptr - line); |
| 4120 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4121 | { |
| 4122 | /* Get the syntax attribute for the character. If there |
| 4123 | * is an error, disable syntax highlighting. */ |
| 4124 | save_did_emsg = did_emsg; |
| 4125 | did_emsg = FALSE; |
| 4126 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4127 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4128 | # ifdef FEAT_SPELL |
| 4129 | has_spell ? &can_spell : |
| 4130 | # endif |
| 4131 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4132 | |
| 4133 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4134 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4135 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4136 | has_syntax = FALSE; |
| 4137 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4138 | else |
| 4139 | did_emsg = save_did_emsg; |
| 4140 | |
| 4141 | /* Need to get the line again, a multi-line regexp may |
| 4142 | * have made it invalid. */ |
| 4143 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4144 | ptr = line + v; |
| 4145 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4146 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4147 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4148 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4149 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4150 | # ifdef FEAT_CONCEAL |
| 4151 | /* no concealing past the end of the line, it interferes |
| 4152 | * with line highlighting */ |
| 4153 | if (c == NUL) |
| 4154 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4155 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4156 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4157 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4158 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4159 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4160 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4161 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4162 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4163 | * Only do this when there is no syntax highlighting, the |
| 4164 | * @Spell cluster is not used or the current syntax item |
| 4165 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4166 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4167 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4168 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4169 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4170 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4171 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4172 | # endif |
| 4173 | if (c != 0 && ( |
| 4174 | # ifdef FEAT_SYN_HL |
| 4175 | !has_syntax || |
| 4176 | # endif |
| 4177 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4178 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4179 | char_u *prev_ptr, *p; |
| 4180 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4181 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4182 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4183 | if (has_mbyte) |
| 4184 | { |
| 4185 | prev_ptr = ptr - mb_l; |
| 4186 | v -= mb_l - 1; |
| 4187 | } |
| 4188 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4189 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4190 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4191 | |
| 4192 | /* Use nextline[] if possible, it has the start of the |
| 4193 | * next line concatenated. */ |
| 4194 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4195 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4196 | else |
| 4197 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4198 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4199 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4200 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4201 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4202 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4203 | /* In Insert mode only highlight a word that |
| 4204 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4205 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4206 | && (State & INSERT) != 0 |
| 4207 | && wp->w_cursor.lnum == lnum |
| 4208 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4209 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4210 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4211 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4212 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4213 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4214 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4215 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4216 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4217 | && (p - nextline) + len > nextline_idx) |
| 4218 | { |
| 4219 | /* Remember that the good word continues at the |
| 4220 | * start of the next line. */ |
| 4221 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4222 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4223 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4224 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4225 | /* Turn index into actual attributes. */ |
| 4226 | if (spell_hlf != HLF_COUNT) |
| 4227 | spell_attr = highlight_attr[spell_hlf]; |
| 4228 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4229 | if (cap_col > 0) |
| 4230 | { |
| 4231 | if (p != prev_ptr |
| 4232 | && (p - nextline) + cap_col >= nextline_idx) |
| 4233 | { |
| 4234 | /* Remember that the word in the next line |
| 4235 | * must start with a capital. */ |
| 4236 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4237 | cap_col = (int)((p - nextline) + cap_col |
| 4238 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4239 | } |
| 4240 | else |
| 4241 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4242 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4243 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4244 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4245 | } |
| 4246 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4247 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4248 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4249 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4250 | else |
| 4251 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4252 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4253 | #endif |
| 4254 | #ifdef FEAT_LINEBREAK |
| 4255 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4256 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4257 | */ |
| 4258 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4259 | && !wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4260 | { |
| 4261 | n_extra = win_lbr_chartabsize(wp, ptr - ( |
| 4262 | # ifdef FEAT_MBYTE |
| 4263 | has_mbyte ? mb_l : |
| 4264 | # endif |
| 4265 | 1), (colnr_T)vcol, NULL) - 1; |
| 4266 | c_extra = ' '; |
| 4267 | if (vim_iswhite(c)) |
| 4268 | c = ' '; |
| 4269 | } |
| 4270 | #endif |
| 4271 | |
| 4272 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4273 | { |
| 4274 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4275 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4276 | { |
| 4277 | n_attr = 1; |
| 4278 | extra_attr = hl_attr(HLF_8); |
| 4279 | saved_attr2 = char_attr; /* save current attr */ |
| 4280 | } |
| 4281 | #ifdef FEAT_MBYTE |
| 4282 | mb_c = c; |
| 4283 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4284 | { |
| 4285 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4286 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4287 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4288 | } |
| 4289 | else |
| 4290 | mb_utf8 = FALSE; |
| 4291 | #endif |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | /* |
| 4296 | * Handling of non-printable characters. |
| 4297 | */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4298 | if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4299 | { |
| 4300 | /* |
| 4301 | * when getting a character from the file, we may have to |
| 4302 | * turn it into something else on the way to putting it |
| 4303 | * into "ScreenLines". |
| 4304 | */ |
| 4305 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4306 | { |
| 4307 | /* tab amount depends on current column */ |
| 4308 | n_extra = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4309 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4310 | #ifdef FEAT_CONCEAL |
| 4311 | /* Tab alignment should be identical regardless of |
| 4312 | * 'conceallevel' value. So tab compensates of all |
| 4313 | * previous concealed characters, and thus resets vcol_off |
| 4314 | * and boguscols accumulated so far in the line. Note that |
| 4315 | * the tab can be longer than 'tabstop' when there |
| 4316 | * are concealed characters. */ |
| 4317 | n_extra += vcol_off; |
| 4318 | vcol -= vcol_off; |
| 4319 | vcol_off = 0; |
| 4320 | col -= boguscols; |
| 4321 | boguscols = 0; |
| 4322 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4323 | #ifdef FEAT_MBYTE |
| 4324 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4325 | #endif |
| 4326 | if (wp->w_p_list) |
| 4327 | { |
| 4328 | c = lcs_tab1; |
| 4329 | c_extra = lcs_tab2; |
| 4330 | n_attr = n_extra + 1; |
| 4331 | extra_attr = hl_attr(HLF_8); |
| 4332 | saved_attr2 = char_attr; /* save current attr */ |
| 4333 | #ifdef FEAT_MBYTE |
| 4334 | mb_c = c; |
| 4335 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4336 | { |
| 4337 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4338 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4339 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4340 | } |
| 4341 | #endif |
| 4342 | } |
| 4343 | else |
| 4344 | { |
| 4345 | c_extra = ' '; |
| 4346 | c = ' '; |
| 4347 | } |
| 4348 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4349 | else if (c == NUL |
| 4350 | && ((wp->w_p_list && lcs_eol > 0) |
| 4351 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4352 | && tocol > vcol |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4353 | #ifdef FEAT_VISUAL |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4354 | && VIsual_mode != Ctrl_V |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 4355 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4356 | && ( |
| 4357 | # ifdef FEAT_RIGHTLEFT |
| 4358 | wp->w_p_rl ? (col >= 0) : |
| 4359 | # endif |
| 4360 | (col < W_WIDTH(wp))) |
| 4361 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4362 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4363 | && (colnr_T)vcol == wp->w_virtcol))) |
| 4364 | && lcs_eol_one >= 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4365 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4366 | /* Display a '$' after the line or highlight an extra |
| 4367 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4368 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4369 | /* For a diff line the highlighting continues after the |
| 4370 | * "$". */ |
| 4371 | if ( |
| 4372 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4373 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4374 | # ifdef LINE_ATTR |
| 4375 | && |
| 4376 | # endif |
| 4377 | # endif |
| 4378 | # ifdef LINE_ATTR |
| 4379 | line_attr == 0 |
| 4380 | # endif |
| 4381 | ) |
| 4382 | #endif |
| 4383 | { |
| 4384 | #ifdef FEAT_VIRTUALEDIT |
| 4385 | /* In virtualedit, visual selections may extend |
| 4386 | * beyond end of line. */ |
| 4387 | if (area_highlighting && virtual_active() |
| 4388 | && tocol != MAXCOL && vcol < tocol) |
| 4389 | n_extra = 0; |
| 4390 | else |
| 4391 | #endif |
| 4392 | { |
| 4393 | p_extra = at_end_str; |
| 4394 | n_extra = 1; |
| 4395 | c_extra = NUL; |
| 4396 | } |
| 4397 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4398 | if (wp->w_p_list) |
| 4399 | c = lcs_eol; |
| 4400 | else |
| 4401 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4402 | lcs_eol_one = -1; |
| 4403 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4404 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4405 | { |
| 4406 | extra_attr = hl_attr(HLF_AT); |
| 4407 | n_attr = 1; |
| 4408 | } |
| 4409 | #ifdef FEAT_MBYTE |
| 4410 | mb_c = c; |
| 4411 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4412 | { |
| 4413 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4414 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4415 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4416 | } |
| 4417 | else |
| 4418 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4419 | #endif |
| 4420 | } |
| 4421 | else if (c != NUL) |
| 4422 | { |
| 4423 | p_extra = transchar(c); |
| 4424 | #ifdef FEAT_RIGHTLEFT |
| 4425 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4426 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4427 | #endif |
| 4428 | n_extra = byte2cells(c) - 1; |
| 4429 | c_extra = NUL; |
| 4430 | c = *p_extra++; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4431 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4432 | { |
| 4433 | n_attr = n_extra + 1; |
| 4434 | extra_attr = hl_attr(HLF_8); |
| 4435 | saved_attr2 = char_attr; /* save current attr */ |
| 4436 | } |
| 4437 | #ifdef FEAT_MBYTE |
| 4438 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4439 | #endif |
| 4440 | } |
| 4441 | #ifdef FEAT_VIRTUALEDIT |
| 4442 | else if (VIsual_active |
| 4443 | && (VIsual_mode == Ctrl_V |
| 4444 | || VIsual_mode == 'v') |
| 4445 | && virtual_active() |
| 4446 | && tocol != MAXCOL |
| 4447 | && vcol < tocol |
| 4448 | && ( |
| 4449 | # ifdef FEAT_RIGHTLEFT |
| 4450 | wp->w_p_rl ? (col >= 0) : |
| 4451 | # endif |
| 4452 | (col < W_WIDTH(wp)))) |
| 4453 | { |
| 4454 | c = ' '; |
| 4455 | --ptr; /* put it back at the NUL */ |
| 4456 | } |
| 4457 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4458 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4459 | else if (( |
| 4460 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4461 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4462 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4463 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4464 | ) && ( |
| 4465 | # ifdef FEAT_RIGHTLEFT |
| 4466 | wp->w_p_rl ? (col >= 0) : |
| 4467 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4468 | (col |
| 4469 | # ifdef FEAT_CONCEAL |
| 4470 | - boguscols |
| 4471 | # endif |
| 4472 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4473 | { |
| 4474 | /* Highlight until the right side of the window */ |
| 4475 | c = ' '; |
| 4476 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4477 | |
| 4478 | /* Remember we do the char for line highlighting. */ |
| 4479 | ++did_line_attr; |
| 4480 | |
| 4481 | /* don't do search HL for the rest of the line */ |
| 4482 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4483 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4484 | # ifdef FEAT_DIFF |
| 4485 | if (diff_hlf == HLF_TXD) |
| 4486 | { |
| 4487 | diff_hlf = HLF_CHD; |
| 4488 | if (attr == 0 || char_attr != attr) |
| 4489 | char_attr = hl_attr(diff_hlf); |
| 4490 | } |
| 4491 | # endif |
| 4492 | } |
| 4493 | #endif |
| 4494 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4495 | |
| 4496 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4497 | if ( wp->w_p_cole > 0 |
| 4498 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
| 4499 | conceal_cursor_line(wp)) |
Bram Moolenaar | f70e3d6 | 2010-07-24 13:15:07 +0200 | [diff] [blame] | 4500 | && (syntax_flags & HL_CONCEAL) != 0 |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4501 | && !(lnum_in_visual_area |
| 4502 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4503 | { |
| 4504 | char_attr = conceal_attr; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4505 | if (prev_syntax_id != syntax_seqnr |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4506 | && (syn_get_sub_char() != NUL || wp->w_p_cole == 1) |
| 4507 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4508 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4509 | /* First time at this concealed item: display one |
| 4510 | * character. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4511 | if (syn_get_sub_char() != NUL) |
| 4512 | c = syn_get_sub_char(); |
| 4513 | else if (lcs_conceal != NUL) |
| 4514 | c = lcs_conceal; |
| 4515 | else |
| 4516 | c = ' '; |
| 4517 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4518 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4519 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4520 | if (n_extra > 0) |
| 4521 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4522 | vcol += n_extra; |
| 4523 | if (wp->w_p_wrap && n_extra > 0) |
| 4524 | { |
| 4525 | # ifdef FEAT_RIGHTLEFT |
| 4526 | if (wp->w_p_rl) |
| 4527 | { |
| 4528 | col -= n_extra; |
| 4529 | boguscols -= n_extra; |
| 4530 | } |
| 4531 | else |
| 4532 | # endif |
| 4533 | { |
| 4534 | boguscols += n_extra; |
| 4535 | col += n_extra; |
| 4536 | } |
| 4537 | } |
| 4538 | n_extra = 0; |
| 4539 | n_attr = 0; |
| 4540 | } |
| 4541 | else if (n_skip == 0) |
| 4542 | { |
| 4543 | is_concealing = TRUE; |
| 4544 | n_skip = 1; |
| 4545 | } |
| 4546 | # ifdef FEAT_MBYTE |
| 4547 | mb_c = c; |
| 4548 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4549 | { |
| 4550 | mb_utf8 = TRUE; |
| 4551 | u8cc[0] = 0; |
| 4552 | c = 0xc0; |
| 4553 | } |
| 4554 | else |
| 4555 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4556 | # endif |
| 4557 | } |
| 4558 | else |
| 4559 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4560 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4561 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4562 | } |
| 4563 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4566 | #ifdef FEAT_CONCEAL |
| 4567 | /* In the cursor line and we may be concealing characters: correct |
| 4568 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 4569 | if (!did_wcol && draw_state == WL_LINE |
| 4570 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4571 | && conceal_cursor_line(wp) |
| 4572 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 4573 | { |
| 4574 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 4575 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4576 | did_wcol = TRUE; |
| 4577 | } |
| 4578 | #endif |
| 4579 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4580 | /* Don't override visual selection highlighting. */ |
| 4581 | if (n_attr > 0 |
| 4582 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4583 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4584 | char_attr = extra_attr; |
| 4585 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4586 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4587 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4588 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4589 | * im_is_preediting() here. */ |
| 4590 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4591 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4592 | && (State & INSERT) |
| 4593 | && !p_imdisable |
| 4594 | && im_is_preediting() |
| 4595 | && draw_state == WL_LINE) |
| 4596 | { |
| 4597 | colnr_T tcol; |
| 4598 | |
| 4599 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4600 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4601 | else |
| 4602 | tcol = preedit_end_col; |
| 4603 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 4604 | { |
| 4605 | if (feedback_old_attr < 0) |
| 4606 | { |
| 4607 | feedback_col = 0; |
| 4608 | feedback_old_attr = char_attr; |
| 4609 | } |
| 4610 | char_attr = im_get_feedback_attr(feedback_col); |
| 4611 | if (char_attr < 0) |
| 4612 | char_attr = feedback_old_attr; |
| 4613 | feedback_col++; |
| 4614 | } |
| 4615 | else if (feedback_old_attr >= 0) |
| 4616 | { |
| 4617 | char_attr = feedback_old_attr; |
| 4618 | feedback_old_attr = -1; |
| 4619 | feedback_col = 0; |
| 4620 | } |
| 4621 | } |
| 4622 | #endif |
| 4623 | /* |
| 4624 | * Handle the case where we are in column 0 but not on the first |
| 4625 | * character of the line and the user wants us to show us a |
| 4626 | * special character (via 'listchars' option "precedes:<char>". |
| 4627 | */ |
| 4628 | if (lcs_prec_todo != NUL |
| 4629 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 4630 | #ifdef FEAT_DIFF |
| 4631 | && filler_todo <= 0 |
| 4632 | #endif |
| 4633 | && draw_state > WL_NR |
| 4634 | && c != NUL) |
| 4635 | { |
| 4636 | c = lcs_prec; |
| 4637 | lcs_prec_todo = NUL; |
| 4638 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4639 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4640 | { |
| 4641 | /* Double-width character being overwritten by the "precedes" |
| 4642 | * character, need to fill up half the character. */ |
| 4643 | c_extra = MB_FILLER_CHAR; |
| 4644 | n_extra = 1; |
| 4645 | n_attr = 2; |
| 4646 | extra_attr = hl_attr(HLF_AT); |
| 4647 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4648 | mb_c = c; |
| 4649 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4650 | { |
| 4651 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4652 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4653 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4654 | } |
| 4655 | else |
| 4656 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4657 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4658 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4659 | { |
| 4660 | saved_attr3 = char_attr; /* save current attr */ |
| 4661 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 4662 | n_attr3 = 1; |
| 4663 | } |
| 4664 | } |
| 4665 | |
| 4666 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4667 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4668 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4669 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4670 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4671 | || did_line_attr == 1 |
| 4672 | #endif |
| 4673 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4674 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4675 | #ifdef FEAT_SEARCH_EXTRA |
| 4676 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4677 | |
| 4678 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 4679 | 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] | 4680 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4681 | #endif |
| 4682 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4683 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4684 | * highlight match at end of line. If it's beyond the last |
| 4685 | * char on the screen, just overwrite that one (tricky!) Not |
| 4686 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4687 | #ifdef FEAT_SEARCH_EXTRA |
| 4688 | prevcol_hl_flag = FALSE; |
| 4689 | if (prevcol == (long)search_hl.startcol) |
| 4690 | prevcol_hl_flag = TRUE; |
| 4691 | else |
| 4692 | { |
| 4693 | cur = wp->w_match_head; |
| 4694 | while (cur != NULL) |
| 4695 | { |
| 4696 | if (prevcol == (long)cur->hl.startcol) |
| 4697 | { |
| 4698 | prevcol_hl_flag = TRUE; |
| 4699 | break; |
| 4700 | } |
| 4701 | cur = cur->next; |
| 4702 | } |
| 4703 | } |
| 4704 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4705 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4706 | && ((area_attr != 0 && vcol == fromcol |
| 4707 | #ifdef FEAT_VISUAL |
| 4708 | && (VIsual_mode != Ctrl_V |
| 4709 | || lnum == VIsual.lnum |
| 4710 | || lnum == curwin->w_cursor.lnum) |
| 4711 | #endif |
| 4712 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4713 | #ifdef FEAT_SEARCH_EXTRA |
| 4714 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4715 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4716 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4717 | && did_line_attr <= 1 |
| 4718 | # endif |
| 4719 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4720 | #endif |
| 4721 | )) |
| 4722 | { |
| 4723 | int n = 0; |
| 4724 | |
| 4725 | #ifdef FEAT_RIGHTLEFT |
| 4726 | if (wp->w_p_rl) |
| 4727 | { |
| 4728 | if (col < 0) |
| 4729 | n = 1; |
| 4730 | } |
| 4731 | else |
| 4732 | #endif |
| 4733 | { |
| 4734 | if (col >= W_WIDTH(wp)) |
| 4735 | n = -1; |
| 4736 | } |
| 4737 | if (n != 0) |
| 4738 | { |
| 4739 | /* At the window boundary, highlight the last character |
| 4740 | * instead (better than nothing). */ |
| 4741 | off += n; |
| 4742 | col += n; |
| 4743 | } |
| 4744 | else |
| 4745 | { |
| 4746 | /* Add a blank character to highlight. */ |
| 4747 | ScreenLines[off] = ' '; |
| 4748 | #ifdef FEAT_MBYTE |
| 4749 | if (enc_utf8) |
| 4750 | ScreenLinesUC[off] = 0; |
| 4751 | #endif |
| 4752 | } |
| 4753 | #ifdef FEAT_SEARCH_EXTRA |
| 4754 | if (area_attr == 0) |
| 4755 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4756 | /* Use attributes from match with highest priority among |
| 4757 | * 'search_hl' and the match list. */ |
| 4758 | char_attr = search_hl.attr; |
| 4759 | cur = wp->w_match_head; |
| 4760 | shl_flag = FALSE; |
| 4761 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4762 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4763 | if (shl_flag == FALSE |
| 4764 | && ((cur != NULL |
| 4765 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4766 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4767 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4768 | shl = &search_hl; |
| 4769 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4770 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4771 | else |
| 4772 | shl = &cur->hl; |
| 4773 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 4774 | char_attr = shl->attr; |
| 4775 | if (shl != &search_hl && cur != NULL) |
| 4776 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4777 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4778 | } |
| 4779 | #endif |
| 4780 | ScreenAttrs[off] = char_attr; |
| 4781 | #ifdef FEAT_RIGHTLEFT |
| 4782 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4783 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4784 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4785 | --off; |
| 4786 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4787 | else |
| 4788 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4789 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4790 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4791 | ++off; |
| 4792 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4793 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4794 | #ifdef FEAT_SYN_HL |
| 4795 | eol_hl_off = 1; |
| 4796 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4797 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4798 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4799 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4800 | /* |
| 4801 | * At end of the text line. |
| 4802 | */ |
| 4803 | if (c == NUL) |
| 4804 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4805 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4806 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 4807 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 4808 | { |
| 4809 | /* highlight last char after line */ |
| 4810 | --col; |
| 4811 | --off; |
| 4812 | --vcol; |
| 4813 | } |
| 4814 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4815 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 4816 | if (wp->w_p_wrap) |
| 4817 | v = wp->w_skipcol; |
| 4818 | else |
| 4819 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4820 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4821 | /* check if line ends before left margin */ |
| 4822 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 4823 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4824 | #ifdef FEAT_CONCEAL |
| 4825 | /* Get rid of the boguscols now, we want to draw until the right |
| 4826 | * edge for 'cursorcolumn'. */ |
| 4827 | col -= boguscols; |
| 4828 | boguscols = 0; |
| 4829 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4830 | |
| 4831 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4832 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4833 | |
| 4834 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4835 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 4836 | && (int)wp->w_virtcol < |
| 4837 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4838 | && lnum != wp->w_cursor.lnum) |
| 4839 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4840 | # ifdef FEAT_RIGHTLEFT |
| 4841 | && !wp->w_p_rl |
| 4842 | # endif |
| 4843 | ) |
| 4844 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4845 | int rightmost_vcol = 0; |
| 4846 | int i; |
| 4847 | |
| 4848 | if (wp->w_p_cuc) |
| 4849 | rightmost_vcol = wp->w_virtcol; |
| 4850 | if (draw_color_col) |
| 4851 | /* determine rightmost colorcolumn to possibly draw */ |
| 4852 | for (i = 0; color_cols[i] >= 0; ++i) |
| 4853 | if (rightmost_vcol < color_cols[i]) |
| 4854 | rightmost_vcol = color_cols[i]; |
| 4855 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4856 | while (col < W_WIDTH(wp)) |
| 4857 | { |
| 4858 | ScreenLines[off] = ' '; |
| 4859 | #ifdef FEAT_MBYTE |
| 4860 | if (enc_utf8) |
| 4861 | ScreenLinesUC[off] = 0; |
| 4862 | #endif |
| 4863 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 4864 | if (draw_color_col) |
| 4865 | draw_color_col = advance_color_col(VCOL_HLC, |
| 4866 | &color_cols); |
| 4867 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4868 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4869 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4870 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4871 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 4872 | else |
| 4873 | ScreenAttrs[off++] = 0; |
| 4874 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4875 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4876 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4877 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4878 | ++vcol; |
| 4879 | } |
| 4880 | } |
| 4881 | #endif |
| 4882 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4883 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 4884 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4885 | row++; |
| 4886 | |
| 4887 | /* |
| 4888 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 4889 | * updated (saves a call to plines() later). |
| 4890 | */ |
| 4891 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 4892 | { |
| 4893 | curwin->w_cline_row = startrow; |
| 4894 | curwin->w_cline_height = row - startrow; |
| 4895 | #ifdef FEAT_FOLDING |
| 4896 | curwin->w_cline_folded = FALSE; |
| 4897 | #endif |
| 4898 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 4899 | } |
| 4900 | |
| 4901 | break; |
| 4902 | } |
| 4903 | |
| 4904 | /* line continues beyond line end */ |
| 4905 | if (lcs_ext |
| 4906 | && !wp->w_p_wrap |
| 4907 | #ifdef FEAT_DIFF |
| 4908 | && filler_todo <= 0 |
| 4909 | #endif |
| 4910 | && ( |
| 4911 | #ifdef FEAT_RIGHTLEFT |
| 4912 | wp->w_p_rl ? col == 0 : |
| 4913 | #endif |
| 4914 | col == W_WIDTH(wp) - 1) |
| 4915 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 4916 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4917 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 4918 | { |
| 4919 | c = lcs_ext; |
| 4920 | char_attr = hl_attr(HLF_AT); |
| 4921 | #ifdef FEAT_MBYTE |
| 4922 | mb_c = c; |
| 4923 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4924 | { |
| 4925 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4926 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4927 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4928 | } |
| 4929 | else |
| 4930 | mb_utf8 = FALSE; |
| 4931 | #endif |
| 4932 | } |
| 4933 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4934 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4935 | /* advance to the next 'colorcolumn' */ |
| 4936 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4937 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4938 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4939 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4940 | * highlight the cursor position itself. |
| 4941 | * Also highlight the 'colorcolumn' if it is different than |
| 4942 | * 'cursorcolumn' */ |
| 4943 | vcol_save_attr = -1; |
| 4944 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4945 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4946 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4947 | && lnum != wp->w_cursor.lnum) |
| 4948 | { |
| 4949 | vcol_save_attr = char_attr; |
| 4950 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 4951 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 4952 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 4953 | { |
| 4954 | vcol_save_attr = char_attr; |
| 4955 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 4956 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4957 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4958 | #endif |
| 4959 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4960 | /* |
| 4961 | * Store character to be displayed. |
| 4962 | * Skip characters that are left of the screen for 'nowrap'. |
| 4963 | */ |
| 4964 | vcol_prev = vcol; |
| 4965 | if (draw_state < WL_LINE || n_skip <= 0) |
| 4966 | { |
| 4967 | /* |
| 4968 | * Store the character. |
| 4969 | */ |
| 4970 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 4971 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 4972 | { |
| 4973 | /* A double-wide character is: put first halve in left cell. */ |
| 4974 | --off; |
| 4975 | --col; |
| 4976 | } |
| 4977 | #endif |
| 4978 | ScreenLines[off] = c; |
| 4979 | #ifdef FEAT_MBYTE |
| 4980 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 4981 | { |
| 4982 | if ((mb_c & 0xff00) == 0x8e00) |
| 4983 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4984 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 4985 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4986 | else if (enc_utf8) |
| 4987 | { |
| 4988 | if (mb_utf8) |
| 4989 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4990 | int i; |
| 4991 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4992 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4993 | if ((c & 0xff) == 0) |
| 4994 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4995 | for (i = 0; i < Screen_mco; ++i) |
| 4996 | { |
| 4997 | ScreenLinesC[i][off] = u8cc[i]; |
| 4998 | if (u8cc[i] == 0) |
| 4999 | break; |
| 5000 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5001 | } |
| 5002 | else |
| 5003 | ScreenLinesUC[off] = 0; |
| 5004 | } |
| 5005 | if (multi_attr) |
| 5006 | { |
| 5007 | ScreenAttrs[off] = multi_attr; |
| 5008 | multi_attr = 0; |
| 5009 | } |
| 5010 | else |
| 5011 | #endif |
| 5012 | ScreenAttrs[off] = char_attr; |
| 5013 | |
| 5014 | #ifdef FEAT_MBYTE |
| 5015 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5016 | { |
| 5017 | /* Need to fill two screen columns. */ |
| 5018 | ++off; |
| 5019 | ++col; |
| 5020 | if (enc_utf8) |
| 5021 | /* UTF-8: Put a 0 in the second screen char. */ |
| 5022 | ScreenLines[off] = 0; |
| 5023 | else |
| 5024 | /* DBCS: Put second byte in the second screen char. */ |
| 5025 | ScreenLines[off] = mb_c & 0xff; |
| 5026 | ++vcol; |
| 5027 | /* When "tocol" is halfway a character, set it to the end of |
| 5028 | * the character, otherwise highlighting won't stop. */ |
| 5029 | if (tocol == vcol) |
| 5030 | ++tocol; |
| 5031 | #ifdef FEAT_RIGHTLEFT |
| 5032 | if (wp->w_p_rl) |
| 5033 | { |
| 5034 | /* now it's time to backup one cell */ |
| 5035 | --off; |
| 5036 | --col; |
| 5037 | } |
| 5038 | #endif |
| 5039 | } |
| 5040 | #endif |
| 5041 | #ifdef FEAT_RIGHTLEFT |
| 5042 | if (wp->w_p_rl) |
| 5043 | { |
| 5044 | --off; |
| 5045 | --col; |
| 5046 | } |
| 5047 | else |
| 5048 | #endif |
| 5049 | { |
| 5050 | ++off; |
| 5051 | ++col; |
| 5052 | } |
| 5053 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5054 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5055 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5056 | { |
| 5057 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5058 | ++vcol_off; |
| 5059 | if (n_extra > 0) |
| 5060 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5061 | if (wp->w_p_wrap) |
| 5062 | { |
| 5063 | /* |
| 5064 | * Special voodoo required if 'wrap' is on. |
| 5065 | * |
| 5066 | * Advance the column indicator to force the line |
| 5067 | * drawing to wrap early. This will make the line |
| 5068 | * take up the same screen space when parts are concealed, |
| 5069 | * so that cursor line computations aren't messed up. |
| 5070 | * |
| 5071 | * To avoid the fictitious advance of 'col' causing |
| 5072 | * trailing junk to be written out of the screen line |
| 5073 | * we are building, 'boguscols' keeps track of the number |
| 5074 | * of bad columns we have advanced. |
| 5075 | */ |
| 5076 | if (n_extra > 0) |
| 5077 | { |
| 5078 | vcol += n_extra; |
| 5079 | # ifdef FEAT_RIGHTLEFT |
| 5080 | if (wp->w_p_rl) |
| 5081 | { |
| 5082 | col -= n_extra; |
| 5083 | boguscols -= n_extra; |
| 5084 | } |
| 5085 | else |
| 5086 | # endif |
| 5087 | { |
| 5088 | col += n_extra; |
| 5089 | boguscols += n_extra; |
| 5090 | } |
| 5091 | n_extra = 0; |
| 5092 | n_attr = 0; |
| 5093 | } |
| 5094 | |
| 5095 | |
| 5096 | # ifdef FEAT_MBYTE |
| 5097 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5098 | { |
| 5099 | /* Need to fill two screen columns. */ |
| 5100 | # ifdef FEAT_RIGHTLEFT |
| 5101 | if (wp->w_p_rl) |
| 5102 | { |
| 5103 | --boguscols; |
| 5104 | --col; |
| 5105 | } |
| 5106 | else |
| 5107 | # endif |
| 5108 | { |
| 5109 | ++boguscols; |
| 5110 | ++col; |
| 5111 | } |
| 5112 | } |
| 5113 | # endif |
| 5114 | |
| 5115 | # ifdef FEAT_RIGHTLEFT |
| 5116 | if (wp->w_p_rl) |
| 5117 | { |
| 5118 | --boguscols; |
| 5119 | --col; |
| 5120 | } |
| 5121 | else |
| 5122 | # endif |
| 5123 | { |
| 5124 | ++boguscols; |
| 5125 | ++col; |
| 5126 | } |
| 5127 | } |
| 5128 | else |
| 5129 | { |
| 5130 | if (n_extra > 0) |
| 5131 | { |
| 5132 | vcol += n_extra; |
| 5133 | n_extra = 0; |
| 5134 | n_attr = 0; |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | } |
| 5139 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5140 | else |
| 5141 | --n_skip; |
| 5142 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5143 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5144 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5145 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5146 | #ifdef FEAT_DIFF |
| 5147 | && filler_todo <= 0 |
| 5148 | #endif |
| 5149 | ) |
| 5150 | ++vcol; |
| 5151 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5152 | #ifdef FEAT_SYN_HL |
| 5153 | if (vcol_save_attr >= 0) |
| 5154 | char_attr = vcol_save_attr; |
| 5155 | #endif |
| 5156 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5157 | /* restore attributes after "predeces" in 'listchars' */ |
| 5158 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5159 | char_attr = saved_attr3; |
| 5160 | |
| 5161 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5162 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5163 | char_attr = saved_attr2; |
| 5164 | |
| 5165 | /* |
| 5166 | * 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] | 5167 | * 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] | 5168 | */ |
| 5169 | if (( |
| 5170 | #ifdef FEAT_RIGHTLEFT |
| 5171 | wp->w_p_rl ? (col < 0) : |
| 5172 | #endif |
| 5173 | (col >= W_WIDTH(wp))) |
| 5174 | && (*ptr != NUL |
| 5175 | #ifdef FEAT_DIFF |
| 5176 | || filler_todo > 0 |
| 5177 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5178 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5179 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5180 | ) |
| 5181 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5182 | #ifdef FEAT_CONCEAL |
| 5183 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5184 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5185 | boguscols = 0; |
| 5186 | #else |
| 5187 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5188 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5189 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5190 | ++row; |
| 5191 | ++screen_row; |
| 5192 | |
| 5193 | /* When not wrapping and finished diff lines, or when displayed |
| 5194 | * '$' and highlighting until last column, break here. */ |
| 5195 | if ((!wp->w_p_wrap |
| 5196 | #ifdef FEAT_DIFF |
| 5197 | && filler_todo <= 0 |
| 5198 | #endif |
| 5199 | ) || lcs_eol_one == -1) |
| 5200 | break; |
| 5201 | |
| 5202 | /* When the window is too narrow draw all "@" lines. */ |
| 5203 | if (draw_state != WL_LINE |
| 5204 | #ifdef FEAT_DIFF |
| 5205 | && filler_todo <= 0 |
| 5206 | #endif |
| 5207 | ) |
| 5208 | { |
| 5209 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 5210 | #ifdef FEAT_VERTSPLIT |
| 5211 | draw_vsep_win(wp, row); |
| 5212 | #endif |
| 5213 | row = endrow; |
| 5214 | } |
| 5215 | |
| 5216 | /* When line got too long for screen break here. */ |
| 5217 | if (row == endrow) |
| 5218 | { |
| 5219 | ++row; |
| 5220 | break; |
| 5221 | } |
| 5222 | |
| 5223 | if (screen_cur_row == screen_row - 1 |
| 5224 | #ifdef FEAT_DIFF |
| 5225 | && filler_todo <= 0 |
| 5226 | #endif |
| 5227 | && W_WIDTH(wp) == Columns) |
| 5228 | { |
| 5229 | /* Remember that the line wraps, used for modeless copy. */ |
| 5230 | LineWraps[screen_row - 1] = TRUE; |
| 5231 | |
| 5232 | /* |
| 5233 | * Special trick to make copy/paste of wrapped lines work with |
| 5234 | * xterm/screen: write an extra character beyond the end of |
| 5235 | * the line. This will work with all terminal types |
| 5236 | * (regardless of the xn,am settings). |
| 5237 | * Only do this on a fast tty. |
| 5238 | * Only do this if the cursor is on the current line |
| 5239 | * (something has been written in it). |
| 5240 | * Don't do this for the GUI. |
| 5241 | * Don't do this for double-width characters. |
| 5242 | * Don't do this for a window not at the right screen border. |
| 5243 | */ |
| 5244 | if (p_tf |
| 5245 | #ifdef FEAT_GUI |
| 5246 | && !gui.in_use |
| 5247 | #endif |
| 5248 | #ifdef FEAT_MBYTE |
| 5249 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5250 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5251 | LineOffset[screen_row] + screen_Columns) |
| 5252 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5253 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5254 | + (int)Columns - 2, |
| 5255 | LineOffset[screen_row] + screen_Columns) |
| 5256 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5257 | #endif |
| 5258 | ) |
| 5259 | { |
| 5260 | /* First make sure we are at the end of the screen line, |
| 5261 | * then output the same character again to let the |
| 5262 | * terminal know about the wrap. If the terminal doesn't |
| 5263 | * auto-wrap, we overwrite the character. */ |
| 5264 | if (screen_cur_col != W_WIDTH(wp)) |
| 5265 | screen_char(LineOffset[screen_row - 1] |
| 5266 | + (unsigned)Columns - 1, |
| 5267 | screen_row - 1, (int)(Columns - 1)); |
| 5268 | |
| 5269 | #ifdef FEAT_MBYTE |
| 5270 | /* When there is a multi-byte character, just output a |
| 5271 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5272 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5273 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5274 | out_char(' '); |
| 5275 | else |
| 5276 | #endif |
| 5277 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5278 | + (Columns - 1)]); |
| 5279 | /* force a redraw of the first char on the next line */ |
| 5280 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5281 | screen_start(); /* don't know where cursor is now */ |
| 5282 | } |
| 5283 | } |
| 5284 | |
| 5285 | col = 0; |
| 5286 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5287 | #ifdef FEAT_RIGHTLEFT |
| 5288 | if (wp->w_p_rl) |
| 5289 | { |
| 5290 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5291 | off += col; |
| 5292 | } |
| 5293 | #endif |
| 5294 | |
| 5295 | /* reset the drawing state for the start of a wrapped line */ |
| 5296 | draw_state = WL_START; |
| 5297 | saved_n_extra = n_extra; |
| 5298 | saved_p_extra = p_extra; |
| 5299 | saved_c_extra = c_extra; |
| 5300 | saved_char_attr = char_attr; |
| 5301 | n_extra = 0; |
| 5302 | lcs_prec_todo = lcs_prec; |
| 5303 | #ifdef FEAT_LINEBREAK |
| 5304 | # ifdef FEAT_DIFF |
| 5305 | if (filler_todo <= 0) |
| 5306 | # endif |
| 5307 | need_showbreak = TRUE; |
| 5308 | #endif |
| 5309 | #ifdef FEAT_DIFF |
| 5310 | --filler_todo; |
| 5311 | /* When the filler lines are actually below the last line of the |
| 5312 | * file, don't draw the line itself, break here. */ |
| 5313 | if (filler_todo == 0 && wp->w_botfill) |
| 5314 | break; |
| 5315 | #endif |
| 5316 | } |
| 5317 | |
| 5318 | } /* for every character in the line */ |
| 5319 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5320 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5321 | /* After an empty line check first word for capital. */ |
| 5322 | if (*skipwhite(line) == NUL) |
| 5323 | { |
| 5324 | capcol_lnum = lnum + 1; |
| 5325 | cap_col = 0; |
| 5326 | } |
| 5327 | #endif |
| 5328 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5329 | return row; |
| 5330 | } |
| 5331 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5332 | #ifdef FEAT_MBYTE |
| 5333 | static int comp_char_differs __ARGS((int, int)); |
| 5334 | |
| 5335 | /* |
| 5336 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5337 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5338 | */ |
| 5339 | static int |
| 5340 | comp_char_differs(off_from, off_to) |
| 5341 | int off_from; |
| 5342 | int off_to; |
| 5343 | { |
| 5344 | int i; |
| 5345 | |
| 5346 | for (i = 0; i < Screen_mco; ++i) |
| 5347 | { |
| 5348 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5349 | return TRUE; |
| 5350 | if (ScreenLinesC[i][off_from] == 0) |
| 5351 | break; |
| 5352 | } |
| 5353 | return FALSE; |
| 5354 | } |
| 5355 | #endif |
| 5356 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5357 | /* |
| 5358 | * Check whether the given character needs redrawing: |
| 5359 | * - the (first byte of the) character is different |
| 5360 | * - the attributes are different |
| 5361 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5362 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5363 | */ |
| 5364 | static int |
| 5365 | char_needs_redraw(off_from, off_to, cols) |
| 5366 | int off_from; |
| 5367 | int off_to; |
| 5368 | int cols; |
| 5369 | { |
| 5370 | if (cols > 0 |
| 5371 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5372 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5373 | |
| 5374 | #ifdef FEAT_MBYTE |
| 5375 | || (enc_dbcs != 0 |
| 5376 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5377 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5378 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5379 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5380 | != ScreenLines[off_to + 1]))) |
| 5381 | || (enc_utf8 |
| 5382 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5383 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5384 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5385 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5386 | && ScreenLines[off_from + 1] |
| 5387 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5388 | #endif |
| 5389 | )) |
| 5390 | return TRUE; |
| 5391 | return FALSE; |
| 5392 | } |
| 5393 | |
| 5394 | /* |
| 5395 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5396 | * have actually changed. Handle insert/delete character. |
| 5397 | * "coloff" gives the first column on the screen for this line. |
| 5398 | * "endcol" gives the columns where valid characters are. |
| 5399 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5400 | * needs to be cleared, negative otherwise. |
| 5401 | * "rlflag" is TRUE in a rightleft window: |
| 5402 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5403 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5404 | */ |
| 5405 | static void |
| 5406 | screen_line(row, coloff, endcol, clear_width |
| 5407 | #ifdef FEAT_RIGHTLEFT |
| 5408 | , rlflag |
| 5409 | #endif |
| 5410 | ) |
| 5411 | int row; |
| 5412 | int coloff; |
| 5413 | int endcol; |
| 5414 | int clear_width; |
| 5415 | #ifdef FEAT_RIGHTLEFT |
| 5416 | int rlflag; |
| 5417 | #endif |
| 5418 | { |
| 5419 | unsigned off_from; |
| 5420 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5421 | #ifdef FEAT_MBYTE |
| 5422 | unsigned max_off_from; |
| 5423 | unsigned max_off_to; |
| 5424 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5425 | int col = 0; |
| 5426 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 5427 | int hl; |
| 5428 | #endif |
| 5429 | int force = FALSE; /* force update rest of the line */ |
| 5430 | int redraw_this /* bool: does character need redraw? */ |
| 5431 | #ifdef FEAT_GUI |
| 5432 | = TRUE /* For GUI when while-loop empty */ |
| 5433 | #endif |
| 5434 | ; |
| 5435 | int redraw_next; /* redraw_this for next character */ |
| 5436 | #ifdef FEAT_MBYTE |
| 5437 | int clear_next = FALSE; |
| 5438 | int char_cells; /* 1: normal char */ |
| 5439 | /* 2: occupies two display cells */ |
| 5440 | # define CHAR_CELLS char_cells |
| 5441 | #else |
| 5442 | # define CHAR_CELLS 1 |
| 5443 | #endif |
| 5444 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5445 | /* Check for illegal row and col, just in case. */ |
| 5446 | if (row >= Rows) |
| 5447 | row = Rows - 1; |
| 5448 | if (endcol > Columns) |
| 5449 | endcol = Columns; |
| 5450 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5451 | # ifdef FEAT_CLIPBOARD |
| 5452 | clip_may_clear_selection(row, row); |
| 5453 | # endif |
| 5454 | |
| 5455 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5456 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5457 | #ifdef FEAT_MBYTE |
| 5458 | max_off_from = off_from + screen_Columns; |
| 5459 | max_off_to = LineOffset[row] + screen_Columns; |
| 5460 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5461 | |
| 5462 | #ifdef FEAT_RIGHTLEFT |
| 5463 | if (rlflag) |
| 5464 | { |
| 5465 | /* Clear rest first, because it's left of the text. */ |
| 5466 | if (clear_width > 0) |
| 5467 | { |
| 5468 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5469 | && ScreenAttrs[off_to] == 0 |
| 5470 | # ifdef FEAT_MBYTE |
| 5471 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5472 | # endif |
| 5473 | ) |
| 5474 | { |
| 5475 | ++off_to; |
| 5476 | ++col; |
| 5477 | } |
| 5478 | if (col <= endcol) |
| 5479 | screen_fill(row, row + 1, col + coloff, |
| 5480 | endcol + coloff + 1, ' ', ' ', 0); |
| 5481 | } |
| 5482 | col = endcol + 1; |
| 5483 | off_to = LineOffset[row] + col + coloff; |
| 5484 | off_from += col; |
| 5485 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5486 | } |
| 5487 | #endif /* FEAT_RIGHTLEFT */ |
| 5488 | |
| 5489 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5490 | |
| 5491 | while (col < endcol) |
| 5492 | { |
| 5493 | #ifdef FEAT_MBYTE |
| 5494 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5495 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5496 | else |
| 5497 | char_cells = 1; |
| 5498 | #endif |
| 5499 | |
| 5500 | redraw_this = redraw_next; |
| 5501 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5502 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5503 | |
| 5504 | #ifdef FEAT_GUI |
| 5505 | /* If the next character was bold, then redraw the current character to |
| 5506 | * remove any pixels that might have spilt over into us. This only |
| 5507 | * happens in the GUI. |
| 5508 | */ |
| 5509 | if (redraw_next && gui.in_use) |
| 5510 | { |
| 5511 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5512 | if (hl > HL_ALL) |
| 5513 | hl = syn_attr2attr(hl); |
| 5514 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5515 | redraw_this = TRUE; |
| 5516 | } |
| 5517 | #endif |
| 5518 | |
| 5519 | if (redraw_this) |
| 5520 | { |
| 5521 | /* |
| 5522 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5523 | * Attributes for characters are stored at the position where the |
| 5524 | * cursor is when writing the highlighting code. The |
| 5525 | * start-highlighting code must be written with the cursor on the |
| 5526 | * first highlighted character. The stop-highlighting code must |
| 5527 | * be written with the cursor just after the last highlighted |
| 5528 | * character. |
| 5529 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5530 | * to clear the rest of the line, and force redrawing it |
| 5531 | * completely. |
| 5532 | */ |
| 5533 | if ( p_wiv |
| 5534 | && !force |
| 5535 | #ifdef FEAT_GUI |
| 5536 | && !gui.in_use |
| 5537 | #endif |
| 5538 | && ScreenAttrs[off_to] != 0 |
| 5539 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5540 | { |
| 5541 | /* |
| 5542 | * Need to remove highlighting attributes here. |
| 5543 | */ |
| 5544 | windgoto(row, col + coloff); |
| 5545 | out_str(T_CE); /* clear rest of this screen line */ |
| 5546 | screen_start(); /* don't know where cursor is now */ |
| 5547 | force = TRUE; /* force redraw of rest of the line */ |
| 5548 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5549 | |
| 5550 | /* |
| 5551 | * If the previous character was highlighted, need to stop |
| 5552 | * highlighting at this character. |
| 5553 | */ |
| 5554 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5555 | { |
| 5556 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5557 | term_windgoto(row, col + coloff); |
| 5558 | screen_stop_highlight(); |
| 5559 | } |
| 5560 | else |
| 5561 | screen_attr = 0; /* highlighting has stopped */ |
| 5562 | } |
| 5563 | #ifdef FEAT_MBYTE |
| 5564 | if (enc_dbcs != 0) |
| 5565 | { |
| 5566 | /* Check if overwriting a double-byte with a single-byte or |
| 5567 | * the other way around requires another character to be |
| 5568 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 5569 | * ScreenLinesUC[] is sufficient. */ |
| 5570 | if (char_cells == 1 |
| 5571 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5572 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5573 | { |
| 5574 | /* Writing a single-cell character over a double-cell |
| 5575 | * character: need to redraw the next cell. */ |
| 5576 | ScreenLines[off_to + 1] = 0; |
| 5577 | redraw_next = TRUE; |
| 5578 | } |
| 5579 | else if (char_cells == 2 |
| 5580 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5581 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5582 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5583 | { |
| 5584 | /* Writing the second half of a double-cell character over |
| 5585 | * a double-cell character: need to redraw the second |
| 5586 | * cell. */ |
| 5587 | ScreenLines[off_to + 2] = 0; |
| 5588 | redraw_next = TRUE; |
| 5589 | } |
| 5590 | |
| 5591 | if (enc_dbcs == DBCS_JPNU) |
| 5592 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 5593 | } |
| 5594 | /* When writing a single-width character over a double-width |
| 5595 | * character and at the end of the redrawn text, need to clear out |
| 5596 | * the right halve of the old character. |
| 5597 | * Also required when writing the right halve of a double-width |
| 5598 | * char over the left halve of an existing one. */ |
| 5599 | if (has_mbyte && col + char_cells == endcol |
| 5600 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5601 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5602 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5603 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5604 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5605 | clear_next = TRUE; |
| 5606 | #endif |
| 5607 | |
| 5608 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 5609 | #ifdef FEAT_MBYTE |
| 5610 | if (enc_utf8) |
| 5611 | { |
| 5612 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 5613 | if (ScreenLinesUC[off_from] != 0) |
| 5614 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5615 | int i; |
| 5616 | |
| 5617 | for (i = 0; i < Screen_mco; ++i) |
| 5618 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5619 | } |
| 5620 | } |
| 5621 | if (char_cells == 2) |
| 5622 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 5623 | #endif |
| 5624 | |
| 5625 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 5626 | /* The bold trick makes a single column of pixels appear in the |
| 5627 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5628 | * character should be redrawn too. This happens for our own GUI |
| 5629 | * and for some xterms. */ |
| 5630 | if ( |
| 5631 | # ifdef FEAT_GUI |
| 5632 | gui.in_use |
| 5633 | # endif |
| 5634 | # if defined(FEAT_GUI) && defined(UNIX) |
| 5635 | || |
| 5636 | # endif |
| 5637 | # ifdef UNIX |
| 5638 | term_is_xterm |
| 5639 | # endif |
| 5640 | ) |
| 5641 | { |
| 5642 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5643 | if (hl > HL_ALL) |
| 5644 | hl = syn_attr2attr(hl); |
| 5645 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5646 | redraw_next = TRUE; |
| 5647 | } |
| 5648 | #endif |
| 5649 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 5650 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5651 | /* For simplicity set the attributes of second half of a |
| 5652 | * double-wide character equal to the first half. */ |
| 5653 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5654 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5655 | |
| 5656 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5657 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5658 | else |
| 5659 | #endif |
| 5660 | screen_char(off_to, row, col + coloff); |
| 5661 | } |
| 5662 | else if ( p_wiv |
| 5663 | #ifdef FEAT_GUI |
| 5664 | && !gui.in_use |
| 5665 | #endif |
| 5666 | && col + coloff > 0) |
| 5667 | { |
| 5668 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 5669 | { |
| 5670 | /* |
| 5671 | * Don't output stop-highlight when moving the cursor, it will |
| 5672 | * stop the highlighting when it should continue. |
| 5673 | */ |
| 5674 | screen_attr = 0; |
| 5675 | } |
| 5676 | else if (screen_attr != 0) |
| 5677 | screen_stop_highlight(); |
| 5678 | } |
| 5679 | |
| 5680 | off_to += CHAR_CELLS; |
| 5681 | off_from += CHAR_CELLS; |
| 5682 | col += CHAR_CELLS; |
| 5683 | } |
| 5684 | |
| 5685 | #ifdef FEAT_MBYTE |
| 5686 | if (clear_next) |
| 5687 | { |
| 5688 | /* Clear the second half of a double-wide character of which the left |
| 5689 | * half was overwritten with a single-wide character. */ |
| 5690 | ScreenLines[off_to] = ' '; |
| 5691 | if (enc_utf8) |
| 5692 | ScreenLinesUC[off_to] = 0; |
| 5693 | screen_char(off_to, row, col + coloff); |
| 5694 | } |
| 5695 | #endif |
| 5696 | |
| 5697 | if (clear_width > 0 |
| 5698 | #ifdef FEAT_RIGHTLEFT |
| 5699 | && !rlflag |
| 5700 | #endif |
| 5701 | ) |
| 5702 | { |
| 5703 | #ifdef FEAT_GUI |
| 5704 | int startCol = col; |
| 5705 | #endif |
| 5706 | |
| 5707 | /* blank out the rest of the line */ |
| 5708 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 5709 | && ScreenAttrs[off_to] == 0 |
| 5710 | #ifdef FEAT_MBYTE |
| 5711 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5712 | #endif |
| 5713 | ) |
| 5714 | { |
| 5715 | ++off_to; |
| 5716 | ++col; |
| 5717 | } |
| 5718 | if (col < clear_width) |
| 5719 | { |
| 5720 | #ifdef FEAT_GUI |
| 5721 | /* |
| 5722 | * In the GUI, clearing the rest of the line may leave pixels |
| 5723 | * behind if the first character cleared was bold. Some bold |
| 5724 | * fonts spill over the left. In this case we redraw the previous |
| 5725 | * character too. If we didn't skip any blanks above, then we |
| 5726 | * only redraw if the character wasn't already redrawn anyway. |
| 5727 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5728 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5729 | { |
| 5730 | hl = ScreenAttrs[off_to]; |
| 5731 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5732 | { |
| 5733 | int prev_cells = 1; |
| 5734 | # ifdef FEAT_MBYTE |
| 5735 | if (enc_utf8) |
| 5736 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 5737 | * that its width is 2. */ |
| 5738 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 5739 | else if (enc_dbcs != 0) |
| 5740 | { |
| 5741 | /* find previous character by counting from first |
| 5742 | * column and get its width. */ |
| 5743 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5744 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5745 | |
| 5746 | while (off < off_to) |
| 5747 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5748 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 5749 | off += prev_cells; |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | if (enc_dbcs != 0 && prev_cells > 1) |
| 5754 | screen_char_2(off_to - prev_cells, row, |
| 5755 | col + coloff - prev_cells); |
| 5756 | else |
| 5757 | # endif |
| 5758 | screen_char(off_to - prev_cells, row, |
| 5759 | col + coloff - prev_cells); |
| 5760 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5761 | } |
| 5762 | #endif |
| 5763 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 5764 | ' ', ' ', 0); |
| 5765 | #ifdef FEAT_VERTSPLIT |
| 5766 | off_to += clear_width - col; |
| 5767 | col = clear_width; |
| 5768 | #endif |
| 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | if (clear_width > 0) |
| 5773 | { |
| 5774 | #ifdef FEAT_VERTSPLIT |
| 5775 | /* For a window that's left of another, draw the separator char. */ |
| 5776 | if (col + coloff < Columns) |
| 5777 | { |
| 5778 | int c; |
| 5779 | |
| 5780 | c = fillchar_vsep(&hl); |
| 5781 | if (ScreenLines[off_to] != c |
| 5782 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5783 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 5784 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5785 | # endif |
| 5786 | || ScreenAttrs[off_to] != hl) |
| 5787 | { |
| 5788 | ScreenLines[off_to] = c; |
| 5789 | ScreenAttrs[off_to] = hl; |
| 5790 | # ifdef FEAT_MBYTE |
| 5791 | if (enc_utf8) |
| 5792 | { |
| 5793 | if (c >= 0x80) |
| 5794 | { |
| 5795 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5796 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5797 | } |
| 5798 | else |
| 5799 | ScreenLinesUC[off_to] = 0; |
| 5800 | } |
| 5801 | # endif |
| 5802 | screen_char(off_to, row, col + coloff); |
| 5803 | } |
| 5804 | } |
| 5805 | else |
| 5806 | #endif |
| 5807 | LineWraps[row] = FALSE; |
| 5808 | } |
| 5809 | } |
| 5810 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5811 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5812 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5813 | * Mirror text "str" for right-left displaying. |
| 5814 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5815 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 5816 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5817 | rl_mirror(str) |
| 5818 | char_u *str; |
| 5819 | { |
| 5820 | char_u *p1, *p2; |
| 5821 | int t; |
| 5822 | |
| 5823 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 5824 | { |
| 5825 | t = *p1; |
| 5826 | *p1 = *p2; |
| 5827 | *p2 = t; |
| 5828 | } |
| 5829 | } |
| 5830 | #endif |
| 5831 | |
| 5832 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 5833 | /* |
| 5834 | * mark all status lines for redraw; used after first :cd |
| 5835 | */ |
| 5836 | void |
| 5837 | status_redraw_all() |
| 5838 | { |
| 5839 | win_T *wp; |
| 5840 | |
| 5841 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5842 | if (wp->w_status_height) |
| 5843 | { |
| 5844 | wp->w_redr_status = TRUE; |
| 5845 | redraw_later(VALID); |
| 5846 | } |
| 5847 | } |
| 5848 | |
| 5849 | /* |
| 5850 | * mark all status lines of the current buffer for redraw |
| 5851 | */ |
| 5852 | void |
| 5853 | status_redraw_curbuf() |
| 5854 | { |
| 5855 | win_T *wp; |
| 5856 | |
| 5857 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5858 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 5859 | { |
| 5860 | wp->w_redr_status = TRUE; |
| 5861 | redraw_later(VALID); |
| 5862 | } |
| 5863 | } |
| 5864 | |
| 5865 | /* |
| 5866 | * Redraw all status lines that need to be redrawn. |
| 5867 | */ |
| 5868 | void |
| 5869 | redraw_statuslines() |
| 5870 | { |
| 5871 | win_T *wp; |
| 5872 | |
| 5873 | for (wp = firstwin; wp; wp = wp->w_next) |
| 5874 | if (wp->w_redr_status) |
| 5875 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 5876 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 5877 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5878 | } |
| 5879 | #endif |
| 5880 | |
| 5881 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 5882 | /* |
| 5883 | * Redraw all status lines at the bottom of frame "frp". |
| 5884 | */ |
| 5885 | void |
| 5886 | win_redraw_last_status(frp) |
| 5887 | frame_T *frp; |
| 5888 | { |
| 5889 | if (frp->fr_layout == FR_LEAF) |
| 5890 | frp->fr_win->w_redr_status = TRUE; |
| 5891 | else if (frp->fr_layout == FR_ROW) |
| 5892 | { |
| 5893 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 5894 | win_redraw_last_status(frp); |
| 5895 | } |
| 5896 | else /* frp->fr_layout == FR_COL */ |
| 5897 | { |
| 5898 | frp = frp->fr_child; |
| 5899 | while (frp->fr_next != NULL) |
| 5900 | frp = frp->fr_next; |
| 5901 | win_redraw_last_status(frp); |
| 5902 | } |
| 5903 | } |
| 5904 | #endif |
| 5905 | |
| 5906 | #ifdef FEAT_VERTSPLIT |
| 5907 | /* |
| 5908 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 5909 | */ |
| 5910 | static void |
| 5911 | draw_vsep_win(wp, row) |
| 5912 | win_T *wp; |
| 5913 | int row; |
| 5914 | { |
| 5915 | int hl; |
| 5916 | int c; |
| 5917 | |
| 5918 | if (wp->w_vsep_width) |
| 5919 | { |
| 5920 | /* draw the vertical separator right of this window */ |
| 5921 | c = fillchar_vsep(&hl); |
| 5922 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 5923 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 5924 | c, ' ', hl); |
| 5925 | } |
| 5926 | } |
| 5927 | #endif |
| 5928 | |
| 5929 | #ifdef FEAT_WILDMENU |
| 5930 | static int status_match_len __ARGS((expand_T *xp, char_u *s)); |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5931 | 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] | 5932 | |
| 5933 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5934 | * 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] | 5935 | */ |
| 5936 | static int |
| 5937 | status_match_len(xp, s) |
| 5938 | expand_T *xp; |
| 5939 | char_u *s; |
| 5940 | { |
| 5941 | int len = 0; |
| 5942 | |
| 5943 | #ifdef FEAT_MENU |
| 5944 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 5945 | || xp->xp_context == EXPAND_MENUNAMES); |
| 5946 | |
| 5947 | /* Check for menu separators - replace with '|'. */ |
| 5948 | if (emenu && menu_is_separator(s)) |
| 5949 | return 1; |
| 5950 | #endif |
| 5951 | |
| 5952 | while (*s != NUL) |
| 5953 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5954 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5955 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 5956 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | return len; |
| 5960 | } |
| 5961 | |
| 5962 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5963 | * 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] | 5964 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 5965 | */ |
| 5966 | static int |
| 5967 | skip_status_match_char(xp, s) |
| 5968 | expand_T *xp; |
| 5969 | char_u *s; |
| 5970 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5971 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5972 | #ifdef FEAT_MENU |
| 5973 | || ((xp->xp_context == EXPAND_MENUS |
| 5974 | || xp->xp_context == EXPAND_MENUNAMES) |
| 5975 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 5976 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 5977 | ) |
| 5978 | { |
| 5979 | #ifndef BACKSLASH_IN_FILENAME |
| 5980 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 5981 | return 2; |
| 5982 | #endif |
| 5983 | return 1; |
| 5984 | } |
| 5985 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5989 | * Show wildchar matches in the status line. |
| 5990 | * Show at least the "match" item. |
| 5991 | * We start at item 'first_match' in the list and show all matches that fit. |
| 5992 | * |
| 5993 | * If inversion is possible we use it. Else '=' characters are used. |
| 5994 | */ |
| 5995 | void |
| 5996 | win_redr_status_matches(xp, num_matches, matches, match, showtail) |
| 5997 | expand_T *xp; |
| 5998 | int num_matches; |
| 5999 | char_u **matches; /* list of matches */ |
| 6000 | int match; |
| 6001 | int showtail; |
| 6002 | { |
| 6003 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 6004 | int row; |
| 6005 | char_u *buf; |
| 6006 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6007 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6008 | int fillchar; |
| 6009 | int attr; |
| 6010 | int i; |
| 6011 | int highlight = TRUE; |
| 6012 | char_u *selstart = NULL; |
| 6013 | int selstart_col = 0; |
| 6014 | char_u *selend = NULL; |
| 6015 | static int first_match = 0; |
| 6016 | int add_left = FALSE; |
| 6017 | char_u *s; |
| 6018 | #ifdef FEAT_MENU |
| 6019 | int emenu; |
| 6020 | #endif |
| 6021 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 6022 | int l; |
| 6023 | #endif |
| 6024 | |
| 6025 | if (matches == NULL) /* interrupted completion? */ |
| 6026 | return; |
| 6027 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6028 | #ifdef FEAT_MBYTE |
| 6029 | if (has_mbyte) |
| 6030 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 6031 | else |
| 6032 | #endif |
| 6033 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6034 | if (buf == NULL) |
| 6035 | return; |
| 6036 | |
| 6037 | if (match == -1) /* don't show match but original text */ |
| 6038 | { |
| 6039 | match = 0; |
| 6040 | highlight = FALSE; |
| 6041 | } |
| 6042 | /* count 1 for the ending ">" */ |
| 6043 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 6044 | if (match == 0) |
| 6045 | first_match = 0; |
| 6046 | else if (match < first_match) |
| 6047 | { |
| 6048 | /* jumping left, as far as we can go */ |
| 6049 | first_match = match; |
| 6050 | add_left = TRUE; |
| 6051 | } |
| 6052 | else |
| 6053 | { |
| 6054 | /* check if match fits on the screen */ |
| 6055 | for (i = first_match; i < match; ++i) |
| 6056 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6057 | if (first_match > 0) |
| 6058 | clen += 2; |
| 6059 | /* jumping right, put match at the left */ |
| 6060 | if ((long)clen > Columns) |
| 6061 | { |
| 6062 | first_match = match; |
| 6063 | /* if showing the last match, we can add some on the left */ |
| 6064 | clen = 2; |
| 6065 | for (i = match; i < num_matches; ++i) |
| 6066 | { |
| 6067 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6068 | if ((long)clen >= Columns) |
| 6069 | break; |
| 6070 | } |
| 6071 | if (i == num_matches) |
| 6072 | add_left = TRUE; |
| 6073 | } |
| 6074 | } |
| 6075 | if (add_left) |
| 6076 | while (first_match > 0) |
| 6077 | { |
| 6078 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6079 | if ((long)clen >= Columns) |
| 6080 | break; |
| 6081 | --first_match; |
| 6082 | } |
| 6083 | |
| 6084 | fillchar = fillchar_status(&attr, TRUE); |
| 6085 | |
| 6086 | if (first_match == 0) |
| 6087 | { |
| 6088 | *buf = NUL; |
| 6089 | len = 0; |
| 6090 | } |
| 6091 | else |
| 6092 | { |
| 6093 | STRCPY(buf, "< "); |
| 6094 | len = 2; |
| 6095 | } |
| 6096 | clen = len; |
| 6097 | |
| 6098 | i = first_match; |
| 6099 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6100 | { |
| 6101 | if (i == match) |
| 6102 | { |
| 6103 | selstart = buf + len; |
| 6104 | selstart_col = clen; |
| 6105 | } |
| 6106 | |
| 6107 | s = L_MATCH(i); |
| 6108 | /* Check for menu separators - replace with '|' */ |
| 6109 | #ifdef FEAT_MENU |
| 6110 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6111 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6112 | if (emenu && menu_is_separator(s)) |
| 6113 | { |
| 6114 | STRCPY(buf + len, transchar('|')); |
| 6115 | l = (int)STRLEN(buf + len); |
| 6116 | len += l; |
| 6117 | clen += l; |
| 6118 | } |
| 6119 | else |
| 6120 | #endif |
| 6121 | for ( ; *s != NUL; ++s) |
| 6122 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6123 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6124 | clen += ptr2cells(s); |
| 6125 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6126 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6127 | { |
| 6128 | STRNCPY(buf + len, s, l); |
| 6129 | s += l - 1; |
| 6130 | len += l; |
| 6131 | } |
| 6132 | else |
| 6133 | #endif |
| 6134 | { |
| 6135 | STRCPY(buf + len, transchar_byte(*s)); |
| 6136 | len += (int)STRLEN(buf + len); |
| 6137 | } |
| 6138 | } |
| 6139 | if (i == match) |
| 6140 | selend = buf + len; |
| 6141 | |
| 6142 | *(buf + len++) = ' '; |
| 6143 | *(buf + len++) = ' '; |
| 6144 | clen += 2; |
| 6145 | if (++i == num_matches) |
| 6146 | break; |
| 6147 | } |
| 6148 | |
| 6149 | if (i != num_matches) |
| 6150 | { |
| 6151 | *(buf + len++) = '>'; |
| 6152 | ++clen; |
| 6153 | } |
| 6154 | |
| 6155 | buf[len] = NUL; |
| 6156 | |
| 6157 | row = cmdline_row - 1; |
| 6158 | if (row >= 0) |
| 6159 | { |
| 6160 | if (wild_menu_showing == 0) |
| 6161 | { |
| 6162 | if (msg_scrolled > 0) |
| 6163 | { |
| 6164 | /* Put the wildmenu just above the command line. If there is |
| 6165 | * no room, scroll the screen one line up. */ |
| 6166 | if (cmdline_row == Rows - 1) |
| 6167 | { |
| 6168 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6169 | ++msg_scrolled; |
| 6170 | } |
| 6171 | else |
| 6172 | { |
| 6173 | ++cmdline_row; |
| 6174 | ++row; |
| 6175 | } |
| 6176 | wild_menu_showing = WM_SCROLLED; |
| 6177 | } |
| 6178 | else |
| 6179 | { |
| 6180 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6181 | * Set 'winminheight' to zero to avoid that the window is |
| 6182 | * resized. */ |
| 6183 | if (lastwin->w_status_height == 0) |
| 6184 | { |
| 6185 | save_p_ls = p_ls; |
| 6186 | save_p_wmh = p_wmh; |
| 6187 | p_ls = 2; |
| 6188 | p_wmh = 0; |
| 6189 | last_status(FALSE); |
| 6190 | } |
| 6191 | wild_menu_showing = WM_SHOWN; |
| 6192 | } |
| 6193 | } |
| 6194 | |
| 6195 | screen_puts(buf, row, 0, attr); |
| 6196 | if (selstart != NULL && highlight) |
| 6197 | { |
| 6198 | *selend = NUL; |
| 6199 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6200 | } |
| 6201 | |
| 6202 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6203 | } |
| 6204 | |
| 6205 | #ifdef FEAT_VERTSPLIT |
| 6206 | win_redraw_last_status(topframe); |
| 6207 | #else |
| 6208 | lastwin->w_redr_status = TRUE; |
| 6209 | #endif |
| 6210 | vim_free(buf); |
| 6211 | } |
| 6212 | #endif |
| 6213 | |
| 6214 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6215 | /* |
| 6216 | * Redraw the status line of window wp. |
| 6217 | * |
| 6218 | * If inversion is possible we use it. Else '=' characters are used. |
| 6219 | */ |
| 6220 | void |
| 6221 | win_redr_status(wp) |
| 6222 | win_T *wp; |
| 6223 | { |
| 6224 | int row; |
| 6225 | char_u *p; |
| 6226 | int len; |
| 6227 | int fillchar; |
| 6228 | int attr; |
| 6229 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6230 | static int busy = FALSE; |
| 6231 | |
| 6232 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6233 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6234 | if (busy) |
| 6235 | return; |
| 6236 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6237 | |
| 6238 | wp->w_redr_status = FALSE; |
| 6239 | if (wp->w_status_height == 0) |
| 6240 | { |
| 6241 | /* no status line, can only be last window */ |
| 6242 | redraw_cmdline = TRUE; |
| 6243 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6244 | else if (!redrawing() |
| 6245 | #ifdef FEAT_INS_EXPAND |
| 6246 | /* don't update status line when popup menu is visible and may be |
| 6247 | * drawn over it */ |
| 6248 | || pum_visible() |
| 6249 | #endif |
| 6250 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6251 | { |
| 6252 | /* Don't redraw right now, do it later. */ |
| 6253 | wp->w_redr_status = TRUE; |
| 6254 | } |
| 6255 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6256 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6257 | { |
| 6258 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6259 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6260 | } |
| 6261 | #endif |
| 6262 | else |
| 6263 | { |
| 6264 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6265 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6266 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6267 | p = NameBuff; |
| 6268 | len = (int)STRLEN(p); |
| 6269 | |
| 6270 | if (wp->w_buffer->b_help |
| 6271 | #ifdef FEAT_QUICKFIX |
| 6272 | || wp->w_p_pvw |
| 6273 | #endif |
| 6274 | || bufIsChanged(wp->w_buffer) |
| 6275 | || wp->w_buffer->b_p_ro) |
| 6276 | *(p + len++) = ' '; |
| 6277 | if (wp->w_buffer->b_help) |
| 6278 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6279 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6280 | len += (int)STRLEN(p + len); |
| 6281 | } |
| 6282 | #ifdef FEAT_QUICKFIX |
| 6283 | if (wp->w_p_pvw) |
| 6284 | { |
| 6285 | STRCPY(p + len, _("[Preview]")); |
| 6286 | len += (int)STRLEN(p + len); |
| 6287 | } |
| 6288 | #endif |
| 6289 | if (bufIsChanged(wp->w_buffer)) |
| 6290 | { |
| 6291 | STRCPY(p + len, "[+]"); |
| 6292 | len += 3; |
| 6293 | } |
| 6294 | if (wp->w_buffer->b_p_ro) |
| 6295 | { |
Bram Moolenaar | 2358403 | 2013-06-07 20:17:11 +0200 | [diff] [blame] | 6296 | STRCPY(p + len, _("[RO]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6297 | len += 4; |
| 6298 | } |
| 6299 | |
| 6300 | #ifndef FEAT_VERTSPLIT |
| 6301 | this_ru_col = ru_col; |
| 6302 | if (this_ru_col < (Columns + 1) / 2) |
| 6303 | this_ru_col = (Columns + 1) / 2; |
| 6304 | #else |
| 6305 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6306 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6307 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6308 | if (this_ru_col <= 1) |
| 6309 | { |
| 6310 | p = (char_u *)"<"; /* No room for file name! */ |
| 6311 | len = 1; |
| 6312 | } |
| 6313 | else |
| 6314 | #endif |
| 6315 | #ifdef FEAT_MBYTE |
| 6316 | if (has_mbyte) |
| 6317 | { |
| 6318 | int clen = 0, i; |
| 6319 | |
| 6320 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6321 | clen = mb_string2cells(p, -1); |
| 6322 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6323 | /* Find first character that will fit. |
| 6324 | * Going from start to end is much faster for DBCS. */ |
| 6325 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6326 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6327 | clen -= (*mb_ptr2cells)(p + i); |
| 6328 | len = clen; |
| 6329 | if (i > 0) |
| 6330 | { |
| 6331 | p = p + i - 1; |
| 6332 | *p = '<'; |
| 6333 | ++len; |
| 6334 | } |
| 6335 | |
| 6336 | } |
| 6337 | else |
| 6338 | #endif |
| 6339 | if (len > this_ru_col - 1) |
| 6340 | { |
| 6341 | p += len - (this_ru_col - 1); |
| 6342 | *p = '<'; |
| 6343 | len = this_ru_col - 1; |
| 6344 | } |
| 6345 | |
| 6346 | row = W_WINROW(wp) + wp->w_height; |
| 6347 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6348 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6349 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6350 | |
| 6351 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 6352 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6353 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6354 | - 1 + W_WINCOL(wp)), attr); |
| 6355 | |
| 6356 | #ifdef FEAT_CMDL_INFO |
| 6357 | win_redr_ruler(wp, TRUE); |
| 6358 | #endif |
| 6359 | } |
| 6360 | |
| 6361 | #ifdef FEAT_VERTSPLIT |
| 6362 | /* |
| 6363 | * May need to draw the character below the vertical separator. |
| 6364 | */ |
| 6365 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6366 | { |
| 6367 | if (stl_connected(wp)) |
| 6368 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6369 | else |
| 6370 | fillchar = fillchar_vsep(&attr); |
| 6371 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6372 | attr); |
| 6373 | } |
| 6374 | #endif |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6375 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6376 | } |
| 6377 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6378 | #ifdef FEAT_STL_OPT |
| 6379 | /* |
| 6380 | * Redraw the status line according to 'statusline' and take care of any |
| 6381 | * errors encountered. |
| 6382 | */ |
| 6383 | static void |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6384 | redraw_custom_statusline(wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6385 | win_T *wp; |
| 6386 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6387 | static int entered = FALSE; |
| 6388 | int save_called_emsg = called_emsg; |
| 6389 | |
| 6390 | /* When called recursively return. This can happen when the statusline |
| 6391 | * contains an expression that triggers a redraw. */ |
| 6392 | if (entered) |
| 6393 | return; |
| 6394 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6395 | |
| 6396 | called_emsg = FALSE; |
| 6397 | win_redr_custom(wp, FALSE); |
| 6398 | if (called_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6399 | { |
| 6400 | /* When there is an error disable the statusline, otherwise the |
| 6401 | * display is messed up with errors and a redraw triggers the problem |
| 6402 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6403 | set_string_option_direct((char_u *)"statusline", -1, |
| 6404 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6405 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6406 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6407 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6408 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6409 | } |
| 6410 | #endif |
| 6411 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6412 | # ifdef FEAT_VERTSPLIT |
| 6413 | /* |
| 6414 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6415 | * line of the window right of it. If not, then it's a vertical separator. |
| 6416 | * Only call if (wp->w_vsep_width != 0). |
| 6417 | */ |
| 6418 | int |
| 6419 | stl_connected(wp) |
| 6420 | win_T *wp; |
| 6421 | { |
| 6422 | frame_T *fr; |
| 6423 | |
| 6424 | fr = wp->w_frame; |
| 6425 | while (fr->fr_parent != NULL) |
| 6426 | { |
| 6427 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6428 | { |
| 6429 | if (fr->fr_next != NULL) |
| 6430 | break; |
| 6431 | } |
| 6432 | else |
| 6433 | { |
| 6434 | if (fr->fr_next != NULL) |
| 6435 | return TRUE; |
| 6436 | } |
| 6437 | fr = fr->fr_parent; |
| 6438 | } |
| 6439 | return FALSE; |
| 6440 | } |
| 6441 | # endif |
| 6442 | |
| 6443 | #endif /* FEAT_WINDOWS */ |
| 6444 | |
| 6445 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6446 | /* |
| 6447 | * Get the value to show for the language mappings, active 'keymap'. |
| 6448 | */ |
| 6449 | int |
| 6450 | get_keymap_str(wp, buf, len) |
| 6451 | win_T *wp; |
| 6452 | char_u *buf; /* buffer for the result */ |
| 6453 | int len; /* length of buffer */ |
| 6454 | { |
| 6455 | char_u *p; |
| 6456 | |
| 6457 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6458 | return FALSE; |
| 6459 | |
| 6460 | { |
| 6461 | #ifdef FEAT_EVAL |
| 6462 | buf_T *old_curbuf = curbuf; |
| 6463 | win_T *old_curwin = curwin; |
| 6464 | char_u *s; |
| 6465 | |
| 6466 | curbuf = wp->w_buffer; |
| 6467 | curwin = wp; |
| 6468 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6469 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6470 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6471 | --emsg_skip; |
| 6472 | curbuf = old_curbuf; |
| 6473 | curwin = old_curwin; |
| 6474 | if (p == NULL || *p == NUL) |
| 6475 | #endif |
| 6476 | { |
| 6477 | #ifdef FEAT_KEYMAP |
| 6478 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6479 | p = wp->w_buffer->b_p_keymap; |
| 6480 | else |
| 6481 | #endif |
| 6482 | p = (char_u *)"lang"; |
| 6483 | } |
| 6484 | if ((int)(STRLEN(p) + 3) < len) |
| 6485 | sprintf((char *)buf, "<%s>", p); |
| 6486 | else |
| 6487 | buf[0] = NUL; |
| 6488 | #ifdef FEAT_EVAL |
| 6489 | vim_free(s); |
| 6490 | #endif |
| 6491 | } |
| 6492 | return buf[0] != NUL; |
| 6493 | } |
| 6494 | #endif |
| 6495 | |
| 6496 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6497 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6498 | * Redraw the status line or ruler of window "wp". |
| 6499 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6500 | */ |
| 6501 | static void |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6502 | win_redr_custom(wp, draw_ruler) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6503 | win_T *wp; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6504 | int draw_ruler; /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6505 | { |
| 6506 | int attr; |
| 6507 | int curattr; |
| 6508 | int row; |
| 6509 | int col = 0; |
| 6510 | int maxwidth; |
| 6511 | int width; |
| 6512 | int n; |
| 6513 | int len; |
| 6514 | int fillchar; |
| 6515 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6516 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6517 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6518 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6519 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6520 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6521 | win_T *ewp; |
| 6522 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6523 | |
| 6524 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6525 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6526 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6527 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6528 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6529 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6530 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6531 | attr = hl_attr(HLF_TPF); |
| 6532 | maxwidth = Columns; |
| 6533 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6534 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6535 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6536 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6537 | else |
| 6538 | { |
| 6539 | row = W_WINROW(wp) + wp->w_height; |
| 6540 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6541 | maxwidth = W_WIDTH(wp); |
| 6542 | |
| 6543 | if (draw_ruler) |
| 6544 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6545 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6546 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6547 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6548 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6549 | if (*++stl == '-') |
| 6550 | stl++; |
| 6551 | if (atoi((char *)stl)) |
| 6552 | while (VIM_ISDIGIT(*stl)) |
| 6553 | stl++; |
| 6554 | if (*stl++ != '(') |
| 6555 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6556 | } |
| 6557 | #ifdef FEAT_VERTSPLIT |
| 6558 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6559 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6560 | col = (W_WIDTH(wp) + 1) / 2; |
| 6561 | #else |
| 6562 | col = ru_col; |
| 6563 | if (col > (Columns + 1) / 2) |
| 6564 | col = (Columns + 1) / 2; |
| 6565 | #endif |
| 6566 | maxwidth = W_WIDTH(wp) - col; |
| 6567 | #ifdef FEAT_WINDOWS |
| 6568 | if (!wp->w_status_height) |
| 6569 | #endif |
| 6570 | { |
| 6571 | row = Rows - 1; |
| 6572 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6573 | fillchar = ' '; |
| 6574 | attr = 0; |
| 6575 | } |
| 6576 | |
| 6577 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6578 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6579 | # endif |
| 6580 | } |
| 6581 | else |
| 6582 | { |
| 6583 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6584 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6585 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6586 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6587 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6588 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 6589 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6590 | # endif |
| 6591 | } |
| 6592 | |
| 6593 | #ifdef FEAT_VERTSPLIT |
| 6594 | col += W_WINCOL(wp); |
| 6595 | #endif |
| 6596 | } |
| 6597 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6598 | if (maxwidth <= 0) |
| 6599 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6600 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6601 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 6602 | * the cursor away and back. */ |
| 6603 | ewp = wp == NULL ? curwin : wp; |
| 6604 | p_crb_save = ewp->w_p_crb; |
| 6605 | ewp->w_p_crb = FALSE; |
| 6606 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6607 | /* Make a copy, because the statusline may include a function call that |
| 6608 | * might change the option value and free the memory. */ |
| 6609 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6610 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6611 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6612 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6613 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6614 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6615 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 6616 | /* Make all characters printable. */ |
| 6617 | p = transstr(buf); |
| 6618 | if (p != NULL) |
| 6619 | { |
| 6620 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 6621 | vim_free(p); |
| 6622 | } |
| 6623 | |
| 6624 | /* fill up with "fillchar" */ |
| 6625 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 6626 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6627 | { |
| 6628 | #ifdef FEAT_MBYTE |
| 6629 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 6630 | #else |
| 6631 | buf[len++] = fillchar; |
| 6632 | #endif |
| 6633 | ++width; |
| 6634 | } |
| 6635 | buf[len] = NUL; |
| 6636 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6637 | /* |
| 6638 | * Draw each snippet with the specified highlighting. |
| 6639 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6640 | curattr = attr; |
| 6641 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6642 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6643 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6644 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6645 | screen_puts_len(p, len, row, col, curattr); |
| 6646 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6647 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6648 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6649 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6650 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6651 | else if (hltab[n].userhl < 0) |
| 6652 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6653 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6654 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6655 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6656 | #endif |
| 6657 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6658 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6659 | } |
| 6660 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6661 | |
| 6662 | if (wp == NULL) |
| 6663 | { |
| 6664 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 6665 | col = 0; |
| 6666 | len = 0; |
| 6667 | p = buf; |
| 6668 | fillchar = 0; |
| 6669 | for (n = 0; tabtab[n].start != NULL; n++) |
| 6670 | { |
| 6671 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 6672 | while (col < len) |
| 6673 | TabPageIdxs[col++] = fillchar; |
| 6674 | p = tabtab[n].start; |
| 6675 | fillchar = tabtab[n].userhl; |
| 6676 | } |
| 6677 | while (col < Columns) |
| 6678 | TabPageIdxs[col++] = fillchar; |
| 6679 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6680 | } |
| 6681 | |
| 6682 | #endif /* FEAT_STL_OPT */ |
| 6683 | |
| 6684 | /* |
| 6685 | * Output a single character directly to the screen and update ScreenLines. |
| 6686 | */ |
| 6687 | void |
| 6688 | screen_putchar(c, row, col, attr) |
| 6689 | int c; |
| 6690 | int row, col; |
| 6691 | int attr; |
| 6692 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6693 | char_u buf[MB_MAXBYTES + 1]; |
| 6694 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 6695 | #ifdef FEAT_MBYTE |
| 6696 | if (has_mbyte) |
| 6697 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 6698 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6699 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 6700 | { |
| 6701 | buf[0] = c; |
| 6702 | buf[1] = NUL; |
| 6703 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6704 | screen_puts(buf, row, col, attr); |
| 6705 | } |
| 6706 | |
| 6707 | /* |
| 6708 | * Get a single character directly from ScreenLines into "bytes[]". |
| 6709 | * Also return its attribute in *attrp; |
| 6710 | */ |
| 6711 | void |
| 6712 | screen_getbytes(row, col, bytes, attrp) |
| 6713 | int row, col; |
| 6714 | char_u *bytes; |
| 6715 | int *attrp; |
| 6716 | { |
| 6717 | unsigned off; |
| 6718 | |
| 6719 | /* safety check */ |
| 6720 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 6721 | { |
| 6722 | off = LineOffset[row] + col; |
| 6723 | *attrp = ScreenAttrs[off]; |
| 6724 | bytes[0] = ScreenLines[off]; |
| 6725 | bytes[1] = NUL; |
| 6726 | |
| 6727 | #ifdef FEAT_MBYTE |
| 6728 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 6729 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 6730 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 6731 | { |
| 6732 | bytes[0] = ScreenLines[off]; |
| 6733 | bytes[1] = ScreenLines2[off]; |
| 6734 | bytes[2] = NUL; |
| 6735 | } |
| 6736 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 6737 | { |
| 6738 | bytes[1] = ScreenLines[off + 1]; |
| 6739 | bytes[2] = NUL; |
| 6740 | } |
| 6741 | #endif |
| 6742 | } |
| 6743 | } |
| 6744 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6745 | #ifdef FEAT_MBYTE |
| 6746 | static int screen_comp_differs __ARGS((int, int*)); |
| 6747 | |
| 6748 | /* |
| 6749 | * Return TRUE if composing characters for screen posn "off" differs from |
| 6750 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 6751 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6752 | */ |
| 6753 | static int |
| 6754 | screen_comp_differs(off, u8cc) |
| 6755 | int off; |
| 6756 | int *u8cc; |
| 6757 | { |
| 6758 | int i; |
| 6759 | |
| 6760 | for (i = 0; i < Screen_mco; ++i) |
| 6761 | { |
| 6762 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 6763 | return TRUE; |
| 6764 | if (u8cc[i] == 0) |
| 6765 | break; |
| 6766 | } |
| 6767 | return FALSE; |
| 6768 | } |
| 6769 | #endif |
| 6770 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6771 | /* |
| 6772 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 6773 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 6774 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 6775 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 6776 | */ |
| 6777 | void |
| 6778 | screen_puts(text, row, col, attr) |
| 6779 | char_u *text; |
| 6780 | int row; |
| 6781 | int col; |
| 6782 | int attr; |
| 6783 | { |
| 6784 | screen_puts_len(text, -1, row, col, attr); |
| 6785 | } |
| 6786 | |
| 6787 | /* |
| 6788 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 6789 | * a NUL. |
| 6790 | */ |
| 6791 | void |
| 6792 | screen_puts_len(text, len, row, col, attr) |
| 6793 | char_u *text; |
| 6794 | int len; |
| 6795 | int row; |
| 6796 | int col; |
| 6797 | int attr; |
| 6798 | { |
| 6799 | unsigned off; |
| 6800 | char_u *ptr = text; |
| 6801 | int c; |
| 6802 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6803 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6804 | int mbyte_blen = 1; |
| 6805 | int mbyte_cells = 1; |
| 6806 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6807 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6808 | int clear_next_cell = FALSE; |
| 6809 | # ifdef FEAT_ARABIC |
| 6810 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6811 | int pc, nc, nc1; |
| 6812 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6813 | # endif |
| 6814 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6815 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6816 | int force_redraw_this; |
| 6817 | int force_redraw_next = FALSE; |
| 6818 | #endif |
| 6819 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6820 | |
| 6821 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 6822 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6823 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6824 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6825 | #ifdef FEAT_MBYTE |
| 6826 | /* When drawing over the right halve of a double-wide char clear out the |
| 6827 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6828 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6829 | # ifdef FEAT_GUI |
| 6830 | && !gui.in_use |
| 6831 | # endif |
| 6832 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6833 | { |
| 6834 | ScreenLines[off - 1] = ' '; |
| 6835 | ScreenAttrs[off - 1] = 0; |
| 6836 | if (enc_utf8) |
| 6837 | { |
| 6838 | ScreenLinesUC[off - 1] = 0; |
| 6839 | ScreenLinesC[0][off - 1] = 0; |
| 6840 | } |
| 6841 | /* redraw the previous cell, make it empty */ |
| 6842 | screen_char(off - 1, row, col - 1); |
| 6843 | /* force the cell at "col" to be redrawn */ |
| 6844 | force_redraw_next = TRUE; |
| 6845 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 6846 | #endif |
| 6847 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6848 | #ifdef FEAT_MBYTE |
| 6849 | max_off = LineOffset[row] + screen_Columns; |
| 6850 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 6851 | while (col < screen_Columns |
| 6852 | && (len < 0 || (int)(ptr - text) < len) |
| 6853 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6854 | { |
| 6855 | c = *ptr; |
| 6856 | #ifdef FEAT_MBYTE |
| 6857 | /* check if this is the first byte of a multibyte */ |
| 6858 | if (has_mbyte) |
| 6859 | { |
| 6860 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6861 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6862 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6863 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6864 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 6865 | mbyte_cells = 1; |
| 6866 | else if (enc_dbcs != 0) |
| 6867 | mbyte_cells = mbyte_blen; |
| 6868 | else /* enc_utf8 */ |
| 6869 | { |
| 6870 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6871 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6872 | (int)((text + len) - ptr)); |
| 6873 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6874 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6875 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6876 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6877 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 6878 | if (u8c >= 0x10000) |
| 6879 | { |
| 6880 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 6881 | if (attr == 0) |
| 6882 | attr = hl_attr(HLF_8); |
| 6883 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 6884 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6885 | # ifdef FEAT_ARABIC |
| 6886 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 6887 | { |
| 6888 | /* Do Arabic shaping. */ |
| 6889 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 6890 | { |
| 6891 | /* Past end of string to be displayed. */ |
| 6892 | nc = NUL; |
| 6893 | nc1 = NUL; |
| 6894 | } |
| 6895 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6896 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 6897 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 6898 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6899 | nc1 = pcc[0]; |
| 6900 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6901 | pc = prev_c; |
| 6902 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6903 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6904 | } |
| 6905 | else |
| 6906 | prev_c = u8c; |
| 6907 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 6908 | if (col + mbyte_cells > screen_Columns) |
| 6909 | { |
| 6910 | /* Only 1 cell left, but character requires 2 cells: |
| 6911 | * display a '>' in the last column to avoid wrapping. */ |
| 6912 | c = '>'; |
| 6913 | mbyte_cells = 1; |
| 6914 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6915 | } |
| 6916 | } |
| 6917 | #endif |
| 6918 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6919 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6920 | force_redraw_this = force_redraw_next; |
| 6921 | force_redraw_next = FALSE; |
| 6922 | #endif |
| 6923 | |
| 6924 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6925 | #ifdef FEAT_MBYTE |
| 6926 | || (mbyte_cells == 2 |
| 6927 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 6928 | || (enc_dbcs == DBCS_JPNU |
| 6929 | && c == 0x8e |
| 6930 | && ScreenLines2[off] != ptr[1]) |
| 6931 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 6932 | && (ScreenLinesUC[off] != |
| 6933 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 6934 | || (ScreenLinesUC[off] != 0 |
| 6935 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6936 | #endif |
| 6937 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6938 | || exmode_active; |
| 6939 | |
| 6940 | if (need_redraw |
| 6941 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 6942 | || force_redraw_this |
| 6943 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6944 | ) |
| 6945 | { |
| 6946 | #if defined(FEAT_GUI) || defined(UNIX) |
| 6947 | /* The bold trick makes a single row of pixels appear in the next |
| 6948 | * character. When a bold character is removed, the next |
| 6949 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6950 | * and for some xterms. */ |
| 6951 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6952 | # ifdef FEAT_GUI |
| 6953 | gui.in_use |
| 6954 | # endif |
| 6955 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6956 | || |
| 6957 | # endif |
| 6958 | # ifdef UNIX |
| 6959 | term_is_xterm |
| 6960 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6961 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6962 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6963 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6964 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6965 | if (n > HL_ALL) |
| 6966 | n = syn_attr2attr(n); |
| 6967 | if (n & HL_BOLD) |
| 6968 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6969 | } |
| 6970 | #endif |
| 6971 | #ifdef FEAT_MBYTE |
| 6972 | /* When at the end of the text and overwriting a two-cell |
| 6973 | * character with a one-cell character, need to clear the next |
| 6974 | * cell. Also when overwriting the left halve of a two-cell char |
| 6975 | * with the right halve of a two-cell char. Do this only once |
| 6976 | * (mb_off2cells() may return 2 on the right halve). */ |
| 6977 | if (clear_next_cell) |
| 6978 | clear_next_cell = FALSE; |
| 6979 | else if (has_mbyte |
| 6980 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 6981 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6982 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6983 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6984 | && (*mb_off2cells)(off, max_off) == 1 |
| 6985 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6986 | clear_next_cell = TRUE; |
| 6987 | |
| 6988 | /* Make sure we never leave a second byte of a double-byte behind, |
| 6989 | * it confuses mb_off2cells(). */ |
| 6990 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6991 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6992 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6993 | && (*mb_off2cells)(off, max_off) == 1 |
| 6994 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6995 | ScreenLines[off + mbyte_blen] = 0; |
| 6996 | #endif |
| 6997 | ScreenLines[off] = c; |
| 6998 | ScreenAttrs[off] = attr; |
| 6999 | #ifdef FEAT_MBYTE |
| 7000 | if (enc_utf8) |
| 7001 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7002 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7003 | ScreenLinesUC[off] = 0; |
| 7004 | else |
| 7005 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7006 | int i; |
| 7007 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7008 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7009 | for (i = 0; i < Screen_mco; ++i) |
| 7010 | { |
| 7011 | ScreenLinesC[i][off] = u8cc[i]; |
| 7012 | if (u8cc[i] == 0) |
| 7013 | break; |
| 7014 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7015 | } |
| 7016 | if (mbyte_cells == 2) |
| 7017 | { |
| 7018 | ScreenLines[off + 1] = 0; |
| 7019 | ScreenAttrs[off + 1] = attr; |
| 7020 | } |
| 7021 | screen_char(off, row, col); |
| 7022 | } |
| 7023 | else if (mbyte_cells == 2) |
| 7024 | { |
| 7025 | ScreenLines[off + 1] = ptr[1]; |
| 7026 | ScreenAttrs[off + 1] = attr; |
| 7027 | screen_char_2(off, row, col); |
| 7028 | } |
| 7029 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7030 | { |
| 7031 | ScreenLines2[off] = ptr[1]; |
| 7032 | screen_char(off, row, col); |
| 7033 | } |
| 7034 | else |
| 7035 | #endif |
| 7036 | screen_char(off, row, col); |
| 7037 | } |
| 7038 | #ifdef FEAT_MBYTE |
| 7039 | if (has_mbyte) |
| 7040 | { |
| 7041 | off += mbyte_cells; |
| 7042 | col += mbyte_cells; |
| 7043 | ptr += mbyte_blen; |
| 7044 | if (clear_next_cell) |
| 7045 | ptr = (char_u *)" "; |
| 7046 | } |
| 7047 | else |
| 7048 | #endif |
| 7049 | { |
| 7050 | ++off; |
| 7051 | ++col; |
| 7052 | ++ptr; |
| 7053 | } |
| 7054 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7055 | |
| 7056 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7057 | /* If we detected the next character needs to be redrawn, but the text |
| 7058 | * doesn't extend up to there, update the character here. */ |
| 7059 | if (force_redraw_next && col < screen_Columns) |
| 7060 | { |
| 7061 | # ifdef FEAT_MBYTE |
| 7062 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7063 | screen_char_2(off, row, col); |
| 7064 | else |
| 7065 | # endif |
| 7066 | screen_char(off, row, col); |
| 7067 | } |
| 7068 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7069 | } |
| 7070 | |
| 7071 | #ifdef FEAT_SEARCH_EXTRA |
| 7072 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7073 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7074 | */ |
| 7075 | static void |
| 7076 | start_search_hl() |
| 7077 | { |
| 7078 | if (p_hls && !no_hlsearch) |
| 7079 | { |
| 7080 | last_pat_prog(&search_hl.rm); |
| 7081 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7082 | # ifdef FEAT_RELTIME |
| 7083 | /* Set the time limit to 'redrawtime'. */ |
| 7084 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7085 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7086 | } |
| 7087 | } |
| 7088 | |
| 7089 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7090 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7091 | */ |
| 7092 | static void |
| 7093 | end_search_hl() |
| 7094 | { |
| 7095 | if (search_hl.rm.regprog != NULL) |
| 7096 | { |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7097 | vim_regfree(search_hl.rm.regprog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7098 | search_hl.rm.regprog = NULL; |
| 7099 | } |
| 7100 | } |
| 7101 | |
| 7102 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7103 | * Init for calling prepare_search_hl(). |
| 7104 | */ |
| 7105 | static void |
| 7106 | init_search_hl(wp) |
| 7107 | win_T *wp; |
| 7108 | { |
| 7109 | matchitem_T *cur; |
| 7110 | |
| 7111 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7112 | * match */ |
| 7113 | cur = wp->w_match_head; |
| 7114 | while (cur != NULL) |
| 7115 | { |
| 7116 | cur->hl.rm = cur->match; |
| 7117 | if (cur->hlg_id == 0) |
| 7118 | cur->hl.attr = 0; |
| 7119 | else |
| 7120 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7121 | cur->hl.buf = wp->w_buffer; |
| 7122 | cur->hl.lnum = 0; |
| 7123 | cur->hl.first_lnum = 0; |
| 7124 | # ifdef FEAT_RELTIME |
| 7125 | /* Set the time limit to 'redrawtime'. */ |
| 7126 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7127 | # endif |
| 7128 | cur = cur->next; |
| 7129 | } |
| 7130 | search_hl.buf = wp->w_buffer; |
| 7131 | search_hl.lnum = 0; |
| 7132 | search_hl.first_lnum = 0; |
| 7133 | /* time limit is set at the toplevel, for all windows */ |
| 7134 | } |
| 7135 | |
| 7136 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7137 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7138 | */ |
| 7139 | static void |
| 7140 | prepare_search_hl(wp, lnum) |
| 7141 | win_T *wp; |
| 7142 | linenr_T lnum; |
| 7143 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7144 | matchitem_T *cur; /* points to the match list */ |
| 7145 | match_T *shl; /* points to search_hl or a match */ |
| 7146 | int shl_flag; /* flag to indicate whether search_hl |
| 7147 | has been processed or not */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7148 | int n; |
| 7149 | |
| 7150 | /* |
| 7151 | * When using a multi-line pattern, start searching at the top |
| 7152 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7153 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7154 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7155 | cur = wp->w_match_head; |
| 7156 | shl_flag = FALSE; |
| 7157 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7158 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7159 | if (shl_flag == FALSE) |
| 7160 | { |
| 7161 | shl = &search_hl; |
| 7162 | shl_flag = TRUE; |
| 7163 | } |
| 7164 | else |
| 7165 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7166 | if (shl->rm.regprog != NULL |
| 7167 | && shl->lnum == 0 |
| 7168 | && re_multiline(shl->rm.regprog)) |
| 7169 | { |
| 7170 | if (shl->first_lnum == 0) |
| 7171 | { |
| 7172 | # ifdef FEAT_FOLDING |
| 7173 | for (shl->first_lnum = lnum; |
| 7174 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7175 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7176 | NULL, NULL, TRUE, NULL)) |
| 7177 | break; |
| 7178 | # else |
| 7179 | shl->first_lnum = wp->w_topline; |
| 7180 | # endif |
| 7181 | } |
| 7182 | n = 0; |
| 7183 | while (shl->first_lnum < lnum && shl->rm.regprog != NULL) |
| 7184 | { |
| 7185 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); |
| 7186 | if (shl->lnum != 0) |
| 7187 | { |
| 7188 | shl->first_lnum = shl->lnum |
| 7189 | + shl->rm.endpos[0].lnum |
| 7190 | - shl->rm.startpos[0].lnum; |
| 7191 | n = shl->rm.endpos[0].col; |
| 7192 | } |
| 7193 | else |
| 7194 | { |
| 7195 | ++shl->first_lnum; |
| 7196 | n = 0; |
| 7197 | } |
| 7198 | } |
| 7199 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7200 | if (shl != &search_hl && cur != NULL) |
| 7201 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7202 | } |
| 7203 | } |
| 7204 | |
| 7205 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7206 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7207 | * Uses shl->buf. |
| 7208 | * Sets shl->lnum and shl->rm contents. |
| 7209 | * Note: Assumes a previous match is always before "lnum", unless |
| 7210 | * shl->lnum is zero. |
| 7211 | * Careful: Any pointers for buffer lines will become invalid. |
| 7212 | */ |
| 7213 | static void |
| 7214 | next_search_hl(win, shl, lnum, mincol) |
| 7215 | win_T *win; |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7216 | match_T *shl; /* points to search_hl or a match */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7217 | linenr_T lnum; |
| 7218 | colnr_T mincol; /* minimal column for a match */ |
| 7219 | { |
| 7220 | linenr_T l; |
| 7221 | colnr_T matchcol; |
| 7222 | long nmatched; |
| 7223 | |
| 7224 | if (shl->lnum != 0) |
| 7225 | { |
| 7226 | /* Check for three situations: |
| 7227 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7228 | * 2. If the previous match includes "mincol", use it. |
| 7229 | * 3. Continue after the previous match. |
| 7230 | */ |
| 7231 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7232 | if (lnum > l) |
| 7233 | shl->lnum = 0; |
| 7234 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7235 | return; |
| 7236 | } |
| 7237 | |
| 7238 | /* |
| 7239 | * Repeat searching for a match until one is found that includes "mincol" |
| 7240 | * or none is found in this line. |
| 7241 | */ |
| 7242 | called_emsg = FALSE; |
| 7243 | for (;;) |
| 7244 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7245 | #ifdef FEAT_RELTIME |
| 7246 | /* Stop searching after passing the time limit. */ |
| 7247 | if (profile_passed_limit(&(shl->tm))) |
| 7248 | { |
| 7249 | shl->lnum = 0; /* no match found in time */ |
| 7250 | break; |
| 7251 | } |
| 7252 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7253 | /* Three situations: |
| 7254 | * 1. No useful previous match: search from start of line. |
| 7255 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7256 | * Break the loop if this is beyond the end of the line. |
| 7257 | * 3. Vi compatible searching: continue at end of previous match. |
| 7258 | */ |
| 7259 | if (shl->lnum == 0) |
| 7260 | matchcol = 0; |
| 7261 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7262 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7263 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7264 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7265 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7266 | |
| 7267 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7268 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7269 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7270 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7271 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7272 | shl->lnum = 0; |
| 7273 | break; |
| 7274 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7275 | #ifdef FEAT_MBYTE |
| 7276 | if (has_mbyte) |
| 7277 | matchcol += mb_ptr2len(ml); |
| 7278 | else |
| 7279 | #endif |
| 7280 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7281 | } |
| 7282 | else |
| 7283 | matchcol = shl->rm.endpos[0].col; |
| 7284 | |
| 7285 | shl->lnum = lnum; |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7286 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
| 7287 | #ifdef FEAT_RELTIME |
| 7288 | &(shl->tm) |
| 7289 | #else |
| 7290 | NULL |
| 7291 | #endif |
| 7292 | ); |
Bram Moolenaar | c7040a5 | 2010-07-20 13:11:28 +0200 | [diff] [blame] | 7293 | if (called_emsg || got_int) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7294 | { |
| 7295 | /* Error while handling regexp: stop using this regexp. */ |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7296 | if (shl == &search_hl) |
| 7297 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7298 | /* don't free regprog in the match list, it's a copy */ |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7299 | vim_regfree(shl->rm.regprog); |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7300 | no_hlsearch = TRUE; |
| 7301 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7302 | shl->rm.regprog = NULL; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7303 | shl->lnum = 0; |
| 7304 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7305 | break; |
| 7306 | } |
| 7307 | if (nmatched == 0) |
| 7308 | { |
| 7309 | shl->lnum = 0; /* no match found */ |
| 7310 | break; |
| 7311 | } |
| 7312 | if (shl->rm.startpos[0].lnum > 0 |
| 7313 | || shl->rm.startpos[0].col >= mincol |
| 7314 | || nmatched > 1 |
| 7315 | || shl->rm.endpos[0].col > mincol) |
| 7316 | { |
| 7317 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7318 | break; /* useful match found */ |
| 7319 | } |
| 7320 | } |
| 7321 | } |
| 7322 | #endif |
| 7323 | |
| 7324 | static void |
| 7325 | screen_start_highlight(attr) |
| 7326 | int attr; |
| 7327 | { |
| 7328 | attrentry_T *aep = NULL; |
| 7329 | |
| 7330 | screen_attr = attr; |
| 7331 | if (full_screen |
| 7332 | #ifdef WIN3264 |
| 7333 | && termcap_active |
| 7334 | #endif |
| 7335 | ) |
| 7336 | { |
| 7337 | #ifdef FEAT_GUI |
| 7338 | if (gui.in_use) |
| 7339 | { |
| 7340 | char buf[20]; |
| 7341 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7342 | /* The GUI handles this internally. */ |
| 7343 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7344 | OUT_STR(buf); |
| 7345 | } |
| 7346 | else |
| 7347 | #endif |
| 7348 | { |
| 7349 | if (attr > HL_ALL) /* special HL attr. */ |
| 7350 | { |
| 7351 | if (t_colors > 1) |
| 7352 | aep = syn_cterm_attr2entry(attr); |
| 7353 | else |
| 7354 | aep = syn_term_attr2entry(attr); |
| 7355 | if (aep == NULL) /* did ":syntax clear" */ |
| 7356 | attr = 0; |
| 7357 | else |
| 7358 | attr = aep->ae_attr; |
| 7359 | } |
| 7360 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7361 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7362 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 7363 | && cterm_normal_fg_bold) |
| 7364 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7365 | * has a FG color defined, clear BOLD. */ |
| 7366 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7367 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7368 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7369 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7370 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7371 | out_str(T_US); |
| 7372 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7373 | out_str(T_CZH); |
| 7374 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7375 | out_str(T_MR); |
| 7376 | |
| 7377 | /* |
| 7378 | * Output the color or start string after bold etc., in case the |
| 7379 | * bold etc. override the color setting. |
| 7380 | */ |
| 7381 | if (aep != NULL) |
| 7382 | { |
| 7383 | if (t_colors > 1) |
| 7384 | { |
| 7385 | if (aep->ae_u.cterm.fg_color) |
| 7386 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7387 | if (aep->ae_u.cterm.bg_color) |
| 7388 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7389 | } |
| 7390 | else |
| 7391 | { |
| 7392 | if (aep->ae_u.term.start != NULL) |
| 7393 | out_str(aep->ae_u.term.start); |
| 7394 | } |
| 7395 | } |
| 7396 | } |
| 7397 | } |
| 7398 | } |
| 7399 | |
| 7400 | void |
| 7401 | screen_stop_highlight() |
| 7402 | { |
| 7403 | int do_ME = FALSE; /* output T_ME code */ |
| 7404 | |
| 7405 | if (screen_attr != 0 |
| 7406 | #ifdef WIN3264 |
| 7407 | && termcap_active |
| 7408 | #endif |
| 7409 | ) |
| 7410 | { |
| 7411 | #ifdef FEAT_GUI |
| 7412 | if (gui.in_use) |
| 7413 | { |
| 7414 | char buf[20]; |
| 7415 | |
| 7416 | /* use internal GUI code */ |
| 7417 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7418 | OUT_STR(buf); |
| 7419 | } |
| 7420 | else |
| 7421 | #endif |
| 7422 | { |
| 7423 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7424 | { |
| 7425 | attrentry_T *aep; |
| 7426 | |
| 7427 | if (t_colors > 1) |
| 7428 | { |
| 7429 | /* |
| 7430 | * Assume that t_me restores the original colors! |
| 7431 | */ |
| 7432 | aep = syn_cterm_attr2entry(screen_attr); |
| 7433 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 7434 | || aep->ae_u.cterm.bg_color)) |
| 7435 | do_ME = TRUE; |
| 7436 | } |
| 7437 | else |
| 7438 | { |
| 7439 | aep = syn_term_attr2entry(screen_attr); |
| 7440 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7441 | { |
| 7442 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7443 | do_ME = TRUE; |
| 7444 | else |
| 7445 | out_str(aep->ae_u.term.stop); |
| 7446 | } |
| 7447 | } |
| 7448 | if (aep == NULL) /* did ":syntax clear" */ |
| 7449 | screen_attr = 0; |
| 7450 | else |
| 7451 | screen_attr = aep->ae_attr; |
| 7452 | } |
| 7453 | |
| 7454 | /* |
| 7455 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 7456 | * same sequence several times. |
| 7457 | */ |
| 7458 | if (screen_attr & HL_STANDOUT) |
| 7459 | { |
| 7460 | if (STRCMP(T_SE, T_ME) == 0) |
| 7461 | do_ME = TRUE; |
| 7462 | else |
| 7463 | out_str(T_SE); |
| 7464 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7465 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7466 | { |
| 7467 | if (STRCMP(T_UE, T_ME) == 0) |
| 7468 | do_ME = TRUE; |
| 7469 | else |
| 7470 | out_str(T_UE); |
| 7471 | } |
| 7472 | if (screen_attr & HL_ITALIC) |
| 7473 | { |
| 7474 | if (STRCMP(T_CZR, T_ME) == 0) |
| 7475 | do_ME = TRUE; |
| 7476 | else |
| 7477 | out_str(T_CZR); |
| 7478 | } |
| 7479 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 7480 | out_str(T_ME); |
| 7481 | |
| 7482 | if (t_colors > 1) |
| 7483 | { |
| 7484 | /* set Normal cterm colors */ |
| 7485 | if (cterm_normal_fg_color != 0) |
| 7486 | term_fg_color(cterm_normal_fg_color - 1); |
| 7487 | if (cterm_normal_bg_color != 0) |
| 7488 | term_bg_color(cterm_normal_bg_color - 1); |
| 7489 | if (cterm_normal_fg_bold) |
| 7490 | out_str(T_MD); |
| 7491 | } |
| 7492 | } |
| 7493 | } |
| 7494 | screen_attr = 0; |
| 7495 | } |
| 7496 | |
| 7497 | /* |
| 7498 | * Reset the colors for a cterm. Used when leaving Vim. |
| 7499 | * The machine specific code may override this again. |
| 7500 | */ |
| 7501 | void |
| 7502 | reset_cterm_colors() |
| 7503 | { |
| 7504 | if (t_colors > 1) |
| 7505 | { |
| 7506 | /* set Normal cterm colors */ |
| 7507 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 7508 | { |
| 7509 | out_str(T_OP); |
| 7510 | screen_attr = -1; |
| 7511 | } |
| 7512 | if (cterm_normal_fg_bold) |
| 7513 | { |
| 7514 | out_str(T_ME); |
| 7515 | screen_attr = -1; |
| 7516 | } |
| 7517 | } |
| 7518 | } |
| 7519 | |
| 7520 | /* |
| 7521 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 7522 | * using the attributes from ScreenAttrs["off"]. |
| 7523 | */ |
| 7524 | static void |
| 7525 | screen_char(off, row, col) |
| 7526 | unsigned off; |
| 7527 | int row; |
| 7528 | int col; |
| 7529 | { |
| 7530 | int attr; |
| 7531 | |
| 7532 | /* Check for illegal values, just in case (could happen just after |
| 7533 | * resizing). */ |
| 7534 | if (row >= screen_Rows || col >= screen_Columns) |
| 7535 | return; |
| 7536 | |
| 7537 | /* Outputting the last character on the screen may scrollup the screen. |
| 7538 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 7539 | if (row == screen_Rows - 1 && col == screen_Columns - 1 |
| 7540 | #ifdef FEAT_RIGHTLEFT |
| 7541 | /* account for first command-line character in rightleft mode */ |
| 7542 | && !cmdmsg_rl |
| 7543 | #endif |
| 7544 | ) |
| 7545 | { |
| 7546 | ScreenAttrs[off] = (sattr_T)-1; |
| 7547 | return; |
| 7548 | } |
| 7549 | |
| 7550 | /* |
| 7551 | * Stop highlighting first, so it's easier to move the cursor. |
| 7552 | */ |
| 7553 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 7554 | if (screen_char_attr != 0) |
| 7555 | attr = screen_char_attr; |
| 7556 | else |
| 7557 | #endif |
| 7558 | attr = ScreenAttrs[off]; |
| 7559 | if (screen_attr != attr) |
| 7560 | screen_stop_highlight(); |
| 7561 | |
| 7562 | windgoto(row, col); |
| 7563 | |
| 7564 | if (screen_attr != attr) |
| 7565 | screen_start_highlight(attr); |
| 7566 | |
| 7567 | #ifdef FEAT_MBYTE |
| 7568 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7569 | { |
| 7570 | char_u buf[MB_MAXBYTES + 1]; |
| 7571 | |
| 7572 | /* Convert UTF-8 character to bytes and write it. */ |
| 7573 | |
| 7574 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 7575 | |
| 7576 | out_str(buf); |
| 7577 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 7578 | ++screen_cur_col; |
| 7579 | } |
| 7580 | else |
| 7581 | #endif |
| 7582 | { |
| 7583 | #ifdef FEAT_MBYTE |
| 7584 | out_flush_check(); |
| 7585 | #endif |
| 7586 | out_char(ScreenLines[off]); |
| 7587 | #ifdef FEAT_MBYTE |
| 7588 | /* double-byte character in single-width cell */ |
| 7589 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7590 | out_char(ScreenLines2[off]); |
| 7591 | #endif |
| 7592 | } |
| 7593 | |
| 7594 | screen_cur_col++; |
| 7595 | } |
| 7596 | |
| 7597 | #ifdef FEAT_MBYTE |
| 7598 | |
| 7599 | /* |
| 7600 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 7601 | * on the screen at position 'row' and 'col'. |
| 7602 | * The attributes of the first byte is used for all. This is required to |
| 7603 | * output the two bytes of a double-byte character with nothing in between. |
| 7604 | */ |
| 7605 | static void |
| 7606 | screen_char_2(off, row, col) |
| 7607 | unsigned off; |
| 7608 | int row; |
| 7609 | int col; |
| 7610 | { |
| 7611 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 7612 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 7613 | return; |
| 7614 | |
| 7615 | /* Outputting the last character on the screen may scrollup the screen. |
| 7616 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 7617 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 7618 | { |
| 7619 | ScreenAttrs[off] = (sattr_T)-1; |
| 7620 | return; |
| 7621 | } |
| 7622 | |
| 7623 | /* Output the first byte normally (positions the cursor), then write the |
| 7624 | * second byte directly. */ |
| 7625 | screen_char(off, row, col); |
| 7626 | out_char(ScreenLines[off + 1]); |
| 7627 | ++screen_cur_col; |
| 7628 | } |
| 7629 | #endif |
| 7630 | |
| 7631 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 7632 | /* |
| 7633 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 7634 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 7635 | */ |
| 7636 | void |
| 7637 | screen_draw_rectangle(row, col, height, width, invert) |
| 7638 | int row; |
| 7639 | int col; |
| 7640 | int height; |
| 7641 | int width; |
| 7642 | int invert; |
| 7643 | { |
| 7644 | int r, c; |
| 7645 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7646 | #ifdef FEAT_MBYTE |
| 7647 | int max_off; |
| 7648 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7649 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 7650 | /* Can't use ScreenLines unless initialized */ |
| 7651 | if (ScreenLines == NULL) |
| 7652 | return; |
| 7653 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7654 | if (invert) |
| 7655 | screen_char_attr = HL_INVERSE; |
| 7656 | for (r = row; r < row + height; ++r) |
| 7657 | { |
| 7658 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7659 | #ifdef FEAT_MBYTE |
| 7660 | max_off = off + screen_Columns; |
| 7661 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7662 | for (c = col; c < col + width; ++c) |
| 7663 | { |
| 7664 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7665 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7666 | { |
| 7667 | screen_char_2(off + c, r, c); |
| 7668 | ++c; |
| 7669 | } |
| 7670 | else |
| 7671 | #endif |
| 7672 | { |
| 7673 | screen_char(off + c, r, c); |
| 7674 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7675 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7676 | ++c; |
| 7677 | #endif |
| 7678 | } |
| 7679 | } |
| 7680 | } |
| 7681 | screen_char_attr = 0; |
| 7682 | } |
| 7683 | #endif |
| 7684 | |
| 7685 | #ifdef FEAT_VERTSPLIT |
| 7686 | /* |
| 7687 | * Redraw the characters for a vertically split window. |
| 7688 | */ |
| 7689 | static void |
| 7690 | redraw_block(row, end, wp) |
| 7691 | int row; |
| 7692 | int end; |
| 7693 | win_T *wp; |
| 7694 | { |
| 7695 | int col; |
| 7696 | int width; |
| 7697 | |
| 7698 | # ifdef FEAT_CLIPBOARD |
| 7699 | clip_may_clear_selection(row, end - 1); |
| 7700 | # endif |
| 7701 | |
| 7702 | if (wp == NULL) |
| 7703 | { |
| 7704 | col = 0; |
| 7705 | width = Columns; |
| 7706 | } |
| 7707 | else |
| 7708 | { |
| 7709 | col = wp->w_wincol; |
| 7710 | width = wp->w_width; |
| 7711 | } |
| 7712 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 7713 | } |
| 7714 | #endif |
| 7715 | |
| 7716 | /* |
| 7717 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 7718 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 7719 | * Use attributes 'attr'. |
| 7720 | */ |
| 7721 | void |
| 7722 | screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) |
| 7723 | int start_row, end_row; |
| 7724 | int start_col, end_col; |
| 7725 | int c1, c2; |
| 7726 | int attr; |
| 7727 | { |
| 7728 | int row; |
| 7729 | int col; |
| 7730 | int off; |
| 7731 | int end_off; |
| 7732 | int did_delete; |
| 7733 | int c; |
| 7734 | int norm_term; |
| 7735 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7736 | int force_next = FALSE; |
| 7737 | #endif |
| 7738 | |
| 7739 | if (end_row > screen_Rows) /* safety check */ |
| 7740 | end_row = screen_Rows; |
| 7741 | if (end_col > screen_Columns) /* safety check */ |
| 7742 | end_col = screen_Columns; |
| 7743 | if (ScreenLines == NULL |
| 7744 | || start_row >= end_row |
| 7745 | || start_col >= end_col) /* nothing to do */ |
| 7746 | return; |
| 7747 | |
| 7748 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 7749 | norm_term = ( |
| 7750 | #ifdef FEAT_GUI |
| 7751 | !gui.in_use && |
| 7752 | #endif |
| 7753 | t_colors <= 1); |
| 7754 | for (row = start_row; row < end_row; ++row) |
| 7755 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7756 | #ifdef FEAT_MBYTE |
| 7757 | if (has_mbyte |
| 7758 | # ifdef FEAT_GUI |
| 7759 | && !gui.in_use |
| 7760 | # endif |
| 7761 | ) |
| 7762 | { |
| 7763 | /* When drawing over the right halve of a double-wide char clear |
| 7764 | * out the left halve. When drawing over the left halve of a |
| 7765 | * double wide-char clear out the right halve. Only needed in a |
| 7766 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7767 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 7768 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 7769 | 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] | 7770 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7771 | } |
| 7772 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7773 | /* |
| 7774 | * Try to use delete-line termcap code, when no attributes or in a |
| 7775 | * "normal" terminal, where a bold/italic space is just a |
| 7776 | * space. |
| 7777 | */ |
| 7778 | did_delete = FALSE; |
| 7779 | if (c2 == ' ' |
| 7780 | && end_col == Columns |
| 7781 | && can_clear(T_CE) |
| 7782 | && (attr == 0 |
| 7783 | || (norm_term |
| 7784 | && attr <= HL_ALL |
| 7785 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 7786 | { |
| 7787 | /* |
| 7788 | * check if we really need to clear something |
| 7789 | */ |
| 7790 | col = start_col; |
| 7791 | if (c1 != ' ') /* don't clear first char */ |
| 7792 | ++col; |
| 7793 | |
| 7794 | off = LineOffset[row] + col; |
| 7795 | end_off = LineOffset[row] + end_col; |
| 7796 | |
| 7797 | /* skip blanks (used often, keep it fast!) */ |
| 7798 | #ifdef FEAT_MBYTE |
| 7799 | if (enc_utf8) |
| 7800 | while (off < end_off && ScreenLines[off] == ' ' |
| 7801 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 7802 | ++off; |
| 7803 | else |
| 7804 | #endif |
| 7805 | while (off < end_off && ScreenLines[off] == ' ' |
| 7806 | && ScreenAttrs[off] == 0) |
| 7807 | ++off; |
| 7808 | if (off < end_off) /* something to be cleared */ |
| 7809 | { |
| 7810 | col = off - LineOffset[row]; |
| 7811 | screen_stop_highlight(); |
| 7812 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 7813 | out_str(T_CE); |
| 7814 | screen_start(); /* don't know where cursor is now */ |
| 7815 | col = end_col - col; |
| 7816 | while (col--) /* clear chars in ScreenLines */ |
| 7817 | { |
| 7818 | ScreenLines[off] = ' '; |
| 7819 | #ifdef FEAT_MBYTE |
| 7820 | if (enc_utf8) |
| 7821 | ScreenLinesUC[off] = 0; |
| 7822 | #endif |
| 7823 | ScreenAttrs[off] = 0; |
| 7824 | ++off; |
| 7825 | } |
| 7826 | } |
| 7827 | did_delete = TRUE; /* the chars are cleared now */ |
| 7828 | } |
| 7829 | |
| 7830 | off = LineOffset[row] + start_col; |
| 7831 | c = c1; |
| 7832 | for (col = start_col; col < end_col; ++col) |
| 7833 | { |
| 7834 | if (ScreenLines[off] != c |
| 7835 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7836 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 7837 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7838 | #endif |
| 7839 | || ScreenAttrs[off] != attr |
| 7840 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7841 | || force_next |
| 7842 | #endif |
| 7843 | ) |
| 7844 | { |
| 7845 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7846 | /* The bold trick may make a single row of pixels appear in |
| 7847 | * the next character. When a bold character is removed, the |
| 7848 | * next character should be redrawn too. This happens for our |
| 7849 | * own GUI and for some xterms. */ |
| 7850 | if ( |
| 7851 | # ifdef FEAT_GUI |
| 7852 | gui.in_use |
| 7853 | # endif |
| 7854 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7855 | || |
| 7856 | # endif |
| 7857 | # ifdef UNIX |
| 7858 | term_is_xterm |
| 7859 | # endif |
| 7860 | ) |
| 7861 | { |
| 7862 | if (ScreenLines[off] != ' ' |
| 7863 | && (ScreenAttrs[off] > HL_ALL |
| 7864 | || ScreenAttrs[off] & HL_BOLD)) |
| 7865 | force_next = TRUE; |
| 7866 | else |
| 7867 | force_next = FALSE; |
| 7868 | } |
| 7869 | #endif |
| 7870 | ScreenLines[off] = c; |
| 7871 | #ifdef FEAT_MBYTE |
| 7872 | if (enc_utf8) |
| 7873 | { |
| 7874 | if (c >= 0x80) |
| 7875 | { |
| 7876 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7877 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7878 | } |
| 7879 | else |
| 7880 | ScreenLinesUC[off] = 0; |
| 7881 | } |
| 7882 | #endif |
| 7883 | ScreenAttrs[off] = attr; |
| 7884 | if (!did_delete || c != ' ') |
| 7885 | screen_char(off, row, col); |
| 7886 | } |
| 7887 | ++off; |
| 7888 | if (col == start_col) |
| 7889 | { |
| 7890 | if (did_delete) |
| 7891 | break; |
| 7892 | c = c2; |
| 7893 | } |
| 7894 | } |
| 7895 | if (end_col == Columns) |
| 7896 | LineWraps[row] = FALSE; |
| 7897 | if (row == Rows - 1) /* overwritten the command line */ |
| 7898 | { |
| 7899 | redraw_cmdline = TRUE; |
| 7900 | if (c1 == ' ' && c2 == ' ') |
| 7901 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 7902 | if (start_col == 0) |
| 7903 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7904 | } |
| 7905 | } |
| 7906 | } |
| 7907 | |
| 7908 | /* |
| 7909 | * Check if there should be a delay. Used before clearing or redrawing the |
| 7910 | * screen or the command line. |
| 7911 | */ |
| 7912 | void |
| 7913 | check_for_delay(check_msg_scroll) |
| 7914 | int check_msg_scroll; |
| 7915 | { |
| 7916 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 7917 | && !did_wait_return |
| 7918 | && emsg_silent == 0) |
| 7919 | { |
| 7920 | out_flush(); |
| 7921 | ui_delay(1000L, TRUE); |
| 7922 | emsg_on_display = FALSE; |
| 7923 | if (check_msg_scroll) |
| 7924 | msg_scroll = FALSE; |
| 7925 | } |
| 7926 | } |
| 7927 | |
| 7928 | /* |
| 7929 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7930 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7931 | * Returns TRUE if there is a valid screen to write to. |
| 7932 | * Returns FALSE when starting up and screen not initialized yet. |
| 7933 | */ |
| 7934 | int |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7935 | screen_valid(doclear) |
| 7936 | int doclear; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7937 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7938 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7939 | return (ScreenLines != NULL); |
| 7940 | } |
| 7941 | |
| 7942 | /* |
| 7943 | * Resize the shell to Rows and Columns. |
| 7944 | * Allocate ScreenLines[] and associated items. |
| 7945 | * |
| 7946 | * There may be some time between setting Rows and Columns and (re)allocating |
| 7947 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 7948 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 7949 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 7950 | * final size of the shell is needed. |
| 7951 | */ |
| 7952 | void |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 7953 | screenalloc(doclear) |
| 7954 | int doclear; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7955 | { |
| 7956 | int new_row, old_row; |
| 7957 | #ifdef FEAT_GUI |
| 7958 | int old_Rows; |
| 7959 | #endif |
| 7960 | win_T *wp; |
| 7961 | int outofmem = FALSE; |
| 7962 | int len; |
| 7963 | schar_T *new_ScreenLines; |
| 7964 | #ifdef FEAT_MBYTE |
| 7965 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7966 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7967 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7968 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7969 | #endif |
| 7970 | sattr_T *new_ScreenAttrs; |
| 7971 | unsigned *new_LineOffset; |
| 7972 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7973 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7974 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 7975 | tabpage_T *tp; |
| 7976 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7977 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 7978 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 7979 | #ifdef FEAT_AUTOCMD |
| 7980 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7981 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 7982 | retry: |
| 7983 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7984 | /* |
| 7985 | * Allocation of the screen buffers is done only when the size changes and |
| 7986 | * when Rows and Columns have been set and we have started doing full |
| 7987 | * screen stuff. |
| 7988 | */ |
| 7989 | if ((ScreenLines != NULL |
| 7990 | && Rows == screen_Rows |
| 7991 | && Columns == screen_Columns |
| 7992 | #ifdef FEAT_MBYTE |
| 7993 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 7994 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7995 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7996 | #endif |
| 7997 | ) |
| 7998 | || Rows == 0 |
| 7999 | || Columns == 0 |
| 8000 | || (!full_screen && ScreenLines == NULL)) |
| 8001 | return; |
| 8002 | |
| 8003 | /* |
| 8004 | * It's possible that we produce an out-of-memory message below, which |
| 8005 | * will cause this function to be called again. To break the loop, just |
| 8006 | * return here. |
| 8007 | */ |
| 8008 | if (entered) |
| 8009 | return; |
| 8010 | entered = TRUE; |
| 8011 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8012 | /* |
| 8013 | * Note that the window sizes are updated before reallocating the arrays, |
| 8014 | * thus we must not redraw here! |
| 8015 | */ |
| 8016 | ++RedrawingDisabled; |
| 8017 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8018 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 8019 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8020 | comp_col(); /* recompute columns for shown command and ruler */ |
| 8021 | |
| 8022 | /* |
| 8023 | * We're changing the size of the screen. |
| 8024 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 8025 | * - Move lines from the old arrays into the new arrays, clear extra |
| 8026 | * lines (unless the screen is going to be cleared). |
| 8027 | * - Free the old arrays. |
| 8028 | * |
| 8029 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 8030 | * Continuing with the old ScreenLines may result in a crash, because the |
| 8031 | * size is wrong. |
| 8032 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8033 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8034 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8035 | #ifdef FEAT_AUTOCMD |
| 8036 | if (aucmd_win != NULL) |
| 8037 | win_free_lsize(aucmd_win); |
| 8038 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8039 | |
| 8040 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 8041 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8042 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 8043 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8044 | if (enc_utf8) |
| 8045 | { |
| 8046 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 8047 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8048 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 8049 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8050 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8051 | } |
| 8052 | if (enc_dbcs == DBCS_JPNU) |
| 8053 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8054 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8055 | #endif |
| 8056 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8057 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8058 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8059 | Rows * sizeof(unsigned)), FALSE); |
| 8060 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8061 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8062 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8063 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8064 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8065 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8066 | { |
| 8067 | if (win_alloc_lines(wp) == FAIL) |
| 8068 | { |
| 8069 | outofmem = TRUE; |
| 8070 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8071 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8072 | #endif |
| 8073 | } |
| 8074 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8075 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8076 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8077 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8078 | outofmem = TRUE; |
| 8079 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8080 | #ifdef FEAT_WINDOWS |
| 8081 | give_up: |
| 8082 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8083 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8084 | #ifdef FEAT_MBYTE |
| 8085 | for (i = 0; i < p_mco; ++i) |
| 8086 | if (new_ScreenLinesC[i] == NULL) |
| 8087 | break; |
| 8088 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8089 | if (new_ScreenLines == NULL |
| 8090 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8091 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8092 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8093 | #endif |
| 8094 | || new_ScreenAttrs == NULL |
| 8095 | || new_LineOffset == NULL |
| 8096 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8097 | #ifdef FEAT_WINDOWS |
| 8098 | || new_TabPageIdxs == NULL |
| 8099 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8100 | || outofmem) |
| 8101 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8102 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8103 | { |
| 8104 | /* guess the size */ |
| 8105 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8106 | |
| 8107 | /* Remember we did this to avoid getting outofmem messages over |
| 8108 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8109 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8110 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8111 | vim_free(new_ScreenLines); |
| 8112 | new_ScreenLines = NULL; |
| 8113 | #ifdef FEAT_MBYTE |
| 8114 | vim_free(new_ScreenLinesUC); |
| 8115 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8116 | for (i = 0; i < p_mco; ++i) |
| 8117 | { |
| 8118 | vim_free(new_ScreenLinesC[i]); |
| 8119 | new_ScreenLinesC[i] = NULL; |
| 8120 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8121 | vim_free(new_ScreenLines2); |
| 8122 | new_ScreenLines2 = NULL; |
| 8123 | #endif |
| 8124 | vim_free(new_ScreenAttrs); |
| 8125 | new_ScreenAttrs = NULL; |
| 8126 | vim_free(new_LineOffset); |
| 8127 | new_LineOffset = NULL; |
| 8128 | vim_free(new_LineWraps); |
| 8129 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8130 | #ifdef FEAT_WINDOWS |
| 8131 | vim_free(new_TabPageIdxs); |
| 8132 | new_TabPageIdxs = NULL; |
| 8133 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8134 | } |
| 8135 | else |
| 8136 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8137 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8138 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8139 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8140 | { |
| 8141 | new_LineOffset[new_row] = new_row * Columns; |
| 8142 | new_LineWraps[new_row] = FALSE; |
| 8143 | |
| 8144 | /* |
| 8145 | * If the screen is not going to be cleared, copy as much as |
| 8146 | * possible from the old screen to the new one and clear the rest |
| 8147 | * (used when resizing the window at the "--more--" prompt or when |
| 8148 | * executing an external command, for the GUI). |
| 8149 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8150 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8151 | { |
| 8152 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8153 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8154 | #ifdef FEAT_MBYTE |
| 8155 | if (enc_utf8) |
| 8156 | { |
| 8157 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8158 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8159 | for (i = 0; i < p_mco; ++i) |
| 8160 | (void)vim_memset(new_ScreenLinesC[i] |
| 8161 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8162 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8163 | } |
| 8164 | if (enc_dbcs == DBCS_JPNU) |
| 8165 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8166 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8167 | #endif |
| 8168 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8169 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8170 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8171 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8172 | { |
| 8173 | if (screen_Columns < Columns) |
| 8174 | len = screen_Columns; |
| 8175 | else |
| 8176 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8177 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8178 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8179 | * may be invalid now. Also when p_mco changes. */ |
| 8180 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8181 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8182 | #endif |
| 8183 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8184 | ScreenLines + LineOffset[old_row], |
| 8185 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8186 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8187 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8188 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8189 | { |
| 8190 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8191 | ScreenLinesUC + LineOffset[old_row], |
| 8192 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8193 | for (i = 0; i < p_mco; ++i) |
| 8194 | mch_memmove(new_ScreenLinesC[i] |
| 8195 | + new_LineOffset[new_row], |
| 8196 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8197 | (size_t)len * sizeof(u8char_T)); |
| 8198 | } |
| 8199 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8200 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8201 | ScreenLines2 + LineOffset[old_row], |
| 8202 | (size_t)len * sizeof(schar_T)); |
| 8203 | #endif |
| 8204 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8205 | ScreenAttrs + LineOffset[old_row], |
| 8206 | (size_t)len * sizeof(sattr_T)); |
| 8207 | } |
| 8208 | } |
| 8209 | } |
| 8210 | /* Use the last line of the screen for the current line. */ |
| 8211 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8212 | } |
| 8213 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8214 | free_screenlines(); |
| 8215 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8216 | ScreenLines = new_ScreenLines; |
| 8217 | #ifdef FEAT_MBYTE |
| 8218 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8219 | for (i = 0; i < p_mco; ++i) |
| 8220 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8221 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8222 | ScreenLines2 = new_ScreenLines2; |
| 8223 | #endif |
| 8224 | ScreenAttrs = new_ScreenAttrs; |
| 8225 | LineOffset = new_LineOffset; |
| 8226 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8227 | #ifdef FEAT_WINDOWS |
| 8228 | TabPageIdxs = new_TabPageIdxs; |
| 8229 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8230 | |
| 8231 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8232 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8233 | #ifdef FEAT_GUI |
| 8234 | old_Rows = screen_Rows; |
| 8235 | #endif |
| 8236 | screen_Rows = Rows; |
| 8237 | screen_Columns = Columns; |
| 8238 | |
| 8239 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8240 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8241 | screenclear2(); |
| 8242 | |
| 8243 | #ifdef FEAT_GUI |
| 8244 | else if (gui.in_use |
| 8245 | && !gui.starting |
| 8246 | && ScreenLines != NULL |
| 8247 | && old_Rows != Rows) |
| 8248 | { |
| 8249 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8250 | /* |
| 8251 | * Adjust the position of the cursor, for when executing an external |
| 8252 | * command. |
| 8253 | */ |
| 8254 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8255 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8256 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8257 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8258 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8259 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8260 | } |
| 8261 | #endif |
| 8262 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8263 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8264 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8265 | |
| 8266 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8267 | /* |
| 8268 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8269 | * in case applying autocommands always changes Rows or Columns. |
| 8270 | */ |
| 8271 | if (starting == 0 && ++retry_count <= 3) |
| 8272 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8273 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8274 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8275 | * jump back to check if we need to allocate the screen again. */ |
| 8276 | goto retry; |
| 8277 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8278 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | void |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8282 | free_screenlines() |
| 8283 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8284 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8285 | int i; |
| 8286 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8287 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8288 | for (i = 0; i < Screen_mco; ++i) |
| 8289 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8290 | vim_free(ScreenLines2); |
| 8291 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8292 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8293 | vim_free(ScreenAttrs); |
| 8294 | vim_free(LineOffset); |
| 8295 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8296 | #ifdef FEAT_WINDOWS |
| 8297 | vim_free(TabPageIdxs); |
| 8298 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8299 | } |
| 8300 | |
| 8301 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8302 | screenclear() |
| 8303 | { |
| 8304 | check_for_delay(FALSE); |
| 8305 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8306 | screenclear2(); /* clear the screen */ |
| 8307 | } |
| 8308 | |
| 8309 | static void |
| 8310 | screenclear2() |
| 8311 | { |
| 8312 | int i; |
| 8313 | |
| 8314 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8315 | #ifdef FEAT_GUI |
| 8316 | || (gui.in_use && gui.starting) |
| 8317 | #endif |
| 8318 | ) |
| 8319 | return; |
| 8320 | |
| 8321 | #ifdef FEAT_GUI |
| 8322 | if (!gui.in_use) |
| 8323 | #endif |
| 8324 | screen_attr = -1; /* force setting the Normal colors */ |
| 8325 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8326 | |
| 8327 | #ifdef FEAT_CLIPBOARD |
| 8328 | /* disable selection without redrawing it */ |
| 8329 | clip_scroll_selection(9999); |
| 8330 | #endif |
| 8331 | |
| 8332 | /* blank out ScreenLines */ |
| 8333 | for (i = 0; i < Rows; ++i) |
| 8334 | { |
| 8335 | lineclear(LineOffset[i], (int)Columns); |
| 8336 | LineWraps[i] = FALSE; |
| 8337 | } |
| 8338 | |
| 8339 | if (can_clear(T_CL)) |
| 8340 | { |
| 8341 | out_str(T_CL); /* clear the display */ |
| 8342 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8343 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8344 | } |
| 8345 | else |
| 8346 | { |
| 8347 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8348 | for (i = 0; i < Rows; ++i) |
| 8349 | lineinvalid(LineOffset[i], (int)Columns); |
| 8350 | clear_cmdline = TRUE; |
| 8351 | } |
| 8352 | |
| 8353 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8354 | |
| 8355 | win_rest_invalid(firstwin); |
| 8356 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8357 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8358 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8359 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8360 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8361 | must_redraw = NOT_VALID; |
| 8362 | compute_cmdrow(); |
| 8363 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8364 | msg_col = 0; |
| 8365 | screen_start(); /* don't know where cursor is now */ |
| 8366 | msg_scrolled = 0; /* can't scroll back */ |
| 8367 | msg_didany = FALSE; |
| 8368 | msg_didout = FALSE; |
| 8369 | } |
| 8370 | |
| 8371 | /* |
| 8372 | * Clear one line in ScreenLines. |
| 8373 | */ |
| 8374 | static void |
| 8375 | lineclear(off, width) |
| 8376 | unsigned off; |
| 8377 | int width; |
| 8378 | { |
| 8379 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8380 | #ifdef FEAT_MBYTE |
| 8381 | if (enc_utf8) |
| 8382 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8383 | (size_t)width * sizeof(u8char_T)); |
| 8384 | #endif |
| 8385 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8386 | } |
| 8387 | |
| 8388 | /* |
| 8389 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8390 | * invalid value. |
| 8391 | */ |
| 8392 | static void |
| 8393 | lineinvalid(off, width) |
| 8394 | unsigned off; |
| 8395 | int width; |
| 8396 | { |
| 8397 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8398 | } |
| 8399 | |
| 8400 | #ifdef FEAT_VERTSPLIT |
| 8401 | /* |
| 8402 | * Copy part of a Screenline for vertically split window "wp". |
| 8403 | */ |
| 8404 | static void |
| 8405 | linecopy(to, from, wp) |
| 8406 | int to; |
| 8407 | int from; |
| 8408 | win_T *wp; |
| 8409 | { |
| 8410 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8411 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8412 | |
| 8413 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8414 | wp->w_width * sizeof(schar_T)); |
| 8415 | # ifdef FEAT_MBYTE |
| 8416 | if (enc_utf8) |
| 8417 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8418 | int i; |
| 8419 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8420 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8421 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8422 | for (i = 0; i < p_mco; ++i) |
| 8423 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8424 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8425 | } |
| 8426 | if (enc_dbcs == DBCS_JPNU) |
| 8427 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8428 | wp->w_width * sizeof(schar_T)); |
| 8429 | # endif |
| 8430 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8431 | wp->w_width * sizeof(sattr_T)); |
| 8432 | } |
| 8433 | #endif |
| 8434 | |
| 8435 | /* |
| 8436 | * Return TRUE if clearing with term string "p" would work. |
| 8437 | * It can't work when the string is empty or it won't set the right background. |
| 8438 | */ |
| 8439 | int |
| 8440 | can_clear(p) |
| 8441 | char_u *p; |
| 8442 | { |
| 8443 | return (*p != NUL && (t_colors <= 1 |
| 8444 | #ifdef FEAT_GUI |
| 8445 | || gui.in_use |
| 8446 | #endif |
| 8447 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 8448 | } |
| 8449 | |
| 8450 | /* |
| 8451 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 8452 | * something directly to the screen (shell commands) or a terminal control |
| 8453 | * code. |
| 8454 | */ |
| 8455 | void |
| 8456 | screen_start() |
| 8457 | { |
| 8458 | screen_cur_row = screen_cur_col = 9999; |
| 8459 | } |
| 8460 | |
| 8461 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8462 | * Move the cursor to position "row","col" in the screen. |
| 8463 | * This tries to find the most efficient way to move, minimizing the number of |
| 8464 | * characters sent to the terminal. |
| 8465 | */ |
| 8466 | void |
| 8467 | windgoto(row, col) |
| 8468 | int row; |
| 8469 | int col; |
| 8470 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8471 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8472 | int i; |
| 8473 | int plan; |
| 8474 | int cost; |
| 8475 | int wouldbe_col; |
| 8476 | int noinvcurs; |
| 8477 | char_u *bs; |
| 8478 | int goto_cost; |
| 8479 | int attr; |
| 8480 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8481 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8482 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 8483 | |
| 8484 | #define PLAN_LE 1 |
| 8485 | #define PLAN_CR 2 |
| 8486 | #define PLAN_NL 3 |
| 8487 | #define PLAN_WRITE 4 |
| 8488 | /* Can't use ScreenLines unless initialized */ |
| 8489 | if (ScreenLines == NULL) |
| 8490 | return; |
| 8491 | |
| 8492 | if (col != screen_cur_col || row != screen_cur_row) |
| 8493 | { |
| 8494 | /* Check for valid position. */ |
| 8495 | if (row < 0) /* window without text lines? */ |
| 8496 | row = 0; |
| 8497 | if (row >= screen_Rows) |
| 8498 | row = screen_Rows - 1; |
| 8499 | if (col >= screen_Columns) |
| 8500 | col = screen_Columns - 1; |
| 8501 | |
| 8502 | /* check if no cursor movement is allowed in highlight mode */ |
| 8503 | if (screen_attr && *T_MS == NUL) |
| 8504 | noinvcurs = HIGHL_COST; |
| 8505 | else |
| 8506 | noinvcurs = 0; |
| 8507 | goto_cost = GOTO_COST + noinvcurs; |
| 8508 | |
| 8509 | /* |
| 8510 | * Plan how to do the positioning: |
| 8511 | * 1. Use CR to move it to column 0, same row. |
| 8512 | * 2. Use T_LE to move it a few columns to the left. |
| 8513 | * 3. Use NL to move a few lines down, column 0. |
| 8514 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 8515 | * |
| 8516 | * Don't do this if the cursor went beyond the last column, the cursor |
| 8517 | * position is unknown then (some terminals wrap, some don't ) |
| 8518 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8519 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8520 | * characters to move the cursor to the right. |
| 8521 | */ |
| 8522 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 8523 | { |
| 8524 | /* |
| 8525 | * If the cursor is in the same row, bigger col, we can use CR |
| 8526 | * or T_LE. |
| 8527 | */ |
| 8528 | bs = NULL; /* init for GCC */ |
| 8529 | attr = screen_attr; |
| 8530 | if (row == screen_cur_row && col < screen_cur_col) |
| 8531 | { |
| 8532 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 8533 | if (*T_LE) |
| 8534 | bs = T_LE; /* "cursor left" */ |
| 8535 | else |
| 8536 | bs = T_BC; /* "backspace character (old) */ |
| 8537 | if (*bs) |
| 8538 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 8539 | else |
| 8540 | cost = 999; |
| 8541 | if (col + 1 < cost) /* using CR is less characters */ |
| 8542 | { |
| 8543 | plan = PLAN_CR; |
| 8544 | wouldbe_col = 0; |
| 8545 | cost = 1; /* CR is just one character */ |
| 8546 | } |
| 8547 | else |
| 8548 | { |
| 8549 | plan = PLAN_LE; |
| 8550 | wouldbe_col = col; |
| 8551 | } |
| 8552 | if (noinvcurs) /* will stop highlighting */ |
| 8553 | { |
| 8554 | cost += noinvcurs; |
| 8555 | attr = 0; |
| 8556 | } |
| 8557 | } |
| 8558 | |
| 8559 | /* |
| 8560 | * If the cursor is above where we want to be, we can use CR LF. |
| 8561 | */ |
| 8562 | else if (row > screen_cur_row) |
| 8563 | { |
| 8564 | plan = PLAN_NL; |
| 8565 | wouldbe_col = 0; |
| 8566 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 8567 | if (noinvcurs) /* will stop highlighting */ |
| 8568 | { |
| 8569 | cost += noinvcurs; |
| 8570 | attr = 0; |
| 8571 | } |
| 8572 | } |
| 8573 | |
| 8574 | /* |
| 8575 | * If the cursor is in the same row, smaller col, just use write. |
| 8576 | */ |
| 8577 | else |
| 8578 | { |
| 8579 | plan = PLAN_WRITE; |
| 8580 | wouldbe_col = screen_cur_col; |
| 8581 | cost = 0; |
| 8582 | } |
| 8583 | |
| 8584 | /* |
| 8585 | * Check if any characters that need to be written have the |
| 8586 | * correct attributes. Also avoid UTF-8 characters. |
| 8587 | */ |
| 8588 | i = col - wouldbe_col; |
| 8589 | if (i > 0) |
| 8590 | cost += i; |
| 8591 | if (cost < goto_cost && i > 0) |
| 8592 | { |
| 8593 | /* |
| 8594 | * Check if the attributes are correct without additionally |
| 8595 | * stopping highlighting. |
| 8596 | */ |
| 8597 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 8598 | while (i && *p++ == attr) |
| 8599 | --i; |
| 8600 | if (i != 0) |
| 8601 | { |
| 8602 | /* |
| 8603 | * Try if it works when highlighting is stopped here. |
| 8604 | */ |
| 8605 | if (*--p == 0) |
| 8606 | { |
| 8607 | cost += noinvcurs; |
| 8608 | while (i && *p++ == 0) |
| 8609 | --i; |
| 8610 | } |
| 8611 | if (i != 0) |
| 8612 | cost = 999; /* different attributes, don't do it */ |
| 8613 | } |
| 8614 | #ifdef FEAT_MBYTE |
| 8615 | if (enc_utf8) |
| 8616 | { |
| 8617 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 8618 | for (i = wouldbe_col; i < col; ++i) |
| 8619 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 8620 | { |
| 8621 | cost = 999; |
| 8622 | break; |
| 8623 | } |
| 8624 | } |
| 8625 | #endif |
| 8626 | } |
| 8627 | |
| 8628 | /* |
| 8629 | * We can do it without term_windgoto()! |
| 8630 | */ |
| 8631 | if (cost < goto_cost) |
| 8632 | { |
| 8633 | if (plan == PLAN_LE) |
| 8634 | { |
| 8635 | if (noinvcurs) |
| 8636 | screen_stop_highlight(); |
| 8637 | while (screen_cur_col > col) |
| 8638 | { |
| 8639 | out_str(bs); |
| 8640 | --screen_cur_col; |
| 8641 | } |
| 8642 | } |
| 8643 | else if (plan == PLAN_CR) |
| 8644 | { |
| 8645 | if (noinvcurs) |
| 8646 | screen_stop_highlight(); |
| 8647 | out_char('\r'); |
| 8648 | screen_cur_col = 0; |
| 8649 | } |
| 8650 | else if (plan == PLAN_NL) |
| 8651 | { |
| 8652 | if (noinvcurs) |
| 8653 | screen_stop_highlight(); |
| 8654 | while (screen_cur_row < row) |
| 8655 | { |
| 8656 | out_char('\n'); |
| 8657 | ++screen_cur_row; |
| 8658 | } |
| 8659 | screen_cur_col = 0; |
| 8660 | } |
| 8661 | |
| 8662 | i = col - screen_cur_col; |
| 8663 | if (i > 0) |
| 8664 | { |
| 8665 | /* |
| 8666 | * Use cursor-right if it's one character only. Avoids |
| 8667 | * removing a line of pixels from the last bold char, when |
| 8668 | * using the bold trick in the GUI. |
| 8669 | */ |
| 8670 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 8671 | { |
| 8672 | while (i-- > 0) |
| 8673 | out_char(*T_ND); |
| 8674 | } |
| 8675 | else |
| 8676 | { |
| 8677 | int off; |
| 8678 | |
| 8679 | off = LineOffset[row] + screen_cur_col; |
| 8680 | while (i-- > 0) |
| 8681 | { |
| 8682 | if (ScreenAttrs[off] != screen_attr) |
| 8683 | screen_stop_highlight(); |
| 8684 | #ifdef FEAT_MBYTE |
| 8685 | out_flush_check(); |
| 8686 | #endif |
| 8687 | out_char(ScreenLines[off]); |
| 8688 | #ifdef FEAT_MBYTE |
| 8689 | if (enc_dbcs == DBCS_JPNU |
| 8690 | && ScreenLines[off] == 0x8e) |
| 8691 | out_char(ScreenLines2[off]); |
| 8692 | #endif |
| 8693 | ++off; |
| 8694 | } |
| 8695 | } |
| 8696 | } |
| 8697 | } |
| 8698 | } |
| 8699 | else |
| 8700 | cost = 999; |
| 8701 | |
| 8702 | if (cost >= goto_cost) |
| 8703 | { |
| 8704 | if (noinvcurs) |
| 8705 | screen_stop_highlight(); |
| 8706 | if (row == screen_cur_row && (col > screen_cur_col) && |
| 8707 | *T_CRI != NUL) |
| 8708 | term_cursor_right(col - screen_cur_col); |
| 8709 | else |
| 8710 | term_windgoto(row, col); |
| 8711 | } |
| 8712 | screen_cur_row = row; |
| 8713 | screen_cur_col = col; |
| 8714 | } |
| 8715 | } |
| 8716 | |
| 8717 | /* |
| 8718 | * Set cursor to its position in the current window. |
| 8719 | */ |
| 8720 | void |
| 8721 | setcursor() |
| 8722 | { |
| 8723 | if (redrawing()) |
| 8724 | { |
| 8725 | validate_cursor(); |
| 8726 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 8727 | W_WINCOL(curwin) + ( |
| 8728 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 8729 | /* With 'rightleft' set and the cursor on a double-wide |
| 8730 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8731 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 8732 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 8733 | (has_mbyte |
| 8734 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 8735 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8736 | # endif |
| 8737 | 1)) : |
| 8738 | #endif |
| 8739 | curwin->w_wcol)); |
| 8740 | } |
| 8741 | } |
| 8742 | |
| 8743 | |
| 8744 | /* |
| 8745 | * insert 'line_count' lines at 'row' in window 'wp' |
| 8746 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 8747 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 8748 | * scrolling. |
| 8749 | * Returns FAIL if the lines are not inserted, OK for success. |
| 8750 | */ |
| 8751 | int |
| 8752 | win_ins_lines(wp, row, line_count, invalid, mayclear) |
| 8753 | win_T *wp; |
| 8754 | int row; |
| 8755 | int line_count; |
| 8756 | int invalid; |
| 8757 | int mayclear; |
| 8758 | { |
| 8759 | int did_delete; |
| 8760 | int nextrow; |
| 8761 | int lastrow; |
| 8762 | int retval; |
| 8763 | |
| 8764 | if (invalid) |
| 8765 | wp->w_lines_valid = 0; |
| 8766 | |
| 8767 | if (wp->w_height < 5) |
| 8768 | return FAIL; |
| 8769 | |
| 8770 | if (line_count > wp->w_height - row) |
| 8771 | line_count = wp->w_height - row; |
| 8772 | |
| 8773 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 8774 | if (retval != MAYBE) |
| 8775 | return retval; |
| 8776 | |
| 8777 | /* |
| 8778 | * If there is a next window or a status line, we first try to delete the |
| 8779 | * lines at the bottom to avoid messing what is after the window. |
| 8780 | * If this fails and there are following windows, don't do anything to avoid |
| 8781 | * messing up those windows, better just redraw. |
| 8782 | */ |
| 8783 | did_delete = FALSE; |
| 8784 | #ifdef FEAT_WINDOWS |
| 8785 | if (wp->w_next != NULL || wp->w_status_height) |
| 8786 | { |
| 8787 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8788 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 8789 | did_delete = TRUE; |
| 8790 | else if (wp->w_next) |
| 8791 | return FAIL; |
| 8792 | } |
| 8793 | #endif |
| 8794 | /* |
| 8795 | * if no lines deleted, blank the lines that will end up below the window |
| 8796 | */ |
| 8797 | if (!did_delete) |
| 8798 | { |
| 8799 | #ifdef FEAT_WINDOWS |
| 8800 | wp->w_redr_status = TRUE; |
| 8801 | #endif |
| 8802 | redraw_cmdline = TRUE; |
| 8803 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 8804 | lastrow = nextrow + line_count; |
| 8805 | if (lastrow > Rows) |
| 8806 | lastrow = Rows; |
| 8807 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 8808 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8809 | ' ', ' ', 0); |
| 8810 | } |
| 8811 | |
| 8812 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 8813 | == FAIL) |
| 8814 | { |
| 8815 | /* deletion will have messed up other windows */ |
| 8816 | if (did_delete) |
| 8817 | { |
| 8818 | #ifdef FEAT_WINDOWS |
| 8819 | wp->w_redr_status = TRUE; |
| 8820 | #endif |
| 8821 | win_rest_invalid(W_NEXT(wp)); |
| 8822 | } |
| 8823 | return FAIL; |
| 8824 | } |
| 8825 | |
| 8826 | return OK; |
| 8827 | } |
| 8828 | |
| 8829 | /* |
| 8830 | * delete "line_count" window lines at "row" in window "wp" |
| 8831 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 8832 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 8833 | * scrolling |
| 8834 | * Return OK for success, FAIL if the lines are not deleted. |
| 8835 | */ |
| 8836 | int |
| 8837 | win_del_lines(wp, row, line_count, invalid, mayclear) |
| 8838 | win_T *wp; |
| 8839 | int row; |
| 8840 | int line_count; |
| 8841 | int invalid; |
| 8842 | int mayclear; |
| 8843 | { |
| 8844 | int retval; |
| 8845 | |
| 8846 | if (invalid) |
| 8847 | wp->w_lines_valid = 0; |
| 8848 | |
| 8849 | if (line_count > wp->w_height - row) |
| 8850 | line_count = wp->w_height - row; |
| 8851 | |
| 8852 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 8853 | if (retval != MAYBE) |
| 8854 | return retval; |
| 8855 | |
| 8856 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 8857 | (int)Rows, FALSE, NULL) == FAIL) |
| 8858 | return FAIL; |
| 8859 | |
| 8860 | #ifdef FEAT_WINDOWS |
| 8861 | /* |
| 8862 | * If there are windows or status lines below, try to put them at the |
| 8863 | * correct place. If we can't do that, they have to be redrawn. |
| 8864 | */ |
| 8865 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 8866 | { |
| 8867 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 8868 | line_count, (int)Rows, NULL) == FAIL) |
| 8869 | { |
| 8870 | wp->w_redr_status = TRUE; |
| 8871 | win_rest_invalid(wp->w_next); |
| 8872 | } |
| 8873 | } |
| 8874 | /* |
| 8875 | * If this is the last window and there is no status line, redraw the |
| 8876 | * command line later. |
| 8877 | */ |
| 8878 | else |
| 8879 | #endif |
| 8880 | redraw_cmdline = TRUE; |
| 8881 | return OK; |
| 8882 | } |
| 8883 | |
| 8884 | /* |
| 8885 | * Common code for win_ins_lines() and win_del_lines(). |
| 8886 | * Returns OK or FAIL when the work has been done. |
| 8887 | * Returns MAYBE when not finished yet. |
| 8888 | */ |
| 8889 | static int |
| 8890 | win_do_lines(wp, row, line_count, mayclear, del) |
| 8891 | win_T *wp; |
| 8892 | int row; |
| 8893 | int line_count; |
| 8894 | int mayclear; |
| 8895 | int del; |
| 8896 | { |
| 8897 | int retval; |
| 8898 | |
| 8899 | if (!redrawing() || line_count <= 0) |
| 8900 | return FAIL; |
| 8901 | |
| 8902 | /* only a few lines left: redraw is faster */ |
| 8903 | if (mayclear && Rows - line_count < 5 |
| 8904 | #ifdef FEAT_VERTSPLIT |
| 8905 | && wp->w_width == Columns |
| 8906 | #endif |
| 8907 | ) |
| 8908 | { |
| 8909 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 8910 | return FAIL; |
| 8911 | } |
| 8912 | |
| 8913 | /* |
| 8914 | * Delete all remaining lines |
| 8915 | */ |
| 8916 | if (row + line_count >= wp->w_height) |
| 8917 | { |
| 8918 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 8919 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 8920 | ' ', ' ', 0); |
| 8921 | return OK; |
| 8922 | } |
| 8923 | |
| 8924 | /* |
| 8925 | * when scrolling, the message on the command line should be cleared, |
| 8926 | * otherwise it will stay there forever. |
| 8927 | */ |
| 8928 | clear_cmdline = TRUE; |
| 8929 | |
| 8930 | /* |
| 8931 | * If the terminal can set a scroll region, use that. |
| 8932 | * Always do this in a vertically split window. This will redraw from |
| 8933 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 8934 | * win_line(). |
| 8935 | * Don't use a scroll region when we are going to redraw the text, writing |
| 8936 | * a character in the lower right corner of the scroll region causes a |
| 8937 | * scroll-up in the DJGPP version. |
| 8938 | */ |
| 8939 | if (scroll_region |
| 8940 | #ifdef FEAT_VERTSPLIT |
| 8941 | || W_WIDTH(wp) != Columns |
| 8942 | #endif |
| 8943 | ) |
| 8944 | { |
| 8945 | #ifdef FEAT_VERTSPLIT |
| 8946 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8947 | #endif |
| 8948 | scroll_region_set(wp, row); |
| 8949 | if (del) |
| 8950 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 8951 | wp->w_height - row, FALSE, wp); |
| 8952 | else |
| 8953 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 8954 | wp->w_height - row, wp); |
| 8955 | #ifdef FEAT_VERTSPLIT |
| 8956 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 8957 | #endif |
| 8958 | scroll_region_reset(); |
| 8959 | return retval; |
| 8960 | } |
| 8961 | |
| 8962 | #ifdef FEAT_WINDOWS |
| 8963 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 8964 | return FAIL; |
| 8965 | #endif |
| 8966 | |
| 8967 | return MAYBE; |
| 8968 | } |
| 8969 | |
| 8970 | /* |
| 8971 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 8972 | */ |
| 8973 | static void |
| 8974 | win_rest_invalid(wp) |
| 8975 | win_T *wp; |
| 8976 | { |
| 8977 | #ifdef FEAT_WINDOWS |
| 8978 | while (wp != NULL) |
| 8979 | #else |
| 8980 | if (wp != NULL) |
| 8981 | #endif |
| 8982 | { |
| 8983 | redraw_win_later(wp, NOT_VALID); |
| 8984 | #ifdef FEAT_WINDOWS |
| 8985 | wp->w_redr_status = TRUE; |
| 8986 | wp = wp->w_next; |
| 8987 | #endif |
| 8988 | } |
| 8989 | redraw_cmdline = TRUE; |
| 8990 | } |
| 8991 | |
| 8992 | /* |
| 8993 | * The rest of the routines in this file perform screen manipulations. The |
| 8994 | * given operation is performed physically on the screen. The corresponding |
| 8995 | * change is also made to the internal screen image. In this way, the editor |
| 8996 | * anticipates the effect of editing changes on the appearance of the screen. |
| 8997 | * That way, when we call screenupdate a complete redraw isn't usually |
| 8998 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 8999 | * screen changes, and in the meantime, everything still works. |
| 9000 | */ |
| 9001 | |
| 9002 | /* |
| 9003 | * types for inserting or deleting lines |
| 9004 | */ |
| 9005 | #define USE_T_CAL 1 |
| 9006 | #define USE_T_CDL 2 |
| 9007 | #define USE_T_AL 3 |
| 9008 | #define USE_T_CE 4 |
| 9009 | #define USE_T_DL 5 |
| 9010 | #define USE_T_SR 6 |
| 9011 | #define USE_NL 7 |
| 9012 | #define USE_T_CD 8 |
| 9013 | #define USE_REDRAW 9 |
| 9014 | |
| 9015 | /* |
| 9016 | * insert lines on the screen and update ScreenLines[] |
| 9017 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9018 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9019 | * 'row' and 'end' are relative to the start of the region. |
| 9020 | * |
| 9021 | * return FAIL for failure, OK for success. |
| 9022 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 9023 | int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9024 | screen_ins_lines(off, row, line_count, end, wp) |
| 9025 | int off; |
| 9026 | int row; |
| 9027 | int line_count; |
| 9028 | int end; |
| 9029 | win_T *wp; /* NULL or window to use width from */ |
| 9030 | { |
| 9031 | int i; |
| 9032 | int j; |
| 9033 | unsigned temp; |
| 9034 | int cursor_row; |
| 9035 | int type; |
| 9036 | int result_empty; |
| 9037 | int can_ce = can_clear(T_CE); |
| 9038 | |
| 9039 | /* |
| 9040 | * FAIL if |
| 9041 | * - there is no valid screen |
| 9042 | * - the screen has to be redrawn completely |
| 9043 | * - the line count is less than one |
| 9044 | * - the line count is more than 'ttyscroll' |
| 9045 | */ |
| 9046 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 9047 | return FAIL; |
| 9048 | |
| 9049 | /* |
| 9050 | * There are seven ways to insert lines: |
| 9051 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9052 | * characters from ScreenLines[]. |
| 9053 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9054 | * the insert is just empty lines |
| 9055 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9056 | * present or line_count > 1. It looks better if we do all the inserts |
| 9057 | * at once. |
| 9058 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9059 | * insert is just empty lines and T_CE is not present or line_count > |
| 9060 | * 1. |
| 9061 | * 4. Use T_AL (insert line) if it exists. |
| 9062 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9063 | * just empty lines. |
| 9064 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9065 | * just empty lines. |
| 9066 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9067 | * the 'da' flag is not set or we have clear line capability. |
| 9068 | * 8. redraw the characters from ScreenLines[]. |
| 9069 | * |
| 9070 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9071 | * the scrollbar for the window. It does have insert line, use that if it |
| 9072 | * exists. |
| 9073 | */ |
| 9074 | result_empty = (row + line_count >= end); |
| 9075 | #ifdef FEAT_VERTSPLIT |
| 9076 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9077 | type = USE_REDRAW; |
| 9078 | else |
| 9079 | #endif |
| 9080 | if (can_clear(T_CD) && result_empty) |
| 9081 | type = USE_T_CD; |
| 9082 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9083 | type = USE_T_CAL; |
| 9084 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9085 | type = USE_T_CDL; |
| 9086 | else if (*T_AL != NUL) |
| 9087 | type = USE_T_AL; |
| 9088 | else if (can_ce && result_empty) |
| 9089 | type = USE_T_CE; |
| 9090 | else if (*T_DL != NUL && result_empty) |
| 9091 | type = USE_T_DL; |
| 9092 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9093 | type = USE_T_SR; |
| 9094 | else |
| 9095 | return FAIL; |
| 9096 | |
| 9097 | /* |
| 9098 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9099 | * care of t_db if necessary. |
| 9100 | */ |
| 9101 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9102 | type == USE_T_CE || type == USE_T_DL) |
| 9103 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9104 | |
| 9105 | /* |
| 9106 | * If text is retained below the screen, first clear or delete as many |
| 9107 | * lines at the bottom of the window as are about to be inserted so that |
| 9108 | * the deleted lines won't later surface during a screen_del_lines. |
| 9109 | */ |
| 9110 | if (*T_DB) |
| 9111 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9112 | |
| 9113 | #ifdef FEAT_CLIPBOARD |
| 9114 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9115 | * or not the full width of the screen. */ |
| 9116 | if (off + row > 0 |
| 9117 | # ifdef FEAT_VERTSPLIT |
| 9118 | || (wp != NULL && wp->w_width != Columns) |
| 9119 | # endif |
| 9120 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9121 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9122 | else |
| 9123 | clip_scroll_selection(-line_count); |
| 9124 | #endif |
| 9125 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9126 | #ifdef FEAT_GUI |
| 9127 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9128 | * scrolling is actually carried out. */ |
| 9129 | gui_dont_update_cursor(); |
| 9130 | #endif |
| 9131 | |
| 9132 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9133 | cursor_row = row; |
| 9134 | else |
| 9135 | cursor_row = row + off; |
| 9136 | |
| 9137 | /* |
| 9138 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9139 | * Clear the inserted lines in ScreenLines[]. |
| 9140 | */ |
| 9141 | row += off; |
| 9142 | end += off; |
| 9143 | for (i = 0; i < line_count; ++i) |
| 9144 | { |
| 9145 | #ifdef FEAT_VERTSPLIT |
| 9146 | if (wp != NULL && wp->w_width != Columns) |
| 9147 | { |
| 9148 | /* need to copy part of a line */ |
| 9149 | j = end - 1 - i; |
| 9150 | while ((j -= line_count) >= row) |
| 9151 | linecopy(j + line_count, j, wp); |
| 9152 | j += line_count; |
| 9153 | if (can_clear((char_u *)" ")) |
| 9154 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9155 | else |
| 9156 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9157 | LineWraps[j] = FALSE; |
| 9158 | } |
| 9159 | else |
| 9160 | #endif |
| 9161 | { |
| 9162 | j = end - 1 - i; |
| 9163 | temp = LineOffset[j]; |
| 9164 | while ((j -= line_count) >= row) |
| 9165 | { |
| 9166 | LineOffset[j + line_count] = LineOffset[j]; |
| 9167 | LineWraps[j + line_count] = LineWraps[j]; |
| 9168 | } |
| 9169 | LineOffset[j + line_count] = temp; |
| 9170 | LineWraps[j + line_count] = FALSE; |
| 9171 | if (can_clear((char_u *)" ")) |
| 9172 | lineclear(temp, (int)Columns); |
| 9173 | else |
| 9174 | lineinvalid(temp, (int)Columns); |
| 9175 | } |
| 9176 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9177 | |
| 9178 | screen_stop_highlight(); |
| 9179 | windgoto(cursor_row, 0); |
| 9180 | |
| 9181 | #ifdef FEAT_VERTSPLIT |
| 9182 | /* redraw the characters */ |
| 9183 | if (type == USE_REDRAW) |
| 9184 | redraw_block(row, end, wp); |
| 9185 | else |
| 9186 | #endif |
| 9187 | if (type == USE_T_CAL) |
| 9188 | { |
| 9189 | term_append_lines(line_count); |
| 9190 | screen_start(); /* don't know where cursor is now */ |
| 9191 | } |
| 9192 | else |
| 9193 | { |
| 9194 | for (i = 0; i < line_count; i++) |
| 9195 | { |
| 9196 | if (type == USE_T_AL) |
| 9197 | { |
| 9198 | if (i && cursor_row != 0) |
| 9199 | windgoto(cursor_row, 0); |
| 9200 | out_str(T_AL); |
| 9201 | } |
| 9202 | else /* type == USE_T_SR */ |
| 9203 | out_str(T_SR); |
| 9204 | screen_start(); /* don't know where cursor is now */ |
| 9205 | } |
| 9206 | } |
| 9207 | |
| 9208 | /* |
| 9209 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9210 | * have been scrolled down into the region. |
| 9211 | */ |
| 9212 | if (type == USE_T_SR && *T_DA) |
| 9213 | { |
| 9214 | for (i = 0; i < line_count; ++i) |
| 9215 | { |
| 9216 | windgoto(off + i, 0); |
| 9217 | out_str(T_CE); |
| 9218 | screen_start(); /* don't know where cursor is now */ |
| 9219 | } |
| 9220 | } |
| 9221 | |
| 9222 | #ifdef FEAT_GUI |
| 9223 | gui_can_update_cursor(); |
| 9224 | if (gui.in_use) |
| 9225 | out_flush(); /* always flush after a scroll */ |
| 9226 | #endif |
| 9227 | return OK; |
| 9228 | } |
| 9229 | |
| 9230 | /* |
| 9231 | * delete lines on the screen and update ScreenLines[] |
| 9232 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9233 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9234 | * 'row' and 'end' are relative to the start of the region. |
| 9235 | * |
| 9236 | * Return OK for success, FAIL if the lines are not deleted. |
| 9237 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9238 | int |
| 9239 | screen_del_lines(off, row, line_count, end, force, wp) |
| 9240 | int off; |
| 9241 | int row; |
| 9242 | int line_count; |
| 9243 | int end; |
| 9244 | int force; /* even when line_count > p_ttyscroll */ |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 9245 | win_T *wp UNUSED; /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9246 | { |
| 9247 | int j; |
| 9248 | int i; |
| 9249 | unsigned temp; |
| 9250 | int cursor_row; |
| 9251 | int cursor_end; |
| 9252 | int result_empty; /* result is empty until end of region */ |
| 9253 | int can_delete; /* deleting line codes can be used */ |
| 9254 | int type; |
| 9255 | |
| 9256 | /* |
| 9257 | * FAIL if |
| 9258 | * - there is no valid screen |
| 9259 | * - the screen has to be redrawn completely |
| 9260 | * - the line count is less than one |
| 9261 | * - the line count is more than 'ttyscroll' |
| 9262 | */ |
| 9263 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9264 | (!force && line_count > p_ttyscroll)) |
| 9265 | return FAIL; |
| 9266 | |
| 9267 | /* |
| 9268 | * Check if the rest of the current region will become empty. |
| 9269 | */ |
| 9270 | result_empty = row + line_count >= end; |
| 9271 | |
| 9272 | /* |
| 9273 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9274 | * available. |
| 9275 | */ |
| 9276 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9277 | |
| 9278 | /* |
| 9279 | * There are six ways to delete lines: |
| 9280 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9281 | * characters from ScreenLines[]. |
| 9282 | * 1. Use T_CD if it exists and the result is empty. |
| 9283 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9284 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9285 | * none of the other ways work. |
| 9286 | * 4. Use T_CE (erase line) if the result is empty. |
| 9287 | * 5. Use T_DL (delete line) if it exists. |
| 9288 | * 6. redraw the characters from ScreenLines[]. |
| 9289 | */ |
| 9290 | #ifdef FEAT_VERTSPLIT |
| 9291 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9292 | type = USE_REDRAW; |
| 9293 | else |
| 9294 | #endif |
| 9295 | if (can_clear(T_CD) && result_empty) |
| 9296 | type = USE_T_CD; |
| 9297 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9298 | /* |
| 9299 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9300 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9301 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9302 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9303 | * the trick... |
| 9304 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9305 | * (Olaf Seibert) |
| 9306 | */ |
| 9307 | else if (row == 0 && T_DB == empty_option |
| 9308 | && (line_count == 1 || *T_CDL == NUL)) |
| 9309 | #else |
| 9310 | else if (row == 0 && ( |
| 9311 | #ifndef AMIGA |
| 9312 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9313 | * up, so use delete-line command */ |
| 9314 | line_count == 1 || |
| 9315 | #endif |
| 9316 | *T_CDL == NUL)) |
| 9317 | #endif |
| 9318 | type = USE_NL; |
| 9319 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9320 | type = USE_T_CDL; |
| 9321 | else if (can_clear(T_CE) && result_empty |
| 9322 | #ifdef FEAT_VERTSPLIT |
| 9323 | && (wp == NULL || wp->w_width == Columns) |
| 9324 | #endif |
| 9325 | ) |
| 9326 | type = USE_T_CE; |
| 9327 | else if (*T_DL != NUL && can_delete) |
| 9328 | type = USE_T_DL; |
| 9329 | else if (*T_CDL != NUL && can_delete) |
| 9330 | type = USE_T_CDL; |
| 9331 | else |
| 9332 | return FAIL; |
| 9333 | |
| 9334 | #ifdef FEAT_CLIPBOARD |
| 9335 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9336 | * not the full width of the screen. */ |
| 9337 | if (off + row > 0 |
| 9338 | # ifdef FEAT_VERTSPLIT |
| 9339 | || (wp != NULL && wp->w_width != Columns) |
| 9340 | # endif |
| 9341 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9342 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9343 | else |
| 9344 | clip_scroll_selection(line_count); |
| 9345 | #endif |
| 9346 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9347 | #ifdef FEAT_GUI |
| 9348 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9349 | * scrolling is actually carried out. */ |
| 9350 | gui_dont_update_cursor(); |
| 9351 | #endif |
| 9352 | |
| 9353 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9354 | { |
| 9355 | cursor_row = row; |
| 9356 | cursor_end = end; |
| 9357 | } |
| 9358 | else |
| 9359 | { |
| 9360 | cursor_row = row + off; |
| 9361 | cursor_end = end + off; |
| 9362 | } |
| 9363 | |
| 9364 | /* |
| 9365 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9366 | * Clear the inserted lines in ScreenLines[]. |
| 9367 | */ |
| 9368 | row += off; |
| 9369 | end += off; |
| 9370 | for (i = 0; i < line_count; ++i) |
| 9371 | { |
| 9372 | #ifdef FEAT_VERTSPLIT |
| 9373 | if (wp != NULL && wp->w_width != Columns) |
| 9374 | { |
| 9375 | /* need to copy part of a line */ |
| 9376 | j = row + i; |
| 9377 | while ((j += line_count) <= end - 1) |
| 9378 | linecopy(j - line_count, j, wp); |
| 9379 | j -= line_count; |
| 9380 | if (can_clear((char_u *)" ")) |
| 9381 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9382 | else |
| 9383 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9384 | LineWraps[j] = FALSE; |
| 9385 | } |
| 9386 | else |
| 9387 | #endif |
| 9388 | { |
| 9389 | /* whole width, moving the line pointers is faster */ |
| 9390 | j = row + i; |
| 9391 | temp = LineOffset[j]; |
| 9392 | while ((j += line_count) <= end - 1) |
| 9393 | { |
| 9394 | LineOffset[j - line_count] = LineOffset[j]; |
| 9395 | LineWraps[j - line_count] = LineWraps[j]; |
| 9396 | } |
| 9397 | LineOffset[j - line_count] = temp; |
| 9398 | LineWraps[j - line_count] = FALSE; |
| 9399 | if (can_clear((char_u *)" ")) |
| 9400 | lineclear(temp, (int)Columns); |
| 9401 | else |
| 9402 | lineinvalid(temp, (int)Columns); |
| 9403 | } |
| 9404 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9405 | |
| 9406 | screen_stop_highlight(); |
| 9407 | |
| 9408 | #ifdef FEAT_VERTSPLIT |
| 9409 | /* redraw the characters */ |
| 9410 | if (type == USE_REDRAW) |
| 9411 | redraw_block(row, end, wp); |
| 9412 | else |
| 9413 | #endif |
| 9414 | if (type == USE_T_CD) /* delete the lines */ |
| 9415 | { |
| 9416 | windgoto(cursor_row, 0); |
| 9417 | out_str(T_CD); |
| 9418 | screen_start(); /* don't know where cursor is now */ |
| 9419 | } |
| 9420 | else if (type == USE_T_CDL) |
| 9421 | { |
| 9422 | windgoto(cursor_row, 0); |
| 9423 | term_delete_lines(line_count); |
| 9424 | screen_start(); /* don't know where cursor is now */ |
| 9425 | } |
| 9426 | /* |
| 9427 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9428 | * the whole screen (scroll region) up by outputting newlines on the |
| 9429 | * last line. |
| 9430 | */ |
| 9431 | else if (type == USE_NL) |
| 9432 | { |
| 9433 | windgoto(cursor_end - 1, 0); |
| 9434 | for (i = line_count; --i >= 0; ) |
| 9435 | out_char('\n'); /* cursor will remain on same line */ |
| 9436 | } |
| 9437 | else |
| 9438 | { |
| 9439 | for (i = line_count; --i >= 0; ) |
| 9440 | { |
| 9441 | if (type == USE_T_DL) |
| 9442 | { |
| 9443 | windgoto(cursor_row, 0); |
| 9444 | out_str(T_DL); /* delete a line */ |
| 9445 | } |
| 9446 | else /* type == USE_T_CE */ |
| 9447 | { |
| 9448 | windgoto(cursor_row + i, 0); |
| 9449 | out_str(T_CE); /* erase a line */ |
| 9450 | } |
| 9451 | screen_start(); /* don't know where cursor is now */ |
| 9452 | } |
| 9453 | } |
| 9454 | |
| 9455 | /* |
| 9456 | * If the 'db' flag is set, we need to clear the lines that have been |
| 9457 | * scrolled up at the bottom of the region. |
| 9458 | */ |
| 9459 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 9460 | { |
| 9461 | for (i = line_count; i > 0; --i) |
| 9462 | { |
| 9463 | windgoto(cursor_end - i, 0); |
| 9464 | out_str(T_CE); /* erase a line */ |
| 9465 | screen_start(); /* don't know where cursor is now */ |
| 9466 | } |
| 9467 | } |
| 9468 | |
| 9469 | #ifdef FEAT_GUI |
| 9470 | gui_can_update_cursor(); |
| 9471 | if (gui.in_use) |
| 9472 | out_flush(); /* always flush after a scroll */ |
| 9473 | #endif |
| 9474 | |
| 9475 | return OK; |
| 9476 | } |
| 9477 | |
| 9478 | /* |
| 9479 | * show the current mode and ruler |
| 9480 | * |
| 9481 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 9482 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 9483 | * cleared only if a mode is shown. |
| 9484 | * Return the length of the message (0 if no message). |
| 9485 | */ |
| 9486 | int |
| 9487 | showmode() |
| 9488 | { |
| 9489 | int need_clear; |
| 9490 | int length = 0; |
| 9491 | int do_mode; |
| 9492 | int attr; |
| 9493 | int nwr_save; |
| 9494 | #ifdef FEAT_INS_EXPAND |
| 9495 | int sub_attr; |
| 9496 | #endif |
| 9497 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 9498 | do_mode = ((p_smd && msg_silent == 0) |
| 9499 | && ((State & INSERT) |
| 9500 | || restart_edit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9501 | #ifdef FEAT_VISUAL |
| 9502 | || VIsual_active |
| 9503 | #endif |
| 9504 | )); |
| 9505 | if (do_mode || Recording) |
| 9506 | { |
| 9507 | /* |
| 9508 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 9509 | * Call char_avail() only when we are going to show something, because |
| 9510 | * it takes a bit of time. |
| 9511 | */ |
| 9512 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 9513 | { |
| 9514 | redraw_cmdline = TRUE; /* show mode later */ |
| 9515 | return 0; |
| 9516 | } |
| 9517 | |
| 9518 | nwr_save = need_wait_return; |
| 9519 | |
| 9520 | /* wait a bit before overwriting an important message */ |
| 9521 | check_for_delay(FALSE); |
| 9522 | |
| 9523 | /* if the cmdline is more than one line high, erase top lines */ |
| 9524 | need_clear = clear_cmdline; |
| 9525 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 9526 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 9527 | |
| 9528 | /* Position on the last line in the window, column 0 */ |
| 9529 | msg_pos_mode(); |
| 9530 | cursor_off(); |
| 9531 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 9532 | if (do_mode) |
| 9533 | { |
| 9534 | MSG_PUTS_ATTR("--", attr); |
| 9535 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9536 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9537 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9538 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9539 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9540 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 9541 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 9542 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 9543 | # 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] | 9544 | MSG_PUTS_ATTR(" IM", attr); |
| 9545 | # else |
| 9546 | MSG_PUTS_ATTR(" XIM", attr); |
| 9547 | # endif |
| 9548 | #endif |
| 9549 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 9550 | if (gui.in_use) |
| 9551 | { |
| 9552 | if (hangul_input_state_get()) |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 9553 | MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9554 | } |
| 9555 | #endif |
| 9556 | #ifdef FEAT_INS_EXPAND |
| 9557 | if (edit_submode != NULL) /* CTRL-X in Insert mode */ |
| 9558 | { |
| 9559 | /* These messages can get long, avoid a wrap in a narrow |
| 9560 | * window. Prefer showing edit_submode_extra. */ |
| 9561 | length = (Rows - msg_row) * Columns - 3; |
| 9562 | if (edit_submode_extra != NULL) |
| 9563 | length -= vim_strsize(edit_submode_extra); |
| 9564 | if (length > 0) |
| 9565 | { |
| 9566 | if (edit_submode_pre != NULL) |
| 9567 | length -= vim_strsize(edit_submode_pre); |
| 9568 | if (length - vim_strsize(edit_submode) > 0) |
| 9569 | { |
| 9570 | if (edit_submode_pre != NULL) |
| 9571 | msg_puts_attr(edit_submode_pre, attr); |
| 9572 | msg_puts_attr(edit_submode, attr); |
| 9573 | } |
| 9574 | if (edit_submode_extra != NULL) |
| 9575 | { |
| 9576 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 9577 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 9578 | sub_attr = hl_attr(edit_submode_highl); |
| 9579 | else |
| 9580 | sub_attr = attr; |
| 9581 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 9582 | } |
| 9583 | } |
| 9584 | length = 0; |
| 9585 | } |
| 9586 | else |
| 9587 | #endif |
| 9588 | { |
| 9589 | #ifdef FEAT_VREPLACE |
| 9590 | if (State & VREPLACE_FLAG) |
| 9591 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 9592 | else |
| 9593 | #endif |
| 9594 | if (State & REPLACE_FLAG) |
| 9595 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 9596 | else if (State & INSERT) |
| 9597 | { |
| 9598 | #ifdef FEAT_RIGHTLEFT |
| 9599 | if (p_ri) |
| 9600 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 9601 | #endif |
| 9602 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 9603 | } |
| 9604 | else if (restart_edit == 'I') |
| 9605 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 9606 | else if (restart_edit == 'R') |
| 9607 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 9608 | else if (restart_edit == 'V') |
| 9609 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 9610 | #ifdef FEAT_RIGHTLEFT |
| 9611 | if (p_hkmap) |
| 9612 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 9613 | # ifdef FEAT_FKMAP |
| 9614 | if (p_fkmap) |
| 9615 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 9616 | # endif |
| 9617 | #endif |
| 9618 | #ifdef FEAT_KEYMAP |
| 9619 | if (State & LANGMAP) |
| 9620 | { |
| 9621 | # ifdef FEAT_ARABIC |
| 9622 | if (curwin->w_p_arab) |
| 9623 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 9624 | else |
| 9625 | # endif |
| 9626 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 9627 | } |
| 9628 | #endif |
| 9629 | if ((State & INSERT) && p_paste) |
| 9630 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 9631 | |
| 9632 | #ifdef FEAT_VISUAL |
| 9633 | if (VIsual_active) |
| 9634 | { |
| 9635 | char *p; |
| 9636 | |
| 9637 | /* Don't concatenate separate words to avoid translation |
| 9638 | * problems. */ |
| 9639 | switch ((VIsual_select ? 4 : 0) |
| 9640 | + (VIsual_mode == Ctrl_V) * 2 |
| 9641 | + (VIsual_mode == 'V')) |
| 9642 | { |
| 9643 | case 0: p = N_(" VISUAL"); break; |
| 9644 | case 1: p = N_(" VISUAL LINE"); break; |
| 9645 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 9646 | case 4: p = N_(" SELECT"); break; |
| 9647 | case 5: p = N_(" SELECT LINE"); break; |
| 9648 | default: p = N_(" SELECT BLOCK"); break; |
| 9649 | } |
| 9650 | MSG_PUTS_ATTR(_(p), attr); |
| 9651 | } |
| 9652 | #endif |
| 9653 | MSG_PUTS_ATTR(" --", attr); |
| 9654 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9655 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9656 | need_clear = TRUE; |
| 9657 | } |
| 9658 | if (Recording |
| 9659 | #ifdef FEAT_INS_EXPAND |
| 9660 | && edit_submode == NULL /* otherwise it gets too long */ |
| 9661 | #endif |
| 9662 | ) |
| 9663 | { |
| 9664 | MSG_PUTS_ATTR(_("recording"), attr); |
| 9665 | need_clear = TRUE; |
| 9666 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9667 | |
| 9668 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9669 | if (need_clear || clear_cmdline) |
| 9670 | msg_clr_eos(); |
| 9671 | msg_didout = FALSE; /* overwrite this message */ |
| 9672 | length = msg_col; |
| 9673 | msg_col = 0; |
| 9674 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 9675 | } |
| 9676 | else if (clear_cmdline && msg_silent == 0) |
| 9677 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 9678 | msg_clr_cmdline(); |
| 9679 | |
| 9680 | #ifdef FEAT_CMDL_INFO |
| 9681 | # ifdef FEAT_VISUAL |
| 9682 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 9683 | if (VIsual_active) |
| 9684 | clear_showcmd(); |
| 9685 | # endif |
| 9686 | |
| 9687 | /* If the last window has no status line, the ruler is after the mode |
| 9688 | * message and must be redrawn */ |
| 9689 | if (redrawing() |
| 9690 | # ifdef FEAT_WINDOWS |
| 9691 | && lastwin->w_status_height == 0 |
| 9692 | # endif |
| 9693 | ) |
| 9694 | win_redr_ruler(lastwin, TRUE); |
| 9695 | #endif |
| 9696 | redraw_cmdline = FALSE; |
| 9697 | clear_cmdline = FALSE; |
| 9698 | |
| 9699 | return length; |
| 9700 | } |
| 9701 | |
| 9702 | /* |
| 9703 | * Position for a mode message. |
| 9704 | */ |
| 9705 | static void |
| 9706 | msg_pos_mode() |
| 9707 | { |
| 9708 | msg_col = 0; |
| 9709 | msg_row = Rows - 1; |
| 9710 | } |
| 9711 | |
| 9712 | /* |
| 9713 | * Delete mode message. Used when ESC is typed which is expected to end |
| 9714 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 9715 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9716 | */ |
| 9717 | void |
| 9718 | unshowmode(force) |
| 9719 | int force; |
| 9720 | { |
| 9721 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 9722 | * 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] | 9723 | */ |
| 9724 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 9725 | redraw_cmdline = TRUE; /* delete mode later */ |
| 9726 | else |
| 9727 | { |
| 9728 | msg_pos_mode(); |
| 9729 | if (Recording) |
| 9730 | MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); |
| 9731 | msg_clr_eos(); |
| 9732 | } |
| 9733 | } |
| 9734 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9735 | #if defined(FEAT_WINDOWS) |
| 9736 | /* |
| 9737 | * Draw the tab pages line at the top of the Vim window. |
| 9738 | */ |
| 9739 | static void |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9740 | draw_tabline() |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9741 | { |
| 9742 | int tabcount = 0; |
| 9743 | tabpage_T *tp; |
| 9744 | int tabwidth; |
| 9745 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9746 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9747 | int attr; |
| 9748 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9749 | win_T *cwp; |
| 9750 | int wincount; |
| 9751 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9752 | int c; |
| 9753 | int len; |
| 9754 | int attr_sel = hl_attr(HLF_TPS); |
| 9755 | int attr_nosel = hl_attr(HLF_TP); |
| 9756 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9757 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9758 | int room; |
| 9759 | int use_sep_chars = (t_colors < 8 |
| 9760 | #ifdef FEAT_GUI |
| 9761 | && !gui.in_use |
| 9762 | #endif |
| 9763 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9764 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 9765 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9766 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9767 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 9768 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9769 | if (gui_use_tabline()) |
| 9770 | { |
| 9771 | gui_update_tabline(); |
| 9772 | return; |
| 9773 | } |
| 9774 | #endif |
| 9775 | |
| 9776 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9777 | return; |
| 9778 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9779 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9780 | |
| 9781 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 9782 | for (scol = 0; scol < Columns; ++scol) |
| 9783 | TabPageIdxs[scol] = 0; |
| 9784 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9785 | /* Use the 'tabline' option if it's set. */ |
| 9786 | if (*p_tal != NUL) |
| 9787 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9788 | int save_called_emsg = called_emsg; |
| 9789 | |
| 9790 | /* Check for an error. If there is one we would loop in redrawing the |
| 9791 | * screen. Avoid that by making 'tabline' empty. */ |
| 9792 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9793 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9794 | if (called_emsg) |
| 9795 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 9796 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9797 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9798 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9799 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9800 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9801 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9802 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 9803 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9804 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9805 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 9806 | if (tabwidth < 6) |
| 9807 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9808 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9809 | attr = attr_nosel; |
| 9810 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9811 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9812 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 9813 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9814 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9815 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9816 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9817 | if (tp->tp_topframe == topframe) |
| 9818 | attr = attr_sel; |
| 9819 | if (use_sep_chars && col > 0) |
| 9820 | screen_putchar('|', 0, col++, attr); |
| 9821 | |
| 9822 | if (tp->tp_topframe != topframe) |
| 9823 | attr = attr_nosel; |
| 9824 | |
| 9825 | screen_putchar(' ', 0, col++, attr); |
| 9826 | |
| 9827 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9828 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9829 | cwp = curwin; |
| 9830 | wp = firstwin; |
| 9831 | } |
| 9832 | else |
| 9833 | { |
| 9834 | cwp = tp->tp_curwin; |
| 9835 | wp = tp->tp_firstwin; |
| 9836 | } |
| 9837 | |
| 9838 | modified = FALSE; |
| 9839 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 9840 | if (bufIsChanged(wp->w_buffer)) |
| 9841 | modified = TRUE; |
| 9842 | if (modified || wincount > 1) |
| 9843 | { |
| 9844 | if (wincount > 1) |
| 9845 | { |
| 9846 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9847 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9848 | if (col + len >= Columns - 3) |
| 9849 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9850 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9851 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9852 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9853 | #else |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9854 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 9855 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9856 | ); |
| 9857 | col += len; |
| 9858 | } |
| 9859 | if (modified) |
| 9860 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 9861 | screen_putchar(' ', 0, col++, attr); |
| 9862 | } |
| 9863 | |
| 9864 | room = scol - col + tabwidth - 1; |
| 9865 | if (room > 0) |
| 9866 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9867 | /* Get buffer name in NameBuff[] */ |
| 9868 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 9869 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9870 | len = vim_strsize(NameBuff); |
| 9871 | p = NameBuff; |
| 9872 | #ifdef FEAT_MBYTE |
| 9873 | if (has_mbyte) |
| 9874 | while (len > room) |
| 9875 | { |
| 9876 | len -= ptr2cells(p); |
| 9877 | mb_ptr_adv(p); |
| 9878 | } |
| 9879 | else |
| 9880 | #endif |
| 9881 | if (len > room) |
| 9882 | { |
| 9883 | p += len - room; |
| 9884 | len = room; |
| 9885 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 9886 | if (len > Columns - col - 1) |
| 9887 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9888 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 9889 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9890 | col += len; |
| 9891 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9892 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9893 | |
| 9894 | /* Store the tab page number in TabPageIdxs[], so that |
| 9895 | * jump_to_mouse() knows where each one is. */ |
| 9896 | ++tabcount; |
| 9897 | while (scol < col) |
| 9898 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 9899 | } |
| 9900 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 9901 | if (use_sep_chars) |
| 9902 | c = '_'; |
| 9903 | else |
| 9904 | c = ' '; |
| 9905 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 9906 | |
| 9907 | /* Put an "X" for closing the current tab if there are several. */ |
| 9908 | if (first_tabpage->tp_next != NULL) |
| 9909 | { |
| 9910 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 9911 | TabPageIdxs[Columns - 1] = -999; |
| 9912 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9913 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 9914 | |
| 9915 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 9916 | * set. */ |
| 9917 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9918 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9919 | |
| 9920 | /* |
| 9921 | * Get buffer name for "buf" into NameBuff[]. |
| 9922 | * Takes care of special buffer names and translates special characters. |
| 9923 | */ |
| 9924 | void |
| 9925 | get_trans_bufname(buf) |
| 9926 | buf_T *buf; |
| 9927 | { |
| 9928 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 9929 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 9930 | else |
| 9931 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 9932 | trans_characters(NameBuff, MAXPATHL); |
| 9933 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 9934 | #endif |
| 9935 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9936 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 9937 | /* |
| 9938 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 9939 | */ |
| 9940 | static int |
| 9941 | fillchar_status(attr, is_curwin) |
| 9942 | int *attr; |
| 9943 | int is_curwin; |
| 9944 | { |
| 9945 | int fill; |
| 9946 | if (is_curwin) |
| 9947 | { |
| 9948 | *attr = hl_attr(HLF_S); |
| 9949 | fill = fill_stl; |
| 9950 | } |
| 9951 | else |
| 9952 | { |
| 9953 | *attr = hl_attr(HLF_SNC); |
| 9954 | fill = fill_stlnc; |
| 9955 | } |
| 9956 | /* Use fill when there is highlighting, and highlighting of current |
| 9957 | * window differs, or the fillchars differ, or this is not the |
| 9958 | * current window */ |
| 9959 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 9960 | || !is_curwin || firstwin == lastwin) |
| 9961 | || (fill_stl != fill_stlnc))) |
| 9962 | return fill; |
| 9963 | if (is_curwin) |
| 9964 | return '^'; |
| 9965 | return '='; |
| 9966 | } |
| 9967 | #endif |
| 9968 | |
| 9969 | #ifdef FEAT_VERTSPLIT |
| 9970 | /* |
| 9971 | * Get the character to use in a separator between vertically split windows. |
| 9972 | * Get its attributes in "*attr". |
| 9973 | */ |
| 9974 | static int |
| 9975 | fillchar_vsep(attr) |
| 9976 | int *attr; |
| 9977 | { |
| 9978 | *attr = hl_attr(HLF_C); |
| 9979 | if (*attr == 0 && fill_vert == ' ') |
| 9980 | return '|'; |
| 9981 | else |
| 9982 | return fill_vert; |
| 9983 | } |
| 9984 | #endif |
| 9985 | |
| 9986 | /* |
| 9987 | * Return TRUE if redrawing should currently be done. |
| 9988 | */ |
| 9989 | int |
| 9990 | redrawing() |
| 9991 | { |
| 9992 | return (!RedrawingDisabled |
| 9993 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 9994 | } |
| 9995 | |
| 9996 | /* |
| 9997 | * Return TRUE if printing messages should currently be done. |
| 9998 | */ |
| 9999 | int |
| 10000 | messaging() |
| 10001 | { |
| 10002 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 10003 | } |
| 10004 | |
| 10005 | /* |
| 10006 | * Show current status info in ruler and various other places |
| 10007 | * If always is FALSE, only show ruler if position has changed. |
| 10008 | */ |
| 10009 | void |
| 10010 | showruler(always) |
| 10011 | int always; |
| 10012 | { |
| 10013 | if (!always && !redrawing()) |
| 10014 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10015 | #ifdef FEAT_INS_EXPAND |
| 10016 | if (pum_visible()) |
| 10017 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10018 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10019 | /* Don't redraw right now, do it later. */ |
| 10020 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10021 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10022 | return; |
| 10023 | } |
| 10024 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10025 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 10026 | 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] | 10027 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 10028 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10029 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10030 | else |
| 10031 | #endif |
| 10032 | #ifdef FEAT_CMDL_INFO |
| 10033 | win_redr_ruler(curwin, always); |
| 10034 | #endif |
| 10035 | |
| 10036 | #ifdef FEAT_TITLE |
| 10037 | if (need_maketitle |
| 10038 | # ifdef FEAT_STL_OPT |
| 10039 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 10040 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 10041 | # endif |
| 10042 | ) |
| 10043 | maketitle(); |
| 10044 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 10045 | #ifdef FEAT_WINDOWS |
| 10046 | /* Redraw the tab pages line if needed. */ |
| 10047 | if (redraw_tabline) |
| 10048 | draw_tabline(); |
| 10049 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10050 | } |
| 10051 | |
| 10052 | #ifdef FEAT_CMDL_INFO |
| 10053 | static void |
| 10054 | win_redr_ruler(wp, always) |
| 10055 | win_T *wp; |
| 10056 | int always; |
| 10057 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10058 | #define RULER_BUF_LEN 70 |
| 10059 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10060 | int row; |
| 10061 | int fillchar; |
| 10062 | int attr; |
| 10063 | int empty_line = FALSE; |
| 10064 | colnr_T virtcol; |
| 10065 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10066 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10067 | int o; |
| 10068 | #ifdef FEAT_VERTSPLIT |
| 10069 | int this_ru_col; |
| 10070 | int off = 0; |
| 10071 | int width = Columns; |
| 10072 | # define WITH_OFF(x) x |
| 10073 | # define WITH_WIDTH(x) x |
| 10074 | #else |
| 10075 | # define WITH_OFF(x) 0 |
| 10076 | # define WITH_WIDTH(x) Columns |
| 10077 | # define this_ru_col ru_col |
| 10078 | #endif |
| 10079 | |
| 10080 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10081 | if (!p_ru) |
| 10082 | return; |
| 10083 | |
| 10084 | /* |
| 10085 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10086 | * after deleting lines, before cursor.lnum is corrected. |
| 10087 | */ |
| 10088 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10089 | return; |
| 10090 | |
| 10091 | #ifdef FEAT_INS_EXPAND |
| 10092 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10093 | * the (long) mode message. */ |
| 10094 | # ifdef FEAT_WINDOWS |
| 10095 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10096 | # endif |
| 10097 | if (edit_submode != NULL) |
| 10098 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10099 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10100 | if (pum_visible()) |
| 10101 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10102 | #endif |
| 10103 | |
| 10104 | #ifdef FEAT_STL_OPT |
| 10105 | if (*p_ruf) |
| 10106 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10107 | int save_called_emsg = called_emsg; |
| 10108 | |
| 10109 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10110 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10111 | if (called_emsg) |
| 10112 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10113 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10114 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10115 | return; |
| 10116 | } |
| 10117 | #endif |
| 10118 | |
| 10119 | /* |
| 10120 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10121 | */ |
| 10122 | if (!(State & INSERT) |
| 10123 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10124 | empty_line = TRUE; |
| 10125 | |
| 10126 | /* |
| 10127 | * Only draw the ruler when something changed. |
| 10128 | */ |
| 10129 | validate_virtcol_win(wp); |
| 10130 | if ( redraw_cmdline |
| 10131 | || always |
| 10132 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10133 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10134 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10135 | #ifdef FEAT_VIRTUALEDIT |
| 10136 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10137 | #endif |
| 10138 | || wp->w_topline != wp->w_ru_topline |
| 10139 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10140 | #ifdef FEAT_DIFF |
| 10141 | || wp->w_topfill != wp->w_ru_topfill |
| 10142 | #endif |
| 10143 | || empty_line != wp->w_ru_empty) |
| 10144 | { |
| 10145 | cursor_off(); |
| 10146 | #ifdef FEAT_WINDOWS |
| 10147 | if (wp->w_status_height) |
| 10148 | { |
| 10149 | row = W_WINROW(wp) + wp->w_height; |
| 10150 | fillchar = fillchar_status(&attr, wp == curwin); |
| 10151 | # ifdef FEAT_VERTSPLIT |
| 10152 | off = W_WINCOL(wp); |
| 10153 | width = W_WIDTH(wp); |
| 10154 | # endif |
| 10155 | } |
| 10156 | else |
| 10157 | #endif |
| 10158 | { |
| 10159 | row = Rows - 1; |
| 10160 | fillchar = ' '; |
| 10161 | attr = 0; |
| 10162 | #ifdef FEAT_VERTSPLIT |
| 10163 | width = Columns; |
| 10164 | off = 0; |
| 10165 | #endif |
| 10166 | } |
| 10167 | |
| 10168 | /* In list mode virtcol needs to be recomputed */ |
| 10169 | virtcol = wp->w_virtcol; |
| 10170 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10171 | { |
| 10172 | wp->w_p_list = FALSE; |
| 10173 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10174 | wp->w_p_list = TRUE; |
| 10175 | } |
| 10176 | |
| 10177 | /* |
| 10178 | * Some sprintfs return the length, some return a pointer. |
| 10179 | * To avoid portability problems we use strlen() here. |
| 10180 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10181 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10182 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10183 | ? 0L |
| 10184 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10185 | len = STRLEN(buffer); |
| 10186 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10187 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10188 | (int)virtcol + 1); |
| 10189 | |
| 10190 | /* |
| 10191 | * Add a "50%" if there is room for it. |
| 10192 | * On the last line, don't print in the last column (scrolls the |
| 10193 | * screen up on some terminals). |
| 10194 | */ |
| 10195 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10196 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10197 | o = i + vim_strsize(buffer + i + 1); |
| 10198 | #ifdef FEAT_WINDOWS |
| 10199 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10200 | #endif |
| 10201 | ++o; |
| 10202 | #ifdef FEAT_VERTSPLIT |
| 10203 | this_ru_col = ru_col - (Columns - width); |
| 10204 | if (this_ru_col < 0) |
| 10205 | this_ru_col = 0; |
| 10206 | #endif |
| 10207 | /* Never use more than half the window/screen width, leave the other |
| 10208 | * half for the filename. */ |
| 10209 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10210 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10211 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10212 | { |
| 10213 | while (this_ru_col + o < WITH_WIDTH(width)) |
| 10214 | { |
| 10215 | #ifdef FEAT_MBYTE |
| 10216 | if (has_mbyte) |
| 10217 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10218 | else |
| 10219 | #endif |
| 10220 | buffer[i++] = fillchar; |
| 10221 | ++o; |
| 10222 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10223 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10224 | } |
| 10225 | /* Truncate at window boundary. */ |
| 10226 | #ifdef FEAT_MBYTE |
| 10227 | if (has_mbyte) |
| 10228 | { |
| 10229 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10230 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10231 | { |
| 10232 | o += (*mb_ptr2cells)(buffer + i); |
| 10233 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10234 | { |
| 10235 | buffer[i] = NUL; |
| 10236 | break; |
| 10237 | } |
| 10238 | } |
| 10239 | } |
| 10240 | else |
| 10241 | #endif |
| 10242 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10243 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10244 | |
| 10245 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10246 | i = redraw_cmdline; |
| 10247 | screen_fill(row, row + 1, |
| 10248 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10249 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10250 | fillchar, fillchar, attr); |
| 10251 | /* don't redraw the cmdline because of showing the ruler */ |
| 10252 | redraw_cmdline = i; |
| 10253 | wp->w_ru_cursor = wp->w_cursor; |
| 10254 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10255 | wp->w_ru_empty = empty_line; |
| 10256 | wp->w_ru_topline = wp->w_topline; |
| 10257 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10258 | #ifdef FEAT_DIFF |
| 10259 | wp->w_ru_topfill = wp->w_topfill; |
| 10260 | #endif |
| 10261 | } |
| 10262 | } |
| 10263 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10264 | |
| 10265 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10266 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10267 | * Return the width of the 'number' and 'relativenumber' column. |
| 10268 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10269 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10270 | */ |
| 10271 | int |
| 10272 | number_width(wp) |
| 10273 | win_T *wp; |
| 10274 | { |
| 10275 | int n; |
| 10276 | linenr_T lnum; |
| 10277 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 10278 | if (wp->w_p_rnu && !wp->w_p_nu) |
| 10279 | /* cursor line shows "0" */ |
| 10280 | lnum = wp->w_height; |
| 10281 | else |
| 10282 | /* cursor line shows absolute line number */ |
| 10283 | lnum = wp->w_buffer->b_ml.ml_line_count; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10284 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10285 | if (lnum == wp->w_nrwidth_line_count) |
| 10286 | return wp->w_nrwidth_width; |
| 10287 | wp->w_nrwidth_line_count = lnum; |
| 10288 | |
| 10289 | n = 0; |
| 10290 | do |
| 10291 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10292 | lnum /= 10; |
| 10293 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10294 | } while (lnum > 0); |
| 10295 | |
| 10296 | /* 'numberwidth' gives the minimal width plus one */ |
| 10297 | if (n < wp->w_p_nuw - 1) |
| 10298 | n = wp->w_p_nuw - 1; |
| 10299 | |
| 10300 | wp->w_nrwidth_width = n; |
| 10301 | return n; |
| 10302 | } |
| 10303 | #endif |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10304 | |
| 10305 | /* |
| 10306 | * Return the current cursor column. This is the actual position on the |
| 10307 | * screen. First column is 0. |
| 10308 | */ |
| 10309 | int |
| 10310 | screen_screencol() |
| 10311 | { |
| 10312 | return screen_cur_col; |
| 10313 | } |
| 10314 | |
| 10315 | /* |
| 10316 | * Return the current cursor row. This is the actual position on the screen. |
| 10317 | * First row is 0. |
| 10318 | */ |
| 10319 | int |
| 10320 | screen_screenrow() |
| 10321 | { |
| 10322 | return screen_cur_row; |
| 10323 | } |