blob: d958e7a89c422383b641c1f22d1ab65ba546badc [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
105
106 int screen_line_flags; // flags for screen_line()
107
108 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
109 int cul_screenline;
110
111 int char_attr; // attributes for the next character
112
113 int n_extra; // number of extra bytes
114 char_u *p_extra; // string of extra chars, plus NUL, only used
115 // when c_extra and c_final are NUL
116 int c_extra; // extra chars, all the same
117 int c_final; // final char, mandatory if set
118
119 // saved "extra" items for when draw_state becomes WL_LINE (again)
120 int saved_n_extra;
121 char_u *saved_p_extra;
122 int saved_c_extra;
123 int saved_c_final;
124 int saved_char_attr;
125
126#ifdef FEAT_DIFF
127 hlf_T diff_hlf; // type of diff highlighting
128#endif
129} winlinevars_T;
130
131// draw_state values for items that are drawn in sequence:
132#define WL_START 0 // nothing done yet, must be zero
133#ifdef FEAT_CMDWIN
134# define WL_CMDLINE (WL_START + 1) // cmdline window column
135#else
136# define WL_CMDLINE WL_START
137#endif
138#ifdef FEAT_FOLDING
139# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
140#else
141# define WL_FOLD WL_CMDLINE
142#endif
143#ifdef FEAT_SIGNS
144# define WL_SIGN (WL_FOLD + 1) // column for signs
145#else
146# define WL_SIGN WL_FOLD // column for signs
147#endif
148#define WL_NR (WL_SIGN + 1) // line number
149#ifdef FEAT_LINEBREAK
150# define WL_BRI (WL_NR + 1) // 'breakindent'
151#else
152# define WL_BRI WL_NR
153#endif
154#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
155# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
156#else
157# define WL_SBR WL_BRI
158#endif
159#define WL_LINE (WL_SBR + 1) // text in the line
160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_cursor_line_sign(win_T *wp, linenr_T lnum)
167{
168 return wp->w_p_cul
169 && lnum == wp->w_cursor.lnum
170 && (wp->w_p_culopt_flags & CULOPT_NBR);
171}
172
173/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * Get information needed to display the sign in line 'lnum' in window 'wp'.
175 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
176 * Otherwise the sign is going to be displayed in the sign column.
177 */
178 static void
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
190 int text_sign;
191# ifdef FEAT_SIGN_ICONS
192 int icon_sign;
193# endif
194
195 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
255 if (nrcol)
256 {
257 int n, width = number_width(wp) - 2;
258
259 for (n = 0; n < width; n++)
260 extra[n] = ' ';
261 extra[n] = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100280#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100281/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100282 * Return the cell size of virtual text after truncation.
283 */
284 static int
285textprop_size_after_trunc(
286 win_T *wp,
287 int flags, // TP_FLAG_ALIGN_*
288 int added,
289 char_u *text,
290 int *n_used_ptr)
291{
292 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
293 ? wp->w_width : added;
294 int len = (int)STRLEN(text);
295 int strsize = 0;
296 int n_used;
297
298 // if the remaining size is to small wrap anyway and use the next line
299 if (space < PROP_TEXT_MIN_CELLS)
300 space += wp->w_width;
301 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
302 {
303 int clen = ptr2cells(text + n_used);
304
305 if (strsize + clen > space)
306 break;
307 strsize += clen;
308 }
309 *n_used_ptr = n_used;
310 return strsize;
311}
312
313/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100314 * Take care of padding, right-align and truncation of virtual text after a
315 * line.
316 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
317 * padding, right-align and truncation. Otherwise only the size is computed.
318 * When "n_attr" is NULL returns the number of screen cells used.
319 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100320 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100321 int
322text_prop_position(
323 win_T *wp,
324 textprop_T *tp,
325 int vcol, // current screen column
326 int *n_extra, // nr of bytes for virtual text
327 char_u **p_extra, // virtual text
328 int *n_attr, // attribute cells, NULL if not used
329 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100331 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100332 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100333 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
334 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
335 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
336 ? tp->tp_len - 1 : 0;
337 int col_with_padding = vcol + (below ? 0 : padding);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100338 int col_off = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100339 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100340 int before = room; // spaces before the text
341 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100342 int n_used = *n_extra;
343 char_u *l = NULL;
344 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100345 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
346 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100348 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100349 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100350 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100351 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100352 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100353 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100354 }
355 else
356 {
357 // Right-align: fill with before
358 if (right)
359 before -= cells;
360 if (before < 0
361 || !(right || below)
362 || (below
363 ? (col_with_padding == 0 || !wp->w_p_wrap)
364 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100365 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100366 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
367 {
368 // right-align on next line instead of wrapping if possible
369 col_off = win_col_off(wp) + win_col_off2(wp);
370 before = wp->w_width - col_off - strsize + room;
371 if (before < 0)
372 before = 0;
373 else
374 n_used = *n_extra;
375 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100376 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100377 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100378 }
Bram 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 Moolenaar79f8b842022-09-11 13:31:01 +0100439 if (above)
440 *n_attr -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100441 *n_attr_skip = before + padding + col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100442 }
443 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100444 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100445
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100446 if (n_attr == NULL)
447 return cells;
448 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200449}
450#endif
451
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100452/*
453 * Called when finished with the line: draw the screen line and handle any
454 * highlighting until the right of the window.
455 */
456 static void
457draw_screen_line(win_T *wp, winlinevars_T *wlv)
458{
459#ifdef FEAT_SYN_HL
460 long v;
461
462 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
463 if (wp->w_p_wrap)
464 v = wp->w_skipcol;
465 else
466 v = wp->w_leftcol;
467
468 // check if line ends before left margin
469 if (wlv->vcol < v + wlv->col - win_col_off(wp))
470 wlv->vcol = v + wlv->col - win_col_off(wp);
471# ifdef FEAT_CONCEAL
472 // Get rid of the boguscols now, we want to draw until the right
473 // edge for 'cursorcolumn'.
474 wlv->col -= wlv->boguscols;
475 wlv->boguscols = 0;
476# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
477# else
478# define VCOL_HLC (wlv->vcol)
479# endif
480
481 if (wlv->draw_color_col)
482 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
483
484 if (((wp->w_p_cuc
485 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
486 && (int)wp->w_virtcol <
487 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
488 && wlv->lnum != wp->w_cursor.lnum)
489 || wlv->draw_color_col
490 || wlv->win_attr != 0)
491# ifdef FEAT_RIGHTLEFT
492 && !wp->w_p_rl
493# endif
494 )
495 {
496 int rightmost_vcol = 0;
497 int i;
498
499 if (wp->w_p_cuc)
500 rightmost_vcol = wp->w_virtcol;
501 if (wlv->draw_color_col)
502 // determine rightmost colorcolumn to possibly draw
503 for (i = 0; wlv->color_cols[i] >= 0; ++i)
504 if (rightmost_vcol < wlv->color_cols[i])
505 rightmost_vcol = wlv->color_cols[i];
506
507 while (wlv->col < wp->w_width)
508 {
509 ScreenLines[wlv->off] = ' ';
510 if (enc_utf8)
511 ScreenLinesUC[wlv->off] = 0;
512 ScreenCols[wlv->off] = MAXCOL;
513 ++wlv->col;
514 if (wlv->draw_color_col)
515 wlv->draw_color_col = advance_color_col(
516 VCOL_HLC, &wlv->color_cols);
517
518 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
519 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
520 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
521 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
522 else
523 ScreenAttrs[wlv->off++] = wlv->win_attr;
524
525 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
526 break;
527
528 ++wlv->vcol;
529 }
530 }
531#endif
532
533 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
534 wp->w_width, wlv->screen_line_flags);
535 ++wlv->row;
536 ++wlv->screen_row;
537}
538#undef VCOL_HLC
539
540/*
541 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100542 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100543 */
544 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100545win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100546{
547 wlv->col = 0;
548 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
549
550#ifdef FEAT_RIGHTLEFT
551 if (wp->w_p_rl)
552 {
553 // Rightleft window: process the text in the normal direction, but put
554 // it in current_ScreenLine[] from right to left. Start at the
555 // rightmost column of the window.
556 wlv->col = wp->w_width - 1;
557 wlv->off += wlv->col;
558 wlv->screen_line_flags |= SLF_RIGHTLEFT;
559 }
560#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100561 if (save_extra)
562 {
563 // reset the drawing state for the start of a wrapped line
564 wlv->draw_state = WL_START;
565 wlv->saved_n_extra = wlv->n_extra;
566 wlv->saved_p_extra = wlv->p_extra;
567 wlv->saved_c_extra = wlv->c_extra;
568 wlv->saved_c_final = wlv->c_final;
569#ifdef FEAT_SYN_HL
570 if (!(wlv->cul_screenline
571# ifdef FEAT_DIFF
572 && wlv->diff_hlf == (hlf_T)0
573# endif
574 ))
575 wlv->saved_char_attr = wlv->char_attr;
576 else
577#endif
578 wlv->saved_char_attr = 0;
579 wlv->n_extra = 0;
580 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100581}
582
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200583/*
584 * Display line "lnum" of window 'wp' on the screen.
585 * Start at row "startrow", stop when "endrow" is reached.
586 * wp->w_virtcol needs to be valid.
587 *
588 * Return the number of last row the line occupies.
589 */
590 int
591win_line(
592 win_T *wp,
593 linenr_T lnum,
594 int startrow,
595 int endrow,
596 int nochange UNUSED, // not updating for changed text
597 int number_only) // only update the number column
598{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100599 winlinevars_T wlv; // variables passed between functions
600
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200601 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200602#ifdef FEAT_LINEBREAK
603 long vcol_sbr = -1; // virtual column after showbreak
604#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100605 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200606 char_u *line; // current line
607 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200608
609 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200610 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100611#ifdef FEAT_PROP_POPUP
612 char_u *p_extra_free2 = NULL; // another p_extra to be freed
613#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200614 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000615#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000616 int in_linebreak = FALSE; // n_extra set for showing linebreak
617#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200618 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100619 // displaying eol at end-of-line
620 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000621 int lcs_prec_todo = wp->w_lcs_chars.prec;
622 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200623
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100624 int n_attr = 0; // chars with special attr
625 int n_attr_skip = 0; // chars to skip before using extra_attr
626 int saved_attr2 = 0; // char_attr saved for n_attr
627 int n_attr3 = 0; // chars with overruling special attr
628 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200629
630 int n_skip = 0; // nr of chars to skip for 'nowrap'
631
632 int fromcol = -10; // start of inverting
633 int tocol = MAXCOL; // end of inverting
634 int fromcol_prev = -2; // start of inverting after cursor
635 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200636 int lnum_in_visual_area = FALSE;
637 pos_T pos;
638 long v;
639
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200640 int attr_pri = FALSE; // char_attr has priority
641 int area_highlighting = FALSE; // Visual or incsearch highlighting
642 // in this line
643 int vi_attr = 0; // attributes for Visual and incsearch
644 // highlighting
645 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200646 int area_attr = 0; // attributes desired by highlighting
647 int search_attr = 0; // attributes desired by 'hlsearch'
648#ifdef FEAT_SYN_HL
649 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
650 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200651 int prev_syntax_col = -1; // column of prev_syntax_attr
652 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200653 int has_syntax = FALSE; // this buffer has syntax highl.
654 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100656#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200657 int text_prop_count;
658 int text_prop_next = 0; // next text property to use
659 textprop_T *text_props = NULL;
660 int *text_prop_idxs = NULL;
661 int text_props_active = 0;
662 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100663 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200664 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100665 int text_prop_attr_comb = 0; // text_prop_attr combined with
666 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100667 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100668 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100669 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100670 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100671 int saved_search_attr = 0; // search_attr to be used when n_extra
672 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100673 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200674#endif
675#ifdef FEAT_SPELL
676 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000677 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200678# define SPWORDLEN 150
679 char_u nextline[SPWORDLEN * 2];// text with start of the next line
680 int nextlinecol = 0; // column where nextline[] starts
681 int nextline_idx = 0; // index in nextline[] where next line
682 // starts
683 int spell_attr = 0; // attributes desired by spelling
684 int word_end = 0; // last byte with same spell_attr
685 static linenr_T checked_lnum = 0; // line number for "checked_col"
686 static int checked_col = 0; // column in "checked_lnum" up to which
687 // there are no spell errors
688 static int cap_col = -1; // column to check for Cap word
689 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
690 int cur_checked_col = 0; // checked column for current line
691#endif
692 int extra_check = 0; // has extra highlighting
693 int multi_attr = 0; // attributes desired by multibyte
694 int mb_l = 1; // multi-byte byte length
695 int mb_c = 0; // decoded multi-byte character
696 int mb_utf8 = FALSE; // screen char is UTF-8 char
697 int u8cc[MAX_MCO]; // composing UTF-8 chars
698#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
699 int filler_lines = 0; // nr of filler lines to be drawn
700 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000701#else
702# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200703#endif
704#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705 int change_start = MAXCOL; // first col of changed area
706 int change_end = -1; // last col of changed area
707#endif
708 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100709 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200710 int in_multispace = FALSE; // in multiple consecutive spaces
711 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200712#ifdef FEAT_LINEBREAK
713 int need_showbreak = FALSE; // overlong line, skipping first x
714 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100715 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200716#endif
717#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
718 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
719# define LINE_ATTR
720 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100721 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200722#endif
723#ifdef FEAT_SIGNS
724 int sign_present = FALSE;
725 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000726 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200727#endif
728#ifdef FEAT_ARABIC
729 int prev_c = 0; // previous Arabic character
730 int prev_c1 = 0; // first composing char for prev_c
731#endif
732#if defined(LINE_ATTR)
733 int did_line_attr = 0;
734#endif
735#ifdef FEAT_TERMINAL
736 int get_term_attr = FALSE;
737#endif
738#ifdef FEAT_SYN_HL
739 int cul_attr = 0; // set when 'cursorline' active
740
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200741 // margin columns for the screen line, needed for when 'cursorlineopt'
742 // contains "screenline"
743 int left_curline_col = 0;
744 int right_curline_col = 0;
745#endif
746
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200747#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
748 int feedback_col = 0;
749 int feedback_old_attr = -1;
750#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200751
752#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
753 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000754 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200755#endif
756#ifdef FEAT_CONCEAL
757 int syntax_flags = 0;
758 int syntax_seqnr = 0;
759 int prev_syntax_id = 0;
760 int conceal_attr = HL_ATTR(HLF_CONCEAL);
761 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200762 int did_wcol = FALSE;
763 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100764# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200765# define FIX_FOR_BOGUSCOLS \
766 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100767 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100768 wlv.vcol -= wlv.vcol_off; \
769 wlv.vcol_off = 0; \
770 wlv.col -= wlv.boguscols; \
771 old_boguscols = wlv.boguscols; \
772 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 }
774#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100775# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200776#endif
777
778 if (startrow > endrow) // past the end already!
779 return startrow;
780
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100781 CLEAR_FIELD(wlv);
782
783 wlv.lnum = lnum;
784 wlv.startrow = startrow;
785 wlv.row = startrow;
786 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200787
788 if (!number_only)
789 {
790 // To speed up the loop below, set extra_check when there is linebreak,
791 // trailing white space and/or syntax processing to be done.
792#ifdef FEAT_LINEBREAK
793 extra_check = wp->w_p_lbr;
794#endif
795#ifdef FEAT_SYN_HL
796 if (syntax_present(wp) && !wp->w_s->b_syn_error
797# ifdef SYN_TIME_LIMIT
798 && !wp->w_s->b_syn_slow
799# endif
800 )
801 {
802 // Prepare for syntax highlighting in this line. When there is an
803 // error, stop syntax highlighting.
804 save_did_emsg = did_emsg;
805 did_emsg = FALSE;
806 syntax_start(wp, lnum);
807 if (did_emsg)
808 wp->w_s->b_syn_error = TRUE;
809 else
810 {
811 did_emsg = save_did_emsg;
812#ifdef SYN_TIME_LIMIT
813 if (!wp->w_s->b_syn_slow)
814#endif
815 {
816 has_syntax = TRUE;
817 extra_check = TRUE;
818 }
819 }
820 }
821
822 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100823 wlv.color_cols = wp->w_p_cc_cols;
824 if (wlv.color_cols != NULL)
825 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200826#endif
827
828#ifdef FEAT_TERMINAL
829 if (term_show_buffer(wp->w_buffer))
830 {
831 extra_check = TRUE;
832 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100833 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200834 }
835#endif
836
837#ifdef FEAT_SPELL
838 if (wp->w_p_spell
839 && *wp->w_s->b_p_spl != NUL
840 && wp->w_s->b_langp.ga_len > 0
841 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
842 {
843 // Prepare for spell checking.
844 has_spell = TRUE;
845 extra_check = TRUE;
846
847 // Get the start of the next line, so that words that wrap to the
848 // next line are found too: "et<line-break>al.".
849 // Trick: skip a few chars for C/shell/Vim comments
850 nextline[SPWORDLEN] = NUL;
851 if (lnum < wp->w_buffer->b_ml.ml_line_count)
852 {
853 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
854 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
855 }
856
857 // When a word wrapped from the previous line the start of the
858 // current line is valid.
859 if (lnum == checked_lnum)
860 cur_checked_col = checked_col;
861 checked_lnum = 0;
862
863 // When there was a sentence end in the previous line may require a
864 // word starting with capital in this line. In line 1 always check
865 // the first word.
866 if (lnum != capcol_lnum)
867 cap_col = -1;
868 if (lnum == 1)
869 cap_col = 0;
870 capcol_lnum = 0;
871 }
872#endif
873
874 // handle Visual active in this window
875 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
876 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100877 pos_T *top, *bot;
878
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200879 if (LTOREQ_POS(curwin->w_cursor, VIsual))
880 {
881 // Visual is after curwin->w_cursor
882 top = &curwin->w_cursor;
883 bot = &VIsual;
884 }
885 else
886 {
887 // Visual is before curwin->w_cursor
888 top = &VIsual;
889 bot = &curwin->w_cursor;
890 }
891 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
892 if (VIsual_mode == Ctrl_V)
893 {
894 // block mode
895 if (lnum_in_visual_area)
896 {
897 fromcol = wp->w_old_cursor_fcol;
898 tocol = wp->w_old_cursor_lcol;
899 }
900 }
901 else
902 {
903 // non-block mode
904 if (lnum > top->lnum && lnum <= bot->lnum)
905 fromcol = 0;
906 else if (lnum == top->lnum)
907 {
908 if (VIsual_mode == 'V') // linewise
909 fromcol = 0;
910 else
911 {
912 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
913 if (gchar_pos(top) == NUL)
914 tocol = fromcol + 1;
915 }
916 }
917 if (VIsual_mode != 'V' && lnum == bot->lnum)
918 {
919 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
920 {
921 fromcol = -10;
922 tocol = MAXCOL;
923 }
924 else if (bot->col == MAXCOL)
925 tocol = MAXCOL;
926 else
927 {
928 pos = *bot;
929 if (*p_sel == 'e')
930 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
931 else
932 {
933 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
934 ++tocol;
935 }
936 }
937 }
938 }
939
940 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200941 if (!highlight_match && lnum == curwin->w_cursor.lnum
942 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200943#ifdef FEAT_GUI
944 && !gui.in_use
945#endif
946 )
947 noinvcur = TRUE;
948
949 // if inverting in this line set area_highlighting
950 if (fromcol >= 0)
951 {
952 area_highlighting = TRUE;
953 vi_attr = HL_ATTR(HLF_V);
954#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
955 if ((clip_star.available && !clip_star.owned
956 && clip_isautosel_star())
957 || (clip_plus.available && !clip_plus.owned
958 && clip_isautosel_plus()))
959 vi_attr = HL_ATTR(HLF_VNC);
960#endif
961 }
962 }
963
964 // handle 'incsearch' and ":s///c" highlighting
965 else if (highlight_match
966 && wp == curwin
967 && lnum >= curwin->w_cursor.lnum
968 && lnum <= curwin->w_cursor.lnum + search_match_lines)
969 {
970 if (lnum == curwin->w_cursor.lnum)
971 getvcol(curwin, &(curwin->w_cursor),
972 (colnr_T *)&fromcol, NULL, NULL);
973 else
974 fromcol = 0;
975 if (lnum == curwin->w_cursor.lnum + search_match_lines)
976 {
977 pos.lnum = lnum;
978 pos.col = search_match_endcol;
979 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
980 }
981 else
982 tocol = MAXCOL;
983 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100984 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985 tocol = fromcol + 1;
986 area_highlighting = TRUE;
987 vi_attr = HL_ATTR(HLF_I);
988 }
989 }
990
991#ifdef FEAT_DIFF
992 filler_lines = diff_check(wp, lnum);
993 if (filler_lines < 0)
994 {
995 if (filler_lines == -1)
996 {
997 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100998 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001000 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001002 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 }
1004 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001005 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 filler_lines = 0;
1007 area_highlighting = TRUE;
1008 }
1009 if (lnum == wp->w_topline)
1010 filler_lines = wp->w_topfill;
1011 filler_todo = filler_lines;
1012#endif
1013
1014#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01001015 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +00001016 if (sign_present)
1017 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001018#endif
1019
1020#ifdef LINE_ATTR
1021# ifdef FEAT_SIGNS
1022 // If this line has a sign with line highlighting set line_attr.
1023 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001024 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025# endif
1026# if defined(FEAT_QUICKFIX)
1027 // Highlight the current line in the quickfix window.
1028 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1029 line_attr = HL_ATTR(HLF_QFL);
1030# endif
1031 if (line_attr != 0)
1032 area_highlighting = TRUE;
1033#endif
1034
1035 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1036 ptr = line;
1037
1038#ifdef FEAT_SPELL
1039 if (has_spell && !number_only)
1040 {
1041 // For checking first word with a capital skip white space.
1042 if (cap_col == 0)
1043 cap_col = getwhitecols(line);
1044
1045 // To be able to spell-check over line boundaries copy the end of the
1046 // current line into nextline[]. Above the start of the next line was
1047 // copied to nextline[SPWORDLEN].
1048 if (nextline[SPWORDLEN] == NUL)
1049 {
1050 // No next line or it is empty.
1051 nextlinecol = MAXCOL;
1052 nextline_idx = 0;
1053 }
1054 else
1055 {
1056 v = (long)STRLEN(line);
1057 if (v < SPWORDLEN)
1058 {
1059 // Short line, use it completely and append the start of the
1060 // next line.
1061 nextlinecol = 0;
1062 mch_memmove(nextline, line, (size_t)v);
1063 STRMOVE(nextline + v, nextline + SPWORDLEN);
1064 nextline_idx = v + 1;
1065 }
1066 else
1067 {
1068 // Long line, use only the last SPWORDLEN bytes.
1069 nextlinecol = v - SPWORDLEN;
1070 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1071 nextline_idx = SPWORDLEN + 1;
1072 }
1073 }
1074 }
1075#endif
1076
1077 if (wp->w_p_list)
1078 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001079 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001080 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001081 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001082 || wp->w_lcs_chars.trail
1083 || wp->w_lcs_chars.lead
1084 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001086
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001088 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089 {
1090 trailcol = (colnr_T)STRLEN(ptr);
1091 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1092 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001093 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001095 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001096 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001097 {
1098 leadcol = 0;
1099 while (VIM_ISWHITE(ptr[leadcol]))
1100 ++leadcol;
1101 if (ptr[leadcol] == NUL)
1102 // in a line full of spaces all of them are treated as trailing
1103 leadcol = (colnr_T)0;
1104 else
1105 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001106 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001107 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001108 }
1109
1110 wcr_attr = get_wcr_attr(wp);
1111 if (wcr_attr != 0)
1112 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001113 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 area_highlighting = TRUE;
1115 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001116
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001117#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001119 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120#endif
1121
1122 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1123 // first character to be displayed.
1124 if (wp->w_p_wrap)
1125 v = wp->w_skipcol;
1126 else
1127 v = wp->w_leftcol;
1128 if (v > 0 && !number_only)
1129 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001130 char_u *prev_ptr = ptr;
1131 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001132 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001133
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001134 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001135 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001136 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001137 charsize = win_lbr_chartabsize(&cts, NULL);
1138 cts.cts_vcol += charsize;
1139 prev_ptr = cts.cts_ptr;
1140 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001142 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001143 ptr = cts.cts_ptr;
1144 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145
1146 // When:
1147 // - 'cuc' is set, or
1148 // - 'colorcolumn' is set, or
1149 // - 'virtualedit' is set, or
1150 // - the visual mode is active,
1151 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001152 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001154 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155#endif
1156 virtual_active() ||
1157 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001158 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159
1160 // Handle a character that's not completely on the screen: Put ptr at
1161 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001162 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001164 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165 ptr = prev_ptr;
1166 // If the character fits on the screen, don't need to skip it.
1167 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001168 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1169 && wlv.col == 0)
1170 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171 }
1172
1173 // Adjust for when the inverted text is before the screen,
1174 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001175 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001177 else if (fromcol >= 0 && fromcol < wlv.vcol)
1178 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179
1180#ifdef FEAT_LINEBREAK
1181 // When w_skipcol is non-zero, first line needs 'showbreak'
1182 if (wp->w_p_wrap)
1183 need_showbreak = TRUE;
1184#endif
1185#ifdef FEAT_SPELL
1186 // When spell checking a word we need to figure out the start of the
1187 // word and if it's badly spelled or not.
1188 if (has_spell)
1189 {
1190 int len;
1191 colnr_T linecol = (colnr_T)(ptr - line);
1192 hlf_T spell_hlf = HLF_COUNT;
1193
1194 pos = wp->w_cursor;
1195 wp->w_cursor.lnum = lnum;
1196 wp->w_cursor.col = linecol;
1197 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1198
1199 // spell_move_to() may call ml_get() and make "line" invalid
1200 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1201 ptr = line + linecol;
1202
1203 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1204 {
1205 // no bad word found at line start, don't check until end of a
1206 // word
1207 spell_hlf = HLF_COUNT;
1208 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1209 }
1210 else
1211 {
1212 // bad word found, use attributes until end of word
1213 word_end = wp->w_cursor.col + len + 1;
1214
1215 // Turn index into actual attributes.
1216 if (spell_hlf != HLF_COUNT)
1217 spell_attr = highlight_attr[spell_hlf];
1218 }
1219 wp->w_cursor = pos;
1220
1221# ifdef FEAT_SYN_HL
1222 // Need to restart syntax highlighting for this line.
1223 if (has_syntax)
1224 syntax_start(wp, lnum);
1225# endif
1226 }
1227#endif
1228 }
1229
1230 // Correct highlighting for cursor that can't be disabled.
1231 // Avoids having to check this for each character.
1232 if (fromcol >= 0)
1233 {
1234 if (noinvcur)
1235 {
1236 if ((colnr_T)fromcol == wp->w_virtcol)
1237 {
1238 // highlighting starts at cursor, let it start just after the
1239 // cursor
1240 fromcol_prev = fromcol;
1241 fromcol = -1;
1242 }
1243 else if ((colnr_T)fromcol < wp->w_virtcol)
1244 // restart highlighting after the cursor
1245 fromcol_prev = wp->w_virtcol;
1246 }
1247 if (fromcol >= tocol)
1248 fromcol = -1;
1249 }
1250
1251#ifdef FEAT_SEARCH_EXTRA
1252 if (!number_only)
1253 {
1254 v = (long)(ptr - line);
1255 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1256 &line, &screen_search_hl,
1257 &search_attr);
1258 ptr = line + v; // "line" may have been updated
1259 }
1260#endif
1261
1262#ifdef FEAT_SYN_HL
1263 // Cursor line highlighting for 'cursorline' in the current window.
1264 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1265 {
1266 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001267 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 if (!(wp == curwin && VIsual_active)
1269 && wp->w_p_culopt_flags != CULOPT_NBR)
1270 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001271 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1273
1274 // Only set line_attr here when "screenline" is not present in
1275 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001276 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 {
1278 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001279# ifdef FEAT_SIGNS
1280 // Combine the 'cursorline' and sign highlighting, depending on
1281 // the sign priority.
1282 if (sign_present && sattr.sat_linehl > 0)
1283 {
1284 if (sattr.sat_priority >= 100)
1285 line_attr = hl_combine_attr(cul_attr, line_attr);
1286 else
1287 line_attr = hl_combine_attr(line_attr, cul_attr);
1288 }
1289 else
1290# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001291# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001292 // let the line attribute overrule 'cursorline', otherwise
1293 // it disappears when both have background set;
1294 // 'cursorline' can use underline or bold to make it show
1295 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001296# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001297 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001298# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 }
1300 else
1301 {
1302 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1304 }
1305 area_highlighting = TRUE;
1306 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 }
1308#endif
1309
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001310#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 {
1312 char_u *prop_start;
1313
1314 text_prop_count = get_text_props(wp->w_buffer, lnum,
1315 &prop_start, FALSE);
1316 if (text_prop_count > 0)
1317 {
1318 // Make a copy of the properties, so that they are properly
1319 // aligned.
1320 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1321 if (text_props != NULL)
1322 mch_memmove(text_props, prop_start,
1323 text_prop_count * sizeof(textprop_T));
1324
1325 // Allocate an array for the indexes.
1326 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001327 if (text_prop_idxs == NULL)
1328 VIM_CLEAR(text_props);
1329
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 area_highlighting = TRUE;
1331 extra_check = TRUE;
1332 }
1333 }
1334#endif
1335
Bram Moolenaar1306b362022-08-06 15:59:06 +01001336 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337
1338 // Repeat for the whole displayed line.
1339 for (;;)
1340 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001341 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001343 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344#endif
1345#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001346 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001348
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001350 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001352#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001353 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001354 {
1355 cul_attr = 0;
1356 line_attr = line_attr_save;
1357 }
1358#endif
1359
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001361 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001363 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 if (cmdwin_type != 0 && wp == curwin)
1365 {
1366 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001367 wlv.n_extra = 1;
1368 wlv.c_extra = cmdwin_type;
1369 wlv.c_final = NUL;
1370 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 }
1372 }
1373#endif
1374
1375#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001376 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 {
1378 int fdc = compute_foldcolumn(wp, 0);
1379
Bram Moolenaar1306b362022-08-06 15:59:06 +01001380 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381 if (fdc > 0)
1382 {
1383 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1384 // already be in use.
1385 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001386 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 if (p_extra_free != NULL)
1388 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001389 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001390 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001391 p_extra_free[wlv.n_extra] = NUL;
1392 wlv.p_extra = p_extra_free;
1393 wlv.c_extra = NUL;
1394 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001395 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001396 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001397 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1398 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001399 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001400 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 }
1402 }
1403 }
1404#endif
1405
1406#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001407 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001409 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 // Show the sign column when there are any signs in this
1411 // buffer or when using Netbeans.
1412 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001413 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1414 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 }
1416#endif
1417
Bram Moolenaar1306b362022-08-06 15:59:06 +01001418 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001420 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 // Display the absolute or relative line number. After the
1422 // first fill with blanks when the 'n' flag isn't in 'cpo'
1423 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001424 && (wlv.row == startrow + filler_lines
1425 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 {
1427#ifdef FEAT_SIGNS
1428 // If 'signcolumn' is set to 'number' and a sign is present
1429 // in 'lnum', then display the sign instead of the line
1430 // number.
1431 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1432 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001433 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1434 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435 else
1436#endif
1437 {
1438 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001439 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440 {
1441 long num;
1442 char *fmt = "%*ld ";
1443
1444 if (wp->w_p_nu && !wp->w_p_rnu)
1445 // 'number' + 'norelativenumber'
1446 num = (long)lnum;
1447 else
1448 {
1449 // 'relativenumber', don't use negative numbers
1450 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1451 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1452 {
1453 // 'number' + 'relativenumber'
1454 num = lnum;
1455 fmt = "%-*ld ";
1456 }
1457 }
1458
1459 sprintf((char *)extra, fmt,
1460 number_width(wp), num);
1461 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001462 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1463 ++wlv.p_extra)
1464 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465#ifdef FEAT_RIGHTLEFT
1466 if (wp->w_p_rl) // reverse line numbers
1467 {
1468 char_u *p1, *p2;
1469 int t;
1470
1471 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001472 p2 = skipwhite(extra);
1473 p2 = skiptowhite(p2) - 1;
1474 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 {
1476 t = *p1;
1477 *p1 = *p2;
1478 *p2 = t;
1479 }
1480 }
1481#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001482 wlv.p_extra = extra;
1483 wlv.c_extra = NUL;
1484 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 }
1486 else
1487 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001488 wlv.c_extra = ' ';
1489 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001491 wlv.n_extra = number_width(wp) + 1;
1492 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493#ifdef FEAT_SYN_HL
1494 // When 'cursorline' is set highlight the line number of
1495 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001496 // When 'cursorlineopt' does not have "line" only
1497 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 // TODO: Can we use CursorLine instead of CursorLineNr
1499 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001500 if (wp->w_p_cul
1501 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001503 && (wlv.row == startrow + filler_lines
1504 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001505 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001506 wlv.char_attr = hl_combine_attr(wcr_attr,
1507 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001509 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1510 && HL_ATTR(HLF_LNA) != 0)
1511 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001512 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001513 HL_ATTR(HLF_LNA));
1514 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1515 && HL_ATTR(HLF_LNB) != 0)
1516 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001517 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001518 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001519 }
James McCoya80aad72021-12-22 19:45:28 +00001520#ifdef FEAT_SIGNS
1521 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001522 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001523#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 }
1525 }
1526
1527#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001528 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1529 && wlv.n_extra == 0
1530 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001532 wlv.draw_state = WL_BRI;
1533 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1534 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001536 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537
1538 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001539 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001541 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001543 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544# ifdef FEAT_DIFF
1545 && filler_lines == 0
1546# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001547# ifdef FEAT_PROP_POPUP
1548 && !dont_use_showbreak
1549# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550 )
1551 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001552 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001554 if (wlv.diff_hlf != (hlf_T)0)
1555 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001557 wlv.p_extra = NULL;
1558 wlv.c_extra = ' ';
1559 wlv.c_final = NUL;
1560 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001562 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001563 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001564 wlv.n_extra -= win_col_off2(wp);
1565 if (wlv.n_extra < 0)
1566 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001567 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001568 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001569 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 // Correct end of highlighted area for 'breakindent',
1571 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001572 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001573 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 }
1575 }
1576#endif
1577
1578#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001579 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001581 char_u *sbr;
1582
Bram Moolenaar1306b362022-08-06 15:59:06 +01001583 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584# ifdef FEAT_DIFF
1585 if (filler_todo > 0)
1586 {
1587 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001588 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001590 wlv.c_extra = '-';
1591 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 }
1593 else
1594 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001595 wlv.c_extra = wp->w_fill_chars.diff;
1596 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 }
1598# ifdef FEAT_RIGHTLEFT
1599 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001600 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 else
1602# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001603 wlv.n_extra = wp->w_width - wlv.col;
1604 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 }
1606# endif
1607# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001608 sbr = get_showbreak_value(wp);
1609 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 {
1611 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001612 wlv.p_extra = sbr;
1613 wlv.c_extra = NUL;
1614 wlv.c_final = NUL;
1615 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001616 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1617 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001618 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 // Correct end of highlighted area for 'showbreak',
1620 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001621 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001622 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001624 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1625 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626# ifdef FEAT_SYN_HL
1627 // combine 'showbreak' with 'cursorline'
1628 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001629 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1630 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631# endif
1632 }
1633# endif
1634 }
1635#endif
1636
Bram Moolenaar1306b362022-08-06 15:59:06 +01001637 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001639 wlv.draw_state = WL_LINE;
1640 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 {
1642 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001643 wlv.n_extra = wlv.saved_n_extra;
1644 wlv.c_extra = wlv.saved_c_extra;
1645 wlv.c_final = wlv.saved_c_final;
1646 wlv.p_extra = wlv.saved_p_extra;
1647 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 }
1649 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001650 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651 }
1652 }
1653#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001654 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001655 && wlv.vcol >= left_curline_col
1656 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001658 cul_attr = HL_ATTR(HLF_CUL);
1659 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660 }
1661#endif
1662
1663 // When still displaying '$' of change command, stop at cursor.
1664 // When only displaying the (relative) line number and that's done,
1665 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001666 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001667 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001668 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669#ifdef FEAT_DIFF
1670 && filler_todo <= 0
1671#endif
1672 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001674 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1675 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 // Pretend we have finished updating the window. Except when
1677 // 'cursorcolumn' is set.
1678#ifdef FEAT_SYN_HL
1679 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001680 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 else
1682#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001683 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 break;
1685 }
1686
Bram Moolenaar1306b362022-08-06 15:59:06 +01001687 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 {
1689 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001690 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001691 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 && (*mb_ptr2cells)(ptr) > 1)
1693 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001694 && vcol_prev < wlv.vcol // not at margin
1695 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 area_attr = vi_attr; // start highlighting
1697 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001698 && (wlv.vcol == tocol
1699 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 area_attr = 0; // stop highlighting
1701
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001702#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 if (text_props != NULL)
1704 {
1705 int pi;
1706 int bcol = (int)(ptr - line);
1707
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001709# ifdef FEAT_LINEBREAK
1710 && !in_linebreak
1711# endif
1712 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713 --bcol; // still working on the previous char, e.g. Tab
1714
1715 // Check if any active property ends.
1716 for (pi = 0; pi < text_props_active; ++pi)
1717 {
1718 int tpi = text_prop_idxs[pi];
1719
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001720 if (text_props[tpi].tp_col != MAXCOL
1721 && bcol >= text_props[tpi].tp_col - 1
1722 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 {
1724 if (pi + 1 < text_props_active)
1725 mch_memmove(text_prop_idxs + pi,
1726 text_prop_idxs + pi + 1,
1727 sizeof(int)
1728 * (text_props_active - (pi + 1)));
1729 --text_props_active;
1730 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001731# ifdef FEAT_LINEBREAK
1732 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001733 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001734 syntax_attr = 0;
1735# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 }
1737 }
1738
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001739# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001741 // not on the next char yet, don't start another prop
1742 --bcol;
1743# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001745 // With 'nowrap' and not in the first screen line only "below"
1746 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001748 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001749 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001750 && (wp->w_p_wrap
1751 || wlv.row == startrow
1752 || (text_props[text_prop_next].tp_flags
1753 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001754 || (bcol == 0 &&
1755 (text_props[text_prop_next].tp_flags
1756 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001757 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001758 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001759 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001760 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1761 {
1762 // first display the '$' after the line
1763 text_prop_follows = TRUE;
1764 break;
1765 }
1766 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001767 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001768 + text_props[text_prop_next].tp_len)
1769 text_prop_idxs[text_props_active++] = text_prop_next;
1770 ++text_prop_next;
1771 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001773 if (wlv.n_extra == 0 || !extra_for_textprop)
1774 {
1775 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001776 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001777 text_prop_flags = 0;
1778 text_prop_type = NULL;
1779 text_prop_id = 0;
1780 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001781 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001783 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001784 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001785 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001786
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 // Sort the properties on priority and/or starting last.
1788 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001789 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001790 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001791 sort_text_props(wp->w_buffer, text_props,
1792 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793
1794 for (pi = 0; pi < text_props_active; ++pi)
1795 {
1796 int tpi = text_prop_idxs[pi];
1797 proptype_T *pt = text_prop_type_by_id(
1798 wp->w_buffer, text_props[tpi].tp_type);
1799
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001800 if (pt != NULL && (pt->pt_hl_id > 0
1801 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001802 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001804 if (pt->pt_hl_id > 0)
1805 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 text_prop_type = pt;
1807 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001808 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001809 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001810 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001811 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001812 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 }
1814 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001815 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001816 && -text_prop_id
1817 <= wp->w_buffer->b_textprop_text.ga_len)
1818 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001819 textprop_T *tp = &text_props[used_tpi];
1820 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001821 ->b_textprop_text.ga_data)[
1822 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001823 int above = (tp->tp_flags
1824 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001825
1826 // reset the ID in the copy to avoid it being used
1827 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001828 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001829
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001830 if (p != NULL)
1831 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001832 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001833 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001834 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001835 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001836 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1837 int padding = tp->tp_col == MAXCOL
1838 && tp->tp_len > 1
1839 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001840
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001841 // Insert virtual text before the current
1842 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 wlv.p_extra = p;
1844 wlv.c_extra = NUL;
1845 wlv.c_final = NUL;
1846 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001847 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001848 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001849 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001850 // restore search_attr and area_attr when n_extra
1851 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001852 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001853 saved_area_attr = area_attr;
1854 search_attr = 0;
1855 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001856 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001857 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001858 if (*ptr == NUL)
1859 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001860 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001861#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001862 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001863 {
1864 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001865 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001866 need_showbreak = FALSE;
1867 dont_use_showbreak = TRUE;
1868 }
1869#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001870 if ((right || above || below || !wrap
1871 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001872 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001873 char_u *prev_p_extra = wlv.p_extra;
1874 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001875
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001876 // Take care of padding, right-align and
1877 // truncation.
1878 // Shared with win_lbr_chartabsize(), must do
1879 // exactly the same.
1880 start_line = text_prop_position(wp, tp,
1881 wlv.col,
1882 &wlv.n_extra, &wlv.p_extra,
1883 &n_attr, &n_attr_skip);
1884 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001885 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001886 // wlv.p_extra was allocated
1887 vim_free(p_extra_free2);
1888 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001889 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001890
Bram Moolenaara4abe512022-09-15 19:44:09 +01001891 if (lcs_eol_one < 0 && wlv.col
1892 + wlv.n_extra - 2 > wp->w_width)
1893 // don't bail out at end of line
1894 lcs_eol_one = 0;
1895
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001896 // When 'wrap' is off then for "below" we need
1897 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001898 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001899 {
1900 draw_screen_line(wp, &wlv);
1901
1902 // When line got too long for screen break
1903 // here.
1904 if (wlv.row == endrow)
1905 {
1906 ++wlv.row;
1907 break;
1908 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909 win_line_start(wp, &wlv, TRUE);
1910 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001911 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001912 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001913 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001914
1915 // If another text prop follows the condition below at
1916 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001917 // If this is an "above" text prop and 'nowrap' the we
1918 // must wrap anyway.
1919 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001920 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001921 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001923 else if (text_prop_next < text_prop_count
1924 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001925 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1926 || (!wp->w_p_wrap
1927 && wlv.col == wp->w_width - 1
1928 && (text_props[text_prop_next].tp_flags
1929 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001930 // When at last-but-one character and a text property
1931 // follows after it, we may need to flush the line after
1932 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001933 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001934 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 }
1936#endif
1937
Bram Moolenaare38fc862022-08-11 17:24:50 +01001938#ifdef FEAT_SEARCH_EXTRA
1939 if (wlv.n_extra == 0)
1940 {
1941 // Check for start/end of 'hlsearch' and other matches.
1942 // After end, check for start/end of next match.
1943 // When another match, have to check for start again.
1944 v = (long)(ptr - line);
1945 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1946 &screen_search_hl, &has_match_conc,
1947 &match_conc, did_line_attr, lcs_eol_one,
1948 &on_last_col);
1949 ptr = line + v; // "line" may have been changed
1950 prev_ptr = ptr;
1951
1952 // Do not allow a conceal over EOL otherwise EOL will be missed
1953 // and bad things happen.
1954 if (*ptr == NUL)
1955 has_match_conc = 0;
1956 }
1957#endif
1958
1959#ifdef FEAT_DIFF
1960 if (wlv.diff_hlf != (hlf_T)0)
1961 {
1962 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1963 && wlv.n_extra == 0)
1964 wlv.diff_hlf = HLF_TXD; // changed text
1965 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1966 && wlv.n_extra == 0)
1967 wlv.diff_hlf = HLF_CHD; // changed line
1968 line_attr = HL_ATTR(wlv.diff_hlf);
1969 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1970 && wp->w_p_culopt_flags != CULOPT_NBR
1971 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1972 && wlv.vcol <= right_curline_col)))
1973 line_attr = hl_combine_attr(
1974 line_attr, HL_ATTR(HLF_CUL));
1975 }
1976#endif
1977
Bram Moolenaara74fda62019-10-19 17:38:03 +02001978#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001979 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001980 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001981 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001982# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001983 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001984 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001985# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001986 // Get syntax attribute.
1987 if (has_syntax)
1988 {
1989 // Get the syntax attribute for the character. If there
1990 // is an error, disable syntax highlighting.
1991 save_did_emsg = did_emsg;
1992 did_emsg = FALSE;
1993
1994 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001995 if (v == prev_syntax_col)
1996 // at same column again
1997 syntax_attr = prev_syntax_attr;
1998 else
1999 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002000# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002001 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002002# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002003 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002004# ifdef FEAT_SPELL
2005 has_spell ? &can_spell :
2006# endif
2007 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002008 prev_syntax_col = v;
2009 prev_syntax_attr = syntax_attr;
2010 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002011
Bram Moolenaar34390282019-10-16 14:38:26 +02002012 if (did_emsg)
2013 {
2014 wp->w_s->b_syn_error = TRUE;
2015 has_syntax = FALSE;
2016 syntax_attr = 0;
2017 }
2018 else
2019 did_emsg = save_did_emsg;
2020# ifdef SYN_TIME_LIMIT
2021 if (wp->w_s->b_syn_slow)
2022 has_syntax = FALSE;
2023# endif
2024
2025 // Need to get the line again, a multi-line regexp may
2026 // have made it invalid.
2027 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2028 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002029 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002030# ifdef FEAT_CONCEAL
2031 // no concealing past the end of the line, it interferes
2032 // with line highlighting
2033 if (*ptr == NUL)
2034 syntax_flags = 0;
2035 else
2036 syntax_flags = get_syntax_info(&syntax_seqnr);
2037# endif
2038 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002039 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002040# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002041 // Combine text property highlight into syntax highlight.
2042 if (text_prop_type != NULL)
2043 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002044 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002045 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2046 else
2047 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002048 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002049 }
2050# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002051#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002052
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053 // Decide which of the highlight attributes to use.
2054 attr_pri = TRUE;
2055#ifdef LINE_ATTR
2056 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002058 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002059 if (!highlight_match)
2060 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002061 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002062# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002063 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002064# endif
2065 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002067 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002068 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002069# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002071# endif
2072 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002074 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2075 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002076 {
2077 // Use line_attr when not in the Visual or 'incsearch' area
2078 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002079# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002080 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002081# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002082 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002083# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084 attr_pri = FALSE;
2085 }
2086#else
2087 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002088 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002090 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091#endif
2092 else
2093 {
2094 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002095#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002096 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002097#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002098 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002099#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002101#ifdef FEAT_PROP_POPUP
2102 // override with text property highlight when "override" is TRUE
2103 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002104 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002105#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002107
2108 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002109 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002110 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002111 if (wlv.char_attr == 0)
2112 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002113 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002114 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002115 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002116
2117 // Get the next character to put on the screen.
2118
2119 // The "p_extra" points to the extra stuff that is inserted to
2120 // represent special characters (non-printable stuff) and other
2121 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002122 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002123 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2124 // "p_extra[n_extra]".
2125 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002126 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002127 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002128 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002129 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2131 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2133 if (enc_utf8 && utf_char2len(c) > 1)
2134 {
2135 mb_utf8 = TRUE;
2136 u8cc[0] = 0;
2137 c = 0xc0;
2138 }
2139 else
2140 mb_utf8 = FALSE;
2141 }
2142 else
2143 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 if (has_mbyte)
2146 {
2147 mb_c = c;
2148 if (enc_utf8)
2149 {
2150 // If the UTF-8 character is more than one byte:
2151 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002153 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002154 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002155 mb_l = 1;
2156 else if (mb_l > 1)
2157 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002158 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159 mb_utf8 = TRUE;
2160 c = 0xc0;
2161 }
2162 }
2163 else
2164 {
2165 // if this is a DBCS character, put it in "mb_c"
2166 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002167 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002168 mb_l = 1;
2169 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 }
2172 if (mb_l == 0) // at the NUL at end-of-line
2173 mb_l = 1;
2174
2175 // If a double-width char doesn't fit display a '>' in the
2176 // last column.
2177 if ((
2178# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002179 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002181 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 && (*mb_char2cells)(mb_c) == 2)
2183 {
2184 c = '>';
2185 mb_c = c;
2186 mb_l = 1;
2187 mb_utf8 = FALSE;
2188 multi_attr = HL_ATTR(HLF_AT);
2189#ifdef FEAT_SYN_HL
2190 if (cul_attr)
2191 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2192#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002193 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002194
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002195 // put the pointer back to output the double-width
2196 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197 ++wlv.n_extra;
2198 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002199 }
2200 else
2201 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002202 wlv.n_extra -= mb_l - 1;
2203 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 }
2205 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002206 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002209#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002210 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002211 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002212 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002213 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002214 if (search_attr == 0)
2215 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002216 if (area_attr == 0 && *ptr != NUL)
2217 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002218 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002219#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 }
2221 else
2222 {
2223#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002224 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002226 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002227
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002228 // Get a character from the line itself.
2229 c = *ptr;
2230#ifdef FEAT_LINEBREAK
2231 c0 = *ptr;
2232#endif
2233 if (has_mbyte)
2234 {
2235 mb_c = c;
2236 if (enc_utf8)
2237 {
2238 // If the UTF-8 character is more than one byte: Decode it
2239 // into "mb_c".
2240 mb_l = utfc_ptr2len(ptr);
2241 mb_utf8 = FALSE;
2242 if (mb_l > 1)
2243 {
2244 mb_c = utfc_ptr2char(ptr, u8cc);
2245 // Overlong encoded ASCII or ASCII with composing char
2246 // is displayed normally, except a NUL.
2247 if (mb_c < 0x80)
2248 {
2249 c = mb_c;
2250#ifdef FEAT_LINEBREAK
2251 c0 = mb_c;
2252#endif
2253 }
2254 mb_utf8 = TRUE;
2255
2256 // At start of the line we can have a composing char.
2257 // Draw it as a space with a composing char.
2258 if (utf_iscomposing(mb_c))
2259 {
2260 int i;
2261
2262 for (i = Screen_mco - 1; i > 0; --i)
2263 u8cc[i] = u8cc[i - 1];
2264 u8cc[0] = mb_c;
2265 mb_c = ' ';
2266 }
2267 }
2268
2269 if ((mb_l == 1 && c >= 0x80)
2270 || (mb_l >= 1 && mb_c == 0)
2271 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2272 {
2273 // Illegal UTF-8 byte: display as <xx>.
2274 // Non-BMP character : display as ? or fullwidth ?.
2275 transchar_hex(extra, mb_c);
2276# ifdef FEAT_RIGHTLEFT
2277 if (wp->w_p_rl) // reverse
2278 rl_mirror(extra);
2279# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002280 wlv.p_extra = extra;
2281 c = *wlv.p_extra;
2282 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002284 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2285 wlv.c_extra = NUL;
2286 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287 if (area_attr == 0 && search_attr == 0)
2288 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002290 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002291 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002292 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 }
2294 }
2295 else if (mb_l == 0) // at the NUL at end-of-line
2296 mb_l = 1;
2297#ifdef FEAT_ARABIC
2298 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2299 {
2300 // Do Arabic shaping.
2301 int pc, pc1, nc;
2302 int pcc[MAX_MCO];
2303
2304 // The idea of what is the previous and next
2305 // character depends on 'rightleft'.
2306 if (wp->w_p_rl)
2307 {
2308 pc = prev_c;
2309 pc1 = prev_c1;
2310 nc = utf_ptr2char(ptr + mb_l);
2311 prev_c1 = u8cc[0];
2312 }
2313 else
2314 {
2315 pc = utfc_ptr2char(ptr + mb_l, pcc);
2316 nc = prev_c;
2317 pc1 = pcc[0];
2318 }
2319 prev_c = mb_c;
2320
2321 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2322 }
2323 else
2324 prev_c = mb_c;
2325#endif
2326 }
2327 else // enc_dbcs
2328 {
2329 mb_l = MB_BYTE2LEN(c);
2330 if (mb_l == 0) // at the NUL at end-of-line
2331 mb_l = 1;
2332 else if (mb_l > 1)
2333 {
2334 // We assume a second byte below 32 is illegal.
2335 // Hopefully this is OK for all double-byte encodings!
2336 if (ptr[1] >= 32)
2337 mb_c = (c << 8) + ptr[1];
2338 else
2339 {
2340 if (ptr[1] == NUL)
2341 {
2342 // head byte at end of line
2343 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002344 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 }
2346 else
2347 {
2348 // illegal tail byte
2349 mb_l = 2;
2350 STRCPY(extra, "XX");
2351 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002352 wlv.p_extra = extra;
2353 wlv.n_extra = (int)STRLEN(extra) - 1;
2354 wlv.c_extra = NUL;
2355 wlv.c_final = NUL;
2356 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 if (area_attr == 0 && search_attr == 0)
2358 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002359 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002360 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002361 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002362 // save current attr
2363 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 }
2365 mb_c = c;
2366 }
2367 }
2368 }
2369 // If a double-width char doesn't fit display a '>' in the
2370 // last column; the character is displayed at the start of the
2371 // next line.
2372 if ((
2373# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002374 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002376 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002377 && (*mb_char2cells)(mb_c) == 2)
2378 {
2379 c = '>';
2380 mb_c = c;
2381 mb_utf8 = FALSE;
2382 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002383 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 // Put pointer back so that the character will be
2385 // displayed at the start of the next line.
2386 --ptr;
2387#ifdef FEAT_CONCEAL
2388 did_decrement_ptr = TRUE;
2389#endif
2390 }
2391 else if (*ptr != NUL)
2392 ptr += mb_l - 1;
2393
2394 // If a double-width char doesn't fit at the left side display
2395 // a '<' in the first column. Don't do this for unprintable
2396 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002399 wlv.n_extra = 1;
2400 wlv.c_extra = MB_FILLER_CHAR;
2401 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 c = ' ';
2403 if (area_attr == 0 && search_attr == 0)
2404 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002405 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002406 extra_attr = hl_combine_attr(
2407 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002408 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002409 }
2410 mb_c = c;
2411 mb_utf8 = FALSE;
2412 mb_l = 1;
2413 }
2414
2415 }
2416 ++ptr;
2417
2418 if (extra_check)
2419 {
2420#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421 // Check spelling (unless at the end of the line).
2422 // Only do this when there is no syntax highlighting, the
2423 // @Spell cluster is not used or the current syntax item
2424 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002425 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 if (has_spell && v >= word_end && v > cur_checked_col)
2427 {
2428 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002429 // do not calculate cap_col at the end of the line or when
2430 // only white space is following
2431 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432# ifdef FEAT_SYN_HL
2433 !has_syntax ||
2434# endif
2435 can_spell))
2436 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002437 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 int len;
2439 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002440
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002443
2444 // Use nextline[] if possible, it has the start of the
2445 // next line concatenated.
2446 if ((prev_ptr - line) - nextlinecol >= 0)
2447 p = nextline + (prev_ptr - line) - nextlinecol;
2448 else
2449 p = prev_ptr;
2450 cap_col -= (int)(prev_ptr - line);
2451 len = spell_check(wp, p, &spell_hlf, &cap_col,
2452 nochange);
2453 word_end = v + len;
2454
2455 // In Insert mode only highlight a word that
2456 // doesn't touch the cursor.
2457 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002458 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 && wp->w_cursor.lnum == lnum
2460 && wp->w_cursor.col >=
2461 (colnr_T)(prev_ptr - line)
2462 && wp->w_cursor.col < (colnr_T)word_end)
2463 {
2464 spell_hlf = HLF_COUNT;
2465 spell_redraw_lnum = lnum;
2466 }
2467
2468 if (spell_hlf == HLF_COUNT && p != prev_ptr
2469 && (p - nextline) + len > nextline_idx)
2470 {
2471 // Remember that the good word continues at the
2472 // start of the next line.
2473 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002474 checked_col = (int)((p - nextline)
2475 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 }
2477
2478 // Turn index into actual attributes.
2479 if (spell_hlf != HLF_COUNT)
2480 spell_attr = highlight_attr[spell_hlf];
2481
2482 if (cap_col > 0)
2483 {
2484 if (p != prev_ptr
2485 && (p - nextline) + cap_col >= nextline_idx)
2486 {
2487 // Remember that the word in the next line
2488 // must start with a capital.
2489 capcol_lnum = lnum + 1;
2490 cap_col = (int)((p - nextline) + cap_col
2491 - nextline_idx);
2492 }
2493 else
2494 // Compute the actual column.
2495 cap_col += (int)(prev_ptr - line);
2496 }
2497 }
2498 }
2499 if (spell_attr != 0)
2500 {
2501 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002502 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2503 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 wlv.char_attr = hl_combine_attr(spell_attr,
2506 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 }
2508#endif
2509#ifdef FEAT_LINEBREAK
2510 // Found last space before word: check for line break.
2511 if (wp->w_p_lbr && c0 == c
2512 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2513 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002514 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2515 : 0;
2516 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002517 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002519 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002520# ifdef FEAT_PROP_POPUP
2521 // do not want virtual text counted here
2522 cts.cts_has_prop_with_text = FALSE;
2523# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002524 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002525 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002526
2527 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002528 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002529 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002530 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2532 if (wlv.n_extra < 0)
2533 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002534 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002535 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002536 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002537 // line break, but for TABs the highlighting should
2538 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002539 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002540
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002542# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002543 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002544 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 wp->w_buffer->b_p_vts_array) - 1;
2546# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002547 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002548 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002549# endif
2550
Bram Moolenaar1306b362022-08-06 15:59:06 +01002551 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2552 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002553# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002554 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002555 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002556# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 if (VIM_ISWHITE(c))
2558 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002559# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 if (c == TAB)
2561 // See "Tab alignment" below.
2562 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002563# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 if (!wp->w_p_list)
2565 c = ' ';
2566 }
2567 }
2568#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002569 in_multispace = c == ' '
2570 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2571 if (!in_multispace)
2572 multispace_pos = 0;
2573
Bram Moolenaareed9d462021-02-15 20:38:25 +01002574 // 'list': Change char 160 to 'nbsp' and space to 'space'
2575 // setting in 'listchars'. But not when the character is
2576 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 if (wp->w_p_list
2578 && ((((c == 160 && mb_l == 1)
2579 || (mb_utf8
2580 && ((mb_c == 160 && mb_l == 2)
2581 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002582 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 || (c == ' '
2584 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002585 && (wp->w_lcs_chars.space
2586 || (in_multispace
2587 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002588 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589 && ptr - line <= trailcol)))
2590 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002591 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2592 {
2593 c = wp->w_lcs_chars.multispace[multispace_pos++];
2594 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2595 multispace_pos = 0;
2596 }
2597 else
2598 c = (c == ' ') ? wp->w_lcs_chars.space
2599 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600 if (area_attr == 0 && search_attr == 0)
2601 {
2602 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002603 extra_attr = hl_combine_attr(wlv.win_attr,
2604 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 }
2607 mb_c = c;
2608 if (enc_utf8 && utf_char2len(c) > 1)
2609 {
2610 mb_utf8 = TRUE;
2611 u8cc[0] = 0;
2612 c = 0xc0;
2613 }
2614 else
2615 mb_utf8 = FALSE;
2616 }
2617
zeertzjq2e7cba32022-06-10 15:30:32 +01002618 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2619 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002621 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2622 && wp->w_lcs_chars.leadmultispace != NULL)
2623 {
2624 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002625 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2626 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002627 multispace_pos = 0;
2628 }
2629
2630 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2631 c = wp->w_lcs_chars.trail;
2632
2633 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2634 c = wp->w_lcs_chars.lead;
2635
zeertzjq2e7cba32022-06-10 15:30:32 +01002636 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002637 c = wp->w_lcs_chars.space;
2638
2639
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640 if (!attr_pri)
2641 {
2642 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002643 extra_attr = hl_combine_attr(wlv.win_attr,
2644 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002645 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 }
2647 mb_c = c;
2648 if (enc_utf8 && utf_char2len(c) > 1)
2649 {
2650 mb_utf8 = TRUE;
2651 u8cc[0] = 0;
2652 c = 0xc0;
2653 }
2654 else
2655 mb_utf8 = FALSE;
2656 }
2657 }
2658
2659 // Handling of non-printable characters.
2660 if (!vim_isprintc(c))
2661 {
2662 // when getting a character from the file, we may have to
2663 // turn it into something else on the way to putting it
2664 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002665 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 {
2667 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002668 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002670 char_u *sbr = get_showbreak_value(wp);
2671
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672 // only adjust the tab_len, when at the first column
2673 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002674 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2675 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002676#endif
2677 // tab amount depends on current column
2678#ifdef FEAT_VARTABS
2679 tab_len = tabstop_padding(vcol_adjusted,
2680 wp->w_buffer->b_p_ts,
2681 wp->w_buffer->b_p_vts_array) - 1;
2682#else
2683 tab_len = (int)wp->w_buffer->b_p_ts
2684 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2685#endif
2686
2687#ifdef FEAT_LINEBREAK
2688 if (!wp->w_p_lbr || !wp->w_p_list)
2689#endif
2690 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002691 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002692#ifdef FEAT_LINEBREAK
2693 else
2694 {
2695 char_u *p;
2696 int len;
2697 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002698 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002700# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002701 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002703 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002704
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002706 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 && old_boguscols > 0
2708 && wlv.n_extra > tab_len)
2709 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002710# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002711 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002713 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002714 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002715 if (wp->w_lcs_chars.tab3)
2716 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002717 if (wlv.n_extra > 0)
2718 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002719 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002721 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002722 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002723 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002725 vim_memset(p, ' ', len);
2726 p[len] = NUL;
2727 vim_free(p_extra_free);
2728 p_extra_free = p;
2729 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002731 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002732
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002733 if (*p == NUL)
2734 {
2735 tab_len = i;
2736 break;
2737 }
2738
2739 // if tab3 is given, use it for the last char
2740 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2741 lcs = wp->w_lcs_chars.tab3;
2742 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002743 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002745 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002747# ifdef FEAT_CONCEAL
2748 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2749 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002750 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002751 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002752# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 }
2755#endif
2756#ifdef FEAT_CONCEAL
2757 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002758 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759
2760 // Tab alignment should be identical regardless of
2761 // 'conceallevel' value. So tab compensates of all
2762 // previous concealed characters, and thus resets
2763 // vcol_off and boguscols accumulated so far in the
2764 // line. Note that the tab can be longer than
2765 // 'tabstop' when there are concealed characters.
2766 FIX_FOR_BOGUSCOLS;
2767
2768 // Make sure, the highlighting for the tab char will be
2769 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002770 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002771 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002772 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002773 tab_len += vc_saved;
2774 }
2775#endif
2776 mb_utf8 = FALSE; // don't draw as UTF-8
2777 if (wp->w_p_list)
2778 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002779 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002780 ? wp->w_lcs_chars.tab3
2781 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782#ifdef FEAT_LINEBREAK
2783 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002784 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 else
2786#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 wlv.c_extra = wp->w_lcs_chars.tab2;
2788 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002790 extra_attr = hl_combine_attr(wlv.win_attr,
2791 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002792 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 mb_c = c;
2794 if (enc_utf8 && utf_char2len(c) > 1)
2795 {
2796 mb_utf8 = TRUE;
2797 u8cc[0] = 0;
2798 c = 0xc0;
2799 }
2800 }
2801 else
2802 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002803 wlv.c_final = NUL;
2804 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 c = ' ';
2806 }
2807 }
2808 else if (c == NUL
2809 && (wp->w_p_list
2810 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002811 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 && VIsual_mode != Ctrl_V
2813 && (
2814# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002815 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002817 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818 && !(noinvcur
2819 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002820 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 && lcs_eol_one > 0)
2822 {
2823 // Display a '$' after the line or highlight an extra
2824 // character if the line break is included.
2825#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2826 // For a diff line the highlighting continues after the
2827 // "$".
2828 if (
2829# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002830 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831# ifdef LINE_ATTR
2832 &&
2833# endif
2834# endif
2835# ifdef LINE_ATTR
2836 line_attr == 0
2837# endif
2838 )
2839#endif
2840 {
2841 // In virtualedit, visual selections may extend
2842 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002843 if (!(area_highlighting && virtual_active()
2844 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002845 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002846 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002848 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2849 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 else
2851 c = ' ';
2852 lcs_eol_one = -1;
2853 --ptr; // put it back at the NUL
2854 if (!attr_pri)
2855 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002856 extra_attr = hl_combine_attr(wlv.win_attr,
2857 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 n_attr = 1;
2859 }
2860 mb_c = c;
2861 if (enc_utf8 && utf_char2len(c) > 1)
2862 {
2863 mb_utf8 = TRUE;
2864 u8cc[0] = 0;
2865 c = 0xc0;
2866 }
2867 else
2868 mb_utf8 = FALSE; // don't draw as UTF-8
2869 }
2870 else if (c != NUL)
2871 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002872 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2873 if (wlv.n_extra == 0)
2874 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002875#ifdef FEAT_RIGHTLEFT
2876 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002877 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 wlv.c_extra = NUL;
2880 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881#ifdef FEAT_LINEBREAK
2882 if (wp->w_p_lbr)
2883 {
2884 char_u *p;
2885
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 c = *wlv.p_extra;
2887 p = alloc(wlv.n_extra + 1);
2888 vim_memset(p, ' ', wlv.n_extra);
2889 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2890 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893 }
2894 else
2895#endif
2896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 wlv.n_extra = byte2cells(c) - 1;
2898 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 }
2900 if (!attr_pri)
2901 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002903 extra_attr = hl_combine_attr(wlv.win_attr,
2904 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002905 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906 }
2907 mb_utf8 = FALSE; // don't draw as UTF-8
2908 }
2909 else if (VIsual_active
2910 && (VIsual_mode == Ctrl_V
2911 || VIsual_mode == 'v')
2912 && virtual_active()
2913 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002914 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 && (
2916#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002917 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002919 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920 {
2921 c = ' ';
2922 --ptr; // put it back at the NUL
2923 }
2924#if defined(LINE_ATTR)
2925 else if ((
2926# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002927 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928# endif
2929# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002930 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931# endif
2932 line_attr != 0
2933 ) && (
2934# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002935 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002937 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002939 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940# endif
2941 < wp->w_width)))
2942 {
2943 // Highlight until the right side of the window
2944 c = ' ';
2945 --ptr; // put it back at the NUL
2946
2947 // Remember we do the char for line highlighting.
2948 ++did_line_attr;
2949
2950 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002953 || (wp->w_p_list &&
2954 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002955 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002959 wlv.diff_hlf = HLF_CHD;
2960 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2964 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002966 || (wlv.vcol >= left_curline_col
2967 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 wlv.char_attr = hl_combine_attr(
2969 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 }
2971 }
2972# endif
2973# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002974 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002976 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002977 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2978 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002980 if (!wlv.cul_screenline
2981 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002982 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 wlv.char_attr = hl_combine_attr(
2984 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 }
2986 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2988 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 }
2990# endif
2991 }
2992#endif
2993 }
2994
2995#ifdef FEAT_CONCEAL
2996 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002997 && (wp != curwin || lnum != wp->w_cursor.lnum
2998 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3000 && !(lnum_in_visual_area
3001 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3002 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003003 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003004 if (((prev_syntax_id != syntax_seqnr
3005 && (syntax_flags & HL_CONCEAL) != 0)
3006 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003007 && (syn_get_sub_char() != NUL
3008 || (has_match_conc && match_conc)
3009 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 && wp->w_p_cole != 3)
3011 {
3012 // First time at this concealed item: display one
3013 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003014 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 c = match_conc;
3016 else if (syn_get_sub_char() != NUL)
3017 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003018 else if (wp->w_lcs_chars.conceal != NUL)
3019 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 else
3021 c = ' ';
3022
3023 prev_syntax_id = syntax_seqnr;
3024
Bram Moolenaar1306b362022-08-06 15:59:06 +01003025 if (wlv.n_extra > 0)
3026 wlv.vcol_off += wlv.n_extra;
3027 wlv.vcol += wlv.n_extra;
3028 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 {
3030# ifdef FEAT_RIGHTLEFT
3031 if (wp->w_p_rl)
3032 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003033 wlv.col -= wlv.n_extra;
3034 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 }
3036 else
3037# endif
3038 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 wlv.boguscols += wlv.n_extra;
3040 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 }
3042 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044 n_attr = 0;
3045 }
3046 else if (n_skip == 0)
3047 {
3048 is_concealing = TRUE;
3049 n_skip = 1;
3050 }
3051 mb_c = c;
3052 if (enc_utf8 && utf_char2len(c) > 1)
3053 {
3054 mb_utf8 = TRUE;
3055 u8cc[0] = 0;
3056 c = 0xc0;
3057 }
3058 else
3059 mb_utf8 = FALSE; // don't draw as UTF-8
3060 }
3061 else
3062 {
3063 prev_syntax_id = 0;
3064 is_concealing = FALSE;
3065 }
3066
3067 if (n_skip > 0 && did_decrement_ptr)
3068 // not showing the '>', put pointer back to avoid getting stuck
3069 ++ptr;
3070
3071#endif // FEAT_CONCEAL
3072 }
3073
3074#ifdef FEAT_CONCEAL
3075 // In the cursor line and we may be concealing characters: correct
3076 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003077 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003078 && wp == curwin && lnum == wp->w_cursor.lnum
3079 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003080 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003082# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003084 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003086# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003087 wp->w_wcol = wlv.col - wlv.boguscols;
3088 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 did_wcol = TRUE;
3090 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003091# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003092 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003093# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094 }
3095#endif
3096
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003097 // Use "extra_attr", but don't override visual selection highlighting,
3098 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003099 // Don't use "extra_attr" until n_attr_skip is zero.
3100 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003101 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003102 && (!attr_pri
3103#ifdef FEAT_PROP_POPUP
3104 || (text_prop_flags & PT_FLAG_OVERRIDE)
3105#endif
3106 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 {
3108#ifdef LINE_ATTR
3109 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003110 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 else
3112#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003113 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 }
3115
3116#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3117 // XIM don't send preedit_start and preedit_end, but they send
3118 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3119 // im_is_preediting() here.
3120 if (p_imst == IM_ON_THE_SPOT
3121 && xic != NULL
3122 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003123 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 && !p_imdisable
3125 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003126 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 {
3128 colnr_T tcol;
3129
3130 if (preedit_end_col == MAXCOL)
3131 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3132 else
3133 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003134 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 {
3136 if (feedback_old_attr < 0)
3137 {
3138 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 wlv.char_attr = im_get_feedback_attr(feedback_col);
3142 if (wlv.char_attr < 0)
3143 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 feedback_col++;
3145 }
3146 else if (feedback_old_attr >= 0)
3147 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 feedback_old_attr = -1;
3150 feedback_col = 0;
3151 }
3152 }
3153#endif
3154 // Handle the case where we are in column 0 but not on the first
3155 // character of the line and the user wants us to show us a
3156 // special character (via 'listchars' option "precedes:<char>".
3157 if (lcs_prec_todo != NUL
3158 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003159 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003160 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003161 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162#ifdef FEAT_DIFF
3163 && filler_todo <= 0
3164#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 && c != NUL)
3167 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003168 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 lcs_prec_todo = NUL;
3170 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3171 {
3172 // Double-width character being overwritten by the "precedes"
3173 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 wlv.c_extra = MB_FILLER_CHAR;
3175 wlv.c_final = NUL;
3176 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003178 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 }
3180 mb_c = c;
3181 if (enc_utf8 && utf_char2len(c) > 1)
3182 {
3183 mb_utf8 = TRUE;
3184 u8cc[0] = 0;
3185 c = 0xc0;
3186 }
3187 else
3188 mb_utf8 = FALSE; // don't draw as UTF-8
3189 if (!attr_pri)
3190 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003191 saved_attr3 = wlv.char_attr; // save current attr
3192 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 n_attr3 = 1;
3194 }
3195 }
3196
3197 // At end of the text line or just after the last character.
3198 if ((c == NUL
3199#if defined(LINE_ATTR)
3200 || did_line_attr == 1
3201#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003202 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 {
3204#ifdef FEAT_SEARCH_EXTRA
3205 // flag to indicate whether prevcol equals startcol of search_hl or
3206 // one of the matches
3207 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3208 (long)(ptr - line) - (c == NUL));
3209#endif
3210 // Invert at least one char, used for Visual and empty line or
3211 // highlight match at end of line. If it's beyond the last
3212 // char on the screen, just overwrite that one (tricky!) Not
3213 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003214 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003215 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 && (VIsual_mode != Ctrl_V
3217 || lnum == VIsual.lnum
3218 || lnum == curwin->w_cursor.lnum)
3219 && c == NUL)
3220#ifdef FEAT_SEARCH_EXTRA
3221 // highlight 'hlsearch' match at end of line
3222 || (prevcol_hl_flag
3223# ifdef FEAT_SYN_HL
3224 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3225 && !(wp == curwin && VIsual_active))
3226# endif
3227# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003228 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229# endif
3230# if defined(LINE_ATTR)
3231 && did_line_attr <= 1
3232# endif
3233 )
3234#endif
3235 ))
3236 {
3237 int n = 0;
3238
3239#ifdef FEAT_RIGHTLEFT
3240 if (wp->w_p_rl)
3241 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 n = 1;
3244 }
3245 else
3246#endif
3247 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003248 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249 n = -1;
3250 }
3251 if (n != 0)
3252 {
3253 // At the window boundary, highlight the last character
3254 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 wlv.off += n;
3256 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 }
3258 else
3259 {
3260 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003261 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003263 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 }
3265#ifdef FEAT_SEARCH_EXTRA
3266 if (area_attr == 0)
3267 {
3268 // Use attributes from match with highest priority among
3269 // 'search_hl' and the match list.
3270 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003271 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003272 }
3273#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003275 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276#ifdef FEAT_RIGHTLEFT
3277 if (wp->w_p_rl)
3278 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 --wlv.col;
3280 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281 }
3282 else
3283#endif
3284 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003285 ++wlv.col;
3286 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 ++wlv.vcol;
3289 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 }
3291 }
3292
3293 // At end of the text line.
3294 if (c == NUL)
3295 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003296 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297
3298 // Update w_cline_height and w_cline_folded if the cursor line was
3299 // updated (saves a call to plines() later).
3300 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3301 {
3302 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304#ifdef FEAT_FOLDING
3305 curwin->w_cline_folded = FALSE;
3306#endif
3307 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3308 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 break;
3310 }
3311
3312 // Show "extends" character from 'listchars' if beyond the line end and
3313 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003314 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003315 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 && wp->w_p_list
3317 && !wp->w_p_wrap
3318#ifdef FEAT_DIFF
3319 && filler_todo <= 0
3320#endif
3321 && (
3322#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003323 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003327 || lcs_eol_one > 0
3328 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003329 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003331 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003332 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 mb_c = c;
3334 if (enc_utf8 && utf_char2len(c) > 1)
3335 {
3336 mb_utf8 = TRUE;
3337 u8cc[0] = 0;
3338 c = 0xc0;
3339 }
3340 else
3341 mb_utf8 = FALSE;
3342 }
3343
3344#ifdef FEAT_SYN_HL
3345 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003346 if (wlv.draw_color_col)
3347 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348
3349 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3350 // highlight the cursor position itself.
3351 // Also highlight the 'colorcolumn' if it is different than
3352 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003353 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3354 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003356 if (((wlv.draw_state == WL_LINE
3357 || wlv.draw_state == WL_BRI
3358 || wlv.draw_state == WL_SBR)
3359 && !lnum_in_visual_area
3360 && search_attr == 0
3361 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003362# ifdef FEAT_DIFF
3363 && filler_todo <= 0
3364# endif
3365 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 {
3367 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3368 && lnum != wp->w_cursor.lnum)
3369 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003370 vcol_save_attr = wlv.char_attr;
3371 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3372 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003374 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003376 vcol_save_attr = wlv.char_attr;
3377 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 }
3379 }
3380#endif
3381
3382 // Store character to be displayed.
3383 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 {
3387 // Store the character.
3388#if defined(FEAT_RIGHTLEFT)
3389 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3390 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003391 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 --wlv.off;
3393 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394 }
3395#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003396 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 if (enc_dbcs == DBCS_JPNU)
3398 {
3399 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003400 ScreenLines[wlv.off] = 0x8e;
3401 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 }
3403 else if (enc_utf8)
3404 {
3405 if (mb_utf8)
3406 {
3407 int i;
3408
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003411 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412 for (i = 0; i < Screen_mco; ++i)
3413 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003414 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 if (u8cc[i] == 0)
3416 break;
3417 }
3418 }
3419 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 }
3422 if (multi_attr)
3423 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003424 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 multi_attr = 0;
3426 }
3427 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003428 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003430 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003431
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3433 {
3434 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 ++wlv.off;
3436 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 if (enc_utf8)
3438 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003439 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 else
3441 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003442 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003443 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444#ifdef FEAT_DIFF
3445 && filler_todo <= 0
3446#endif
3447 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 // When "tocol" is halfway a character, set it to the end of
3450 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003453
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003454 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003455
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456#ifdef FEAT_RIGHTLEFT
3457 if (wp->w_p_rl)
3458 {
3459 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 --wlv.off;
3461 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 }
3463#endif
3464 }
3465#ifdef FEAT_RIGHTLEFT
3466 if (wp->w_p_rl)
3467 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 --wlv.off;
3469 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 }
3471 else
3472#endif
3473 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 ++wlv.off;
3475 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 }
3477 }
3478#ifdef FEAT_CONCEAL
3479 else if (wp->w_p_cole > 0 && is_concealing)
3480 {
3481 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 if (wlv.n_extra > 0)
3484 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 if (wp->w_p_wrap)
3486 {
3487 // Special voodoo required if 'wrap' is on.
3488 //
3489 // Advance the column indicator to force the line
3490 // drawing to wrap early. This will make the line
3491 // take up the same screen space when parts are concealed,
3492 // so that cursor line computations aren't messed up.
3493 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003494 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 // trailing junk to be written out of the screen line
3496 // we are building, 'boguscols' keeps track of the number
3497 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003498 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501# ifdef FEAT_RIGHTLEFT
3502 if (wp->w_p_rl)
3503 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003504 wlv.col -= wlv.n_extra;
3505 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 }
3507 else
3508# endif
3509 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003510 wlv.col += wlv.n_extra;
3511 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003513 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 n_attr = 0;
3515 }
3516
3517
3518 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3519 {
3520 // Need to fill two screen columns.
3521# ifdef FEAT_RIGHTLEFT
3522 if (wp->w_p_rl)
3523 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 --wlv.boguscols;
3525 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 }
3527 else
3528# endif
3529 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 ++wlv.boguscols;
3531 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 }
3533 }
3534
3535# ifdef FEAT_RIGHTLEFT
3536 if (wp->w_p_rl)
3537 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003538 --wlv.boguscols;
3539 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540 }
3541 else
3542# endif
3543 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 ++wlv.boguscols;
3545 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 }
3547 }
3548 else
3549 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003550 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003552 wlv.vcol += wlv.n_extra;
3553 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 n_attr = 0;
3555 }
3556 }
3557
3558 }
3559#endif // FEAT_CONCEAL
3560 else
3561 --n_skip;
3562
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 // Only advance the "wlv.vcol" when after the 'number' or
3564 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003565 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566#ifdef FEAT_DIFF
3567 && filler_todo <= 0
3568#endif
3569 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571
3572#ifdef FEAT_SYN_HL
3573 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003574 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575#endif
3576
3577 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3579 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580
3581 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003582 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003583 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003584 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003585 if (n_attr_skip > 0)
3586 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587
3588 // At end of screen line and there is more to come: Display the line
3589 // so far. If there is no more to display it is caught above.
3590 if ((
3591#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003595 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003596 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597#ifdef FEAT_DIFF
3598 || filler_todo > 0
3599#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003600#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003601 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003602#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003603 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003604 && wlv.p_extra != at_end_str)
3605 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3606 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 )
3608 {
3609#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 screen_line(wp, wlv.screen_row, wp->w_wincol,
3611 wlv.col - wlv.boguscols,
3612 wp->w_width, wlv.screen_line_flags);
3613 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003615 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3616 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 ++wlv.row;
3619 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620
3621 // When not wrapping and finished diff lines, or when displayed
3622 // '$' and highlighting until last column, break here.
3623 if ((!wp->w_p_wrap
3624#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003625 && filler_todo <= 0
3626#endif
3627#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003628 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629#endif
3630 ) || lcs_eol_one == -1)
3631 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003632#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003633 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003634 {
3635 // do not output more of the line, only the "below" prop
3636 ptr += STRLEN(ptr);
3637# ifdef FEAT_LINEBREAK
3638 dont_use_showbreak = TRUE;
3639# endif
3640 }
3641#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642
3643 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645#ifdef FEAT_DIFF
3646 && filler_todo <= 0
3647#endif
3648 )
3649 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3651 draw_vsep_win(wp, wlv.row);
3652 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 }
3654
3655 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003656 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 break;
3660 }
3661
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003662 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663#ifdef FEAT_DIFF
3664 && filler_todo <= 0
3665#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003666#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003667 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003668#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 && wp->w_width == Columns)
3670 {
3671 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003672 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673
3674 // Special trick to make copy/paste of wrapped lines work with
3675 // xterm/screen: write an extra character beyond the end of
3676 // the line. This will work with all terminal types
3677 // (regardless of the xn,am settings).
3678 // Only do this on a fast tty.
3679 // Only do this if the cursor is on the current line
3680 // (something has been written in it).
3681 // Don't do this for the GUI.
3682 // Don't do this for double-width characters.
3683 // Don't do this for a window not at the right screen border.
3684 if (p_tf
3685#ifdef FEAT_GUI
3686 && !gui.in_use
3687#endif
3688 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003689 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3690 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003692 || (*mb_off2cells)(
3693 LineOffset[wlv.screen_row - 1]
3694 + (int)Columns - 2,
3695 LineOffset[wlv.screen_row]
3696 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 {
3698 // First make sure we are at the end of the screen line,
3699 // then output the same character again to let the
3700 // terminal know about the wrap. If the terminal doesn't
3701 // auto-wrap, we overwrite the character.
3702 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003703 screen_char(LineOffset[wlv.screen_row - 1]
3704 + (unsigned)Columns - 1,
3705 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706
3707 // When there is a multi-byte character, just output a
3708 // space to keep it simple.
3709 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 out_char(' ');
3712 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 + (Columns - 1)]);
3715 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003716 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 screen_start(); // don't know where cursor is now
3718 }
3719 }
3720
Bram Moolenaar1306b362022-08-06 15:59:06 +01003721 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722
Bram Moolenaareed9d462021-02-15 20:38:25 +01003723 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003725 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003727 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003729 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 need_showbreak = TRUE;
3731#endif
3732#ifdef FEAT_DIFF
3733 --filler_todo;
3734 // When the filler lines are actually below the last line of the
3735 // file, don't draw the line itself, break here.
3736 if (filler_todo == 0 && wp->w_botfill)
3737 break;
3738#endif
3739 }
3740
3741 } // for every character in the line
3742
3743#ifdef FEAT_SPELL
3744 // After an empty line check first word for capital.
3745 if (*skipwhite(line) == NUL)
3746 {
3747 capcol_lnum = lnum + 1;
3748 cap_col = 0;
3749 }
3750#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003751#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 vim_free(text_props);
3753 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755#endif
3756
3757 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003758 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759}