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