blob: 7f9660349b0c9296354b0da582564afca5bfadd2 [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 Moolenaarb7963df2022-07-31 17:12:43 +0100669 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100670 int saved_search_attr = 0; // search_attr to be used when n_extra
671 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200672#endif
673#ifdef FEAT_SPELL
674 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000675 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200676# define SPWORDLEN 150
677 char_u nextline[SPWORDLEN * 2];// text with start of the next line
678 int nextlinecol = 0; // column where nextline[] starts
679 int nextline_idx = 0; // index in nextline[] where next line
680 // starts
681 int spell_attr = 0; // attributes desired by spelling
682 int word_end = 0; // last byte with same spell_attr
683 static linenr_T checked_lnum = 0; // line number for "checked_col"
684 static int checked_col = 0; // column in "checked_lnum" up to which
685 // there are no spell errors
686 static int cap_col = -1; // column to check for Cap word
687 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
688 int cur_checked_col = 0; // checked column for current line
689#endif
690 int extra_check = 0; // has extra highlighting
691 int multi_attr = 0; // attributes desired by multibyte
692 int mb_l = 1; // multi-byte byte length
693 int mb_c = 0; // decoded multi-byte character
694 int mb_utf8 = FALSE; // screen char is UTF-8 char
695 int u8cc[MAX_MCO]; // composing UTF-8 chars
696#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
697 int filler_lines = 0; // nr of filler lines to be drawn
698 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000699#else
700# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200701#endif
702#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200703 int change_start = MAXCOL; // first col of changed area
704 int change_end = -1; // last col of changed area
705#endif
706 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100707 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200708 int in_multispace = FALSE; // in multiple consecutive spaces
709 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200710#ifdef FEAT_LINEBREAK
711 int need_showbreak = FALSE; // overlong line, skipping first x
712 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100713 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200714#endif
715#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
716 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
717# define LINE_ATTR
718 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100719 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200720#endif
721#ifdef FEAT_SIGNS
722 int sign_present = FALSE;
723 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000724 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200725#endif
726#ifdef FEAT_ARABIC
727 int prev_c = 0; // previous Arabic character
728 int prev_c1 = 0; // first composing char for prev_c
729#endif
730#if defined(LINE_ATTR)
731 int did_line_attr = 0;
732#endif
733#ifdef FEAT_TERMINAL
734 int get_term_attr = FALSE;
735#endif
736#ifdef FEAT_SYN_HL
737 int cul_attr = 0; // set when 'cursorline' active
738
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200739 // margin columns for the screen line, needed for when 'cursorlineopt'
740 // contains "screenline"
741 int left_curline_col = 0;
742 int right_curline_col = 0;
743#endif
744
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200745#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
746 int feedback_col = 0;
747 int feedback_old_attr = -1;
748#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200749
750#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
751 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000752 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200753#endif
754#ifdef FEAT_CONCEAL
755 int syntax_flags = 0;
756 int syntax_seqnr = 0;
757 int prev_syntax_id = 0;
758 int conceal_attr = HL_ATTR(HLF_CONCEAL);
759 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200760 int did_wcol = FALSE;
761 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100762# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200763# define FIX_FOR_BOGUSCOLS \
764 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100765 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100766 wlv.vcol -= wlv.vcol_off; \
767 wlv.vcol_off = 0; \
768 wlv.col -= wlv.boguscols; \
769 old_boguscols = wlv.boguscols; \
770 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200771 }
772#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100773# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200774#endif
775
776 if (startrow > endrow) // past the end already!
777 return startrow;
778
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100779 CLEAR_FIELD(wlv);
780
781 wlv.lnum = lnum;
782 wlv.startrow = startrow;
783 wlv.row = startrow;
784 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200785
786 if (!number_only)
787 {
788 // To speed up the loop below, set extra_check when there is linebreak,
789 // trailing white space and/or syntax processing to be done.
790#ifdef FEAT_LINEBREAK
791 extra_check = wp->w_p_lbr;
792#endif
793#ifdef FEAT_SYN_HL
794 if (syntax_present(wp) && !wp->w_s->b_syn_error
795# ifdef SYN_TIME_LIMIT
796 && !wp->w_s->b_syn_slow
797# endif
798 )
799 {
800 // Prepare for syntax highlighting in this line. When there is an
801 // error, stop syntax highlighting.
802 save_did_emsg = did_emsg;
803 did_emsg = FALSE;
804 syntax_start(wp, lnum);
805 if (did_emsg)
806 wp->w_s->b_syn_error = TRUE;
807 else
808 {
809 did_emsg = save_did_emsg;
810#ifdef SYN_TIME_LIMIT
811 if (!wp->w_s->b_syn_slow)
812#endif
813 {
814 has_syntax = TRUE;
815 extra_check = TRUE;
816 }
817 }
818 }
819
820 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100821 wlv.color_cols = wp->w_p_cc_cols;
822 if (wlv.color_cols != NULL)
823 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200824#endif
825
826#ifdef FEAT_TERMINAL
827 if (term_show_buffer(wp->w_buffer))
828 {
829 extra_check = TRUE;
830 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100831 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200832 }
833#endif
834
835#ifdef FEAT_SPELL
836 if (wp->w_p_spell
837 && *wp->w_s->b_p_spl != NUL
838 && wp->w_s->b_langp.ga_len > 0
839 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
840 {
841 // Prepare for spell checking.
842 has_spell = TRUE;
843 extra_check = TRUE;
844
845 // Get the start of the next line, so that words that wrap to the
846 // next line are found too: "et<line-break>al.".
847 // Trick: skip a few chars for C/shell/Vim comments
848 nextline[SPWORDLEN] = NUL;
849 if (lnum < wp->w_buffer->b_ml.ml_line_count)
850 {
851 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
852 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
853 }
854
855 // When a word wrapped from the previous line the start of the
856 // current line is valid.
857 if (lnum == checked_lnum)
858 cur_checked_col = checked_col;
859 checked_lnum = 0;
860
861 // When there was a sentence end in the previous line may require a
862 // word starting with capital in this line. In line 1 always check
863 // the first word.
864 if (lnum != capcol_lnum)
865 cap_col = -1;
866 if (lnum == 1)
867 cap_col = 0;
868 capcol_lnum = 0;
869 }
870#endif
871
872 // handle Visual active in this window
873 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
874 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100875 pos_T *top, *bot;
876
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200877 if (LTOREQ_POS(curwin->w_cursor, VIsual))
878 {
879 // Visual is after curwin->w_cursor
880 top = &curwin->w_cursor;
881 bot = &VIsual;
882 }
883 else
884 {
885 // Visual is before curwin->w_cursor
886 top = &VIsual;
887 bot = &curwin->w_cursor;
888 }
889 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
890 if (VIsual_mode == Ctrl_V)
891 {
892 // block mode
893 if (lnum_in_visual_area)
894 {
895 fromcol = wp->w_old_cursor_fcol;
896 tocol = wp->w_old_cursor_lcol;
897 }
898 }
899 else
900 {
901 // non-block mode
902 if (lnum > top->lnum && lnum <= bot->lnum)
903 fromcol = 0;
904 else if (lnum == top->lnum)
905 {
906 if (VIsual_mode == 'V') // linewise
907 fromcol = 0;
908 else
909 {
910 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
911 if (gchar_pos(top) == NUL)
912 tocol = fromcol + 1;
913 }
914 }
915 if (VIsual_mode != 'V' && lnum == bot->lnum)
916 {
917 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
918 {
919 fromcol = -10;
920 tocol = MAXCOL;
921 }
922 else if (bot->col == MAXCOL)
923 tocol = MAXCOL;
924 else
925 {
926 pos = *bot;
927 if (*p_sel == 'e')
928 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
929 else
930 {
931 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
932 ++tocol;
933 }
934 }
935 }
936 }
937
938 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200939 if (!highlight_match && lnum == curwin->w_cursor.lnum
940 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941#ifdef FEAT_GUI
942 && !gui.in_use
943#endif
944 )
945 noinvcur = TRUE;
946
947 // if inverting in this line set area_highlighting
948 if (fromcol >= 0)
949 {
950 area_highlighting = TRUE;
951 vi_attr = HL_ATTR(HLF_V);
952#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
953 if ((clip_star.available && !clip_star.owned
954 && clip_isautosel_star())
955 || (clip_plus.available && !clip_plus.owned
956 && clip_isautosel_plus()))
957 vi_attr = HL_ATTR(HLF_VNC);
958#endif
959 }
960 }
961
962 // handle 'incsearch' and ":s///c" highlighting
963 else if (highlight_match
964 && wp == curwin
965 && lnum >= curwin->w_cursor.lnum
966 && lnum <= curwin->w_cursor.lnum + search_match_lines)
967 {
968 if (lnum == curwin->w_cursor.lnum)
969 getvcol(curwin, &(curwin->w_cursor),
970 (colnr_T *)&fromcol, NULL, NULL);
971 else
972 fromcol = 0;
973 if (lnum == curwin->w_cursor.lnum + search_match_lines)
974 {
975 pos.lnum = lnum;
976 pos.col = search_match_endcol;
977 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
978 }
979 else
980 tocol = MAXCOL;
981 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100982 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200983 tocol = fromcol + 1;
984 area_highlighting = TRUE;
985 vi_attr = HL_ATTR(HLF_I);
986 }
987 }
988
989#ifdef FEAT_DIFF
990 filler_lines = diff_check(wp, lnum);
991 if (filler_lines < 0)
992 {
993 if (filler_lines == -1)
994 {
995 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100996 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100998 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001000 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001 }
1002 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001003 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004 filler_lines = 0;
1005 area_highlighting = TRUE;
1006 }
1007 if (lnum == wp->w_topline)
1008 filler_lines = wp->w_topfill;
1009 filler_todo = filler_lines;
1010#endif
1011
1012#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01001013 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +00001014 if (sign_present)
1015 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001016#endif
1017
1018#ifdef LINE_ATTR
1019# ifdef FEAT_SIGNS
1020 // If this line has a sign with line highlighting set line_attr.
1021 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001022 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023# endif
1024# if defined(FEAT_QUICKFIX)
1025 // Highlight the current line in the quickfix window.
1026 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1027 line_attr = HL_ATTR(HLF_QFL);
1028# endif
1029 if (line_attr != 0)
1030 area_highlighting = TRUE;
1031#endif
1032
1033 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1034 ptr = line;
1035
1036#ifdef FEAT_SPELL
1037 if (has_spell && !number_only)
1038 {
1039 // For checking first word with a capital skip white space.
1040 if (cap_col == 0)
1041 cap_col = getwhitecols(line);
1042
1043 // To be able to spell-check over line boundaries copy the end of the
1044 // current line into nextline[]. Above the start of the next line was
1045 // copied to nextline[SPWORDLEN].
1046 if (nextline[SPWORDLEN] == NUL)
1047 {
1048 // No next line or it is empty.
1049 nextlinecol = MAXCOL;
1050 nextline_idx = 0;
1051 }
1052 else
1053 {
1054 v = (long)STRLEN(line);
1055 if (v < SPWORDLEN)
1056 {
1057 // Short line, use it completely and append the start of the
1058 // next line.
1059 nextlinecol = 0;
1060 mch_memmove(nextline, line, (size_t)v);
1061 STRMOVE(nextline + v, nextline + SPWORDLEN);
1062 nextline_idx = v + 1;
1063 }
1064 else
1065 {
1066 // Long line, use only the last SPWORDLEN bytes.
1067 nextlinecol = v - SPWORDLEN;
1068 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1069 nextline_idx = SPWORDLEN + 1;
1070 }
1071 }
1072 }
1073#endif
1074
1075 if (wp->w_p_list)
1076 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001077 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001078 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001079 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001080 || wp->w_lcs_chars.trail
1081 || wp->w_lcs_chars.lead
1082 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001084
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001086 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 {
1088 trailcol = (colnr_T)STRLEN(ptr);
1089 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1090 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001091 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001093 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001094 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001095 {
1096 leadcol = 0;
1097 while (VIM_ISWHITE(ptr[leadcol]))
1098 ++leadcol;
1099 if (ptr[leadcol] == NUL)
1100 // in a line full of spaces all of them are treated as trailing
1101 leadcol = (colnr_T)0;
1102 else
1103 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001104 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001105 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106 }
1107
1108 wcr_attr = get_wcr_attr(wp);
1109 if (wcr_attr != 0)
1110 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001111 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112 area_highlighting = TRUE;
1113 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001114
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001115#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001117 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118#endif
1119
1120 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1121 // first character to be displayed.
1122 if (wp->w_p_wrap)
1123 v = wp->w_skipcol;
1124 else
1125 v = wp->w_leftcol;
1126 if (v > 0 && !number_only)
1127 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001128 char_u *prev_ptr = ptr;
1129 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001130 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001132 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001133 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001135 charsize = win_lbr_chartabsize(&cts, NULL);
1136 cts.cts_vcol += charsize;
1137 prev_ptr = cts.cts_ptr;
1138 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001140 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001141 ptr = cts.cts_ptr;
1142 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143
1144 // When:
1145 // - 'cuc' is set, or
1146 // - 'colorcolumn' is set, or
1147 // - 'virtualedit' is set, or
1148 // - the visual mode is active,
1149 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001150 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001152 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153#endif
1154 virtual_active() ||
1155 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001156 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001157
1158 // Handle a character that's not completely on the screen: Put ptr at
1159 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001160 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001162 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 ptr = prev_ptr;
1164 // If the character fits on the screen, don't need to skip it.
1165 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001166 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1167 && wlv.col == 0)
1168 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 }
1170
1171 // Adjust for when the inverted text is before the screen,
1172 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001173 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001175 else if (fromcol >= 0 && fromcol < wlv.vcol)
1176 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177
1178#ifdef FEAT_LINEBREAK
1179 // When w_skipcol is non-zero, first line needs 'showbreak'
1180 if (wp->w_p_wrap)
1181 need_showbreak = TRUE;
1182#endif
1183#ifdef FEAT_SPELL
1184 // When spell checking a word we need to figure out the start of the
1185 // word and if it's badly spelled or not.
1186 if (has_spell)
1187 {
1188 int len;
1189 colnr_T linecol = (colnr_T)(ptr - line);
1190 hlf_T spell_hlf = HLF_COUNT;
1191
1192 pos = wp->w_cursor;
1193 wp->w_cursor.lnum = lnum;
1194 wp->w_cursor.col = linecol;
1195 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1196
1197 // spell_move_to() may call ml_get() and make "line" invalid
1198 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1199 ptr = line + linecol;
1200
1201 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1202 {
1203 // no bad word found at line start, don't check until end of a
1204 // word
1205 spell_hlf = HLF_COUNT;
1206 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1207 }
1208 else
1209 {
1210 // bad word found, use attributes until end of word
1211 word_end = wp->w_cursor.col + len + 1;
1212
1213 // Turn index into actual attributes.
1214 if (spell_hlf != HLF_COUNT)
1215 spell_attr = highlight_attr[spell_hlf];
1216 }
1217 wp->w_cursor = pos;
1218
1219# ifdef FEAT_SYN_HL
1220 // Need to restart syntax highlighting for this line.
1221 if (has_syntax)
1222 syntax_start(wp, lnum);
1223# endif
1224 }
1225#endif
1226 }
1227
1228 // Correct highlighting for cursor that can't be disabled.
1229 // Avoids having to check this for each character.
1230 if (fromcol >= 0)
1231 {
1232 if (noinvcur)
1233 {
1234 if ((colnr_T)fromcol == wp->w_virtcol)
1235 {
1236 // highlighting starts at cursor, let it start just after the
1237 // cursor
1238 fromcol_prev = fromcol;
1239 fromcol = -1;
1240 }
1241 else if ((colnr_T)fromcol < wp->w_virtcol)
1242 // restart highlighting after the cursor
1243 fromcol_prev = wp->w_virtcol;
1244 }
1245 if (fromcol >= tocol)
1246 fromcol = -1;
1247 }
1248
1249#ifdef FEAT_SEARCH_EXTRA
1250 if (!number_only)
1251 {
1252 v = (long)(ptr - line);
1253 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1254 &line, &screen_search_hl,
1255 &search_attr);
1256 ptr = line + v; // "line" may have been updated
1257 }
1258#endif
1259
1260#ifdef FEAT_SYN_HL
1261 // Cursor line highlighting for 'cursorline' in the current window.
1262 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1263 {
1264 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001265 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266 if (!(wp == curwin && VIsual_active)
1267 && wp->w_p_culopt_flags != CULOPT_NBR)
1268 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001269 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1271
1272 // Only set line_attr here when "screenline" is not present in
1273 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001274 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 {
1276 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001277# ifdef FEAT_SIGNS
1278 // Combine the 'cursorline' and sign highlighting, depending on
1279 // the sign priority.
1280 if (sign_present && sattr.sat_linehl > 0)
1281 {
1282 if (sattr.sat_priority >= 100)
1283 line_attr = hl_combine_attr(cul_attr, line_attr);
1284 else
1285 line_attr = hl_combine_attr(line_attr, cul_attr);
1286 }
1287 else
1288# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001289# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001290 // let the line attribute overrule 'cursorline', otherwise
1291 // it disappears when both have background set;
1292 // 'cursorline' can use underline or bold to make it show
1293 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001294# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001295 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001296# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 }
1298 else
1299 {
1300 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1302 }
1303 area_highlighting = TRUE;
1304 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 }
1306#endif
1307
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001308#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001309 {
1310 char_u *prop_start;
1311
1312 text_prop_count = get_text_props(wp->w_buffer, lnum,
1313 &prop_start, FALSE);
1314 if (text_prop_count > 0)
1315 {
1316 // Make a copy of the properties, so that they are properly
1317 // aligned.
1318 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1319 if (text_props != NULL)
1320 mch_memmove(text_props, prop_start,
1321 text_prop_count * sizeof(textprop_T));
1322
1323 // Allocate an array for the indexes.
1324 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001325 if (text_prop_idxs == NULL)
1326 VIM_CLEAR(text_props);
1327
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 area_highlighting = TRUE;
1329 extra_check = TRUE;
1330 }
1331 }
1332#endif
1333
Bram Moolenaar1306b362022-08-06 15:59:06 +01001334 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335
1336 // Repeat for the whole displayed line.
1337 for (;;)
1338 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001339 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001341 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342#endif
1343#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001344 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001346
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001348 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001350#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001351 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001352 {
1353 cul_attr = 0;
1354 line_attr = line_attr_save;
1355 }
1356#endif
1357
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001359 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001361 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 if (cmdwin_type != 0 && wp == curwin)
1363 {
1364 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001365 wlv.n_extra = 1;
1366 wlv.c_extra = cmdwin_type;
1367 wlv.c_final = NUL;
1368 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370 }
1371#endif
1372
1373#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001374 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375 {
1376 int fdc = compute_foldcolumn(wp, 0);
1377
Bram Moolenaar1306b362022-08-06 15:59:06 +01001378 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 if (fdc > 0)
1380 {
1381 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1382 // already be in use.
1383 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001384 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 if (p_extra_free != NULL)
1386 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001387 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001388 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001389 p_extra_free[wlv.n_extra] = NUL;
1390 wlv.p_extra = p_extra_free;
1391 wlv.c_extra = NUL;
1392 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001393 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001394 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001395 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1396 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001397 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001398 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 }
1400 }
1401 }
1402#endif
1403
1404#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001405 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001407 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 // Show the sign column when there are any signs in this
1409 // buffer or when using Netbeans.
1410 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001411 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1412 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 }
1414#endif
1415
Bram Moolenaar1306b362022-08-06 15:59:06 +01001416 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001418 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 // Display the absolute or relative line number. After the
1420 // first fill with blanks when the 'n' flag isn't in 'cpo'
1421 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001422 && (wlv.row == startrow + filler_lines
1423 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 {
1425#ifdef FEAT_SIGNS
1426 // If 'signcolumn' is set to 'number' and a sign is present
1427 // in 'lnum', then display the sign instead of the line
1428 // number.
1429 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1430 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001431 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1432 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 else
1434#endif
1435 {
1436 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001437 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 {
1439 long num;
1440 char *fmt = "%*ld ";
1441
1442 if (wp->w_p_nu && !wp->w_p_rnu)
1443 // 'number' + 'norelativenumber'
1444 num = (long)lnum;
1445 else
1446 {
1447 // 'relativenumber', don't use negative numbers
1448 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1449 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1450 {
1451 // 'number' + 'relativenumber'
1452 num = lnum;
1453 fmt = "%-*ld ";
1454 }
1455 }
1456
1457 sprintf((char *)extra, fmt,
1458 number_width(wp), num);
1459 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001460 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1461 ++wlv.p_extra)
1462 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463#ifdef FEAT_RIGHTLEFT
1464 if (wp->w_p_rl) // reverse line numbers
1465 {
1466 char_u *p1, *p2;
1467 int t;
1468
1469 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001470 p2 = skipwhite(extra);
1471 p2 = skiptowhite(p2) - 1;
1472 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 {
1474 t = *p1;
1475 *p1 = *p2;
1476 *p2 = t;
1477 }
1478 }
1479#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001480 wlv.p_extra = extra;
1481 wlv.c_extra = NUL;
1482 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 }
1484 else
1485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001486 wlv.c_extra = ' ';
1487 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001489 wlv.n_extra = number_width(wp) + 1;
1490 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491#ifdef FEAT_SYN_HL
1492 // When 'cursorline' is set highlight the line number of
1493 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001494 // When 'cursorlineopt' does not have "line" only
1495 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496 // TODO: Can we use CursorLine instead of CursorLineNr
1497 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001498 if (wp->w_p_cul
1499 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001501 && (wlv.row == startrow + filler_lines
1502 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001503 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001504 wlv.char_attr = hl_combine_attr(wcr_attr,
1505 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001507 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1508 && HL_ATTR(HLF_LNA) != 0)
1509 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001510 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001511 HL_ATTR(HLF_LNA));
1512 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1513 && HL_ATTR(HLF_LNB) != 0)
1514 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001515 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001516 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517 }
James McCoya80aad72021-12-22 19:45:28 +00001518#ifdef FEAT_SIGNS
1519 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001520 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001521#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 }
1523 }
1524
1525#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001526 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1527 && wlv.n_extra == 0
1528 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001530 wlv.draw_state = WL_BRI;
1531 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1532 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001534 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535
1536 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001537 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001539 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001541 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542# ifdef FEAT_DIFF
1543 && filler_lines == 0
1544# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001545# ifdef FEAT_PROP_POPUP
1546 && !dont_use_showbreak
1547# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548 )
1549 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001550 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001552 if (wlv.diff_hlf != (hlf_T)0)
1553 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001555 wlv.p_extra = NULL;
1556 wlv.c_extra = ' ';
1557 wlv.c_final = NUL;
1558 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001560 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001561 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001562 wlv.n_extra -= win_col_off2(wp);
1563 if (wlv.n_extra < 0)
1564 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001565 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001566 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001567 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 // Correct end of highlighted area for 'breakindent',
1569 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001570 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001571 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572 }
1573 }
1574#endif
1575
1576#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001577 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001579 char_u *sbr;
1580
Bram Moolenaar1306b362022-08-06 15:59:06 +01001581 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582# ifdef FEAT_DIFF
1583 if (filler_todo > 0)
1584 {
1585 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001586 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001588 wlv.c_extra = '-';
1589 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001590 }
1591 else
1592 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001593 wlv.c_extra = wp->w_fill_chars.diff;
1594 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 }
1596# ifdef FEAT_RIGHTLEFT
1597 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001598 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 else
1600# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001601 wlv.n_extra = wp->w_width - wlv.col;
1602 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 }
1604# endif
1605# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001606 sbr = get_showbreak_value(wp);
1607 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 {
1609 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001610 wlv.p_extra = sbr;
1611 wlv.c_extra = NUL;
1612 wlv.c_final = NUL;
1613 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001614 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1615 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001616 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 // Correct end of highlighted area for 'showbreak',
1618 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001619 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001620 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001622 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1623 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001624# ifdef FEAT_SYN_HL
1625 // combine 'showbreak' with 'cursorline'
1626 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001627 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1628 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629# endif
1630 }
1631# endif
1632 }
1633#endif
1634
Bram Moolenaar1306b362022-08-06 15:59:06 +01001635 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001637 wlv.draw_state = WL_LINE;
1638 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001639 {
1640 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001641 wlv.n_extra = wlv.saved_n_extra;
1642 wlv.c_extra = wlv.saved_c_extra;
1643 wlv.c_final = wlv.saved_c_final;
1644 wlv.p_extra = wlv.saved_p_extra;
1645 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 }
1647 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001648 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649 }
1650 }
1651#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001652 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001653 && wlv.vcol >= left_curline_col
1654 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001656 cul_attr = HL_ATTR(HLF_CUL);
1657 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 }
1659#endif
1660
1661 // When still displaying '$' of change command, stop at cursor.
1662 // When only displaying the (relative) line number and that's done,
1663 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001664 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001665 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001666 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667#ifdef FEAT_DIFF
1668 && filler_todo <= 0
1669#endif
1670 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001672 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1673 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 // Pretend we have finished updating the window. Except when
1675 // 'cursorcolumn' is set.
1676#ifdef FEAT_SYN_HL
1677 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001678 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 else
1680#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001681 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 break;
1683 }
1684
Bram Moolenaar1306b362022-08-06 15:59:06 +01001685 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001686 {
1687 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001688 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001689 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 && (*mb_ptr2cells)(ptr) > 1)
1691 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001692 && vcol_prev < wlv.vcol // not at margin
1693 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 area_attr = vi_attr; // start highlighting
1695 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001696 && (wlv.vcol == tocol
1697 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 area_attr = 0; // stop highlighting
1699
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001700#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701 if (text_props != NULL)
1702 {
1703 int pi;
1704 int bcol = (int)(ptr - line);
1705
Bram Moolenaar1306b362022-08-06 15:59:06 +01001706 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001707# ifdef FEAT_LINEBREAK
1708 && !in_linebreak
1709# endif
1710 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 --bcol; // still working on the previous char, e.g. Tab
1712
1713 // Check if any active property ends.
1714 for (pi = 0; pi < text_props_active; ++pi)
1715 {
1716 int tpi = text_prop_idxs[pi];
1717
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001718 if (text_props[tpi].tp_col != MAXCOL
1719 && bcol >= text_props[tpi].tp_col - 1
1720 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 {
1722 if (pi + 1 < text_props_active)
1723 mch_memmove(text_prop_idxs + pi,
1724 text_prop_idxs + pi + 1,
1725 sizeof(int)
1726 * (text_props_active - (pi + 1)));
1727 --text_props_active;
1728 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001729# ifdef FEAT_LINEBREAK
1730 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001731 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001732 syntax_attr = 0;
1733# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 }
1735 }
1736
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001737# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001738 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001739 // not on the next char yet, don't start another prop
1740 --bcol;
1741# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001743 // With 'nowrap' and not in the first screen line only "below"
1744 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001746 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001747 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001748 && (wp->w_p_wrap
1749 || wlv.row == startrow
1750 || (text_props[text_prop_next].tp_flags
1751 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001752 || (bcol == 0 &&
1753 (text_props[text_prop_next].tp_flags
1754 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001755 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001756 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001757 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001758 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1759 {
1760 // first display the '$' after the line
1761 text_prop_follows = TRUE;
1762 break;
1763 }
1764 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001765 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001766 + text_props[text_prop_next].tp_len)
1767 text_prop_idxs[text_props_active++] = text_prop_next;
1768 ++text_prop_next;
1769 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001771 if (wlv.n_extra == 0 || !extra_for_textprop)
1772 {
1773 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001774 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001775 text_prop_flags = 0;
1776 text_prop_type = NULL;
1777 text_prop_id = 0;
1778 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001779 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001781 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001782 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001783 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001784
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 // Sort the properties on priority and/or starting last.
1786 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001787 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001788 sort_text_props(wp->w_buffer, text_props,
1789 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790
1791 for (pi = 0; pi < text_props_active; ++pi)
1792 {
1793 int tpi = text_prop_idxs[pi];
1794 proptype_T *pt = text_prop_type_by_id(
1795 wp->w_buffer, text_props[tpi].tp_type);
1796
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001797 if (pt != NULL && (pt->pt_hl_id > 0
1798 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001799 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001801 if (pt->pt_hl_id > 0)
1802 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 text_prop_type = pt;
1804 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001805 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001806 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001807 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001808 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001809 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 }
1811 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001812 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001813 && -text_prop_id
1814 <= wp->w_buffer->b_textprop_text.ga_len)
1815 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001816 textprop_T *tp = &text_props[used_tpi];
1817 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001818 ->b_textprop_text.ga_data)[
1819 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001820
1821 // reset the ID in the copy to avoid it being used
1822 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001823 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001824
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001825 if (p != NULL)
1826 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001827 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001828 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001829 int above = (tp->tp_flags
1830 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001831 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001832 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001833 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1834 int padding = tp->tp_col == MAXCOL
1835 && tp->tp_len > 1
1836 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001837
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001838 // Insert virtual text before the current
1839 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001840 wlv.p_extra = p;
1841 wlv.c_extra = NUL;
1842 wlv.c_final = NUL;
1843 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001844 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001845 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001846 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001847 saved_search_attr = search_attr;
1848 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001849 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001850 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001851 if (*ptr == NUL)
1852 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001853 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001854#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001855 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001856 {
1857 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001858 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001859 need_showbreak = FALSE;
1860 dont_use_showbreak = TRUE;
1861 }
1862#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001863 if ((right || above || below || !wrap
1864 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001865 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001866 char_u *prev_p_extra = wlv.p_extra;
1867 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001868
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001869 // Take care of padding, right-align and
1870 // truncation.
1871 // Shared with win_lbr_chartabsize(), must do
1872 // exactly the same.
1873 start_line = text_prop_position(wp, tp,
1874 wlv.col,
1875 &wlv.n_extra, &wlv.p_extra,
1876 &n_attr, &n_attr_skip);
1877 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001878 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001879 // wlv.p_extra was allocated
1880 vim_free(p_extra_free2);
1881 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001882 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001883
1884 // When 'wrap' is off then for "below" we need
1885 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001886 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001887 {
1888 draw_screen_line(wp, &wlv);
1889
1890 // When line got too long for screen break
1891 // here.
1892 if (wlv.row == endrow)
1893 {
1894 ++wlv.row;
1895 break;
1896 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 win_line_start(wp, &wlv, TRUE);
1898 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001899 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001900 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001901 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001902
1903 // If another text prop follows the condition below at
1904 // the last window column must know.
1905 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001906 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001908 else if (text_prop_next < text_prop_count
1909 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001910 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1911 || (!wp->w_p_wrap
1912 && wlv.col == wp->w_width - 1
1913 && (text_props[text_prop_next].tp_flags
1914 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001915 // When at last-but-one character and a text property
1916 // follows after it, we may need to flush the line after
1917 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001918 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001919 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001920 }
1921#endif
1922
Bram Moolenaare38fc862022-08-11 17:24:50 +01001923#ifdef FEAT_SEARCH_EXTRA
1924 if (wlv.n_extra == 0)
1925 {
1926 // Check for start/end of 'hlsearch' and other matches.
1927 // After end, check for start/end of next match.
1928 // When another match, have to check for start again.
1929 v = (long)(ptr - line);
1930 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1931 &screen_search_hl, &has_match_conc,
1932 &match_conc, did_line_attr, lcs_eol_one,
1933 &on_last_col);
1934 ptr = line + v; // "line" may have been changed
1935 prev_ptr = ptr;
1936
1937 // Do not allow a conceal over EOL otherwise EOL will be missed
1938 // and bad things happen.
1939 if (*ptr == NUL)
1940 has_match_conc = 0;
1941 }
1942#endif
1943
1944#ifdef FEAT_DIFF
1945 if (wlv.diff_hlf != (hlf_T)0)
1946 {
1947 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1948 && wlv.n_extra == 0)
1949 wlv.diff_hlf = HLF_TXD; // changed text
1950 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1951 && wlv.n_extra == 0)
1952 wlv.diff_hlf = HLF_CHD; // changed line
1953 line_attr = HL_ATTR(wlv.diff_hlf);
1954 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1955 && wp->w_p_culopt_flags != CULOPT_NBR
1956 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1957 && wlv.vcol <= right_curline_col)))
1958 line_attr = hl_combine_attr(
1959 line_attr, HL_ATTR(HLF_CUL));
1960 }
1961#endif
1962
Bram Moolenaara74fda62019-10-19 17:38:03 +02001963#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001964 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001965 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001966 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001967# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001968 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001969 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001970# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001971 // Get syntax attribute.
1972 if (has_syntax)
1973 {
1974 // Get the syntax attribute for the character. If there
1975 // is an error, disable syntax highlighting.
1976 save_did_emsg = did_emsg;
1977 did_emsg = FALSE;
1978
1979 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001980 if (v == prev_syntax_col)
1981 // at same column again
1982 syntax_attr = prev_syntax_attr;
1983 else
1984 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001985# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001986 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001987# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001988 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001989# ifdef FEAT_SPELL
1990 has_spell ? &can_spell :
1991# endif
1992 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001993 prev_syntax_col = v;
1994 prev_syntax_attr = syntax_attr;
1995 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001996
Bram Moolenaar34390282019-10-16 14:38:26 +02001997 if (did_emsg)
1998 {
1999 wp->w_s->b_syn_error = TRUE;
2000 has_syntax = FALSE;
2001 syntax_attr = 0;
2002 }
2003 else
2004 did_emsg = save_did_emsg;
2005# ifdef SYN_TIME_LIMIT
2006 if (wp->w_s->b_syn_slow)
2007 has_syntax = FALSE;
2008# endif
2009
2010 // Need to get the line again, a multi-line regexp may
2011 // have made it invalid.
2012 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2013 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002014 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002015# ifdef FEAT_CONCEAL
2016 // no concealing past the end of the line, it interferes
2017 // with line highlighting
2018 if (*ptr == NUL)
2019 syntax_flags = 0;
2020 else
2021 syntax_flags = get_syntax_info(&syntax_seqnr);
2022# endif
2023 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002024 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002025# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002026 // Combine text property highlight into syntax highlight.
2027 if (text_prop_type != NULL)
2028 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002029 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002030 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2031 else
2032 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002033 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002034 }
2035# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002036#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002037
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 // Decide which of the highlight attributes to use.
2039 attr_pri = TRUE;
2040#ifdef LINE_ATTR
2041 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002043 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002044 if (!highlight_match)
2045 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002046 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002047# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002048 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002049# endif
2050 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002052 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002053 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002054# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002055 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002056# endif
2057 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002058 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002059 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2060 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 {
2062 // Use line_attr when not in the Visual or 'incsearch' area
2063 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002064# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002065 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002066# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002067 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002068# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 attr_pri = FALSE;
2070 }
2071#else
2072 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002073 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002075 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002076#endif
2077 else
2078 {
2079 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002080#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002081 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002082#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002083 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002084#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002086#ifdef FEAT_PROP_POPUP
2087 // override with text property highlight when "override" is TRUE
2088 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002089 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002090#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002092
2093 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002094 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002095 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002096 if (wlv.char_attr == 0)
2097 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002098 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002099 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002100 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101
2102 // Get the next character to put on the screen.
2103
2104 // The "p_extra" points to the extra stuff that is inserted to
2105 // represent special characters (non-printable stuff) and other
2106 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002107 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002108 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2109 // "p_extra[n_extra]".
2110 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002111 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002112 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002113 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002114 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002115 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2116 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002117 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2118 if (enc_utf8 && utf_char2len(c) > 1)
2119 {
2120 mb_utf8 = TRUE;
2121 u8cc[0] = 0;
2122 c = 0xc0;
2123 }
2124 else
2125 mb_utf8 = FALSE;
2126 }
2127 else
2128 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130 if (has_mbyte)
2131 {
2132 mb_c = c;
2133 if (enc_utf8)
2134 {
2135 // If the UTF-8 character is more than one byte:
2136 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002139 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002140 mb_l = 1;
2141 else if (mb_l > 1)
2142 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002143 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002144 mb_utf8 = TRUE;
2145 c = 0xc0;
2146 }
2147 }
2148 else
2149 {
2150 // if this is a DBCS character, put it in "mb_c"
2151 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002153 mb_l = 1;
2154 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002155 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002156 }
2157 if (mb_l == 0) // at the NUL at end-of-line
2158 mb_l = 1;
2159
2160 // If a double-width char doesn't fit display a '>' in the
2161 // last column.
2162 if ((
2163# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002164 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002166 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002167 && (*mb_char2cells)(mb_c) == 2)
2168 {
2169 c = '>';
2170 mb_c = c;
2171 mb_l = 1;
2172 mb_utf8 = FALSE;
2173 multi_attr = HL_ATTR(HLF_AT);
2174#ifdef FEAT_SYN_HL
2175 if (cul_attr)
2176 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2177#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002178 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002179
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180 // put the pointer back to output the double-width
2181 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002182 ++wlv.n_extra;
2183 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184 }
2185 else
2186 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002187 wlv.n_extra -= mb_l - 1;
2188 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189 }
2190 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002193 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002194#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002195 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002196 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002197 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002198 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002199 if (search_attr == 0)
2200 search_attr = saved_search_attr;
2201 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002202#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 }
2204 else
2205 {
2206#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002207 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002209 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 // Get a character from the line itself.
2212 c = *ptr;
2213#ifdef FEAT_LINEBREAK
2214 c0 = *ptr;
2215#endif
2216 if (has_mbyte)
2217 {
2218 mb_c = c;
2219 if (enc_utf8)
2220 {
2221 // If the UTF-8 character is more than one byte: Decode it
2222 // into "mb_c".
2223 mb_l = utfc_ptr2len(ptr);
2224 mb_utf8 = FALSE;
2225 if (mb_l > 1)
2226 {
2227 mb_c = utfc_ptr2char(ptr, u8cc);
2228 // Overlong encoded ASCII or ASCII with composing char
2229 // is displayed normally, except a NUL.
2230 if (mb_c < 0x80)
2231 {
2232 c = mb_c;
2233#ifdef FEAT_LINEBREAK
2234 c0 = mb_c;
2235#endif
2236 }
2237 mb_utf8 = TRUE;
2238
2239 // At start of the line we can have a composing char.
2240 // Draw it as a space with a composing char.
2241 if (utf_iscomposing(mb_c))
2242 {
2243 int i;
2244
2245 for (i = Screen_mco - 1; i > 0; --i)
2246 u8cc[i] = u8cc[i - 1];
2247 u8cc[0] = mb_c;
2248 mb_c = ' ';
2249 }
2250 }
2251
2252 if ((mb_l == 1 && c >= 0x80)
2253 || (mb_l >= 1 && mb_c == 0)
2254 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2255 {
2256 // Illegal UTF-8 byte: display as <xx>.
2257 // Non-BMP character : display as ? or fullwidth ?.
2258 transchar_hex(extra, mb_c);
2259# ifdef FEAT_RIGHTLEFT
2260 if (wp->w_p_rl) // reverse
2261 rl_mirror(extra);
2262# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002263 wlv.p_extra = extra;
2264 c = *wlv.p_extra;
2265 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002267 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2268 wlv.c_extra = NUL;
2269 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 if (area_attr == 0 && search_attr == 0)
2271 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002273 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002274 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002275 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276 }
2277 }
2278 else if (mb_l == 0) // at the NUL at end-of-line
2279 mb_l = 1;
2280#ifdef FEAT_ARABIC
2281 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2282 {
2283 // Do Arabic shaping.
2284 int pc, pc1, nc;
2285 int pcc[MAX_MCO];
2286
2287 // The idea of what is the previous and next
2288 // character depends on 'rightleft'.
2289 if (wp->w_p_rl)
2290 {
2291 pc = prev_c;
2292 pc1 = prev_c1;
2293 nc = utf_ptr2char(ptr + mb_l);
2294 prev_c1 = u8cc[0];
2295 }
2296 else
2297 {
2298 pc = utfc_ptr2char(ptr + mb_l, pcc);
2299 nc = prev_c;
2300 pc1 = pcc[0];
2301 }
2302 prev_c = mb_c;
2303
2304 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2305 }
2306 else
2307 prev_c = mb_c;
2308#endif
2309 }
2310 else // enc_dbcs
2311 {
2312 mb_l = MB_BYTE2LEN(c);
2313 if (mb_l == 0) // at the NUL at end-of-line
2314 mb_l = 1;
2315 else if (mb_l > 1)
2316 {
2317 // We assume a second byte below 32 is illegal.
2318 // Hopefully this is OK for all double-byte encodings!
2319 if (ptr[1] >= 32)
2320 mb_c = (c << 8) + ptr[1];
2321 else
2322 {
2323 if (ptr[1] == NUL)
2324 {
2325 // head byte at end of line
2326 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002327 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002328 }
2329 else
2330 {
2331 // illegal tail byte
2332 mb_l = 2;
2333 STRCPY(extra, "XX");
2334 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002335 wlv.p_extra = extra;
2336 wlv.n_extra = (int)STRLEN(extra) - 1;
2337 wlv.c_extra = NUL;
2338 wlv.c_final = NUL;
2339 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002340 if (area_attr == 0 && search_attr == 0)
2341 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002342 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002343 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002344 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002345 // save current attr
2346 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347 }
2348 mb_c = c;
2349 }
2350 }
2351 }
2352 // If a double-width char doesn't fit display a '>' in the
2353 // last column; the character is displayed at the start of the
2354 // next line.
2355 if ((
2356# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002357 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002359 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360 && (*mb_char2cells)(mb_c) == 2)
2361 {
2362 c = '>';
2363 mb_c = c;
2364 mb_utf8 = FALSE;
2365 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002366 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 // Put pointer back so that the character will be
2368 // displayed at the start of the next line.
2369 --ptr;
2370#ifdef FEAT_CONCEAL
2371 did_decrement_ptr = TRUE;
2372#endif
2373 }
2374 else if (*ptr != NUL)
2375 ptr += mb_l - 1;
2376
2377 // If a double-width char doesn't fit at the left side display
2378 // a '<' in the first column. Don't do this for unprintable
2379 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002380 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002382 wlv.n_extra = 1;
2383 wlv.c_extra = MB_FILLER_CHAR;
2384 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385 c = ' ';
2386 if (area_attr == 0 && search_attr == 0)
2387 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002388 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002389 extra_attr = hl_combine_attr(
2390 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002391 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392 }
2393 mb_c = c;
2394 mb_utf8 = FALSE;
2395 mb_l = 1;
2396 }
2397
2398 }
2399 ++ptr;
2400
2401 if (extra_check)
2402 {
2403#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002404 // Check spelling (unless at the end of the line).
2405 // Only do this when there is no syntax highlighting, the
2406 // @Spell cluster is not used or the current syntax item
2407 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002408 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002409 if (has_spell && v >= word_end && v > cur_checked_col)
2410 {
2411 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002412 // do not calculate cap_col at the end of the line or when
2413 // only white space is following
2414 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002415# ifdef FEAT_SYN_HL
2416 !has_syntax ||
2417# endif
2418 can_spell))
2419 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002420 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421 int len;
2422 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002423
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002424 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426
2427 // Use nextline[] if possible, it has the start of the
2428 // next line concatenated.
2429 if ((prev_ptr - line) - nextlinecol >= 0)
2430 p = nextline + (prev_ptr - line) - nextlinecol;
2431 else
2432 p = prev_ptr;
2433 cap_col -= (int)(prev_ptr - line);
2434 len = spell_check(wp, p, &spell_hlf, &cap_col,
2435 nochange);
2436 word_end = v + len;
2437
2438 // In Insert mode only highlight a word that
2439 // doesn't touch the cursor.
2440 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002441 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 && wp->w_cursor.lnum == lnum
2443 && wp->w_cursor.col >=
2444 (colnr_T)(prev_ptr - line)
2445 && wp->w_cursor.col < (colnr_T)word_end)
2446 {
2447 spell_hlf = HLF_COUNT;
2448 spell_redraw_lnum = lnum;
2449 }
2450
2451 if (spell_hlf == HLF_COUNT && p != prev_ptr
2452 && (p - nextline) + len > nextline_idx)
2453 {
2454 // Remember that the good word continues at the
2455 // start of the next line.
2456 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002457 checked_col = (int)((p - nextline)
2458 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 }
2460
2461 // Turn index into actual attributes.
2462 if (spell_hlf != HLF_COUNT)
2463 spell_attr = highlight_attr[spell_hlf];
2464
2465 if (cap_col > 0)
2466 {
2467 if (p != prev_ptr
2468 && (p - nextline) + cap_col >= nextline_idx)
2469 {
2470 // Remember that the word in the next line
2471 // must start with a capital.
2472 capcol_lnum = lnum + 1;
2473 cap_col = (int)((p - nextline) + cap_col
2474 - nextline_idx);
2475 }
2476 else
2477 // Compute the actual column.
2478 cap_col += (int)(prev_ptr - line);
2479 }
2480 }
2481 }
2482 if (spell_attr != 0)
2483 {
2484 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002485 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2486 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002488 wlv.char_attr = hl_combine_attr(spell_attr,
2489 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 }
2491#endif
2492#ifdef FEAT_LINEBREAK
2493 // Found last space before word: check for line break.
2494 if (wp->w_p_lbr && c0 == c
2495 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2496 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002497 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2498 : 0;
2499 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002500 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002502 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002503# ifdef FEAT_PROP_POPUP
2504 // do not want virtual text counted here
2505 cts.cts_has_prop_with_text = FALSE;
2506# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002507 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002508 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002509
2510 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002511 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002512 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002513 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002514 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2515 if (wlv.n_extra < 0)
2516 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002517 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002518 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002519 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002520 // line break, but for TABs the highlighting should
2521 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002522 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002523
Bram Moolenaar1306b362022-08-06 15:59:06 +01002524 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002526 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002527 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 wp->w_buffer->b_p_vts_array) - 1;
2529# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002530 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002531 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532# endif
2533
Bram Moolenaar1306b362022-08-06 15:59:06 +01002534 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2535 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002536# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002537 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002538 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002539# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 if (VIM_ISWHITE(c))
2541 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002542# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 if (c == TAB)
2544 // See "Tab alignment" below.
2545 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002546# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 if (!wp->w_p_list)
2548 c = ' ';
2549 }
2550 }
2551#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002552 in_multispace = c == ' '
2553 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2554 if (!in_multispace)
2555 multispace_pos = 0;
2556
Bram Moolenaareed9d462021-02-15 20:38:25 +01002557 // 'list': Change char 160 to 'nbsp' and space to 'space'
2558 // setting in 'listchars'. But not when the character is
2559 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 if (wp->w_p_list
2561 && ((((c == 160 && mb_l == 1)
2562 || (mb_utf8
2563 && ((mb_c == 160 && mb_l == 2)
2564 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002565 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 || (c == ' '
2567 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002568 && (wp->w_lcs_chars.space
2569 || (in_multispace
2570 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002571 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 && ptr - line <= trailcol)))
2573 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002574 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2575 {
2576 c = wp->w_lcs_chars.multispace[multispace_pos++];
2577 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2578 multispace_pos = 0;
2579 }
2580 else
2581 c = (c == ' ') ? wp->w_lcs_chars.space
2582 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 if (area_attr == 0 && search_attr == 0)
2584 {
2585 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002586 extra_attr = hl_combine_attr(wlv.win_attr,
2587 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002588 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589 }
2590 mb_c = c;
2591 if (enc_utf8 && utf_char2len(c) > 1)
2592 {
2593 mb_utf8 = TRUE;
2594 u8cc[0] = 0;
2595 c = 0xc0;
2596 }
2597 else
2598 mb_utf8 = FALSE;
2599 }
2600
zeertzjq2e7cba32022-06-10 15:30:32 +01002601 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2602 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002604 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2605 && wp->w_lcs_chars.leadmultispace != NULL)
2606 {
2607 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002608 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2609 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002610 multispace_pos = 0;
2611 }
2612
2613 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2614 c = wp->w_lcs_chars.trail;
2615
2616 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2617 c = wp->w_lcs_chars.lead;
2618
zeertzjq2e7cba32022-06-10 15:30:32 +01002619 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002620 c = wp->w_lcs_chars.space;
2621
2622
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 if (!attr_pri)
2624 {
2625 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002626 extra_attr = hl_combine_attr(wlv.win_attr,
2627 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002628 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629 }
2630 mb_c = c;
2631 if (enc_utf8 && utf_char2len(c) > 1)
2632 {
2633 mb_utf8 = TRUE;
2634 u8cc[0] = 0;
2635 c = 0xc0;
2636 }
2637 else
2638 mb_utf8 = FALSE;
2639 }
2640 }
2641
2642 // Handling of non-printable characters.
2643 if (!vim_isprintc(c))
2644 {
2645 // when getting a character from the file, we may have to
2646 // turn it into something else on the way to putting it
2647 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002648 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 {
2650 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002651 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002653 char_u *sbr = get_showbreak_value(wp);
2654
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 // only adjust the tab_len, when at the first column
2656 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002657 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2658 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659#endif
2660 // tab amount depends on current column
2661#ifdef FEAT_VARTABS
2662 tab_len = tabstop_padding(vcol_adjusted,
2663 wp->w_buffer->b_p_ts,
2664 wp->w_buffer->b_p_vts_array) - 1;
2665#else
2666 tab_len = (int)wp->w_buffer->b_p_ts
2667 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2668#endif
2669
2670#ifdef FEAT_LINEBREAK
2671 if (!wp->w_p_lbr || !wp->w_p_list)
2672#endif
2673 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002674 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675#ifdef FEAT_LINEBREAK
2676 else
2677 {
2678 char_u *p;
2679 int len;
2680 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002681 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002683# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002684 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002686 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002687
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002689 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002690 && old_boguscols > 0
2691 && wlv.n_extra > tab_len)
2692 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002693# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002694 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002696 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002697 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002698 if (wp->w_lcs_chars.tab3)
2699 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002700 if (wlv.n_extra > 0)
2701 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002702 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002704 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002706 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002708 vim_memset(p, ' ', len);
2709 p[len] = NUL;
2710 vim_free(p_extra_free);
2711 p_extra_free = p;
2712 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002714 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002716 if (*p == NUL)
2717 {
2718 tab_len = i;
2719 break;
2720 }
2721
2722 // if tab3 is given, use it for the last char
2723 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2724 lcs = wp->w_lcs_chars.tab3;
2725 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002726 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002728 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002730# ifdef FEAT_CONCEAL
2731 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2732 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002733 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002735# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 }
2738#endif
2739#ifdef FEAT_CONCEAL
2740 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002741 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742
2743 // Tab alignment should be identical regardless of
2744 // 'conceallevel' value. So tab compensates of all
2745 // previous concealed characters, and thus resets
2746 // vcol_off and boguscols accumulated so far in the
2747 // line. Note that the tab can be longer than
2748 // 'tabstop' when there are concealed characters.
2749 FIX_FOR_BOGUSCOLS;
2750
2751 // Make sure, the highlighting for the tab char will be
2752 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002753 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002754 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002755 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756 tab_len += vc_saved;
2757 }
2758#endif
2759 mb_utf8 = FALSE; // don't draw as UTF-8
2760 if (wp->w_p_list)
2761 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002762 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002763 ? wp->w_lcs_chars.tab3
2764 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765#ifdef FEAT_LINEBREAK
2766 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768 else
2769#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002770 wlv.c_extra = wp->w_lcs_chars.tab2;
2771 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002773 extra_attr = hl_combine_attr(wlv.win_attr,
2774 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002775 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 mb_c = c;
2777 if (enc_utf8 && utf_char2len(c) > 1)
2778 {
2779 mb_utf8 = TRUE;
2780 u8cc[0] = 0;
2781 c = 0xc0;
2782 }
2783 }
2784 else
2785 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002786 wlv.c_final = NUL;
2787 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 c = ' ';
2789 }
2790 }
2791 else if (c == NUL
2792 && (wp->w_p_list
2793 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002794 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 && VIsual_mode != Ctrl_V
2796 && (
2797# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002798 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002800 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 && !(noinvcur
2802 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002803 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804 && lcs_eol_one > 0)
2805 {
2806 // Display a '$' after the line or highlight an extra
2807 // character if the line break is included.
2808#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2809 // For a diff line the highlighting continues after the
2810 // "$".
2811 if (
2812# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002813 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814# ifdef LINE_ATTR
2815 &&
2816# endif
2817# endif
2818# ifdef LINE_ATTR
2819 line_attr == 0
2820# endif
2821 )
2822#endif
2823 {
2824 // In virtualedit, visual selections may extend
2825 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002826 if (!(area_highlighting && virtual_active()
2827 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002828 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002829 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002831 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2832 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833 else
2834 c = ' ';
2835 lcs_eol_one = -1;
2836 --ptr; // put it back at the NUL
2837 if (!attr_pri)
2838 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002839 extra_attr = hl_combine_attr(wlv.win_attr,
2840 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 n_attr = 1;
2842 }
2843 mb_c = c;
2844 if (enc_utf8 && utf_char2len(c) > 1)
2845 {
2846 mb_utf8 = TRUE;
2847 u8cc[0] = 0;
2848 c = 0xc0;
2849 }
2850 else
2851 mb_utf8 = FALSE; // don't draw as UTF-8
2852 }
2853 else if (c != NUL)
2854 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002855 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2856 if (wlv.n_extra == 0)
2857 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858#ifdef FEAT_RIGHTLEFT
2859 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002860 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 wlv.c_extra = NUL;
2863 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864#ifdef FEAT_LINEBREAK
2865 if (wp->w_p_lbr)
2866 {
2867 char_u *p;
2868
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 c = *wlv.p_extra;
2870 p = alloc(wlv.n_extra + 1);
2871 vim_memset(p, ' ', wlv.n_extra);
2872 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2873 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 }
2877 else
2878#endif
2879 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002880 wlv.n_extra = byte2cells(c) - 1;
2881 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 }
2883 if (!attr_pri)
2884 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002885 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002886 extra_attr = hl_combine_attr(wlv.win_attr,
2887 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 }
2890 mb_utf8 = FALSE; // don't draw as UTF-8
2891 }
2892 else if (VIsual_active
2893 && (VIsual_mode == Ctrl_V
2894 || VIsual_mode == 'v')
2895 && virtual_active()
2896 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002897 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 && (
2899#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002900 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002902 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 {
2904 c = ' ';
2905 --ptr; // put it back at the NUL
2906 }
2907#if defined(LINE_ATTR)
2908 else if ((
2909# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002910 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911# endif
2912# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002913 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914# endif
2915 line_attr != 0
2916 ) && (
2917# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002918 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002922 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923# endif
2924 < wp->w_width)))
2925 {
2926 // Highlight until the right side of the window
2927 c = ' ';
2928 --ptr; // put it back at the NUL
2929
2930 // Remember we do the char for line highlighting.
2931 ++did_line_attr;
2932
2933 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002934 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002936 || (wp->w_p_list &&
2937 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002938 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002940 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002942 wlv.diff_hlf = HLF_CHD;
2943 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002945 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2947 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002948 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002949 || (wlv.vcol >= left_curline_col
2950 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 wlv.char_attr = hl_combine_attr(
2952 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 }
2954 }
2955# endif
2956# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002957 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002959 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002960 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2961 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 if (!wlv.cul_screenline
2964 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002965 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 wlv.char_attr = hl_combine_attr(
2967 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 }
2969 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2971 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 }
2973# endif
2974 }
2975#endif
2976 }
2977
2978#ifdef FEAT_CONCEAL
2979 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002980 && (wp != curwin || lnum != wp->w_cursor.lnum
2981 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2983 && !(lnum_in_visual_area
2984 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2985 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002987 if (((prev_syntax_id != syntax_seqnr
2988 && (syntax_flags & HL_CONCEAL) != 0)
2989 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002990 && (syn_get_sub_char() != NUL
2991 || (has_match_conc && match_conc)
2992 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 && wp->w_p_cole != 3)
2994 {
2995 // First time at this concealed item: display one
2996 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002997 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 c = match_conc;
2999 else if (syn_get_sub_char() != NUL)
3000 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003001 else if (wp->w_lcs_chars.conceal != NUL)
3002 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 else
3004 c = ' ';
3005
3006 prev_syntax_id = syntax_seqnr;
3007
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 if (wlv.n_extra > 0)
3009 wlv.vcol_off += wlv.n_extra;
3010 wlv.vcol += wlv.n_extra;
3011 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 {
3013# ifdef FEAT_RIGHTLEFT
3014 if (wp->w_p_rl)
3015 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 wlv.col -= wlv.n_extra;
3017 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 }
3019 else
3020# endif
3021 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003022 wlv.boguscols += wlv.n_extra;
3023 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 }
3025 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003026 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 n_attr = 0;
3028 }
3029 else if (n_skip == 0)
3030 {
3031 is_concealing = TRUE;
3032 n_skip = 1;
3033 }
3034 mb_c = c;
3035 if (enc_utf8 && utf_char2len(c) > 1)
3036 {
3037 mb_utf8 = TRUE;
3038 u8cc[0] = 0;
3039 c = 0xc0;
3040 }
3041 else
3042 mb_utf8 = FALSE; // don't draw as UTF-8
3043 }
3044 else
3045 {
3046 prev_syntax_id = 0;
3047 is_concealing = FALSE;
3048 }
3049
3050 if (n_skip > 0 && did_decrement_ptr)
3051 // not showing the '>', put pointer back to avoid getting stuck
3052 ++ptr;
3053
3054#endif // FEAT_CONCEAL
3055 }
3056
3057#ifdef FEAT_CONCEAL
3058 // In the cursor line and we may be concealing characters: correct
3059 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003060 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061 && wp == curwin && lnum == wp->w_cursor.lnum
3062 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003063 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003065# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003067 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003069# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003070 wp->w_wcol = wlv.col - wlv.boguscols;
3071 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 did_wcol = TRUE;
3073 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003074# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003075 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003076# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 }
3078#endif
3079
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003080 // Use "extra_attr", but don't override visual selection highlighting,
3081 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003082 // Don't use "extra_attr" until n_attr_skip is zero.
3083 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003084 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003085 && (!attr_pri
3086#ifdef FEAT_PROP_POPUP
3087 || (text_prop_flags & PT_FLAG_OVERRIDE)
3088#endif
3089 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 {
3091#ifdef LINE_ATTR
3092 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003093 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094 else
3095#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003096 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 }
3098
3099#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3100 // XIM don't send preedit_start and preedit_end, but they send
3101 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3102 // im_is_preediting() here.
3103 if (p_imst == IM_ON_THE_SPOT
3104 && xic != NULL
3105 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003106 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 && !p_imdisable
3108 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 {
3111 colnr_T tcol;
3112
3113 if (preedit_end_col == MAXCOL)
3114 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3115 else
3116 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003117 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 {
3119 if (feedback_old_attr < 0)
3120 {
3121 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003124 wlv.char_attr = im_get_feedback_attr(feedback_col);
3125 if (wlv.char_attr < 0)
3126 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 feedback_col++;
3128 }
3129 else if (feedback_old_attr >= 0)
3130 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003131 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 feedback_old_attr = -1;
3133 feedback_col = 0;
3134 }
3135 }
3136#endif
3137 // Handle the case where we are in column 0 but not on the first
3138 // character of the line and the user wants us to show us a
3139 // special character (via 'listchars' option "precedes:<char>".
3140 if (lcs_prec_todo != NUL
3141 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003142 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003143 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003144 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145#ifdef FEAT_DIFF
3146 && filler_todo <= 0
3147#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 && c != NUL)
3150 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003151 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 lcs_prec_todo = NUL;
3153 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3154 {
3155 // Double-width character being overwritten by the "precedes"
3156 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003157 wlv.c_extra = MB_FILLER_CHAR;
3158 wlv.c_final = NUL;
3159 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003161 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 }
3163 mb_c = c;
3164 if (enc_utf8 && utf_char2len(c) > 1)
3165 {
3166 mb_utf8 = TRUE;
3167 u8cc[0] = 0;
3168 c = 0xc0;
3169 }
3170 else
3171 mb_utf8 = FALSE; // don't draw as UTF-8
3172 if (!attr_pri)
3173 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 saved_attr3 = wlv.char_attr; // save current attr
3175 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176 n_attr3 = 1;
3177 }
3178 }
3179
3180 // At end of the text line or just after the last character.
3181 if ((c == NUL
3182#if defined(LINE_ATTR)
3183 || did_line_attr == 1
3184#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003185 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 {
3187#ifdef FEAT_SEARCH_EXTRA
3188 // flag to indicate whether prevcol equals startcol of search_hl or
3189 // one of the matches
3190 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3191 (long)(ptr - line) - (c == NUL));
3192#endif
3193 // Invert at least one char, used for Visual and empty line or
3194 // highlight match at end of line. If it's beyond the last
3195 // char on the screen, just overwrite that one (tricky!) Not
3196 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003197 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003198 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 && (VIsual_mode != Ctrl_V
3200 || lnum == VIsual.lnum
3201 || lnum == curwin->w_cursor.lnum)
3202 && c == NUL)
3203#ifdef FEAT_SEARCH_EXTRA
3204 // highlight 'hlsearch' match at end of line
3205 || (prevcol_hl_flag
3206# ifdef FEAT_SYN_HL
3207 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3208 && !(wp == curwin && VIsual_active))
3209# endif
3210# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003211 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212# endif
3213# if defined(LINE_ATTR)
3214 && did_line_attr <= 1
3215# endif
3216 )
3217#endif
3218 ))
3219 {
3220 int n = 0;
3221
3222#ifdef FEAT_RIGHTLEFT
3223 if (wp->w_p_rl)
3224 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003225 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 n = 1;
3227 }
3228 else
3229#endif
3230 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003231 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 n = -1;
3233 }
3234 if (n != 0)
3235 {
3236 // At the window boundary, highlight the last character
3237 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003238 wlv.off += n;
3239 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 }
3241 else
3242 {
3243 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003244 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003246 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 }
3248#ifdef FEAT_SEARCH_EXTRA
3249 if (area_attr == 0)
3250 {
3251 // Use attributes from match with highest priority among
3252 // 'search_hl' and the match list.
3253 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003254 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 }
3256#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003257 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259#ifdef FEAT_RIGHTLEFT
3260 if (wp->w_p_rl)
3261 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003262 --wlv.col;
3263 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 }
3265 else
3266#endif
3267 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 ++wlv.col;
3269 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003271 ++wlv.vcol;
3272 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 }
3274 }
3275
3276 // At end of the text line.
3277 if (c == NUL)
3278 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280
3281 // Update w_cline_height and w_cline_folded if the cursor line was
3282 // updated (saves a call to plines() later).
3283 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3284 {
3285 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003286 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287#ifdef FEAT_FOLDING
3288 curwin->w_cline_folded = FALSE;
3289#endif
3290 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3291 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 break;
3293 }
3294
3295 // Show "extends" character from 'listchars' if beyond the line end and
3296 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003297 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003298 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 && wp->w_p_list
3300 && !wp->w_p_wrap
3301#ifdef FEAT_DIFF
3302 && filler_todo <= 0
3303#endif
3304 && (
3305#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003308 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003310 || lcs_eol_one > 0
3311 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003312 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003314 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003315 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 mb_c = c;
3317 if (enc_utf8 && utf_char2len(c) > 1)
3318 {
3319 mb_utf8 = TRUE;
3320 u8cc[0] = 0;
3321 c = 0xc0;
3322 }
3323 else
3324 mb_utf8 = FALSE;
3325 }
3326
3327#ifdef FEAT_SYN_HL
3328 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003329 if (wlv.draw_color_col)
3330 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331
3332 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3333 // highlight the cursor position itself.
3334 // Also highlight the 'colorcolumn' if it is different than
3335 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003336 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3337 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003339 if (((wlv.draw_state == WL_LINE
3340 || wlv.draw_state == WL_BRI
3341 || wlv.draw_state == WL_SBR)
3342 && !lnum_in_visual_area
3343 && search_attr == 0
3344 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003345# ifdef FEAT_DIFF
3346 && filler_todo <= 0
3347# endif
3348 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 {
3350 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3351 && lnum != wp->w_cursor.lnum)
3352 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003353 vcol_save_attr = wlv.char_attr;
3354 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3355 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003357 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 vcol_save_attr = wlv.char_attr;
3360 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 }
3362 }
3363#endif
3364
3365 // Store character to be displayed.
3366 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003367 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003368 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 {
3370 // Store the character.
3371#if defined(FEAT_RIGHTLEFT)
3372 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3373 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003374 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003375 --wlv.off;
3376 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 }
3378#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003379 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 if (enc_dbcs == DBCS_JPNU)
3381 {
3382 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 ScreenLines[wlv.off] = 0x8e;
3384 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 }
3386 else if (enc_utf8)
3387 {
3388 if (mb_utf8)
3389 {
3390 int i;
3391
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003394 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 for (i = 0; i < Screen_mco; ++i)
3396 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003397 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398 if (u8cc[i] == 0)
3399 break;
3400 }
3401 }
3402 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003403 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 }
3405 if (multi_attr)
3406 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003407 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 multi_attr = 0;
3409 }
3410 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003411 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003413 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003414
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3416 {
3417 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 ++wlv.off;
3419 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 if (enc_utf8)
3421 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003422 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 else
3424 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003426 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427#ifdef FEAT_DIFF
3428 && filler_todo <= 0
3429#endif
3430 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003431 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 // When "tocol" is halfway a character, set it to the end of
3433 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003434 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003436
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003437 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003438
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439#ifdef FEAT_RIGHTLEFT
3440 if (wp->w_p_rl)
3441 {
3442 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 --wlv.off;
3444 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 }
3446#endif
3447 }
3448#ifdef FEAT_RIGHTLEFT
3449 if (wp->w_p_rl)
3450 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 --wlv.off;
3452 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 }
3454 else
3455#endif
3456 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 ++wlv.off;
3458 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 }
3460 }
3461#ifdef FEAT_CONCEAL
3462 else if (wp->w_p_cole > 0 && is_concealing)
3463 {
3464 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003465 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003466 if (wlv.n_extra > 0)
3467 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 if (wp->w_p_wrap)
3469 {
3470 // Special voodoo required if 'wrap' is on.
3471 //
3472 // Advance the column indicator to force the line
3473 // drawing to wrap early. This will make the line
3474 // take up the same screen space when parts are concealed,
3475 // so that cursor line computations aren't messed up.
3476 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 // trailing junk to be written out of the screen line
3479 // we are building, 'boguscols' keeps track of the number
3480 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003481 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484# ifdef FEAT_RIGHTLEFT
3485 if (wp->w_p_rl)
3486 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003487 wlv.col -= wlv.n_extra;
3488 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 }
3490 else
3491# endif
3492 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003493 wlv.col += wlv.n_extra;
3494 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003496 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 n_attr = 0;
3498 }
3499
3500
3501 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3502 {
3503 // Need to fill two screen columns.
3504# ifdef FEAT_RIGHTLEFT
3505 if (wp->w_p_rl)
3506 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003507 --wlv.boguscols;
3508 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 }
3510 else
3511# endif
3512 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003513 ++wlv.boguscols;
3514 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 }
3516 }
3517
3518# ifdef FEAT_RIGHTLEFT
3519 if (wp->w_p_rl)
3520 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003521 --wlv.boguscols;
3522 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 }
3524 else
3525# endif
3526 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003527 ++wlv.boguscols;
3528 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 }
3530 }
3531 else
3532 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003533 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003535 wlv.vcol += wlv.n_extra;
3536 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 n_attr = 0;
3538 }
3539 }
3540
3541 }
3542#endif // FEAT_CONCEAL
3543 else
3544 --n_skip;
3545
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 // Only advance the "wlv.vcol" when after the 'number' or
3547 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003548 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549#ifdef FEAT_DIFF
3550 && filler_todo <= 0
3551#endif
3552 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003553 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554
3555#ifdef FEAT_SYN_HL
3556 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003557 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558#endif
3559
3560 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3562 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563
3564 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003565 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003566 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003567 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003568 if (n_attr_skip > 0)
3569 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570
3571 // At end of screen line and there is more to come: Display the line
3572 // so far. If there is no more to display it is caught above.
3573 if ((
3574#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003577 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003579 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580#ifdef FEAT_DIFF
3581 || filler_todo > 0
3582#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003583#ifdef FEAT_PROP_POPUP
3584 || text_prop_follows
3585#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003586 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003587 && wlv.p_extra != at_end_str)
3588 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3589 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590 )
3591 {
3592#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 screen_line(wp, wlv.screen_row, wp->w_wincol,
3594 wlv.col - wlv.boguscols,
3595 wp->w_width, wlv.screen_line_flags);
3596 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3599 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003601 ++wlv.row;
3602 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603
3604 // When not wrapping and finished diff lines, or when displayed
3605 // '$' and highlighting until last column, break here.
3606 if ((!wp->w_p_wrap
3607#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003608 && filler_todo <= 0
3609#endif
3610#ifdef FEAT_PROP_POPUP
3611 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612#endif
3613 ) || lcs_eol_one == -1)
3614 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003615#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003616 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003617 {
3618 // do not output more of the line, only the "below" prop
3619 ptr += STRLEN(ptr);
3620# ifdef FEAT_LINEBREAK
3621 dont_use_showbreak = TRUE;
3622# endif
3623 }
3624#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003625
3626 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003627 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628#ifdef FEAT_DIFF
3629 && filler_todo <= 0
3630#endif
3631 )
3632 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3634 draw_vsep_win(wp, wlv.row);
3635 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 }
3637
3638 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003639 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003641 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 break;
3643 }
3644
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646#ifdef FEAT_DIFF
3647 && filler_todo <= 0
3648#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003649#ifdef FEAT_PROP_POPUP
3650 && !text_prop_follows
3651#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 && wp->w_width == Columns)
3653 {
3654 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003655 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656
3657 // Special trick to make copy/paste of wrapped lines work with
3658 // xterm/screen: write an extra character beyond the end of
3659 // the line. This will work with all terminal types
3660 // (regardless of the xn,am settings).
3661 // Only do this on a fast tty.
3662 // Only do this if the cursor is on the current line
3663 // (something has been written in it).
3664 // Don't do this for the GUI.
3665 // Don't do this for double-width characters.
3666 // Don't do this for a window not at the right screen border.
3667 if (p_tf
3668#ifdef FEAT_GUI
3669 && !gui.in_use
3670#endif
3671 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003672 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3673 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 || (*mb_off2cells)(
3676 LineOffset[wlv.screen_row - 1]
3677 + (int)Columns - 2,
3678 LineOffset[wlv.screen_row]
3679 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 {
3681 // First make sure we are at the end of the screen line,
3682 // then output the same character again to let the
3683 // terminal know about the wrap. If the terminal doesn't
3684 // auto-wrap, we overwrite the character.
3685 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003686 screen_char(LineOffset[wlv.screen_row - 1]
3687 + (unsigned)Columns - 1,
3688 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689
3690 // When there is a multi-byte character, just output a
3691 // space to keep it simple.
3692 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003693 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 out_char(' ');
3695 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 + (Columns - 1)]);
3698 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003699 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700 screen_start(); // don't know where cursor is now
3701 }
3702 }
3703
Bram Moolenaar1306b362022-08-06 15:59:06 +01003704 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705
Bram Moolenaareed9d462021-02-15 20:38:25 +01003706 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003708 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003710 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003712 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003713 need_showbreak = TRUE;
3714#endif
3715#ifdef FEAT_DIFF
3716 --filler_todo;
3717 // When the filler lines are actually below the last line of the
3718 // file, don't draw the line itself, break here.
3719 if (filler_todo == 0 && wp->w_botfill)
3720 break;
3721#endif
3722 }
3723
3724 } // for every character in the line
3725
3726#ifdef FEAT_SPELL
3727 // After an empty line check first word for capital.
3728 if (*skipwhite(line) == NUL)
3729 {
3730 capcol_lnum = lnum + 1;
3731 cap_col = 0;
3732 }
3733#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003734#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 vim_free(text_props);
3736 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003737 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738#endif
3739
3740 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003741 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742}