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