blob: aa7519073c9f5be293d84f1bc1aba6d05a2534b1 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * 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
23advance_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
37margin_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 Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef 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 Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_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 Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * 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
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
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 Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
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 Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100280#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100281/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100282 * Return the cell size of virtual text after truncation.
283 */
284 static int
285textprop_size_after_trunc(
286 win_T *wp,
287 int flags, // TP_FLAG_ALIGN_*
288 int added,
289 char_u *text,
290 int *n_used_ptr)
291{
292 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
293 ? wp->w_width : added;
294 int len = (int)STRLEN(text);
295 int strsize = 0;
296 int n_used;
297
298 // if the remaining size is to small wrap anyway and use the next line
299 if (space < PROP_TEXT_MIN_CELLS)
300 space += wp->w_width;
301 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
302 {
303 int clen = ptr2cells(text + n_used);
304
305 if (strsize + clen > space)
306 break;
307 strsize += clen;
308 }
309 *n_used_ptr = n_used;
310 return strsize;
311}
312
313/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100314 * Take care of padding, right-align and truncation of virtual text after a
315 * line.
316 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
317 * padding, right-align and truncation. Otherwise only the size is computed.
318 * When "n_attr" is NULL returns the number of screen cells used.
319 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100320 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100321 int
322text_prop_position(
323 win_T *wp,
324 textprop_T *tp,
325 int vcol, // current screen column
326 int *n_extra, // nr of bytes for virtual text
327 char_u **p_extra, // virtual text
328 int *n_attr, // attribute cells, NULL if not used
329 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100331 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100332 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100333 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
334 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
335 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
336 ? tp->tp_len - 1 : 0;
337 int col_with_padding = vcol + (below ? 0 : padding);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100338 int col_off = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100339 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100340 int before = room; // spaces before the text
341 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100342 int n_used = *n_extra;
343 char_u *l = NULL;
344 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100345 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
346 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100348 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100349 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100350 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100351 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100352 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100353 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100354 }
355 else
356 {
357 // Right-align: fill with before
358 if (right)
359 before -= cells;
360 if (before < 0
361 || !(right || below)
362 || (below
363 ? (col_with_padding == 0 || !wp->w_p_wrap)
364 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100365 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100366 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
367 {
368 // right-align on next line instead of wrapping if possible
369 col_off = win_col_off(wp) + win_col_off2(wp);
370 before = wp->w_width - col_off - strsize + room;
371 if (before < 0)
372 before = 0;
373 else
374 n_used = *n_extra;
375 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100376 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100377 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100378 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100379 else if (below && before > 0)
380 // include 'number' column et al.
381 col_off = win_col_off(wp) + win_col_off2(wp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100382 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100383
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100384 // With 'nowrap' add one to show the "extends" character if needed (it
385 // doesn't show if the text just fits).
386 if (!wp->w_p_wrap
387 && n_used < *n_extra
388 && wp->w_lcs_chars.ext != NUL
389 && wp->w_p_list)
390 ++n_used;
391
392 // add 1 for NUL, 2 for when '…' is used
393 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100394 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100395 if (n_attr == NULL || l != NULL)
396 {
397 int off = 0;
398
399 if (n_attr != NULL)
400 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100401 vim_memset(l, ' ', before);
402 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100403 if (padding > 0)
404 {
405 vim_memset(l + off, ' ', padding);
406 off += padding;
407 }
408 vim_strncpy(l + off, *p_extra, n_used);
409 off += n_used;
410 }
411 else
412 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100413 off = before + after + padding + n_used;
414 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100415 }
416 if (n_attr != NULL)
417 {
418 if (n_used < *n_extra && wp->w_p_wrap)
419 {
420 char_u *lp = l + off - 1;
421
422 if (has_mbyte)
423 {
424 // change last character to '…'
425 lp -= (*mb_head_off)(l, lp);
426 STRCPY(lp, "…");
427 n_used = lp - l + 3 - padding;
428 }
429 else
430 // change last character to '>'
431 *lp = '>';
432 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100433 else if (after > 0)
434 {
435 vim_memset(l + off, ' ', after);
436 l[off + after] = NUL;
437 }
438
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100439 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100440 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100441 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100442 if (above)
443 *n_attr -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100444 *n_attr_skip = before + padding + col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100445 }
446 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100447 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100448
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100449 if (n_attr == NULL)
450 return cells;
451 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200452}
453#endif
454
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100455/*
456 * Called when finished with the line: draw the screen line and handle any
457 * highlighting until the right of the window.
458 */
459 static void
460draw_screen_line(win_T *wp, winlinevars_T *wlv)
461{
462#ifdef FEAT_SYN_HL
463 long v;
464
465 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
466 if (wp->w_p_wrap)
467 v = wp->w_skipcol;
468 else
469 v = wp->w_leftcol;
470
471 // check if line ends before left margin
472 if (wlv->vcol < v + wlv->col - win_col_off(wp))
473 wlv->vcol = v + wlv->col - win_col_off(wp);
474# ifdef FEAT_CONCEAL
475 // Get rid of the boguscols now, we want to draw until the right
476 // edge for 'cursorcolumn'.
477 wlv->col -= wlv->boguscols;
478 wlv->boguscols = 0;
479# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
480# else
481# define VCOL_HLC (wlv->vcol)
482# endif
483
484 if (wlv->draw_color_col)
485 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
486
487 if (((wp->w_p_cuc
488 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
489 && (int)wp->w_virtcol <
490 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
491 && wlv->lnum != wp->w_cursor.lnum)
492 || wlv->draw_color_col
493 || wlv->win_attr != 0)
494# ifdef FEAT_RIGHTLEFT
495 && !wp->w_p_rl
496# endif
497 )
498 {
499 int rightmost_vcol = 0;
500 int i;
501
502 if (wp->w_p_cuc)
503 rightmost_vcol = wp->w_virtcol;
504 if (wlv->draw_color_col)
505 // determine rightmost colorcolumn to possibly draw
506 for (i = 0; wlv->color_cols[i] >= 0; ++i)
507 if (rightmost_vcol < wlv->color_cols[i])
508 rightmost_vcol = wlv->color_cols[i];
509
510 while (wlv->col < wp->w_width)
511 {
512 ScreenLines[wlv->off] = ' ';
513 if (enc_utf8)
514 ScreenLinesUC[wlv->off] = 0;
515 ScreenCols[wlv->off] = MAXCOL;
516 ++wlv->col;
517 if (wlv->draw_color_col)
518 wlv->draw_color_col = advance_color_col(
519 VCOL_HLC, &wlv->color_cols);
520
521 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
522 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
523 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
524 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
525 else
526 ScreenAttrs[wlv->off++] = wlv->win_attr;
527
528 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
529 break;
530
531 ++wlv->vcol;
532 }
533 }
534#endif
535
536 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
537 wp->w_width, wlv->screen_line_flags);
538 ++wlv->row;
539 ++wlv->screen_row;
540}
541#undef VCOL_HLC
542
543/*
544 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100545 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100546 */
547 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100548win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100549{
550 wlv->col = 0;
551 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
552
553#ifdef FEAT_RIGHTLEFT
554 if (wp->w_p_rl)
555 {
556 // Rightleft window: process the text in the normal direction, but put
557 // it in current_ScreenLine[] from right to left. Start at the
558 // rightmost column of the window.
559 wlv->col = wp->w_width - 1;
560 wlv->off += wlv->col;
561 wlv->screen_line_flags |= SLF_RIGHTLEFT;
562 }
563#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100564 if (save_extra)
565 {
566 // reset the drawing state for the start of a wrapped line
567 wlv->draw_state = WL_START;
568 wlv->saved_n_extra = wlv->n_extra;
569 wlv->saved_p_extra = wlv->p_extra;
570 wlv->saved_c_extra = wlv->c_extra;
571 wlv->saved_c_final = wlv->c_final;
572#ifdef FEAT_SYN_HL
573 if (!(wlv->cul_screenline
574# ifdef FEAT_DIFF
575 && wlv->diff_hlf == (hlf_T)0
576# endif
577 ))
578 wlv->saved_char_attr = wlv->char_attr;
579 else
580#endif
581 wlv->saved_char_attr = 0;
582 wlv->n_extra = 0;
583 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100584}
585
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200586/*
587 * Display line "lnum" of window 'wp' on the screen.
588 * Start at row "startrow", stop when "endrow" is reached.
589 * wp->w_virtcol needs to be valid.
590 *
591 * Return the number of last row the line occupies.
592 */
593 int
594win_line(
595 win_T *wp,
596 linenr_T lnum,
597 int startrow,
598 int endrow,
599 int nochange UNUSED, // not updating for changed text
600 int number_only) // only update the number column
601{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100602 winlinevars_T wlv; // variables passed between functions
603
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200604 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200605#ifdef FEAT_LINEBREAK
606 long vcol_sbr = -1; // virtual column after showbreak
607#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100608 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200609 char_u *line; // current line
610 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200611
612 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200613 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100614#ifdef FEAT_PROP_POPUP
615 char_u *p_extra_free2 = NULL; // another p_extra to be freed
616#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000618#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000619 int in_linebreak = FALSE; // n_extra set for showing linebreak
620#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100622 // displaying eol at end-of-line
623 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000624 int lcs_prec_todo = wp->w_lcs_chars.prec;
625 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200626
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100627 int n_attr = 0; // chars with special attr
628 int n_attr_skip = 0; // chars to skip before using extra_attr
629 int saved_attr2 = 0; // char_attr saved for n_attr
630 int n_attr3 = 0; // chars with overruling special attr
631 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200632
633 int n_skip = 0; // nr of chars to skip for 'nowrap'
634
635 int fromcol = -10; // start of inverting
636 int tocol = MAXCOL; // end of inverting
637 int fromcol_prev = -2; // start of inverting after cursor
638 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200639 int lnum_in_visual_area = FALSE;
640 pos_T pos;
641 long v;
642
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643 int attr_pri = FALSE; // char_attr has priority
644 int area_highlighting = FALSE; // Visual or incsearch highlighting
645 // in this line
646 int vi_attr = 0; // attributes for Visual and incsearch
647 // highlighting
648 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200649 int area_attr = 0; // attributes desired by highlighting
650 int search_attr = 0; // attributes desired by 'hlsearch'
651#ifdef FEAT_SYN_HL
652 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
653 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200654 int prev_syntax_col = -1; // column of prev_syntax_attr
655 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200656 int has_syntax = FALSE; // this buffer has syntax highl.
657 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200658#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100659#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200660 int text_prop_count;
661 int text_prop_next = 0; // next text property to use
662 textprop_T *text_props = NULL;
663 int *text_prop_idxs = NULL;
664 int text_props_active = 0;
665 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100666 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200667 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100668 int text_prop_attr_comb = 0; // text_prop_attr combined with
669 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100670 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100671 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100672 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100673 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100674 int saved_search_attr = 0; // search_attr to be used when n_extra
675 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100676 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200677#endif
678#ifdef FEAT_SPELL
679 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000680 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200681# define SPWORDLEN 150
682 char_u nextline[SPWORDLEN * 2];// text with start of the next line
683 int nextlinecol = 0; // column where nextline[] starts
684 int nextline_idx = 0; // index in nextline[] where next line
685 // starts
686 int spell_attr = 0; // attributes desired by spelling
687 int word_end = 0; // last byte with same spell_attr
688 static linenr_T checked_lnum = 0; // line number for "checked_col"
689 static int checked_col = 0; // column in "checked_lnum" up to which
690 // there are no spell errors
691 static int cap_col = -1; // column to check for Cap word
692 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
693 int cur_checked_col = 0; // checked column for current line
694#endif
695 int extra_check = 0; // has extra highlighting
696 int multi_attr = 0; // attributes desired by multibyte
697 int mb_l = 1; // multi-byte byte length
698 int mb_c = 0; // decoded multi-byte character
699 int mb_utf8 = FALSE; // screen char is UTF-8 char
700 int u8cc[MAX_MCO]; // composing UTF-8 chars
701#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
702 int filler_lines = 0; // nr of filler lines to be drawn
703 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000704#else
705# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200706#endif
707#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200708 int change_start = MAXCOL; // first col of changed area
709 int change_end = -1; // last col of changed area
710#endif
711 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100712 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200713 int in_multispace = FALSE; // in multiple consecutive spaces
714 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200715#ifdef FEAT_LINEBREAK
716 int need_showbreak = FALSE; // overlong line, skipping first x
717 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100718 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200719#endif
720#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
721 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
722# define LINE_ATTR
723 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100724 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200725#endif
726#ifdef FEAT_SIGNS
727 int sign_present = FALSE;
728 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000729 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200730#endif
731#ifdef FEAT_ARABIC
732 int prev_c = 0; // previous Arabic character
733 int prev_c1 = 0; // first composing char for prev_c
734#endif
735#if defined(LINE_ATTR)
736 int did_line_attr = 0;
737#endif
738#ifdef FEAT_TERMINAL
739 int get_term_attr = FALSE;
740#endif
741#ifdef FEAT_SYN_HL
742 int cul_attr = 0; // set when 'cursorline' active
743
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200744 // margin columns for the screen line, needed for when 'cursorlineopt'
745 // contains "screenline"
746 int left_curline_col = 0;
747 int right_curline_col = 0;
748#endif
749
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200750#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
751 int feedback_col = 0;
752 int feedback_old_attr = -1;
753#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200754
755#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
756 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000757 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200758#endif
759#ifdef FEAT_CONCEAL
760 int syntax_flags = 0;
761 int syntax_seqnr = 0;
762 int prev_syntax_id = 0;
763 int conceal_attr = HL_ATTR(HLF_CONCEAL);
764 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200765 int did_wcol = FALSE;
766 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100767# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200768# define FIX_FOR_BOGUSCOLS \
769 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100770 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100771 wlv.vcol -= wlv.vcol_off; \
772 wlv.vcol_off = 0; \
773 wlv.col -= wlv.boguscols; \
774 old_boguscols = wlv.boguscols; \
775 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200776 }
777#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100778# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200779#endif
780
781 if (startrow > endrow) // past the end already!
782 return startrow;
783
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100784 CLEAR_FIELD(wlv);
785
786 wlv.lnum = lnum;
787 wlv.startrow = startrow;
788 wlv.row = startrow;
789 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200790
791 if (!number_only)
792 {
793 // To speed up the loop below, set extra_check when there is linebreak,
794 // trailing white space and/or syntax processing to be done.
795#ifdef FEAT_LINEBREAK
796 extra_check = wp->w_p_lbr;
797#endif
798#ifdef FEAT_SYN_HL
799 if (syntax_present(wp) && !wp->w_s->b_syn_error
800# ifdef SYN_TIME_LIMIT
801 && !wp->w_s->b_syn_slow
802# endif
803 )
804 {
805 // Prepare for syntax highlighting in this line. When there is an
806 // error, stop syntax highlighting.
807 save_did_emsg = did_emsg;
808 did_emsg = FALSE;
809 syntax_start(wp, lnum);
810 if (did_emsg)
811 wp->w_s->b_syn_error = TRUE;
812 else
813 {
814 did_emsg = save_did_emsg;
815#ifdef SYN_TIME_LIMIT
816 if (!wp->w_s->b_syn_slow)
817#endif
818 {
819 has_syntax = TRUE;
820 extra_check = TRUE;
821 }
822 }
823 }
824
825 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100826 wlv.color_cols = wp->w_p_cc_cols;
827 if (wlv.color_cols != NULL)
828 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200829#endif
830
831#ifdef FEAT_TERMINAL
832 if (term_show_buffer(wp->w_buffer))
833 {
834 extra_check = TRUE;
835 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100836 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200837 }
838#endif
839
840#ifdef FEAT_SPELL
841 if (wp->w_p_spell
842 && *wp->w_s->b_p_spl != NUL
843 && wp->w_s->b_langp.ga_len > 0
844 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
845 {
846 // Prepare for spell checking.
847 has_spell = TRUE;
848 extra_check = TRUE;
849
850 // Get the start of the next line, so that words that wrap to the
851 // next line are found too: "et<line-break>al.".
852 // Trick: skip a few chars for C/shell/Vim comments
853 nextline[SPWORDLEN] = NUL;
854 if (lnum < wp->w_buffer->b_ml.ml_line_count)
855 {
856 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
857 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
858 }
859
860 // When a word wrapped from the previous line the start of the
861 // current line is valid.
862 if (lnum == checked_lnum)
863 cur_checked_col = checked_col;
864 checked_lnum = 0;
865
866 // When there was a sentence end in the previous line may require a
867 // word starting with capital in this line. In line 1 always check
868 // the first word.
869 if (lnum != capcol_lnum)
870 cap_col = -1;
871 if (lnum == 1)
872 cap_col = 0;
873 capcol_lnum = 0;
874 }
875#endif
876
877 // handle Visual active in this window
878 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
879 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100880 pos_T *top, *bot;
881
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200882 if (LTOREQ_POS(curwin->w_cursor, VIsual))
883 {
884 // Visual is after curwin->w_cursor
885 top = &curwin->w_cursor;
886 bot = &VIsual;
887 }
888 else
889 {
890 // Visual is before curwin->w_cursor
891 top = &VIsual;
892 bot = &curwin->w_cursor;
893 }
894 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
895 if (VIsual_mode == Ctrl_V)
896 {
897 // block mode
898 if (lnum_in_visual_area)
899 {
900 fromcol = wp->w_old_cursor_fcol;
901 tocol = wp->w_old_cursor_lcol;
902 }
903 }
904 else
905 {
906 // non-block mode
907 if (lnum > top->lnum && lnum <= bot->lnum)
908 fromcol = 0;
909 else if (lnum == top->lnum)
910 {
911 if (VIsual_mode == 'V') // linewise
912 fromcol = 0;
913 else
914 {
915 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
916 if (gchar_pos(top) == NUL)
917 tocol = fromcol + 1;
918 }
919 }
920 if (VIsual_mode != 'V' && lnum == bot->lnum)
921 {
922 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
923 {
924 fromcol = -10;
925 tocol = MAXCOL;
926 }
927 else if (bot->col == MAXCOL)
928 tocol = MAXCOL;
929 else
930 {
931 pos = *bot;
932 if (*p_sel == 'e')
933 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
934 else
935 {
936 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
937 ++tocol;
938 }
939 }
940 }
941 }
942
943 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200944 if (!highlight_match && lnum == curwin->w_cursor.lnum
945 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200946#ifdef FEAT_GUI
947 && !gui.in_use
948#endif
949 )
950 noinvcur = TRUE;
951
952 // if inverting in this line set area_highlighting
953 if (fromcol >= 0)
954 {
955 area_highlighting = TRUE;
956 vi_attr = HL_ATTR(HLF_V);
957#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
958 if ((clip_star.available && !clip_star.owned
959 && clip_isautosel_star())
960 || (clip_plus.available && !clip_plus.owned
961 && clip_isautosel_plus()))
962 vi_attr = HL_ATTR(HLF_VNC);
963#endif
964 }
965 }
966
967 // handle 'incsearch' and ":s///c" highlighting
968 else if (highlight_match
969 && wp == curwin
970 && lnum >= curwin->w_cursor.lnum
971 && lnum <= curwin->w_cursor.lnum + search_match_lines)
972 {
973 if (lnum == curwin->w_cursor.lnum)
974 getvcol(curwin, &(curwin->w_cursor),
975 (colnr_T *)&fromcol, NULL, NULL);
976 else
977 fromcol = 0;
978 if (lnum == curwin->w_cursor.lnum + search_match_lines)
979 {
980 pos.lnum = lnum;
981 pos.col = search_match_endcol;
982 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
983 }
984 else
985 tocol = MAXCOL;
986 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100987 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 tocol = fromcol + 1;
989 area_highlighting = TRUE;
990 vi_attr = HL_ATTR(HLF_I);
991 }
992 }
993
994#ifdef FEAT_DIFF
995 filler_lines = diff_check(wp, lnum);
996 if (filler_lines < 0)
997 {
998 if (filler_lines == -1)
999 {
1000 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001001 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001003 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001005 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 }
1007 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001008 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001009 filler_lines = 0;
1010 area_highlighting = TRUE;
1011 }
1012 if (lnum == wp->w_topline)
1013 filler_lines = wp->w_topfill;
1014 filler_todo = filler_lines;
1015#endif
1016
1017#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01001018 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +00001019 if (sign_present)
1020 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021#endif
1022
1023#ifdef LINE_ATTR
1024# ifdef FEAT_SIGNS
1025 // If this line has a sign with line highlighting set line_attr.
1026 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001027 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028# endif
1029# if defined(FEAT_QUICKFIX)
1030 // Highlight the current line in the quickfix window.
1031 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1032 line_attr = HL_ATTR(HLF_QFL);
1033# endif
1034 if (line_attr != 0)
1035 area_highlighting = TRUE;
1036#endif
1037
1038 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1039 ptr = line;
1040
1041#ifdef FEAT_SPELL
1042 if (has_spell && !number_only)
1043 {
1044 // For checking first word with a capital skip white space.
1045 if (cap_col == 0)
1046 cap_col = getwhitecols(line);
1047
1048 // To be able to spell-check over line boundaries copy the end of the
1049 // current line into nextline[]. Above the start of the next line was
1050 // copied to nextline[SPWORDLEN].
1051 if (nextline[SPWORDLEN] == NUL)
1052 {
1053 // No next line or it is empty.
1054 nextlinecol = MAXCOL;
1055 nextline_idx = 0;
1056 }
1057 else
1058 {
1059 v = (long)STRLEN(line);
1060 if (v < SPWORDLEN)
1061 {
1062 // Short line, use it completely and append the start of the
1063 // next line.
1064 nextlinecol = 0;
1065 mch_memmove(nextline, line, (size_t)v);
1066 STRMOVE(nextline + v, nextline + SPWORDLEN);
1067 nextline_idx = v + 1;
1068 }
1069 else
1070 {
1071 // Long line, use only the last SPWORDLEN bytes.
1072 nextlinecol = v - SPWORDLEN;
1073 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1074 nextline_idx = SPWORDLEN + 1;
1075 }
1076 }
1077 }
1078#endif
1079
1080 if (wp->w_p_list)
1081 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001082 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001083 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001084 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001085 || wp->w_lcs_chars.trail
1086 || wp->w_lcs_chars.lead
1087 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001089
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001090 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001091 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092 {
1093 trailcol = (colnr_T)STRLEN(ptr);
1094 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1095 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001096 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001097 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001098 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001099 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001100 {
1101 leadcol = 0;
1102 while (VIM_ISWHITE(ptr[leadcol]))
1103 ++leadcol;
1104 if (ptr[leadcol] == NUL)
1105 // in a line full of spaces all of them are treated as trailing
1106 leadcol = (colnr_T)0;
1107 else
1108 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001109 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001110 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 }
1112
1113 wcr_attr = get_wcr_attr(wp);
1114 if (wcr_attr != 0)
1115 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001116 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 area_highlighting = TRUE;
1118 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001119
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001120#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001122 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123#endif
1124
1125 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1126 // first character to be displayed.
1127 if (wp->w_p_wrap)
1128 v = wp->w_skipcol;
1129 else
1130 v = wp->w_leftcol;
1131 if (v > 0 && !number_only)
1132 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001133 char_u *prev_ptr = ptr;
1134 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001135 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001136
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001137 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001138 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001140 charsize = win_lbr_chartabsize(&cts, NULL);
1141 cts.cts_vcol += charsize;
1142 prev_ptr = cts.cts_ptr;
1143 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001145 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001146 ptr = cts.cts_ptr;
1147 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148
1149 // When:
1150 // - 'cuc' is set, or
1151 // - 'colorcolumn' is set, or
1152 // - 'virtualedit' is set, or
1153 // - the visual mode is active,
1154 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001155 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001156#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001157 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158#endif
1159 virtual_active() ||
1160 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001161 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162
1163 // Handle a character that's not completely on the screen: Put ptr at
1164 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001165 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001167 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001168 ptr = prev_ptr;
1169 // If the character fits on the screen, don't need to skip it.
1170 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001171 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1172 && wlv.col == 0)
1173 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174 }
1175
1176 // Adjust for when the inverted text is before the screen,
1177 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001178 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001180 else if (fromcol >= 0 && fromcol < wlv.vcol)
1181 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001182
1183#ifdef FEAT_LINEBREAK
1184 // When w_skipcol is non-zero, first line needs 'showbreak'
1185 if (wp->w_p_wrap)
1186 need_showbreak = TRUE;
1187#endif
1188#ifdef FEAT_SPELL
1189 // When spell checking a word we need to figure out the start of the
1190 // word and if it's badly spelled or not.
1191 if (has_spell)
1192 {
1193 int len;
1194 colnr_T linecol = (colnr_T)(ptr - line);
1195 hlf_T spell_hlf = HLF_COUNT;
1196
1197 pos = wp->w_cursor;
1198 wp->w_cursor.lnum = lnum;
1199 wp->w_cursor.col = linecol;
1200 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1201
1202 // spell_move_to() may call ml_get() and make "line" invalid
1203 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1204 ptr = line + linecol;
1205
1206 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1207 {
1208 // no bad word found at line start, don't check until end of a
1209 // word
1210 spell_hlf = HLF_COUNT;
1211 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1212 }
1213 else
1214 {
1215 // bad word found, use attributes until end of word
1216 word_end = wp->w_cursor.col + len + 1;
1217
1218 // Turn index into actual attributes.
1219 if (spell_hlf != HLF_COUNT)
1220 spell_attr = highlight_attr[spell_hlf];
1221 }
1222 wp->w_cursor = pos;
1223
1224# ifdef FEAT_SYN_HL
1225 // Need to restart syntax highlighting for this line.
1226 if (has_syntax)
1227 syntax_start(wp, lnum);
1228# endif
1229 }
1230#endif
1231 }
1232
1233 // Correct highlighting for cursor that can't be disabled.
1234 // Avoids having to check this for each character.
1235 if (fromcol >= 0)
1236 {
1237 if (noinvcur)
1238 {
1239 if ((colnr_T)fromcol == wp->w_virtcol)
1240 {
1241 // highlighting starts at cursor, let it start just after the
1242 // cursor
1243 fromcol_prev = fromcol;
1244 fromcol = -1;
1245 }
1246 else if ((colnr_T)fromcol < wp->w_virtcol)
1247 // restart highlighting after the cursor
1248 fromcol_prev = wp->w_virtcol;
1249 }
1250 if (fromcol >= tocol)
1251 fromcol = -1;
1252 }
1253
1254#ifdef FEAT_SEARCH_EXTRA
1255 if (!number_only)
1256 {
1257 v = (long)(ptr - line);
1258 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1259 &line, &screen_search_hl,
1260 &search_attr);
1261 ptr = line + v; // "line" may have been updated
1262 }
1263#endif
1264
1265#ifdef FEAT_SYN_HL
1266 // Cursor line highlighting for 'cursorline' in the current window.
1267 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1268 {
1269 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001270 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271 if (!(wp == curwin && VIsual_active)
1272 && wp->w_p_culopt_flags != CULOPT_NBR)
1273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001274 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1276
1277 // Only set line_attr here when "screenline" is not present in
1278 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001279 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001280 {
1281 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001282# ifdef FEAT_SIGNS
1283 // Combine the 'cursorline' and sign highlighting, depending on
1284 // the sign priority.
1285 if (sign_present && sattr.sat_linehl > 0)
1286 {
1287 if (sattr.sat_priority >= 100)
1288 line_attr = hl_combine_attr(cul_attr, line_attr);
1289 else
1290 line_attr = hl_combine_attr(line_attr, cul_attr);
1291 }
1292 else
1293# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001294# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001295 // let the line attribute overrule 'cursorline', otherwise
1296 // it disappears when both have background set;
1297 // 'cursorline' can use underline or bold to make it show
1298 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001299# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001300 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001301# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 }
1303 else
1304 {
1305 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1307 }
1308 area_highlighting = TRUE;
1309 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 }
1311#endif
1312
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001313#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 {
1315 char_u *prop_start;
1316
1317 text_prop_count = get_text_props(wp->w_buffer, lnum,
1318 &prop_start, FALSE);
1319 if (text_prop_count > 0)
1320 {
1321 // Make a copy of the properties, so that they are properly
1322 // aligned.
1323 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1324 if (text_props != NULL)
1325 mch_memmove(text_props, prop_start,
1326 text_prop_count * sizeof(textprop_T));
1327
1328 // Allocate an array for the indexes.
1329 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001330 if (text_prop_idxs == NULL)
1331 VIM_CLEAR(text_props);
1332
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 area_highlighting = TRUE;
1334 extra_check = TRUE;
1335 }
1336 }
1337#endif
1338
Bram Moolenaar1306b362022-08-06 15:59:06 +01001339 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340
1341 // Repeat for the whole displayed line.
1342 for (;;)
1343 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001344 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001346 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347#endif
1348#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001349 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001351
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001353 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001355#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001356 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001357 {
1358 cul_attr = 0;
1359 line_attr = line_attr_save;
1360 }
1361#endif
1362
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001364 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 if (cmdwin_type != 0 && wp == curwin)
1368 {
1369 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001370 wlv.n_extra = 1;
1371 wlv.c_extra = cmdwin_type;
1372 wlv.c_final = NUL;
1373 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 }
1375 }
1376#endif
1377
1378#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001379 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 {
1381 int fdc = compute_foldcolumn(wp, 0);
1382
Bram Moolenaar1306b362022-08-06 15:59:06 +01001383 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 if (fdc > 0)
1385 {
1386 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1387 // already be in use.
1388 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001389 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390 if (p_extra_free != NULL)
1391 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001392 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001393 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001394 p_extra_free[wlv.n_extra] = NUL;
1395 wlv.p_extra = p_extra_free;
1396 wlv.c_extra = NUL;
1397 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001398 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001399 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001400 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1401 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001402 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001403 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 }
1405 }
1406 }
1407#endif
1408
1409#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001410 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001412 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 // Show the sign column when there are any signs in this
1414 // buffer or when using Netbeans.
1415 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001416 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1417 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 }
1419#endif
1420
Bram Moolenaar1306b362022-08-06 15:59:06 +01001421 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001423 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 // Display the absolute or relative line number. After the
1425 // first fill with blanks when the 'n' flag isn't in 'cpo'
1426 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001427 && (wlv.row == startrow + filler_lines
1428 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 {
1430#ifdef FEAT_SIGNS
1431 // If 'signcolumn' is set to 'number' and a sign is present
1432 // in 'lnum', then display the sign instead of the line
1433 // number.
1434 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1435 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001436 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1437 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 else
1439#endif
1440 {
1441 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001442 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443 {
1444 long num;
1445 char *fmt = "%*ld ";
1446
1447 if (wp->w_p_nu && !wp->w_p_rnu)
1448 // 'number' + 'norelativenumber'
1449 num = (long)lnum;
1450 else
1451 {
1452 // 'relativenumber', don't use negative numbers
1453 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1454 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1455 {
1456 // 'number' + 'relativenumber'
1457 num = lnum;
1458 fmt = "%-*ld ";
1459 }
1460 }
1461
1462 sprintf((char *)extra, fmt,
1463 number_width(wp), num);
1464 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001465 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1466 ++wlv.p_extra)
1467 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468#ifdef FEAT_RIGHTLEFT
1469 if (wp->w_p_rl) // reverse line numbers
1470 {
1471 char_u *p1, *p2;
1472 int t;
1473
1474 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001475 p2 = skipwhite(extra);
1476 p2 = skiptowhite(p2) - 1;
1477 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 {
1479 t = *p1;
1480 *p1 = *p2;
1481 *p2 = t;
1482 }
1483 }
1484#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001485 wlv.p_extra = extra;
1486 wlv.c_extra = NUL;
1487 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488 }
1489 else
1490 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001491 wlv.c_extra = ' ';
1492 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001494 wlv.n_extra = number_width(wp) + 1;
1495 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496#ifdef FEAT_SYN_HL
1497 // When 'cursorline' is set highlight the line number of
1498 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001499 // When 'cursorlineopt' does not have "line" only
1500 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 // TODO: Can we use CursorLine instead of CursorLineNr
1502 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001503 if (wp->w_p_cul
1504 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001506 && (wlv.row == startrow + filler_lines
1507 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001508 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001509 wlv.char_attr = hl_combine_attr(wcr_attr,
1510 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001512 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1513 && HL_ATTR(HLF_LNA) != 0)
1514 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001515 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001516 HL_ATTR(HLF_LNA));
1517 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1518 && HL_ATTR(HLF_LNB) != 0)
1519 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001520 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001521 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 }
James McCoya80aad72021-12-22 19:45:28 +00001523#ifdef FEAT_SIGNS
1524 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001525 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001526#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 }
1528 }
1529
1530#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001531 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1532 && wlv.n_extra == 0
1533 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001535 wlv.draw_state = WL_BRI;
1536 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1537 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001539 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540
1541 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001542 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001544 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001546 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547# ifdef FEAT_DIFF
1548 && filler_lines == 0
1549# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001550# ifdef FEAT_PROP_POPUP
1551 && !dont_use_showbreak
1552# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 )
1554 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001555 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001557 if (wlv.diff_hlf != (hlf_T)0)
1558 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001560 wlv.p_extra = NULL;
1561 wlv.c_extra = ' ';
1562 wlv.c_final = NUL;
1563 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001564 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001565 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001566 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001567 wlv.n_extra -= win_col_off2(wp);
1568 if (wlv.n_extra < 0)
1569 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001570 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001571 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001572 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001573 // Correct end of highlighted area for 'breakindent',
1574 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001575 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001576 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577 }
1578 }
1579#endif
1580
1581#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001582 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001584 char_u *sbr;
1585
Bram Moolenaar1306b362022-08-06 15:59:06 +01001586 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587# ifdef FEAT_DIFF
1588 if (filler_todo > 0)
1589 {
1590 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001591 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001593 wlv.c_extra = '-';
1594 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 }
1596 else
1597 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001598 wlv.c_extra = wp->w_fill_chars.diff;
1599 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 }
1601# ifdef FEAT_RIGHTLEFT
1602 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001603 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 else
1605# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001606 wlv.n_extra = wp->w_width - wlv.col;
1607 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 }
1609# endif
1610# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001611 sbr = get_showbreak_value(wp);
1612 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613 {
1614 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001615 wlv.p_extra = sbr;
1616 wlv.c_extra = NUL;
1617 wlv.c_final = NUL;
1618 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001619 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1620 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001621 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 // Correct end of highlighted area for 'showbreak',
1623 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001624 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001625 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001627 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1628 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629# ifdef FEAT_SYN_HL
1630 // combine 'showbreak' with 'cursorline'
1631 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001632 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1633 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634# endif
1635 }
1636# endif
1637 }
1638#endif
1639
Bram Moolenaar1306b362022-08-06 15:59:06 +01001640 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001642 wlv.draw_state = WL_LINE;
1643 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 {
1645 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001646 wlv.n_extra = wlv.saved_n_extra;
1647 wlv.c_extra = wlv.saved_c_extra;
1648 wlv.c_final = wlv.saved_c_final;
1649 wlv.p_extra = wlv.saved_p_extra;
1650 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651 }
1652 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001653 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 }
1655 }
1656#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001657 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001658 && wlv.vcol >= left_curline_col
1659 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001661 cul_attr = HL_ATTR(HLF_CUL);
1662 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001663 }
1664#endif
1665
1666 // When still displaying '$' of change command, stop at cursor.
1667 // When only displaying the (relative) line number and that's done,
1668 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001669 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001670 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001671 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672#ifdef FEAT_DIFF
1673 && filler_todo <= 0
1674#endif
1675 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001677 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1678 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 // Pretend we have finished updating the window. Except when
1680 // 'cursorcolumn' is set.
1681#ifdef FEAT_SYN_HL
1682 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001683 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 else
1685#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001686 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 break;
1688 }
1689
Bram Moolenaar1306b362022-08-06 15:59:06 +01001690 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 {
1692 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001693 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001694 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 && (*mb_ptr2cells)(ptr) > 1)
1696 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001697 && vcol_prev < wlv.vcol // not at margin
1698 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 area_attr = vi_attr; // start highlighting
1700 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001701 && (wlv.vcol == tocol
1702 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 area_attr = 0; // stop highlighting
1704
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001705#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 if (text_props != NULL)
1707 {
1708 int pi;
1709 int bcol = (int)(ptr - line);
1710
Bram Moolenaar1306b362022-08-06 15:59:06 +01001711 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001712# ifdef FEAT_LINEBREAK
1713 && !in_linebreak
1714# endif
1715 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 --bcol; // still working on the previous char, e.g. Tab
1717
1718 // Check if any active property ends.
1719 for (pi = 0; pi < text_props_active; ++pi)
1720 {
1721 int tpi = text_prop_idxs[pi];
1722
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001723 if (text_props[tpi].tp_col != MAXCOL
1724 && bcol >= text_props[tpi].tp_col - 1
1725 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 {
1727 if (pi + 1 < text_props_active)
1728 mch_memmove(text_prop_idxs + pi,
1729 text_prop_idxs + pi + 1,
1730 sizeof(int)
1731 * (text_props_active - (pi + 1)));
1732 --text_props_active;
1733 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001734# ifdef FEAT_LINEBREAK
1735 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001736 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001737 syntax_attr = 0;
1738# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 }
1740 }
1741
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001742# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001743 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001744 // not on the next char yet, don't start another prop
1745 --bcol;
1746# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001748 // With 'nowrap' and not in the first screen line only "below"
1749 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001751 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001752 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001753 && (wp->w_p_wrap
1754 || wlv.row == startrow
1755 || (text_props[text_prop_next].tp_flags
1756 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001757 || (bcol == 0 &&
1758 (text_props[text_prop_next].tp_flags
1759 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001760 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001761 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001762 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001763 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1764 {
1765 // first display the '$' after the line
1766 text_prop_follows = TRUE;
1767 break;
1768 }
1769 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001770 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001771 + text_props[text_prop_next].tp_len)
1772 text_prop_idxs[text_props_active++] = text_prop_next;
1773 ++text_prop_next;
1774 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001776 if (wlv.n_extra == 0 || !extra_for_textprop)
1777 {
1778 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001779 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001780 text_prop_flags = 0;
1781 text_prop_type = NULL;
1782 text_prop_id = 0;
1783 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001784 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001786 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001787 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001788 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001789
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790 // Sort the properties on priority and/or starting last.
1791 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001792 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001793 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001794 sort_text_props(wp->w_buffer, text_props,
1795 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796
1797 for (pi = 0; pi < text_props_active; ++pi)
1798 {
1799 int tpi = text_prop_idxs[pi];
1800 proptype_T *pt = text_prop_type_by_id(
1801 wp->w_buffer, text_props[tpi].tp_type);
1802
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001803 if (pt != NULL && (pt->pt_hl_id > 0
1804 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001805 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001807 if (pt->pt_hl_id > 0)
1808 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 text_prop_type = pt;
1810 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001811 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001812 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001813 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001814 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001815 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 }
1817 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001818 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001819 && -text_prop_id
1820 <= wp->w_buffer->b_textprop_text.ga_len)
1821 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001822 textprop_T *tp = &text_props[used_tpi];
1823 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001824 ->b_textprop_text.ga_data)[
1825 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001826 int above = (tp->tp_flags
1827 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001828
1829 // reset the ID in the copy to avoid it being used
1830 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001831 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001832
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001833 if (p != NULL)
1834 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001835 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001836 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001837 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001838 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001839 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1840 int padding = tp->tp_col == MAXCOL
1841 && tp->tp_len > 1
1842 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001843
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001844 // Insert virtual text before the current
1845 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001846 wlv.p_extra = p;
1847 wlv.c_extra = NUL;
1848 wlv.c_final = NUL;
1849 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001850 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001851 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001852 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001853 // restore search_attr and area_attr when n_extra
1854 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001855 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001856 saved_area_attr = area_attr;
1857 search_attr = 0;
1858 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001859 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001860 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001861 if (*ptr == NUL)
1862 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001863 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001864#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001865 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001866 {
1867 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001868 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001869 need_showbreak = FALSE;
1870 dont_use_showbreak = TRUE;
1871 }
1872#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001873 if ((right || above || below || !wrap
1874 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001875 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001876 char_u *prev_p_extra = wlv.p_extra;
1877 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001878
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001879 // Take care of padding, right-align and
1880 // truncation.
1881 // Shared with win_lbr_chartabsize(), must do
1882 // exactly the same.
1883 start_line = text_prop_position(wp, tp,
1884 wlv.col,
1885 &wlv.n_extra, &wlv.p_extra,
1886 &n_attr, &n_attr_skip);
1887 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001888 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001889 // wlv.p_extra was allocated
1890 vim_free(p_extra_free2);
1891 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001892 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001893
Bram Moolenaara4abe512022-09-15 19:44:09 +01001894 if (lcs_eol_one < 0 && wlv.col
1895 + wlv.n_extra - 2 > wp->w_width)
1896 // don't bail out at end of line
1897 lcs_eol_one = 0;
1898
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001899 // When 'wrap' is off then for "below" we need
1900 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001901 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001902 {
1903 draw_screen_line(wp, &wlv);
1904
1905 // When line got too long for screen break
1906 // here.
1907 if (wlv.row == endrow)
1908 {
1909 ++wlv.row;
1910 break;
1911 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001912 win_line_start(wp, &wlv, TRUE);
1913 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001914 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001915 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001916 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001917
1918 // If another text prop follows the condition below at
1919 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001920 // If this is an "above" text prop and 'nowrap' the we
1921 // must wrap anyway.
1922 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001923 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001924 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001926 else if (text_prop_next < text_prop_count
1927 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001928 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1929 || (!wp->w_p_wrap
1930 && wlv.col == wp->w_width - 1
1931 && (text_props[text_prop_next].tp_flags
1932 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001933 // When at last-but-one character and a text property
1934 // follows after it, we may need to flush the line after
1935 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001936 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001937 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 }
1939#endif
1940
Bram Moolenaare38fc862022-08-11 17:24:50 +01001941#ifdef FEAT_SEARCH_EXTRA
1942 if (wlv.n_extra == 0)
1943 {
1944 // Check for start/end of 'hlsearch' and other matches.
1945 // After end, check for start/end of next match.
1946 // When another match, have to check for start again.
1947 v = (long)(ptr - line);
1948 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1949 &screen_search_hl, &has_match_conc,
1950 &match_conc, did_line_attr, lcs_eol_one,
1951 &on_last_col);
1952 ptr = line + v; // "line" may have been changed
1953 prev_ptr = ptr;
1954
1955 // Do not allow a conceal over EOL otherwise EOL will be missed
1956 // and bad things happen.
1957 if (*ptr == NUL)
1958 has_match_conc = 0;
1959 }
1960#endif
1961
1962#ifdef FEAT_DIFF
1963 if (wlv.diff_hlf != (hlf_T)0)
1964 {
1965 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1966 && wlv.n_extra == 0)
1967 wlv.diff_hlf = HLF_TXD; // changed text
1968 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1969 && wlv.n_extra == 0)
1970 wlv.diff_hlf = HLF_CHD; // changed line
1971 line_attr = HL_ATTR(wlv.diff_hlf);
1972 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1973 && wp->w_p_culopt_flags != CULOPT_NBR
1974 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1975 && wlv.vcol <= right_curline_col)))
1976 line_attr = hl_combine_attr(
1977 line_attr, HL_ATTR(HLF_CUL));
1978 }
1979#endif
1980
Bram Moolenaara74fda62019-10-19 17:38:03 +02001981#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001982 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001983 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001984 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001985# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001986 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001987 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001988# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001989 // Get syntax attribute.
1990 if (has_syntax)
1991 {
1992 // Get the syntax attribute for the character. If there
1993 // is an error, disable syntax highlighting.
1994 save_did_emsg = did_emsg;
1995 did_emsg = FALSE;
1996
1997 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001998 if (v == prev_syntax_col)
1999 // at same column again
2000 syntax_attr = prev_syntax_attr;
2001 else
2002 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002003# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002004 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002005# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002006 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002007# ifdef FEAT_SPELL
2008 has_spell ? &can_spell :
2009# endif
2010 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002011 prev_syntax_col = v;
2012 prev_syntax_attr = syntax_attr;
2013 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002014
Bram Moolenaar34390282019-10-16 14:38:26 +02002015 if (did_emsg)
2016 {
2017 wp->w_s->b_syn_error = TRUE;
2018 has_syntax = FALSE;
2019 syntax_attr = 0;
2020 }
2021 else
2022 did_emsg = save_did_emsg;
2023# ifdef SYN_TIME_LIMIT
2024 if (wp->w_s->b_syn_slow)
2025 has_syntax = FALSE;
2026# endif
2027
2028 // Need to get the line again, a multi-line regexp may
2029 // have made it invalid.
2030 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2031 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002032 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002033# ifdef FEAT_CONCEAL
2034 // no concealing past the end of the line, it interferes
2035 // with line highlighting
2036 if (*ptr == NUL)
2037 syntax_flags = 0;
2038 else
2039 syntax_flags = get_syntax_info(&syntax_seqnr);
2040# endif
2041 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002042 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002043# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002044 // Combine text property highlight into syntax highlight.
2045 if (text_prop_type != NULL)
2046 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002047 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002048 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2049 else
2050 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002051 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002052 }
2053# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002054#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002055
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056 // Decide which of the highlight attributes to use.
2057 attr_pri = TRUE;
2058#ifdef LINE_ATTR
2059 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002060 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002061 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002062 if (!highlight_match)
2063 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002064 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002065# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002066 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002067# endif
2068 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002070 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002071 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002072# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002073 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002074# endif
2075 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002076 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002077 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2078 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 {
2080 // Use line_attr when not in the Visual or 'incsearch' area
2081 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002082# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002083 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002084# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002085 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002086# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087 attr_pri = FALSE;
2088 }
2089#else
2090 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002091 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002093 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094#endif
2095 else
2096 {
2097 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002099 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002100#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002101 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002102#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002103 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002104#ifdef FEAT_PROP_POPUP
2105 // override with text property highlight when "override" is TRUE
2106 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002107 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002108#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002109 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002110
2111 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002112 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002113 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002114 if (wlv.char_attr == 0)
2115 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002116 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002117 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002118 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002119
2120 // Get the next character to put on the screen.
2121
2122 // The "p_extra" points to the extra stuff that is inserted to
2123 // represent special characters (non-printable stuff) and other
2124 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002125 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002126 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2127 // "p_extra[n_extra]".
2128 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002131 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002133 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2134 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002135 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2136 if (enc_utf8 && utf_char2len(c) > 1)
2137 {
2138 mb_utf8 = TRUE;
2139 u8cc[0] = 0;
2140 c = 0xc0;
2141 }
2142 else
2143 mb_utf8 = FALSE;
2144 }
2145 else
2146 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002147 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002148 if (has_mbyte)
2149 {
2150 mb_c = c;
2151 if (enc_utf8)
2152 {
2153 // If the UTF-8 character is more than one byte:
2154 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002155 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002156 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002157 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002158 mb_l = 1;
2159 else if (mb_l > 1)
2160 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002161 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 mb_utf8 = TRUE;
2163 c = 0xc0;
2164 }
2165 }
2166 else
2167 {
2168 // if this is a DBCS character, put it in "mb_c"
2169 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 mb_l = 1;
2172 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002173 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002174 }
2175 if (mb_l == 0) // at the NUL at end-of-line
2176 mb_l = 1;
2177
2178 // If a double-width char doesn't fit display a '>' in the
2179 // last column.
2180 if ((
2181# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002182 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002183# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002184 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002185 && (*mb_char2cells)(mb_c) == 2)
2186 {
2187 c = '>';
2188 mb_c = c;
2189 mb_l = 1;
2190 mb_utf8 = FALSE;
2191 multi_attr = HL_ATTR(HLF_AT);
2192#ifdef FEAT_SYN_HL
2193 if (cul_attr)
2194 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2195#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002196 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002197
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002198 // put the pointer back to output the double-width
2199 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002200 ++wlv.n_extra;
2201 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202 }
2203 else
2204 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002205 wlv.n_extra -= mb_l - 1;
2206 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 }
2208 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002209 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002211 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002212#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002213 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002214 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002215 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002216 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002217 if (search_attr == 0)
2218 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002219 if (area_attr == 0 && *ptr != NUL)
2220 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002221 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002222#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 }
2224 else
2225 {
2226#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002227 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002228#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002229 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002230
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 // Get a character from the line itself.
2232 c = *ptr;
2233#ifdef FEAT_LINEBREAK
2234 c0 = *ptr;
2235#endif
2236 if (has_mbyte)
2237 {
2238 mb_c = c;
2239 if (enc_utf8)
2240 {
2241 // If the UTF-8 character is more than one byte: Decode it
2242 // into "mb_c".
2243 mb_l = utfc_ptr2len(ptr);
2244 mb_utf8 = FALSE;
2245 if (mb_l > 1)
2246 {
2247 mb_c = utfc_ptr2char(ptr, u8cc);
2248 // Overlong encoded ASCII or ASCII with composing char
2249 // is displayed normally, except a NUL.
2250 if (mb_c < 0x80)
2251 {
2252 c = mb_c;
2253#ifdef FEAT_LINEBREAK
2254 c0 = mb_c;
2255#endif
2256 }
2257 mb_utf8 = TRUE;
2258
2259 // At start of the line we can have a composing char.
2260 // Draw it as a space with a composing char.
2261 if (utf_iscomposing(mb_c))
2262 {
2263 int i;
2264
2265 for (i = Screen_mco - 1; i > 0; --i)
2266 u8cc[i] = u8cc[i - 1];
2267 u8cc[0] = mb_c;
2268 mb_c = ' ';
2269 }
2270 }
2271
2272 if ((mb_l == 1 && c >= 0x80)
2273 || (mb_l >= 1 && mb_c == 0)
2274 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2275 {
2276 // Illegal UTF-8 byte: display as <xx>.
2277 // Non-BMP character : display as ? or fullwidth ?.
2278 transchar_hex(extra, mb_c);
2279# ifdef FEAT_RIGHTLEFT
2280 if (wp->w_p_rl) // reverse
2281 rl_mirror(extra);
2282# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 wlv.p_extra = extra;
2284 c = *wlv.p_extra;
2285 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2288 wlv.c_extra = NUL;
2289 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 if (area_attr == 0 && search_attr == 0)
2291 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002292 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002293 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002294 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002295 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296 }
2297 }
2298 else if (mb_l == 0) // at the NUL at end-of-line
2299 mb_l = 1;
2300#ifdef FEAT_ARABIC
2301 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2302 {
2303 // Do Arabic shaping.
2304 int pc, pc1, nc;
2305 int pcc[MAX_MCO];
2306
2307 // The idea of what is the previous and next
2308 // character depends on 'rightleft'.
2309 if (wp->w_p_rl)
2310 {
2311 pc = prev_c;
2312 pc1 = prev_c1;
2313 nc = utf_ptr2char(ptr + mb_l);
2314 prev_c1 = u8cc[0];
2315 }
2316 else
2317 {
2318 pc = utfc_ptr2char(ptr + mb_l, pcc);
2319 nc = prev_c;
2320 pc1 = pcc[0];
2321 }
2322 prev_c = mb_c;
2323
2324 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2325 }
2326 else
2327 prev_c = mb_c;
2328#endif
2329 }
2330 else // enc_dbcs
2331 {
2332 mb_l = MB_BYTE2LEN(c);
2333 if (mb_l == 0) // at the NUL at end-of-line
2334 mb_l = 1;
2335 else if (mb_l > 1)
2336 {
2337 // We assume a second byte below 32 is illegal.
2338 // Hopefully this is OK for all double-byte encodings!
2339 if (ptr[1] >= 32)
2340 mb_c = (c << 8) + ptr[1];
2341 else
2342 {
2343 if (ptr[1] == NUL)
2344 {
2345 // head byte at end of line
2346 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002347 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 }
2349 else
2350 {
2351 // illegal tail byte
2352 mb_l = 2;
2353 STRCPY(extra, "XX");
2354 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002355 wlv.p_extra = extra;
2356 wlv.n_extra = (int)STRLEN(extra) - 1;
2357 wlv.c_extra = NUL;
2358 wlv.c_final = NUL;
2359 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360 if (area_attr == 0 && search_attr == 0)
2361 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002362 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002363 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002364 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002365 // save current attr
2366 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 }
2368 mb_c = c;
2369 }
2370 }
2371 }
2372 // If a double-width char doesn't fit display a '>' in the
2373 // last column; the character is displayed at the start of the
2374 // next line.
2375 if ((
2376# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002377 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002378# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002379 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 && (*mb_char2cells)(mb_c) == 2)
2381 {
2382 c = '>';
2383 mb_c = c;
2384 mb_utf8 = FALSE;
2385 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002386 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002387 // Put pointer back so that the character will be
2388 // displayed at the start of the next line.
2389 --ptr;
2390#ifdef FEAT_CONCEAL
2391 did_decrement_ptr = TRUE;
2392#endif
2393 }
2394 else if (*ptr != NUL)
2395 ptr += mb_l - 1;
2396
2397 // If a double-width char doesn't fit at the left side display
2398 // a '<' in the first column. Don't do this for unprintable
2399 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002400 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002402 wlv.n_extra = 1;
2403 wlv.c_extra = MB_FILLER_CHAR;
2404 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405 c = ' ';
2406 if (area_attr == 0 && search_attr == 0)
2407 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002408 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002409 extra_attr = hl_combine_attr(
2410 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002411 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002412 }
2413 mb_c = c;
2414 mb_utf8 = FALSE;
2415 mb_l = 1;
2416 }
2417
2418 }
2419 ++ptr;
2420
2421 if (extra_check)
2422 {
2423#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002424 // Check spelling (unless at the end of the line).
2425 // Only do this when there is no syntax highlighting, the
2426 // @Spell cluster is not used or the current syntax item
2427 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002428 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429 if (has_spell && v >= word_end && v > cur_checked_col)
2430 {
2431 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002432 // do not calculate cap_col at the end of the line or when
2433 // only white space is following
2434 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435# ifdef FEAT_SYN_HL
2436 !has_syntax ||
2437# endif
2438 can_spell))
2439 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002440 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 int len;
2442 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002443
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446
2447 // Use nextline[] if possible, it has the start of the
2448 // next line concatenated.
2449 if ((prev_ptr - line) - nextlinecol >= 0)
2450 p = nextline + (prev_ptr - line) - nextlinecol;
2451 else
2452 p = prev_ptr;
2453 cap_col -= (int)(prev_ptr - line);
2454 len = spell_check(wp, p, &spell_hlf, &cap_col,
2455 nochange);
2456 word_end = v + len;
2457
2458 // In Insert mode only highlight a word that
2459 // doesn't touch the cursor.
2460 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002461 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002462 && wp->w_cursor.lnum == lnum
2463 && wp->w_cursor.col >=
2464 (colnr_T)(prev_ptr - line)
2465 && wp->w_cursor.col < (colnr_T)word_end)
2466 {
2467 spell_hlf = HLF_COUNT;
2468 spell_redraw_lnum = lnum;
2469 }
2470
2471 if (spell_hlf == HLF_COUNT && p != prev_ptr
2472 && (p - nextline) + len > nextline_idx)
2473 {
2474 // Remember that the good word continues at the
2475 // start of the next line.
2476 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002477 checked_col = (int)((p - nextline)
2478 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002479 }
2480
2481 // Turn index into actual attributes.
2482 if (spell_hlf != HLF_COUNT)
2483 spell_attr = highlight_attr[spell_hlf];
2484
2485 if (cap_col > 0)
2486 {
2487 if (p != prev_ptr
2488 && (p - nextline) + cap_col >= nextline_idx)
2489 {
2490 // Remember that the word in the next line
2491 // must start with a capital.
2492 capcol_lnum = lnum + 1;
2493 cap_col = (int)((p - nextline) + cap_col
2494 - nextline_idx);
2495 }
2496 else
2497 // Compute the actual column.
2498 cap_col += (int)(prev_ptr - line);
2499 }
2500 }
2501 }
2502 if (spell_attr != 0)
2503 {
2504 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2506 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002508 wlv.char_attr = hl_combine_attr(spell_attr,
2509 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 }
2511#endif
2512#ifdef FEAT_LINEBREAK
2513 // Found last space before word: check for line break.
2514 if (wp->w_p_lbr && c0 == c
2515 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2516 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002517 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2518 : 0;
2519 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002520 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002522 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002523# ifdef FEAT_PROP_POPUP
2524 // do not want virtual text counted here
2525 cts.cts_has_prop_with_text = FALSE;
2526# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002527 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002528 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002529
2530 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002531 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002532 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002533 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002534 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2535 if (wlv.n_extra < 0)
2536 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002537 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002538 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002539 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002540 // line break, but for TABs the highlighting should
2541 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002542 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002543
Bram Moolenaar1306b362022-08-06 15:59:06 +01002544 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002547 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 wp->w_buffer->b_p_vts_array) - 1;
2549# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002550 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002551 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552# endif
2553
Bram Moolenaar1306b362022-08-06 15:59:06 +01002554 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2555 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002556# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002557 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002558 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002559# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 if (VIM_ISWHITE(c))
2561 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002562# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002563 if (c == TAB)
2564 // See "Tab alignment" below.
2565 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002566# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 if (!wp->w_p_list)
2568 c = ' ';
2569 }
2570 }
2571#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002572 in_multispace = c == ' '
2573 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2574 if (!in_multispace)
2575 multispace_pos = 0;
2576
Bram Moolenaareed9d462021-02-15 20:38:25 +01002577 // 'list': Change char 160 to 'nbsp' and space to 'space'
2578 // setting in 'listchars'. But not when the character is
2579 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580 if (wp->w_p_list
2581 && ((((c == 160 && mb_l == 1)
2582 || (mb_utf8
2583 && ((mb_c == 160 && mb_l == 2)
2584 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002585 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 || (c == ' '
2587 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002588 && (wp->w_lcs_chars.space
2589 || (in_multispace
2590 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002591 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 && ptr - line <= trailcol)))
2593 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002594 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2595 {
2596 c = wp->w_lcs_chars.multispace[multispace_pos++];
2597 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2598 multispace_pos = 0;
2599 }
2600 else
2601 c = (c == ' ') ? wp->w_lcs_chars.space
2602 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 if (area_attr == 0 && search_attr == 0)
2604 {
2605 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002606 extra_attr = hl_combine_attr(wlv.win_attr,
2607 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002608 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 }
2610 mb_c = c;
2611 if (enc_utf8 && utf_char2len(c) > 1)
2612 {
2613 mb_utf8 = TRUE;
2614 u8cc[0] = 0;
2615 c = 0xc0;
2616 }
2617 else
2618 mb_utf8 = FALSE;
2619 }
2620
zeertzjq2e7cba32022-06-10 15:30:32 +01002621 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2622 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002624 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2625 && wp->w_lcs_chars.leadmultispace != NULL)
2626 {
2627 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002628 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2629 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002630 multispace_pos = 0;
2631 }
2632
2633 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2634 c = wp->w_lcs_chars.trail;
2635
2636 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2637 c = wp->w_lcs_chars.lead;
2638
zeertzjq2e7cba32022-06-10 15:30:32 +01002639 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002640 c = wp->w_lcs_chars.space;
2641
2642
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 if (!attr_pri)
2644 {
2645 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002646 extra_attr = hl_combine_attr(wlv.win_attr,
2647 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 }
2650 mb_c = c;
2651 if (enc_utf8 && utf_char2len(c) > 1)
2652 {
2653 mb_utf8 = TRUE;
2654 u8cc[0] = 0;
2655 c = 0xc0;
2656 }
2657 else
2658 mb_utf8 = FALSE;
2659 }
2660 }
2661
2662 // Handling of non-printable characters.
2663 if (!vim_isprintc(c))
2664 {
2665 // when getting a character from the file, we may have to
2666 // turn it into something else on the way to putting it
2667 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002668 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 {
2670 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002671 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002673 char_u *sbr = get_showbreak_value(wp);
2674
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 // only adjust the tab_len, when at the first column
2676 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002677 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2678 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002679#endif
2680 // tab amount depends on current column
2681#ifdef FEAT_VARTABS
2682 tab_len = tabstop_padding(vcol_adjusted,
2683 wp->w_buffer->b_p_ts,
2684 wp->w_buffer->b_p_vts_array) - 1;
2685#else
2686 tab_len = (int)wp->w_buffer->b_p_ts
2687 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2688#endif
2689
2690#ifdef FEAT_LINEBREAK
2691 if (!wp->w_p_lbr || !wp->w_p_list)
2692#endif
2693 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002694 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695#ifdef FEAT_LINEBREAK
2696 else
2697 {
2698 char_u *p;
2699 int len;
2700 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002701 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002703# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002704 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002706 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002707
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002709 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 && old_boguscols > 0
2711 && wlv.n_extra > tab_len)
2712 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002713# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002714 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002716 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002717 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002718 if (wp->w_lcs_chars.tab3)
2719 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002720 if (wlv.n_extra > 0)
2721 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002722 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002724 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002725 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002726 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002728 vim_memset(p, ' ', len);
2729 p[len] = NUL;
2730 vim_free(p_extra_free);
2731 p_extra_free = p;
2732 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002734 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002736 if (*p == NUL)
2737 {
2738 tab_len = i;
2739 break;
2740 }
2741
2742 // if tab3 is given, use it for the last char
2743 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2744 lcs = wp->w_lcs_chars.tab3;
2745 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002748 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002749 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002750# ifdef FEAT_CONCEAL
2751 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2752 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002753 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002754 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002755# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757 }
2758#endif
2759#ifdef FEAT_CONCEAL
2760 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002761 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762
2763 // Tab alignment should be identical regardless of
2764 // 'conceallevel' value. So tab compensates of all
2765 // previous concealed characters, and thus resets
2766 // vcol_off and boguscols accumulated so far in the
2767 // line. Note that the tab can be longer than
2768 // 'tabstop' when there are concealed characters.
2769 FIX_FOR_BOGUSCOLS;
2770
2771 // Make sure, the highlighting for the tab char will be
2772 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002773 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002774 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002775 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 tab_len += vc_saved;
2777 }
2778#endif
2779 mb_utf8 = FALSE; // don't draw as UTF-8
2780 if (wp->w_p_list)
2781 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002782 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002783 ? wp->w_lcs_chars.tab3
2784 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785#ifdef FEAT_LINEBREAK
2786 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 else
2789#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002790 wlv.c_extra = wp->w_lcs_chars.tab2;
2791 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002793 extra_attr = hl_combine_attr(wlv.win_attr,
2794 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002795 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796 mb_c = c;
2797 if (enc_utf8 && utf_char2len(c) > 1)
2798 {
2799 mb_utf8 = TRUE;
2800 u8cc[0] = 0;
2801 c = 0xc0;
2802 }
2803 }
2804 else
2805 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002806 wlv.c_final = NUL;
2807 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 c = ' ';
2809 }
2810 }
2811 else if (c == NUL
2812 && (wp->w_p_list
2813 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002814 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 && VIsual_mode != Ctrl_V
2816 && (
2817# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002820 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 && !(noinvcur
2822 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002823 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 && lcs_eol_one > 0)
2825 {
2826 // Display a '$' after the line or highlight an extra
2827 // character if the line break is included.
2828#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2829 // For a diff line the highlighting continues after the
2830 // "$".
2831 if (
2832# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002833 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834# ifdef LINE_ATTR
2835 &&
2836# endif
2837# endif
2838# ifdef LINE_ATTR
2839 line_attr == 0
2840# endif
2841 )
2842#endif
2843 {
2844 // In virtualedit, visual selections may extend
2845 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002846 if (!(area_highlighting && virtual_active()
2847 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002848 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002849 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002851 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2852 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 else
2854 c = ' ';
2855 lcs_eol_one = -1;
2856 --ptr; // put it back at the NUL
2857 if (!attr_pri)
2858 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002859 extra_attr = hl_combine_attr(wlv.win_attr,
2860 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 n_attr = 1;
2862 }
2863 mb_c = c;
2864 if (enc_utf8 && utf_char2len(c) > 1)
2865 {
2866 mb_utf8 = TRUE;
2867 u8cc[0] = 0;
2868 c = 0xc0;
2869 }
2870 else
2871 mb_utf8 = FALSE; // don't draw as UTF-8
2872 }
2873 else if (c != NUL)
2874 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2876 if (wlv.n_extra == 0)
2877 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878#ifdef FEAT_RIGHTLEFT
2879 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002880 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002882 wlv.c_extra = NUL;
2883 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884#ifdef FEAT_LINEBREAK
2885 if (wp->w_p_lbr)
2886 {
2887 char_u *p;
2888
Bram Moolenaar1306b362022-08-06 15:59:06 +01002889 c = *wlv.p_extra;
2890 p = alloc(wlv.n_extra + 1);
2891 vim_memset(p, ' ', wlv.n_extra);
2892 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2893 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002895 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 }
2897 else
2898#endif
2899 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002900 wlv.n_extra = byte2cells(c) - 1;
2901 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 }
2903 if (!attr_pri)
2904 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002905 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002906 extra_attr = hl_combine_attr(wlv.win_attr,
2907 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002908 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 }
2910 mb_utf8 = FALSE; // don't draw as UTF-8
2911 }
2912 else if (VIsual_active
2913 && (VIsual_mode == Ctrl_V
2914 || VIsual_mode == 'v')
2915 && virtual_active()
2916 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002917 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918 && (
2919#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002922 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 {
2924 c = ' ';
2925 --ptr; // put it back at the NUL
2926 }
2927#if defined(LINE_ATTR)
2928 else if ((
2929# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002930 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931# endif
2932# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002933 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934# endif
2935 line_attr != 0
2936 ) && (
2937# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002938 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002940 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002942 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943# endif
2944 < wp->w_width)))
2945 {
2946 // Highlight until the right side of the window
2947 c = ' ';
2948 --ptr; // put it back at the NUL
2949
2950 // Remember we do the char for line highlighting.
2951 ++did_line_attr;
2952
2953 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002954 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002956 || (wp->w_p_list &&
2957 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002958 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 wlv.diff_hlf = HLF_CHD;
2963 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2967 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002969 || (wlv.vcol >= left_curline_col
2970 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 wlv.char_attr = hl_combine_attr(
2972 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002973 }
2974 }
2975# endif
2976# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002977 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002979 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002980 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2981 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 if (!wlv.cul_screenline
2984 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002985 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 wlv.char_attr = hl_combine_attr(
2987 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 }
2989 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002990 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2991 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992 }
2993# endif
2994 }
2995#endif
2996 }
2997
2998#ifdef FEAT_CONCEAL
2999 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003000 && (wp != curwin || lnum != wp->w_cursor.lnum
3001 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3003 && !(lnum_in_visual_area
3004 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3005 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003006 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003007 if (((prev_syntax_id != syntax_seqnr
3008 && (syntax_flags & HL_CONCEAL) != 0)
3009 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003010 && (syn_get_sub_char() != NUL
3011 || (has_match_conc && match_conc)
3012 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013 && wp->w_p_cole != 3)
3014 {
3015 // First time at this concealed item: display one
3016 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003017 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 c = match_conc;
3019 else if (syn_get_sub_char() != NUL)
3020 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003021 else if (wp->w_lcs_chars.conceal != NUL)
3022 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 else
3024 c = ' ';
3025
3026 prev_syntax_id = syntax_seqnr;
3027
Bram Moolenaar1306b362022-08-06 15:59:06 +01003028 if (wlv.n_extra > 0)
3029 wlv.vcol_off += wlv.n_extra;
3030 wlv.vcol += wlv.n_extra;
3031 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 {
3033# ifdef FEAT_RIGHTLEFT
3034 if (wp->w_p_rl)
3035 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003036 wlv.col -= wlv.n_extra;
3037 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 }
3039 else
3040# endif
3041 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003042 wlv.boguscols += wlv.n_extra;
3043 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044 }
3045 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 n_attr = 0;
3048 }
3049 else if (n_skip == 0)
3050 {
3051 is_concealing = TRUE;
3052 n_skip = 1;
3053 }
3054 mb_c = c;
3055 if (enc_utf8 && utf_char2len(c) > 1)
3056 {
3057 mb_utf8 = TRUE;
3058 u8cc[0] = 0;
3059 c = 0xc0;
3060 }
3061 else
3062 mb_utf8 = FALSE; // don't draw as UTF-8
3063 }
3064 else
3065 {
3066 prev_syntax_id = 0;
3067 is_concealing = FALSE;
3068 }
3069
3070 if (n_skip > 0 && did_decrement_ptr)
3071 // not showing the '>', put pointer back to avoid getting stuck
3072 ++ptr;
3073
3074#endif // FEAT_CONCEAL
3075 }
3076
3077#ifdef FEAT_CONCEAL
3078 // In the cursor line and we may be concealing characters: correct
3079 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003080 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 && wp == curwin && lnum == wp->w_cursor.lnum
3082 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003083 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003085# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003087 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003089# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003090 wp->w_wcol = wlv.col - wlv.boguscols;
3091 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 did_wcol = TRUE;
3093 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003094# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003095 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003096# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 }
3098#endif
3099
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003100 // Use "extra_attr", but don't override visual selection highlighting,
3101 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003102 // Don't use "extra_attr" until n_attr_skip is zero.
3103 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003104 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003105 && (!attr_pri
3106#ifdef FEAT_PROP_POPUP
3107 || (text_prop_flags & PT_FLAG_OVERRIDE)
3108#endif
3109 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 {
3111#ifdef LINE_ATTR
3112 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003113 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 else
3115#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003116 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 }
3118
3119#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3120 // XIM don't send preedit_start and preedit_end, but they send
3121 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3122 // im_is_preediting() here.
3123 if (p_imst == IM_ON_THE_SPOT
3124 && xic != NULL
3125 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003126 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 && !p_imdisable
3128 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003129 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 {
3131 colnr_T tcol;
3132
3133 if (preedit_end_col == MAXCOL)
3134 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3135 else
3136 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003137 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 {
3139 if (feedback_old_attr < 0)
3140 {
3141 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003142 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 wlv.char_attr = im_get_feedback_attr(feedback_col);
3145 if (wlv.char_attr < 0)
3146 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 feedback_col++;
3148 }
3149 else if (feedback_old_attr >= 0)
3150 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003151 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 feedback_old_attr = -1;
3153 feedback_col = 0;
3154 }
3155 }
3156#endif
3157 // Handle the case where we are in column 0 but not on the first
3158 // character of the line and the user wants us to show us a
3159 // special character (via 'listchars' option "precedes:<char>".
3160 if (lcs_prec_todo != NUL
3161 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003162 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003163 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003164 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165#ifdef FEAT_DIFF
3166 && filler_todo <= 0
3167#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003168 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 && c != NUL)
3170 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003171 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 lcs_prec_todo = NUL;
3173 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3174 {
3175 // Double-width character being overwritten by the "precedes"
3176 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003177 wlv.c_extra = MB_FILLER_CHAR;
3178 wlv.c_final = NUL;
3179 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003181 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 }
3183 mb_c = c;
3184 if (enc_utf8 && utf_char2len(c) > 1)
3185 {
3186 mb_utf8 = TRUE;
3187 u8cc[0] = 0;
3188 c = 0xc0;
3189 }
3190 else
3191 mb_utf8 = FALSE; // don't draw as UTF-8
3192 if (!attr_pri)
3193 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003194 saved_attr3 = wlv.char_attr; // save current attr
3195 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 n_attr3 = 1;
3197 }
3198 }
3199
3200 // At end of the text line or just after the last character.
3201 if ((c == NUL
3202#if defined(LINE_ATTR)
3203 || did_line_attr == 1
3204#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003205 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 {
3207#ifdef FEAT_SEARCH_EXTRA
3208 // flag to indicate whether prevcol equals startcol of search_hl or
3209 // one of the matches
3210 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3211 (long)(ptr - line) - (c == NUL));
3212#endif
3213 // Invert at least one char, used for Visual and empty line or
3214 // highlight match at end of line. If it's beyond the last
3215 // char on the screen, just overwrite that one (tricky!) Not
3216 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003217 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003218 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 && (VIsual_mode != Ctrl_V
3220 || lnum == VIsual.lnum
3221 || lnum == curwin->w_cursor.lnum)
3222 && c == NUL)
3223#ifdef FEAT_SEARCH_EXTRA
3224 // highlight 'hlsearch' match at end of line
3225 || (prevcol_hl_flag
3226# ifdef FEAT_SYN_HL
3227 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3228 && !(wp == curwin && VIsual_active))
3229# endif
3230# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003231 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232# endif
3233# if defined(LINE_ATTR)
3234 && did_line_attr <= 1
3235# endif
3236 )
3237#endif
3238 ))
3239 {
3240 int n = 0;
3241
3242#ifdef FEAT_RIGHTLEFT
3243 if (wp->w_p_rl)
3244 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003245 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 n = 1;
3247 }
3248 else
3249#endif
3250 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 n = -1;
3253 }
3254 if (n != 0)
3255 {
3256 // At the window boundary, highlight the last character
3257 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 wlv.off += n;
3259 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 }
3261 else
3262 {
3263 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 }
3268#ifdef FEAT_SEARCH_EXTRA
3269 if (area_attr == 0)
3270 {
3271 // Use attributes from match with highest priority among
3272 // 'search_hl' and the match list.
3273 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 }
3276#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003277 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003278 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279#ifdef FEAT_RIGHTLEFT
3280 if (wp->w_p_rl)
3281 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 --wlv.col;
3283 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 }
3285 else
3286#endif
3287 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 ++wlv.col;
3289 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 ++wlv.vcol;
3292 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 }
3294 }
3295
3296 // At end of the text line.
3297 if (c == NUL)
3298 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300
3301 // Update w_cline_height and w_cline_folded if the cursor line was
3302 // updated (saves a call to plines() later).
3303 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3304 {
3305 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307#ifdef FEAT_FOLDING
3308 curwin->w_cline_folded = FALSE;
3309#endif
3310 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3311 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 break;
3313 }
3314
3315 // Show "extends" character from 'listchars' if beyond the line end and
3316 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003317 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319 && wp->w_p_list
3320 && !wp->w_p_wrap
3321#ifdef FEAT_DIFF
3322 && filler_todo <= 0
3323#endif
3324 && (
3325#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003326 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003328 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003330 || lcs_eol_one > 0
3331 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003332 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003334 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003335 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 mb_c = c;
3337 if (enc_utf8 && utf_char2len(c) > 1)
3338 {
3339 mb_utf8 = TRUE;
3340 u8cc[0] = 0;
3341 c = 0xc0;
3342 }
3343 else
3344 mb_utf8 = FALSE;
3345 }
3346
3347#ifdef FEAT_SYN_HL
3348 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003349 if (wlv.draw_color_col)
3350 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351
3352 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3353 // highlight the cursor position itself.
3354 // Also highlight the 'colorcolumn' if it is different than
3355 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003356 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3357 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 if (((wlv.draw_state == WL_LINE
3360 || wlv.draw_state == WL_BRI
3361 || wlv.draw_state == WL_SBR)
3362 && !lnum_in_visual_area
3363 && search_attr == 0
3364 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003365# ifdef FEAT_DIFF
3366 && filler_todo <= 0
3367# endif
3368 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 {
3370 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3371 && lnum != wp->w_cursor.lnum)
3372 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003373 vcol_save_attr = wlv.char_attr;
3374 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3375 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003379 vcol_save_attr = wlv.char_attr;
3380 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381 }
3382 }
3383#endif
3384
3385 // Store character to be displayed.
3386 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003387 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003388 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 {
3390 // Store the character.
3391#if defined(FEAT_RIGHTLEFT)
3392 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3393 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003394 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003395 --wlv.off;
3396 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 }
3398#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003399 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400 if (enc_dbcs == DBCS_JPNU)
3401 {
3402 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003403 ScreenLines[wlv.off] = 0x8e;
3404 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 }
3406 else if (enc_utf8)
3407 {
3408 if (mb_utf8)
3409 {
3410 int i;
3411
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003414 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 for (i = 0; i < Screen_mco; ++i)
3416 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003417 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 if (u8cc[i] == 0)
3419 break;
3420 }
3421 }
3422 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 }
3425 if (multi_attr)
3426 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 multi_attr = 0;
3429 }
3430 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003431 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003434
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3436 {
3437 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003438 ++wlv.off;
3439 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 if (enc_utf8)
3441 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003442 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 else
3444 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003445 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003446 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447#ifdef FEAT_DIFF
3448 && filler_todo <= 0
3449#endif
3450 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 // When "tocol" is halfway a character, set it to the end of
3453 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003454 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003456
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003458
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459#ifdef FEAT_RIGHTLEFT
3460 if (wp->w_p_rl)
3461 {
3462 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 --wlv.off;
3464 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 }
3466#endif
3467 }
3468#ifdef FEAT_RIGHTLEFT
3469 if (wp->w_p_rl)
3470 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 --wlv.off;
3472 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 }
3474 else
3475#endif
3476 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ++wlv.off;
3478 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 }
3480 }
3481#ifdef FEAT_CONCEAL
3482 else if (wp->w_p_cole > 0 && is_concealing)
3483 {
3484 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003485 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003486 if (wlv.n_extra > 0)
3487 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 if (wp->w_p_wrap)
3489 {
3490 // Special voodoo required if 'wrap' is on.
3491 //
3492 // Advance the column indicator to force the line
3493 // drawing to wrap early. This will make the line
3494 // take up the same screen space when parts are concealed,
3495 // so that cursor line computations aren't messed up.
3496 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003497 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 // trailing junk to be written out of the screen line
3499 // we are building, 'boguscols' keeps track of the number
3500 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003501 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003503 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504# ifdef FEAT_RIGHTLEFT
3505 if (wp->w_p_rl)
3506 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003507 wlv.col -= wlv.n_extra;
3508 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 }
3510 else
3511# endif
3512 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003513 wlv.col += wlv.n_extra;
3514 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003516 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 n_attr = 0;
3518 }
3519
3520
3521 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3522 {
3523 // Need to fill two screen columns.
3524# ifdef FEAT_RIGHTLEFT
3525 if (wp->w_p_rl)
3526 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003527 --wlv.boguscols;
3528 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 }
3530 else
3531# endif
3532 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003533 ++wlv.boguscols;
3534 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 }
3536 }
3537
3538# ifdef FEAT_RIGHTLEFT
3539 if (wp->w_p_rl)
3540 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003541 --wlv.boguscols;
3542 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543 }
3544 else
3545# endif
3546 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003547 ++wlv.boguscols;
3548 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 }
3550 }
3551 else
3552 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003555 wlv.vcol += wlv.n_extra;
3556 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 n_attr = 0;
3558 }
3559 }
3560
3561 }
3562#endif // FEAT_CONCEAL
3563 else
3564 --n_skip;
3565
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003566 // Only advance the "wlv.vcol" when after the 'number' or
3567 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003568 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569#ifdef FEAT_DIFF
3570 && filler_todo <= 0
3571#endif
3572 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574
3575#ifdef FEAT_SYN_HL
3576 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003577 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578#endif
3579
3580 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003581 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3582 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583
3584 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003585 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003586 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003587 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003588 if (n_attr_skip > 0)
3589 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590
3591 // At end of screen line and there is more to come: Display the line
3592 // so far. If there is no more to display it is caught above.
3593 if ((
3594#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003595 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003597 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003598 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003599 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600#ifdef FEAT_DIFF
3601 || filler_todo > 0
3602#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003603#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003604 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003605#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003606 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003607 && wlv.p_extra != at_end_str)
3608 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3609 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003610 )
3611 {
3612#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 screen_line(wp, wlv.screen_row, wp->w_wincol,
3614 wlv.col - wlv.boguscols,
3615 wp->w_width, wlv.screen_line_flags);
3616 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3619 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003621 ++wlv.row;
3622 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623
3624 // When not wrapping and finished diff lines, or when displayed
3625 // '$' and highlighting until last column, break here.
3626 if ((!wp->w_p_wrap
3627#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003628 && filler_todo <= 0
3629#endif
3630#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003631 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632#endif
3633 ) || lcs_eol_one == -1)
3634 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003635#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003636 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003637 {
3638 // do not output more of the line, only the "below" prop
3639 ptr += STRLEN(ptr);
3640# ifdef FEAT_LINEBREAK
3641 dont_use_showbreak = TRUE;
3642# endif
3643 }
3644#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645
3646 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648#ifdef FEAT_DIFF
3649 && filler_todo <= 0
3650#endif
3651 )
3652 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3654 draw_vsep_win(wp, wlv.row);
3655 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 }
3657
3658 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003661 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 break;
3663 }
3664
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003665 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666#ifdef FEAT_DIFF
3667 && filler_todo <= 0
3668#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003669#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003670 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003671#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 && wp->w_width == Columns)
3673 {
3674 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676
3677 // Special trick to make copy/paste of wrapped lines work with
3678 // xterm/screen: write an extra character beyond the end of
3679 // the line. This will work with all terminal types
3680 // (regardless of the xn,am settings).
3681 // Only do this on a fast tty.
3682 // Only do this if the cursor is on the current line
3683 // (something has been written in it).
3684 // Don't do this for the GUI.
3685 // Don't do this for double-width characters.
3686 // Don't do this for a window not at the right screen border.
3687 if (p_tf
3688#ifdef FEAT_GUI
3689 && !gui.in_use
3690#endif
3691 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003692 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3693 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003695 || (*mb_off2cells)(
3696 LineOffset[wlv.screen_row - 1]
3697 + (int)Columns - 2,
3698 LineOffset[wlv.screen_row]
3699 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700 {
3701 // First make sure we are at the end of the screen line,
3702 // then output the same character again to let the
3703 // terminal know about the wrap. If the terminal doesn't
3704 // auto-wrap, we overwrite the character.
3705 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003706 screen_char(LineOffset[wlv.screen_row - 1]
3707 + (unsigned)Columns - 1,
3708 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709
3710 // When there is a multi-byte character, just output a
3711 // space to keep it simple.
3712 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 out_char(' ');
3715 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003716 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 + (Columns - 1)]);
3718 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 screen_start(); // don't know where cursor is now
3721 }
3722 }
3723
Bram Moolenaar1306b362022-08-06 15:59:06 +01003724 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725
Bram Moolenaareed9d462021-02-15 20:38:25 +01003726 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003728 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003730 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003732 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 need_showbreak = TRUE;
3734#endif
3735#ifdef FEAT_DIFF
3736 --filler_todo;
3737 // When the filler lines are actually below the last line of the
3738 // file, don't draw the line itself, break here.
3739 if (filler_todo == 0 && wp->w_botfill)
3740 break;
3741#endif
3742 }
3743
3744 } // for every character in the line
3745
3746#ifdef FEAT_SPELL
3747 // After an empty line check first word for capital.
3748 if (*skipwhite(line) == NUL)
3749 {
3750 capcol_lnum = lnum + 1;
3751 cap_col = 0;
3752 }
3753#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003754#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 vim_free(text_props);
3756 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003757 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758#endif
3759
3760 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003761 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762}