blob: b0980e58c24c39f9e08e5754e5bbe3479a0982c2 [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);
338 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100339 int before = room; // spaces before the text
340 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100341 int n_used = *n_extra;
342 char_u *l = NULL;
343 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100344 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
345 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100347 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100348 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100349 int col_off = win_col_off(wp) + win_col_off2(wp);
350 int skip_add = 0;
351
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100352 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100353 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100354 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100355 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100356 }
357 else
358 {
359 // Right-align: fill with before
360 if (right)
361 before -= cells;
362 if (before < 0
363 || !(right || below)
364 || (below
365 ? (col_with_padding == 0 || !wp->w_p_wrap)
366 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100367 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100368 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
369 {
370 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100371 before = wp->w_width - col_off - strsize + room;
372 if (before < 0)
373 before = 0;
374 else
375 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100376 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100377 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100378 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100379 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100380 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100381 else if (below && before > 0)
382 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100383 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100384 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100385
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100386 // With 'nowrap' add one to show the "extends" character if needed (it
387 // doesn't show if the text just fits).
388 if (!wp->w_p_wrap
389 && n_used < *n_extra
390 && wp->w_lcs_chars.ext != NUL
391 && wp->w_p_list)
392 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100393 if (!wp->w_p_wrap && below && padding > 0)
394 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100395
396 // add 1 for NUL, 2 for when '…' is used
397 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100398 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100399 if (n_attr == NULL || l != NULL)
400 {
401 int off = 0;
402
403 if (n_attr != NULL)
404 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100405 vim_memset(l, ' ', before);
406 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100407 if (padding > 0)
408 {
409 vim_memset(l + off, ' ', padding);
410 off += padding;
411 }
412 vim_strncpy(l + off, *p_extra, n_used);
413 off += n_used;
414 }
415 else
416 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100417 off = before + after + padding + n_used;
418 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100419 }
420 if (n_attr != NULL)
421 {
422 if (n_used < *n_extra && wp->w_p_wrap)
423 {
424 char_u *lp = l + off - 1;
425
426 if (has_mbyte)
427 {
428 // change last character to '…'
429 lp -= (*mb_head_off)(l, lp);
430 STRCPY(lp, "…");
431 n_used = lp - l + 3 - padding;
432 }
433 else
434 // change last character to '>'
435 *lp = '>';
436 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100437 else if (after > 0)
438 {
439 vim_memset(l + off, ' ', after);
440 l[off + after] = NUL;
441 }
442
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100443 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100444 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100445 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100446 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100447 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100448 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100449 }
450 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100451 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100452
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100453 if (n_attr == NULL)
454 return cells;
455 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200456}
457#endif
458
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100459/*
460 * Called when finished with the line: draw the screen line and handle any
461 * highlighting until the right of the window.
462 */
463 static void
464draw_screen_line(win_T *wp, winlinevars_T *wlv)
465{
466#ifdef FEAT_SYN_HL
467 long v;
468
469 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
470 if (wp->w_p_wrap)
471 v = wp->w_skipcol;
472 else
473 v = wp->w_leftcol;
474
475 // check if line ends before left margin
476 if (wlv->vcol < v + wlv->col - win_col_off(wp))
477 wlv->vcol = v + wlv->col - win_col_off(wp);
478# ifdef FEAT_CONCEAL
479 // Get rid of the boguscols now, we want to draw until the right
480 // edge for 'cursorcolumn'.
481 wlv->col -= wlv->boguscols;
482 wlv->boguscols = 0;
483# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
484# else
485# define VCOL_HLC (wlv->vcol)
486# endif
487
488 if (wlv->draw_color_col)
489 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
490
491 if (((wp->w_p_cuc
492 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
493 && (int)wp->w_virtcol <
494 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
495 && wlv->lnum != wp->w_cursor.lnum)
496 || wlv->draw_color_col
497 || wlv->win_attr != 0)
498# ifdef FEAT_RIGHTLEFT
499 && !wp->w_p_rl
500# endif
501 )
502 {
503 int rightmost_vcol = 0;
504 int i;
505
506 if (wp->w_p_cuc)
507 rightmost_vcol = wp->w_virtcol;
508 if (wlv->draw_color_col)
509 // determine rightmost colorcolumn to possibly draw
510 for (i = 0; wlv->color_cols[i] >= 0; ++i)
511 if (rightmost_vcol < wlv->color_cols[i])
512 rightmost_vcol = wlv->color_cols[i];
513
514 while (wlv->col < wp->w_width)
515 {
516 ScreenLines[wlv->off] = ' ';
517 if (enc_utf8)
518 ScreenLinesUC[wlv->off] = 0;
519 ScreenCols[wlv->off] = MAXCOL;
520 ++wlv->col;
521 if (wlv->draw_color_col)
522 wlv->draw_color_col = advance_color_col(
523 VCOL_HLC, &wlv->color_cols);
524
525 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
526 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
527 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
528 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
529 else
530 ScreenAttrs[wlv->off++] = wlv->win_attr;
531
532 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
533 break;
534
535 ++wlv->vcol;
536 }
537 }
538#endif
539
540 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
541 wp->w_width, wlv->screen_line_flags);
542 ++wlv->row;
543 ++wlv->screen_row;
544}
545#undef VCOL_HLC
546
547/*
548 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100549 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100550 */
551 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100552win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100553{
554 wlv->col = 0;
555 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
556
557#ifdef FEAT_RIGHTLEFT
558 if (wp->w_p_rl)
559 {
560 // Rightleft window: process the text in the normal direction, but put
561 // it in current_ScreenLine[] from right to left. Start at the
562 // rightmost column of the window.
563 wlv->col = wp->w_width - 1;
564 wlv->off += wlv->col;
565 wlv->screen_line_flags |= SLF_RIGHTLEFT;
566 }
567#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100568 if (save_extra)
569 {
570 // reset the drawing state for the start of a wrapped line
571 wlv->draw_state = WL_START;
572 wlv->saved_n_extra = wlv->n_extra;
573 wlv->saved_p_extra = wlv->p_extra;
574 wlv->saved_c_extra = wlv->c_extra;
575 wlv->saved_c_final = wlv->c_final;
576#ifdef FEAT_SYN_HL
577 if (!(wlv->cul_screenline
578# ifdef FEAT_DIFF
579 && wlv->diff_hlf == (hlf_T)0
580# endif
581 ))
582 wlv->saved_char_attr = wlv->char_attr;
583 else
584#endif
585 wlv->saved_char_attr = 0;
586 wlv->n_extra = 0;
587 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100588}
589
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200590/*
591 * Display line "lnum" of window 'wp' on the screen.
592 * Start at row "startrow", stop when "endrow" is reached.
593 * wp->w_virtcol needs to be valid.
594 *
595 * Return the number of last row the line occupies.
596 */
597 int
598win_line(
599 win_T *wp,
600 linenr_T lnum,
601 int startrow,
602 int endrow,
603 int nochange UNUSED, // not updating for changed text
604 int number_only) // only update the number column
605{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100606 winlinevars_T wlv; // variables passed between functions
607
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200608 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200609#ifdef FEAT_LINEBREAK
610 long vcol_sbr = -1; // virtual column after showbreak
611#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100612 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200613 char_u *line; // current line
614 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200615
616 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100618#ifdef FEAT_PROP_POPUP
619 char_u *p_extra_free2 = NULL; // another p_extra to be freed
620#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000622#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000623 int in_linebreak = FALSE; // n_extra set for showing linebreak
624#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200625 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100626 // displaying eol at end-of-line
627 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000628 int lcs_prec_todo = wp->w_lcs_chars.prec;
629 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100631 int n_attr = 0; // chars with special attr
632 int n_attr_skip = 0; // chars to skip before using extra_attr
633 int saved_attr2 = 0; // char_attr saved for n_attr
634 int n_attr3 = 0; // chars with overruling special attr
635 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200636
637 int n_skip = 0; // nr of chars to skip for 'nowrap'
638
639 int fromcol = -10; // start of inverting
640 int tocol = MAXCOL; // end of inverting
641 int fromcol_prev = -2; // start of inverting after cursor
642 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643 int lnum_in_visual_area = FALSE;
644 pos_T pos;
645 long v;
646
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200647 int attr_pri = FALSE; // char_attr has priority
648 int area_highlighting = FALSE; // Visual or incsearch highlighting
649 // in this line
650 int vi_attr = 0; // attributes for Visual and incsearch
651 // highlighting
652 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200653 int area_attr = 0; // attributes desired by highlighting
654 int search_attr = 0; // attributes desired by 'hlsearch'
655#ifdef FEAT_SYN_HL
656 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
657 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200658 int prev_syntax_col = -1; // column of prev_syntax_attr
659 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200660 int has_syntax = FALSE; // this buffer has syntax highl.
661 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200662#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100663#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200664 int text_prop_count;
665 int text_prop_next = 0; // next text property to use
666 textprop_T *text_props = NULL;
667 int *text_prop_idxs = NULL;
668 int text_props_active = 0;
669 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100670 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200671 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100672 int text_prop_attr_comb = 0; // text_prop_attr combined with
673 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100674 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100675 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100676 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100677 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100678 int saved_search_attr = 0; // search_attr to be used when n_extra
679 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100680 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200681#endif
682#ifdef FEAT_SPELL
683 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000684 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200685# define SPWORDLEN 150
686 char_u nextline[SPWORDLEN * 2];// text with start of the next line
687 int nextlinecol = 0; // column where nextline[] starts
688 int nextline_idx = 0; // index in nextline[] where next line
689 // starts
690 int spell_attr = 0; // attributes desired by spelling
691 int word_end = 0; // last byte with same spell_attr
692 static linenr_T checked_lnum = 0; // line number for "checked_col"
693 static int checked_col = 0; // column in "checked_lnum" up to which
694 // there are no spell errors
695 static int cap_col = -1; // column to check for Cap word
696 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
697 int cur_checked_col = 0; // checked column for current line
698#endif
699 int extra_check = 0; // has extra highlighting
700 int multi_attr = 0; // attributes desired by multibyte
701 int mb_l = 1; // multi-byte byte length
702 int mb_c = 0; // decoded multi-byte character
703 int mb_utf8 = FALSE; // screen char is UTF-8 char
704 int u8cc[MAX_MCO]; // composing UTF-8 chars
705#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
706 int filler_lines = 0; // nr of filler lines to be drawn
707 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000708#else
709# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200710#endif
711#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200712 int change_start = MAXCOL; // first col of changed area
713 int change_end = -1; // last col of changed area
714#endif
715 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100716 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200717 int in_multispace = FALSE; // in multiple consecutive spaces
718 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200719#ifdef FEAT_LINEBREAK
720 int need_showbreak = FALSE; // overlong line, skipping first x
721 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100722 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200723#endif
724#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
725 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
726# define LINE_ATTR
727 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100728 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200729#endif
730#ifdef FEAT_SIGNS
731 int sign_present = FALSE;
732 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000733 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200734#endif
735#ifdef FEAT_ARABIC
736 int prev_c = 0; // previous Arabic character
737 int prev_c1 = 0; // first composing char for prev_c
738#endif
739#if defined(LINE_ATTR)
740 int did_line_attr = 0;
741#endif
742#ifdef FEAT_TERMINAL
743 int get_term_attr = FALSE;
744#endif
745#ifdef FEAT_SYN_HL
746 int cul_attr = 0; // set when 'cursorline' active
747
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200748 // margin columns for the screen line, needed for when 'cursorlineopt'
749 // contains "screenline"
750 int left_curline_col = 0;
751 int right_curline_col = 0;
752#endif
753
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200754#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
755 int feedback_col = 0;
756 int feedback_old_attr = -1;
757#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200758
759#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
760 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000761 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200762#endif
763#ifdef FEAT_CONCEAL
764 int syntax_flags = 0;
765 int syntax_seqnr = 0;
766 int prev_syntax_id = 0;
767 int conceal_attr = HL_ATTR(HLF_CONCEAL);
768 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200769 int did_wcol = FALSE;
770 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100771# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772# define FIX_FOR_BOGUSCOLS \
773 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100774 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100775 wlv.vcol -= wlv.vcol_off; \
776 wlv.vcol_off = 0; \
777 wlv.col -= wlv.boguscols; \
778 old_boguscols = wlv.boguscols; \
779 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200780 }
781#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100782# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200783#endif
784
785 if (startrow > endrow) // past the end already!
786 return startrow;
787
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100788 CLEAR_FIELD(wlv);
789
790 wlv.lnum = lnum;
791 wlv.startrow = startrow;
792 wlv.row = startrow;
793 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200794
795 if (!number_only)
796 {
797 // To speed up the loop below, set extra_check when there is linebreak,
798 // trailing white space and/or syntax processing to be done.
799#ifdef FEAT_LINEBREAK
800 extra_check = wp->w_p_lbr;
801#endif
802#ifdef FEAT_SYN_HL
803 if (syntax_present(wp) && !wp->w_s->b_syn_error
804# ifdef SYN_TIME_LIMIT
805 && !wp->w_s->b_syn_slow
806# endif
807 )
808 {
809 // Prepare for syntax highlighting in this line. When there is an
810 // error, stop syntax highlighting.
811 save_did_emsg = did_emsg;
812 did_emsg = FALSE;
813 syntax_start(wp, lnum);
814 if (did_emsg)
815 wp->w_s->b_syn_error = TRUE;
816 else
817 {
818 did_emsg = save_did_emsg;
819#ifdef SYN_TIME_LIMIT
820 if (!wp->w_s->b_syn_slow)
821#endif
822 {
823 has_syntax = TRUE;
824 extra_check = TRUE;
825 }
826 }
827 }
828
829 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100830 wlv.color_cols = wp->w_p_cc_cols;
831 if (wlv.color_cols != NULL)
832 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200833#endif
834
835#ifdef FEAT_TERMINAL
836 if (term_show_buffer(wp->w_buffer))
837 {
838 extra_check = TRUE;
839 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100840 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200841 }
842#endif
843
844#ifdef FEAT_SPELL
845 if (wp->w_p_spell
846 && *wp->w_s->b_p_spl != NUL
847 && wp->w_s->b_langp.ga_len > 0
848 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
849 {
850 // Prepare for spell checking.
851 has_spell = TRUE;
852 extra_check = TRUE;
853
854 // Get the start of the next line, so that words that wrap to the
855 // next line are found too: "et<line-break>al.".
856 // Trick: skip a few chars for C/shell/Vim comments
857 nextline[SPWORDLEN] = NUL;
858 if (lnum < wp->w_buffer->b_ml.ml_line_count)
859 {
860 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
861 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
862 }
863
864 // When a word wrapped from the previous line the start of the
865 // current line is valid.
866 if (lnum == checked_lnum)
867 cur_checked_col = checked_col;
868 checked_lnum = 0;
869
870 // When there was a sentence end in the previous line may require a
871 // word starting with capital in this line. In line 1 always check
872 // the first word.
873 if (lnum != capcol_lnum)
874 cap_col = -1;
875 if (lnum == 1)
876 cap_col = 0;
877 capcol_lnum = 0;
878 }
879#endif
880
881 // handle Visual active in this window
882 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
883 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100884 pos_T *top, *bot;
885
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200886 if (LTOREQ_POS(curwin->w_cursor, VIsual))
887 {
888 // Visual is after curwin->w_cursor
889 top = &curwin->w_cursor;
890 bot = &VIsual;
891 }
892 else
893 {
894 // Visual is before curwin->w_cursor
895 top = &VIsual;
896 bot = &curwin->w_cursor;
897 }
898 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
899 if (VIsual_mode == Ctrl_V)
900 {
901 // block mode
902 if (lnum_in_visual_area)
903 {
904 fromcol = wp->w_old_cursor_fcol;
905 tocol = wp->w_old_cursor_lcol;
906 }
907 }
908 else
909 {
910 // non-block mode
911 if (lnum > top->lnum && lnum <= bot->lnum)
912 fromcol = 0;
913 else if (lnum == top->lnum)
914 {
915 if (VIsual_mode == 'V') // linewise
916 fromcol = 0;
917 else
918 {
919 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
920 if (gchar_pos(top) == NUL)
921 tocol = fromcol + 1;
922 }
923 }
924 if (VIsual_mode != 'V' && lnum == bot->lnum)
925 {
926 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
927 {
928 fromcol = -10;
929 tocol = MAXCOL;
930 }
931 else if (bot->col == MAXCOL)
932 tocol = MAXCOL;
933 else
934 {
935 pos = *bot;
936 if (*p_sel == 'e')
937 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
938 else
939 {
940 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
941 ++tocol;
942 }
943 }
944 }
945 }
946
947 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200948 if (!highlight_match && lnum == curwin->w_cursor.lnum
949 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200950#ifdef FEAT_GUI
951 && !gui.in_use
952#endif
953 )
954 noinvcur = TRUE;
955
956 // if inverting in this line set area_highlighting
957 if (fromcol >= 0)
958 {
959 area_highlighting = TRUE;
960 vi_attr = HL_ATTR(HLF_V);
961#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
962 if ((clip_star.available && !clip_star.owned
963 && clip_isautosel_star())
964 || (clip_plus.available && !clip_plus.owned
965 && clip_isautosel_plus()))
966 vi_attr = HL_ATTR(HLF_VNC);
967#endif
968 }
969 }
970
971 // handle 'incsearch' and ":s///c" highlighting
972 else if (highlight_match
973 && wp == curwin
974 && lnum >= curwin->w_cursor.lnum
975 && lnum <= curwin->w_cursor.lnum + search_match_lines)
976 {
977 if (lnum == curwin->w_cursor.lnum)
978 getvcol(curwin, &(curwin->w_cursor),
979 (colnr_T *)&fromcol, NULL, NULL);
980 else
981 fromcol = 0;
982 if (lnum == curwin->w_cursor.lnum + search_match_lines)
983 {
984 pos.lnum = lnum;
985 pos.col = search_match_endcol;
986 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
987 }
988 else
989 tocol = MAXCOL;
990 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100991 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200992 tocol = fromcol + 1;
993 area_highlighting = TRUE;
994 vi_attr = HL_ATTR(HLF_I);
995 }
996 }
997
998#ifdef FEAT_DIFF
999 filler_lines = diff_check(wp, lnum);
1000 if (filler_lines < 0)
1001 {
1002 if (filler_lines == -1)
1003 {
1004 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001005 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001007 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001009 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010 }
1011 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001012 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013 filler_lines = 0;
1014 area_highlighting = TRUE;
1015 }
1016 if (lnum == wp->w_topline)
1017 filler_lines = wp->w_topfill;
1018 filler_todo = filler_lines;
1019#endif
1020
1021#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01001022 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +00001023 if (sign_present)
1024 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025#endif
1026
1027#ifdef LINE_ATTR
1028# ifdef FEAT_SIGNS
1029 // If this line has a sign with line highlighting set line_attr.
1030 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001031 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032# endif
1033# if defined(FEAT_QUICKFIX)
1034 // Highlight the current line in the quickfix window.
1035 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1036 line_attr = HL_ATTR(HLF_QFL);
1037# endif
1038 if (line_attr != 0)
1039 area_highlighting = TRUE;
1040#endif
1041
1042 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1043 ptr = line;
1044
1045#ifdef FEAT_SPELL
1046 if (has_spell && !number_only)
1047 {
1048 // For checking first word with a capital skip white space.
1049 if (cap_col == 0)
1050 cap_col = getwhitecols(line);
1051
1052 // To be able to spell-check over line boundaries copy the end of the
1053 // current line into nextline[]. Above the start of the next line was
1054 // copied to nextline[SPWORDLEN].
1055 if (nextline[SPWORDLEN] == NUL)
1056 {
1057 // No next line or it is empty.
1058 nextlinecol = MAXCOL;
1059 nextline_idx = 0;
1060 }
1061 else
1062 {
1063 v = (long)STRLEN(line);
1064 if (v < SPWORDLEN)
1065 {
1066 // Short line, use it completely and append the start of the
1067 // next line.
1068 nextlinecol = 0;
1069 mch_memmove(nextline, line, (size_t)v);
1070 STRMOVE(nextline + v, nextline + SPWORDLEN);
1071 nextline_idx = v + 1;
1072 }
1073 else
1074 {
1075 // Long line, use only the last SPWORDLEN bytes.
1076 nextlinecol = v - SPWORDLEN;
1077 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1078 nextline_idx = SPWORDLEN + 1;
1079 }
1080 }
1081 }
1082#endif
1083
1084 if (wp->w_p_list)
1085 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001086 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001087 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001088 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001089 || wp->w_lcs_chars.trail
1090 || wp->w_lcs_chars.lead
1091 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001093
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001095 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096 {
1097 trailcol = (colnr_T)STRLEN(ptr);
1098 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1099 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001100 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001102 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001103 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001104 {
1105 leadcol = 0;
1106 while (VIM_ISWHITE(ptr[leadcol]))
1107 ++leadcol;
1108 if (ptr[leadcol] == NUL)
1109 // in a line full of spaces all of them are treated as trailing
1110 leadcol = (colnr_T)0;
1111 else
1112 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001113 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001114 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115 }
1116
1117 wcr_attr = get_wcr_attr(wp);
1118 if (wcr_attr != 0)
1119 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001120 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 area_highlighting = TRUE;
1122 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001123
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001124#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001125 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001126 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127#endif
1128
1129 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1130 // first character to be displayed.
1131 if (wp->w_p_wrap)
1132 v = wp->w_skipcol;
1133 else
1134 v = wp->w_leftcol;
1135 if (v > 0 && !number_only)
1136 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001137 char_u *prev_ptr = ptr;
1138 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001139 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001141 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001142 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001144 charsize = win_lbr_chartabsize(&cts, NULL);
1145 cts.cts_vcol += charsize;
1146 prev_ptr = cts.cts_ptr;
1147 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001149 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001150 ptr = cts.cts_ptr;
1151 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001152
1153 // When:
1154 // - 'cuc' is set, or
1155 // - 'colorcolumn' is set, or
1156 // - 'virtualedit' is set, or
1157 // - the visual mode is active,
1158 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001159 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001161 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162#endif
1163 virtual_active() ||
1164 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001165 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166
1167 // Handle a character that's not completely on the screen: Put ptr at
1168 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001169 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001170 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001171 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001172 ptr = prev_ptr;
1173 // If the character fits on the screen, don't need to skip it.
1174 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001175 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1176 && wlv.col == 0)
1177 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178 }
1179
1180 // Adjust for when the inverted text is before the screen,
1181 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001182 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001183 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001184 else if (fromcol >= 0 && fromcol < wlv.vcol)
1185 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186
1187#ifdef FEAT_LINEBREAK
1188 // When w_skipcol is non-zero, first line needs 'showbreak'
1189 if (wp->w_p_wrap)
1190 need_showbreak = TRUE;
1191#endif
1192#ifdef FEAT_SPELL
1193 // When spell checking a word we need to figure out the start of the
1194 // word and if it's badly spelled or not.
1195 if (has_spell)
1196 {
1197 int len;
1198 colnr_T linecol = (colnr_T)(ptr - line);
1199 hlf_T spell_hlf = HLF_COUNT;
1200
1201 pos = wp->w_cursor;
1202 wp->w_cursor.lnum = lnum;
1203 wp->w_cursor.col = linecol;
1204 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1205
1206 // spell_move_to() may call ml_get() and make "line" invalid
1207 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1208 ptr = line + linecol;
1209
1210 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1211 {
1212 // no bad word found at line start, don't check until end of a
1213 // word
1214 spell_hlf = HLF_COUNT;
1215 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1216 }
1217 else
1218 {
1219 // bad word found, use attributes until end of word
1220 word_end = wp->w_cursor.col + len + 1;
1221
1222 // Turn index into actual attributes.
1223 if (spell_hlf != HLF_COUNT)
1224 spell_attr = highlight_attr[spell_hlf];
1225 }
1226 wp->w_cursor = pos;
1227
1228# ifdef FEAT_SYN_HL
1229 // Need to restart syntax highlighting for this line.
1230 if (has_syntax)
1231 syntax_start(wp, lnum);
1232# endif
1233 }
1234#endif
1235 }
1236
1237 // Correct highlighting for cursor that can't be disabled.
1238 // Avoids having to check this for each character.
1239 if (fromcol >= 0)
1240 {
1241 if (noinvcur)
1242 {
1243 if ((colnr_T)fromcol == wp->w_virtcol)
1244 {
1245 // highlighting starts at cursor, let it start just after the
1246 // cursor
1247 fromcol_prev = fromcol;
1248 fromcol = -1;
1249 }
1250 else if ((colnr_T)fromcol < wp->w_virtcol)
1251 // restart highlighting after the cursor
1252 fromcol_prev = wp->w_virtcol;
1253 }
1254 if (fromcol >= tocol)
1255 fromcol = -1;
1256 }
1257
1258#ifdef FEAT_SEARCH_EXTRA
1259 if (!number_only)
1260 {
1261 v = (long)(ptr - line);
1262 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1263 &line, &screen_search_hl,
1264 &search_attr);
1265 ptr = line + v; // "line" may have been updated
1266 }
1267#endif
1268
1269#ifdef FEAT_SYN_HL
1270 // Cursor line highlighting for 'cursorline' in the current window.
1271 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1272 {
1273 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001274 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 if (!(wp == curwin && VIsual_active)
1276 && wp->w_p_culopt_flags != CULOPT_NBR)
1277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001278 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1280
1281 // Only set line_attr here when "screenline" is not present in
1282 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001283 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 {
1285 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001286# ifdef FEAT_SIGNS
1287 // Combine the 'cursorline' and sign highlighting, depending on
1288 // the sign priority.
1289 if (sign_present && sattr.sat_linehl > 0)
1290 {
1291 if (sattr.sat_priority >= 100)
1292 line_attr = hl_combine_attr(cul_attr, line_attr);
1293 else
1294 line_attr = hl_combine_attr(line_attr, cul_attr);
1295 }
1296 else
1297# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001298# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001299 // let the line attribute overrule 'cursorline', otherwise
1300 // it disappears when both have background set;
1301 // 'cursorline' can use underline or bold to make it show
1302 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001303# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001304 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001305# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 }
1307 else
1308 {
1309 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1311 }
1312 area_highlighting = TRUE;
1313 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 }
1315#endif
1316
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001317#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 {
1319 char_u *prop_start;
1320
1321 text_prop_count = get_text_props(wp->w_buffer, lnum,
1322 &prop_start, FALSE);
1323 if (text_prop_count > 0)
1324 {
1325 // Make a copy of the properties, so that they are properly
1326 // aligned.
1327 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1328 if (text_props != NULL)
1329 mch_memmove(text_props, prop_start,
1330 text_prop_count * sizeof(textprop_T));
1331
1332 // Allocate an array for the indexes.
1333 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001334 if (text_prop_idxs == NULL)
1335 VIM_CLEAR(text_props);
1336
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337 area_highlighting = TRUE;
1338 extra_check = TRUE;
1339 }
1340 }
1341#endif
1342
Bram Moolenaar1306b362022-08-06 15:59:06 +01001343 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344
1345 // Repeat for the whole displayed line.
1346 for (;;)
1347 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001348 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001350 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351#endif
1352#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001353 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001355
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001357 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001359#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001360 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001361 {
1362 cul_attr = 0;
1363 line_attr = line_attr_save;
1364 }
1365#endif
1366
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001368 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001370 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 if (cmdwin_type != 0 && wp == curwin)
1372 {
1373 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001374 wlv.n_extra = 1;
1375 wlv.c_extra = cmdwin_type;
1376 wlv.c_final = NUL;
1377 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378 }
1379 }
1380#endif
1381
1382#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001383 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 {
1385 int fdc = compute_foldcolumn(wp, 0);
1386
Bram Moolenaar1306b362022-08-06 15:59:06 +01001387 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 if (fdc > 0)
1389 {
1390 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1391 // already be in use.
1392 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001393 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 if (p_extra_free != NULL)
1395 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001396 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001397 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001398 p_extra_free[wlv.n_extra] = NUL;
1399 wlv.p_extra = p_extra_free;
1400 wlv.c_extra = NUL;
1401 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001402 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001403 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001404 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1405 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001406 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001407 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 }
1409 }
1410 }
1411#endif
1412
1413#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001414 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001416 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 // Show the sign column when there are any signs in this
1418 // buffer or when using Netbeans.
1419 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001420 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1421 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 }
1423#endif
1424
Bram Moolenaar1306b362022-08-06 15:59:06 +01001425 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001427 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 // Display the absolute or relative line number. After the
1429 // first fill with blanks when the 'n' flag isn't in 'cpo'
1430 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001431 && (wlv.row == startrow + filler_lines
1432 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 {
1434#ifdef FEAT_SIGNS
1435 // If 'signcolumn' is set to 'number' and a sign is present
1436 // in 'lnum', then display the sign instead of the line
1437 // number.
1438 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1439 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001440 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1441 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 else
1443#endif
1444 {
1445 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001446 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 {
1448 long num;
1449 char *fmt = "%*ld ";
1450
1451 if (wp->w_p_nu && !wp->w_p_rnu)
1452 // 'number' + 'norelativenumber'
1453 num = (long)lnum;
1454 else
1455 {
1456 // 'relativenumber', don't use negative numbers
1457 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1458 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1459 {
1460 // 'number' + 'relativenumber'
1461 num = lnum;
1462 fmt = "%-*ld ";
1463 }
1464 }
1465
1466 sprintf((char *)extra, fmt,
1467 number_width(wp), num);
1468 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001469 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1470 ++wlv.p_extra)
1471 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472#ifdef FEAT_RIGHTLEFT
1473 if (wp->w_p_rl) // reverse line numbers
1474 {
1475 char_u *p1, *p2;
1476 int t;
1477
1478 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001479 p2 = skipwhite(extra);
1480 p2 = skiptowhite(p2) - 1;
1481 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 {
1483 t = *p1;
1484 *p1 = *p2;
1485 *p2 = t;
1486 }
1487 }
1488#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001489 wlv.p_extra = extra;
1490 wlv.c_extra = NUL;
1491 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492 }
1493 else
1494 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001495 wlv.c_extra = ' ';
1496 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001498 wlv.n_extra = number_width(wp) + 1;
1499 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500#ifdef FEAT_SYN_HL
1501 // When 'cursorline' is set highlight the line number of
1502 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001503 // When 'cursorlineopt' does not have "line" only
1504 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 // TODO: Can we use CursorLine instead of CursorLineNr
1506 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001507 if (wp->w_p_cul
1508 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001510 && (wlv.row == startrow + filler_lines
1511 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001512 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001513 wlv.char_attr = hl_combine_attr(wcr_attr,
1514 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001516 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1517 && HL_ATTR(HLF_LNA) != 0)
1518 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001519 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001520 HL_ATTR(HLF_LNA));
1521 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1522 && HL_ATTR(HLF_LNB) != 0)
1523 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001524 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001525 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526 }
James McCoya80aad72021-12-22 19:45:28 +00001527#ifdef FEAT_SIGNS
1528 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001529 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001530#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 }
1532 }
1533
1534#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001535 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1536 && wlv.n_extra == 0
1537 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001539 wlv.draw_state = WL_BRI;
1540 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1541 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001543 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544
1545 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001546 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001548 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001550 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551# ifdef FEAT_DIFF
1552 && filler_lines == 0
1553# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001554# ifdef FEAT_PROP_POPUP
1555 && !dont_use_showbreak
1556# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 )
1558 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001559 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001561 if (wlv.diff_hlf != (hlf_T)0)
1562 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001564 wlv.p_extra = NULL;
1565 wlv.c_extra = ' ';
1566 wlv.c_final = NUL;
1567 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001569 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001570 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001571 wlv.n_extra -= win_col_off2(wp);
1572 if (wlv.n_extra < 0)
1573 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001574 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001575 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001576 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577 // Correct end of highlighted area for 'breakindent',
1578 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001579 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001580 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001581 }
1582 }
1583#endif
1584
1585#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001586 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001588 char_u *sbr;
1589
Bram Moolenaar1306b362022-08-06 15:59:06 +01001590 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591# ifdef FEAT_DIFF
1592 if (filler_todo > 0)
1593 {
1594 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001595 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001597 wlv.c_extra = '-';
1598 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 }
1600 else
1601 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001602 wlv.c_extra = wp->w_fill_chars.diff;
1603 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 }
1605# ifdef FEAT_RIGHTLEFT
1606 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001607 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 else
1609# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001610 wlv.n_extra = wp->w_width - wlv.col;
1611 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001612 }
1613# endif
1614# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001615 sbr = get_showbreak_value(wp);
1616 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 {
1618 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001619 wlv.p_extra = sbr;
1620 wlv.c_extra = NUL;
1621 wlv.c_final = NUL;
1622 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001623 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1624 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001625 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 // Correct end of highlighted area for 'showbreak',
1627 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001628 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001629 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001631 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1632 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001633# ifdef FEAT_SYN_HL
1634 // combine 'showbreak' with 'cursorline'
1635 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001636 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1637 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638# endif
1639 }
1640# endif
1641 }
1642#endif
1643
Bram Moolenaar1306b362022-08-06 15:59:06 +01001644 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001646 wlv.draw_state = WL_LINE;
1647 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 {
1649 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001650 wlv.n_extra = wlv.saved_n_extra;
1651 wlv.c_extra = wlv.saved_c_extra;
1652 wlv.c_final = wlv.saved_c_final;
1653 wlv.p_extra = wlv.saved_p_extra;
1654 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655 }
1656 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001657 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 }
1659 }
1660#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001661 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001662 && wlv.vcol >= left_curline_col
1663 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001664 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001665 cul_attr = HL_ATTR(HLF_CUL);
1666 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667 }
1668#endif
1669
1670 // When still displaying '$' of change command, stop at cursor.
1671 // When only displaying the (relative) line number and that's done,
1672 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001673 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001674 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001675 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676#ifdef FEAT_DIFF
1677 && filler_todo <= 0
1678#endif
1679 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001681 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1682 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 // Pretend we have finished updating the window. Except when
1684 // 'cursorcolumn' is set.
1685#ifdef FEAT_SYN_HL
1686 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001687 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 else
1689#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001690 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 break;
1692 }
1693
Bram Moolenaar1306b362022-08-06 15:59:06 +01001694 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 {
1696 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001697 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001698 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 && (*mb_ptr2cells)(ptr) > 1)
1700 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001701 && vcol_prev < wlv.vcol // not at margin
1702 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 area_attr = vi_attr; // start highlighting
1704 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001705 && (wlv.vcol == tocol
1706 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 area_attr = 0; // stop highlighting
1708
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001709#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 if (text_props != NULL)
1711 {
1712 int pi;
1713 int bcol = (int)(ptr - line);
1714
Bram Moolenaar1306b362022-08-06 15:59:06 +01001715 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001716# ifdef FEAT_LINEBREAK
1717 && !in_linebreak
1718# endif
1719 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 --bcol; // still working on the previous char, e.g. Tab
1721
1722 // Check if any active property ends.
1723 for (pi = 0; pi < text_props_active; ++pi)
1724 {
1725 int tpi = text_prop_idxs[pi];
1726
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001727 if (text_props[tpi].tp_col != MAXCOL
1728 && bcol >= text_props[tpi].tp_col - 1
1729 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 {
1731 if (pi + 1 < text_props_active)
1732 mch_memmove(text_prop_idxs + pi,
1733 text_prop_idxs + pi + 1,
1734 sizeof(int)
1735 * (text_props_active - (pi + 1)));
1736 --text_props_active;
1737 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001738# ifdef FEAT_LINEBREAK
1739 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001740 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001741 syntax_attr = 0;
1742# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 }
1744 }
1745
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001746# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001747 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001748 // not on the next char yet, don't start another prop
1749 --bcol;
1750# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001752 // With 'nowrap' and not in the first screen line only "below"
1753 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001755 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001756 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001757 && (wp->w_p_wrap
1758 || wlv.row == startrow
1759 || (text_props[text_prop_next].tp_flags
1760 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001761 || (bcol == 0 &&
1762 (text_props[text_prop_next].tp_flags
1763 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001764 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001765 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001766 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001767 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1768 {
1769 // first display the '$' after the line
1770 text_prop_follows = TRUE;
1771 break;
1772 }
1773 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001774 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001775 + text_props[text_prop_next].tp_len)
1776 text_prop_idxs[text_props_active++] = text_prop_next;
1777 ++text_prop_next;
1778 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001780 if (wlv.n_extra == 0 || !extra_for_textprop)
1781 {
1782 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001783 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001784 text_prop_flags = 0;
1785 text_prop_type = NULL;
1786 text_prop_id = 0;
1787 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001788 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001790 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001791 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001792 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001793
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 // Sort the properties on priority and/or starting last.
1795 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001796 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001797 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001798 sort_text_props(wp->w_buffer, text_props,
1799 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800
1801 for (pi = 0; pi < text_props_active; ++pi)
1802 {
1803 int tpi = text_prop_idxs[pi];
1804 proptype_T *pt = text_prop_type_by_id(
1805 wp->w_buffer, text_props[tpi].tp_type);
1806
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001807 if (pt != NULL && (pt->pt_hl_id > 0
1808 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001809 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001811 if (pt->pt_hl_id > 0)
1812 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 text_prop_type = pt;
1814 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001815 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001816 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001817 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001818 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001819 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820 }
1821 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001822 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001823 && -text_prop_id
1824 <= wp->w_buffer->b_textprop_text.ga_len)
1825 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001826 textprop_T *tp = &text_props[used_tpi];
1827 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001828 ->b_textprop_text.ga_data)[
1829 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001830 int above = (tp->tp_flags
1831 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001832
1833 // reset the ID in the copy to avoid it being used
1834 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001835 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001836
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001837 if (p != NULL)
1838 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001839 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001840 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001841 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001842 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001843 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1844 int padding = tp->tp_col == MAXCOL
1845 && tp->tp_len > 1
1846 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001847
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001848 // Insert virtual text before the current
1849 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001850 wlv.p_extra = p;
1851 wlv.c_extra = NUL;
1852 wlv.c_final = NUL;
1853 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001854 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001855 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001856 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001857 // restore search_attr and area_attr when n_extra
1858 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001859 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001860 saved_area_attr = area_attr;
1861 search_attr = 0;
1862 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001863 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001864 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001865 if (*ptr == NUL)
1866 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001867 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001868#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001869 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001870 {
1871 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001872 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001873 need_showbreak = FALSE;
1874 dont_use_showbreak = TRUE;
1875 }
1876#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001877 if ((right || above || below || !wrap
1878 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001879 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001880 char_u *prev_p_extra = wlv.p_extra;
1881 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001882
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001883 // Take care of padding, right-align and
1884 // truncation.
1885 // Shared with win_lbr_chartabsize(), must do
1886 // exactly the same.
1887 start_line = text_prop_position(wp, tp,
1888 wlv.col,
1889 &wlv.n_extra, &wlv.p_extra,
1890 &n_attr, &n_attr_skip);
1891 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001892 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001893 // wlv.p_extra was allocated
1894 vim_free(p_extra_free2);
1895 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001896 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001897
Bram Moolenaara4abe512022-09-15 19:44:09 +01001898 if (lcs_eol_one < 0 && wlv.col
1899 + wlv.n_extra - 2 > wp->w_width)
1900 // don't bail out at end of line
1901 lcs_eol_one = 0;
1902
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001903 // When 'wrap' is off then for "below" we need
1904 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001905 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001906 {
1907 draw_screen_line(wp, &wlv);
1908
1909 // When line got too long for screen break
1910 // here.
1911 if (wlv.row == endrow)
1912 {
1913 ++wlv.row;
1914 break;
1915 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 win_line_start(wp, &wlv, TRUE);
1917 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001918 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001919 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001920 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001921
1922 // If another text prop follows the condition below at
1923 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001924 // If this is an "above" text prop and 'nowrap' the we
1925 // must wrap anyway.
1926 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001927 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001928 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001930 else if (text_prop_next < text_prop_count
1931 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001932 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1933 || (!wp->w_p_wrap
1934 && wlv.col == wp->w_width - 1
1935 && (text_props[text_prop_next].tp_flags
1936 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001937 // When at last-but-one character and a text property
1938 // follows after it, we may need to flush the line after
1939 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001940 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001941 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 }
1943#endif
1944
Bram Moolenaare38fc862022-08-11 17:24:50 +01001945#ifdef FEAT_SEARCH_EXTRA
1946 if (wlv.n_extra == 0)
1947 {
1948 // Check for start/end of 'hlsearch' and other matches.
1949 // After end, check for start/end of next match.
1950 // When another match, have to check for start again.
1951 v = (long)(ptr - line);
1952 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1953 &screen_search_hl, &has_match_conc,
1954 &match_conc, did_line_attr, lcs_eol_one,
1955 &on_last_col);
1956 ptr = line + v; // "line" may have been changed
1957 prev_ptr = ptr;
1958
1959 // Do not allow a conceal over EOL otherwise EOL will be missed
1960 // and bad things happen.
1961 if (*ptr == NUL)
1962 has_match_conc = 0;
1963 }
1964#endif
1965
1966#ifdef FEAT_DIFF
1967 if (wlv.diff_hlf != (hlf_T)0)
1968 {
1969 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1970 && wlv.n_extra == 0)
1971 wlv.diff_hlf = HLF_TXD; // changed text
1972 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1973 && wlv.n_extra == 0)
1974 wlv.diff_hlf = HLF_CHD; // changed line
1975 line_attr = HL_ATTR(wlv.diff_hlf);
1976 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1977 && wp->w_p_culopt_flags != CULOPT_NBR
1978 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1979 && wlv.vcol <= right_curline_col)))
1980 line_attr = hl_combine_attr(
1981 line_attr, HL_ATTR(HLF_CUL));
1982 }
1983#endif
1984
Bram Moolenaara74fda62019-10-19 17:38:03 +02001985#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001987 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001988 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001989# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001990 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001991 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001992# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001993 // Get syntax attribute.
1994 if (has_syntax)
1995 {
1996 // Get the syntax attribute for the character. If there
1997 // is an error, disable syntax highlighting.
1998 save_did_emsg = did_emsg;
1999 did_emsg = FALSE;
2000
2001 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002002 if (v == prev_syntax_col)
2003 // at same column again
2004 syntax_attr = prev_syntax_attr;
2005 else
2006 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002007# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002008 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002009# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002010 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002011# ifdef FEAT_SPELL
2012 has_spell ? &can_spell :
2013# endif
2014 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002015 prev_syntax_col = v;
2016 prev_syntax_attr = syntax_attr;
2017 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002018
Bram Moolenaar34390282019-10-16 14:38:26 +02002019 if (did_emsg)
2020 {
2021 wp->w_s->b_syn_error = TRUE;
2022 has_syntax = FALSE;
2023 syntax_attr = 0;
2024 }
2025 else
2026 did_emsg = save_did_emsg;
2027# ifdef SYN_TIME_LIMIT
2028 if (wp->w_s->b_syn_slow)
2029 has_syntax = FALSE;
2030# endif
2031
2032 // Need to get the line again, a multi-line regexp may
2033 // have made it invalid.
2034 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2035 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002036 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002037# ifdef FEAT_CONCEAL
2038 // no concealing past the end of the line, it interferes
2039 // with line highlighting
2040 if (*ptr == NUL)
2041 syntax_flags = 0;
2042 else
2043 syntax_flags = get_syntax_info(&syntax_seqnr);
2044# endif
2045 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002046 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002047# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002048 // Combine text property highlight into syntax highlight.
2049 if (text_prop_type != NULL)
2050 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002051 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002052 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2053 else
2054 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002055 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002056 }
2057# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002058#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002059
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060 // Decide which of the highlight attributes to use.
2061 attr_pri = TRUE;
2062#ifdef LINE_ATTR
2063 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002064 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002065 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002066 if (!highlight_match)
2067 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002068 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002069# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002071# endif
2072 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002074 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002075 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002076# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002077 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002078# endif
2079 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002080 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002081 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2082 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 {
2084 // Use line_attr when not in the Visual or 'incsearch' area
2085 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002086# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002087 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002088# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002089 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002090# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091 attr_pri = FALSE;
2092 }
2093#else
2094 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002095 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002097 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098#endif
2099 else
2100 {
2101 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002102#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002103 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002104#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002105 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002106#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002108#ifdef FEAT_PROP_POPUP
2109 // override with text property highlight when "override" is TRUE
2110 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002111 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002112#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002114
2115 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002116 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002117 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002118 if (wlv.char_attr == 0)
2119 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002120 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002121 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002122 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002123
2124 // Get the next character to put on the screen.
2125
2126 // The "p_extra" points to the extra stuff that is inserted to
2127 // represent special characters (non-printable stuff) and other
2128 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2131 // "p_extra[n_extra]".
2132 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002133 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002134 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002135 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002136 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2138 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002139 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2140 if (enc_utf8 && utf_char2len(c) > 1)
2141 {
2142 mb_utf8 = TRUE;
2143 u8cc[0] = 0;
2144 c = 0xc0;
2145 }
2146 else
2147 mb_utf8 = FALSE;
2148 }
2149 else
2150 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002151 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002152 if (has_mbyte)
2153 {
2154 mb_c = c;
2155 if (enc_utf8)
2156 {
2157 // If the UTF-8 character is more than one byte:
2158 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002159 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002160 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002161 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 mb_l = 1;
2163 else if (mb_l > 1)
2164 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002165 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002166 mb_utf8 = TRUE;
2167 c = 0xc0;
2168 }
2169 }
2170 else
2171 {
2172 // if this is a DBCS character, put it in "mb_c"
2173 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002174 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175 mb_l = 1;
2176 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002177 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002178 }
2179 if (mb_l == 0) // at the NUL at end-of-line
2180 mb_l = 1;
2181
2182 // If a double-width char doesn't fit display a '>' in the
2183 // last column.
2184 if ((
2185# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002186 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002188 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189 && (*mb_char2cells)(mb_c) == 2)
2190 {
2191 c = '>';
2192 mb_c = c;
2193 mb_l = 1;
2194 mb_utf8 = FALSE;
2195 multi_attr = HL_ATTR(HLF_AT);
2196#ifdef FEAT_SYN_HL
2197 if (cul_attr)
2198 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2199#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002200 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002201
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202 // put the pointer back to output the double-width
2203 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002204 ++wlv.n_extra;
2205 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002206 }
2207 else
2208 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002209 wlv.n_extra -= mb_l - 1;
2210 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 }
2212 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002213 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002214 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002216#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002217 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002218 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002219 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002220 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002221 if (search_attr == 0)
2222 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002223 if (area_attr == 0 && *ptr != NUL)
2224 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002225 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002226#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002227 }
2228 else
2229 {
2230#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002231 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002232#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002233 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002234
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002235 // Get a character from the line itself.
2236 c = *ptr;
2237#ifdef FEAT_LINEBREAK
2238 c0 = *ptr;
2239#endif
2240 if (has_mbyte)
2241 {
2242 mb_c = c;
2243 if (enc_utf8)
2244 {
2245 // If the UTF-8 character is more than one byte: Decode it
2246 // into "mb_c".
2247 mb_l = utfc_ptr2len(ptr);
2248 mb_utf8 = FALSE;
2249 if (mb_l > 1)
2250 {
2251 mb_c = utfc_ptr2char(ptr, u8cc);
2252 // Overlong encoded ASCII or ASCII with composing char
2253 // is displayed normally, except a NUL.
2254 if (mb_c < 0x80)
2255 {
2256 c = mb_c;
2257#ifdef FEAT_LINEBREAK
2258 c0 = mb_c;
2259#endif
2260 }
2261 mb_utf8 = TRUE;
2262
2263 // At start of the line we can have a composing char.
2264 // Draw it as a space with a composing char.
2265 if (utf_iscomposing(mb_c))
2266 {
2267 int i;
2268
2269 for (i = Screen_mco - 1; i > 0; --i)
2270 u8cc[i] = u8cc[i - 1];
2271 u8cc[0] = mb_c;
2272 mb_c = ' ';
2273 }
2274 }
2275
2276 if ((mb_l == 1 && c >= 0x80)
2277 || (mb_l >= 1 && mb_c == 0)
2278 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2279 {
2280 // Illegal UTF-8 byte: display as <xx>.
2281 // Non-BMP character : display as ? or fullwidth ?.
2282 transchar_hex(extra, mb_c);
2283# ifdef FEAT_RIGHTLEFT
2284 if (wp->w_p_rl) // reverse
2285 rl_mirror(extra);
2286# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 wlv.p_extra = extra;
2288 c = *wlv.p_extra;
2289 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2292 wlv.c_extra = NUL;
2293 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 if (area_attr == 0 && search_attr == 0)
2295 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002296 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002297 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002298 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002299 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002300 }
2301 }
2302 else if (mb_l == 0) // at the NUL at end-of-line
2303 mb_l = 1;
2304#ifdef FEAT_ARABIC
2305 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2306 {
2307 // Do Arabic shaping.
2308 int pc, pc1, nc;
2309 int pcc[MAX_MCO];
2310
2311 // The idea of what is the previous and next
2312 // character depends on 'rightleft'.
2313 if (wp->w_p_rl)
2314 {
2315 pc = prev_c;
2316 pc1 = prev_c1;
2317 nc = utf_ptr2char(ptr + mb_l);
2318 prev_c1 = u8cc[0];
2319 }
2320 else
2321 {
2322 pc = utfc_ptr2char(ptr + mb_l, pcc);
2323 nc = prev_c;
2324 pc1 = pcc[0];
2325 }
2326 prev_c = mb_c;
2327
2328 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2329 }
2330 else
2331 prev_c = mb_c;
2332#endif
2333 }
2334 else // enc_dbcs
2335 {
2336 mb_l = MB_BYTE2LEN(c);
2337 if (mb_l == 0) // at the NUL at end-of-line
2338 mb_l = 1;
2339 else if (mb_l > 1)
2340 {
2341 // We assume a second byte below 32 is illegal.
2342 // Hopefully this is OK for all double-byte encodings!
2343 if (ptr[1] >= 32)
2344 mb_c = (c << 8) + ptr[1];
2345 else
2346 {
2347 if (ptr[1] == NUL)
2348 {
2349 // head byte at end of line
2350 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002351 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 }
2353 else
2354 {
2355 // illegal tail byte
2356 mb_l = 2;
2357 STRCPY(extra, "XX");
2358 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002359 wlv.p_extra = extra;
2360 wlv.n_extra = (int)STRLEN(extra) - 1;
2361 wlv.c_extra = NUL;
2362 wlv.c_final = NUL;
2363 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 if (area_attr == 0 && search_attr == 0)
2365 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002367 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002368 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002369 // save current attr
2370 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002371 }
2372 mb_c = c;
2373 }
2374 }
2375 }
2376 // If a double-width char doesn't fit display a '>' in the
2377 // last column; the character is displayed at the start of the
2378 // next line.
2379 if ((
2380# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002381 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002383 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 && (*mb_char2cells)(mb_c) == 2)
2385 {
2386 c = '>';
2387 mb_c = c;
2388 mb_utf8 = FALSE;
2389 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002390 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391 // Put pointer back so that the character will be
2392 // displayed at the start of the next line.
2393 --ptr;
2394#ifdef FEAT_CONCEAL
2395 did_decrement_ptr = TRUE;
2396#endif
2397 }
2398 else if (*ptr != NUL)
2399 ptr += mb_l - 1;
2400
2401 // If a double-width char doesn't fit at the left side display
2402 // a '<' in the first column. Don't do this for unprintable
2403 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002406 wlv.n_extra = 1;
2407 wlv.c_extra = MB_FILLER_CHAR;
2408 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002409 c = ' ';
2410 if (area_attr == 0 && search_attr == 0)
2411 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002413 extra_attr = hl_combine_attr(
2414 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 }
2417 mb_c = c;
2418 mb_utf8 = FALSE;
2419 mb_l = 1;
2420 }
2421
2422 }
2423 ++ptr;
2424
2425 if (extra_check)
2426 {
2427#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002428 // Check spelling (unless at the end of the line).
2429 // Only do this when there is no syntax highlighting, the
2430 // @Spell cluster is not used or the current syntax item
2431 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002432 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 if (has_spell && v >= word_end && v > cur_checked_col)
2434 {
2435 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002436 // do not calculate cap_col at the end of the line or when
2437 // only white space is following
2438 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439# ifdef FEAT_SYN_HL
2440 !has_syntax ||
2441# endif
2442 can_spell))
2443 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002444 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 int len;
2446 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002447
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450
2451 // Use nextline[] if possible, it has the start of the
2452 // next line concatenated.
2453 if ((prev_ptr - line) - nextlinecol >= 0)
2454 p = nextline + (prev_ptr - line) - nextlinecol;
2455 else
2456 p = prev_ptr;
2457 cap_col -= (int)(prev_ptr - line);
2458 len = spell_check(wp, p, &spell_hlf, &cap_col,
2459 nochange);
2460 word_end = v + len;
2461
2462 // In Insert mode only highlight a word that
2463 // doesn't touch the cursor.
2464 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002465 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466 && wp->w_cursor.lnum == lnum
2467 && wp->w_cursor.col >=
2468 (colnr_T)(prev_ptr - line)
2469 && wp->w_cursor.col < (colnr_T)word_end)
2470 {
2471 spell_hlf = HLF_COUNT;
2472 spell_redraw_lnum = lnum;
2473 }
2474
2475 if (spell_hlf == HLF_COUNT && p != prev_ptr
2476 && (p - nextline) + len > nextline_idx)
2477 {
2478 // Remember that the good word continues at the
2479 // start of the next line.
2480 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002481 checked_col = (int)((p - nextline)
2482 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 }
2484
2485 // Turn index into actual attributes.
2486 if (spell_hlf != HLF_COUNT)
2487 spell_attr = highlight_attr[spell_hlf];
2488
2489 if (cap_col > 0)
2490 {
2491 if (p != prev_ptr
2492 && (p - nextline) + cap_col >= nextline_idx)
2493 {
2494 // Remember that the word in the next line
2495 // must start with a capital.
2496 capcol_lnum = lnum + 1;
2497 cap_col = (int)((p - nextline) + cap_col
2498 - nextline_idx);
2499 }
2500 else
2501 // Compute the actual column.
2502 cap_col += (int)(prev_ptr - line);
2503 }
2504 }
2505 }
2506 if (spell_attr != 0)
2507 {
2508 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002509 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2510 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 wlv.char_attr = hl_combine_attr(spell_attr,
2513 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 }
2515#endif
2516#ifdef FEAT_LINEBREAK
2517 // Found last space before word: check for line break.
2518 if (wp->w_p_lbr && c0 == c
2519 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2520 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002521 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2522 : 0;
2523 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002524 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002526 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002527# ifdef FEAT_PROP_POPUP
2528 // do not want virtual text counted here
2529 cts.cts_has_prop_with_text = FALSE;
2530# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002532 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002533
2534 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002535 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002536 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002537 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002538 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2539 if (wlv.n_extra < 0)
2540 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002541 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002542 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002543 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002544 // line break, but for TABs the highlighting should
2545 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002546 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002547
Bram Moolenaar1306b362022-08-06 15:59:06 +01002548 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002549# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002550 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002551 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 wp->w_buffer->b_p_vts_array) - 1;
2553# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002554 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002555 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556# endif
2557
Bram Moolenaar1306b362022-08-06 15:59:06 +01002558 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2559 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002560# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002561 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002562 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002563# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 if (VIM_ISWHITE(c))
2565 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002566# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 if (c == TAB)
2568 // See "Tab alignment" below.
2569 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002570# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 if (!wp->w_p_list)
2572 c = ' ';
2573 }
2574 }
2575#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002576 in_multispace = c == ' '
2577 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2578 if (!in_multispace)
2579 multispace_pos = 0;
2580
Bram Moolenaareed9d462021-02-15 20:38:25 +01002581 // 'list': Change char 160 to 'nbsp' and space to 'space'
2582 // setting in 'listchars'. But not when the character is
2583 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 if (wp->w_p_list
2585 && ((((c == 160 && mb_l == 1)
2586 || (mb_utf8
2587 && ((mb_c == 160 && mb_l == 2)
2588 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002589 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 || (c == ' '
2591 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002592 && (wp->w_lcs_chars.space
2593 || (in_multispace
2594 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002595 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 && ptr - line <= trailcol)))
2597 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002598 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2599 {
2600 c = wp->w_lcs_chars.multispace[multispace_pos++];
2601 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2602 multispace_pos = 0;
2603 }
2604 else
2605 c = (c == ' ') ? wp->w_lcs_chars.space
2606 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 if (area_attr == 0 && search_attr == 0)
2608 {
2609 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002610 extra_attr = hl_combine_attr(wlv.win_attr,
2611 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002612 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613 }
2614 mb_c = c;
2615 if (enc_utf8 && utf_char2len(c) > 1)
2616 {
2617 mb_utf8 = TRUE;
2618 u8cc[0] = 0;
2619 c = 0xc0;
2620 }
2621 else
2622 mb_utf8 = FALSE;
2623 }
2624
zeertzjq2e7cba32022-06-10 15:30:32 +01002625 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2626 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002628 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2629 && wp->w_lcs_chars.leadmultispace != NULL)
2630 {
2631 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002632 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2633 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002634 multispace_pos = 0;
2635 }
2636
2637 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2638 c = wp->w_lcs_chars.trail;
2639
2640 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2641 c = wp->w_lcs_chars.lead;
2642
zeertzjq2e7cba32022-06-10 15:30:32 +01002643 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002644 c = wp->w_lcs_chars.space;
2645
2646
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 if (!attr_pri)
2648 {
2649 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002650 extra_attr = hl_combine_attr(wlv.win_attr,
2651 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002652 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653 }
2654 mb_c = c;
2655 if (enc_utf8 && utf_char2len(c) > 1)
2656 {
2657 mb_utf8 = TRUE;
2658 u8cc[0] = 0;
2659 c = 0xc0;
2660 }
2661 else
2662 mb_utf8 = FALSE;
2663 }
2664 }
2665
2666 // Handling of non-printable characters.
2667 if (!vim_isprintc(c))
2668 {
2669 // when getting a character from the file, we may have to
2670 // turn it into something else on the way to putting it
2671 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002672 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 {
2674 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002675 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002676#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002677 char_u *sbr = get_showbreak_value(wp);
2678
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002679 // only adjust the tab_len, when at the first column
2680 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002681 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2682 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683#endif
2684 // tab amount depends on current column
2685#ifdef FEAT_VARTABS
2686 tab_len = tabstop_padding(vcol_adjusted,
2687 wp->w_buffer->b_p_ts,
2688 wp->w_buffer->b_p_vts_array) - 1;
2689#else
2690 tab_len = (int)wp->w_buffer->b_p_ts
2691 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2692#endif
2693
2694#ifdef FEAT_LINEBREAK
2695 if (!wp->w_p_lbr || !wp->w_p_list)
2696#endif
2697 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002698 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699#ifdef FEAT_LINEBREAK
2700 else
2701 {
2702 char_u *p;
2703 int len;
2704 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002707# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002708 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002710 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002711
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002713 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002714 && old_boguscols > 0
2715 && wlv.n_extra > tab_len)
2716 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002717# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002720 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002721 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002722 if (wp->w_lcs_chars.tab3)
2723 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002724 if (wlv.n_extra > 0)
2725 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002726 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002728 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002730 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002732 vim_memset(p, ' ', len);
2733 p[len] = NUL;
2734 vim_free(p_extra_free);
2735 p_extra_free = p;
2736 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002738 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002740 if (*p == NUL)
2741 {
2742 tab_len = i;
2743 break;
2744 }
2745
2746 // if tab3 is given, use it for the last char
2747 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2748 lcs = wp->w_lcs_chars.tab3;
2749 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002750 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002751 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002752 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002753 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002754# ifdef FEAT_CONCEAL
2755 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2756 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002757 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002758 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002759# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761 }
2762#endif
2763#ifdef FEAT_CONCEAL
2764 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002765 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766
2767 // Tab alignment should be identical regardless of
2768 // 'conceallevel' value. So tab compensates of all
2769 // previous concealed characters, and thus resets
2770 // vcol_off and boguscols accumulated so far in the
2771 // line. Note that the tab can be longer than
2772 // 'tabstop' when there are concealed characters.
2773 FIX_FOR_BOGUSCOLS;
2774
2775 // Make sure, the highlighting for the tab char will be
2776 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002777 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002778 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002779 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780 tab_len += vc_saved;
2781 }
2782#endif
2783 mb_utf8 = FALSE; // don't draw as UTF-8
2784 if (wp->w_p_list)
2785 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002786 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002787 ? wp->w_lcs_chars.tab3
2788 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789#ifdef FEAT_LINEBREAK
2790 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002791 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 else
2793#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002794 wlv.c_extra = wp->w_lcs_chars.tab2;
2795 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 extra_attr = hl_combine_attr(wlv.win_attr,
2798 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002799 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 mb_c = c;
2801 if (enc_utf8 && utf_char2len(c) > 1)
2802 {
2803 mb_utf8 = TRUE;
2804 u8cc[0] = 0;
2805 c = 0xc0;
2806 }
2807 }
2808 else
2809 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 wlv.c_final = NUL;
2811 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 c = ' ';
2813 }
2814 }
2815 else if (c == NUL
2816 && (wp->w_p_list
2817 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 && VIsual_mode != Ctrl_V
2820 && (
2821# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002822 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 && !(noinvcur
2826 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002827 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 && lcs_eol_one > 0)
2829 {
2830 // Display a '$' after the line or highlight an extra
2831 // character if the line break is included.
2832#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2833 // For a diff line the highlighting continues after the
2834 // "$".
2835 if (
2836# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002837 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838# ifdef LINE_ATTR
2839 &&
2840# endif
2841# endif
2842# ifdef LINE_ATTR
2843 line_attr == 0
2844# endif
2845 )
2846#endif
2847 {
2848 // In virtualedit, visual selections may extend
2849 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002850 if (!(area_highlighting && virtual_active()
2851 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002852 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002853 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002855 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2856 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 else
2858 c = ' ';
2859 lcs_eol_one = -1;
2860 --ptr; // put it back at the NUL
2861 if (!attr_pri)
2862 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002863 extra_attr = hl_combine_attr(wlv.win_attr,
2864 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 n_attr = 1;
2866 }
2867 mb_c = c;
2868 if (enc_utf8 && utf_char2len(c) > 1)
2869 {
2870 mb_utf8 = TRUE;
2871 u8cc[0] = 0;
2872 c = 0xc0;
2873 }
2874 else
2875 mb_utf8 = FALSE; // don't draw as UTF-8
2876 }
2877 else if (c != NUL)
2878 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2880 if (wlv.n_extra == 0)
2881 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882#ifdef FEAT_RIGHTLEFT
2883 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002884 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 wlv.c_extra = NUL;
2887 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888#ifdef FEAT_LINEBREAK
2889 if (wp->w_p_lbr)
2890 {
2891 char_u *p;
2892
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 c = *wlv.p_extra;
2894 p = alloc(wlv.n_extra + 1);
2895 vim_memset(p, ' ', wlv.n_extra);
2896 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2897 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002899 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 }
2901 else
2902#endif
2903 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 wlv.n_extra = byte2cells(c) - 1;
2905 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906 }
2907 if (!attr_pri)
2908 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002909 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002910 extra_attr = hl_combine_attr(wlv.win_attr,
2911 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002912 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 }
2914 mb_utf8 = FALSE; // don't draw as UTF-8
2915 }
2916 else if (VIsual_active
2917 && (VIsual_mode == Ctrl_V
2918 || VIsual_mode == 'v')
2919 && virtual_active()
2920 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002921 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 && (
2923#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002924 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002926 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927 {
2928 c = ' ';
2929 --ptr; // put it back at the NUL
2930 }
2931#if defined(LINE_ATTR)
2932 else if ((
2933# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002934 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935# endif
2936# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002937 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938# endif
2939 line_attr != 0
2940 ) && (
2941# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002942 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002944 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002946 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947# endif
2948 < wp->w_width)))
2949 {
2950 // Highlight until the right side of the window
2951 c = ' ';
2952 --ptr; // put it back at the NUL
2953
2954 // Remember we do the char for line highlighting.
2955 ++did_line_attr;
2956
2957 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002958 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002960 || (wp->w_p_list &&
2961 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 wlv.diff_hlf = HLF_CHD;
2967 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2971 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002972 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002973 || (wlv.vcol >= left_curline_col
2974 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 wlv.char_attr = hl_combine_attr(
2976 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 }
2978 }
2979# endif
2980# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002981 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002984 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2985 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 if (!wlv.cul_screenline
2988 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002989 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002990 wlv.char_attr = hl_combine_attr(
2991 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992 }
2993 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002994 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2995 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 }
2997# endif
2998 }
2999#endif
3000 }
3001
3002#ifdef FEAT_CONCEAL
3003 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003004 && (wp != curwin || lnum != wp->w_cursor.lnum
3005 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3007 && !(lnum_in_visual_area
3008 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3009 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003010 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003011 if (((prev_syntax_id != syntax_seqnr
3012 && (syntax_flags & HL_CONCEAL) != 0)
3013 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003014 && (syn_get_sub_char() != NUL
3015 || (has_match_conc && match_conc)
3016 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 && wp->w_p_cole != 3)
3018 {
3019 // First time at this concealed item: display one
3020 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003021 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022 c = match_conc;
3023 else if (syn_get_sub_char() != NUL)
3024 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003025 else if (wp->w_lcs_chars.conceal != NUL)
3026 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 else
3028 c = ' ';
3029
3030 prev_syntax_id = syntax_seqnr;
3031
Bram Moolenaar1306b362022-08-06 15:59:06 +01003032 if (wlv.n_extra > 0)
3033 wlv.vcol_off += wlv.n_extra;
3034 wlv.vcol += wlv.n_extra;
3035 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 {
3037# ifdef FEAT_RIGHTLEFT
3038 if (wp->w_p_rl)
3039 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003040 wlv.col -= wlv.n_extra;
3041 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 }
3043 else
3044# endif
3045 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 wlv.boguscols += wlv.n_extra;
3047 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 }
3049 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 n_attr = 0;
3052 }
3053 else if (n_skip == 0)
3054 {
3055 is_concealing = TRUE;
3056 n_skip = 1;
3057 }
3058 mb_c = c;
3059 if (enc_utf8 && utf_char2len(c) > 1)
3060 {
3061 mb_utf8 = TRUE;
3062 u8cc[0] = 0;
3063 c = 0xc0;
3064 }
3065 else
3066 mb_utf8 = FALSE; // don't draw as UTF-8
3067 }
3068 else
3069 {
3070 prev_syntax_id = 0;
3071 is_concealing = FALSE;
3072 }
3073
3074 if (n_skip > 0 && did_decrement_ptr)
3075 // not showing the '>', put pointer back to avoid getting stuck
3076 ++ptr;
3077
3078#endif // FEAT_CONCEAL
3079 }
3080
3081#ifdef FEAT_CONCEAL
3082 // In the cursor line and we may be concealing characters: correct
3083 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003084 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 && wp == curwin && lnum == wp->w_cursor.lnum
3086 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003087 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003089# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003091 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003093# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003094 wp->w_wcol = wlv.col - wlv.boguscols;
3095 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096 did_wcol = TRUE;
3097 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003098# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003099 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003100# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 }
3102#endif
3103
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003104 // Use "extra_attr", but don't override visual selection highlighting,
3105 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003106 // Don't use "extra_attr" until n_attr_skip is zero.
3107 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003108 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003109 && (!attr_pri
3110#ifdef FEAT_PROP_POPUP
3111 || (text_prop_flags & PT_FLAG_OVERRIDE)
3112#endif
3113 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 {
3115#ifdef LINE_ATTR
3116 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003117 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 else
3119#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003120 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 }
3122
3123#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3124 // XIM don't send preedit_start and preedit_end, but they send
3125 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3126 // im_is_preediting() here.
3127 if (p_imst == IM_ON_THE_SPOT
3128 && xic != NULL
3129 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003130 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003131 && !p_imdisable
3132 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003133 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 {
3135 colnr_T tcol;
3136
3137 if (preedit_end_col == MAXCOL)
3138 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3139 else
3140 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003141 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 {
3143 if (feedback_old_attr < 0)
3144 {
3145 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 wlv.char_attr = im_get_feedback_attr(feedback_col);
3149 if (wlv.char_attr < 0)
3150 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 feedback_col++;
3152 }
3153 else if (feedback_old_attr >= 0)
3154 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003155 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 feedback_old_attr = -1;
3157 feedback_col = 0;
3158 }
3159 }
3160#endif
3161 // Handle the case where we are in column 0 but not on the first
3162 // character of the line and the user wants us to show us a
3163 // special character (via 'listchars' option "precedes:<char>".
3164 if (lcs_prec_todo != NUL
3165 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003166 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003167 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003168 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169#ifdef FEAT_DIFF
3170 && filler_todo <= 0
3171#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003172 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 && c != NUL)
3174 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003175 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176 lcs_prec_todo = NUL;
3177 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3178 {
3179 // Double-width character being overwritten by the "precedes"
3180 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003181 wlv.c_extra = MB_FILLER_CHAR;
3182 wlv.c_final = NUL;
3183 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003185 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 }
3187 mb_c = c;
3188 if (enc_utf8 && utf_char2len(c) > 1)
3189 {
3190 mb_utf8 = TRUE;
3191 u8cc[0] = 0;
3192 c = 0xc0;
3193 }
3194 else
3195 mb_utf8 = FALSE; // don't draw as UTF-8
3196 if (!attr_pri)
3197 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003198 saved_attr3 = wlv.char_attr; // save current attr
3199 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 n_attr3 = 1;
3201 }
3202 }
3203
3204 // At end of the text line or just after the last character.
3205 if ((c == NUL
3206#if defined(LINE_ATTR)
3207 || did_line_attr == 1
3208#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003209 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 {
3211#ifdef FEAT_SEARCH_EXTRA
3212 // flag to indicate whether prevcol equals startcol of search_hl or
3213 // one of the matches
3214 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3215 (long)(ptr - line) - (c == NUL));
3216#endif
3217 // Invert at least one char, used for Visual and empty line or
3218 // highlight match at end of line. If it's beyond the last
3219 // char on the screen, just overwrite that one (tricky!) Not
3220 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003221 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003222 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 && (VIsual_mode != Ctrl_V
3224 || lnum == VIsual.lnum
3225 || lnum == curwin->w_cursor.lnum)
3226 && c == NUL)
3227#ifdef FEAT_SEARCH_EXTRA
3228 // highlight 'hlsearch' match at end of line
3229 || (prevcol_hl_flag
3230# ifdef FEAT_SYN_HL
3231 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3232 && !(wp == curwin && VIsual_active))
3233# endif
3234# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236# endif
3237# if defined(LINE_ATTR)
3238 && did_line_attr <= 1
3239# endif
3240 )
3241#endif
3242 ))
3243 {
3244 int n = 0;
3245
3246#ifdef FEAT_RIGHTLEFT
3247 if (wp->w_p_rl)
3248 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 n = 1;
3251 }
3252 else
3253#endif
3254 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 n = -1;
3257 }
3258 if (n != 0)
3259 {
3260 // At the window boundary, highlight the last character
3261 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003262 wlv.off += n;
3263 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 }
3265 else
3266 {
3267 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 }
3272#ifdef FEAT_SEARCH_EXTRA
3273 if (area_attr == 0)
3274 {
3275 // Use attributes from match with highest priority among
3276 // 'search_hl' and the match list.
3277 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003278 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 }
3280#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003281 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283#ifdef FEAT_RIGHTLEFT
3284 if (wp->w_p_rl)
3285 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003286 --wlv.col;
3287 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 }
3289 else
3290#endif
3291 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003292 ++wlv.col;
3293 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003295 ++wlv.vcol;
3296 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 }
3298 }
3299
3300 // At end of the text line.
3301 if (c == NUL)
3302 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304
3305 // Update w_cline_height and w_cline_folded if the cursor line was
3306 // updated (saves a call to plines() later).
3307 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3308 {
3309 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003310 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311#ifdef FEAT_FOLDING
3312 curwin->w_cline_folded = FALSE;
3313#endif
3314 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3315 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 break;
3317 }
3318
3319 // Show "extends" character from 'listchars' if beyond the line end and
3320 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003321 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003322 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 && wp->w_p_list
3324 && !wp->w_p_wrap
3325#ifdef FEAT_DIFF
3326 && filler_todo <= 0
3327#endif
3328 && (
3329#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003330 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003332 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003334 || lcs_eol_one > 0
3335 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003336 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003338 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003339 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340 mb_c = c;
3341 if (enc_utf8 && utf_char2len(c) > 1)
3342 {
3343 mb_utf8 = TRUE;
3344 u8cc[0] = 0;
3345 c = 0xc0;
3346 }
3347 else
3348 mb_utf8 = FALSE;
3349 }
3350
3351#ifdef FEAT_SYN_HL
3352 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003353 if (wlv.draw_color_col)
3354 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355
3356 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3357 // highlight the cursor position itself.
3358 // Also highlight the 'colorcolumn' if it is different than
3359 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003360 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3361 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 if (((wlv.draw_state == WL_LINE
3364 || wlv.draw_state == WL_BRI
3365 || wlv.draw_state == WL_SBR)
3366 && !lnum_in_visual_area
3367 && search_attr == 0
3368 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003369# ifdef FEAT_DIFF
3370 && filler_todo <= 0
3371# endif
3372 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 {
3374 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3375 && lnum != wp->w_cursor.lnum)
3376 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003377 vcol_save_attr = wlv.char_attr;
3378 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3379 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003381 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 vcol_save_attr = wlv.char_attr;
3384 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 }
3386 }
3387#endif
3388
3389 // Store character to be displayed.
3390 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 {
3394 // Store the character.
3395#if defined(FEAT_RIGHTLEFT)
3396 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3397 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003398 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003399 --wlv.off;
3400 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401 }
3402#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003403 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 if (enc_dbcs == DBCS_JPNU)
3405 {
3406 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003407 ScreenLines[wlv.off] = 0x8e;
3408 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 }
3410 else if (enc_utf8)
3411 {
3412 if (mb_utf8)
3413 {
3414 int i;
3415
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003416 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 for (i = 0; i < Screen_mco; ++i)
3420 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003421 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 if (u8cc[i] == 0)
3423 break;
3424 }
3425 }
3426 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 }
3429 if (multi_attr)
3430 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003431 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 multi_attr = 0;
3433 }
3434 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003437 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003438
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3440 {
3441 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003442 ++wlv.off;
3443 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 if (enc_utf8)
3445 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 else
3448 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003450 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451#ifdef FEAT_DIFF
3452 && filler_todo <= 0
3453#endif
3454 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 // When "tocol" is halfway a character, set it to the end of
3457 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003458 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003460
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003461 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003462
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463#ifdef FEAT_RIGHTLEFT
3464 if (wp->w_p_rl)
3465 {
3466 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 --wlv.off;
3468 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 }
3470#endif
3471 }
3472#ifdef FEAT_RIGHTLEFT
3473 if (wp->w_p_rl)
3474 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 --wlv.off;
3476 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477 }
3478 else
3479#endif
3480 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 ++wlv.off;
3482 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484 }
3485#ifdef FEAT_CONCEAL
3486 else if (wp->w_p_cole > 0 && is_concealing)
3487 {
3488 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003490 if (wlv.n_extra > 0)
3491 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 if (wp->w_p_wrap)
3493 {
3494 // Special voodoo required if 'wrap' is on.
3495 //
3496 // Advance the column indicator to force the line
3497 // drawing to wrap early. This will make the line
3498 // take up the same screen space when parts are concealed,
3499 // so that cursor line computations aren't messed up.
3500 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 // trailing junk to be written out of the screen line
3503 // we are building, 'boguscols' keeps track of the number
3504 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003505 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003507 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508# ifdef FEAT_RIGHTLEFT
3509 if (wp->w_p_rl)
3510 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003511 wlv.col -= wlv.n_extra;
3512 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 }
3514 else
3515# endif
3516 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003517 wlv.col += wlv.n_extra;
3518 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003520 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 n_attr = 0;
3522 }
3523
3524
3525 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3526 {
3527 // Need to fill two screen columns.
3528# ifdef FEAT_RIGHTLEFT
3529 if (wp->w_p_rl)
3530 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 --wlv.boguscols;
3532 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 }
3534 else
3535# endif
3536 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 ++wlv.boguscols;
3538 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 }
3540 }
3541
3542# ifdef FEAT_RIGHTLEFT
3543 if (wp->w_p_rl)
3544 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 --wlv.boguscols;
3546 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 }
3548 else
3549# endif
3550 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 ++wlv.boguscols;
3552 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 }
3554 }
3555 else
3556 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003557 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 wlv.vcol += wlv.n_extra;
3560 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 n_attr = 0;
3562 }
3563 }
3564
3565 }
3566#endif // FEAT_CONCEAL
3567 else
3568 --n_skip;
3569
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 // Only advance the "wlv.vcol" when after the 'number' or
3571 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003572 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573#ifdef FEAT_DIFF
3574 && filler_todo <= 0
3575#endif
3576 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003577 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578
3579#ifdef FEAT_SYN_HL
3580 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003581 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582#endif
3583
3584 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003585 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3586 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587
3588 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003589 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003590 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003592 if (n_attr_skip > 0)
3593 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594
3595 // At end of screen line and there is more to come: Display the line
3596 // so far. If there is no more to display it is caught above.
3597 if ((
3598#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003601 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003602 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003603 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604#ifdef FEAT_DIFF
3605 || filler_todo > 0
3606#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003607#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003608 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003609#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003610 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 && wlv.p_extra != at_end_str)
3612 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3613 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 )
3615 {
3616#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003617 screen_line(wp, wlv.screen_row, wp->w_wincol,
3618 wlv.col - wlv.boguscols,
3619 wp->w_width, wlv.screen_line_flags);
3620 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003622 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3623 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003625 ++wlv.row;
3626 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627
3628 // When not wrapping and finished diff lines, or when displayed
3629 // '$' and highlighting until last column, break here.
3630 if ((!wp->w_p_wrap
3631#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003632 && filler_todo <= 0
3633#endif
3634#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003635 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636#endif
3637 ) || lcs_eol_one == -1)
3638 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003639#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003640 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003641 {
3642 // do not output more of the line, only the "below" prop
3643 ptr += STRLEN(ptr);
3644# ifdef FEAT_LINEBREAK
3645 dont_use_showbreak = TRUE;
3646# endif
3647 }
3648#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649
3650 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003651 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652#ifdef FEAT_DIFF
3653 && filler_todo <= 0
3654#endif
3655 )
3656 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3658 draw_vsep_win(wp, wlv.row);
3659 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 }
3661
3662 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003663 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003665 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666 break;
3667 }
3668
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003669 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670#ifdef FEAT_DIFF
3671 && filler_todo <= 0
3672#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003673#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003674 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003675#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 && wp->w_width == Columns)
3677 {
3678 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003679 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680
3681 // Special trick to make copy/paste of wrapped lines work with
3682 // xterm/screen: write an extra character beyond the end of
3683 // the line. This will work with all terminal types
3684 // (regardless of the xn,am settings).
3685 // Only do this on a fast tty.
3686 // Only do this if the cursor is on the current line
3687 // (something has been written in it).
3688 // Don't do this for the GUI.
3689 // Don't do this for double-width characters.
3690 // Don't do this for a window not at the right screen border.
3691 if (p_tf
3692#ifdef FEAT_GUI
3693 && !gui.in_use
3694#endif
3695 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3697 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003699 || (*mb_off2cells)(
3700 LineOffset[wlv.screen_row - 1]
3701 + (int)Columns - 2,
3702 LineOffset[wlv.screen_row]
3703 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 {
3705 // First make sure we are at the end of the screen line,
3706 // then output the same character again to let the
3707 // terminal know about the wrap. If the terminal doesn't
3708 // auto-wrap, we overwrite the character.
3709 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 screen_char(LineOffset[wlv.screen_row - 1]
3711 + (unsigned)Columns - 1,
3712 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003713
3714 // When there is a multi-byte character, just output a
3715 // space to keep it simple.
3716 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003717 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 out_char(' ');
3719 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003720 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721 + (Columns - 1)]);
3722 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003723 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724 screen_start(); // don't know where cursor is now
3725 }
3726 }
3727
Bram Moolenaar1306b362022-08-06 15:59:06 +01003728 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729
Bram Moolenaareed9d462021-02-15 20:38:25 +01003730 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003732 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003734 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003736 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 need_showbreak = TRUE;
3738#endif
3739#ifdef FEAT_DIFF
3740 --filler_todo;
3741 // When the filler lines are actually below the last line of the
3742 // file, don't draw the line itself, break here.
3743 if (filler_todo == 0 && wp->w_botfill)
3744 break;
3745#endif
3746 }
3747
3748 } // for every character in the line
3749
3750#ifdef FEAT_SPELL
3751 // After an empty line check first word for capital.
3752 if (*skipwhite(line) == NUL)
3753 {
3754 capcol_lnum = lnum + 1;
3755 cap_col = 0;
3756 }
3757#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003758#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759 vim_free(text_props);
3760 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003761 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762#endif
3763
3764 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766}