Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
| 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 | * drawline.c: Functions for drawing window lines on the screen. |
| 12 | * This is the middle level, drawscreen. is the higher level and screen.c the |
| 13 | * lower level. |
| 14 | */ |
| 15 | |
| 16 | #include "vim.h" |
| 17 | |
| 18 | #ifdef FEAT_SYN_HL |
| 19 | /* |
| 20 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 21 | */ |
| 22 | static int |
| 23 | advance_color_col(int vcol, int **color_cols) |
| 24 | { |
| 25 | while (**color_cols >= 0 && vcol > **color_cols) |
| 26 | ++*color_cols; |
| 27 | return (**color_cols >= 0); |
| 28 | } |
| 29 | #endif |
| 30 | |
| 31 | #ifdef FEAT_SYN_HL |
| 32 | /* |
| 33 | * Used when 'cursorlineopt' contains "screenline": compute the margins between |
| 34 | * which the highlighting is used. |
| 35 | */ |
| 36 | static void |
| 37 | margin_columns_win(win_T *wp, int *left_col, int *right_col) |
| 38 | { |
| 39 | // cache previous calculations depending on w_virtcol |
| 40 | static int saved_w_virtcol; |
| 41 | static win_T *prev_wp; |
| 42 | static int prev_left_col; |
| 43 | static int prev_right_col; |
| 44 | static int prev_col_off; |
| 45 | |
| 46 | int cur_col_off = win_col_off(wp); |
| 47 | int width1; |
| 48 | int width2; |
| 49 | |
| 50 | if (saved_w_virtcol == wp->w_virtcol |
| 51 | && prev_wp == wp && prev_col_off == cur_col_off) |
| 52 | { |
| 53 | *right_col = prev_right_col; |
| 54 | *left_col = prev_left_col; |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | width1 = wp->w_width - cur_col_off; |
| 59 | width2 = width1 + win_col_off2(wp); |
| 60 | |
| 61 | *left_col = 0; |
| 62 | *right_col = width1; |
| 63 | |
| 64 | if (wp->w_virtcol >= (colnr_T)width1) |
| 65 | *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2; |
| 66 | if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0) |
| 67 | *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1; |
| 68 | |
| 69 | // cache values |
| 70 | prev_left_col = *left_col; |
| 71 | prev_right_col = *right_col; |
| 72 | prev_wp = wp; |
| 73 | saved_w_virtcol = wp->w_virtcol; |
| 74 | prev_col_off = cur_col_off; |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | #ifdef FEAT_SIGNS |
| 79 | /* |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 80 | * Return TRUE if CursorLineSign highlight is to be used. |
| 81 | */ |
| 82 | static int |
| 83 | use_cursor_line_sign(win_T *wp, linenr_T lnum) |
| 84 | { |
| 85 | return wp->w_p_cul |
| 86 | && lnum == wp->w_cursor.lnum |
| 87 | && (wp->w_p_culopt_flags & CULOPT_NBR); |
| 88 | } |
| 89 | |
| 90 | /* |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 91 | * Get information needed to display the sign in line 'lnum' in window 'wp'. |
| 92 | * If 'nrcol' is TRUE, the sign is going to be displayed in the number column. |
| 93 | * Otherwise the sign is going to be displayed in the sign column. |
| 94 | */ |
| 95 | static void |
| 96 | get_sign_display_info( |
| 97 | int nrcol, |
| 98 | win_T *wp, |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 99 | linenr_T lnum, |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 100 | sign_attrs_T *sattr, |
| 101 | int wcr_attr, |
| 102 | int row, |
| 103 | int startrow, |
| 104 | int filler_lines UNUSED, |
| 105 | int filler_todo UNUSED, |
| 106 | int *c_extrap, |
| 107 | int *c_finalp, |
| 108 | char_u *extra, |
| 109 | char_u **pp_extra, |
| 110 | int *n_extrap, |
| 111 | int *char_attrp) |
| 112 | { |
| 113 | int text_sign; |
| 114 | # ifdef FEAT_SIGN_ICONS |
| 115 | int icon_sign; |
| 116 | # endif |
| 117 | |
| 118 | // Draw two cells with the sign value or blank. |
| 119 | *c_extrap = ' '; |
| 120 | *c_finalp = NUL; |
| 121 | if (nrcol) |
| 122 | *n_extrap = number_width(wp) + 1; |
| 123 | else |
| 124 | { |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 125 | if (use_cursor_line_sign(wp, lnum)) |
| 126 | *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS)); |
| 127 | else |
| 128 | *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 129 | *n_extrap = 2; |
| 130 | } |
| 131 | |
| 132 | if (row == startrow |
| 133 | #ifdef FEAT_DIFF |
| 134 | + filler_lines && filler_todo <= 0 |
| 135 | #endif |
| 136 | ) |
| 137 | { |
Bram Moolenaar | 6656c2e | 2019-10-24 15:00:04 +0200 | [diff] [blame] | 138 | text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 139 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 6656c2e | 2019-10-24 15:00:04 +0200 | [diff] [blame] | 140 | icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 141 | if (gui.in_use && icon_sign != 0) |
| 142 | { |
| 143 | // Use the image in this position. |
| 144 | if (nrcol) |
| 145 | { |
| 146 | *c_extrap = NUL; |
| 147 | sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE); |
| 148 | *pp_extra = extra; |
| 149 | *n_extrap = (int)STRLEN(*pp_extra); |
| 150 | } |
| 151 | else |
| 152 | *c_extrap = SIGN_BYTE; |
| 153 | # ifdef FEAT_NETBEANS_INTG |
| 154 | if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1)) |
| 155 | { |
| 156 | if (nrcol) |
| 157 | { |
| 158 | *c_extrap = NUL; |
| 159 | sprintf((char *)extra, "%-*c ", number_width(wp), |
| 160 | MULTISIGN_BYTE); |
| 161 | *pp_extra = extra; |
| 162 | *n_extrap = (int)STRLEN(*pp_extra); |
| 163 | } |
| 164 | else |
| 165 | *c_extrap = MULTISIGN_BYTE; |
| 166 | } |
| 167 | # endif |
| 168 | *c_finalp = NUL; |
| 169 | *char_attrp = icon_sign; |
| 170 | } |
| 171 | else |
| 172 | # endif |
| 173 | if (text_sign != 0) |
| 174 | { |
Bram Moolenaar | 6656c2e | 2019-10-24 15:00:04 +0200 | [diff] [blame] | 175 | *pp_extra = sattr->sat_text; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 176 | if (*pp_extra != NULL) |
| 177 | { |
| 178 | if (nrcol) |
| 179 | { |
| 180 | int n, width = number_width(wp) - 2; |
| 181 | |
| 182 | for (n = 0; n < width; n++) |
| 183 | extra[n] = ' '; |
| 184 | extra[n] = 0; |
| 185 | STRCAT(extra, *pp_extra); |
| 186 | STRCAT(extra, " "); |
| 187 | *pp_extra = extra; |
| 188 | } |
| 189 | *c_extrap = NUL; |
| 190 | *c_finalp = NUL; |
| 191 | *n_extrap = (int)STRLEN(*pp_extra); |
| 192 | } |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 193 | |
| 194 | if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0) |
| 195 | *char_attrp = sattr->sat_culhl; |
| 196 | else |
| 197 | *char_attrp = sattr->sat_texthl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | #endif |
| 202 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 203 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 204 | static textprop_T *current_text_props = NULL; |
| 205 | static buf_T *current_buf = NULL; |
| 206 | |
| 207 | static int |
| 208 | text_prop_compare(const void *s1, const void *s2) |
| 209 | { |
| 210 | int idx1, idx2; |
| 211 | proptype_T *pt1, *pt2; |
| 212 | colnr_T col1, col2; |
| 213 | |
| 214 | idx1 = *(int *)s1; |
| 215 | idx2 = *(int *)s2; |
| 216 | pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type); |
| 217 | pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type); |
| 218 | if (pt1 == pt2) |
| 219 | return 0; |
| 220 | if (pt1 == NULL) |
| 221 | return -1; |
| 222 | if (pt2 == NULL) |
| 223 | return 1; |
| 224 | if (pt1->pt_priority != pt2->pt_priority) |
| 225 | return pt1->pt_priority > pt2->pt_priority ? 1 : -1; |
| 226 | col1 = current_text_props[idx1].tp_col; |
| 227 | col2 = current_text_props[idx2].tp_col; |
| 228 | return col1 == col2 ? 0 : col1 > col2 ? 1 : -1; |
| 229 | } |
| 230 | #endif |
| 231 | |
| 232 | /* |
| 233 | * Display line "lnum" of window 'wp' on the screen. |
| 234 | * Start at row "startrow", stop when "endrow" is reached. |
| 235 | * wp->w_virtcol needs to be valid. |
| 236 | * |
| 237 | * Return the number of last row the line occupies. |
| 238 | */ |
| 239 | int |
| 240 | win_line( |
| 241 | win_T *wp, |
| 242 | linenr_T lnum, |
| 243 | int startrow, |
| 244 | int endrow, |
| 245 | int nochange UNUSED, // not updating for changed text |
| 246 | int number_only) // only update the number column |
| 247 | { |
| 248 | int col = 0; // visual column on screen |
| 249 | unsigned off; // offset in ScreenLines/ScreenAttrs |
| 250 | int c = 0; // init for GCC |
| 251 | long vcol = 0; // virtual column (for tabs) |
| 252 | #ifdef FEAT_LINEBREAK |
| 253 | long vcol_sbr = -1; // virtual column after showbreak |
| 254 | #endif |
| 255 | long vcol_prev = -1; // "vcol" of previous character |
| 256 | char_u *line; // current line |
| 257 | char_u *ptr; // current position in "line" |
| 258 | int row; // row in the window, excl w_winrow |
| 259 | int screen_row; // row on the screen, incl w_winrow |
| 260 | |
| 261 | char_u extra[21]; // "%ld " and 'fdc' must fit in here |
| 262 | int n_extra = 0; // number of extra chars |
| 263 | char_u *p_extra = NULL; // string of extra chars, plus NUL |
| 264 | char_u *p_extra_free = NULL; // p_extra needs to be freed |
| 265 | int c_extra = NUL; // extra chars, all the same |
| 266 | int c_final = NUL; // final char, mandatory if set |
| 267 | int extra_attr = 0; // attributes when n_extra != 0 |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 268 | #if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 269 | int in_linebreak = FALSE; // n_extra set for showing linebreak |
| 270 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 271 | static char_u *at_end_str = (char_u *)""; // used for p_extra when |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 272 | // displaying eol at end-of-line |
| 273 | int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 274 | int lcs_prec_todo = wp->w_lcs_chars.prec; |
| 275 | // prec until it's been used |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 276 | |
| 277 | // saved "extra" items for when draw_state becomes WL_LINE (again) |
| 278 | int saved_n_extra = 0; |
| 279 | char_u *saved_p_extra = NULL; |
| 280 | int saved_c_extra = 0; |
| 281 | int saved_c_final = 0; |
| 282 | int saved_char_attr = 0; |
| 283 | |
| 284 | int n_attr = 0; // chars with special attr |
| 285 | int saved_attr2 = 0; // char_attr saved for n_attr |
| 286 | int n_attr3 = 0; // chars with overruling special attr |
| 287 | int saved_attr3 = 0; // char_attr saved for n_attr3 |
| 288 | |
| 289 | int n_skip = 0; // nr of chars to skip for 'nowrap' |
| 290 | |
| 291 | int fromcol = -10; // start of inverting |
| 292 | int tocol = MAXCOL; // end of inverting |
| 293 | int fromcol_prev = -2; // start of inverting after cursor |
| 294 | int noinvcur = FALSE; // don't invert the cursor |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 295 | int lnum_in_visual_area = FALSE; |
| 296 | pos_T pos; |
| 297 | long v; |
| 298 | |
| 299 | int char_attr = 0; // attributes for next character |
| 300 | int attr_pri = FALSE; // char_attr has priority |
| 301 | int area_highlighting = FALSE; // Visual or incsearch highlighting |
| 302 | // in this line |
| 303 | int vi_attr = 0; // attributes for Visual and incsearch |
| 304 | // highlighting |
| 305 | int wcr_attr = 0; // attributes from 'wincolor' |
| 306 | int win_attr = 0; // background for whole window, except |
| 307 | // margins and "~" lines. |
| 308 | int area_attr = 0; // attributes desired by highlighting |
| 309 | int search_attr = 0; // attributes desired by 'hlsearch' |
| 310 | #ifdef FEAT_SYN_HL |
| 311 | int vcol_save_attr = 0; // saved attr for 'cursorcolumn' |
| 312 | int syntax_attr = 0; // attributes desired by syntax |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 313 | int prev_syntax_col = -1; // column of prev_syntax_attr |
| 314 | int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 315 | int has_syntax = FALSE; // this buffer has syntax highl. |
| 316 | int save_did_emsg; |
| 317 | int draw_color_col = FALSE; // highlight colorcolumn |
| 318 | int *color_cols = NULL; // pointer to according columns array |
| 319 | #endif |
| 320 | int eol_hl_off = 0; // 1 if highlighted char after EOL |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 321 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 322 | int text_prop_count; |
| 323 | int text_prop_next = 0; // next text property to use |
| 324 | textprop_T *text_props = NULL; |
| 325 | int *text_prop_idxs = NULL; |
| 326 | int text_props_active = 0; |
| 327 | proptype_T *text_prop_type = NULL; |
| 328 | int text_prop_attr = 0; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 329 | int text_prop_id = 0; // active property ID |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 330 | int text_prop_combine = FALSE; |
| 331 | #endif |
| 332 | #ifdef FEAT_SPELL |
| 333 | int has_spell = FALSE; // this buffer has spell checking |
Bram Moolenaar | ae49aa8 | 2022-02-25 21:05:36 +0000 | [diff] [blame] | 334 | int can_spell = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 335 | # define SPWORDLEN 150 |
| 336 | char_u nextline[SPWORDLEN * 2];// text with start of the next line |
| 337 | int nextlinecol = 0; // column where nextline[] starts |
| 338 | int nextline_idx = 0; // index in nextline[] where next line |
| 339 | // starts |
| 340 | int spell_attr = 0; // attributes desired by spelling |
| 341 | int word_end = 0; // last byte with same spell_attr |
| 342 | static linenr_T checked_lnum = 0; // line number for "checked_col" |
| 343 | static int checked_col = 0; // column in "checked_lnum" up to which |
| 344 | // there are no spell errors |
| 345 | static int cap_col = -1; // column to check for Cap word |
| 346 | static linenr_T capcol_lnum = 0; // line number where "cap_col" used |
| 347 | int cur_checked_col = 0; // checked column for current line |
| 348 | #endif |
| 349 | int extra_check = 0; // has extra highlighting |
| 350 | int multi_attr = 0; // attributes desired by multibyte |
| 351 | int mb_l = 1; // multi-byte byte length |
| 352 | int mb_c = 0; // decoded multi-byte character |
| 353 | int mb_utf8 = FALSE; // screen char is UTF-8 char |
| 354 | int u8cc[MAX_MCO]; // composing UTF-8 chars |
| 355 | #if defined(FEAT_DIFF) || defined(FEAT_SIGNS) |
| 356 | int filler_lines = 0; // nr of filler lines to be drawn |
| 357 | int filler_todo = 0; // nr of filler lines still to do + 1 |
Bram Moolenaar | 936dc60 | 2022-03-06 20:47:01 +0000 | [diff] [blame] | 358 | #else |
| 359 | # define filler_lines 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 360 | #endif |
| 361 | #ifdef FEAT_DIFF |
| 362 | hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting |
| 363 | int change_start = MAXCOL; // first col of changed area |
| 364 | int change_end = -1; // last col of changed area |
| 365 | #endif |
| 366 | colnr_T trailcol = MAXCOL; // start of trailing spaces |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 367 | colnr_T leadcol = 0; // start of leading spaces |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 368 | int in_multispace = FALSE; // in multiple consecutive spaces |
| 369 | int multispace_pos = 0; // position in lcs-multispace string |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 370 | #ifdef FEAT_LINEBREAK |
| 371 | int need_showbreak = FALSE; // overlong line, skipping first x |
| 372 | // chars |
| 373 | #endif |
| 374 | #if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \ |
| 375 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
| 376 | # define LINE_ATTR |
| 377 | int line_attr = 0; // attribute for the whole line |
| 378 | int line_attr_save; |
| 379 | #endif |
| 380 | #ifdef FEAT_SIGNS |
| 381 | int sign_present = FALSE; |
| 382 | sign_attrs_T sattr; |
James McCoy | a80aad7 | 2021-12-22 19:45:28 +0000 | [diff] [blame] | 383 | int num_attr = 0; // attribute for the number column |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 384 | #endif |
| 385 | #ifdef FEAT_ARABIC |
| 386 | int prev_c = 0; // previous Arabic character |
| 387 | int prev_c1 = 0; // first composing char for prev_c |
| 388 | #endif |
| 389 | #if defined(LINE_ATTR) |
| 390 | int did_line_attr = 0; |
| 391 | #endif |
| 392 | #ifdef FEAT_TERMINAL |
| 393 | int get_term_attr = FALSE; |
| 394 | #endif |
| 395 | #ifdef FEAT_SYN_HL |
| 396 | int cul_attr = 0; // set when 'cursorline' active |
| 397 | |
| 398 | // 'cursorlineopt' has "screenline" and cursor is in this line |
| 399 | int cul_screenline = FALSE; |
| 400 | |
| 401 | // margin columns for the screen line, needed for when 'cursorlineopt' |
| 402 | // contains "screenline" |
| 403 | int left_curline_col = 0; |
| 404 | int right_curline_col = 0; |
| 405 | #endif |
| 406 | |
| 407 | // draw_state: items that are drawn in sequence: |
| 408 | #define WL_START 0 // nothing done yet |
| 409 | #ifdef FEAT_CMDWIN |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 410 | # define WL_CMDLINE (WL_START + 1) // cmdline window column |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 411 | #else |
| 412 | # define WL_CMDLINE WL_START |
| 413 | #endif |
| 414 | #ifdef FEAT_FOLDING |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 415 | # define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn' |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 416 | #else |
| 417 | # define WL_FOLD WL_CMDLINE |
| 418 | #endif |
| 419 | #ifdef FEAT_SIGNS |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 420 | # define WL_SIGN (WL_FOLD + 1) // column for signs |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 421 | #else |
| 422 | # define WL_SIGN WL_FOLD // column for signs |
| 423 | #endif |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 424 | #define WL_NR (WL_SIGN + 1) // line number |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 425 | #ifdef FEAT_LINEBREAK |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 426 | # define WL_BRI (WL_NR + 1) // 'breakindent' |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 427 | #else |
| 428 | # define WL_BRI WL_NR |
| 429 | #endif |
| 430 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 431 | # define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff' |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 432 | #else |
| 433 | # define WL_SBR WL_BRI |
| 434 | #endif |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 435 | #define WL_LINE (WL_SBR + 1) // text in the line |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 436 | int draw_state = WL_START; // what to draw next |
| 437 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
| 438 | int feedback_col = 0; |
| 439 | int feedback_old_attr = -1; |
| 440 | #endif |
| 441 | int screen_line_flags = 0; |
| 442 | |
| 443 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) |
| 444 | int match_conc = 0; // cchar for match functions |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 445 | int on_last_col = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 446 | #endif |
| 447 | #ifdef FEAT_CONCEAL |
| 448 | int syntax_flags = 0; |
| 449 | int syntax_seqnr = 0; |
| 450 | int prev_syntax_id = 0; |
| 451 | int conceal_attr = HL_ATTR(HLF_CONCEAL); |
| 452 | int is_concealing = FALSE; |
| 453 | int boguscols = 0; // nonexistent columns added to force |
| 454 | // wrapping |
| 455 | int vcol_off = 0; // offset for concealed characters |
| 456 | int did_wcol = FALSE; |
| 457 | int old_boguscols = 0; |
| 458 | # define VCOL_HLC (vcol - vcol_off) |
| 459 | # define FIX_FOR_BOGUSCOLS \ |
| 460 | { \ |
| 461 | n_extra += vcol_off; \ |
| 462 | vcol -= vcol_off; \ |
| 463 | vcol_off = 0; \ |
| 464 | col -= boguscols; \ |
| 465 | old_boguscols = boguscols; \ |
| 466 | boguscols = 0; \ |
| 467 | } |
| 468 | #else |
| 469 | # define VCOL_HLC (vcol) |
| 470 | #endif |
| 471 | |
| 472 | if (startrow > endrow) // past the end already! |
| 473 | return startrow; |
| 474 | |
| 475 | row = startrow; |
| 476 | screen_row = row + W_WINROW(wp); |
| 477 | |
| 478 | if (!number_only) |
| 479 | { |
| 480 | // To speed up the loop below, set extra_check when there is linebreak, |
| 481 | // trailing white space and/or syntax processing to be done. |
| 482 | #ifdef FEAT_LINEBREAK |
| 483 | extra_check = wp->w_p_lbr; |
| 484 | #endif |
| 485 | #ifdef FEAT_SYN_HL |
| 486 | if (syntax_present(wp) && !wp->w_s->b_syn_error |
| 487 | # ifdef SYN_TIME_LIMIT |
| 488 | && !wp->w_s->b_syn_slow |
| 489 | # endif |
| 490 | ) |
| 491 | { |
| 492 | // Prepare for syntax highlighting in this line. When there is an |
| 493 | // error, stop syntax highlighting. |
| 494 | save_did_emsg = did_emsg; |
| 495 | did_emsg = FALSE; |
| 496 | syntax_start(wp, lnum); |
| 497 | if (did_emsg) |
| 498 | wp->w_s->b_syn_error = TRUE; |
| 499 | else |
| 500 | { |
| 501 | did_emsg = save_did_emsg; |
| 502 | #ifdef SYN_TIME_LIMIT |
| 503 | if (!wp->w_s->b_syn_slow) |
| 504 | #endif |
| 505 | { |
| 506 | has_syntax = TRUE; |
| 507 | extra_check = TRUE; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // Check for columns to display for 'colorcolumn'. |
| 513 | color_cols = wp->w_p_cc_cols; |
| 514 | if (color_cols != NULL) |
| 515 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
| 516 | #endif |
| 517 | |
| 518 | #ifdef FEAT_TERMINAL |
| 519 | if (term_show_buffer(wp->w_buffer)) |
| 520 | { |
| 521 | extra_check = TRUE; |
| 522 | get_term_attr = TRUE; |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 523 | win_attr = term_get_attr(wp, lnum, -1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 524 | } |
| 525 | #endif |
| 526 | |
| 527 | #ifdef FEAT_SPELL |
| 528 | if (wp->w_p_spell |
| 529 | && *wp->w_s->b_p_spl != NUL |
| 530 | && wp->w_s->b_langp.ga_len > 0 |
| 531 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
| 532 | { |
| 533 | // Prepare for spell checking. |
| 534 | has_spell = TRUE; |
| 535 | extra_check = TRUE; |
| 536 | |
| 537 | // Get the start of the next line, so that words that wrap to the |
| 538 | // next line are found too: "et<line-break>al.". |
| 539 | // Trick: skip a few chars for C/shell/Vim comments |
| 540 | nextline[SPWORDLEN] = NUL; |
| 541 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 542 | { |
| 543 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 544 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 545 | } |
| 546 | |
| 547 | // When a word wrapped from the previous line the start of the |
| 548 | // current line is valid. |
| 549 | if (lnum == checked_lnum) |
| 550 | cur_checked_col = checked_col; |
| 551 | checked_lnum = 0; |
| 552 | |
| 553 | // When there was a sentence end in the previous line may require a |
| 554 | // word starting with capital in this line. In line 1 always check |
| 555 | // the first word. |
| 556 | if (lnum != capcol_lnum) |
| 557 | cap_col = -1; |
| 558 | if (lnum == 1) |
| 559 | cap_col = 0; |
| 560 | capcol_lnum = 0; |
| 561 | } |
| 562 | #endif |
| 563 | |
| 564 | // handle Visual active in this window |
| 565 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 566 | { |
Bram Moolenaar | 14285cb | 2020-03-27 20:58:37 +0100 | [diff] [blame] | 567 | pos_T *top, *bot; |
| 568 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 569 | if (LTOREQ_POS(curwin->w_cursor, VIsual)) |
| 570 | { |
| 571 | // Visual is after curwin->w_cursor |
| 572 | top = &curwin->w_cursor; |
| 573 | bot = &VIsual; |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | // Visual is before curwin->w_cursor |
| 578 | top = &VIsual; |
| 579 | bot = &curwin->w_cursor; |
| 580 | } |
| 581 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
| 582 | if (VIsual_mode == Ctrl_V) |
| 583 | { |
| 584 | // block mode |
| 585 | if (lnum_in_visual_area) |
| 586 | { |
| 587 | fromcol = wp->w_old_cursor_fcol; |
| 588 | tocol = wp->w_old_cursor_lcol; |
| 589 | } |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | // non-block mode |
| 594 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 595 | fromcol = 0; |
| 596 | else if (lnum == top->lnum) |
| 597 | { |
| 598 | if (VIsual_mode == 'V') // linewise |
| 599 | fromcol = 0; |
| 600 | else |
| 601 | { |
| 602 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 603 | if (gchar_pos(top) == NUL) |
| 604 | tocol = fromcol + 1; |
| 605 | } |
| 606 | } |
| 607 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 608 | { |
| 609 | if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0) |
| 610 | { |
| 611 | fromcol = -10; |
| 612 | tocol = MAXCOL; |
| 613 | } |
| 614 | else if (bot->col == MAXCOL) |
| 615 | tocol = MAXCOL; |
| 616 | else |
| 617 | { |
| 618 | pos = *bot; |
| 619 | if (*p_sel == 'e') |
| 620 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 621 | else |
| 622 | { |
| 623 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 624 | ++tocol; |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | // Check if the character under the cursor should not be inverted |
Bram Moolenaar | 6656c2e | 2019-10-24 15:00:04 +0200 | [diff] [blame] | 631 | if (!highlight_match && lnum == curwin->w_cursor.lnum |
| 632 | && wp == curwin |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 633 | #ifdef FEAT_GUI |
| 634 | && !gui.in_use |
| 635 | #endif |
| 636 | ) |
| 637 | noinvcur = TRUE; |
| 638 | |
| 639 | // if inverting in this line set area_highlighting |
| 640 | if (fromcol >= 0) |
| 641 | { |
| 642 | area_highlighting = TRUE; |
| 643 | vi_attr = HL_ATTR(HLF_V); |
| 644 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
| 645 | if ((clip_star.available && !clip_star.owned |
| 646 | && clip_isautosel_star()) |
| 647 | || (clip_plus.available && !clip_plus.owned |
| 648 | && clip_isautosel_plus())) |
| 649 | vi_attr = HL_ATTR(HLF_VNC); |
| 650 | #endif |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | // handle 'incsearch' and ":s///c" highlighting |
| 655 | else if (highlight_match |
| 656 | && wp == curwin |
| 657 | && lnum >= curwin->w_cursor.lnum |
| 658 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 659 | { |
| 660 | if (lnum == curwin->w_cursor.lnum) |
| 661 | getvcol(curwin, &(curwin->w_cursor), |
| 662 | (colnr_T *)&fromcol, NULL, NULL); |
| 663 | else |
| 664 | fromcol = 0; |
| 665 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 666 | { |
| 667 | pos.lnum = lnum; |
| 668 | pos.col = search_match_endcol; |
| 669 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 670 | } |
| 671 | else |
| 672 | tocol = MAXCOL; |
| 673 | // do at least one character; happens when past end of line |
Bram Moolenaar | 448465e | 2020-11-25 13:49:27 +0100 | [diff] [blame] | 674 | if (fromcol == tocol && search_match_endcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 675 | tocol = fromcol + 1; |
| 676 | area_highlighting = TRUE; |
| 677 | vi_attr = HL_ATTR(HLF_I); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | #ifdef FEAT_DIFF |
| 682 | filler_lines = diff_check(wp, lnum); |
| 683 | if (filler_lines < 0) |
| 684 | { |
| 685 | if (filler_lines == -1) |
| 686 | { |
| 687 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 688 | diff_hlf = HLF_ADD; // added line |
| 689 | else if (change_start == 0) |
| 690 | diff_hlf = HLF_TXD; // changed text |
| 691 | else |
| 692 | diff_hlf = HLF_CHD; // changed line |
| 693 | } |
| 694 | else |
| 695 | diff_hlf = HLF_ADD; // added line |
| 696 | filler_lines = 0; |
| 697 | area_highlighting = TRUE; |
| 698 | } |
| 699 | if (lnum == wp->w_topline) |
| 700 | filler_lines = wp->w_topfill; |
| 701 | filler_todo = filler_lines; |
| 702 | #endif |
| 703 | |
| 704 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 4eb7dae | 2019-11-12 22:33:45 +0100 | [diff] [blame] | 705 | sign_present = buf_get_signattrs(wp, lnum, &sattr); |
James McCoy | a80aad7 | 2021-12-22 19:45:28 +0000 | [diff] [blame] | 706 | if (sign_present) |
| 707 | num_attr = sattr.sat_numhl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 708 | #endif |
| 709 | |
| 710 | #ifdef LINE_ATTR |
| 711 | # ifdef FEAT_SIGNS |
| 712 | // If this line has a sign with line highlighting set line_attr. |
| 713 | if (sign_present) |
Bram Moolenaar | 6656c2e | 2019-10-24 15:00:04 +0200 | [diff] [blame] | 714 | line_attr = sattr.sat_linehl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 715 | # endif |
| 716 | # if defined(FEAT_QUICKFIX) |
| 717 | // Highlight the current line in the quickfix window. |
| 718 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
| 719 | line_attr = HL_ATTR(HLF_QFL); |
| 720 | # endif |
| 721 | if (line_attr != 0) |
| 722 | area_highlighting = TRUE; |
| 723 | #endif |
| 724 | |
| 725 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 726 | ptr = line; |
| 727 | |
| 728 | #ifdef FEAT_SPELL |
| 729 | if (has_spell && !number_only) |
| 730 | { |
| 731 | // For checking first word with a capital skip white space. |
| 732 | if (cap_col == 0) |
| 733 | cap_col = getwhitecols(line); |
| 734 | |
| 735 | // To be able to spell-check over line boundaries copy the end of the |
| 736 | // current line into nextline[]. Above the start of the next line was |
| 737 | // copied to nextline[SPWORDLEN]. |
| 738 | if (nextline[SPWORDLEN] == NUL) |
| 739 | { |
| 740 | // No next line or it is empty. |
| 741 | nextlinecol = MAXCOL; |
| 742 | nextline_idx = 0; |
| 743 | } |
| 744 | else |
| 745 | { |
| 746 | v = (long)STRLEN(line); |
| 747 | if (v < SPWORDLEN) |
| 748 | { |
| 749 | // Short line, use it completely and append the start of the |
| 750 | // next line. |
| 751 | nextlinecol = 0; |
| 752 | mch_memmove(nextline, line, (size_t)v); |
| 753 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
| 754 | nextline_idx = v + 1; |
| 755 | } |
| 756 | else |
| 757 | { |
| 758 | // Long line, use only the last SPWORDLEN bytes. |
| 759 | nextlinecol = v - SPWORDLEN; |
| 760 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 761 | nextline_idx = SPWORDLEN + 1; |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | #endif |
| 766 | |
| 767 | if (wp->w_p_list) |
| 768 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 769 | if (wp->w_lcs_chars.space |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 770 | || wp->w_lcs_chars.multispace != NULL |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 771 | || wp->w_lcs_chars.leadmultispace != NULL |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 772 | || wp->w_lcs_chars.trail |
| 773 | || wp->w_lcs_chars.lead |
| 774 | || wp->w_lcs_chars.nbsp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 775 | extra_check = TRUE; |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 776 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 777 | // find start of trailing whitespace |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 778 | if (wp->w_lcs_chars.trail) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 779 | { |
| 780 | trailcol = (colnr_T)STRLEN(ptr); |
| 781 | while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1])) |
| 782 | --trailcol; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 783 | trailcol += (colnr_T)(ptr - line); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 784 | } |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 785 | // find end of leading whitespace |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 786 | if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL) |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 787 | { |
| 788 | leadcol = 0; |
| 789 | while (VIM_ISWHITE(ptr[leadcol])) |
| 790 | ++leadcol; |
| 791 | if (ptr[leadcol] == NUL) |
| 792 | // in a line full of spaces all of them are treated as trailing |
| 793 | leadcol = (colnr_T)0; |
| 794 | else |
| 795 | // keep track of the first column not filled with spaces |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 796 | leadcol += (colnr_T)(ptr - line) + 1; |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 797 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | wcr_attr = get_wcr_attr(wp); |
| 801 | if (wcr_attr != 0) |
| 802 | { |
| 803 | win_attr = wcr_attr; |
| 804 | area_highlighting = TRUE; |
| 805 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 806 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 807 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 808 | if (WIN_IS_POPUP(wp)) |
| 809 | screen_line_flags |= SLF_POPUP; |
| 810 | #endif |
| 811 | |
| 812 | // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 813 | // first character to be displayed. |
| 814 | if (wp->w_p_wrap) |
| 815 | v = wp->w_skipcol; |
| 816 | else |
| 817 | v = wp->w_leftcol; |
| 818 | if (v > 0 && !number_only) |
| 819 | { |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 820 | char_u *prev_ptr = ptr; |
| 821 | chartabsize_T cts; |
Bram Moolenaar | 6d023f9 | 2022-07-25 21:15:45 +0100 | [diff] [blame] | 822 | int charsize = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 823 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 824 | init_chartabsize_arg(&cts, wp, lnum, vcol, line, ptr); |
| 825 | while (cts.cts_vcol < v && *cts.cts_ptr != NUL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 826 | { |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 827 | charsize = win_lbr_chartabsize(&cts, NULL); |
| 828 | cts.cts_vcol += charsize; |
| 829 | prev_ptr = cts.cts_ptr; |
| 830 | MB_PTR_ADV(cts.cts_ptr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 831 | } |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 832 | vcol = cts.cts_vcol; |
| 833 | ptr = cts.cts_ptr; |
| 834 | clear_chartabsize_arg(&cts); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 835 | |
| 836 | // When: |
| 837 | // - 'cuc' is set, or |
| 838 | // - 'colorcolumn' is set, or |
| 839 | // - 'virtualedit' is set, or |
| 840 | // - the visual mode is active, |
| 841 | // the end of the line may be before the start of the displayed part. |
| 842 | if (vcol < v && ( |
| 843 | #ifdef FEAT_SYN_HL |
| 844 | wp->w_p_cuc || draw_color_col || |
| 845 | #endif |
| 846 | virtual_active() || |
| 847 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
| 848 | vcol = v; |
| 849 | |
| 850 | // Handle a character that's not completely on the screen: Put ptr at |
| 851 | // that character but skip the first few screen characters. |
| 852 | if (vcol > v) |
| 853 | { |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 854 | vcol -= charsize; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 855 | ptr = prev_ptr; |
| 856 | // If the character fits on the screen, don't need to skip it. |
| 857 | // Except for a TAB. |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 858 | if (( (*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB) && col == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 859 | n_skip = v - vcol; |
| 860 | } |
| 861 | |
| 862 | // Adjust for when the inverted text is before the screen, |
| 863 | // and when the start of the inverted text is before the screen. |
| 864 | if (tocol <= vcol) |
| 865 | fromcol = 0; |
| 866 | else if (fromcol >= 0 && fromcol < vcol) |
| 867 | fromcol = vcol; |
| 868 | |
| 869 | #ifdef FEAT_LINEBREAK |
| 870 | // When w_skipcol is non-zero, first line needs 'showbreak' |
| 871 | if (wp->w_p_wrap) |
| 872 | need_showbreak = TRUE; |
| 873 | #endif |
| 874 | #ifdef FEAT_SPELL |
| 875 | // When spell checking a word we need to figure out the start of the |
| 876 | // word and if it's badly spelled or not. |
| 877 | if (has_spell) |
| 878 | { |
| 879 | int len; |
| 880 | colnr_T linecol = (colnr_T)(ptr - line); |
| 881 | hlf_T spell_hlf = HLF_COUNT; |
| 882 | |
| 883 | pos = wp->w_cursor; |
| 884 | wp->w_cursor.lnum = lnum; |
| 885 | wp->w_cursor.col = linecol; |
| 886 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
| 887 | |
| 888 | // spell_move_to() may call ml_get() and make "line" invalid |
| 889 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 890 | ptr = line + linecol; |
| 891 | |
| 892 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
| 893 | { |
| 894 | // no bad word found at line start, don't check until end of a |
| 895 | // word |
| 896 | spell_hlf = HLF_COUNT; |
| 897 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
| 898 | } |
| 899 | else |
| 900 | { |
| 901 | // bad word found, use attributes until end of word |
| 902 | word_end = wp->w_cursor.col + len + 1; |
| 903 | |
| 904 | // Turn index into actual attributes. |
| 905 | if (spell_hlf != HLF_COUNT) |
| 906 | spell_attr = highlight_attr[spell_hlf]; |
| 907 | } |
| 908 | wp->w_cursor = pos; |
| 909 | |
| 910 | # ifdef FEAT_SYN_HL |
| 911 | // Need to restart syntax highlighting for this line. |
| 912 | if (has_syntax) |
| 913 | syntax_start(wp, lnum); |
| 914 | # endif |
| 915 | } |
| 916 | #endif |
| 917 | } |
| 918 | |
| 919 | // Correct highlighting for cursor that can't be disabled. |
| 920 | // Avoids having to check this for each character. |
| 921 | if (fromcol >= 0) |
| 922 | { |
| 923 | if (noinvcur) |
| 924 | { |
| 925 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 926 | { |
| 927 | // highlighting starts at cursor, let it start just after the |
| 928 | // cursor |
| 929 | fromcol_prev = fromcol; |
| 930 | fromcol = -1; |
| 931 | } |
| 932 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 933 | // restart highlighting after the cursor |
| 934 | fromcol_prev = wp->w_virtcol; |
| 935 | } |
| 936 | if (fromcol >= tocol) |
| 937 | fromcol = -1; |
| 938 | } |
| 939 | |
| 940 | #ifdef FEAT_SEARCH_EXTRA |
| 941 | if (!number_only) |
| 942 | { |
| 943 | v = (long)(ptr - line); |
| 944 | area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v, |
| 945 | &line, &screen_search_hl, |
| 946 | &search_attr); |
| 947 | ptr = line + v; // "line" may have been updated |
| 948 | } |
| 949 | #endif |
| 950 | |
| 951 | #ifdef FEAT_SYN_HL |
| 952 | // Cursor line highlighting for 'cursorline' in the current window. |
| 953 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 954 | { |
| 955 | // Do not show the cursor line in the text when Visual mode is active, |
zeertzjq | c20e46a | 2022-03-23 14:55:23 +0000 | [diff] [blame] | 956 | // because it's not clear what is selected then. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 957 | if (!(wp == curwin && VIsual_active) |
| 958 | && wp->w_p_culopt_flags != CULOPT_NBR) |
| 959 | { |
| 960 | cul_screenline = (wp->w_p_wrap |
| 961 | && (wp->w_p_culopt_flags & CULOPT_SCRLINE)); |
| 962 | |
| 963 | // Only set line_attr here when "screenline" is not present in |
| 964 | // 'cursorlineopt'. Otherwise it's done later. |
| 965 | if (!cul_screenline) |
| 966 | { |
| 967 | cul_attr = HL_ATTR(HLF_CUL); |
Bram Moolenaar | 39f7aa3 | 2020-08-31 22:00:05 +0200 | [diff] [blame] | 968 | # ifdef FEAT_SIGNS |
| 969 | // Combine the 'cursorline' and sign highlighting, depending on |
| 970 | // the sign priority. |
| 971 | if (sign_present && sattr.sat_linehl > 0) |
| 972 | { |
| 973 | if (sattr.sat_priority >= 100) |
| 974 | line_attr = hl_combine_attr(cul_attr, line_attr); |
| 975 | else |
| 976 | line_attr = hl_combine_attr(line_attr, cul_attr); |
| 977 | } |
| 978 | else |
| 979 | # endif |
Bram Moolenaar | 7fe956d | 2022-07-03 14:21:09 +0100 | [diff] [blame] | 980 | # if defined(FEAT_QUICKFIX) |
| 981 | line_attr = hl_combine_attr(line_attr, cul_attr); |
| 982 | # else |
Bram Moolenaar | 39f7aa3 | 2020-08-31 22:00:05 +0200 | [diff] [blame] | 983 | line_attr = cul_attr; |
Bram Moolenaar | 7fe956d | 2022-07-03 14:21:09 +0100 | [diff] [blame] | 984 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 985 | } |
| 986 | else |
| 987 | { |
| 988 | line_attr_save = line_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 989 | margin_columns_win(wp, &left_curline_col, &right_curline_col); |
| 990 | } |
| 991 | area_highlighting = TRUE; |
| 992 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 993 | } |
| 994 | #endif |
| 995 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 996 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 997 | { |
| 998 | char_u *prop_start; |
| 999 | |
| 1000 | text_prop_count = get_text_props(wp->w_buffer, lnum, |
| 1001 | &prop_start, FALSE); |
| 1002 | if (text_prop_count > 0) |
| 1003 | { |
| 1004 | // Make a copy of the properties, so that they are properly |
| 1005 | // aligned. |
| 1006 | text_props = ALLOC_MULT(textprop_T, text_prop_count); |
| 1007 | if (text_props != NULL) |
| 1008 | mch_memmove(text_props, prop_start, |
| 1009 | text_prop_count * sizeof(textprop_T)); |
| 1010 | |
| 1011 | // Allocate an array for the indexes. |
| 1012 | text_prop_idxs = ALLOC_MULT(int, text_prop_count); |
| 1013 | area_highlighting = TRUE; |
| 1014 | extra_check = TRUE; |
| 1015 | } |
| 1016 | } |
| 1017 | #endif |
| 1018 | |
| 1019 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 1020 | col = 0; |
| 1021 | |
| 1022 | #ifdef FEAT_RIGHTLEFT |
| 1023 | if (wp->w_p_rl) |
| 1024 | { |
| 1025 | // Rightleft window: process the text in the normal direction, but put |
| 1026 | // it in current_ScreenLine[] from right to left. Start at the |
| 1027 | // rightmost column of the window. |
| 1028 | col = wp->w_width - 1; |
| 1029 | off += col; |
| 1030 | screen_line_flags |= SLF_RIGHTLEFT; |
| 1031 | } |
| 1032 | #endif |
| 1033 | |
| 1034 | // Repeat for the whole displayed line. |
| 1035 | for (;;) |
| 1036 | { |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1037 | char_u *prev_ptr = ptr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1038 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1039 | int has_match_conc = 0; // match wants to conceal |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1040 | #endif |
| 1041 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1042 | int did_decrement_ptr = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1043 | #endif |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1044 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1045 | // Skip this quickly when working on the text. |
| 1046 | if (draw_state != WL_LINE) |
| 1047 | { |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1048 | #ifdef FEAT_SYN_HL |
| 1049 | if (cul_screenline) |
| 1050 | { |
| 1051 | cul_attr = 0; |
| 1052 | line_attr = line_attr_save; |
| 1053 | } |
| 1054 | #endif |
| 1055 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1056 | #ifdef FEAT_CMDWIN |
| 1057 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 1058 | { |
| 1059 | draw_state = WL_CMDLINE; |
| 1060 | if (cmdwin_type != 0 && wp == curwin) |
| 1061 | { |
| 1062 | // Draw the cmdline character. |
| 1063 | n_extra = 1; |
| 1064 | c_extra = cmdwin_type; |
| 1065 | c_final = NUL; |
| 1066 | char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT)); |
| 1067 | } |
| 1068 | } |
| 1069 | #endif |
| 1070 | |
| 1071 | #ifdef FEAT_FOLDING |
| 1072 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 1073 | { |
| 1074 | int fdc = compute_foldcolumn(wp, 0); |
| 1075 | |
| 1076 | draw_state = WL_FOLD; |
| 1077 | if (fdc > 0) |
| 1078 | { |
| 1079 | // Draw the 'foldcolumn'. Allocate a buffer, "extra" may |
| 1080 | // already be in use. |
| 1081 | vim_free(p_extra_free); |
Bram Moolenaar | 4fa1175 | 2021-03-03 13:26:02 +0100 | [diff] [blame] | 1082 | p_extra_free = alloc(MAX_MCO * fdc + 1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1083 | if (p_extra_free != NULL) |
| 1084 | { |
Bram Moolenaar | 9355ae4 | 2021-03-08 19:04:05 +0100 | [diff] [blame] | 1085 | n_extra = (int)fill_foldcolumn(p_extra_free, wp, |
Bram Moolenaar | 4fa1175 | 2021-03-03 13:26:02 +0100 | [diff] [blame] | 1086 | FALSE, lnum); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1087 | p_extra_free[n_extra] = NUL; |
| 1088 | p_extra = p_extra_free; |
| 1089 | c_extra = NUL; |
| 1090 | c_final = NUL; |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 1091 | if (use_cursor_line_sign(wp, lnum)) |
| 1092 | char_attr = |
| 1093 | hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF)); |
| 1094 | else |
| 1095 | char_attr = |
| 1096 | hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | #endif |
| 1101 | |
| 1102 | #ifdef FEAT_SIGNS |
| 1103 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 1104 | { |
| 1105 | draw_state = WL_SIGN; |
| 1106 | // Show the sign column when there are any signs in this |
| 1107 | // buffer or when using Netbeans. |
| 1108 | if (signcolumn_on(wp)) |
| 1109 | get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr, |
| 1110 | row, startrow, filler_lines, filler_todo, &c_extra, |
| 1111 | &c_final, extra, &p_extra, &n_extra, &char_attr); |
| 1112 | } |
| 1113 | #endif |
| 1114 | |
| 1115 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 1116 | { |
| 1117 | draw_state = WL_NR; |
| 1118 | // Display the absolute or relative line number. After the |
| 1119 | // first fill with blanks when the 'n' flag isn't in 'cpo' |
| 1120 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 936dc60 | 2022-03-06 20:47:01 +0000 | [diff] [blame] | 1121 | && (row == startrow + filler_lines |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1122 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 1123 | { |
| 1124 | #ifdef FEAT_SIGNS |
| 1125 | // If 'signcolumn' is set to 'number' and a sign is present |
| 1126 | // in 'lnum', then display the sign instead of the line |
| 1127 | // number. |
| 1128 | if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') |
| 1129 | && sign_present) |
| 1130 | get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr, |
| 1131 | row, startrow, filler_lines, filler_todo, |
| 1132 | &c_extra, &c_final, extra, &p_extra, &n_extra, |
| 1133 | &char_attr); |
| 1134 | else |
| 1135 | #endif |
| 1136 | { |
| 1137 | // Draw the line number (empty space after wrapping). |
Bram Moolenaar | 936dc60 | 2022-03-06 20:47:01 +0000 | [diff] [blame] | 1138 | if (row == startrow + filler_lines) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1139 | { |
| 1140 | long num; |
| 1141 | char *fmt = "%*ld "; |
| 1142 | |
| 1143 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 1144 | // 'number' + 'norelativenumber' |
| 1145 | num = (long)lnum; |
| 1146 | else |
| 1147 | { |
| 1148 | // 'relativenumber', don't use negative numbers |
| 1149 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
| 1150 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
| 1151 | { |
| 1152 | // 'number' + 'relativenumber' |
| 1153 | num = lnum; |
| 1154 | fmt = "%-*ld "; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | sprintf((char *)extra, fmt, |
| 1159 | number_width(wp), num); |
| 1160 | if (wp->w_skipcol > 0) |
| 1161 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 1162 | *p_extra = '-'; |
| 1163 | #ifdef FEAT_RIGHTLEFT |
| 1164 | if (wp->w_p_rl) // reverse line numbers |
| 1165 | { |
| 1166 | char_u *p1, *p2; |
| 1167 | int t; |
| 1168 | |
| 1169 | // like rl_mirror(), but keep the space at the end |
Christian Brabandt | 29f0dc3 | 2021-06-16 19:28:34 +0200 | [diff] [blame] | 1170 | p2 = skipwhite(extra); |
| 1171 | p2 = skiptowhite(p2) - 1; |
| 1172 | for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1173 | { |
| 1174 | t = *p1; |
| 1175 | *p1 = *p2; |
| 1176 | *p2 = t; |
| 1177 | } |
| 1178 | } |
| 1179 | #endif |
| 1180 | p_extra = extra; |
| 1181 | c_extra = NUL; |
| 1182 | c_final = NUL; |
| 1183 | } |
| 1184 | else |
| 1185 | { |
| 1186 | c_extra = ' '; |
| 1187 | c_final = NUL; |
| 1188 | } |
| 1189 | n_extra = number_width(wp) + 1; |
| 1190 | char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N)); |
| 1191 | #ifdef FEAT_SYN_HL |
| 1192 | // When 'cursorline' is set highlight the line number of |
| 1193 | // the current line differently. |
zeertzjq | 754d2b4 | 2022-03-13 13:40:45 +0000 | [diff] [blame] | 1194 | // When 'cursorlineopt' does not have "line" only |
| 1195 | // highlight the line number itself. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1196 | // TODO: Can we use CursorLine instead of CursorLineNr |
| 1197 | // when CursorLineNr isn't set? |
Bram Moolenaar | 49474ca | 2019-10-05 21:57:12 +0200 | [diff] [blame] | 1198 | if (wp->w_p_cul |
| 1199 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1200 | && (wp->w_p_culopt_flags & CULOPT_NBR) |
Bram Moolenaar | 127969c | 2022-03-06 19:54:13 +0000 | [diff] [blame] | 1201 | && (row == startrow + filler_lines |
| 1202 | || (row > startrow + filler_lines |
zeertzjq | 754d2b4 | 2022-03-13 13:40:45 +0000 | [diff] [blame] | 1203 | && (wp->w_p_culopt_flags & CULOPT_LINE)))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1204 | char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN)); |
| 1205 | #endif |
Bram Moolenaar | efae76a | 2019-10-27 22:54:58 +0100 | [diff] [blame] | 1206 | if (wp->w_p_rnu && lnum < wp->w_cursor.lnum |
| 1207 | && HL_ATTR(HLF_LNA) != 0) |
| 1208 | // Use LineNrAbove |
| 1209 | char_attr = hl_combine_attr(wcr_attr, |
| 1210 | HL_ATTR(HLF_LNA)); |
| 1211 | if (wp->w_p_rnu && lnum > wp->w_cursor.lnum |
| 1212 | && HL_ATTR(HLF_LNB) != 0) |
| 1213 | // Use LineNrBelow |
| 1214 | char_attr = hl_combine_attr(wcr_attr, |
| 1215 | HL_ATTR(HLF_LNB)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1216 | } |
James McCoy | a80aad7 | 2021-12-22 19:45:28 +0000 | [diff] [blame] | 1217 | #ifdef FEAT_SIGNS |
| 1218 | if (num_attr) |
| 1219 | char_attr = num_attr; |
| 1220 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b81f56f | 2020-02-23 15:29:46 +0100 | [diff] [blame] | 1225 | if (wp->w_briopt_sbr && draw_state == WL_BRI - 1 |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1226 | && n_extra == 0 && *get_showbreak_value(wp) != NUL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1227 | // draw indent after showbreak value |
| 1228 | draw_state = WL_BRI; |
Bram Moolenaar | b81f56f | 2020-02-23 15:29:46 +0100 | [diff] [blame] | 1229 | else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1230 | // After the showbreak, draw the breakindent |
| 1231 | draw_state = WL_BRI - 1; |
| 1232 | |
| 1233 | // draw 'breakindent': indent wrapped text accordingly |
| 1234 | if (draw_state == WL_BRI - 1 && n_extra == 0) |
| 1235 | { |
| 1236 | draw_state = WL_BRI; |
| 1237 | // if need_showbreak is set, breakindent also applies |
Bram Moolenaar | fe15499 | 2022-03-22 20:42:12 +0000 | [diff] [blame] | 1238 | if (wp->w_p_bri && (row != startrow || need_showbreak) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1239 | # ifdef FEAT_DIFF |
| 1240 | && filler_lines == 0 |
| 1241 | # endif |
| 1242 | ) |
| 1243 | { |
| 1244 | char_attr = 0; |
| 1245 | # ifdef FEAT_DIFF |
| 1246 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1247 | char_attr = HL_ATTR(diff_hlf); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1248 | # endif |
| 1249 | p_extra = NULL; |
| 1250 | c_extra = ' '; |
Bram Moolenaar | 2f7b7b1 | 2019-11-03 15:46:48 +0100 | [diff] [blame] | 1251 | c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1252 | n_extra = get_breakindent_win(wp, |
| 1253 | ml_get_buf(wp->w_buffer, lnum, FALSE)); |
Bram Moolenaar | e882f7a | 2020-05-16 14:07:39 +0200 | [diff] [blame] | 1254 | if (row == startrow) |
| 1255 | { |
| 1256 | n_extra -= win_col_off2(wp); |
| 1257 | if (n_extra < 0) |
| 1258 | n_extra = 0; |
| 1259 | } |
Bram Moolenaar | b81f56f | 2020-02-23 15:29:46 +0100 | [diff] [blame] | 1260 | if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr) |
Bram Moolenaar | dfede9a | 2020-01-23 19:59:22 +0100 | [diff] [blame] | 1261 | need_showbreak = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1262 | // Correct end of highlighted area for 'breakindent', |
| 1263 | // required when 'linebreak' is also set. |
| 1264 | if (tocol == vcol) |
| 1265 | tocol += n_extra; |
| 1266 | } |
| 1267 | } |
| 1268 | #endif |
| 1269 | |
| 1270 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 1271 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 1272 | { |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1273 | char_u *sbr; |
| 1274 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1275 | draw_state = WL_SBR; |
| 1276 | # ifdef FEAT_DIFF |
| 1277 | if (filler_todo > 0) |
| 1278 | { |
| 1279 | // Draw "deleted" diff line(s). |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1280 | if (char2cells(wp->w_fill_chars.diff) > 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1281 | { |
| 1282 | c_extra = '-'; |
| 1283 | c_final = NUL; |
| 1284 | } |
| 1285 | else |
| 1286 | { |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1287 | c_extra = wp->w_fill_chars.diff; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1288 | c_final = NUL; |
| 1289 | } |
| 1290 | # ifdef FEAT_RIGHTLEFT |
| 1291 | if (wp->w_p_rl) |
| 1292 | n_extra = col + 1; |
| 1293 | else |
| 1294 | # endif |
| 1295 | n_extra = wp->w_width - col; |
| 1296 | char_attr = HL_ATTR(HLF_DED); |
| 1297 | } |
| 1298 | # endif |
| 1299 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1300 | sbr = get_showbreak_value(wp); |
| 1301 | if (*sbr != NUL && need_showbreak) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1302 | { |
| 1303 | // Draw 'showbreak' at the start of each broken line. |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1304 | p_extra = sbr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1305 | c_extra = NUL; |
| 1306 | c_final = NUL; |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1307 | n_extra = (int)STRLEN(sbr); |
Bram Moolenaar | dfede9a | 2020-01-23 19:59:22 +0100 | [diff] [blame] | 1308 | if (wp->w_skipcol == 0 || !wp->w_p_wrap) |
| 1309 | need_showbreak = FALSE; |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1310 | vcol_sbr = vcol + MB_CHARLEN(sbr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1311 | // Correct end of highlighted area for 'showbreak', |
| 1312 | // required when 'linebreak' is also set. |
| 1313 | if (tocol == vcol) |
| 1314 | tocol += n_extra; |
| 1315 | // combine 'showbreak' with 'wincolor' |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 1316 | char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1317 | # ifdef FEAT_SYN_HL |
| 1318 | // combine 'showbreak' with 'cursorline' |
| 1319 | if (cul_attr != 0) |
| 1320 | char_attr = hl_combine_attr(char_attr, cul_attr); |
| 1321 | # endif |
| 1322 | } |
| 1323 | # endif |
| 1324 | } |
| 1325 | #endif |
| 1326 | |
| 1327 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 1328 | { |
| 1329 | draw_state = WL_LINE; |
| 1330 | if (saved_n_extra) |
| 1331 | { |
| 1332 | // Continue item from end of wrapped line. |
| 1333 | n_extra = saved_n_extra; |
| 1334 | c_extra = saved_c_extra; |
| 1335 | c_final = saved_c_final; |
| 1336 | p_extra = saved_p_extra; |
| 1337 | char_attr = saved_char_attr; |
| 1338 | } |
| 1339 | else |
| 1340 | char_attr = win_attr; |
| 1341 | } |
| 1342 | } |
| 1343 | #ifdef FEAT_SYN_HL |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1344 | if (cul_screenline && draw_state == WL_LINE |
| 1345 | && vcol >= left_curline_col |
| 1346 | && vcol < right_curline_col) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1347 | { |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1348 | cul_attr = HL_ATTR(HLF_CUL); |
| 1349 | line_attr = cul_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1350 | } |
| 1351 | #endif |
| 1352 | |
| 1353 | // When still displaying '$' of change command, stop at cursor. |
| 1354 | // When only displaying the (relative) line number and that's done, |
| 1355 | // stop here. |
Bram Moolenaar | 511feec | 2020-06-18 19:15:27 +0200 | [diff] [blame] | 1356 | if (((dollar_vcol >= 0 && wp == curwin |
| 1357 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol) |
| 1358 | || (number_only && draw_state > WL_NR)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1359 | #ifdef FEAT_DIFF |
| 1360 | && filler_todo <= 0 |
| 1361 | #endif |
| 1362 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1363 | { |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1364 | screen_line(wp, screen_row, wp->w_wincol, col, -wp->w_width, |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1365 | screen_line_flags); |
| 1366 | // Pretend we have finished updating the window. Except when |
| 1367 | // 'cursorcolumn' is set. |
| 1368 | #ifdef FEAT_SYN_HL |
| 1369 | if (wp->w_p_cuc) |
| 1370 | row = wp->w_cline_row + wp->w_cline_height; |
| 1371 | else |
| 1372 | #endif |
| 1373 | row = wp->w_height; |
| 1374 | break; |
| 1375 | } |
| 1376 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1377 | if (draw_state == WL_LINE && (area_highlighting || extra_check)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1378 | { |
| 1379 | // handle Visual or match highlighting in this line |
| 1380 | if (vcol == fromcol |
| 1381 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 1382 | && (*mb_ptr2cells)(ptr) > 1) |
| 1383 | || ((int)vcol_prev == fromcol_prev |
| 1384 | && vcol_prev < vcol // not at margin |
| 1385 | && vcol < tocol)) |
| 1386 | area_attr = vi_attr; // start highlighting |
| 1387 | else if (area_attr != 0 |
| 1388 | && (vcol == tocol |
| 1389 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
| 1390 | area_attr = 0; // stop highlighting |
| 1391 | |
| 1392 | #ifdef FEAT_SEARCH_EXTRA |
| 1393 | if (!n_extra) |
| 1394 | { |
| 1395 | // Check for start/end of 'hlsearch' and other matches. |
| 1396 | // After end, check for start/end of next match. |
| 1397 | // When another match, have to check for start again. |
| 1398 | v = (long)(ptr - line); |
| 1399 | search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line, |
| 1400 | &screen_search_hl, &has_match_conc, |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 1401 | &match_conc, did_line_attr, lcs_eol_one, |
| 1402 | &on_last_col); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1403 | ptr = line + v; // "line" may have been changed |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1404 | prev_ptr = ptr; |
Bram Moolenaar | fc838d6 | 2020-06-25 22:23:48 +0200 | [diff] [blame] | 1405 | |
| 1406 | // Do not allow a conceal over EOL otherwise EOL will be missed |
| 1407 | // and bad things happen. |
| 1408 | if (*ptr == NUL) |
| 1409 | has_match_conc = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1410 | } |
| 1411 | #endif |
| 1412 | |
| 1413 | #ifdef FEAT_DIFF |
| 1414 | if (diff_hlf != (hlf_T)0) |
| 1415 | { |
| 1416 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 1417 | && n_extra == 0) |
| 1418 | diff_hlf = HLF_TXD; // changed text |
| 1419 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 1420 | && n_extra == 0) |
| 1421 | diff_hlf = HLF_CHD; // changed line |
| 1422 | line_attr = HL_ATTR(diff_hlf); |
| 1423 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 1424 | && wp->w_p_culopt_flags != CULOPT_NBR |
| 1425 | && (!cul_screenline || (vcol >= left_curline_col |
| 1426 | && vcol <= right_curline_col))) |
| 1427 | line_attr = hl_combine_attr( |
| 1428 | line_attr, HL_ATTR(HLF_CUL)); |
| 1429 | } |
| 1430 | #endif |
| 1431 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 1432 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1433 | if (text_props != NULL) |
| 1434 | { |
| 1435 | int pi; |
| 1436 | int bcol = (int)(ptr - line); |
| 1437 | |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1438 | if (n_extra > 0 |
| 1439 | # ifdef FEAT_LINEBREAK |
| 1440 | && !in_linebreak |
| 1441 | # endif |
| 1442 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1443 | --bcol; // still working on the previous char, e.g. Tab |
| 1444 | |
| 1445 | // Check if any active property ends. |
| 1446 | for (pi = 0; pi < text_props_active; ++pi) |
| 1447 | { |
| 1448 | int tpi = text_prop_idxs[pi]; |
| 1449 | |
| 1450 | if (bcol >= text_props[tpi].tp_col - 1 |
| 1451 | + text_props[tpi].tp_len) |
| 1452 | { |
| 1453 | if (pi + 1 < text_props_active) |
| 1454 | mch_memmove(text_prop_idxs + pi, |
| 1455 | text_prop_idxs + pi + 1, |
| 1456 | sizeof(int) |
| 1457 | * (text_props_active - (pi + 1))); |
| 1458 | --text_props_active; |
| 1459 | --pi; |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1460 | # ifdef FEAT_LINEBREAK |
| 1461 | // not exactly right but should work in most cases |
| 1462 | if (in_linebreak && syntax_attr == text_prop_attr) |
| 1463 | syntax_attr = 0; |
| 1464 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1465 | } |
| 1466 | } |
| 1467 | |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 1468 | # ifdef FEAT_LINEBREAK |
| 1469 | if (n_extra > 0 && in_linebreak) |
| 1470 | // not on the next char yet, don't start another prop |
| 1471 | --bcol; |
| 1472 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1473 | // Add any text property that starts in this column. |
| 1474 | while (text_prop_next < text_prop_count |
| 1475 | && bcol >= text_props[text_prop_next].tp_col - 1) |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1476 | { |
| 1477 | if (bcol <= text_props[text_prop_next].tp_col - 1 |
| 1478 | + text_props[text_prop_next].tp_len) |
| 1479 | text_prop_idxs[text_props_active++] = text_prop_next; |
| 1480 | ++text_prop_next; |
| 1481 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1482 | |
| 1483 | text_prop_attr = 0; |
| 1484 | text_prop_combine = FALSE; |
Bram Moolenaar | 053f712 | 2019-09-23 22:17:15 +0200 | [diff] [blame] | 1485 | text_prop_type = NULL; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1486 | text_prop_id = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1487 | if (text_props_active > 0) |
| 1488 | { |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1489 | int used_tpi; |
| 1490 | int used_attr = 0; |
| 1491 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1492 | // Sort the properties on priority and/or starting last. |
| 1493 | // Then combine the attributes, highest priority last. |
| 1494 | current_text_props = text_props; |
| 1495 | current_buf = wp->w_buffer; |
| 1496 | qsort((void *)text_prop_idxs, (size_t)text_props_active, |
| 1497 | sizeof(int), text_prop_compare); |
| 1498 | |
| 1499 | for (pi = 0; pi < text_props_active; ++pi) |
| 1500 | { |
| 1501 | int tpi = text_prop_idxs[pi]; |
| 1502 | proptype_T *pt = text_prop_type_by_id( |
| 1503 | wp->w_buffer, text_props[tpi].tp_type); |
| 1504 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1505 | if (pt != NULL && pt->pt_hl_id > 0 |
| 1506 | && text_props[tpi].tp_id != -MAXCOL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1507 | { |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1508 | used_attr = syn_id2attr(pt->pt_hl_id); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1509 | text_prop_type = pt; |
| 1510 | text_prop_attr = |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1511 | hl_combine_attr(text_prop_attr, used_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1512 | text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1513 | text_prop_id = text_props[tpi].tp_id; |
| 1514 | used_tpi = tpi; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1515 | } |
| 1516 | } |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1517 | if (n_extra == 0 && text_prop_id < 0 |
| 1518 | && -text_prop_id |
| 1519 | <= wp->w_buffer->b_textprop_text.ga_len) |
| 1520 | { |
| 1521 | char_u *p = ((char_u **)wp->w_buffer |
| 1522 | ->b_textprop_text.ga_data)[ |
| 1523 | -text_prop_id - 1]; |
| 1524 | if (p != NULL) |
| 1525 | { |
| 1526 | p_extra = p; |
| 1527 | n_extra = STRLEN(p); |
| 1528 | extra_attr = used_attr; |
| 1529 | n_attr = n_extra; |
| 1530 | text_prop_attr = 0; |
| 1531 | |
| 1532 | // If the cursor is on or after this position, |
| 1533 | // move it forward. |
| 1534 | if (wp == curwin |
| 1535 | && lnum == curwin->w_cursor.lnum |
| 1536 | && curwin->w_cursor.col >= vcol) |
| 1537 | curwin->w_cursor.col += n_extra; |
| 1538 | } |
| 1539 | // reset the ID in the copy to avoid it being used |
| 1540 | // again |
| 1541 | text_props[used_tpi].tp_id = -MAXCOL; |
| 1542 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | #endif |
| 1546 | |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 1547 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 1548 | if (extra_check && n_extra == 0) |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1549 | { |
Bram Moolenaar | 82260af | 2019-10-20 13:16:22 +0200 | [diff] [blame] | 1550 | syntax_attr = 0; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 1551 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1552 | if (get_term_attr) |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 1553 | syntax_attr = term_get_attr(wp, lnum, vcol); |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 1554 | # endif |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1555 | // Get syntax attribute. |
| 1556 | if (has_syntax) |
| 1557 | { |
| 1558 | // Get the syntax attribute for the character. If there |
| 1559 | // is an error, disable syntax highlighting. |
| 1560 | save_did_emsg = did_emsg; |
| 1561 | did_emsg = FALSE; |
| 1562 | |
| 1563 | v = (long)(ptr - line); |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 1564 | if (v == prev_syntax_col) |
| 1565 | // at same column again |
| 1566 | syntax_attr = prev_syntax_attr; |
| 1567 | else |
| 1568 | { |
Bram Moolenaar | b2fe1d6 | 2019-10-16 21:33:40 +0200 | [diff] [blame] | 1569 | # ifdef FEAT_SPELL |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 1570 | can_spell = TRUE; |
Bram Moolenaar | b2fe1d6 | 2019-10-16 21:33:40 +0200 | [diff] [blame] | 1571 | # endif |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 1572 | syntax_attr = get_syntax_attr((colnr_T)v, |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1573 | # ifdef FEAT_SPELL |
| 1574 | has_spell ? &can_spell : |
| 1575 | # endif |
| 1576 | NULL, FALSE); |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 1577 | prev_syntax_col = v; |
| 1578 | prev_syntax_attr = syntax_attr; |
| 1579 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1580 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1581 | if (did_emsg) |
| 1582 | { |
| 1583 | wp->w_s->b_syn_error = TRUE; |
| 1584 | has_syntax = FALSE; |
| 1585 | syntax_attr = 0; |
| 1586 | } |
| 1587 | else |
| 1588 | did_emsg = save_did_emsg; |
| 1589 | # ifdef SYN_TIME_LIMIT |
| 1590 | if (wp->w_s->b_syn_slow) |
| 1591 | has_syntax = FALSE; |
| 1592 | # endif |
| 1593 | |
| 1594 | // Need to get the line again, a multi-line regexp may |
| 1595 | // have made it invalid. |
| 1596 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 1597 | ptr = line + v; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1598 | prev_ptr = ptr; |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1599 | # ifdef FEAT_CONCEAL |
| 1600 | // no concealing past the end of the line, it interferes |
| 1601 | // with line highlighting |
| 1602 | if (*ptr == NUL) |
| 1603 | syntax_flags = 0; |
| 1604 | else |
| 1605 | syntax_flags = get_syntax_info(&syntax_seqnr); |
| 1606 | # endif |
| 1607 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1608 | } |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 1609 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1610 | // Combine text property highlight into syntax highlight. |
| 1611 | if (text_prop_type != NULL) |
| 1612 | { |
| 1613 | if (text_prop_combine) |
| 1614 | syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr); |
| 1615 | else |
| 1616 | syntax_attr = text_prop_attr; |
| 1617 | } |
| 1618 | # endif |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 1619 | #endif |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1620 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1621 | // Decide which of the highlight attributes to use. |
| 1622 | attr_pri = TRUE; |
| 1623 | #ifdef LINE_ATTR |
| 1624 | if (area_attr != 0) |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 1625 | { |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1626 | char_attr = hl_combine_attr(line_attr, area_attr); |
Bram Moolenaar | 2d5f385 | 2021-04-21 15:11:42 +0200 | [diff] [blame] | 1627 | if (!highlight_match) |
| 1628 | // let search highlight show in Visual area if possible |
| 1629 | char_attr = hl_combine_attr(search_attr, char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 1630 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1631 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 1632 | # endif |
| 1633 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1634 | else if (search_attr != 0) |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 1635 | { |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1636 | char_attr = hl_combine_attr(line_attr, search_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 1637 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1638 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 1639 | # endif |
| 1640 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1641 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
| 1642 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 1643 | || vcol >= tocol)) |
| 1644 | { |
| 1645 | // Use line_attr when not in the Visual or 'incsearch' area |
| 1646 | // (area_attr may be 0 when "noinvcur" is set). |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1647 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1648 | char_attr = hl_combine_attr(syntax_attr, line_attr); |
| 1649 | # else |
| 1650 | char_attr = line_attr; |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1651 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1652 | attr_pri = FALSE; |
| 1653 | } |
| 1654 | #else |
| 1655 | if (area_attr != 0) |
| 1656 | char_attr = area_attr; |
| 1657 | else if (search_attr != 0) |
| 1658 | char_attr = search_attr; |
| 1659 | #endif |
| 1660 | else |
| 1661 | { |
| 1662 | attr_pri = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1663 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1664 | char_attr = syntax_attr; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 1665 | #else |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1666 | char_attr = 0; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 1667 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1668 | } |
| 1669 | } |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 1670 | |
| 1671 | // combine attribute with 'wincolor' |
| 1672 | if (win_attr != 0) |
| 1673 | { |
| 1674 | if (char_attr == 0) |
| 1675 | char_attr = win_attr; |
| 1676 | else |
| 1677 | char_attr = hl_combine_attr(win_attr, char_attr); |
| 1678 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1679 | |
| 1680 | // Get the next character to put on the screen. |
| 1681 | |
| 1682 | // The "p_extra" points to the extra stuff that is inserted to |
| 1683 | // represent special characters (non-printable stuff) and other |
| 1684 | // things. When all characters are the same, c_extra is used. |
| 1685 | // If c_final is set, it will compulsorily be used at the end. |
| 1686 | // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 1687 | // "p_extra[n_extra]". |
| 1688 | // For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 1689 | if (n_extra > 0) |
| 1690 | { |
| 1691 | if (c_extra != NUL || (n_extra == 1 && c_final != NUL)) |
| 1692 | { |
| 1693 | c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra; |
| 1694 | mb_c = c; // doesn't handle non-utf-8 multi-byte! |
| 1695 | if (enc_utf8 && utf_char2len(c) > 1) |
| 1696 | { |
| 1697 | mb_utf8 = TRUE; |
| 1698 | u8cc[0] = 0; |
| 1699 | c = 0xc0; |
| 1700 | } |
| 1701 | else |
| 1702 | mb_utf8 = FALSE; |
| 1703 | } |
| 1704 | else |
| 1705 | { |
| 1706 | c = *p_extra; |
| 1707 | if (has_mbyte) |
| 1708 | { |
| 1709 | mb_c = c; |
| 1710 | if (enc_utf8) |
| 1711 | { |
| 1712 | // If the UTF-8 character is more than one byte: |
| 1713 | // Decode it into "mb_c". |
| 1714 | mb_l = utfc_ptr2len(p_extra); |
| 1715 | mb_utf8 = FALSE; |
| 1716 | if (mb_l > n_extra) |
| 1717 | mb_l = 1; |
| 1718 | else if (mb_l > 1) |
| 1719 | { |
| 1720 | mb_c = utfc_ptr2char(p_extra, u8cc); |
| 1721 | mb_utf8 = TRUE; |
| 1722 | c = 0xc0; |
| 1723 | } |
| 1724 | } |
| 1725 | else |
| 1726 | { |
| 1727 | // if this is a DBCS character, put it in "mb_c" |
| 1728 | mb_l = MB_BYTE2LEN(c); |
| 1729 | if (mb_l >= n_extra) |
| 1730 | mb_l = 1; |
| 1731 | else if (mb_l > 1) |
| 1732 | mb_c = (c << 8) + p_extra[1]; |
| 1733 | } |
| 1734 | if (mb_l == 0) // at the NUL at end-of-line |
| 1735 | mb_l = 1; |
| 1736 | |
| 1737 | // If a double-width char doesn't fit display a '>' in the |
| 1738 | // last column. |
| 1739 | if (( |
| 1740 | # ifdef FEAT_RIGHTLEFT |
| 1741 | wp->w_p_rl ? (col <= 0) : |
| 1742 | # endif |
| 1743 | (col >= wp->w_width - 1)) |
| 1744 | && (*mb_char2cells)(mb_c) == 2) |
| 1745 | { |
| 1746 | c = '>'; |
| 1747 | mb_c = c; |
| 1748 | mb_l = 1; |
| 1749 | mb_utf8 = FALSE; |
| 1750 | multi_attr = HL_ATTR(HLF_AT); |
| 1751 | #ifdef FEAT_SYN_HL |
| 1752 | if (cul_attr) |
| 1753 | multi_attr = hl_combine_attr(multi_attr, cul_attr); |
| 1754 | #endif |
Bram Moolenaar | 92e25ab | 2019-11-26 22:39:10 +0100 | [diff] [blame] | 1755 | multi_attr = hl_combine_attr(win_attr, multi_attr); |
| 1756 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1757 | // put the pointer back to output the double-width |
| 1758 | // character at the start of the next line. |
| 1759 | ++n_extra; |
| 1760 | --p_extra; |
| 1761 | } |
| 1762 | else |
| 1763 | { |
| 1764 | n_extra -= mb_l - 1; |
| 1765 | p_extra += mb_l - 1; |
| 1766 | } |
| 1767 | } |
| 1768 | ++p_extra; |
| 1769 | } |
| 1770 | --n_extra; |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 1771 | #if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1772 | if (n_extra <= 0) |
| 1773 | in_linebreak = FALSE; |
| 1774 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1775 | } |
| 1776 | else |
| 1777 | { |
| 1778 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1779 | int c0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1780 | #endif |
Bram Moolenaar | 2f7b7b1 | 2019-11-03 15:46:48 +0100 | [diff] [blame] | 1781 | VIM_CLEAR(p_extra_free); |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1782 | prev_ptr = ptr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1783 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1784 | // Get a character from the line itself. |
| 1785 | c = *ptr; |
| 1786 | #ifdef FEAT_LINEBREAK |
| 1787 | c0 = *ptr; |
| 1788 | #endif |
| 1789 | if (has_mbyte) |
| 1790 | { |
| 1791 | mb_c = c; |
| 1792 | if (enc_utf8) |
| 1793 | { |
| 1794 | // If the UTF-8 character is more than one byte: Decode it |
| 1795 | // into "mb_c". |
| 1796 | mb_l = utfc_ptr2len(ptr); |
| 1797 | mb_utf8 = FALSE; |
| 1798 | if (mb_l > 1) |
| 1799 | { |
| 1800 | mb_c = utfc_ptr2char(ptr, u8cc); |
| 1801 | // Overlong encoded ASCII or ASCII with composing char |
| 1802 | // is displayed normally, except a NUL. |
| 1803 | if (mb_c < 0x80) |
| 1804 | { |
| 1805 | c = mb_c; |
| 1806 | #ifdef FEAT_LINEBREAK |
| 1807 | c0 = mb_c; |
| 1808 | #endif |
| 1809 | } |
| 1810 | mb_utf8 = TRUE; |
| 1811 | |
| 1812 | // At start of the line we can have a composing char. |
| 1813 | // Draw it as a space with a composing char. |
| 1814 | if (utf_iscomposing(mb_c)) |
| 1815 | { |
| 1816 | int i; |
| 1817 | |
| 1818 | for (i = Screen_mco - 1; i > 0; --i) |
| 1819 | u8cc[i] = u8cc[i - 1]; |
| 1820 | u8cc[0] = mb_c; |
| 1821 | mb_c = ' '; |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | if ((mb_l == 1 && c >= 0x80) |
| 1826 | || (mb_l >= 1 && mb_c == 0) |
| 1827 | || (mb_l > 1 && (!vim_isprintc(mb_c)))) |
| 1828 | { |
| 1829 | // Illegal UTF-8 byte: display as <xx>. |
| 1830 | // Non-BMP character : display as ? or fullwidth ?. |
| 1831 | transchar_hex(extra, mb_c); |
| 1832 | # ifdef FEAT_RIGHTLEFT |
| 1833 | if (wp->w_p_rl) // reverse |
| 1834 | rl_mirror(extra); |
| 1835 | # endif |
| 1836 | p_extra = extra; |
| 1837 | c = *p_extra; |
| 1838 | mb_c = mb_ptr2char_adv(&p_extra); |
| 1839 | mb_utf8 = (c >= 0x80); |
| 1840 | n_extra = (int)STRLEN(p_extra); |
| 1841 | c_extra = NUL; |
| 1842 | c_final = NUL; |
| 1843 | if (area_attr == 0 && search_attr == 0) |
| 1844 | { |
| 1845 | n_attr = n_extra + 1; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 1846 | extra_attr = hl_combine_attr( |
| 1847 | win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1848 | saved_attr2 = char_attr; // save current attr |
| 1849 | } |
| 1850 | } |
| 1851 | else if (mb_l == 0) // at the NUL at end-of-line |
| 1852 | mb_l = 1; |
| 1853 | #ifdef FEAT_ARABIC |
| 1854 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 1855 | { |
| 1856 | // Do Arabic shaping. |
| 1857 | int pc, pc1, nc; |
| 1858 | int pcc[MAX_MCO]; |
| 1859 | |
| 1860 | // The idea of what is the previous and next |
| 1861 | // character depends on 'rightleft'. |
| 1862 | if (wp->w_p_rl) |
| 1863 | { |
| 1864 | pc = prev_c; |
| 1865 | pc1 = prev_c1; |
| 1866 | nc = utf_ptr2char(ptr + mb_l); |
| 1867 | prev_c1 = u8cc[0]; |
| 1868 | } |
| 1869 | else |
| 1870 | { |
| 1871 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
| 1872 | nc = prev_c; |
| 1873 | pc1 = pcc[0]; |
| 1874 | } |
| 1875 | prev_c = mb_c; |
| 1876 | |
| 1877 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
| 1878 | } |
| 1879 | else |
| 1880 | prev_c = mb_c; |
| 1881 | #endif |
| 1882 | } |
| 1883 | else // enc_dbcs |
| 1884 | { |
| 1885 | mb_l = MB_BYTE2LEN(c); |
| 1886 | if (mb_l == 0) // at the NUL at end-of-line |
| 1887 | mb_l = 1; |
| 1888 | else if (mb_l > 1) |
| 1889 | { |
| 1890 | // We assume a second byte below 32 is illegal. |
| 1891 | // Hopefully this is OK for all double-byte encodings! |
| 1892 | if (ptr[1] >= 32) |
| 1893 | mb_c = (c << 8) + ptr[1]; |
| 1894 | else |
| 1895 | { |
| 1896 | if (ptr[1] == NUL) |
| 1897 | { |
| 1898 | // head byte at end of line |
| 1899 | mb_l = 1; |
Bram Moolenaar | 32ee627 | 2020-06-10 14:16:49 +0200 | [diff] [blame] | 1900 | transchar_nonprint(wp->w_buffer, extra, c); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1901 | } |
| 1902 | else |
| 1903 | { |
| 1904 | // illegal tail byte |
| 1905 | mb_l = 2; |
| 1906 | STRCPY(extra, "XX"); |
| 1907 | } |
| 1908 | p_extra = extra; |
| 1909 | n_extra = (int)STRLEN(extra) - 1; |
| 1910 | c_extra = NUL; |
| 1911 | c_final = NUL; |
| 1912 | c = *p_extra++; |
| 1913 | if (area_attr == 0 && search_attr == 0) |
| 1914 | { |
| 1915 | n_attr = n_extra + 1; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 1916 | extra_attr = hl_combine_attr( |
| 1917 | win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1918 | saved_attr2 = char_attr; // save current attr |
| 1919 | } |
| 1920 | mb_c = c; |
| 1921 | } |
| 1922 | } |
| 1923 | } |
| 1924 | // If a double-width char doesn't fit display a '>' in the |
| 1925 | // last column; the character is displayed at the start of the |
| 1926 | // next line. |
| 1927 | if (( |
| 1928 | # ifdef FEAT_RIGHTLEFT |
| 1929 | wp->w_p_rl ? (col <= 0) : |
| 1930 | # endif |
| 1931 | (col >= wp->w_width - 1)) |
| 1932 | && (*mb_char2cells)(mb_c) == 2) |
| 1933 | { |
| 1934 | c = '>'; |
| 1935 | mb_c = c; |
| 1936 | mb_utf8 = FALSE; |
| 1937 | mb_l = 1; |
Bram Moolenaar | 92e25ab | 2019-11-26 22:39:10 +0100 | [diff] [blame] | 1938 | multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1939 | // Put pointer back so that the character will be |
| 1940 | // displayed at the start of the next line. |
| 1941 | --ptr; |
| 1942 | #ifdef FEAT_CONCEAL |
| 1943 | did_decrement_ptr = TRUE; |
| 1944 | #endif |
| 1945 | } |
| 1946 | else if (*ptr != NUL) |
| 1947 | ptr += mb_l - 1; |
| 1948 | |
| 1949 | // If a double-width char doesn't fit at the left side display |
| 1950 | // a '<' in the first column. Don't do this for unprintable |
| 1951 | // characters. |
| 1952 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
| 1953 | { |
| 1954 | n_extra = 1; |
| 1955 | c_extra = MB_FILLER_CHAR; |
| 1956 | c_final = NUL; |
| 1957 | c = ' '; |
| 1958 | if (area_attr == 0 && search_attr == 0) |
| 1959 | { |
| 1960 | n_attr = n_extra + 1; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 1961 | extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1962 | saved_attr2 = char_attr; // save current attr |
| 1963 | } |
| 1964 | mb_c = c; |
| 1965 | mb_utf8 = FALSE; |
| 1966 | mb_l = 1; |
| 1967 | } |
| 1968 | |
| 1969 | } |
| 1970 | ++ptr; |
| 1971 | |
| 1972 | if (extra_check) |
| 1973 | { |
| 1974 | #ifdef FEAT_SPELL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1975 | // Check spelling (unless at the end of the line). |
| 1976 | // Only do this when there is no syntax highlighting, the |
| 1977 | // @Spell cluster is not used or the current syntax item |
| 1978 | // contains the @Spell cluster. |
Bram Moolenaar | 7751d1d | 2019-10-18 20:37:08 +0200 | [diff] [blame] | 1979 | v = (long)(ptr - line); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1980 | if (has_spell && v >= word_end && v > cur_checked_col) |
| 1981 | { |
| 1982 | spell_attr = 0; |
| 1983 | if (c != 0 && ( |
| 1984 | # ifdef FEAT_SYN_HL |
| 1985 | !has_syntax || |
| 1986 | # endif |
| 1987 | can_spell)) |
| 1988 | { |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1989 | char_u *p; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1990 | int len; |
| 1991 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 1992 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1993 | if (has_mbyte) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1994 | v -= mb_l - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1995 | |
| 1996 | // Use nextline[] if possible, it has the start of the |
| 1997 | // next line concatenated. |
| 1998 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 1999 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 2000 | else |
| 2001 | p = prev_ptr; |
| 2002 | cap_col -= (int)(prev_ptr - line); |
| 2003 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 2004 | nochange); |
| 2005 | word_end = v + len; |
| 2006 | |
| 2007 | // In Insert mode only highlight a word that |
| 2008 | // doesn't touch the cursor. |
| 2009 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 2010 | && (State & MODE_INSERT) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2011 | && wp->w_cursor.lnum == lnum |
| 2012 | && wp->w_cursor.col >= |
| 2013 | (colnr_T)(prev_ptr - line) |
| 2014 | && wp->w_cursor.col < (colnr_T)word_end) |
| 2015 | { |
| 2016 | spell_hlf = HLF_COUNT; |
| 2017 | spell_redraw_lnum = lnum; |
| 2018 | } |
| 2019 | |
| 2020 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
| 2021 | && (p - nextline) + len > nextline_idx) |
| 2022 | { |
| 2023 | // Remember that the good word continues at the |
| 2024 | // start of the next line. |
| 2025 | checked_lnum = lnum + 1; |
Bram Moolenaar | 7751d1d | 2019-10-18 20:37:08 +0200 | [diff] [blame] | 2026 | checked_col = (int)((p - nextline) |
| 2027 | + len - nextline_idx); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | // Turn index into actual attributes. |
| 2031 | if (spell_hlf != HLF_COUNT) |
| 2032 | spell_attr = highlight_attr[spell_hlf]; |
| 2033 | |
| 2034 | if (cap_col > 0) |
| 2035 | { |
| 2036 | if (p != prev_ptr |
| 2037 | && (p - nextline) + cap_col >= nextline_idx) |
| 2038 | { |
| 2039 | // Remember that the word in the next line |
| 2040 | // must start with a capital. |
| 2041 | capcol_lnum = lnum + 1; |
| 2042 | cap_col = (int)((p - nextline) + cap_col |
| 2043 | - nextline_idx); |
| 2044 | } |
| 2045 | else |
| 2046 | // Compute the actual column. |
| 2047 | cap_col += (int)(prev_ptr - line); |
| 2048 | } |
| 2049 | } |
| 2050 | } |
| 2051 | if (spell_attr != 0) |
| 2052 | { |
| 2053 | if (!attr_pri) |
| 2054 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 2055 | else |
| 2056 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 2057 | } |
| 2058 | #endif |
| 2059 | #ifdef FEAT_LINEBREAK |
| 2060 | // Found last space before word: check for line break. |
| 2061 | if (wp->w_p_lbr && c0 == c |
| 2062 | && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr)) |
| 2063 | { |
Bram Moolenaar | 20e0c3d | 2021-08-31 20:57:55 +0200 | [diff] [blame] | 2064 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) |
| 2065 | : 0; |
| 2066 | char_u *p = ptr - (mb_off + 1); |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2067 | chartabsize_T cts; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2068 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2069 | init_chartabsize_arg(&cts, wp, lnum, vcol, line, p); |
| 2070 | n_extra = win_lbr_chartabsize(&cts, NULL) - 1; |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 2071 | |
| 2072 | // We have just drawn the showbreak value, no need to add |
Bram Moolenaar | 20e0c3d | 2021-08-31 20:57:55 +0200 | [diff] [blame] | 2073 | // space for it again. |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 2074 | if (vcol == vcol_sbr) |
Bram Moolenaar | 20e0c3d | 2021-08-31 20:57:55 +0200 | [diff] [blame] | 2075 | { |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 2076 | n_extra -= MB_CHARLEN(get_showbreak_value(wp)); |
Bram Moolenaar | 20e0c3d | 2021-08-31 20:57:55 +0200 | [diff] [blame] | 2077 | if (n_extra < 0) |
| 2078 | n_extra = 0; |
| 2079 | } |
Bram Moolenaar | 0bbca54 | 2022-01-11 13:14:54 +0000 | [diff] [blame] | 2080 | if (on_last_col && c != TAB) |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 2081 | // Do not continue search/match highlighting over the |
Bram Moolenaar | 0bbca54 | 2022-01-11 13:14:54 +0000 | [diff] [blame] | 2082 | // line break, but for TABs the highlighting should |
| 2083 | // include the complete width of the character |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 2084 | search_attr = 0; |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 2085 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2086 | if (c == TAB && n_extra + col > wp->w_width) |
| 2087 | # ifdef FEAT_VARTABS |
| 2088 | n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts, |
| 2089 | wp->w_buffer->b_p_vts_array) - 1; |
| 2090 | # else |
| 2091 | n_extra = (int)wp->w_buffer->b_p_ts |
| 2092 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 2093 | # endif |
| 2094 | |
| 2095 | c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
| 2096 | c_final = NUL; |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 2097 | # if defined(FEAT_PROP_POPUP) |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2098 | if (n_extra > 0 && c != TAB) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2099 | in_linebreak = TRUE; |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 2100 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2101 | if (VIM_ISWHITE(c)) |
| 2102 | { |
Bram Moolenaar | 912bc4a | 2019-12-01 18:58:11 +0100 | [diff] [blame] | 2103 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2104 | if (c == TAB) |
| 2105 | // See "Tab alignment" below. |
| 2106 | FIX_FOR_BOGUSCOLS; |
Bram Moolenaar | 912bc4a | 2019-12-01 18:58:11 +0100 | [diff] [blame] | 2107 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2108 | if (!wp->w_p_list) |
| 2109 | c = ' '; |
| 2110 | } |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2111 | clear_chartabsize_arg(&cts); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2112 | } |
| 2113 | #endif |
| 2114 | |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 2115 | in_multispace = c == ' ' |
| 2116 | && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' '); |
| 2117 | if (!in_multispace) |
| 2118 | multispace_pos = 0; |
| 2119 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2120 | // 'list': Change char 160 to 'nbsp' and space to 'space' |
| 2121 | // setting in 'listchars'. But not when the character is |
| 2122 | // followed by a composing character (use mb_l to check that). |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2123 | if (wp->w_p_list |
| 2124 | && ((((c == 160 && mb_l == 1) |
| 2125 | || (mb_utf8 |
| 2126 | && ((mb_c == 160 && mb_l == 2) |
| 2127 | || (mb_c == 0x202f && mb_l == 3)))) |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2128 | && wp->w_lcs_chars.nbsp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2129 | || (c == ' ' |
| 2130 | && mb_l == 1 |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 2131 | && (wp->w_lcs_chars.space |
| 2132 | || (in_multispace |
| 2133 | && wp->w_lcs_chars.multispace != NULL)) |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 2134 | && ptr - line >= leadcol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2135 | && ptr - line <= trailcol))) |
| 2136 | { |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 2137 | if (in_multispace && wp->w_lcs_chars.multispace != NULL) |
| 2138 | { |
| 2139 | c = wp->w_lcs_chars.multispace[multispace_pos++]; |
| 2140 | if (wp->w_lcs_chars.multispace[multispace_pos] == NUL) |
| 2141 | multispace_pos = 0; |
| 2142 | } |
| 2143 | else |
| 2144 | c = (c == ' ') ? wp->w_lcs_chars.space |
| 2145 | : wp->w_lcs_chars.nbsp; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2146 | if (area_attr == 0 && search_attr == 0) |
| 2147 | { |
| 2148 | n_attr = 1; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2149 | extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2150 | saved_attr2 = char_attr; // save current attr |
| 2151 | } |
| 2152 | mb_c = c; |
| 2153 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2154 | { |
| 2155 | mb_utf8 = TRUE; |
| 2156 | u8cc[0] = 0; |
| 2157 | c = 0xc0; |
| 2158 | } |
| 2159 | else |
| 2160 | mb_utf8 = FALSE; |
| 2161 | } |
| 2162 | |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 2163 | if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol) |
| 2164 | || (leadcol != 0 && ptr < line + leadcol))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2165 | { |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 2166 | if (leadcol != 0 && in_multispace && ptr < line + leadcol |
| 2167 | && wp->w_lcs_chars.leadmultispace != NULL) |
| 2168 | { |
| 2169 | c = wp->w_lcs_chars.leadmultispace[multispace_pos++]; |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 2170 | if (wp->w_lcs_chars.leadmultispace[multispace_pos] |
| 2171 | == NUL) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 2172 | multispace_pos = 0; |
| 2173 | } |
| 2174 | |
| 2175 | else if (ptr > line + trailcol && wp->w_lcs_chars.trail) |
| 2176 | c = wp->w_lcs_chars.trail; |
| 2177 | |
| 2178 | else if (ptr < line + leadcol && wp->w_lcs_chars.lead) |
| 2179 | c = wp->w_lcs_chars.lead; |
| 2180 | |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 2181 | else if (leadcol != 0 && wp->w_lcs_chars.space) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 2182 | c = wp->w_lcs_chars.space; |
| 2183 | |
| 2184 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2185 | if (!attr_pri) |
| 2186 | { |
| 2187 | n_attr = 1; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2188 | extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2189 | saved_attr2 = char_attr; // save current attr |
| 2190 | } |
| 2191 | mb_c = c; |
| 2192 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2193 | { |
| 2194 | mb_utf8 = TRUE; |
| 2195 | u8cc[0] = 0; |
| 2196 | c = 0xc0; |
| 2197 | } |
| 2198 | else |
| 2199 | mb_utf8 = FALSE; |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | // Handling of non-printable characters. |
| 2204 | if (!vim_isprintc(c)) |
| 2205 | { |
| 2206 | // when getting a character from the file, we may have to |
| 2207 | // turn it into something else on the way to putting it |
| 2208 | // into "ScreenLines". |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2209 | if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2210 | { |
| 2211 | int tab_len = 0; |
| 2212 | long vcol_adjusted = vcol; // removed showbreak length |
| 2213 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 2214 | char_u *sbr = get_showbreak_value(wp); |
| 2215 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2216 | // only adjust the tab_len, when at the first column |
| 2217 | // after the showbreak value was drawn |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 2218 | if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) |
| 2219 | vcol_adjusted = vcol - MB_CHARLEN(sbr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2220 | #endif |
| 2221 | // tab amount depends on current column |
| 2222 | #ifdef FEAT_VARTABS |
| 2223 | tab_len = tabstop_padding(vcol_adjusted, |
| 2224 | wp->w_buffer->b_p_ts, |
| 2225 | wp->w_buffer->b_p_vts_array) - 1; |
| 2226 | #else |
| 2227 | tab_len = (int)wp->w_buffer->b_p_ts |
| 2228 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 2229 | #endif |
| 2230 | |
| 2231 | #ifdef FEAT_LINEBREAK |
| 2232 | if (!wp->w_p_lbr || !wp->w_p_list) |
| 2233 | #endif |
| 2234 | // tab amount depends on current column |
| 2235 | n_extra = tab_len; |
| 2236 | #ifdef FEAT_LINEBREAK |
| 2237 | else |
| 2238 | { |
| 2239 | char_u *p; |
| 2240 | int len; |
| 2241 | int i; |
| 2242 | int saved_nextra = n_extra; |
| 2243 | |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2244 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2245 | if (vcol_off > 0) |
| 2246 | // there are characters to conceal |
| 2247 | tab_len += vcol_off; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2248 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2249 | // boguscols before FIX_FOR_BOGUSCOLS macro from above |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2250 | if (wp->w_p_list && wp->w_lcs_chars.tab1 |
| 2251 | && old_boguscols > 0 |
| 2252 | && n_extra > tab_len) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2253 | tab_len += n_extra - tab_len; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2254 | # endif |
| 2255 | // If n_extra > 0, it gives the number of chars, to |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2256 | // use for a tab, else we need to calculate the width |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2257 | // for a tab. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2258 | len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2)); |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2259 | if (wp->w_lcs_chars.tab3) |
| 2260 | len += mb_char2len(wp->w_lcs_chars.tab3); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2261 | if (n_extra > 0) |
| 2262 | len += n_extra - tab_len; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2263 | c = wp->w_lcs_chars.tab1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2264 | p = alloc(len + 1); |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2265 | if (p == NULL) |
| 2266 | n_extra = 0; |
| 2267 | else |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2268 | { |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2269 | vim_memset(p, ' ', len); |
| 2270 | p[len] = NUL; |
| 2271 | vim_free(p_extra_free); |
| 2272 | p_extra_free = p; |
| 2273 | for (i = 0; i < tab_len; i++) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2274 | { |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2275 | int lcs = wp->w_lcs_chars.tab2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2276 | |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2277 | if (*p == NUL) |
| 2278 | { |
| 2279 | tab_len = i; |
| 2280 | break; |
| 2281 | } |
| 2282 | |
| 2283 | // if tab3 is given, use it for the last char |
| 2284 | if (wp->w_lcs_chars.tab3 && i == tab_len - 1) |
| 2285 | lcs = wp->w_lcs_chars.tab3; |
| 2286 | p += mb_char2bytes(lcs, p); |
| 2287 | n_extra += mb_char2len(lcs) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2288 | - (saved_nextra > 0 ? 1 : 0); |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 2289 | } |
| 2290 | p_extra = p_extra_free; |
| 2291 | # ifdef FEAT_CONCEAL |
| 2292 | // n_extra will be increased by FIX_FOX_BOGUSCOLS |
| 2293 | // macro below, so need to adjust for that here |
| 2294 | if (vcol_off > 0) |
| 2295 | n_extra -= vcol_off; |
| 2296 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2297 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2298 | } |
| 2299 | #endif |
| 2300 | #ifdef FEAT_CONCEAL |
| 2301 | { |
| 2302 | int vc_saved = vcol_off; |
| 2303 | |
| 2304 | // Tab alignment should be identical regardless of |
| 2305 | // 'conceallevel' value. So tab compensates of all |
| 2306 | // previous concealed characters, and thus resets |
| 2307 | // vcol_off and boguscols accumulated so far in the |
| 2308 | // line. Note that the tab can be longer than |
| 2309 | // 'tabstop' when there are concealed characters. |
| 2310 | FIX_FOR_BOGUSCOLS; |
| 2311 | |
| 2312 | // Make sure, the highlighting for the tab char will be |
| 2313 | // correctly set further below (effectively reverts the |
Dominique Pelle | af4a61a | 2021-12-27 17:21:41 +0000 | [diff] [blame] | 2314 | // FIX_FOR_BOGSUCOLS macro). |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2315 | if (n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2316 | && wp->w_lcs_chars.tab1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2317 | tab_len += vc_saved; |
| 2318 | } |
| 2319 | #endif |
| 2320 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 2321 | if (wp->w_p_list) |
| 2322 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2323 | c = (n_extra == 0 && wp->w_lcs_chars.tab3) |
| 2324 | ? wp->w_lcs_chars.tab3 |
| 2325 | : wp->w_lcs_chars.tab1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2326 | #ifdef FEAT_LINEBREAK |
| 2327 | if (wp->w_p_lbr) |
| 2328 | c_extra = NUL; // using p_extra from above |
| 2329 | else |
| 2330 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2331 | c_extra = wp->w_lcs_chars.tab2; |
| 2332 | c_final = wp->w_lcs_chars.tab3; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2333 | n_attr = tab_len + 1; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2334 | extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2335 | saved_attr2 = char_attr; // save current attr |
| 2336 | mb_c = c; |
| 2337 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2338 | { |
| 2339 | mb_utf8 = TRUE; |
| 2340 | u8cc[0] = 0; |
| 2341 | c = 0xc0; |
| 2342 | } |
| 2343 | } |
| 2344 | else |
| 2345 | { |
| 2346 | c_final = NUL; |
| 2347 | c_extra = ' '; |
| 2348 | c = ' '; |
| 2349 | } |
| 2350 | } |
| 2351 | else if (c == NUL |
| 2352 | && (wp->w_p_list |
| 2353 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 2354 | && tocol > vcol |
| 2355 | && VIsual_mode != Ctrl_V |
| 2356 | && ( |
| 2357 | # ifdef FEAT_RIGHTLEFT |
| 2358 | wp->w_p_rl ? (col >= 0) : |
| 2359 | # endif |
| 2360 | (col < wp->w_width)) |
| 2361 | && !(noinvcur |
| 2362 | && lnum == wp->w_cursor.lnum |
| 2363 | && (colnr_T)vcol == wp->w_virtcol))) |
| 2364 | && lcs_eol_one > 0) |
| 2365 | { |
| 2366 | // Display a '$' after the line or highlight an extra |
| 2367 | // character if the line break is included. |
| 2368 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 2369 | // For a diff line the highlighting continues after the |
| 2370 | // "$". |
| 2371 | if ( |
| 2372 | # ifdef FEAT_DIFF |
| 2373 | diff_hlf == (hlf_T)0 |
| 2374 | # ifdef LINE_ATTR |
| 2375 | && |
| 2376 | # endif |
| 2377 | # endif |
| 2378 | # ifdef LINE_ATTR |
| 2379 | line_attr == 0 |
| 2380 | # endif |
| 2381 | ) |
| 2382 | #endif |
| 2383 | { |
| 2384 | // In virtualedit, visual selections may extend |
| 2385 | // beyond end of line. |
| 2386 | if (area_highlighting && virtual_active() |
| 2387 | && tocol != MAXCOL && vcol < tocol) |
| 2388 | n_extra = 0; |
| 2389 | else |
| 2390 | { |
| 2391 | p_extra = at_end_str; |
| 2392 | n_extra = 1; |
| 2393 | c_extra = NUL; |
| 2394 | c_final = NUL; |
| 2395 | } |
| 2396 | } |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2397 | if (wp->w_p_list && wp->w_lcs_chars.eol > 0) |
| 2398 | c = wp->w_lcs_chars.eol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2399 | else |
| 2400 | c = ' '; |
| 2401 | lcs_eol_one = -1; |
| 2402 | --ptr; // put it back at the NUL |
| 2403 | if (!attr_pri) |
| 2404 | { |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2405 | extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2406 | n_attr = 1; |
| 2407 | } |
| 2408 | mb_c = c; |
| 2409 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2410 | { |
| 2411 | mb_utf8 = TRUE; |
| 2412 | u8cc[0] = 0; |
| 2413 | c = 0xc0; |
| 2414 | } |
| 2415 | else |
| 2416 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 2417 | } |
| 2418 | else if (c != NUL) |
| 2419 | { |
Bram Moolenaar | 32ee627 | 2020-06-10 14:16:49 +0200 | [diff] [blame] | 2420 | p_extra = transchar_buf(wp->w_buffer, c); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2421 | if (n_extra == 0) |
| 2422 | n_extra = byte2cells(c) - 1; |
| 2423 | #ifdef FEAT_RIGHTLEFT |
| 2424 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 2425 | rl_mirror(p_extra); // reverse "<12>" |
| 2426 | #endif |
| 2427 | c_extra = NUL; |
| 2428 | c_final = NUL; |
| 2429 | #ifdef FEAT_LINEBREAK |
| 2430 | if (wp->w_p_lbr) |
| 2431 | { |
| 2432 | char_u *p; |
| 2433 | |
| 2434 | c = *p_extra; |
| 2435 | p = alloc(n_extra + 1); |
| 2436 | vim_memset(p, ' ', n_extra); |
| 2437 | STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); |
| 2438 | p[n_extra] = NUL; |
| 2439 | vim_free(p_extra_free); |
| 2440 | p_extra_free = p_extra = p; |
| 2441 | } |
| 2442 | else |
| 2443 | #endif |
| 2444 | { |
| 2445 | n_extra = byte2cells(c) - 1; |
| 2446 | c = *p_extra++; |
| 2447 | } |
| 2448 | if (!attr_pri) |
| 2449 | { |
| 2450 | n_attr = n_extra + 1; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2451 | extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2452 | saved_attr2 = char_attr; // save current attr |
| 2453 | } |
| 2454 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 2455 | } |
| 2456 | else if (VIsual_active |
| 2457 | && (VIsual_mode == Ctrl_V |
| 2458 | || VIsual_mode == 'v') |
| 2459 | && virtual_active() |
| 2460 | && tocol != MAXCOL |
| 2461 | && vcol < tocol |
| 2462 | && ( |
| 2463 | #ifdef FEAT_RIGHTLEFT |
| 2464 | wp->w_p_rl ? (col >= 0) : |
| 2465 | #endif |
| 2466 | (col < wp->w_width))) |
| 2467 | { |
| 2468 | c = ' '; |
| 2469 | --ptr; // put it back at the NUL |
| 2470 | } |
| 2471 | #if defined(LINE_ATTR) |
| 2472 | else if (( |
| 2473 | # ifdef FEAT_DIFF |
| 2474 | diff_hlf != (hlf_T)0 || |
| 2475 | # endif |
| 2476 | # ifdef FEAT_TERMINAL |
| 2477 | win_attr != 0 || |
| 2478 | # endif |
| 2479 | line_attr != 0 |
| 2480 | ) && ( |
| 2481 | # ifdef FEAT_RIGHTLEFT |
| 2482 | wp->w_p_rl ? (col >= 0) : |
| 2483 | # endif |
| 2484 | (col |
| 2485 | # ifdef FEAT_CONCEAL |
| 2486 | - boguscols |
| 2487 | # endif |
| 2488 | < wp->w_width))) |
| 2489 | { |
| 2490 | // Highlight until the right side of the window |
| 2491 | c = ' '; |
| 2492 | --ptr; // put it back at the NUL |
| 2493 | |
| 2494 | // Remember we do the char for line highlighting. |
| 2495 | ++did_line_attr; |
| 2496 | |
| 2497 | // don't do search HL for the rest of the line |
| 2498 | if (line_attr != 0 && char_attr == search_attr |
| 2499 | && (did_line_attr > 1 |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2500 | || (wp->w_p_list && |
| 2501 | wp->w_lcs_chars.eol > 0))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2502 | char_attr = line_attr; |
| 2503 | # ifdef FEAT_DIFF |
| 2504 | if (diff_hlf == HLF_TXD) |
| 2505 | { |
| 2506 | diff_hlf = HLF_CHD; |
| 2507 | if (vi_attr == 0 || char_attr != vi_attr) |
| 2508 | { |
| 2509 | char_attr = HL_ATTR(diff_hlf); |
| 2510 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 2511 | && wp->w_p_culopt_flags != CULOPT_NBR |
| 2512 | && (!cul_screenline |
| 2513 | || (vcol >= left_curline_col |
| 2514 | && vcol <= right_curline_col))) |
| 2515 | char_attr = hl_combine_attr( |
| 2516 | char_attr, HL_ATTR(HLF_CUL)); |
| 2517 | } |
| 2518 | } |
| 2519 | # endif |
| 2520 | # ifdef FEAT_TERMINAL |
| 2521 | if (win_attr != 0) |
| 2522 | { |
| 2523 | char_attr = win_attr; |
Bram Moolenaar | a381773 | 2019-10-16 16:31:44 +0200 | [diff] [blame] | 2524 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 2525 | && wp->w_p_culopt_flags != CULOPT_NBR) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2526 | { |
| 2527 | if (!cul_screenline || (vcol >= left_curline_col |
| 2528 | && vcol <= right_curline_col)) |
| 2529 | char_attr = hl_combine_attr( |
| 2530 | char_attr, HL_ATTR(HLF_CUL)); |
| 2531 | } |
| 2532 | else if (line_attr) |
| 2533 | char_attr = hl_combine_attr(char_attr, line_attr); |
| 2534 | } |
| 2535 | # endif |
| 2536 | } |
| 2537 | #endif |
| 2538 | } |
| 2539 | |
| 2540 | #ifdef FEAT_CONCEAL |
| 2541 | if ( wp->w_p_cole > 0 |
LemonBoy | 9830db6 | 2022-05-08 21:25:20 +0100 | [diff] [blame] | 2542 | && (wp != curwin || lnum != wp->w_cursor.lnum |
| 2543 | || conceal_cursor_line(wp)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2544 | && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0) |
| 2545 | && !(lnum_in_visual_area |
| 2546 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
| 2547 | { |
| 2548 | char_attr = conceal_attr; |
LemonBoy | 9830db6 | 2022-05-08 21:25:20 +0100 | [diff] [blame] | 2549 | if (((prev_syntax_id != syntax_seqnr |
| 2550 | && (syntax_flags & HL_CONCEAL) != 0) |
| 2551 | || has_match_conc > 1) |
Bram Moolenaar | 211dd3f | 2020-06-25 20:07:04 +0200 | [diff] [blame] | 2552 | && (syn_get_sub_char() != NUL |
| 2553 | || (has_match_conc && match_conc) |
| 2554 | || wp->w_p_cole == 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2555 | && wp->w_p_cole != 3) |
| 2556 | { |
| 2557 | // First time at this concealed item: display one |
| 2558 | // character. |
Bram Moolenaar | 211dd3f | 2020-06-25 20:07:04 +0200 | [diff] [blame] | 2559 | if (has_match_conc && match_conc) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2560 | c = match_conc; |
| 2561 | else if (syn_get_sub_char() != NUL) |
| 2562 | c = syn_get_sub_char(); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2563 | else if (wp->w_lcs_chars.conceal != NUL) |
| 2564 | c = wp->w_lcs_chars.conceal; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2565 | else |
| 2566 | c = ' '; |
| 2567 | |
| 2568 | prev_syntax_id = syntax_seqnr; |
| 2569 | |
| 2570 | if (n_extra > 0) |
| 2571 | vcol_off += n_extra; |
| 2572 | vcol += n_extra; |
| 2573 | if (wp->w_p_wrap && n_extra > 0) |
| 2574 | { |
| 2575 | # ifdef FEAT_RIGHTLEFT |
| 2576 | if (wp->w_p_rl) |
| 2577 | { |
| 2578 | col -= n_extra; |
| 2579 | boguscols -= n_extra; |
| 2580 | } |
| 2581 | else |
| 2582 | # endif |
| 2583 | { |
| 2584 | boguscols += n_extra; |
| 2585 | col += n_extra; |
| 2586 | } |
| 2587 | } |
| 2588 | n_extra = 0; |
| 2589 | n_attr = 0; |
| 2590 | } |
| 2591 | else if (n_skip == 0) |
| 2592 | { |
| 2593 | is_concealing = TRUE; |
| 2594 | n_skip = 1; |
| 2595 | } |
| 2596 | mb_c = c; |
| 2597 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2598 | { |
| 2599 | mb_utf8 = TRUE; |
| 2600 | u8cc[0] = 0; |
| 2601 | c = 0xc0; |
| 2602 | } |
| 2603 | else |
| 2604 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 2605 | } |
| 2606 | else |
| 2607 | { |
| 2608 | prev_syntax_id = 0; |
| 2609 | is_concealing = FALSE; |
| 2610 | } |
| 2611 | |
| 2612 | if (n_skip > 0 && did_decrement_ptr) |
| 2613 | // not showing the '>', put pointer back to avoid getting stuck |
| 2614 | ++ptr; |
| 2615 | |
| 2616 | #endif // FEAT_CONCEAL |
| 2617 | } |
| 2618 | |
| 2619 | #ifdef FEAT_CONCEAL |
| 2620 | // In the cursor line and we may be concealing characters: correct |
| 2621 | // the cursor column when we reach its position. |
| 2622 | if (!did_wcol && draw_state == WL_LINE |
| 2623 | && wp == curwin && lnum == wp->w_cursor.lnum |
| 2624 | && conceal_cursor_line(wp) |
| 2625 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 2626 | { |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 2627 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2628 | if (wp->w_p_rl) |
| 2629 | wp->w_wcol = wp->w_width - col + boguscols - 1; |
| 2630 | else |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 2631 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2632 | wp->w_wcol = col - boguscols; |
| 2633 | wp->w_wrow = row; |
| 2634 | did_wcol = TRUE; |
| 2635 | curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 2636 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 6a07644 | 2020-11-15 20:32:58 +0100 | [diff] [blame] | 2637 | curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED); |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 2638 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2639 | } |
| 2640 | #endif |
| 2641 | |
| 2642 | // Don't override visual selection highlighting. |
| 2643 | if (n_attr > 0 |
| 2644 | && draw_state == WL_LINE |
| 2645 | && !attr_pri) |
| 2646 | { |
| 2647 | #ifdef LINE_ATTR |
| 2648 | if (line_attr) |
| 2649 | char_attr = hl_combine_attr(extra_attr, line_attr); |
| 2650 | else |
| 2651 | #endif |
| 2652 | char_attr = extra_attr; |
| 2653 | } |
| 2654 | |
| 2655 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
| 2656 | // XIM don't send preedit_start and preedit_end, but they send |
| 2657 | // preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 2658 | // im_is_preediting() here. |
| 2659 | if (p_imst == IM_ON_THE_SPOT |
| 2660 | && xic != NULL |
| 2661 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 2662 | && (State & MODE_INSERT) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2663 | && !p_imdisable |
| 2664 | && im_is_preediting() |
| 2665 | && draw_state == WL_LINE) |
| 2666 | { |
| 2667 | colnr_T tcol; |
| 2668 | |
| 2669 | if (preedit_end_col == MAXCOL) |
| 2670 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
| 2671 | else |
| 2672 | tcol = preedit_end_col; |
| 2673 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 2674 | { |
| 2675 | if (feedback_old_attr < 0) |
| 2676 | { |
| 2677 | feedback_col = 0; |
| 2678 | feedback_old_attr = char_attr; |
| 2679 | } |
| 2680 | char_attr = im_get_feedback_attr(feedback_col); |
| 2681 | if (char_attr < 0) |
| 2682 | char_attr = feedback_old_attr; |
| 2683 | feedback_col++; |
| 2684 | } |
| 2685 | else if (feedback_old_attr >= 0) |
| 2686 | { |
| 2687 | char_attr = feedback_old_attr; |
| 2688 | feedback_old_attr = -1; |
| 2689 | feedback_col = 0; |
| 2690 | } |
| 2691 | } |
| 2692 | #endif |
| 2693 | // Handle the case where we are in column 0 but not on the first |
| 2694 | // character of the line and the user wants us to show us a |
| 2695 | // special character (via 'listchars' option "precedes:<char>". |
| 2696 | if (lcs_prec_todo != NUL |
| 2697 | && wp->w_p_list |
Bram Moolenaar | bffba7f | 2019-09-20 17:00:17 +0200 | [diff] [blame] | 2698 | && (wp->w_p_wrap ? |
| 2699 | (wp->w_skipcol > 0 && row == 0) : |
| 2700 | wp->w_leftcol > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2701 | #ifdef FEAT_DIFF |
| 2702 | && filler_todo <= 0 |
| 2703 | #endif |
| 2704 | && draw_state > WL_NR |
| 2705 | && c != NUL) |
| 2706 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2707 | c = wp->w_lcs_chars.prec; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2708 | lcs_prec_todo = NUL; |
| 2709 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 2710 | { |
| 2711 | // Double-width character being overwritten by the "precedes" |
| 2712 | // character, need to fill up half the character. |
| 2713 | c_extra = MB_FILLER_CHAR; |
| 2714 | c_final = NUL; |
| 2715 | n_extra = 1; |
| 2716 | n_attr = 2; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2717 | extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2718 | } |
| 2719 | mb_c = c; |
| 2720 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2721 | { |
| 2722 | mb_utf8 = TRUE; |
| 2723 | u8cc[0] = 0; |
| 2724 | c = 0xc0; |
| 2725 | } |
| 2726 | else |
| 2727 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 2728 | if (!attr_pri) |
| 2729 | { |
| 2730 | saved_attr3 = char_attr; // save current attr |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2731 | char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2732 | n_attr3 = 1; |
| 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | // At end of the text line or just after the last character. |
| 2737 | if ((c == NUL |
| 2738 | #if defined(LINE_ATTR) |
| 2739 | || did_line_attr == 1 |
| 2740 | #endif |
| 2741 | ) && eol_hl_off == 0) |
| 2742 | { |
| 2743 | #ifdef FEAT_SEARCH_EXTRA |
| 2744 | // flag to indicate whether prevcol equals startcol of search_hl or |
| 2745 | // one of the matches |
| 2746 | int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl, |
| 2747 | (long)(ptr - line) - (c == NUL)); |
| 2748 | #endif |
| 2749 | // Invert at least one char, used for Visual and empty line or |
| 2750 | // highlight match at end of line. If it's beyond the last |
| 2751 | // char on the screen, just overwrite that one (tricky!) Not |
| 2752 | // needed when a '$' was displayed for 'list'. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2753 | if (wp->w_lcs_chars.eol == lcs_eol_one |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2754 | && ((area_attr != 0 && vcol == fromcol |
| 2755 | && (VIsual_mode != Ctrl_V |
| 2756 | || lnum == VIsual.lnum |
| 2757 | || lnum == curwin->w_cursor.lnum) |
| 2758 | && c == NUL) |
| 2759 | #ifdef FEAT_SEARCH_EXTRA |
| 2760 | // highlight 'hlsearch' match at end of line |
| 2761 | || (prevcol_hl_flag |
| 2762 | # ifdef FEAT_SYN_HL |
| 2763 | && !(wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 2764 | && !(wp == curwin && VIsual_active)) |
| 2765 | # endif |
| 2766 | # ifdef FEAT_DIFF |
| 2767 | && diff_hlf == (hlf_T)0 |
| 2768 | # endif |
| 2769 | # if defined(LINE_ATTR) |
| 2770 | && did_line_attr <= 1 |
| 2771 | # endif |
| 2772 | ) |
| 2773 | #endif |
| 2774 | )) |
| 2775 | { |
| 2776 | int n = 0; |
| 2777 | |
| 2778 | #ifdef FEAT_RIGHTLEFT |
| 2779 | if (wp->w_p_rl) |
| 2780 | { |
| 2781 | if (col < 0) |
| 2782 | n = 1; |
| 2783 | } |
| 2784 | else |
| 2785 | #endif |
| 2786 | { |
| 2787 | if (col >= wp->w_width) |
| 2788 | n = -1; |
| 2789 | } |
| 2790 | if (n != 0) |
| 2791 | { |
| 2792 | // At the window boundary, highlight the last character |
| 2793 | // instead (better than nothing). |
| 2794 | off += n; |
| 2795 | col += n; |
| 2796 | } |
| 2797 | else |
| 2798 | { |
| 2799 | // Add a blank character to highlight. |
| 2800 | ScreenLines[off] = ' '; |
| 2801 | if (enc_utf8) |
| 2802 | ScreenLinesUC[off] = 0; |
| 2803 | } |
| 2804 | #ifdef FEAT_SEARCH_EXTRA |
| 2805 | if (area_attr == 0) |
| 2806 | { |
| 2807 | // Use attributes from match with highest priority among |
| 2808 | // 'search_hl' and the match list. |
| 2809 | get_search_match_hl(wp, &screen_search_hl, |
| 2810 | (long)(ptr - line), &char_attr); |
| 2811 | } |
| 2812 | #endif |
| 2813 | ScreenAttrs[off] = char_attr; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 2814 | ScreenCols[off] = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2815 | #ifdef FEAT_RIGHTLEFT |
| 2816 | if (wp->w_p_rl) |
| 2817 | { |
| 2818 | --col; |
| 2819 | --off; |
| 2820 | } |
| 2821 | else |
| 2822 | #endif |
| 2823 | { |
| 2824 | ++col; |
| 2825 | ++off; |
| 2826 | } |
| 2827 | ++vcol; |
| 2828 | eol_hl_off = 1; |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | // At end of the text line. |
| 2833 | if (c == NUL) |
| 2834 | { |
| 2835 | #ifdef FEAT_SYN_HL |
| 2836 | // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. |
| 2837 | if (wp->w_p_wrap) |
| 2838 | v = wp->w_skipcol; |
| 2839 | else |
| 2840 | v = wp->w_leftcol; |
| 2841 | |
| 2842 | // check if line ends before left margin |
| 2843 | if (vcol < v + col - win_col_off(wp)) |
| 2844 | vcol = v + col - win_col_off(wp); |
| 2845 | #ifdef FEAT_CONCEAL |
| 2846 | // Get rid of the boguscols now, we want to draw until the right |
| 2847 | // edge for 'cursorcolumn'. |
| 2848 | col -= boguscols; |
| 2849 | boguscols = 0; |
| 2850 | #endif |
| 2851 | |
| 2852 | if (draw_color_col) |
| 2853 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
| 2854 | |
| 2855 | if (((wp->w_p_cuc |
| 2856 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 2857 | && (int)wp->w_virtcol < |
=?UTF-8?q?Dundar=20G=C3=B6c?= | d5cec1f | 2022-01-29 15:19:23 +0000 | [diff] [blame] | 2858 | (long)wp->w_width * (row - startrow + 1) + v |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2859 | && lnum != wp->w_cursor.lnum) |
| 2860 | || draw_color_col |
| 2861 | || win_attr != 0) |
| 2862 | # ifdef FEAT_RIGHTLEFT |
| 2863 | && !wp->w_p_rl |
| 2864 | # endif |
| 2865 | ) |
| 2866 | { |
| 2867 | int rightmost_vcol = 0; |
| 2868 | int i; |
| 2869 | |
| 2870 | if (wp->w_p_cuc) |
| 2871 | rightmost_vcol = wp->w_virtcol; |
| 2872 | if (draw_color_col) |
| 2873 | // determine rightmost colorcolumn to possibly draw |
| 2874 | for (i = 0; color_cols[i] >= 0; ++i) |
| 2875 | if (rightmost_vcol < color_cols[i]) |
| 2876 | rightmost_vcol = color_cols[i]; |
| 2877 | |
| 2878 | while (col < wp->w_width) |
| 2879 | { |
| 2880 | ScreenLines[off] = ' '; |
| 2881 | if (enc_utf8) |
| 2882 | ScreenLinesUC[off] = 0; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 2883 | ScreenCols[off] = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2884 | ++col; |
| 2885 | if (draw_color_col) |
| 2886 | draw_color_col = advance_color_col(VCOL_HLC, |
| 2887 | &color_cols); |
| 2888 | |
| 2889 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
| 2890 | ScreenAttrs[off++] = HL_ATTR(HLF_CUC); |
| 2891 | else if (draw_color_col && VCOL_HLC == *color_cols) |
| 2892 | ScreenAttrs[off++] = HL_ATTR(HLF_MC); |
| 2893 | else |
| 2894 | ScreenAttrs[off++] = win_attr; |
| 2895 | |
| 2896 | if (VCOL_HLC >= rightmost_vcol && win_attr == 0) |
| 2897 | break; |
| 2898 | |
| 2899 | ++vcol; |
| 2900 | } |
| 2901 | } |
| 2902 | #endif |
| 2903 | |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 2904 | screen_line(wp, screen_row, wp->w_wincol, col, |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 2905 | wp->w_width, screen_line_flags); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2906 | row++; |
| 2907 | |
| 2908 | // Update w_cline_height and w_cline_folded if the cursor line was |
| 2909 | // updated (saves a call to plines() later). |
| 2910 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 2911 | { |
| 2912 | curwin->w_cline_row = startrow; |
| 2913 | curwin->w_cline_height = row - startrow; |
| 2914 | #ifdef FEAT_FOLDING |
| 2915 | curwin->w_cline_folded = FALSE; |
| 2916 | #endif |
| 2917 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2918 | } |
| 2919 | |
| 2920 | break; |
| 2921 | } |
| 2922 | |
| 2923 | // Show "extends" character from 'listchars' if beyond the line end and |
| 2924 | // 'list' is set. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2925 | if (wp->w_lcs_chars.ext != NUL |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 2926 | && draw_state == WL_LINE |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2927 | && wp->w_p_list |
| 2928 | && !wp->w_p_wrap |
| 2929 | #ifdef FEAT_DIFF |
| 2930 | && filler_todo <= 0 |
| 2931 | #endif |
| 2932 | && ( |
| 2933 | #ifdef FEAT_RIGHTLEFT |
| 2934 | wp->w_p_rl ? col == 0 : |
| 2935 | #endif |
| 2936 | col == wp->w_width - 1) |
| 2937 | && (*ptr != NUL |
| 2938 | || (wp->w_p_list && lcs_eol_one > 0) |
| 2939 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 2940 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 2941 | c = wp->w_lcs_chars.ext; |
Bram Moolenaar | 42e931b | 2019-12-04 19:08:50 +0100 | [diff] [blame] | 2942 | char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2943 | mb_c = c; |
| 2944 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2945 | { |
| 2946 | mb_utf8 = TRUE; |
| 2947 | u8cc[0] = 0; |
| 2948 | c = 0xc0; |
| 2949 | } |
| 2950 | else |
| 2951 | mb_utf8 = FALSE; |
| 2952 | } |
| 2953 | |
| 2954 | #ifdef FEAT_SYN_HL |
| 2955 | // advance to the next 'colorcolumn' |
| 2956 | if (draw_color_col) |
| 2957 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
| 2958 | |
| 2959 | // Highlight the cursor column if 'cursorcolumn' is set. But don't |
| 2960 | // highlight the cursor position itself. |
| 2961 | // Also highlight the 'colorcolumn' if it is different than |
| 2962 | // 'cursorcolumn' |
Bram Moolenaar | ad5e563 | 2020-09-15 20:52:26 +0200 | [diff] [blame] | 2963 | // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak' |
| 2964 | // options are set |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2965 | vcol_save_attr = -1; |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 2966 | if (((draw_state == WL_LINE || |
Bram Moolenaar | ad5e563 | 2020-09-15 20:52:26 +0200 | [diff] [blame] | 2967 | draw_state == WL_BRI || |
| 2968 | draw_state == WL_SBR) && !lnum_in_visual_area |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2969 | && search_attr == 0 && area_attr == 0) |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 2970 | # ifdef FEAT_DIFF |
| 2971 | && filler_todo <= 0 |
| 2972 | # endif |
| 2973 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2974 | { |
| 2975 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
| 2976 | && lnum != wp->w_cursor.lnum) |
| 2977 | { |
| 2978 | vcol_save_attr = char_attr; |
| 2979 | char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC)); |
| 2980 | } |
| 2981 | else if (draw_color_col && VCOL_HLC == *color_cols) |
| 2982 | { |
| 2983 | vcol_save_attr = char_attr; |
| 2984 | char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC)); |
| 2985 | } |
| 2986 | } |
| 2987 | #endif |
| 2988 | |
| 2989 | // Store character to be displayed. |
| 2990 | // Skip characters that are left of the screen for 'nowrap'. |
| 2991 | vcol_prev = vcol; |
| 2992 | if (draw_state < WL_LINE || n_skip <= 0) |
| 2993 | { |
| 2994 | // Store the character. |
| 2995 | #if defined(FEAT_RIGHTLEFT) |
| 2996 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 2997 | { |
Dominique Pelle | af4a61a | 2021-12-27 17:21:41 +0000 | [diff] [blame] | 2998 | // A double-wide character is: put first half in left cell. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2999 | --off; |
| 3000 | --col; |
| 3001 | } |
| 3002 | #endif |
| 3003 | ScreenLines[off] = c; |
| 3004 | if (enc_dbcs == DBCS_JPNU) |
| 3005 | { |
| 3006 | if ((mb_c & 0xff00) == 0x8e00) |
| 3007 | ScreenLines[off] = 0x8e; |
| 3008 | ScreenLines2[off] = mb_c & 0xff; |
| 3009 | } |
| 3010 | else if (enc_utf8) |
| 3011 | { |
| 3012 | if (mb_utf8) |
| 3013 | { |
| 3014 | int i; |
| 3015 | |
| 3016 | ScreenLinesUC[off] = mb_c; |
| 3017 | if ((c & 0xff) == 0) |
| 3018 | ScreenLines[off] = 0x80; // avoid storing zero |
| 3019 | for (i = 0; i < Screen_mco; ++i) |
| 3020 | { |
| 3021 | ScreenLinesC[i][off] = u8cc[i]; |
| 3022 | if (u8cc[i] == 0) |
| 3023 | break; |
| 3024 | } |
| 3025 | } |
| 3026 | else |
| 3027 | ScreenLinesUC[off] = 0; |
| 3028 | } |
| 3029 | if (multi_attr) |
| 3030 | { |
| 3031 | ScreenAttrs[off] = multi_attr; |
| 3032 | multi_attr = 0; |
| 3033 | } |
| 3034 | else |
| 3035 | ScreenAttrs[off] = char_attr; |
| 3036 | |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 3037 | ScreenCols[off] = (colnr_T)(prev_ptr - line); |
| 3038 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3039 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 3040 | { |
| 3041 | // Need to fill two screen columns. |
| 3042 | ++off; |
| 3043 | ++col; |
| 3044 | if (enc_utf8) |
| 3045 | // UTF-8: Put a 0 in the second screen char. |
| 3046 | ScreenLines[off] = 0; |
| 3047 | else |
| 3048 | // DBCS: Put second byte in the second screen char. |
| 3049 | ScreenLines[off] = mb_c & 0xff; |
| 3050 | if (draw_state > WL_NR |
| 3051 | #ifdef FEAT_DIFF |
| 3052 | && filler_todo <= 0 |
| 3053 | #endif |
| 3054 | ) |
| 3055 | ++vcol; |
| 3056 | // When "tocol" is halfway a character, set it to the end of |
| 3057 | // the character, otherwise highlighting won't stop. |
| 3058 | if (tocol == vcol) |
| 3059 | ++tocol; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 3060 | |
| 3061 | ScreenCols[off] = (colnr_T)(prev_ptr - line); |
| 3062 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3063 | #ifdef FEAT_RIGHTLEFT |
| 3064 | if (wp->w_p_rl) |
| 3065 | { |
| 3066 | // now it's time to backup one cell |
| 3067 | --off; |
| 3068 | --col; |
| 3069 | } |
| 3070 | #endif |
| 3071 | } |
| 3072 | #ifdef FEAT_RIGHTLEFT |
| 3073 | if (wp->w_p_rl) |
| 3074 | { |
| 3075 | --off; |
| 3076 | --col; |
| 3077 | } |
| 3078 | else |
| 3079 | #endif |
| 3080 | { |
| 3081 | ++off; |
| 3082 | ++col; |
| 3083 | } |
| 3084 | } |
| 3085 | #ifdef FEAT_CONCEAL |
| 3086 | else if (wp->w_p_cole > 0 && is_concealing) |
| 3087 | { |
| 3088 | --n_skip; |
| 3089 | ++vcol_off; |
| 3090 | if (n_extra > 0) |
| 3091 | vcol_off += n_extra; |
| 3092 | if (wp->w_p_wrap) |
| 3093 | { |
| 3094 | // Special voodoo required if 'wrap' is on. |
| 3095 | // |
| 3096 | // Advance the column indicator to force the line |
| 3097 | // drawing to wrap early. This will make the line |
| 3098 | // take up the same screen space when parts are concealed, |
| 3099 | // so that cursor line computations aren't messed up. |
| 3100 | // |
| 3101 | // To avoid the fictitious advance of 'col' causing |
| 3102 | // trailing junk to be written out of the screen line |
| 3103 | // we are building, 'boguscols' keeps track of the number |
| 3104 | // of bad columns we have advanced. |
| 3105 | if (n_extra > 0) |
| 3106 | { |
| 3107 | vcol += n_extra; |
| 3108 | # ifdef FEAT_RIGHTLEFT |
| 3109 | if (wp->w_p_rl) |
| 3110 | { |
| 3111 | col -= n_extra; |
| 3112 | boguscols -= n_extra; |
| 3113 | } |
| 3114 | else |
| 3115 | # endif |
| 3116 | { |
| 3117 | col += n_extra; |
| 3118 | boguscols += n_extra; |
| 3119 | } |
| 3120 | n_extra = 0; |
| 3121 | n_attr = 0; |
| 3122 | } |
| 3123 | |
| 3124 | |
| 3125 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 3126 | { |
| 3127 | // Need to fill two screen columns. |
| 3128 | # ifdef FEAT_RIGHTLEFT |
| 3129 | if (wp->w_p_rl) |
| 3130 | { |
| 3131 | --boguscols; |
| 3132 | --col; |
| 3133 | } |
| 3134 | else |
| 3135 | # endif |
| 3136 | { |
| 3137 | ++boguscols; |
| 3138 | ++col; |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | # ifdef FEAT_RIGHTLEFT |
| 3143 | if (wp->w_p_rl) |
| 3144 | { |
| 3145 | --boguscols; |
| 3146 | --col; |
| 3147 | } |
| 3148 | else |
| 3149 | # endif |
| 3150 | { |
| 3151 | ++boguscols; |
| 3152 | ++col; |
| 3153 | } |
| 3154 | } |
| 3155 | else |
| 3156 | { |
| 3157 | if (n_extra > 0) |
| 3158 | { |
| 3159 | vcol += n_extra; |
| 3160 | n_extra = 0; |
| 3161 | n_attr = 0; |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | } |
| 3166 | #endif // FEAT_CONCEAL |
| 3167 | else |
| 3168 | --n_skip; |
| 3169 | |
| 3170 | // Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 3171 | // column. |
| 3172 | if (draw_state > WL_NR |
| 3173 | #ifdef FEAT_DIFF |
| 3174 | && filler_todo <= 0 |
| 3175 | #endif |
| 3176 | ) |
| 3177 | ++vcol; |
| 3178 | |
| 3179 | #ifdef FEAT_SYN_HL |
| 3180 | if (vcol_save_attr >= 0) |
| 3181 | char_attr = vcol_save_attr; |
| 3182 | #endif |
| 3183 | |
| 3184 | // restore attributes after "predeces" in 'listchars' |
| 3185 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 3186 | char_attr = saved_attr3; |
| 3187 | |
| 3188 | // restore attributes after last 'listchars' or 'number' char |
| 3189 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 3190 | char_attr = saved_attr2; |
| 3191 | |
| 3192 | // At end of screen line and there is more to come: Display the line |
| 3193 | // so far. If there is no more to display it is caught above. |
| 3194 | if (( |
| 3195 | #ifdef FEAT_RIGHTLEFT |
| 3196 | wp->w_p_rl ? (col < 0) : |
| 3197 | #endif |
| 3198 | (col >= wp->w_width)) |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 3199 | && (draw_state != WL_LINE |
| 3200 | || *ptr != NUL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3201 | #ifdef FEAT_DIFF |
| 3202 | || filler_todo > 0 |
| 3203 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3204 | || (wp->w_p_list && wp->w_lcs_chars.eol != NUL |
| 3205 | && p_extra != at_end_str) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3206 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 3207 | ) |
| 3208 | { |
| 3209 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 3210 | screen_line(wp, screen_row, wp->w_wincol, col - boguscols, |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 3211 | wp->w_width, screen_line_flags); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3212 | boguscols = 0; |
| 3213 | #else |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 3214 | screen_line(wp, screen_row, wp->w_wincol, col, |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 3215 | wp->w_width, screen_line_flags); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3216 | #endif |
| 3217 | ++row; |
| 3218 | ++screen_row; |
| 3219 | |
| 3220 | // When not wrapping and finished diff lines, or when displayed |
| 3221 | // '$' and highlighting until last column, break here. |
| 3222 | if ((!wp->w_p_wrap |
| 3223 | #ifdef FEAT_DIFF |
| 3224 | && filler_todo <= 0 |
| 3225 | #endif |
| 3226 | ) || lcs_eol_one == -1) |
| 3227 | break; |
| 3228 | |
| 3229 | // When the window is too narrow draw all "@" lines. |
| 3230 | if (draw_state != WL_LINE |
| 3231 | #ifdef FEAT_DIFF |
| 3232 | && filler_todo <= 0 |
| 3233 | #endif |
| 3234 | ) |
| 3235 | { |
| 3236 | win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT); |
| 3237 | draw_vsep_win(wp, row); |
| 3238 | row = endrow; |
| 3239 | } |
| 3240 | |
| 3241 | // When line got too long for screen break here. |
| 3242 | if (row == endrow) |
| 3243 | { |
| 3244 | ++row; |
| 3245 | break; |
| 3246 | } |
| 3247 | |
| 3248 | if (screen_cur_row == screen_row - 1 |
| 3249 | #ifdef FEAT_DIFF |
| 3250 | && filler_todo <= 0 |
| 3251 | #endif |
| 3252 | && wp->w_width == Columns) |
| 3253 | { |
| 3254 | // Remember that the line wraps, used for modeless copy. |
| 3255 | LineWraps[screen_row - 1] = TRUE; |
| 3256 | |
| 3257 | // Special trick to make copy/paste of wrapped lines work with |
| 3258 | // xterm/screen: write an extra character beyond the end of |
| 3259 | // the line. This will work with all terminal types |
| 3260 | // (regardless of the xn,am settings). |
| 3261 | // Only do this on a fast tty. |
| 3262 | // Only do this if the cursor is on the current line |
| 3263 | // (something has been written in it). |
| 3264 | // Don't do this for the GUI. |
| 3265 | // Don't do this for double-width characters. |
| 3266 | // Don't do this for a window not at the right screen border. |
| 3267 | if (p_tf |
| 3268 | #ifdef FEAT_GUI |
| 3269 | && !gui.in_use |
| 3270 | #endif |
| 3271 | && !(has_mbyte |
| 3272 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 3273 | LineOffset[screen_row] + screen_Columns) |
| 3274 | == 2 |
| 3275 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
| 3276 | + (int)Columns - 2, |
| 3277 | LineOffset[screen_row] + screen_Columns) |
| 3278 | == 2))) |
| 3279 | { |
| 3280 | // First make sure we are at the end of the screen line, |
| 3281 | // then output the same character again to let the |
| 3282 | // terminal know about the wrap. If the terminal doesn't |
| 3283 | // auto-wrap, we overwrite the character. |
| 3284 | if (screen_cur_col != wp->w_width) |
| 3285 | screen_char(LineOffset[screen_row - 1] |
| 3286 | + (unsigned)Columns - 1, |
| 3287 | screen_row - 1, (int)(Columns - 1)); |
| 3288 | |
| 3289 | // When there is a multi-byte character, just output a |
| 3290 | // space to keep it simple. |
| 3291 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 3292 | screen_row - 1] + (Columns - 1)]) > 1) |
| 3293 | out_char(' '); |
| 3294 | else |
| 3295 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 3296 | + (Columns - 1)]); |
| 3297 | // force a redraw of the first char on the next line |
| 3298 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 3299 | screen_start(); // don't know where cursor is now |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | col = 0; |
| 3304 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 3305 | #ifdef FEAT_RIGHTLEFT |
| 3306 | if (wp->w_p_rl) |
| 3307 | { |
| 3308 | col = wp->w_width - 1; // col is not used if breaking! |
| 3309 | off += col; |
| 3310 | } |
| 3311 | #endif |
| 3312 | |
| 3313 | // reset the drawing state for the start of a wrapped line |
| 3314 | draw_state = WL_START; |
| 3315 | saved_n_extra = n_extra; |
| 3316 | saved_p_extra = p_extra; |
| 3317 | saved_c_extra = c_extra; |
| 3318 | saved_c_final = c_final; |
| 3319 | #ifdef FEAT_SYN_HL |
| 3320 | if (!(cul_screenline |
| 3321 | # ifdef FEAT_DIFF |
Bram Moolenaar | e770598 | 2020-04-21 22:23:15 +0200 | [diff] [blame] | 3322 | && diff_hlf == (hlf_T)0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3323 | # endif |
Bram Moolenaar | e770598 | 2020-04-21 22:23:15 +0200 | [diff] [blame] | 3324 | )) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3325 | saved_char_attr = char_attr; |
| 3326 | else |
| 3327 | #endif |
| 3328 | saved_char_attr = 0; |
| 3329 | n_extra = 0; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3330 | lcs_prec_todo = wp->w_lcs_chars.prec; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3331 | #ifdef FEAT_LINEBREAK |
| 3332 | # ifdef FEAT_DIFF |
| 3333 | if (filler_todo <= 0) |
| 3334 | # endif |
| 3335 | need_showbreak = TRUE; |
| 3336 | #endif |
| 3337 | #ifdef FEAT_DIFF |
| 3338 | --filler_todo; |
| 3339 | // When the filler lines are actually below the last line of the |
| 3340 | // file, don't draw the line itself, break here. |
| 3341 | if (filler_todo == 0 && wp->w_botfill) |
| 3342 | break; |
| 3343 | #endif |
| 3344 | } |
| 3345 | |
| 3346 | } // for every character in the line |
| 3347 | |
| 3348 | #ifdef FEAT_SPELL |
| 3349 | // After an empty line check first word for capital. |
| 3350 | if (*skipwhite(line) == NUL) |
| 3351 | { |
| 3352 | capcol_lnum = lnum + 1; |
| 3353 | cap_col = 0; |
| 3354 | } |
| 3355 | #endif |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 3356 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3357 | vim_free(text_props); |
| 3358 | vim_free(text_prop_idxs); |
| 3359 | #endif |
| 3360 | |
| 3361 | vim_free(p_extra_free); |
| 3362 | return row; |
| 3363 | } |