blob: 56d42e2a7fb838c17e21913b6002580f69f97f39 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
105
106 int screen_line_flags; // flags for screen_line()
107
108 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
109 int cul_screenline;
110
111 int char_attr; // attributes for the next character
112
113 int n_extra; // number of extra bytes
114 char_u *p_extra; // string of extra chars, plus NUL, only used
115 // when c_extra and c_final are NUL
116 int c_extra; // extra chars, all the same
117 int c_final; // final char, mandatory if set
118
119 // saved "extra" items for when draw_state becomes WL_LINE (again)
120 int saved_n_extra;
121 char_u *saved_p_extra;
122 int saved_c_extra;
123 int saved_c_final;
124 int saved_char_attr;
125
126#ifdef FEAT_DIFF
127 hlf_T diff_hlf; // type of diff highlighting
128#endif
129} winlinevars_T;
130
131// draw_state values for items that are drawn in sequence:
132#define WL_START 0 // nothing done yet, must be zero
133#ifdef FEAT_CMDWIN
134# define WL_CMDLINE (WL_START + 1) // cmdline window column
135#else
136# define WL_CMDLINE WL_START
137#endif
138#ifdef FEAT_FOLDING
139# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
140#else
141# define WL_FOLD WL_CMDLINE
142#endif
143#ifdef FEAT_SIGNS
144# define WL_SIGN (WL_FOLD + 1) // column for signs
145#else
146# define WL_SIGN WL_FOLD // column for signs
147#endif
148#define WL_NR (WL_SIGN + 1) // line number
149#ifdef FEAT_LINEBREAK
150# define WL_BRI (WL_NR + 1) // 'breakindent'
151#else
152# define WL_BRI WL_NR
153#endif
154#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
155# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
156#else
157# define WL_SBR WL_BRI
158#endif
159#define WL_LINE (WL_SBR + 1) // text in the line
160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_cursor_line_sign(win_T *wp, linenr_T lnum)
167{
168 return wp->w_p_cul
169 && lnum == wp->w_cursor.lnum
170 && (wp->w_p_culopt_flags & CULOPT_NBR);
171}
172
173/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * Get information needed to display the sign in line 'lnum' in window 'wp'.
175 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
176 * Otherwise the sign is going to be displayed in the sign column.
177 */
178 static void
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
190 int text_sign;
191# ifdef FEAT_SIGN_ICONS
192 int icon_sign;
193# endif
194
195 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
255 if (nrcol)
256 {
257 int n, width = number_width(wp) - 2;
258
259 for (n = 0; n < width; n++)
260 extra[n] = ' ';
261 extra[n] = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100280#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100281/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100282 * Return the cell size of virtual text after truncation.
283 */
284 static int
285textprop_size_after_trunc(
286 win_T *wp,
287 int flags, // TP_FLAG_ALIGN_*
288 int added,
289 char_u *text,
290 int *n_used_ptr)
291{
292 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
293 ? wp->w_width : added;
294 int len = (int)STRLEN(text);
295 int strsize = 0;
296 int n_used;
297
298 // if the remaining size is to small wrap anyway and use the next line
299 if (space < PROP_TEXT_MIN_CELLS)
300 space += wp->w_width;
301 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
302 {
303 int clen = ptr2cells(text + n_used);
304
305 if (strsize + clen > space)
306 break;
307 strsize += clen;
308 }
309 *n_used_ptr = n_used;
310 return strsize;
311}
312
313/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100314 * Take care of padding, right-align and truncation of virtual text after a
315 * line.
316 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
317 * padding, right-align and truncation. Otherwise only the size is computed.
318 * When "n_attr" is NULL returns the number of screen cells used.
319 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100320 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100321 int
322text_prop_position(
323 win_T *wp,
324 textprop_T *tp,
325 int vcol, // current screen column
326 int *n_extra, // nr of bytes for virtual text
327 char_u **p_extra, // virtual text
328 int *n_attr, // attribute cells, NULL if not used
329 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100331 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100332 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100333 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
334 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
335 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
336 ? tp->tp_len - 1 : 0;
337 int col_with_padding = vcol + (below ? 0 : padding);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100338 int col_off = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100339 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100340 int before = room; // spaces before the text
341 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100342 int n_used = *n_extra;
343 char_u *l = NULL;
344 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100345 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
346 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100348 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100349 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100350 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100351 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100352 before = 0;
353 after = wp->w_width - cells;
354 }
355 else
356 {
357 // Right-align: fill with before
358 if (right)
359 before -= cells;
360 if (before < 0
361 || !(right || below)
362 || (below
363 ? (col_with_padding == 0 || !wp->w_p_wrap)
364 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100365 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100366 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
367 {
368 // right-align on next line instead of wrapping if possible
369 col_off = win_col_off(wp) + win_col_off2(wp);
370 before = wp->w_width - col_off - strsize + room;
371 if (before < 0)
372 before = 0;
373 else
374 n_used = *n_extra;
375 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100376 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100377 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100378 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100379 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100380
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100381 // With 'nowrap' add one to show the "extends" character if needed (it
382 // doesn't show if the text just fits).
383 if (!wp->w_p_wrap
384 && n_used < *n_extra
385 && wp->w_lcs_chars.ext != NUL
386 && wp->w_p_list)
387 ++n_used;
388
389 // add 1 for NUL, 2 for when '…' is used
390 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100391 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100392 if (n_attr == NULL || l != NULL)
393 {
394 int off = 0;
395
396 if (n_attr != NULL)
397 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100398 vim_memset(l, ' ', before);
399 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100400 if (padding > 0)
401 {
402 vim_memset(l + off, ' ', padding);
403 off += padding;
404 }
405 vim_strncpy(l + off, *p_extra, n_used);
406 off += n_used;
407 }
408 else
409 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100410 off = before + after + padding + n_used;
411 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100412 }
413 if (n_attr != NULL)
414 {
415 if (n_used < *n_extra && wp->w_p_wrap)
416 {
417 char_u *lp = l + off - 1;
418
419 if (has_mbyte)
420 {
421 // change last character to '…'
422 lp -= (*mb_head_off)(l, lp);
423 STRCPY(lp, "…");
424 n_used = lp - l + 3 - padding;
425 }
426 else
427 // change last character to '>'
428 *lp = '>';
429 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100430 else if (after > 0)
431 {
432 vim_memset(l + off, ' ', after);
433 l[off + after] = NUL;
434 }
435
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100436 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100437 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100438 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100439 *n_attr_skip = before + padding + col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100440 }
441 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100442 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100443
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100444 if (n_attr == NULL)
445 return cells;
446 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200447}
448#endif
449
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100450/*
451 * Called when finished with the line: draw the screen line and handle any
452 * highlighting until the right of the window.
453 */
454 static void
455draw_screen_line(win_T *wp, winlinevars_T *wlv)
456{
457#ifdef FEAT_SYN_HL
458 long v;
459
460 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
461 if (wp->w_p_wrap)
462 v = wp->w_skipcol;
463 else
464 v = wp->w_leftcol;
465
466 // check if line ends before left margin
467 if (wlv->vcol < v + wlv->col - win_col_off(wp))
468 wlv->vcol = v + wlv->col - win_col_off(wp);
469# ifdef FEAT_CONCEAL
470 // Get rid of the boguscols now, we want to draw until the right
471 // edge for 'cursorcolumn'.
472 wlv->col -= wlv->boguscols;
473 wlv->boguscols = 0;
474# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
475# else
476# define VCOL_HLC (wlv->vcol)
477# endif
478
479 if (wlv->draw_color_col)
480 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
481
482 if (((wp->w_p_cuc
483 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
484 && (int)wp->w_virtcol <
485 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
486 && wlv->lnum != wp->w_cursor.lnum)
487 || wlv->draw_color_col
488 || wlv->win_attr != 0)
489# ifdef FEAT_RIGHTLEFT
490 && !wp->w_p_rl
491# endif
492 )
493 {
494 int rightmost_vcol = 0;
495 int i;
496
497 if (wp->w_p_cuc)
498 rightmost_vcol = wp->w_virtcol;
499 if (wlv->draw_color_col)
500 // determine rightmost colorcolumn to possibly draw
501 for (i = 0; wlv->color_cols[i] >= 0; ++i)
502 if (rightmost_vcol < wlv->color_cols[i])
503 rightmost_vcol = wlv->color_cols[i];
504
505 while (wlv->col < wp->w_width)
506 {
507 ScreenLines[wlv->off] = ' ';
508 if (enc_utf8)
509 ScreenLinesUC[wlv->off] = 0;
510 ScreenCols[wlv->off] = MAXCOL;
511 ++wlv->col;
512 if (wlv->draw_color_col)
513 wlv->draw_color_col = advance_color_col(
514 VCOL_HLC, &wlv->color_cols);
515
516 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
517 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
518 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
519 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
520 else
521 ScreenAttrs[wlv->off++] = wlv->win_attr;
522
523 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
524 break;
525
526 ++wlv->vcol;
527 }
528 }
529#endif
530
531 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
532 wp->w_width, wlv->screen_line_flags);
533 ++wlv->row;
534 ++wlv->screen_row;
535}
536#undef VCOL_HLC
537
538/*
539 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100540 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100541 */
542 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100543win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100544{
545 wlv->col = 0;
546 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
547
548#ifdef FEAT_RIGHTLEFT
549 if (wp->w_p_rl)
550 {
551 // Rightleft window: process the text in the normal direction, but put
552 // it in current_ScreenLine[] from right to left. Start at the
553 // rightmost column of the window.
554 wlv->col = wp->w_width - 1;
555 wlv->off += wlv->col;
556 wlv->screen_line_flags |= SLF_RIGHTLEFT;
557 }
558#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100559 if (save_extra)
560 {
561 // reset the drawing state for the start of a wrapped line
562 wlv->draw_state = WL_START;
563 wlv->saved_n_extra = wlv->n_extra;
564 wlv->saved_p_extra = wlv->p_extra;
565 wlv->saved_c_extra = wlv->c_extra;
566 wlv->saved_c_final = wlv->c_final;
567#ifdef FEAT_SYN_HL
568 if (!(wlv->cul_screenline
569# ifdef FEAT_DIFF
570 && wlv->diff_hlf == (hlf_T)0
571# endif
572 ))
573 wlv->saved_char_attr = wlv->char_attr;
574 else
575#endif
576 wlv->saved_char_attr = 0;
577 wlv->n_extra = 0;
578 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100579}
580
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200581/*
582 * Display line "lnum" of window 'wp' on the screen.
583 * Start at row "startrow", stop when "endrow" is reached.
584 * wp->w_virtcol needs to be valid.
585 *
586 * Return the number of last row the line occupies.
587 */
588 int
589win_line(
590 win_T *wp,
591 linenr_T lnum,
592 int startrow,
593 int endrow,
594 int nochange UNUSED, // not updating for changed text
595 int number_only) // only update the number column
596{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100597 winlinevars_T wlv; // variables passed between functions
598
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200599 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200600#ifdef FEAT_LINEBREAK
601 long vcol_sbr = -1; // virtual column after showbreak
602#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100603 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200604 char_u *line; // current line
605 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200606
607 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200608 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100609#ifdef FEAT_PROP_POPUP
610 char_u *p_extra_free2 = NULL; // another p_extra to be freed
611#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200612 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000613#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000614 int in_linebreak = FALSE; // n_extra set for showing linebreak
615#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200616 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100617 // displaying eol at end-of-line
618 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000619 int lcs_prec_todo = wp->w_lcs_chars.prec;
620 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100622 int n_attr = 0; // chars with special attr
623 int n_attr_skip = 0; // chars to skip before using extra_attr
624 int saved_attr2 = 0; // char_attr saved for n_attr
625 int n_attr3 = 0; // chars with overruling special attr
626 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200627
628 int n_skip = 0; // nr of chars to skip for 'nowrap'
629
630 int fromcol = -10; // start of inverting
631 int tocol = MAXCOL; // end of inverting
632 int fromcol_prev = -2; // start of inverting after cursor
633 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200634 int lnum_in_visual_area = FALSE;
635 pos_T pos;
636 long v;
637
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200638 int attr_pri = FALSE; // char_attr has priority
639 int area_highlighting = FALSE; // Visual or incsearch highlighting
640 // in this line
641 int vi_attr = 0; // attributes for Visual and incsearch
642 // highlighting
643 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200644 int area_attr = 0; // attributes desired by highlighting
645 int search_attr = 0; // attributes desired by 'hlsearch'
646#ifdef FEAT_SYN_HL
647 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
648 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200649 int prev_syntax_col = -1; // column of prev_syntax_attr
650 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200651 int has_syntax = FALSE; // this buffer has syntax highl.
652 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200653#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100654#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655 int text_prop_count;
656 int text_prop_next = 0; // next text property to use
657 textprop_T *text_props = NULL;
658 int *text_prop_idxs = NULL;
659 int text_props_active = 0;
660 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100661 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200662 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100663 int text_prop_attr_comb = 0; // text_prop_attr combined with
664 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100665 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100666 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100667 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100668 int saved_search_attr = 0; // search_attr to be used when n_extra
669 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200670#endif
671#ifdef FEAT_SPELL
672 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000673 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200674# define SPWORDLEN 150
675 char_u nextline[SPWORDLEN * 2];// text with start of the next line
676 int nextlinecol = 0; // column where nextline[] starts
677 int nextline_idx = 0; // index in nextline[] where next line
678 // starts
679 int spell_attr = 0; // attributes desired by spelling
680 int word_end = 0; // last byte with same spell_attr
681 static linenr_T checked_lnum = 0; // line number for "checked_col"
682 static int checked_col = 0; // column in "checked_lnum" up to which
683 // there are no spell errors
684 static int cap_col = -1; // column to check for Cap word
685 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
686 int cur_checked_col = 0; // checked column for current line
687#endif
688 int extra_check = 0; // has extra highlighting
689 int multi_attr = 0; // attributes desired by multibyte
690 int mb_l = 1; // multi-byte byte length
691 int mb_c = 0; // decoded multi-byte character
692 int mb_utf8 = FALSE; // screen char is UTF-8 char
693 int u8cc[MAX_MCO]; // composing UTF-8 chars
694#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
695 int filler_lines = 0; // nr of filler lines to be drawn
696 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000697#else
698# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200699#endif
700#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200701 int change_start = MAXCOL; // first col of changed area
702 int change_end = -1; // last col of changed area
703#endif
704 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100705 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200706 int in_multispace = FALSE; // in multiple consecutive spaces
707 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200708#ifdef FEAT_LINEBREAK
709 int need_showbreak = FALSE; // overlong line, skipping first x
710 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100711 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200712#endif
713#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
714 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
715# define LINE_ATTR
716 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100717 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200718#endif
719#ifdef FEAT_SIGNS
720 int sign_present = FALSE;
721 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000722 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200723#endif
724#ifdef FEAT_ARABIC
725 int prev_c = 0; // previous Arabic character
726 int prev_c1 = 0; // first composing char for prev_c
727#endif
728#if defined(LINE_ATTR)
729 int did_line_attr = 0;
730#endif
731#ifdef FEAT_TERMINAL
732 int get_term_attr = FALSE;
733#endif
734#ifdef FEAT_SYN_HL
735 int cul_attr = 0; // set when 'cursorline' active
736
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200737 // margin columns for the screen line, needed for when 'cursorlineopt'
738 // contains "screenline"
739 int left_curline_col = 0;
740 int right_curline_col = 0;
741#endif
742
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200743#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
744 int feedback_col = 0;
745 int feedback_old_attr = -1;
746#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200747
748#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
749 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000750 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200751#endif
752#ifdef FEAT_CONCEAL
753 int syntax_flags = 0;
754 int syntax_seqnr = 0;
755 int prev_syntax_id = 0;
756 int conceal_attr = HL_ATTR(HLF_CONCEAL);
757 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200758 int did_wcol = FALSE;
759 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100760# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200761# define FIX_FOR_BOGUSCOLS \
762 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100763 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100764 wlv.vcol -= wlv.vcol_off; \
765 wlv.vcol_off = 0; \
766 wlv.col -= wlv.boguscols; \
767 old_boguscols = wlv.boguscols; \
768 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200769 }
770#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100771# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772#endif
773
774 if (startrow > endrow) // past the end already!
775 return startrow;
776
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100777 CLEAR_FIELD(wlv);
778
779 wlv.lnum = lnum;
780 wlv.startrow = startrow;
781 wlv.row = startrow;
782 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200783
784 if (!number_only)
785 {
786 // To speed up the loop below, set extra_check when there is linebreak,
787 // trailing white space and/or syntax processing to be done.
788#ifdef FEAT_LINEBREAK
789 extra_check = wp->w_p_lbr;
790#endif
791#ifdef FEAT_SYN_HL
792 if (syntax_present(wp) && !wp->w_s->b_syn_error
793# ifdef SYN_TIME_LIMIT
794 && !wp->w_s->b_syn_slow
795# endif
796 )
797 {
798 // Prepare for syntax highlighting in this line. When there is an
799 // error, stop syntax highlighting.
800 save_did_emsg = did_emsg;
801 did_emsg = FALSE;
802 syntax_start(wp, lnum);
803 if (did_emsg)
804 wp->w_s->b_syn_error = TRUE;
805 else
806 {
807 did_emsg = save_did_emsg;
808#ifdef SYN_TIME_LIMIT
809 if (!wp->w_s->b_syn_slow)
810#endif
811 {
812 has_syntax = TRUE;
813 extra_check = TRUE;
814 }
815 }
816 }
817
818 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100819 wlv.color_cols = wp->w_p_cc_cols;
820 if (wlv.color_cols != NULL)
821 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200822#endif
823
824#ifdef FEAT_TERMINAL
825 if (term_show_buffer(wp->w_buffer))
826 {
827 extra_check = TRUE;
828 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100829 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200830 }
831#endif
832
833#ifdef FEAT_SPELL
834 if (wp->w_p_spell
835 && *wp->w_s->b_p_spl != NUL
836 && wp->w_s->b_langp.ga_len > 0
837 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
838 {
839 // Prepare for spell checking.
840 has_spell = TRUE;
841 extra_check = TRUE;
842
843 // Get the start of the next line, so that words that wrap to the
844 // next line are found too: "et<line-break>al.".
845 // Trick: skip a few chars for C/shell/Vim comments
846 nextline[SPWORDLEN] = NUL;
847 if (lnum < wp->w_buffer->b_ml.ml_line_count)
848 {
849 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
850 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
851 }
852
853 // When a word wrapped from the previous line the start of the
854 // current line is valid.
855 if (lnum == checked_lnum)
856 cur_checked_col = checked_col;
857 checked_lnum = 0;
858
859 // When there was a sentence end in the previous line may require a
860 // word starting with capital in this line. In line 1 always check
861 // the first word.
862 if (lnum != capcol_lnum)
863 cap_col = -1;
864 if (lnum == 1)
865 cap_col = 0;
866 capcol_lnum = 0;
867 }
868#endif
869
870 // handle Visual active in this window
871 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
872 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100873 pos_T *top, *bot;
874
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200875 if (LTOREQ_POS(curwin->w_cursor, VIsual))
876 {
877 // Visual is after curwin->w_cursor
878 top = &curwin->w_cursor;
879 bot = &VIsual;
880 }
881 else
882 {
883 // Visual is before curwin->w_cursor
884 top = &VIsual;
885 bot = &curwin->w_cursor;
886 }
887 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
888 if (VIsual_mode == Ctrl_V)
889 {
890 // block mode
891 if (lnum_in_visual_area)
892 {
893 fromcol = wp->w_old_cursor_fcol;
894 tocol = wp->w_old_cursor_lcol;
895 }
896 }
897 else
898 {
899 // non-block mode
900 if (lnum > top->lnum && lnum <= bot->lnum)
901 fromcol = 0;
902 else if (lnum == top->lnum)
903 {
904 if (VIsual_mode == 'V') // linewise
905 fromcol = 0;
906 else
907 {
908 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
909 if (gchar_pos(top) == NUL)
910 tocol = fromcol + 1;
911 }
912 }
913 if (VIsual_mode != 'V' && lnum == bot->lnum)
914 {
915 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
916 {
917 fromcol = -10;
918 tocol = MAXCOL;
919 }
920 else if (bot->col == MAXCOL)
921 tocol = MAXCOL;
922 else
923 {
924 pos = *bot;
925 if (*p_sel == 'e')
926 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
927 else
928 {
929 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
930 ++tocol;
931 }
932 }
933 }
934 }
935
936 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200937 if (!highlight_match && lnum == curwin->w_cursor.lnum
938 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200939#ifdef FEAT_GUI
940 && !gui.in_use
941#endif
942 )
943 noinvcur = TRUE;
944
945 // if inverting in this line set area_highlighting
946 if (fromcol >= 0)
947 {
948 area_highlighting = TRUE;
949 vi_attr = HL_ATTR(HLF_V);
950#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
951 if ((clip_star.available && !clip_star.owned
952 && clip_isautosel_star())
953 || (clip_plus.available && !clip_plus.owned
954 && clip_isautosel_plus()))
955 vi_attr = HL_ATTR(HLF_VNC);
956#endif
957 }
958 }
959
960 // handle 'incsearch' and ":s///c" highlighting
961 else if (highlight_match
962 && wp == curwin
963 && lnum >= curwin->w_cursor.lnum
964 && lnum <= curwin->w_cursor.lnum + search_match_lines)
965 {
966 if (lnum == curwin->w_cursor.lnum)
967 getvcol(curwin, &(curwin->w_cursor),
968 (colnr_T *)&fromcol, NULL, NULL);
969 else
970 fromcol = 0;
971 if (lnum == curwin->w_cursor.lnum + search_match_lines)
972 {
973 pos.lnum = lnum;
974 pos.col = search_match_endcol;
975 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
976 }
977 else
978 tocol = MAXCOL;
979 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100980 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 tocol = fromcol + 1;
982 area_highlighting = TRUE;
983 vi_attr = HL_ATTR(HLF_I);
984 }
985 }
986
987#ifdef FEAT_DIFF
988 filler_lines = diff_check(wp, lnum);
989 if (filler_lines < 0)
990 {
991 if (filler_lines == -1)
992 {
993 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100994 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200995 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100996 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100998 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 }
1000 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001001 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002 filler_lines = 0;
1003 area_highlighting = TRUE;
1004 }
1005 if (lnum == wp->w_topline)
1006 filler_lines = wp->w_topfill;
1007 filler_todo = filler_lines;
1008#endif
1009
1010#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01001011 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +00001012 if (sign_present)
1013 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014#endif
1015
1016#ifdef LINE_ATTR
1017# ifdef FEAT_SIGNS
1018 // If this line has a sign with line highlighting set line_attr.
1019 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001020 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021# endif
1022# if defined(FEAT_QUICKFIX)
1023 // Highlight the current line in the quickfix window.
1024 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1025 line_attr = HL_ATTR(HLF_QFL);
1026# endif
1027 if (line_attr != 0)
1028 area_highlighting = TRUE;
1029#endif
1030
1031 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1032 ptr = line;
1033
1034#ifdef FEAT_SPELL
1035 if (has_spell && !number_only)
1036 {
1037 // For checking first word with a capital skip white space.
1038 if (cap_col == 0)
1039 cap_col = getwhitecols(line);
1040
1041 // To be able to spell-check over line boundaries copy the end of the
1042 // current line into nextline[]. Above the start of the next line was
1043 // copied to nextline[SPWORDLEN].
1044 if (nextline[SPWORDLEN] == NUL)
1045 {
1046 // No next line or it is empty.
1047 nextlinecol = MAXCOL;
1048 nextline_idx = 0;
1049 }
1050 else
1051 {
1052 v = (long)STRLEN(line);
1053 if (v < SPWORDLEN)
1054 {
1055 // Short line, use it completely and append the start of the
1056 // next line.
1057 nextlinecol = 0;
1058 mch_memmove(nextline, line, (size_t)v);
1059 STRMOVE(nextline + v, nextline + SPWORDLEN);
1060 nextline_idx = v + 1;
1061 }
1062 else
1063 {
1064 // Long line, use only the last SPWORDLEN bytes.
1065 nextlinecol = v - SPWORDLEN;
1066 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1067 nextline_idx = SPWORDLEN + 1;
1068 }
1069 }
1070 }
1071#endif
1072
1073 if (wp->w_p_list)
1074 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001075 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001076 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001077 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001078 || wp->w_lcs_chars.trail
1079 || wp->w_lcs_chars.lead
1080 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001082
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001084 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 {
1086 trailcol = (colnr_T)STRLEN(ptr);
1087 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1088 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001089 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001090 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001091 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001092 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001093 {
1094 leadcol = 0;
1095 while (VIM_ISWHITE(ptr[leadcol]))
1096 ++leadcol;
1097 if (ptr[leadcol] == NUL)
1098 // in a line full of spaces all of them are treated as trailing
1099 leadcol = (colnr_T)0;
1100 else
1101 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001102 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001103 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001104 }
1105
1106 wcr_attr = get_wcr_attr(wp);
1107 if (wcr_attr != 0)
1108 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001109 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110 area_highlighting = TRUE;
1111 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001112
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001113#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001115 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116#endif
1117
1118 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1119 // first character to be displayed.
1120 if (wp->w_p_wrap)
1121 v = wp->w_skipcol;
1122 else
1123 v = wp->w_leftcol;
1124 if (v > 0 && !number_only)
1125 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001126 char_u *prev_ptr = ptr;
1127 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001128 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001129
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001130 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001131 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001132 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001133 charsize = win_lbr_chartabsize(&cts, NULL);
1134 cts.cts_vcol += charsize;
1135 prev_ptr = cts.cts_ptr;
1136 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001138 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001139 ptr = cts.cts_ptr;
1140 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141
1142 // When:
1143 // - 'cuc' is set, or
1144 // - 'colorcolumn' is set, or
1145 // - 'virtualedit' is set, or
1146 // - the visual mode is active,
1147 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001148 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001149#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001150 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151#endif
1152 virtual_active() ||
1153 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001154 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155
1156 // Handle a character that's not completely on the screen: Put ptr at
1157 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001158 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001160 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 ptr = prev_ptr;
1162 // If the character fits on the screen, don't need to skip it.
1163 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001164 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1165 && wlv.col == 0)
1166 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 }
1168
1169 // Adjust for when the inverted text is before the screen,
1170 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001171 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001172 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001173 else if (fromcol >= 0 && fromcol < wlv.vcol)
1174 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001175
1176#ifdef FEAT_LINEBREAK
1177 // When w_skipcol is non-zero, first line needs 'showbreak'
1178 if (wp->w_p_wrap)
1179 need_showbreak = TRUE;
1180#endif
1181#ifdef FEAT_SPELL
1182 // When spell checking a word we need to figure out the start of the
1183 // word and if it's badly spelled or not.
1184 if (has_spell)
1185 {
1186 int len;
1187 colnr_T linecol = (colnr_T)(ptr - line);
1188 hlf_T spell_hlf = HLF_COUNT;
1189
1190 pos = wp->w_cursor;
1191 wp->w_cursor.lnum = lnum;
1192 wp->w_cursor.col = linecol;
1193 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1194
1195 // spell_move_to() may call ml_get() and make "line" invalid
1196 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1197 ptr = line + linecol;
1198
1199 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1200 {
1201 // no bad word found at line start, don't check until end of a
1202 // word
1203 spell_hlf = HLF_COUNT;
1204 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1205 }
1206 else
1207 {
1208 // bad word found, use attributes until end of word
1209 word_end = wp->w_cursor.col + len + 1;
1210
1211 // Turn index into actual attributes.
1212 if (spell_hlf != HLF_COUNT)
1213 spell_attr = highlight_attr[spell_hlf];
1214 }
1215 wp->w_cursor = pos;
1216
1217# ifdef FEAT_SYN_HL
1218 // Need to restart syntax highlighting for this line.
1219 if (has_syntax)
1220 syntax_start(wp, lnum);
1221# endif
1222 }
1223#endif
1224 }
1225
1226 // Correct highlighting for cursor that can't be disabled.
1227 // Avoids having to check this for each character.
1228 if (fromcol >= 0)
1229 {
1230 if (noinvcur)
1231 {
1232 if ((colnr_T)fromcol == wp->w_virtcol)
1233 {
1234 // highlighting starts at cursor, let it start just after the
1235 // cursor
1236 fromcol_prev = fromcol;
1237 fromcol = -1;
1238 }
1239 else if ((colnr_T)fromcol < wp->w_virtcol)
1240 // restart highlighting after the cursor
1241 fromcol_prev = wp->w_virtcol;
1242 }
1243 if (fromcol >= tocol)
1244 fromcol = -1;
1245 }
1246
1247#ifdef FEAT_SEARCH_EXTRA
1248 if (!number_only)
1249 {
1250 v = (long)(ptr - line);
1251 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1252 &line, &screen_search_hl,
1253 &search_attr);
1254 ptr = line + v; // "line" may have been updated
1255 }
1256#endif
1257
1258#ifdef FEAT_SYN_HL
1259 // Cursor line highlighting for 'cursorline' in the current window.
1260 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1261 {
1262 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001263 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 if (!(wp == curwin && VIsual_active)
1265 && wp->w_p_culopt_flags != CULOPT_NBR)
1266 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001267 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1269
1270 // Only set line_attr here when "screenline" is not present in
1271 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001272 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001273 {
1274 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001275# ifdef FEAT_SIGNS
1276 // Combine the 'cursorline' and sign highlighting, depending on
1277 // the sign priority.
1278 if (sign_present && sattr.sat_linehl > 0)
1279 {
1280 if (sattr.sat_priority >= 100)
1281 line_attr = hl_combine_attr(cul_attr, line_attr);
1282 else
1283 line_attr = hl_combine_attr(line_attr, cul_attr);
1284 }
1285 else
1286# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001287# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001288 // let the line attribute overrule 'cursorline', otherwise
1289 // it disappears when both have background set;
1290 // 'cursorline' can use underline or bold to make it show
1291 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001292# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001293 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001294# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 }
1296 else
1297 {
1298 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1300 }
1301 area_highlighting = TRUE;
1302 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 }
1304#endif
1305
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001306#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 {
1308 char_u *prop_start;
1309
1310 text_prop_count = get_text_props(wp->w_buffer, lnum,
1311 &prop_start, FALSE);
1312 if (text_prop_count > 0)
1313 {
1314 // Make a copy of the properties, so that they are properly
1315 // aligned.
1316 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1317 if (text_props != NULL)
1318 mch_memmove(text_props, prop_start,
1319 text_prop_count * sizeof(textprop_T));
1320
1321 // Allocate an array for the indexes.
1322 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001323 if (text_prop_idxs == NULL)
1324 VIM_CLEAR(text_props);
1325
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 area_highlighting = TRUE;
1327 extra_check = TRUE;
1328 }
1329 }
1330#endif
1331
Bram Moolenaar1306b362022-08-06 15:59:06 +01001332 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333
1334 // Repeat for the whole displayed line.
1335 for (;;)
1336 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001337 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001339 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340#endif
1341#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001342 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001344
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001346 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001348#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001349 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001350 {
1351 cul_attr = 0;
1352 line_attr = line_attr_save;
1353 }
1354#endif
1355
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001357 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001359 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 if (cmdwin_type != 0 && wp == curwin)
1361 {
1362 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001363 wlv.n_extra = 1;
1364 wlv.c_extra = cmdwin_type;
1365 wlv.c_final = NUL;
1366 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 }
1368 }
1369#endif
1370
1371#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001372 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 {
1374 int fdc = compute_foldcolumn(wp, 0);
1375
Bram Moolenaar1306b362022-08-06 15:59:06 +01001376 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 if (fdc > 0)
1378 {
1379 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1380 // already be in use.
1381 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001382 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 if (p_extra_free != NULL)
1384 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001385 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001386 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001387 p_extra_free[wlv.n_extra] = NUL;
1388 wlv.p_extra = p_extra_free;
1389 wlv.c_extra = NUL;
1390 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001391 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001392 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001393 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1394 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001395 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001396 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 }
1398 }
1399 }
1400#endif
1401
1402#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001403 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001405 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 // Show the sign column when there are any signs in this
1407 // buffer or when using Netbeans.
1408 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001409 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1410 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 }
1412#endif
1413
Bram Moolenaar1306b362022-08-06 15:59:06 +01001414 if (wlv.draw_state == WL_NR - 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_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 // Display the absolute or relative line number. After the
1418 // first fill with blanks when the 'n' flag isn't in 'cpo'
1419 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001420 && (wlv.row == startrow + filler_lines
1421 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 {
1423#ifdef FEAT_SIGNS
1424 // If 'signcolumn' is set to 'number' and a sign is present
1425 // in 'lnum', then display the sign instead of the line
1426 // number.
1427 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1428 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001429 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1430 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 else
1432#endif
1433 {
1434 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001435 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 {
1437 long num;
1438 char *fmt = "%*ld ";
1439
1440 if (wp->w_p_nu && !wp->w_p_rnu)
1441 // 'number' + 'norelativenumber'
1442 num = (long)lnum;
1443 else
1444 {
1445 // 'relativenumber', don't use negative numbers
1446 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1447 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1448 {
1449 // 'number' + 'relativenumber'
1450 num = lnum;
1451 fmt = "%-*ld ";
1452 }
1453 }
1454
1455 sprintf((char *)extra, fmt,
1456 number_width(wp), num);
1457 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001458 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1459 ++wlv.p_extra)
1460 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461#ifdef FEAT_RIGHTLEFT
1462 if (wp->w_p_rl) // reverse line numbers
1463 {
1464 char_u *p1, *p2;
1465 int t;
1466
1467 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001468 p2 = skipwhite(extra);
1469 p2 = skiptowhite(p2) - 1;
1470 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 {
1472 t = *p1;
1473 *p1 = *p2;
1474 *p2 = t;
1475 }
1476 }
1477#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001478 wlv.p_extra = extra;
1479 wlv.c_extra = NUL;
1480 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 }
1482 else
1483 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001484 wlv.c_extra = ' ';
1485 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001487 wlv.n_extra = number_width(wp) + 1;
1488 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489#ifdef FEAT_SYN_HL
1490 // When 'cursorline' is set highlight the line number of
1491 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001492 // When 'cursorlineopt' does not have "line" only
1493 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 // TODO: Can we use CursorLine instead of CursorLineNr
1495 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001496 if (wp->w_p_cul
1497 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001499 && (wlv.row == startrow + filler_lines
1500 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001501 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001502 wlv.char_attr = hl_combine_attr(wcr_attr,
1503 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001504#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001505 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1506 && HL_ATTR(HLF_LNA) != 0)
1507 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001508 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001509 HL_ATTR(HLF_LNA));
1510 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1511 && HL_ATTR(HLF_LNB) != 0)
1512 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001513 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001514 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 }
James McCoya80aad72021-12-22 19:45:28 +00001516#ifdef FEAT_SIGNS
1517 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001518 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001519#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 }
1521 }
1522
1523#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001524 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1525 && wlv.n_extra == 0
1526 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001528 wlv.draw_state = WL_BRI;
1529 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1530 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001532 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533
1534 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001535 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001537 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001539 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540# ifdef FEAT_DIFF
1541 && filler_lines == 0
1542# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001543# ifdef FEAT_PROP_POPUP
1544 && !dont_use_showbreak
1545# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546 )
1547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001548 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001550 if (wlv.diff_hlf != (hlf_T)0)
1551 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001553 wlv.p_extra = NULL;
1554 wlv.c_extra = ' ';
1555 wlv.c_final = NUL;
1556 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001558 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001559 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001560 wlv.n_extra -= win_col_off2(wp);
1561 if (wlv.n_extra < 0)
1562 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001563 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001564 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001565 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 // Correct end of highlighted area for 'breakindent',
1567 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001568 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001569 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 }
1571 }
1572#endif
1573
1574#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001575 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001577 char_u *sbr;
1578
Bram Moolenaar1306b362022-08-06 15:59:06 +01001579 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580# ifdef FEAT_DIFF
1581 if (filler_todo > 0)
1582 {
1583 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001584 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001586 wlv.c_extra = '-';
1587 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 }
1589 else
1590 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001591 wlv.c_extra = wp->w_fill_chars.diff;
1592 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 }
1594# ifdef FEAT_RIGHTLEFT
1595 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001596 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 else
1598# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001599 wlv.n_extra = wp->w_width - wlv.col;
1600 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 }
1602# endif
1603# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001604 sbr = get_showbreak_value(wp);
1605 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 {
1607 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001608 wlv.p_extra = sbr;
1609 wlv.c_extra = NUL;
1610 wlv.c_final = NUL;
1611 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001612 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1613 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001614 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 // Correct end of highlighted area for 'showbreak',
1616 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001617 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001618 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001620 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1621 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622# ifdef FEAT_SYN_HL
1623 // combine 'showbreak' with 'cursorline'
1624 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001625 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1626 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627# endif
1628 }
1629# endif
1630 }
1631#endif
1632
Bram Moolenaar1306b362022-08-06 15:59:06 +01001633 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001635 wlv.draw_state = WL_LINE;
1636 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 {
1638 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001639 wlv.n_extra = wlv.saved_n_extra;
1640 wlv.c_extra = wlv.saved_c_extra;
1641 wlv.c_final = wlv.saved_c_final;
1642 wlv.p_extra = wlv.saved_p_extra;
1643 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 }
1645 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001646 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 }
1648 }
1649#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001650 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001651 && wlv.vcol >= left_curline_col
1652 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001654 cul_attr = HL_ATTR(HLF_CUL);
1655 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001656 }
1657#endif
1658
1659 // When still displaying '$' of change command, stop at cursor.
1660 // When only displaying the (relative) line number and that's done,
1661 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001662 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001663 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001664 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665#ifdef FEAT_DIFF
1666 && filler_todo <= 0
1667#endif
1668 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001670 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1671 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 // Pretend we have finished updating the window. Except when
1673 // 'cursorcolumn' is set.
1674#ifdef FEAT_SYN_HL
1675 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001676 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677 else
1678#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001679 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 break;
1681 }
1682
Bram Moolenaar1306b362022-08-06 15:59:06 +01001683 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 {
1685 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001686 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001687 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 && (*mb_ptr2cells)(ptr) > 1)
1689 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001690 && vcol_prev < wlv.vcol // not at margin
1691 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 area_attr = vi_attr; // start highlighting
1693 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001694 && (wlv.vcol == tocol
1695 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 area_attr = 0; // stop highlighting
1697
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001698#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 if (text_props != NULL)
1700 {
1701 int pi;
1702 int bcol = (int)(ptr - line);
1703
Bram Moolenaar1306b362022-08-06 15:59:06 +01001704 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001705# ifdef FEAT_LINEBREAK
1706 && !in_linebreak
1707# endif
1708 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 --bcol; // still working on the previous char, e.g. Tab
1710
1711 // Check if any active property ends.
1712 for (pi = 0; pi < text_props_active; ++pi)
1713 {
1714 int tpi = text_prop_idxs[pi];
1715
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001716 if (text_props[tpi].tp_col != MAXCOL
1717 && bcol >= text_props[tpi].tp_col - 1
1718 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 {
1720 if (pi + 1 < text_props_active)
1721 mch_memmove(text_prop_idxs + pi,
1722 text_prop_idxs + pi + 1,
1723 sizeof(int)
1724 * (text_props_active - (pi + 1)));
1725 --text_props_active;
1726 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001727# ifdef FEAT_LINEBREAK
1728 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001729 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001730 syntax_attr = 0;
1731# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 }
1733 }
1734
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001735# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001736 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001737 // not on the next char yet, don't start another prop
1738 --bcol;
1739# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001741 // With 'nowrap' and not in the first screen line only "below"
1742 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001744 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001745 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001746 && (wp->w_p_wrap
1747 || wlv.row == startrow
1748 || (text_props[text_prop_next].tp_flags
1749 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001750 || (bcol == 0 &&
1751 (text_props[text_prop_next].tp_flags
1752 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001753 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001754 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001755 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001756 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1757 {
1758 // first display the '$' after the line
1759 text_prop_follows = TRUE;
1760 break;
1761 }
1762 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001763 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001764 + text_props[text_prop_next].tp_len)
1765 text_prop_idxs[text_props_active++] = text_prop_next;
1766 ++text_prop_next;
1767 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001769 if (wlv.n_extra == 0 || !extra_for_textprop)
1770 {
1771 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001772 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001773 text_prop_flags = 0;
1774 text_prop_type = NULL;
1775 text_prop_id = 0;
1776 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001779 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001780 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001781 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001782
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 // Sort the properties on priority and/or starting last.
1784 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001785 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001786 sort_text_props(wp->w_buffer, text_props,
1787 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788
1789 for (pi = 0; pi < text_props_active; ++pi)
1790 {
1791 int tpi = text_prop_idxs[pi];
1792 proptype_T *pt = text_prop_type_by_id(
1793 wp->w_buffer, text_props[tpi].tp_type);
1794
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001795 if (pt != NULL && (pt->pt_hl_id > 0
1796 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001797 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001799 if (pt->pt_hl_id > 0)
1800 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 text_prop_type = pt;
1802 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001803 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001804 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001805 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001806 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001807 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 }
1809 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001810 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001811 && -text_prop_id
1812 <= wp->w_buffer->b_textprop_text.ga_len)
1813 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001814 textprop_T *tp = &text_props[used_tpi];
1815 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001816 ->b_textprop_text.ga_data)[
1817 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001818
1819 // reset the ID in the copy to avoid it being used
1820 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001821 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001822
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001823 if (p != NULL)
1824 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001825 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001826 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001827 int above = (tp->tp_flags
1828 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001829 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001830 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001831 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1832 int padding = tp->tp_col == MAXCOL
1833 && tp->tp_len > 1
1834 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001835
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001836 // Insert virtual text before the current
1837 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001838 wlv.p_extra = p;
1839 wlv.c_extra = NUL;
1840 wlv.c_final = NUL;
1841 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001842 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001843 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001844 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001845 saved_search_attr = search_attr;
1846 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001847 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001848 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001849 if (*ptr == NUL)
1850 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001851 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001852#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001853 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001854 {
1855 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001856 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001857 need_showbreak = FALSE;
1858 dont_use_showbreak = TRUE;
1859 }
1860#endif
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001861 if ((right || above || below || !wrap || padding > 0)
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001862 && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001863 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001864 char_u *prev_p_extra = wlv.p_extra;
1865 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001866
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001867 // Take care of padding, right-align and
1868 // truncation.
1869 // Shared with win_lbr_chartabsize(), must do
1870 // exactly the same.
1871 start_line = text_prop_position(wp, tp,
1872 wlv.col,
1873 &wlv.n_extra, &wlv.p_extra,
1874 &n_attr, &n_attr_skip);
1875 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001876 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001877 // wlv.p_extra was allocated
1878 vim_free(p_extra_free2);
1879 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001880 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001881
1882 // When 'wrap' is off then for "below" we need
1883 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001884 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001885 {
1886 draw_screen_line(wp, &wlv);
1887
1888 // When line got too long for screen break
1889 // here.
1890 if (wlv.row == endrow)
1891 {
1892 ++wlv.row;
1893 break;
1894 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 win_line_start(wp, &wlv, TRUE);
1896 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001897 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001898 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001899 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001900
1901 // If another text prop follows the condition below at
1902 // the last window column must know.
1903 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001904 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001906 else if (text_prop_next < text_prop_count
1907 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001908 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1909 || (!wp->w_p_wrap
1910 && wlv.col == wp->w_width - 1
1911 && (text_props[text_prop_next].tp_flags
1912 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001913 // When at last-but-one character and a text property
1914 // follows after it, we may need to flush the line after
1915 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001916 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001917 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 }
1919#endif
1920
Bram Moolenaare38fc862022-08-11 17:24:50 +01001921#ifdef FEAT_SEARCH_EXTRA
1922 if (wlv.n_extra == 0)
1923 {
1924 // Check for start/end of 'hlsearch' and other matches.
1925 // After end, check for start/end of next match.
1926 // When another match, have to check for start again.
1927 v = (long)(ptr - line);
1928 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1929 &screen_search_hl, &has_match_conc,
1930 &match_conc, did_line_attr, lcs_eol_one,
1931 &on_last_col);
1932 ptr = line + v; // "line" may have been changed
1933 prev_ptr = ptr;
1934
1935 // Do not allow a conceal over EOL otherwise EOL will be missed
1936 // and bad things happen.
1937 if (*ptr == NUL)
1938 has_match_conc = 0;
1939 }
1940#endif
1941
1942#ifdef FEAT_DIFF
1943 if (wlv.diff_hlf != (hlf_T)0)
1944 {
1945 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1946 && wlv.n_extra == 0)
1947 wlv.diff_hlf = HLF_TXD; // changed text
1948 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1949 && wlv.n_extra == 0)
1950 wlv.diff_hlf = HLF_CHD; // changed line
1951 line_attr = HL_ATTR(wlv.diff_hlf);
1952 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1953 && wp->w_p_culopt_flags != CULOPT_NBR
1954 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1955 && wlv.vcol <= right_curline_col)))
1956 line_attr = hl_combine_attr(
1957 line_attr, HL_ATTR(HLF_CUL));
1958 }
1959#endif
1960
Bram Moolenaara74fda62019-10-19 17:38:03 +02001961#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001962 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001963 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001964 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001965# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001966 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001967 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001968# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001969 // Get syntax attribute.
1970 if (has_syntax)
1971 {
1972 // Get the syntax attribute for the character. If there
1973 // is an error, disable syntax highlighting.
1974 save_did_emsg = did_emsg;
1975 did_emsg = FALSE;
1976
1977 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001978 if (v == prev_syntax_col)
1979 // at same column again
1980 syntax_attr = prev_syntax_attr;
1981 else
1982 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001983# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001984 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001985# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001986 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001987# ifdef FEAT_SPELL
1988 has_spell ? &can_spell :
1989# endif
1990 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001991 prev_syntax_col = v;
1992 prev_syntax_attr = syntax_attr;
1993 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001994
Bram Moolenaar34390282019-10-16 14:38:26 +02001995 if (did_emsg)
1996 {
1997 wp->w_s->b_syn_error = TRUE;
1998 has_syntax = FALSE;
1999 syntax_attr = 0;
2000 }
2001 else
2002 did_emsg = save_did_emsg;
2003# ifdef SYN_TIME_LIMIT
2004 if (wp->w_s->b_syn_slow)
2005 has_syntax = FALSE;
2006# endif
2007
2008 // Need to get the line again, a multi-line regexp may
2009 // have made it invalid.
2010 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2011 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002012 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002013# ifdef FEAT_CONCEAL
2014 // no concealing past the end of the line, it interferes
2015 // with line highlighting
2016 if (*ptr == NUL)
2017 syntax_flags = 0;
2018 else
2019 syntax_flags = get_syntax_info(&syntax_seqnr);
2020# endif
2021 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002022 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002023# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002024 // Combine text property highlight into syntax highlight.
2025 if (text_prop_type != NULL)
2026 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002027 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002028 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2029 else
2030 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002031 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002032 }
2033# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002034#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002035
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002036 // Decide which of the highlight attributes to use.
2037 attr_pri = TRUE;
2038#ifdef LINE_ATTR
2039 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002040 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002041 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002042 if (!highlight_match)
2043 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002044 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002045# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002046 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002047# endif
2048 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002050 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002051 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002052# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002053 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002054# endif
2055 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002057 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2058 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059 {
2060 // Use line_attr when not in the Visual or 'incsearch' area
2061 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002062# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002063 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002064# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002065 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002066# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067 attr_pri = FALSE;
2068 }
2069#else
2070 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002071 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002072 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002073 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074#endif
2075 else
2076 {
2077 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002079 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002080#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002081 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002082#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002084#ifdef FEAT_PROP_POPUP
2085 // override with text property highlight when "override" is TRUE
2086 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002087 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002088#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002090
2091 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002092 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002093 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002094 if (wlv.char_attr == 0)
2095 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002096 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002097 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002098 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099
2100 // Get the next character to put on the screen.
2101
2102 // The "p_extra" points to the extra stuff that is inserted to
2103 // represent special characters (non-printable stuff) and other
2104 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002105 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2107 // "p_extra[n_extra]".
2108 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002109 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002111 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002112 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002113 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2114 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002115 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2116 if (enc_utf8 && utf_char2len(c) > 1)
2117 {
2118 mb_utf8 = TRUE;
2119 u8cc[0] = 0;
2120 c = 0xc0;
2121 }
2122 else
2123 mb_utf8 = FALSE;
2124 }
2125 else
2126 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002127 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 if (has_mbyte)
2129 {
2130 mb_c = c;
2131 if (enc_utf8)
2132 {
2133 // If the UTF-8 character is more than one byte:
2134 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002135 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002136 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 mb_l = 1;
2139 else if (mb_l > 1)
2140 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002141 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002142 mb_utf8 = TRUE;
2143 c = 0xc0;
2144 }
2145 }
2146 else
2147 {
2148 // if this is a DBCS character, put it in "mb_c"
2149 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002150 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 mb_l = 1;
2152 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002154 }
2155 if (mb_l == 0) // at the NUL at end-of-line
2156 mb_l = 1;
2157
2158 // If a double-width char doesn't fit display a '>' in the
2159 // last column.
2160 if ((
2161# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002162 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002164 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 && (*mb_char2cells)(mb_c) == 2)
2166 {
2167 c = '>';
2168 mb_c = c;
2169 mb_l = 1;
2170 mb_utf8 = FALSE;
2171 multi_attr = HL_ATTR(HLF_AT);
2172#ifdef FEAT_SYN_HL
2173 if (cul_attr)
2174 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2175#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002176 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002177
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002178 // put the pointer back to output the double-width
2179 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002180 ++wlv.n_extra;
2181 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 }
2183 else
2184 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002185 wlv.n_extra -= mb_l - 1;
2186 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 }
2188 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002189 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002190 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002192#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002193 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002194 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002195 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002196 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002197 if (search_attr == 0)
2198 search_attr = saved_search_attr;
2199 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002200#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002201 }
2202 else
2203 {
2204#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002205 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002206#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002207 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 // Get a character from the line itself.
2210 c = *ptr;
2211#ifdef FEAT_LINEBREAK
2212 c0 = *ptr;
2213#endif
2214 if (has_mbyte)
2215 {
2216 mb_c = c;
2217 if (enc_utf8)
2218 {
2219 // If the UTF-8 character is more than one byte: Decode it
2220 // into "mb_c".
2221 mb_l = utfc_ptr2len(ptr);
2222 mb_utf8 = FALSE;
2223 if (mb_l > 1)
2224 {
2225 mb_c = utfc_ptr2char(ptr, u8cc);
2226 // Overlong encoded ASCII or ASCII with composing char
2227 // is displayed normally, except a NUL.
2228 if (mb_c < 0x80)
2229 {
2230 c = mb_c;
2231#ifdef FEAT_LINEBREAK
2232 c0 = mb_c;
2233#endif
2234 }
2235 mb_utf8 = TRUE;
2236
2237 // At start of the line we can have a composing char.
2238 // Draw it as a space with a composing char.
2239 if (utf_iscomposing(mb_c))
2240 {
2241 int i;
2242
2243 for (i = Screen_mco - 1; i > 0; --i)
2244 u8cc[i] = u8cc[i - 1];
2245 u8cc[0] = mb_c;
2246 mb_c = ' ';
2247 }
2248 }
2249
2250 if ((mb_l == 1 && c >= 0x80)
2251 || (mb_l >= 1 && mb_c == 0)
2252 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2253 {
2254 // Illegal UTF-8 byte: display as <xx>.
2255 // Non-BMP character : display as ? or fullwidth ?.
2256 transchar_hex(extra, mb_c);
2257# ifdef FEAT_RIGHTLEFT
2258 if (wp->w_p_rl) // reverse
2259 rl_mirror(extra);
2260# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002261 wlv.p_extra = extra;
2262 c = *wlv.p_extra;
2263 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002265 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2266 wlv.c_extra = NUL;
2267 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002268 if (area_attr == 0 && search_attr == 0)
2269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002271 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002272 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002273 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 }
2275 }
2276 else if (mb_l == 0) // at the NUL at end-of-line
2277 mb_l = 1;
2278#ifdef FEAT_ARABIC
2279 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2280 {
2281 // Do Arabic shaping.
2282 int pc, pc1, nc;
2283 int pcc[MAX_MCO];
2284
2285 // The idea of what is the previous and next
2286 // character depends on 'rightleft'.
2287 if (wp->w_p_rl)
2288 {
2289 pc = prev_c;
2290 pc1 = prev_c1;
2291 nc = utf_ptr2char(ptr + mb_l);
2292 prev_c1 = u8cc[0];
2293 }
2294 else
2295 {
2296 pc = utfc_ptr2char(ptr + mb_l, pcc);
2297 nc = prev_c;
2298 pc1 = pcc[0];
2299 }
2300 prev_c = mb_c;
2301
2302 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2303 }
2304 else
2305 prev_c = mb_c;
2306#endif
2307 }
2308 else // enc_dbcs
2309 {
2310 mb_l = MB_BYTE2LEN(c);
2311 if (mb_l == 0) // at the NUL at end-of-line
2312 mb_l = 1;
2313 else if (mb_l > 1)
2314 {
2315 // We assume a second byte below 32 is illegal.
2316 // Hopefully this is OK for all double-byte encodings!
2317 if (ptr[1] >= 32)
2318 mb_c = (c << 8) + ptr[1];
2319 else
2320 {
2321 if (ptr[1] == NUL)
2322 {
2323 // head byte at end of line
2324 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002325 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326 }
2327 else
2328 {
2329 // illegal tail byte
2330 mb_l = 2;
2331 STRCPY(extra, "XX");
2332 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002333 wlv.p_extra = extra;
2334 wlv.n_extra = (int)STRLEN(extra) - 1;
2335 wlv.c_extra = NUL;
2336 wlv.c_final = NUL;
2337 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002338 if (area_attr == 0 && search_attr == 0)
2339 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002340 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002341 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002342 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002343 // save current attr
2344 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 }
2346 mb_c = c;
2347 }
2348 }
2349 }
2350 // If a double-width char doesn't fit display a '>' in the
2351 // last column; the character is displayed at the start of the
2352 // next line.
2353 if ((
2354# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002355 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002357 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358 && (*mb_char2cells)(mb_c) == 2)
2359 {
2360 c = '>';
2361 mb_c = c;
2362 mb_utf8 = FALSE;
2363 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002364 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365 // Put pointer back so that the character will be
2366 // displayed at the start of the next line.
2367 --ptr;
2368#ifdef FEAT_CONCEAL
2369 did_decrement_ptr = TRUE;
2370#endif
2371 }
2372 else if (*ptr != NUL)
2373 ptr += mb_l - 1;
2374
2375 // If a double-width char doesn't fit at the left side display
2376 // a '<' in the first column. Don't do this for unprintable
2377 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002380 wlv.n_extra = 1;
2381 wlv.c_extra = MB_FILLER_CHAR;
2382 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002383 c = ' ';
2384 if (area_attr == 0 && search_attr == 0)
2385 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002386 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002387 extra_attr = hl_combine_attr(
2388 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002389 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 }
2391 mb_c = c;
2392 mb_utf8 = FALSE;
2393 mb_l = 1;
2394 }
2395
2396 }
2397 ++ptr;
2398
2399 if (extra_check)
2400 {
2401#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 // Check spelling (unless at the end of the line).
2403 // Only do this when there is no syntax highlighting, the
2404 // @Spell cluster is not used or the current syntax item
2405 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002406 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 if (has_spell && v >= word_end && v > cur_checked_col)
2408 {
2409 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002410 // do not calculate cap_col at the end of the line or when
2411 // only white space is following
2412 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002413# ifdef FEAT_SYN_HL
2414 !has_syntax ||
2415# endif
2416 can_spell))
2417 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002418 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002419 int len;
2420 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002421
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002424
2425 // Use nextline[] if possible, it has the start of the
2426 // next line concatenated.
2427 if ((prev_ptr - line) - nextlinecol >= 0)
2428 p = nextline + (prev_ptr - line) - nextlinecol;
2429 else
2430 p = prev_ptr;
2431 cap_col -= (int)(prev_ptr - line);
2432 len = spell_check(wp, p, &spell_hlf, &cap_col,
2433 nochange);
2434 word_end = v + len;
2435
2436 // In Insert mode only highlight a word that
2437 // doesn't touch the cursor.
2438 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002439 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440 && wp->w_cursor.lnum == lnum
2441 && wp->w_cursor.col >=
2442 (colnr_T)(prev_ptr - line)
2443 && wp->w_cursor.col < (colnr_T)word_end)
2444 {
2445 spell_hlf = HLF_COUNT;
2446 spell_redraw_lnum = lnum;
2447 }
2448
2449 if (spell_hlf == HLF_COUNT && p != prev_ptr
2450 && (p - nextline) + len > nextline_idx)
2451 {
2452 // Remember that the good word continues at the
2453 // start of the next line.
2454 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002455 checked_col = (int)((p - nextline)
2456 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 }
2458
2459 // Turn index into actual attributes.
2460 if (spell_hlf != HLF_COUNT)
2461 spell_attr = highlight_attr[spell_hlf];
2462
2463 if (cap_col > 0)
2464 {
2465 if (p != prev_ptr
2466 && (p - nextline) + cap_col >= nextline_idx)
2467 {
2468 // Remember that the word in the next line
2469 // must start with a capital.
2470 capcol_lnum = lnum + 1;
2471 cap_col = (int)((p - nextline) + cap_col
2472 - nextline_idx);
2473 }
2474 else
2475 // Compute the actual column.
2476 cap_col += (int)(prev_ptr - line);
2477 }
2478 }
2479 }
2480 if (spell_attr != 0)
2481 {
2482 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002483 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2484 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 wlv.char_attr = hl_combine_attr(spell_attr,
2487 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 }
2489#endif
2490#ifdef FEAT_LINEBREAK
2491 // Found last space before word: check for line break.
2492 if (wp->w_p_lbr && c0 == c
2493 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2494 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002495 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2496 : 0;
2497 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002498 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002500 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002501# ifdef FEAT_PROP_POPUP
2502 // do not want virtual text counted here
2503 cts.cts_has_prop_with_text = FALSE;
2504# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002506 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002507
2508 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002509 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002510 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002511 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2513 if (wlv.n_extra < 0)
2514 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002515 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002516 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002517 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002518 // line break, but for TABs the highlighting should
2519 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002520 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002521
Bram Moolenaar1306b362022-08-06 15:59:06 +01002522 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002524 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002525 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 wp->w_buffer->b_p_vts_array) - 1;
2527# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002528 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002529 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530# endif
2531
Bram Moolenaar1306b362022-08-06 15:59:06 +01002532 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2533 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002534# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002535 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002536 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002537# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 if (VIM_ISWHITE(c))
2539 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002540# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 if (c == TAB)
2542 // See "Tab alignment" below.
2543 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002544# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 if (!wp->w_p_list)
2546 c = ' ';
2547 }
2548 }
2549#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002550 in_multispace = c == ' '
2551 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2552 if (!in_multispace)
2553 multispace_pos = 0;
2554
Bram Moolenaareed9d462021-02-15 20:38:25 +01002555 // 'list': Change char 160 to 'nbsp' and space to 'space'
2556 // setting in 'listchars'. But not when the character is
2557 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 if (wp->w_p_list
2559 && ((((c == 160 && mb_l == 1)
2560 || (mb_utf8
2561 && ((mb_c == 160 && mb_l == 2)
2562 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002563 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 || (c == ' '
2565 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002566 && (wp->w_lcs_chars.space
2567 || (in_multispace
2568 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002569 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 && ptr - line <= trailcol)))
2571 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002572 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2573 {
2574 c = wp->w_lcs_chars.multispace[multispace_pos++];
2575 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2576 multispace_pos = 0;
2577 }
2578 else
2579 c = (c == ' ') ? wp->w_lcs_chars.space
2580 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 if (area_attr == 0 && search_attr == 0)
2582 {
2583 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002584 extra_attr = hl_combine_attr(wlv.win_attr,
2585 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002587 }
2588 mb_c = c;
2589 if (enc_utf8 && utf_char2len(c) > 1)
2590 {
2591 mb_utf8 = TRUE;
2592 u8cc[0] = 0;
2593 c = 0xc0;
2594 }
2595 else
2596 mb_utf8 = FALSE;
2597 }
2598
zeertzjq2e7cba32022-06-10 15:30:32 +01002599 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2600 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002602 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2603 && wp->w_lcs_chars.leadmultispace != NULL)
2604 {
2605 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002606 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2607 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002608 multispace_pos = 0;
2609 }
2610
2611 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2612 c = wp->w_lcs_chars.trail;
2613
2614 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2615 c = wp->w_lcs_chars.lead;
2616
zeertzjq2e7cba32022-06-10 15:30:32 +01002617 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002618 c = wp->w_lcs_chars.space;
2619
2620
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621 if (!attr_pri)
2622 {
2623 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002624 extra_attr = hl_combine_attr(wlv.win_attr,
2625 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002626 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 }
2628 mb_c = c;
2629 if (enc_utf8 && utf_char2len(c) > 1)
2630 {
2631 mb_utf8 = TRUE;
2632 u8cc[0] = 0;
2633 c = 0xc0;
2634 }
2635 else
2636 mb_utf8 = FALSE;
2637 }
2638 }
2639
2640 // Handling of non-printable characters.
2641 if (!vim_isprintc(c))
2642 {
2643 // when getting a character from the file, we may have to
2644 // turn it into something else on the way to putting it
2645 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002646 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 {
2648 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002649 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002650#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002651 char_u *sbr = get_showbreak_value(wp);
2652
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653 // only adjust the tab_len, when at the first column
2654 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002655 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2656 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657#endif
2658 // tab amount depends on current column
2659#ifdef FEAT_VARTABS
2660 tab_len = tabstop_padding(vcol_adjusted,
2661 wp->w_buffer->b_p_ts,
2662 wp->w_buffer->b_p_vts_array) - 1;
2663#else
2664 tab_len = (int)wp->w_buffer->b_p_ts
2665 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2666#endif
2667
2668#ifdef FEAT_LINEBREAK
2669 if (!wp->w_p_lbr || !wp->w_p_list)
2670#endif
2671 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002672 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673#ifdef FEAT_LINEBREAK
2674 else
2675 {
2676 char_u *p;
2677 int len;
2678 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002679 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002681# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002682 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002684 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002685
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002686 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002687 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002688 && old_boguscols > 0
2689 && wlv.n_extra > tab_len)
2690 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002691# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002692 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002694 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002695 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002696 if (wp->w_lcs_chars.tab3)
2697 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002698 if (wlv.n_extra > 0)
2699 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002700 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002702 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002704 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002706 vim_memset(p, ' ', len);
2707 p[len] = NUL;
2708 vim_free(p_extra_free);
2709 p_extra_free = p;
2710 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002712 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002714 if (*p == NUL)
2715 {
2716 tab_len = i;
2717 break;
2718 }
2719
2720 // if tab3 is given, use it for the last char
2721 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2722 lcs = wp->w_lcs_chars.tab3;
2723 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002724 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002725 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002726 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002727 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002728# ifdef FEAT_CONCEAL
2729 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2730 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002731 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002732 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002733# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735 }
2736#endif
2737#ifdef FEAT_CONCEAL
2738 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002739 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740
2741 // Tab alignment should be identical regardless of
2742 // 'conceallevel' value. So tab compensates of all
2743 // previous concealed characters, and thus resets
2744 // vcol_off and boguscols accumulated so far in the
2745 // line. Note that the tab can be longer than
2746 // 'tabstop' when there are concealed characters.
2747 FIX_FOR_BOGUSCOLS;
2748
2749 // Make sure, the highlighting for the tab char will be
2750 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002751 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002752 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002753 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 tab_len += vc_saved;
2755 }
2756#endif
2757 mb_utf8 = FALSE; // don't draw as UTF-8
2758 if (wp->w_p_list)
2759 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002760 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002761 ? wp->w_lcs_chars.tab3
2762 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763#ifdef FEAT_LINEBREAK
2764 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002765 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 else
2767#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002768 wlv.c_extra = wp->w_lcs_chars.tab2;
2769 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002771 extra_attr = hl_combine_attr(wlv.win_attr,
2772 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002773 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 mb_c = c;
2775 if (enc_utf8 && utf_char2len(c) > 1)
2776 {
2777 mb_utf8 = TRUE;
2778 u8cc[0] = 0;
2779 c = 0xc0;
2780 }
2781 }
2782 else
2783 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002784 wlv.c_final = NUL;
2785 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786 c = ' ';
2787 }
2788 }
2789 else if (c == NUL
2790 && (wp->w_p_list
2791 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002792 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 && VIsual_mode != Ctrl_V
2794 && (
2795# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002796 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002798 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 && !(noinvcur
2800 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002801 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 && lcs_eol_one > 0)
2803 {
2804 // Display a '$' after the line or highlight an extra
2805 // character if the line break is included.
2806#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2807 // For a diff line the highlighting continues after the
2808 // "$".
2809 if (
2810# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002811 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812# ifdef LINE_ATTR
2813 &&
2814# endif
2815# endif
2816# ifdef LINE_ATTR
2817 line_attr == 0
2818# endif
2819 )
2820#endif
2821 {
2822 // In virtualedit, visual selections may extend
2823 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002824 if (!(area_highlighting && virtual_active()
2825 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002826 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002827 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002829 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2830 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831 else
2832 c = ' ';
2833 lcs_eol_one = -1;
2834 --ptr; // put it back at the NUL
2835 if (!attr_pri)
2836 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002837 extra_attr = hl_combine_attr(wlv.win_attr,
2838 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 n_attr = 1;
2840 }
2841 mb_c = c;
2842 if (enc_utf8 && utf_char2len(c) > 1)
2843 {
2844 mb_utf8 = TRUE;
2845 u8cc[0] = 0;
2846 c = 0xc0;
2847 }
2848 else
2849 mb_utf8 = FALSE; // don't draw as UTF-8
2850 }
2851 else if (c != NUL)
2852 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2854 if (wlv.n_extra == 0)
2855 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856#ifdef FEAT_RIGHTLEFT
2857 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002858 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002860 wlv.c_extra = NUL;
2861 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862#ifdef FEAT_LINEBREAK
2863 if (wp->w_p_lbr)
2864 {
2865 char_u *p;
2866
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 c = *wlv.p_extra;
2868 p = alloc(wlv.n_extra + 1);
2869 vim_memset(p, ' ', wlv.n_extra);
2870 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2871 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002873 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 }
2875 else
2876#endif
2877 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002878 wlv.n_extra = byte2cells(c) - 1;
2879 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 }
2881 if (!attr_pri)
2882 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002883 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002884 extra_attr = hl_combine_attr(wlv.win_attr,
2885 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 }
2888 mb_utf8 = FALSE; // don't draw as UTF-8
2889 }
2890 else if (VIsual_active
2891 && (VIsual_mode == Ctrl_V
2892 || VIsual_mode == 'v')
2893 && virtual_active()
2894 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002895 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 && (
2897#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002900 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 {
2902 c = ' ';
2903 --ptr; // put it back at the NUL
2904 }
2905#if defined(LINE_ATTR)
2906 else if ((
2907# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002908 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909# endif
2910# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002911 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912# endif
2913 line_attr != 0
2914 ) && (
2915# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002916 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002918 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921# endif
2922 < wp->w_width)))
2923 {
2924 // Highlight until the right side of the window
2925 c = ' ';
2926 --ptr; // put it back at the NUL
2927
2928 // Remember we do the char for line highlighting.
2929 ++did_line_attr;
2930
2931 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002932 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002934 || (wp->w_p_list &&
2935 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002936 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002938 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002940 wlv.diff_hlf = HLF_CHD;
2941 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2945 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002946 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002947 || (wlv.vcol >= left_curline_col
2948 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002949 wlv.char_attr = hl_combine_attr(
2950 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 }
2952 }
2953# endif
2954# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002955 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002958 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2959 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002961 if (!wlv.cul_screenline
2962 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002963 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 wlv.char_attr = hl_combine_attr(
2965 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 }
2967 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2969 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 }
2971# endif
2972 }
2973#endif
2974 }
2975
2976#ifdef FEAT_CONCEAL
2977 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002978 && (wp != curwin || lnum != wp->w_cursor.lnum
2979 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2981 && !(lnum_in_visual_area
2982 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2983 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002984 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002985 if (((prev_syntax_id != syntax_seqnr
2986 && (syntax_flags & HL_CONCEAL) != 0)
2987 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002988 && (syn_get_sub_char() != NUL
2989 || (has_match_conc && match_conc)
2990 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 && wp->w_p_cole != 3)
2992 {
2993 // First time at this concealed item: display one
2994 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002995 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 c = match_conc;
2997 else if (syn_get_sub_char() != NUL)
2998 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002999 else if (wp->w_lcs_chars.conceal != NUL)
3000 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 else
3002 c = ' ';
3003
3004 prev_syntax_id = syntax_seqnr;
3005
Bram Moolenaar1306b362022-08-06 15:59:06 +01003006 if (wlv.n_extra > 0)
3007 wlv.vcol_off += wlv.n_extra;
3008 wlv.vcol += wlv.n_extra;
3009 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 {
3011# ifdef FEAT_RIGHTLEFT
3012 if (wp->w_p_rl)
3013 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003014 wlv.col -= wlv.n_extra;
3015 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 }
3017 else
3018# endif
3019 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003020 wlv.boguscols += wlv.n_extra;
3021 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022 }
3023 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003024 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 n_attr = 0;
3026 }
3027 else if (n_skip == 0)
3028 {
3029 is_concealing = TRUE;
3030 n_skip = 1;
3031 }
3032 mb_c = c;
3033 if (enc_utf8 && utf_char2len(c) > 1)
3034 {
3035 mb_utf8 = TRUE;
3036 u8cc[0] = 0;
3037 c = 0xc0;
3038 }
3039 else
3040 mb_utf8 = FALSE; // don't draw as UTF-8
3041 }
3042 else
3043 {
3044 prev_syntax_id = 0;
3045 is_concealing = FALSE;
3046 }
3047
3048 if (n_skip > 0 && did_decrement_ptr)
3049 // not showing the '>', put pointer back to avoid getting stuck
3050 ++ptr;
3051
3052#endif // FEAT_CONCEAL
3053 }
3054
3055#ifdef FEAT_CONCEAL
3056 // In the cursor line and we may be concealing characters: correct
3057 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 && wp == curwin && lnum == wp->w_cursor.lnum
3060 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003061 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003063# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003065 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003067# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003068 wp->w_wcol = wlv.col - wlv.boguscols;
3069 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003070 did_wcol = TRUE;
3071 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003072# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003073 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003074# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 }
3076#endif
3077
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003078 // Use "extra_attr", but don't override visual selection highlighting,
3079 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003080 // Don't use "extra_attr" until n_attr_skip is zero.
3081 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003082 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003083 && (!attr_pri
3084#ifdef FEAT_PROP_POPUP
3085 || (text_prop_flags & PT_FLAG_OVERRIDE)
3086#endif
3087 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 {
3089#ifdef LINE_ATTR
3090 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003091 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 else
3093#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003094 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 }
3096
3097#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3098 // XIM don't send preedit_start and preedit_end, but they send
3099 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3100 // im_is_preediting() here.
3101 if (p_imst == IM_ON_THE_SPOT
3102 && xic != NULL
3103 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003104 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 && !p_imdisable
3106 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003107 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 {
3109 colnr_T tcol;
3110
3111 if (preedit_end_col == MAXCOL)
3112 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3113 else
3114 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003115 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 {
3117 if (feedback_old_attr < 0)
3118 {
3119 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003120 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 wlv.char_attr = im_get_feedback_attr(feedback_col);
3123 if (wlv.char_attr < 0)
3124 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 feedback_col++;
3126 }
3127 else if (feedback_old_attr >= 0)
3128 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003129 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 feedback_old_attr = -1;
3131 feedback_col = 0;
3132 }
3133 }
3134#endif
3135 // Handle the case where we are in column 0 but not on the first
3136 // character of the line and the user wants us to show us a
3137 // special character (via 'listchars' option "precedes:<char>".
3138 if (lcs_prec_todo != NUL
3139 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003140 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003141 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003142 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143#ifdef FEAT_DIFF
3144 && filler_todo <= 0
3145#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 && c != NUL)
3148 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003149 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150 lcs_prec_todo = NUL;
3151 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3152 {
3153 // Double-width character being overwritten by the "precedes"
3154 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003155 wlv.c_extra = MB_FILLER_CHAR;
3156 wlv.c_final = NUL;
3157 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003159 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 }
3161 mb_c = c;
3162 if (enc_utf8 && utf_char2len(c) > 1)
3163 {
3164 mb_utf8 = TRUE;
3165 u8cc[0] = 0;
3166 c = 0xc0;
3167 }
3168 else
3169 mb_utf8 = FALSE; // don't draw as UTF-8
3170 if (!attr_pri)
3171 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003172 saved_attr3 = wlv.char_attr; // save current attr
3173 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 n_attr3 = 1;
3175 }
3176 }
3177
3178 // At end of the text line or just after the last character.
3179 if ((c == NUL
3180#if defined(LINE_ATTR)
3181 || did_line_attr == 1
3182#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003183 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 {
3185#ifdef FEAT_SEARCH_EXTRA
3186 // flag to indicate whether prevcol equals startcol of search_hl or
3187 // one of the matches
3188 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3189 (long)(ptr - line) - (c == NUL));
3190#endif
3191 // Invert at least one char, used for Visual and empty line or
3192 // highlight match at end of line. If it's beyond the last
3193 // char on the screen, just overwrite that one (tricky!) Not
3194 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003195 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003196 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197 && (VIsual_mode != Ctrl_V
3198 || lnum == VIsual.lnum
3199 || lnum == curwin->w_cursor.lnum)
3200 && c == NUL)
3201#ifdef FEAT_SEARCH_EXTRA
3202 // highlight 'hlsearch' match at end of line
3203 || (prevcol_hl_flag
3204# ifdef FEAT_SYN_HL
3205 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3206 && !(wp == curwin && VIsual_active))
3207# endif
3208# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210# endif
3211# if defined(LINE_ATTR)
3212 && did_line_attr <= 1
3213# endif
3214 )
3215#endif
3216 ))
3217 {
3218 int n = 0;
3219
3220#ifdef FEAT_RIGHTLEFT
3221 if (wp->w_p_rl)
3222 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003223 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224 n = 1;
3225 }
3226 else
3227#endif
3228 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003229 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 n = -1;
3231 }
3232 if (n != 0)
3233 {
3234 // At the window boundary, highlight the last character
3235 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003236 wlv.off += n;
3237 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 }
3239 else
3240 {
3241 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003244 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 }
3246#ifdef FEAT_SEARCH_EXTRA
3247 if (area_attr == 0)
3248 {
3249 // Use attributes from match with highest priority among
3250 // 'search_hl' and the match list.
3251 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003252 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 }
3254#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003256 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257#ifdef FEAT_RIGHTLEFT
3258 if (wp->w_p_rl)
3259 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003260 --wlv.col;
3261 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 }
3263 else
3264#endif
3265 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 ++wlv.col;
3267 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003269 ++wlv.vcol;
3270 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 }
3272 }
3273
3274 // At end of the text line.
3275 if (c == NUL)
3276 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003277 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278
3279 // Update w_cline_height and w_cline_folded if the cursor line was
3280 // updated (saves a call to plines() later).
3281 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3282 {
3283 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285#ifdef FEAT_FOLDING
3286 curwin->w_cline_folded = FALSE;
3287#endif
3288 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3289 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 break;
3291 }
3292
3293 // Show "extends" character from 'listchars' if beyond the line end and
3294 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003295 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003296 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 && wp->w_p_list
3298 && !wp->w_p_wrap
3299#ifdef FEAT_DIFF
3300 && filler_todo <= 0
3301#endif
3302 && (
3303#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003304 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003308 || lcs_eol_one > 0
3309 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003312 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003313 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 mb_c = c;
3315 if (enc_utf8 && utf_char2len(c) > 1)
3316 {
3317 mb_utf8 = TRUE;
3318 u8cc[0] = 0;
3319 c = 0xc0;
3320 }
3321 else
3322 mb_utf8 = FALSE;
3323 }
3324
3325#ifdef FEAT_SYN_HL
3326 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003327 if (wlv.draw_color_col)
3328 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329
3330 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3331 // highlight the cursor position itself.
3332 // Also highlight the 'colorcolumn' if it is different than
3333 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003334 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3335 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003337 if (((wlv.draw_state == WL_LINE
3338 || wlv.draw_state == WL_BRI
3339 || wlv.draw_state == WL_SBR)
3340 && !lnum_in_visual_area
3341 && search_attr == 0
3342 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003343# ifdef FEAT_DIFF
3344 && filler_todo <= 0
3345# endif
3346 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 {
3348 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3349 && lnum != wp->w_cursor.lnum)
3350 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003351 vcol_save_attr = wlv.char_attr;
3352 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3353 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 vcol_save_attr = wlv.char_attr;
3358 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 }
3360 }
3361#endif
3362
3363 // Store character to be displayed.
3364 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003365 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 {
3368 // Store the character.
3369#if defined(FEAT_RIGHTLEFT)
3370 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3371 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003372 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003373 --wlv.off;
3374 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 }
3376#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 if (enc_dbcs == DBCS_JPNU)
3379 {
3380 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003381 ScreenLines[wlv.off] = 0x8e;
3382 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 }
3384 else if (enc_utf8)
3385 {
3386 if (mb_utf8)
3387 {
3388 int i;
3389
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003390 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 for (i = 0; i < Screen_mco; ++i)
3394 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003395 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 if (u8cc[i] == 0)
3397 break;
3398 }
3399 }
3400 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003401 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 }
3403 if (multi_attr)
3404 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 multi_attr = 0;
3407 }
3408 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003409 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003411 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003412
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3414 {
3415 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003416 ++wlv.off;
3417 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 if (enc_utf8)
3419 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 else
3422 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003424 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425#ifdef FEAT_DIFF
3426 && filler_todo <= 0
3427#endif
3428 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 // When "tocol" is halfway a character, set it to the end of
3431 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003432 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003434
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003436
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437#ifdef FEAT_RIGHTLEFT
3438 if (wp->w_p_rl)
3439 {
3440 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003441 --wlv.off;
3442 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 }
3444#endif
3445 }
3446#ifdef FEAT_RIGHTLEFT
3447 if (wp->w_p_rl)
3448 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 --wlv.off;
3450 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 }
3452 else
3453#endif
3454 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 ++wlv.off;
3456 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
3458 }
3459#ifdef FEAT_CONCEAL
3460 else if (wp->w_p_cole > 0 && is_concealing)
3461 {
3462 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003464 if (wlv.n_extra > 0)
3465 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 if (wp->w_p_wrap)
3467 {
3468 // Special voodoo required if 'wrap' is on.
3469 //
3470 // Advance the column indicator to force the line
3471 // drawing to wrap early. This will make the line
3472 // take up the same screen space when parts are concealed,
3473 // so that cursor line computations aren't messed up.
3474 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 // trailing junk to be written out of the screen line
3477 // we are building, 'boguscols' keeps track of the number
3478 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003479 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003481 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482# ifdef FEAT_RIGHTLEFT
3483 if (wp->w_p_rl)
3484 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003485 wlv.col -= wlv.n_extra;
3486 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 }
3488 else
3489# endif
3490 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 wlv.col += wlv.n_extra;
3492 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003494 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 n_attr = 0;
3496 }
3497
3498
3499 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3500 {
3501 // Need to fill two screen columns.
3502# ifdef FEAT_RIGHTLEFT
3503 if (wp->w_p_rl)
3504 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 --wlv.boguscols;
3506 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 }
3508 else
3509# endif
3510 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 ++wlv.boguscols;
3512 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 }
3514 }
3515
3516# ifdef FEAT_RIGHTLEFT
3517 if (wp->w_p_rl)
3518 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 --wlv.boguscols;
3520 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 }
3522 else
3523# endif
3524 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 ++wlv.boguscols;
3526 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 }
3528 }
3529 else
3530 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003533 wlv.vcol += wlv.n_extra;
3534 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 n_attr = 0;
3536 }
3537 }
3538
3539 }
3540#endif // FEAT_CONCEAL
3541 else
3542 --n_skip;
3543
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 // Only advance the "wlv.vcol" when after the 'number' or
3545 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003546 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547#ifdef FEAT_DIFF
3548 && filler_todo <= 0
3549#endif
3550 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552
3553#ifdef FEAT_SYN_HL
3554 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003555 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556#endif
3557
3558 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3560 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561
3562 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003563 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003564 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003565 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003566 if (n_attr_skip > 0)
3567 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568
3569 // At end of screen line and there is more to come: Display the line
3570 // so far. If there is no more to display it is caught above.
3571 if ((
3572#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003576 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003577 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578#ifdef FEAT_DIFF
3579 || filler_todo > 0
3580#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003581#ifdef FEAT_PROP_POPUP
3582 || text_prop_follows
3583#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003584 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003585 && wlv.p_extra != at_end_str)
3586 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3587 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 )
3589 {
3590#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003591 screen_line(wp, wlv.screen_row, wp->w_wincol,
3592 wlv.col - wlv.boguscols,
3593 wp->w_width, wlv.screen_line_flags);
3594 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3597 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 ++wlv.row;
3600 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601
3602 // When not wrapping and finished diff lines, or when displayed
3603 // '$' and highlighting until last column, break here.
3604 if ((!wp->w_p_wrap
3605#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003606 && filler_todo <= 0
3607#endif
3608#ifdef FEAT_PROP_POPUP
3609 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003610#endif
3611 ) || lcs_eol_one == -1)
3612 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003613#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003614 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003615 {
3616 // do not output more of the line, only the "below" prop
3617 ptr += STRLEN(ptr);
3618# ifdef FEAT_LINEBREAK
3619 dont_use_showbreak = TRUE;
3620# endif
3621 }
3622#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623
3624 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003625 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626#ifdef FEAT_DIFF
3627 && filler_todo <= 0
3628#endif
3629 )
3630 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3632 draw_vsep_win(wp, wlv.row);
3633 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 }
3635
3636 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003639 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 break;
3641 }
3642
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003644#ifdef FEAT_DIFF
3645 && filler_todo <= 0
3646#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003647#ifdef FEAT_PROP_POPUP
3648 && !text_prop_follows
3649#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 && wp->w_width == Columns)
3651 {
3652 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654
3655 // Special trick to make copy/paste of wrapped lines work with
3656 // xterm/screen: write an extra character beyond the end of
3657 // the line. This will work with all terminal types
3658 // (regardless of the xn,am settings).
3659 // Only do this on a fast tty.
3660 // Only do this if the cursor is on the current line
3661 // (something has been written in it).
3662 // Don't do this for the GUI.
3663 // Don't do this for double-width characters.
3664 // Don't do this for a window not at the right screen border.
3665 if (p_tf
3666#ifdef FEAT_GUI
3667 && !gui.in_use
3668#endif
3669 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003670 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3671 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003673 || (*mb_off2cells)(
3674 LineOffset[wlv.screen_row - 1]
3675 + (int)Columns - 2,
3676 LineOffset[wlv.screen_row]
3677 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 {
3679 // First make sure we are at the end of the screen line,
3680 // then output the same character again to let the
3681 // terminal know about the wrap. If the terminal doesn't
3682 // auto-wrap, we overwrite the character.
3683 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 screen_char(LineOffset[wlv.screen_row - 1]
3685 + (unsigned)Columns - 1,
3686 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687
3688 // When there is a multi-byte character, just output a
3689 // space to keep it simple.
3690 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003691 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 out_char(' ');
3693 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 + (Columns - 1)]);
3696 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003697 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698 screen_start(); // don't know where cursor is now
3699 }
3700 }
3701
Bram Moolenaar1306b362022-08-06 15:59:06 +01003702 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703
Bram Moolenaareed9d462021-02-15 20:38:25 +01003704 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003706 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003708 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003710 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 need_showbreak = TRUE;
3712#endif
3713#ifdef FEAT_DIFF
3714 --filler_todo;
3715 // When the filler lines are actually below the last line of the
3716 // file, don't draw the line itself, break here.
3717 if (filler_todo == 0 && wp->w_botfill)
3718 break;
3719#endif
3720 }
3721
3722 } // for every character in the line
3723
3724#ifdef FEAT_SPELL
3725 // After an empty line check first word for capital.
3726 if (*skipwhite(line) == NUL)
3727 {
3728 capcol_lnum = lnum + 1;
3729 cap_col = 0;
3730 }
3731#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003732#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 vim_free(text_props);
3734 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003735 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736#endif
3737
3738 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003739 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740}