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