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