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