blob: 50d18ec97e80f51fe5a3dd7391ab4e55e1ff9f17 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
105
106 int screen_line_flags; // flags for screen_line()
107
108 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
109 int cul_screenline;
110
111 int char_attr; // attributes for the next character
112
113 int n_extra; // number of extra bytes
114 char_u *p_extra; // string of extra chars, plus NUL, only used
115 // when c_extra and c_final are NUL
116 int c_extra; // extra chars, all the same
117 int c_final; // final char, mandatory if set
118
119 // saved "extra" items for when draw_state becomes WL_LINE (again)
120 int saved_n_extra;
121 char_u *saved_p_extra;
122 int saved_c_extra;
123 int saved_c_final;
124 int saved_char_attr;
125
126#ifdef FEAT_DIFF
127 hlf_T diff_hlf; // type of diff highlighting
128#endif
129} winlinevars_T;
130
131// draw_state values for items that are drawn in sequence:
132#define WL_START 0 // nothing done yet, must be zero
133#ifdef FEAT_CMDWIN
134# define WL_CMDLINE (WL_START + 1) // cmdline window column
135#else
136# define WL_CMDLINE WL_START
137#endif
138#ifdef FEAT_FOLDING
139# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
140#else
141# define WL_FOLD WL_CMDLINE
142#endif
143#ifdef FEAT_SIGNS
144# define WL_SIGN (WL_FOLD + 1) // column for signs
145#else
146# define WL_SIGN WL_FOLD // column for signs
147#endif
148#define WL_NR (WL_SIGN + 1) // line number
149#ifdef FEAT_LINEBREAK
150# define WL_BRI (WL_NR + 1) // 'breakindent'
151#else
152# define WL_BRI WL_NR
153#endif
154#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
155# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
156#else
157# define WL_SBR WL_BRI
158#endif
159#define WL_LINE (WL_SBR + 1) // text in the line
160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_cursor_line_sign(win_T *wp, linenr_T lnum)
167{
168 return wp->w_p_cul
169 && lnum == wp->w_cursor.lnum
170 && (wp->w_p_culopt_flags & CULOPT_NBR);
171}
172
173/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * Get information needed to display the sign in line 'lnum' in window 'wp'.
175 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
176 * Otherwise the sign is going to be displayed in the sign column.
177 */
178 static void
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
190 int text_sign;
191# ifdef FEAT_SIGN_ICONS
192 int icon_sign;
193# endif
194
195 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
255 if (nrcol)
256 {
257 int n, width = number_width(wp) - 2;
258
259 for (n = 0; n < width; n++)
260 extra[n] = ' ';
261 extra[n] = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100280#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100281/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100282 * Return the cell size of virtual text after truncation.
283 */
284 static int
285textprop_size_after_trunc(
286 win_T *wp,
287 int flags, // TP_FLAG_ALIGN_*
288 int added,
289 char_u *text,
290 int *n_used_ptr)
291{
292 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
293 ? wp->w_width : added;
294 int len = (int)STRLEN(text);
295 int strsize = 0;
296 int n_used;
297
298 // if the remaining size is to small wrap anyway and use the next line
299 if (space < PROP_TEXT_MIN_CELLS)
300 space += wp->w_width;
301 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
302 {
303 int clen = ptr2cells(text + n_used);
304
305 if (strsize + clen > space)
306 break;
307 strsize += clen;
308 }
309 *n_used_ptr = n_used;
310 return strsize;
311}
312
313/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100314 * Take care of padding, right-align and truncation of virtual text after a
315 * line.
316 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
317 * padding, right-align and truncation. Otherwise only the size is computed.
318 * When "n_attr" is NULL returns the number of screen cells used.
319 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100320 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100321 int
322text_prop_position(
323 win_T *wp,
324 textprop_T *tp,
325 int vcol, // current screen column
326 int *n_extra, // nr of bytes for virtual text
327 char_u **p_extra, // virtual text
328 int *n_attr, // attribute cells, NULL if not used
329 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100331 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100332 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100333 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
334 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
335 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
336 ? tp->tp_len - 1 : 0;
337 int col_with_padding = vcol + (below ? 0 : padding);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100338 int col_off = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100339 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100340 int before = room; // spaces before the text
341 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100342 int n_used = *n_extra;
343 char_u *l = NULL;
344 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100345 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
346 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100348 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100349 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100350 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100351 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100352 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100353 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100354 }
355 else
356 {
357 // Right-align: fill with before
358 if (right)
359 before -= cells;
360 if (before < 0
361 || !(right || below)
362 || (below
363 ? (col_with_padding == 0 || !wp->w_p_wrap)
364 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100365 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100366 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
367 {
368 // right-align on next line instead of wrapping if possible
369 col_off = win_col_off(wp) + win_col_off2(wp);
370 before = wp->w_width - col_off - strsize + room;
371 if (before < 0)
372 before = 0;
373 else
374 n_used = *n_extra;
375 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100376 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100377 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100378 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100379 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100380
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100381 // With 'nowrap' add one to show the "extends" character if needed (it
382 // doesn't show if the text just fits).
383 if (!wp->w_p_wrap
384 && n_used < *n_extra
385 && wp->w_lcs_chars.ext != NUL
386 && wp->w_p_list)
387 ++n_used;
388
389 // add 1 for NUL, 2 for when '…' is used
390 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100391 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100392 if (n_attr == NULL || l != NULL)
393 {
394 int off = 0;
395
396 if (n_attr != NULL)
397 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100398 vim_memset(l, ' ', before);
399 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100400 if (padding > 0)
401 {
402 vim_memset(l + off, ' ', padding);
403 off += padding;
404 }
405 vim_strncpy(l + off, *p_extra, n_used);
406 off += n_used;
407 }
408 else
409 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100410 off = before + after + padding + n_used;
411 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100412 }
413 if (n_attr != NULL)
414 {
415 if (n_used < *n_extra && wp->w_p_wrap)
416 {
417 char_u *lp = l + off - 1;
418
419 if (has_mbyte)
420 {
421 // change last character to '…'
422 lp -= (*mb_head_off)(l, lp);
423 STRCPY(lp, "…");
424 n_used = lp - l + 3 - padding;
425 }
426 else
427 // change last character to '>'
428 *lp = '>';
429 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100430 else if (after > 0)
431 {
432 vim_memset(l + off, ' ', after);
433 l[off + after] = NUL;
434 }
435
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100436 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100437 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100438 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100439 if (above)
440 *n_attr -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100441 *n_attr_skip = before + padding + col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100442 }
443 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100444 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100445
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100446 if (n_attr == NULL)
447 return cells;
448 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200449}
450#endif
451
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100452/*
453 * Called when finished with the line: draw the screen line and handle any
454 * highlighting until the right of the window.
455 */
456 static void
457draw_screen_line(win_T *wp, winlinevars_T *wlv)
458{
459#ifdef FEAT_SYN_HL
460 long v;
461
462 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
463 if (wp->w_p_wrap)
464 v = wp->w_skipcol;
465 else
466 v = wp->w_leftcol;
467
468 // check if line ends before left margin
469 if (wlv->vcol < v + wlv->col - win_col_off(wp))
470 wlv->vcol = v + wlv->col - win_col_off(wp);
471# ifdef FEAT_CONCEAL
472 // Get rid of the boguscols now, we want to draw until the right
473 // edge for 'cursorcolumn'.
474 wlv->col -= wlv->boguscols;
475 wlv->boguscols = 0;
476# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
477# else
478# define VCOL_HLC (wlv->vcol)
479# endif
480
481 if (wlv->draw_color_col)
482 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
483
484 if (((wp->w_p_cuc
485 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
486 && (int)wp->w_virtcol <
487 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
488 && wlv->lnum != wp->w_cursor.lnum)
489 || wlv->draw_color_col
490 || wlv->win_attr != 0)
491# ifdef FEAT_RIGHTLEFT
492 && !wp->w_p_rl
493# endif
494 )
495 {
496 int rightmost_vcol = 0;
497 int i;
498
499 if (wp->w_p_cuc)
500 rightmost_vcol = wp->w_virtcol;
501 if (wlv->draw_color_col)
502 // determine rightmost colorcolumn to possibly draw
503 for (i = 0; wlv->color_cols[i] >= 0; ++i)
504 if (rightmost_vcol < wlv->color_cols[i])
505 rightmost_vcol = wlv->color_cols[i];
506
507 while (wlv->col < wp->w_width)
508 {
509 ScreenLines[wlv->off] = ' ';
510 if (enc_utf8)
511 ScreenLinesUC[wlv->off] = 0;
512 ScreenCols[wlv->off] = MAXCOL;
513 ++wlv->col;
514 if (wlv->draw_color_col)
515 wlv->draw_color_col = advance_color_col(
516 VCOL_HLC, &wlv->color_cols);
517
518 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
519 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
520 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
521 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
522 else
523 ScreenAttrs[wlv->off++] = wlv->win_attr;
524
525 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
526 break;
527
528 ++wlv->vcol;
529 }
530 }
531#endif
532
533 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
534 wp->w_width, wlv->screen_line_flags);
535 ++wlv->row;
536 ++wlv->screen_row;
537}
538#undef VCOL_HLC
539
540/*
541 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100542 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100543 */
544 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100545win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100546{
547 wlv->col = 0;
548 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
549
550#ifdef FEAT_RIGHTLEFT
551 if (wp->w_p_rl)
552 {
553 // Rightleft window: process the text in the normal direction, but put
554 // it in current_ScreenLine[] from right to left. Start at the
555 // rightmost column of the window.
556 wlv->col = wp->w_width - 1;
557 wlv->off += wlv->col;
558 wlv->screen_line_flags |= SLF_RIGHTLEFT;
559 }
560#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100561 if (save_extra)
562 {
563 // reset the drawing state for the start of a wrapped line
564 wlv->draw_state = WL_START;
565 wlv->saved_n_extra = wlv->n_extra;
566 wlv->saved_p_extra = wlv->p_extra;
567 wlv->saved_c_extra = wlv->c_extra;
568 wlv->saved_c_final = wlv->c_final;
569#ifdef FEAT_SYN_HL
570 if (!(wlv->cul_screenline
571# ifdef FEAT_DIFF
572 && wlv->diff_hlf == (hlf_T)0
573# endif
574 ))
575 wlv->saved_char_attr = wlv->char_attr;
576 else
577#endif
578 wlv->saved_char_attr = 0;
579 wlv->n_extra = 0;
580 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100581}
582
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200583/*
584 * Display line "lnum" of window 'wp' on the screen.
585 * Start at row "startrow", stop when "endrow" is reached.
586 * wp->w_virtcol needs to be valid.
587 *
588 * Return the number of last row the line occupies.
589 */
590 int
591win_line(
592 win_T *wp,
593 linenr_T lnum,
594 int startrow,
595 int endrow,
596 int nochange UNUSED, // not updating for changed text
597 int number_only) // only update the number column
598{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100599 winlinevars_T wlv; // variables passed between functions
600
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200601 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200602#ifdef FEAT_LINEBREAK
603 long vcol_sbr = -1; // virtual column after showbreak
604#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100605 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200606 char_u *line; // current line
607 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200608
609 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200610 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100611#ifdef FEAT_PROP_POPUP
612 char_u *p_extra_free2 = NULL; // another p_extra to be freed
613#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200614 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000615#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000616 int in_linebreak = FALSE; // n_extra set for showing linebreak
617#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200618 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100619 // displaying eol at end-of-line
620 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000621 int lcs_prec_todo = wp->w_lcs_chars.prec;
622 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200623
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100624 int n_attr = 0; // chars with special attr
625 int n_attr_skip = 0; // chars to skip before using extra_attr
626 int saved_attr2 = 0; // char_attr saved for n_attr
627 int n_attr3 = 0; // chars with overruling special attr
628 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200629
630 int n_skip = 0; // nr of chars to skip for 'nowrap'
631
632 int fromcol = -10; // start of inverting
633 int tocol = MAXCOL; // end of inverting
634 int fromcol_prev = -2; // start of inverting after cursor
635 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200636 int lnum_in_visual_area = FALSE;
637 pos_T pos;
638 long v;
639
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200640 int attr_pri = FALSE; // char_attr has priority
641 int area_highlighting = FALSE; // Visual or incsearch highlighting
642 // in this line
643 int vi_attr = 0; // attributes for Visual and incsearch
644 // highlighting
645 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200646 int area_attr = 0; // attributes desired by highlighting
647 int search_attr = 0; // attributes desired by 'hlsearch'
648#ifdef FEAT_SYN_HL
649 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
650 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200651 int prev_syntax_col = -1; // column of prev_syntax_attr
652 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200653 int has_syntax = FALSE; // this buffer has syntax highl.
654 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100656#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200657 int text_prop_count;
658 int text_prop_next = 0; // next text property to use
659 textprop_T *text_props = NULL;
660 int *text_prop_idxs = NULL;
661 int text_props_active = 0;
662 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100663 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200664 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100665 int text_prop_attr_comb = 0; // text_prop_attr combined with
666 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100667 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100668 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100669 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100670 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100671 int saved_search_attr = 0; // search_attr to be used when n_extra
672 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100673 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200674#endif
675#ifdef FEAT_SPELL
676 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000677 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200678# define SPWORDLEN 150
679 char_u nextline[SPWORDLEN * 2];// text with start of the next line
680 int nextlinecol = 0; // column where nextline[] starts
681 int nextline_idx = 0; // index in nextline[] where next line
682 // starts
683 int spell_attr = 0; // attributes desired by spelling
684 int word_end = 0; // last byte with same spell_attr
685 static linenr_T checked_lnum = 0; // line number for "checked_col"
686 static int checked_col = 0; // column in "checked_lnum" up to which
687 // there are no spell errors
688 static int cap_col = -1; // column to check for Cap word
689 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
690 int cur_checked_col = 0; // checked column for current line
691#endif
692 int extra_check = 0; // has extra highlighting
693 int multi_attr = 0; // attributes desired by multibyte
694 int mb_l = 1; // multi-byte byte length
695 int mb_c = 0; // decoded multi-byte character
696 int mb_utf8 = FALSE; // screen char is UTF-8 char
697 int u8cc[MAX_MCO]; // composing UTF-8 chars
698#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
699 int filler_lines = 0; // nr of filler lines to be drawn
700 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000701#else
702# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200703#endif
704#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705 int change_start = MAXCOL; // first col of changed area
706 int change_end = -1; // last col of changed area
707#endif
708 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100709 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200710 int in_multispace = FALSE; // in multiple consecutive spaces
711 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200712#ifdef FEAT_LINEBREAK
713 int need_showbreak = FALSE; // overlong line, skipping first x
714 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100715 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200716#endif
717#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
718 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
719# define LINE_ATTR
720 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100721 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200722#endif
723#ifdef FEAT_SIGNS
724 int sign_present = FALSE;
725 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000726 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200727#endif
728#ifdef FEAT_ARABIC
729 int prev_c = 0; // previous Arabic character
730 int prev_c1 = 0; // first composing char for prev_c
731#endif
732#if defined(LINE_ATTR)
733 int did_line_attr = 0;
734#endif
735#ifdef FEAT_TERMINAL
736 int get_term_attr = FALSE;
737#endif
738#ifdef FEAT_SYN_HL
739 int cul_attr = 0; // set when 'cursorline' active
740
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200741 // margin columns for the screen line, needed for when 'cursorlineopt'
742 // contains "screenline"
743 int left_curline_col = 0;
744 int right_curline_col = 0;
745#endif
746
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200747#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
748 int feedback_col = 0;
749 int feedback_old_attr = -1;
750#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200751
752#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
753 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000754 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200755#endif
756#ifdef FEAT_CONCEAL
757 int syntax_flags = 0;
758 int syntax_seqnr = 0;
759 int prev_syntax_id = 0;
760 int conceal_attr = HL_ATTR(HLF_CONCEAL);
761 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200762 int did_wcol = FALSE;
763 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100764# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200765# define FIX_FOR_BOGUSCOLS \
766 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100767 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100768 wlv.vcol -= wlv.vcol_off; \
769 wlv.vcol_off = 0; \
770 wlv.col -= wlv.boguscols; \
771 old_boguscols = wlv.boguscols; \
772 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 }
774#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100775# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200776#endif
777
778 if (startrow > endrow) // past the end already!
779 return startrow;
780
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100781 CLEAR_FIELD(wlv);
782
783 wlv.lnum = lnum;
784 wlv.startrow = startrow;
785 wlv.row = startrow;
786 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200787
788 if (!number_only)
789 {
790 // To speed up the loop below, set extra_check when there is linebreak,
791 // trailing white space and/or syntax processing to be done.
792#ifdef FEAT_LINEBREAK
793 extra_check = wp->w_p_lbr;
794#endif
795#ifdef FEAT_SYN_HL
796 if (syntax_present(wp) && !wp->w_s->b_syn_error
797# ifdef SYN_TIME_LIMIT
798 && !wp->w_s->b_syn_slow
799# endif
800 )
801 {
802 // Prepare for syntax highlighting in this line. When there is an
803 // error, stop syntax highlighting.
804 save_did_emsg = did_emsg;
805 did_emsg = FALSE;
806 syntax_start(wp, lnum);
807 if (did_emsg)
808 wp->w_s->b_syn_error = TRUE;
809 else
810 {
811 did_emsg = save_did_emsg;
812#ifdef SYN_TIME_LIMIT
813 if (!wp->w_s->b_syn_slow)
814#endif
815 {
816 has_syntax = TRUE;
817 extra_check = TRUE;
818 }
819 }
820 }
821
822 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100823 wlv.color_cols = wp->w_p_cc_cols;
824 if (wlv.color_cols != NULL)
825 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200826#endif
827
828#ifdef FEAT_TERMINAL
829 if (term_show_buffer(wp->w_buffer))
830 {
831 extra_check = TRUE;
832 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100833 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200834 }
835#endif
836
837#ifdef FEAT_SPELL
838 if (wp->w_p_spell
839 && *wp->w_s->b_p_spl != NUL
840 && wp->w_s->b_langp.ga_len > 0
841 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
842 {
843 // Prepare for spell checking.
844 has_spell = TRUE;
845 extra_check = TRUE;
846
847 // Get the start of the next line, so that words that wrap to the
848 // next line are found too: "et<line-break>al.".
849 // Trick: skip a few chars for C/shell/Vim comments
850 nextline[SPWORDLEN] = NUL;
851 if (lnum < wp->w_buffer->b_ml.ml_line_count)
852 {
853 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
854 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
855 }
856
857 // When a word wrapped from the previous line the start of the
858 // current line is valid.
859 if (lnum == checked_lnum)
860 cur_checked_col = checked_col;
861 checked_lnum = 0;
862
863 // When there was a sentence end in the previous line may require a
864 // word starting with capital in this line. In line 1 always check
865 // the first word.
866 if (lnum != capcol_lnum)
867 cap_col = -1;
868 if (lnum == 1)
869 cap_col = 0;
870 capcol_lnum = 0;
871 }
872#endif
873
874 // handle Visual active in this window
875 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
876 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100877 pos_T *top, *bot;
878
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200879 if (LTOREQ_POS(curwin->w_cursor, VIsual))
880 {
881 // Visual is after curwin->w_cursor
882 top = &curwin->w_cursor;
883 bot = &VIsual;
884 }
885 else
886 {
887 // Visual is before curwin->w_cursor
888 top = &VIsual;
889 bot = &curwin->w_cursor;
890 }
891 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
892 if (VIsual_mode == Ctrl_V)
893 {
894 // block mode
895 if (lnum_in_visual_area)
896 {
897 fromcol = wp->w_old_cursor_fcol;
898 tocol = wp->w_old_cursor_lcol;
899 }
900 }
901 else
902 {
903 // non-block mode
904 if (lnum > top->lnum && lnum <= bot->lnum)
905 fromcol = 0;
906 else if (lnum == top->lnum)
907 {
908 if (VIsual_mode == 'V') // linewise
909 fromcol = 0;
910 else
911 {
912 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
913 if (gchar_pos(top) == NUL)
914 tocol = fromcol + 1;
915 }
916 }
917 if (VIsual_mode != 'V' && lnum == bot->lnum)
918 {
919 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
920 {
921 fromcol = -10;
922 tocol = MAXCOL;
923 }
924 else if (bot->col == MAXCOL)
925 tocol = MAXCOL;
926 else
927 {
928 pos = *bot;
929 if (*p_sel == 'e')
930 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
931 else
932 {
933 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
934 ++tocol;
935 }
936 }
937 }
938 }
939
940 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200941 if (!highlight_match && lnum == curwin->w_cursor.lnum
942 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200943#ifdef FEAT_GUI
944 && !gui.in_use
945#endif
946 )
947 noinvcur = TRUE;
948
949 // if inverting in this line set area_highlighting
950 if (fromcol >= 0)
951 {
952 area_highlighting = TRUE;
953 vi_attr = HL_ATTR(HLF_V);
954#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
955 if ((clip_star.available && !clip_star.owned
956 && clip_isautosel_star())
957 || (clip_plus.available && !clip_plus.owned
958 && clip_isautosel_plus()))
959 vi_attr = HL_ATTR(HLF_VNC);
960#endif
961 }
962 }
963
964 // handle 'incsearch' and ":s///c" highlighting
965 else if (highlight_match
966 && wp == curwin
967 && lnum >= curwin->w_cursor.lnum
968 && lnum <= curwin->w_cursor.lnum + search_match_lines)
969 {
970 if (lnum == curwin->w_cursor.lnum)
971 getvcol(curwin, &(curwin->w_cursor),
972 (colnr_T *)&fromcol, NULL, NULL);
973 else
974 fromcol = 0;
975 if (lnum == curwin->w_cursor.lnum + search_match_lines)
976 {
977 pos.lnum = lnum;
978 pos.col = search_match_endcol;
979 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
980 }
981 else
982 tocol = MAXCOL;
983 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100984 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985 tocol = fromcol + 1;
986 area_highlighting = TRUE;
987 vi_attr = HL_ATTR(HLF_I);
988 }
989 }
990
991#ifdef FEAT_DIFF
992 filler_lines = diff_check(wp, lnum);
993 if (filler_lines < 0)
994 {
995 if (filler_lines == -1)
996 {
997 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100998 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001000 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001002 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 }
1004 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001005 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 filler_lines = 0;
1007 area_highlighting = TRUE;
1008 }
1009 if (lnum == wp->w_topline)
1010 filler_lines = wp->w_topfill;
1011 filler_todo = filler_lines;
1012#endif
1013
1014#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01001015 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +00001016 if (sign_present)
1017 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001018#endif
1019
1020#ifdef LINE_ATTR
1021# ifdef FEAT_SIGNS
1022 // If this line has a sign with line highlighting set line_attr.
1023 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001024 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025# endif
1026# if defined(FEAT_QUICKFIX)
1027 // Highlight the current line in the quickfix window.
1028 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1029 line_attr = HL_ATTR(HLF_QFL);
1030# endif
1031 if (line_attr != 0)
1032 area_highlighting = TRUE;
1033#endif
1034
1035 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1036 ptr = line;
1037
1038#ifdef FEAT_SPELL
1039 if (has_spell && !number_only)
1040 {
1041 // For checking first word with a capital skip white space.
1042 if (cap_col == 0)
1043 cap_col = getwhitecols(line);
1044
1045 // To be able to spell-check over line boundaries copy the end of the
1046 // current line into nextline[]. Above the start of the next line was
1047 // copied to nextline[SPWORDLEN].
1048 if (nextline[SPWORDLEN] == NUL)
1049 {
1050 // No next line or it is empty.
1051 nextlinecol = MAXCOL;
1052 nextline_idx = 0;
1053 }
1054 else
1055 {
1056 v = (long)STRLEN(line);
1057 if (v < SPWORDLEN)
1058 {
1059 // Short line, use it completely and append the start of the
1060 // next line.
1061 nextlinecol = 0;
1062 mch_memmove(nextline, line, (size_t)v);
1063 STRMOVE(nextline + v, nextline + SPWORDLEN);
1064 nextline_idx = v + 1;
1065 }
1066 else
1067 {
1068 // Long line, use only the last SPWORDLEN bytes.
1069 nextlinecol = v - SPWORDLEN;
1070 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1071 nextline_idx = SPWORDLEN + 1;
1072 }
1073 }
1074 }
1075#endif
1076
1077 if (wp->w_p_list)
1078 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001079 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001080 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001081 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001082 || wp->w_lcs_chars.trail
1083 || wp->w_lcs_chars.lead
1084 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001086
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001088 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089 {
1090 trailcol = (colnr_T)STRLEN(ptr);
1091 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1092 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001093 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001095 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001096 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001097 {
1098 leadcol = 0;
1099 while (VIM_ISWHITE(ptr[leadcol]))
1100 ++leadcol;
1101 if (ptr[leadcol] == NUL)
1102 // in a line full of spaces all of them are treated as trailing
1103 leadcol = (colnr_T)0;
1104 else
1105 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001106 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001107 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001108 }
1109
1110 wcr_attr = get_wcr_attr(wp);
1111 if (wcr_attr != 0)
1112 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001113 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 area_highlighting = TRUE;
1115 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001116
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001117#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001119 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120#endif
1121
1122 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1123 // first character to be displayed.
1124 if (wp->w_p_wrap)
1125 v = wp->w_skipcol;
1126 else
1127 v = wp->w_leftcol;
1128 if (v > 0 && !number_only)
1129 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001130 char_u *prev_ptr = ptr;
1131 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001132 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001133
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001134 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001135 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001136 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001137 charsize = win_lbr_chartabsize(&cts, NULL);
1138 cts.cts_vcol += charsize;
1139 prev_ptr = cts.cts_ptr;
1140 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001142 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001143 ptr = cts.cts_ptr;
1144 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145
1146 // When:
1147 // - 'cuc' is set, or
1148 // - 'colorcolumn' is set, or
1149 // - 'virtualedit' is set, or
1150 // - the visual mode is active,
1151 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001152 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001154 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155#endif
1156 virtual_active() ||
1157 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001158 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159
1160 // Handle a character that's not completely on the screen: Put ptr at
1161 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001162 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001164 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165 ptr = prev_ptr;
1166 // If the character fits on the screen, don't need to skip it.
1167 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001168 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1169 && wlv.col == 0)
1170 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171 }
1172
1173 // Adjust for when the inverted text is before the screen,
1174 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001175 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001177 else if (fromcol >= 0 && fromcol < wlv.vcol)
1178 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179
1180#ifdef FEAT_LINEBREAK
1181 // When w_skipcol is non-zero, first line needs 'showbreak'
1182 if (wp->w_p_wrap)
1183 need_showbreak = TRUE;
1184#endif
1185#ifdef FEAT_SPELL
1186 // When spell checking a word we need to figure out the start of the
1187 // word and if it's badly spelled or not.
1188 if (has_spell)
1189 {
1190 int len;
1191 colnr_T linecol = (colnr_T)(ptr - line);
1192 hlf_T spell_hlf = HLF_COUNT;
1193
1194 pos = wp->w_cursor;
1195 wp->w_cursor.lnum = lnum;
1196 wp->w_cursor.col = linecol;
1197 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1198
1199 // spell_move_to() may call ml_get() and make "line" invalid
1200 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1201 ptr = line + linecol;
1202
1203 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1204 {
1205 // no bad word found at line start, don't check until end of a
1206 // word
1207 spell_hlf = HLF_COUNT;
1208 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1209 }
1210 else
1211 {
1212 // bad word found, use attributes until end of word
1213 word_end = wp->w_cursor.col + len + 1;
1214
1215 // Turn index into actual attributes.
1216 if (spell_hlf != HLF_COUNT)
1217 spell_attr = highlight_attr[spell_hlf];
1218 }
1219 wp->w_cursor = pos;
1220
1221# ifdef FEAT_SYN_HL
1222 // Need to restart syntax highlighting for this line.
1223 if (has_syntax)
1224 syntax_start(wp, lnum);
1225# endif
1226 }
1227#endif
1228 }
1229
1230 // Correct highlighting for cursor that can't be disabled.
1231 // Avoids having to check this for each character.
1232 if (fromcol >= 0)
1233 {
1234 if (noinvcur)
1235 {
1236 if ((colnr_T)fromcol == wp->w_virtcol)
1237 {
1238 // highlighting starts at cursor, let it start just after the
1239 // cursor
1240 fromcol_prev = fromcol;
1241 fromcol = -1;
1242 }
1243 else if ((colnr_T)fromcol < wp->w_virtcol)
1244 // restart highlighting after the cursor
1245 fromcol_prev = wp->w_virtcol;
1246 }
1247 if (fromcol >= tocol)
1248 fromcol = -1;
1249 }
1250
1251#ifdef FEAT_SEARCH_EXTRA
1252 if (!number_only)
1253 {
1254 v = (long)(ptr - line);
1255 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1256 &line, &screen_search_hl,
1257 &search_attr);
1258 ptr = line + v; // "line" may have been updated
1259 }
1260#endif
1261
1262#ifdef FEAT_SYN_HL
1263 // Cursor line highlighting for 'cursorline' in the current window.
1264 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1265 {
1266 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001267 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 if (!(wp == curwin && VIsual_active)
1269 && wp->w_p_culopt_flags != CULOPT_NBR)
1270 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001271 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1273
1274 // Only set line_attr here when "screenline" is not present in
1275 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001276 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 {
1278 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001279# ifdef FEAT_SIGNS
1280 // Combine the 'cursorline' and sign highlighting, depending on
1281 // the sign priority.
1282 if (sign_present && sattr.sat_linehl > 0)
1283 {
1284 if (sattr.sat_priority >= 100)
1285 line_attr = hl_combine_attr(cul_attr, line_attr);
1286 else
1287 line_attr = hl_combine_attr(line_attr, cul_attr);
1288 }
1289 else
1290# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001291# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001292 // let the line attribute overrule 'cursorline', otherwise
1293 // it disappears when both have background set;
1294 // 'cursorline' can use underline or bold to make it show
1295 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001296# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001297 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001298# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 }
1300 else
1301 {
1302 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1304 }
1305 area_highlighting = TRUE;
1306 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 }
1308#endif
1309
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001310#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 {
1312 char_u *prop_start;
1313
1314 text_prop_count = get_text_props(wp->w_buffer, lnum,
1315 &prop_start, FALSE);
1316 if (text_prop_count > 0)
1317 {
1318 // Make a copy of the properties, so that they are properly
1319 // aligned.
1320 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1321 if (text_props != NULL)
1322 mch_memmove(text_props, prop_start,
1323 text_prop_count * sizeof(textprop_T));
1324
1325 // Allocate an array for the indexes.
1326 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001327 if (text_prop_idxs == NULL)
1328 VIM_CLEAR(text_props);
1329
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 area_highlighting = TRUE;
1331 extra_check = TRUE;
1332 }
1333 }
1334#endif
1335
Bram Moolenaar1306b362022-08-06 15:59:06 +01001336 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337
1338 // Repeat for the whole displayed line.
1339 for (;;)
1340 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001341 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001343 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344#endif
1345#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001346 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001348
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001350 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001352#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001353 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001354 {
1355 cul_attr = 0;
1356 line_attr = line_attr_save;
1357 }
1358#endif
1359
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001361 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001363 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 if (cmdwin_type != 0 && wp == curwin)
1365 {
1366 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001367 wlv.n_extra = 1;
1368 wlv.c_extra = cmdwin_type;
1369 wlv.c_final = NUL;
1370 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 }
1372 }
1373#endif
1374
1375#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001376 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 {
1378 int fdc = compute_foldcolumn(wp, 0);
1379
Bram Moolenaar1306b362022-08-06 15:59:06 +01001380 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381 if (fdc > 0)
1382 {
1383 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1384 // already be in use.
1385 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001386 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 if (p_extra_free != NULL)
1388 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001389 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001390 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001391 p_extra_free[wlv.n_extra] = NUL;
1392 wlv.p_extra = p_extra_free;
1393 wlv.c_extra = NUL;
1394 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001395 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001396 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001397 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1398 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001399 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001400 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 }
1402 }
1403 }
1404#endif
1405
1406#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001407 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001409 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 // Show the sign column when there are any signs in this
1411 // buffer or when using Netbeans.
1412 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001413 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1414 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 }
1416#endif
1417
Bram Moolenaar1306b362022-08-06 15:59:06 +01001418 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001420 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 // Display the absolute or relative line number. After the
1422 // first fill with blanks when the 'n' flag isn't in 'cpo'
1423 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001424 && (wlv.row == startrow + filler_lines
1425 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 {
1427#ifdef FEAT_SIGNS
1428 // If 'signcolumn' is set to 'number' and a sign is present
1429 // in 'lnum', then display the sign instead of the line
1430 // number.
1431 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1432 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001433 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1434 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435 else
1436#endif
1437 {
1438 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001439 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440 {
1441 long num;
1442 char *fmt = "%*ld ";
1443
1444 if (wp->w_p_nu && !wp->w_p_rnu)
1445 // 'number' + 'norelativenumber'
1446 num = (long)lnum;
1447 else
1448 {
1449 // 'relativenumber', don't use negative numbers
1450 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1451 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1452 {
1453 // 'number' + 'relativenumber'
1454 num = lnum;
1455 fmt = "%-*ld ";
1456 }
1457 }
1458
1459 sprintf((char *)extra, fmt,
1460 number_width(wp), num);
1461 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001462 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1463 ++wlv.p_extra)
1464 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465#ifdef FEAT_RIGHTLEFT
1466 if (wp->w_p_rl) // reverse line numbers
1467 {
1468 char_u *p1, *p2;
1469 int t;
1470
1471 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001472 p2 = skipwhite(extra);
1473 p2 = skiptowhite(p2) - 1;
1474 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 {
1476 t = *p1;
1477 *p1 = *p2;
1478 *p2 = t;
1479 }
1480 }
1481#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001482 wlv.p_extra = extra;
1483 wlv.c_extra = NUL;
1484 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 }
1486 else
1487 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001488 wlv.c_extra = ' ';
1489 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001491 wlv.n_extra = number_width(wp) + 1;
1492 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493#ifdef FEAT_SYN_HL
1494 // When 'cursorline' is set highlight the line number of
1495 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001496 // When 'cursorlineopt' does not have "line" only
1497 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 // TODO: Can we use CursorLine instead of CursorLineNr
1499 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001500 if (wp->w_p_cul
1501 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001503 && (wlv.row == startrow + filler_lines
1504 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001505 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001506 wlv.char_attr = hl_combine_attr(wcr_attr,
1507 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001509 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1510 && HL_ATTR(HLF_LNA) != 0)
1511 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001512 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001513 HL_ATTR(HLF_LNA));
1514 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1515 && HL_ATTR(HLF_LNB) != 0)
1516 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001517 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001518 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001519 }
James McCoya80aad72021-12-22 19:45:28 +00001520#ifdef FEAT_SIGNS
1521 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001522 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001523#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 }
1525 }
1526
1527#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001528 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1529 && wlv.n_extra == 0
1530 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001532 wlv.draw_state = WL_BRI;
1533 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1534 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001536 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537
1538 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001539 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001541 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001543 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544# ifdef FEAT_DIFF
1545 && filler_lines == 0
1546# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001547# ifdef FEAT_PROP_POPUP
1548 && !dont_use_showbreak
1549# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550 )
1551 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001552 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001554 if (wlv.diff_hlf != (hlf_T)0)
1555 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001557 wlv.p_extra = NULL;
1558 wlv.c_extra = ' ';
1559 wlv.c_final = NUL;
1560 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001562 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001563 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001564 wlv.n_extra -= win_col_off2(wp);
1565 if (wlv.n_extra < 0)
1566 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001567 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001568 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001569 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 // Correct end of highlighted area for 'breakindent',
1571 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001572 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001573 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 }
1575 }
1576#endif
1577
1578#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001579 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001581 char_u *sbr;
1582
Bram Moolenaar1306b362022-08-06 15:59:06 +01001583 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584# ifdef FEAT_DIFF
1585 if (filler_todo > 0)
1586 {
1587 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001588 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001590 wlv.c_extra = '-';
1591 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 }
1593 else
1594 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001595 wlv.c_extra = wp->w_fill_chars.diff;
1596 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 }
1598# ifdef FEAT_RIGHTLEFT
1599 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001600 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 else
1602# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001603 wlv.n_extra = wp->w_width - wlv.col;
1604 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 }
1606# endif
1607# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001608 sbr = get_showbreak_value(wp);
1609 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 {
1611 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001612 wlv.p_extra = sbr;
1613 wlv.c_extra = NUL;
1614 wlv.c_final = NUL;
1615 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001616 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1617 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001618 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 // Correct end of highlighted area for 'showbreak',
1620 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001621 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001622 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001624 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1625 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626# ifdef FEAT_SYN_HL
1627 // combine 'showbreak' with 'cursorline'
1628 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001629 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1630 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631# endif
1632 }
1633# endif
1634 }
1635#endif
1636
Bram Moolenaar1306b362022-08-06 15:59:06 +01001637 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001639 wlv.draw_state = WL_LINE;
1640 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 {
1642 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001643 wlv.n_extra = wlv.saved_n_extra;
1644 wlv.c_extra = wlv.saved_c_extra;
1645 wlv.c_final = wlv.saved_c_final;
1646 wlv.p_extra = wlv.saved_p_extra;
1647 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 }
1649 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001650 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651 }
1652 }
1653#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001654 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001655 && wlv.vcol >= left_curline_col
1656 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001658 cul_attr = HL_ATTR(HLF_CUL);
1659 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660 }
1661#endif
1662
1663 // When still displaying '$' of change command, stop at cursor.
1664 // When only displaying the (relative) line number and that's done,
1665 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001666 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001667 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001668 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669#ifdef FEAT_DIFF
1670 && filler_todo <= 0
1671#endif
1672 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001674 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1675 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 // Pretend we have finished updating the window. Except when
1677 // 'cursorcolumn' is set.
1678#ifdef FEAT_SYN_HL
1679 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001680 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 else
1682#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001683 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 break;
1685 }
1686
Bram Moolenaar1306b362022-08-06 15:59:06 +01001687 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 {
1689 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001690 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001691 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 && (*mb_ptr2cells)(ptr) > 1)
1693 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001694 && vcol_prev < wlv.vcol // not at margin
1695 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 area_attr = vi_attr; // start highlighting
1697 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001698 && (wlv.vcol == tocol
1699 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 area_attr = 0; // stop highlighting
1701
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001702#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 if (text_props != NULL)
1704 {
1705 int pi;
1706 int bcol = (int)(ptr - line);
1707
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001709# ifdef FEAT_LINEBREAK
1710 && !in_linebreak
1711# endif
1712 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713 --bcol; // still working on the previous char, e.g. Tab
1714
1715 // Check if any active property ends.
1716 for (pi = 0; pi < text_props_active; ++pi)
1717 {
1718 int tpi = text_prop_idxs[pi];
1719
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001720 if (text_props[tpi].tp_col != MAXCOL
1721 && bcol >= text_props[tpi].tp_col - 1
1722 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 {
1724 if (pi + 1 < text_props_active)
1725 mch_memmove(text_prop_idxs + pi,
1726 text_prop_idxs + pi + 1,
1727 sizeof(int)
1728 * (text_props_active - (pi + 1)));
1729 --text_props_active;
1730 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001731# ifdef FEAT_LINEBREAK
1732 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001733 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001734 syntax_attr = 0;
1735# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 }
1737 }
1738
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001739# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001741 // not on the next char yet, don't start another prop
1742 --bcol;
1743# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001745 // With 'nowrap' and not in the first screen line only "below"
1746 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001748 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001749 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001750 && (wp->w_p_wrap
1751 || wlv.row == startrow
1752 || (text_props[text_prop_next].tp_flags
1753 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001754 || (bcol == 0 &&
1755 (text_props[text_prop_next].tp_flags
1756 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001757 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001758 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001759 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001760 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1761 {
1762 // first display the '$' after the line
1763 text_prop_follows = TRUE;
1764 break;
1765 }
1766 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001767 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001768 + text_props[text_prop_next].tp_len)
1769 text_prop_idxs[text_props_active++] = text_prop_next;
1770 ++text_prop_next;
1771 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001773 if (wlv.n_extra == 0 || !extra_for_textprop)
1774 {
1775 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001776 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001777 text_prop_flags = 0;
1778 text_prop_type = NULL;
1779 text_prop_id = 0;
1780 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001781 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001783 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001784 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001785 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001786
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 // Sort the properties on priority and/or starting last.
1788 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001789 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001790 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001791 sort_text_props(wp->w_buffer, text_props,
1792 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793
1794 for (pi = 0; pi < text_props_active; ++pi)
1795 {
1796 int tpi = text_prop_idxs[pi];
1797 proptype_T *pt = text_prop_type_by_id(
1798 wp->w_buffer, text_props[tpi].tp_type);
1799
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001800 if (pt != NULL && (pt->pt_hl_id > 0
1801 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001802 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001804 if (pt->pt_hl_id > 0)
1805 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 text_prop_type = pt;
1807 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001808 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001809 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001810 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001811 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001812 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 }
1814 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001815 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001816 && -text_prop_id
1817 <= wp->w_buffer->b_textprop_text.ga_len)
1818 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001819 textprop_T *tp = &text_props[used_tpi];
1820 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001821 ->b_textprop_text.ga_data)[
1822 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001823 int above = (tp->tp_flags
1824 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001825
1826 // reset the ID in the copy to avoid it being used
1827 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001828 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001829
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001830 if (p != NULL)
1831 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001832 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001833 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001834 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001835 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001836 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1837 int padding = tp->tp_col == MAXCOL
1838 && tp->tp_len > 1
1839 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001840
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001841 // Insert virtual text before the current
1842 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 wlv.p_extra = p;
1844 wlv.c_extra = NUL;
1845 wlv.c_final = NUL;
1846 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001847 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001848 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001849 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001850 // restore search_attr and area_attr when n_extra
1851 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001852 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001853 saved_area_attr = area_attr;
1854 search_attr = 0;
1855 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001856 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001857 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001858 if (*ptr == NUL)
1859 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001860 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001861#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001862 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001863 {
1864 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001865 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001866 need_showbreak = FALSE;
1867 dont_use_showbreak = TRUE;
1868 }
1869#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001870 if ((right || above || below || !wrap
1871 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001872 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001873 char_u *prev_p_extra = wlv.p_extra;
1874 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001875
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001876 // Take care of padding, right-align and
1877 // truncation.
1878 // Shared with win_lbr_chartabsize(), must do
1879 // exactly the same.
1880 start_line = text_prop_position(wp, tp,
1881 wlv.col,
1882 &wlv.n_extra, &wlv.p_extra,
1883 &n_attr, &n_attr_skip);
1884 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001885 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001886 // wlv.p_extra was allocated
1887 vim_free(p_extra_free2);
1888 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001889 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001890
1891 // When 'wrap' is off then for "below" we need
1892 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001893 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001894 {
1895 draw_screen_line(wp, &wlv);
1896
1897 // When line got too long for screen break
1898 // here.
1899 if (wlv.row == endrow)
1900 {
1901 ++wlv.row;
1902 break;
1903 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001904 win_line_start(wp, &wlv, TRUE);
1905 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001906 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001907 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001908 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001909
1910 // If another text prop follows the condition below at
1911 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001912 // If this is an "above" text prop and 'nowrap' the we
1913 // must wrap anyway.
1914 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001915 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001916 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001918 else if (text_prop_next < text_prop_count
1919 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001920 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1921 || (!wp->w_p_wrap
1922 && wlv.col == wp->w_width - 1
1923 && (text_props[text_prop_next].tp_flags
1924 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001925 // When at last-but-one character and a text property
1926 // follows after it, we may need to flush the line after
1927 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001928 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001929 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 }
1931#endif
1932
Bram Moolenaare38fc862022-08-11 17:24:50 +01001933#ifdef FEAT_SEARCH_EXTRA
1934 if (wlv.n_extra == 0)
1935 {
1936 // Check for start/end of 'hlsearch' and other matches.
1937 // After end, check for start/end of next match.
1938 // When another match, have to check for start again.
1939 v = (long)(ptr - line);
1940 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1941 &screen_search_hl, &has_match_conc,
1942 &match_conc, did_line_attr, lcs_eol_one,
1943 &on_last_col);
1944 ptr = line + v; // "line" may have been changed
1945 prev_ptr = ptr;
1946
1947 // Do not allow a conceal over EOL otherwise EOL will be missed
1948 // and bad things happen.
1949 if (*ptr == NUL)
1950 has_match_conc = 0;
1951 }
1952#endif
1953
1954#ifdef FEAT_DIFF
1955 if (wlv.diff_hlf != (hlf_T)0)
1956 {
1957 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1958 && wlv.n_extra == 0)
1959 wlv.diff_hlf = HLF_TXD; // changed text
1960 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1961 && wlv.n_extra == 0)
1962 wlv.diff_hlf = HLF_CHD; // changed line
1963 line_attr = HL_ATTR(wlv.diff_hlf);
1964 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1965 && wp->w_p_culopt_flags != CULOPT_NBR
1966 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1967 && wlv.vcol <= right_curline_col)))
1968 line_attr = hl_combine_attr(
1969 line_attr, HL_ATTR(HLF_CUL));
1970 }
1971#endif
1972
Bram Moolenaara74fda62019-10-19 17:38:03 +02001973#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001974 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001975 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001976 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001977# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001978 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001979 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001980# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001981 // Get syntax attribute.
1982 if (has_syntax)
1983 {
1984 // Get the syntax attribute for the character. If there
1985 // is an error, disable syntax highlighting.
1986 save_did_emsg = did_emsg;
1987 did_emsg = FALSE;
1988
1989 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001990 if (v == prev_syntax_col)
1991 // at same column again
1992 syntax_attr = prev_syntax_attr;
1993 else
1994 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001995# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001996 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001997# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001998 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001999# ifdef FEAT_SPELL
2000 has_spell ? &can_spell :
2001# endif
2002 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002003 prev_syntax_col = v;
2004 prev_syntax_attr = syntax_attr;
2005 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002006
Bram Moolenaar34390282019-10-16 14:38:26 +02002007 if (did_emsg)
2008 {
2009 wp->w_s->b_syn_error = TRUE;
2010 has_syntax = FALSE;
2011 syntax_attr = 0;
2012 }
2013 else
2014 did_emsg = save_did_emsg;
2015# ifdef SYN_TIME_LIMIT
2016 if (wp->w_s->b_syn_slow)
2017 has_syntax = FALSE;
2018# endif
2019
2020 // Need to get the line again, a multi-line regexp may
2021 // have made it invalid.
2022 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2023 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002024 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002025# ifdef FEAT_CONCEAL
2026 // no concealing past the end of the line, it interferes
2027 // with line highlighting
2028 if (*ptr == NUL)
2029 syntax_flags = 0;
2030 else
2031 syntax_flags = get_syntax_info(&syntax_seqnr);
2032# endif
2033 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002034 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002035# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002036 // Combine text property highlight into syntax highlight.
2037 if (text_prop_type != NULL)
2038 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002039 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002040 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2041 else
2042 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002043 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002044 }
2045# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002046#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002047
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048 // Decide which of the highlight attributes to use.
2049 attr_pri = TRUE;
2050#ifdef LINE_ATTR
2051 if (area_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, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002054 if (!highlight_match)
2055 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002056 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002057# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002058 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002059# endif
2060 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002062 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002063 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002064# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002065 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002066# endif
2067 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002068 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002069 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2070 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 {
2072 // Use line_attr when not in the Visual or 'incsearch' area
2073 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002074# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002075 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002076# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002077 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002078# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 attr_pri = FALSE;
2080 }
2081#else
2082 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002083 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002085 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002086#endif
2087 else
2088 {
2089 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002091 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002092#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002093 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002094#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002095 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002096#ifdef FEAT_PROP_POPUP
2097 // override with text property highlight when "override" is TRUE
2098 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002099 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002100#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002102
2103 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002104 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002105 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002106 if (wlv.char_attr == 0)
2107 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002108 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002109 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002110 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111
2112 // Get the next character to put on the screen.
2113
2114 // The "p_extra" points to the extra stuff that is inserted to
2115 // represent special characters (non-printable stuff) and other
2116 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002117 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002118 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2119 // "p_extra[n_extra]".
2120 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002121 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002122 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002123 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002124 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002125 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2126 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002127 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2128 if (enc_utf8 && utf_char2len(c) > 1)
2129 {
2130 mb_utf8 = TRUE;
2131 u8cc[0] = 0;
2132 c = 0xc0;
2133 }
2134 else
2135 mb_utf8 = FALSE;
2136 }
2137 else
2138 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002139 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002140 if (has_mbyte)
2141 {
2142 mb_c = c;
2143 if (enc_utf8)
2144 {
2145 // If the UTF-8 character is more than one byte:
2146 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002147 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002148 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002149 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002150 mb_l = 1;
2151 else if (mb_l > 1)
2152 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002154 mb_utf8 = TRUE;
2155 c = 0xc0;
2156 }
2157 }
2158 else
2159 {
2160 // if this is a DBCS character, put it in "mb_c"
2161 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 mb_l = 1;
2164 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002165 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002166 }
2167 if (mb_l == 0) // at the NUL at end-of-line
2168 mb_l = 1;
2169
2170 // If a double-width char doesn't fit display a '>' in the
2171 // last column.
2172 if ((
2173# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002174 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002176 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 && (*mb_char2cells)(mb_c) == 2)
2178 {
2179 c = '>';
2180 mb_c = c;
2181 mb_l = 1;
2182 mb_utf8 = FALSE;
2183 multi_attr = HL_ATTR(HLF_AT);
2184#ifdef FEAT_SYN_HL
2185 if (cul_attr)
2186 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2187#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002188 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002189
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002190 // put the pointer back to output the double-width
2191 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 ++wlv.n_extra;
2193 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 }
2195 else
2196 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197 wlv.n_extra -= mb_l - 1;
2198 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002199 }
2200 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002201 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002203 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002204#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002205 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002206 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002207 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002208 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002209 if (search_attr == 0)
2210 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002211 if (area_attr == 0 && *ptr != NUL)
2212 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002213 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002214#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215 }
2216 else
2217 {
2218#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002219 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002221 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002222
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 // Get a character from the line itself.
2224 c = *ptr;
2225#ifdef FEAT_LINEBREAK
2226 c0 = *ptr;
2227#endif
2228 if (has_mbyte)
2229 {
2230 mb_c = c;
2231 if (enc_utf8)
2232 {
2233 // If the UTF-8 character is more than one byte: Decode it
2234 // into "mb_c".
2235 mb_l = utfc_ptr2len(ptr);
2236 mb_utf8 = FALSE;
2237 if (mb_l > 1)
2238 {
2239 mb_c = utfc_ptr2char(ptr, u8cc);
2240 // Overlong encoded ASCII or ASCII with composing char
2241 // is displayed normally, except a NUL.
2242 if (mb_c < 0x80)
2243 {
2244 c = mb_c;
2245#ifdef FEAT_LINEBREAK
2246 c0 = mb_c;
2247#endif
2248 }
2249 mb_utf8 = TRUE;
2250
2251 // At start of the line we can have a composing char.
2252 // Draw it as a space with a composing char.
2253 if (utf_iscomposing(mb_c))
2254 {
2255 int i;
2256
2257 for (i = Screen_mco - 1; i > 0; --i)
2258 u8cc[i] = u8cc[i - 1];
2259 u8cc[0] = mb_c;
2260 mb_c = ' ';
2261 }
2262 }
2263
2264 if ((mb_l == 1 && c >= 0x80)
2265 || (mb_l >= 1 && mb_c == 0)
2266 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2267 {
2268 // Illegal UTF-8 byte: display as <xx>.
2269 // Non-BMP character : display as ? or fullwidth ?.
2270 transchar_hex(extra, mb_c);
2271# ifdef FEAT_RIGHTLEFT
2272 if (wp->w_p_rl) // reverse
2273 rl_mirror(extra);
2274# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002275 wlv.p_extra = extra;
2276 c = *wlv.p_extra;
2277 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002279 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2280 wlv.c_extra = NUL;
2281 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 if (area_attr == 0 && search_attr == 0)
2283 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002284 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002285 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002286 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002287 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 }
2289 }
2290 else if (mb_l == 0) // at the NUL at end-of-line
2291 mb_l = 1;
2292#ifdef FEAT_ARABIC
2293 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2294 {
2295 // Do Arabic shaping.
2296 int pc, pc1, nc;
2297 int pcc[MAX_MCO];
2298
2299 // The idea of what is the previous and next
2300 // character depends on 'rightleft'.
2301 if (wp->w_p_rl)
2302 {
2303 pc = prev_c;
2304 pc1 = prev_c1;
2305 nc = utf_ptr2char(ptr + mb_l);
2306 prev_c1 = u8cc[0];
2307 }
2308 else
2309 {
2310 pc = utfc_ptr2char(ptr + mb_l, pcc);
2311 nc = prev_c;
2312 pc1 = pcc[0];
2313 }
2314 prev_c = mb_c;
2315
2316 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2317 }
2318 else
2319 prev_c = mb_c;
2320#endif
2321 }
2322 else // enc_dbcs
2323 {
2324 mb_l = MB_BYTE2LEN(c);
2325 if (mb_l == 0) // at the NUL at end-of-line
2326 mb_l = 1;
2327 else if (mb_l > 1)
2328 {
2329 // We assume a second byte below 32 is illegal.
2330 // Hopefully this is OK for all double-byte encodings!
2331 if (ptr[1] >= 32)
2332 mb_c = (c << 8) + ptr[1];
2333 else
2334 {
2335 if (ptr[1] == NUL)
2336 {
2337 // head byte at end of line
2338 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002339 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002340 }
2341 else
2342 {
2343 // illegal tail byte
2344 mb_l = 2;
2345 STRCPY(extra, "XX");
2346 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002347 wlv.p_extra = extra;
2348 wlv.n_extra = (int)STRLEN(extra) - 1;
2349 wlv.c_extra = NUL;
2350 wlv.c_final = NUL;
2351 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 if (area_attr == 0 && search_attr == 0)
2353 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002354 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002355 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002356 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002357 // save current attr
2358 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 }
2360 mb_c = c;
2361 }
2362 }
2363 }
2364 // If a double-width char doesn't fit display a '>' in the
2365 // last column; the character is displayed at the start of the
2366 // next line.
2367 if ((
2368# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002369 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002371 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 && (*mb_char2cells)(mb_c) == 2)
2373 {
2374 c = '>';
2375 mb_c = c;
2376 mb_utf8 = FALSE;
2377 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002378 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379 // Put pointer back so that the character will be
2380 // displayed at the start of the next line.
2381 --ptr;
2382#ifdef FEAT_CONCEAL
2383 did_decrement_ptr = TRUE;
2384#endif
2385 }
2386 else if (*ptr != NUL)
2387 ptr += mb_l - 1;
2388
2389 // If a double-width char doesn't fit at the left side display
2390 // a '<' in the first column. Don't do this for unprintable
2391 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002392 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002394 wlv.n_extra = 1;
2395 wlv.c_extra = MB_FILLER_CHAR;
2396 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397 c = ' ';
2398 if (area_attr == 0 && search_attr == 0)
2399 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002400 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002401 extra_attr = hl_combine_attr(
2402 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002403 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002404 }
2405 mb_c = c;
2406 mb_utf8 = FALSE;
2407 mb_l = 1;
2408 }
2409
2410 }
2411 ++ptr;
2412
2413 if (extra_check)
2414 {
2415#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 // Check spelling (unless at the end of the line).
2417 // Only do this when there is no syntax highlighting, the
2418 // @Spell cluster is not used or the current syntax item
2419 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002420 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421 if (has_spell && v >= word_end && v > cur_checked_col)
2422 {
2423 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002424 // do not calculate cap_col at the end of the line or when
2425 // only white space is following
2426 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427# ifdef FEAT_SYN_HL
2428 !has_syntax ||
2429# endif
2430 can_spell))
2431 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002432 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 int len;
2434 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002435
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002436 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438
2439 // Use nextline[] if possible, it has the start of the
2440 // next line concatenated.
2441 if ((prev_ptr - line) - nextlinecol >= 0)
2442 p = nextline + (prev_ptr - line) - nextlinecol;
2443 else
2444 p = prev_ptr;
2445 cap_col -= (int)(prev_ptr - line);
2446 len = spell_check(wp, p, &spell_hlf, &cap_col,
2447 nochange);
2448 word_end = v + len;
2449
2450 // In Insert mode only highlight a word that
2451 // doesn't touch the cursor.
2452 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002453 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454 && wp->w_cursor.lnum == lnum
2455 && wp->w_cursor.col >=
2456 (colnr_T)(prev_ptr - line)
2457 && wp->w_cursor.col < (colnr_T)word_end)
2458 {
2459 spell_hlf = HLF_COUNT;
2460 spell_redraw_lnum = lnum;
2461 }
2462
2463 if (spell_hlf == HLF_COUNT && p != prev_ptr
2464 && (p - nextline) + len > nextline_idx)
2465 {
2466 // Remember that the good word continues at the
2467 // start of the next line.
2468 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002469 checked_col = (int)((p - nextline)
2470 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 }
2472
2473 // Turn index into actual attributes.
2474 if (spell_hlf != HLF_COUNT)
2475 spell_attr = highlight_attr[spell_hlf];
2476
2477 if (cap_col > 0)
2478 {
2479 if (p != prev_ptr
2480 && (p - nextline) + cap_col >= nextline_idx)
2481 {
2482 // Remember that the word in the next line
2483 // must start with a capital.
2484 capcol_lnum = lnum + 1;
2485 cap_col = (int)((p - nextline) + cap_col
2486 - nextline_idx);
2487 }
2488 else
2489 // Compute the actual column.
2490 cap_col += (int)(prev_ptr - line);
2491 }
2492 }
2493 }
2494 if (spell_attr != 0)
2495 {
2496 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002497 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2498 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002500 wlv.char_attr = hl_combine_attr(spell_attr,
2501 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 }
2503#endif
2504#ifdef FEAT_LINEBREAK
2505 // Found last space before word: check for line break.
2506 if (wp->w_p_lbr && c0 == c
2507 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2508 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002509 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2510 : 0;
2511 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002512 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002514 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002515# ifdef FEAT_PROP_POPUP
2516 // do not want virtual text counted here
2517 cts.cts_has_prop_with_text = FALSE;
2518# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002519 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002520 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002521
2522 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002523 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002524 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002525 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002526 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2527 if (wlv.n_extra < 0)
2528 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002529 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002530 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002531 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002532 // line break, but for TABs the highlighting should
2533 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002534 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002535
Bram Moolenaar1306b362022-08-06 15:59:06 +01002536 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002538 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002539 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 wp->w_buffer->b_p_vts_array) - 1;
2541# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002543 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544# endif
2545
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2547 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002548# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002550 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002551# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 if (VIM_ISWHITE(c))
2553 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002554# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002555 if (c == TAB)
2556 // See "Tab alignment" below.
2557 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002558# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 if (!wp->w_p_list)
2560 c = ' ';
2561 }
2562 }
2563#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002564 in_multispace = c == ' '
2565 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2566 if (!in_multispace)
2567 multispace_pos = 0;
2568
Bram Moolenaareed9d462021-02-15 20:38:25 +01002569 // 'list': Change char 160 to 'nbsp' and space to 'space'
2570 // setting in 'listchars'. But not when the character is
2571 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 if (wp->w_p_list
2573 && ((((c == 160 && mb_l == 1)
2574 || (mb_utf8
2575 && ((mb_c == 160 && mb_l == 2)
2576 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002577 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002578 || (c == ' '
2579 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002580 && (wp->w_lcs_chars.space
2581 || (in_multispace
2582 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002583 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 && ptr - line <= trailcol)))
2585 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002586 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2587 {
2588 c = wp->w_lcs_chars.multispace[multispace_pos++];
2589 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2590 multispace_pos = 0;
2591 }
2592 else
2593 c = (c == ' ') ? wp->w_lcs_chars.space
2594 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 if (area_attr == 0 && search_attr == 0)
2596 {
2597 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002598 extra_attr = hl_combine_attr(wlv.win_attr,
2599 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002600 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 }
2602 mb_c = c;
2603 if (enc_utf8 && utf_char2len(c) > 1)
2604 {
2605 mb_utf8 = TRUE;
2606 u8cc[0] = 0;
2607 c = 0xc0;
2608 }
2609 else
2610 mb_utf8 = FALSE;
2611 }
2612
zeertzjq2e7cba32022-06-10 15:30:32 +01002613 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2614 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002616 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2617 && wp->w_lcs_chars.leadmultispace != NULL)
2618 {
2619 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002620 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2621 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002622 multispace_pos = 0;
2623 }
2624
2625 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2626 c = wp->w_lcs_chars.trail;
2627
2628 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2629 c = wp->w_lcs_chars.lead;
2630
zeertzjq2e7cba32022-06-10 15:30:32 +01002631 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002632 c = wp->w_lcs_chars.space;
2633
2634
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 if (!attr_pri)
2636 {
2637 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002638 extra_attr = hl_combine_attr(wlv.win_attr,
2639 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002640 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 }
2642 mb_c = c;
2643 if (enc_utf8 && utf_char2len(c) > 1)
2644 {
2645 mb_utf8 = TRUE;
2646 u8cc[0] = 0;
2647 c = 0xc0;
2648 }
2649 else
2650 mb_utf8 = FALSE;
2651 }
2652 }
2653
2654 // Handling of non-printable characters.
2655 if (!vim_isprintc(c))
2656 {
2657 // when getting a character from the file, we may have to
2658 // turn it into something else on the way to putting it
2659 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002660 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002661 {
2662 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002663 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002665 char_u *sbr = get_showbreak_value(wp);
2666
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 // only adjust the tab_len, when at the first column
2668 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002669 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2670 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671#endif
2672 // tab amount depends on current column
2673#ifdef FEAT_VARTABS
2674 tab_len = tabstop_padding(vcol_adjusted,
2675 wp->w_buffer->b_p_ts,
2676 wp->w_buffer->b_p_vts_array) - 1;
2677#else
2678 tab_len = (int)wp->w_buffer->b_p_ts
2679 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2680#endif
2681
2682#ifdef FEAT_LINEBREAK
2683 if (!wp->w_p_lbr || !wp->w_p_list)
2684#endif
2685 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687#ifdef FEAT_LINEBREAK
2688 else
2689 {
2690 char_u *p;
2691 int len;
2692 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002693 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002695# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002696 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002698 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002699
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002701 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 && old_boguscols > 0
2703 && wlv.n_extra > tab_len)
2704 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002705# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002706 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002708 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002709 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002710 if (wp->w_lcs_chars.tab3)
2711 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002712 if (wlv.n_extra > 0)
2713 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002714 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002716 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002717 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002718 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002720 vim_memset(p, ' ', len);
2721 p[len] = NUL;
2722 vim_free(p_extra_free);
2723 p_extra_free = p;
2724 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002725 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002726 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002728 if (*p == NUL)
2729 {
2730 tab_len = i;
2731 break;
2732 }
2733
2734 // if tab3 is given, use it for the last char
2735 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2736 lcs = wp->w_lcs_chars.tab3;
2737 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002738 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002740 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002741 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002742# ifdef FEAT_CONCEAL
2743 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2744 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002745 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002747# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002749 }
2750#endif
2751#ifdef FEAT_CONCEAL
2752 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002753 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754
2755 // Tab alignment should be identical regardless of
2756 // 'conceallevel' value. So tab compensates of all
2757 // previous concealed characters, and thus resets
2758 // vcol_off and boguscols accumulated so far in the
2759 // line. Note that the tab can be longer than
2760 // 'tabstop' when there are concealed characters.
2761 FIX_FOR_BOGUSCOLS;
2762
2763 // Make sure, the highlighting for the tab char will be
2764 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002765 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002766 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002767 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768 tab_len += vc_saved;
2769 }
2770#endif
2771 mb_utf8 = FALSE; // don't draw as UTF-8
2772 if (wp->w_p_list)
2773 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002774 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002775 ? wp->w_lcs_chars.tab3
2776 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777#ifdef FEAT_LINEBREAK
2778 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002779 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780 else
2781#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002782 wlv.c_extra = wp->w_lcs_chars.tab2;
2783 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002785 extra_attr = hl_combine_attr(wlv.win_attr,
2786 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 mb_c = c;
2789 if (enc_utf8 && utf_char2len(c) > 1)
2790 {
2791 mb_utf8 = TRUE;
2792 u8cc[0] = 0;
2793 c = 0xc0;
2794 }
2795 }
2796 else
2797 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 wlv.c_final = NUL;
2799 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 c = ' ';
2801 }
2802 }
2803 else if (c == NUL
2804 && (wp->w_p_list
2805 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002806 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 && VIsual_mode != Ctrl_V
2808 && (
2809# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002810 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002812 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 && !(noinvcur
2814 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002815 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 && lcs_eol_one > 0)
2817 {
2818 // Display a '$' after the line or highlight an extra
2819 // character if the line break is included.
2820#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2821 // For a diff line the highlighting continues after the
2822 // "$".
2823 if (
2824# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002825 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826# ifdef LINE_ATTR
2827 &&
2828# endif
2829# endif
2830# ifdef LINE_ATTR
2831 line_attr == 0
2832# endif
2833 )
2834#endif
2835 {
2836 // In virtualedit, visual selections may extend
2837 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002838 if (!(area_highlighting && virtual_active()
2839 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002840 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002841 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002843 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2844 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 else
2846 c = ' ';
2847 lcs_eol_one = -1;
2848 --ptr; // put it back at the NUL
2849 if (!attr_pri)
2850 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002851 extra_attr = hl_combine_attr(wlv.win_attr,
2852 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 n_attr = 1;
2854 }
2855 mb_c = c;
2856 if (enc_utf8 && utf_char2len(c) > 1)
2857 {
2858 mb_utf8 = TRUE;
2859 u8cc[0] = 0;
2860 c = 0xc0;
2861 }
2862 else
2863 mb_utf8 = FALSE; // don't draw as UTF-8
2864 }
2865 else if (c != NUL)
2866 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2868 if (wlv.n_extra == 0)
2869 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870#ifdef FEAT_RIGHTLEFT
2871 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002872 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002874 wlv.c_extra = NUL;
2875 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876#ifdef FEAT_LINEBREAK
2877 if (wp->w_p_lbr)
2878 {
2879 char_u *p;
2880
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 c = *wlv.p_extra;
2882 p = alloc(wlv.n_extra + 1);
2883 vim_memset(p, ' ', wlv.n_extra);
2884 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2885 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002887 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 }
2889 else
2890#endif
2891 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.n_extra = byte2cells(c) - 1;
2893 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 }
2895 if (!attr_pri)
2896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 extra_attr = hl_combine_attr(wlv.win_attr,
2899 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002900 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 }
2902 mb_utf8 = FALSE; // don't draw as UTF-8
2903 }
2904 else if (VIsual_active
2905 && (VIsual_mode == Ctrl_V
2906 || VIsual_mode == 'v')
2907 && virtual_active()
2908 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002909 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 && (
2911#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002912 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002914 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 {
2916 c = ' ';
2917 --ptr; // put it back at the NUL
2918 }
2919#if defined(LINE_ATTR)
2920 else if ((
2921# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002922 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923# endif
2924# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002925 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926# endif
2927 line_attr != 0
2928 ) && (
2929# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002930 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002932 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002934 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935# endif
2936 < wp->w_width)))
2937 {
2938 // Highlight until the right side of the window
2939 c = ' ';
2940 --ptr; // put it back at the NUL
2941
2942 // Remember we do the char for line highlighting.
2943 ++did_line_attr;
2944
2945 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002946 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002948 || (wp->w_p_list &&
2949 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002950 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002952 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002954 wlv.diff_hlf = HLF_CHD;
2955 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2959 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002961 || (wlv.vcol >= left_curline_col
2962 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 wlv.char_attr = hl_combine_attr(
2964 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 }
2966 }
2967# endif
2968# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002969 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002972 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2973 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 if (!wlv.cul_screenline
2976 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002977 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002978 wlv.char_attr = hl_combine_attr(
2979 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 }
2981 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002982 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2983 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 }
2985# endif
2986 }
2987#endif
2988 }
2989
2990#ifdef FEAT_CONCEAL
2991 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002992 && (wp != curwin || lnum != wp->w_cursor.lnum
2993 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2995 && !(lnum_in_visual_area
2996 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2997 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002998 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002999 if (((prev_syntax_id != syntax_seqnr
3000 && (syntax_flags & HL_CONCEAL) != 0)
3001 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003002 && (syn_get_sub_char() != NUL
3003 || (has_match_conc && match_conc)
3004 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005 && wp->w_p_cole != 3)
3006 {
3007 // First time at this concealed item: display one
3008 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003009 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 c = match_conc;
3011 else if (syn_get_sub_char() != NUL)
3012 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003013 else if (wp->w_lcs_chars.conceal != NUL)
3014 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 else
3016 c = ' ';
3017
3018 prev_syntax_id = syntax_seqnr;
3019
Bram Moolenaar1306b362022-08-06 15:59:06 +01003020 if (wlv.n_extra > 0)
3021 wlv.vcol_off += wlv.n_extra;
3022 wlv.vcol += wlv.n_extra;
3023 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 {
3025# ifdef FEAT_RIGHTLEFT
3026 if (wp->w_p_rl)
3027 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003028 wlv.col -= wlv.n_extra;
3029 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003030 }
3031 else
3032# endif
3033 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003034 wlv.boguscols += wlv.n_extra;
3035 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 }
3037 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 n_attr = 0;
3040 }
3041 else if (n_skip == 0)
3042 {
3043 is_concealing = TRUE;
3044 n_skip = 1;
3045 }
3046 mb_c = c;
3047 if (enc_utf8 && utf_char2len(c) > 1)
3048 {
3049 mb_utf8 = TRUE;
3050 u8cc[0] = 0;
3051 c = 0xc0;
3052 }
3053 else
3054 mb_utf8 = FALSE; // don't draw as UTF-8
3055 }
3056 else
3057 {
3058 prev_syntax_id = 0;
3059 is_concealing = FALSE;
3060 }
3061
3062 if (n_skip > 0 && did_decrement_ptr)
3063 // not showing the '>', put pointer back to avoid getting stuck
3064 ++ptr;
3065
3066#endif // FEAT_CONCEAL
3067 }
3068
3069#ifdef FEAT_CONCEAL
3070 // In the cursor line and we may be concealing characters: correct
3071 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 && wp == curwin && lnum == wp->w_cursor.lnum
3074 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003075 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003077# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003078 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003079 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003081# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003082 wp->w_wcol = wlv.col - wlv.boguscols;
3083 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 did_wcol = TRUE;
3085 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003086# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003087 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003088# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 }
3090#endif
3091
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003092 // Use "extra_attr", but don't override visual selection highlighting,
3093 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003094 // Don't use "extra_attr" until n_attr_skip is zero.
3095 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003096 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003097 && (!attr_pri
3098#ifdef FEAT_PROP_POPUP
3099 || (text_prop_flags & PT_FLAG_OVERRIDE)
3100#endif
3101 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102 {
3103#ifdef LINE_ATTR
3104 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003105 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106 else
3107#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003108 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109 }
3110
3111#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3112 // XIM don't send preedit_start and preedit_end, but they send
3113 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3114 // im_is_preediting() here.
3115 if (p_imst == IM_ON_THE_SPOT
3116 && xic != NULL
3117 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003118 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 && !p_imdisable
3120 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003121 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122 {
3123 colnr_T tcol;
3124
3125 if (preedit_end_col == MAXCOL)
3126 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3127 else
3128 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003129 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 {
3131 if (feedback_old_attr < 0)
3132 {
3133 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003134 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003136 wlv.char_attr = im_get_feedback_attr(feedback_col);
3137 if (wlv.char_attr < 0)
3138 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 feedback_col++;
3140 }
3141 else if (feedback_old_attr >= 0)
3142 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003143 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 feedback_old_attr = -1;
3145 feedback_col = 0;
3146 }
3147 }
3148#endif
3149 // Handle the case where we are in column 0 but not on the first
3150 // character of the line and the user wants us to show us a
3151 // special character (via 'listchars' option "precedes:<char>".
3152 if (lcs_prec_todo != NUL
3153 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003154 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003155 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003156 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157#ifdef FEAT_DIFF
3158 && filler_todo <= 0
3159#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003160 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 && c != NUL)
3162 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003163 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 lcs_prec_todo = NUL;
3165 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3166 {
3167 // Double-width character being overwritten by the "precedes"
3168 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003169 wlv.c_extra = MB_FILLER_CHAR;
3170 wlv.c_final = NUL;
3171 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003173 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 }
3175 mb_c = c;
3176 if (enc_utf8 && utf_char2len(c) > 1)
3177 {
3178 mb_utf8 = TRUE;
3179 u8cc[0] = 0;
3180 c = 0xc0;
3181 }
3182 else
3183 mb_utf8 = FALSE; // don't draw as UTF-8
3184 if (!attr_pri)
3185 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003186 saved_attr3 = wlv.char_attr; // save current attr
3187 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 n_attr3 = 1;
3189 }
3190 }
3191
3192 // At end of the text line or just after the last character.
3193 if ((c == NUL
3194#if defined(LINE_ATTR)
3195 || did_line_attr == 1
3196#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003197 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 {
3199#ifdef FEAT_SEARCH_EXTRA
3200 // flag to indicate whether prevcol equals startcol of search_hl or
3201 // one of the matches
3202 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3203 (long)(ptr - line) - (c == NUL));
3204#endif
3205 // Invert at least one char, used for Visual and empty line or
3206 // highlight match at end of line. If it's beyond the last
3207 // char on the screen, just overwrite that one (tricky!) Not
3208 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003209 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003210 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 && (VIsual_mode != Ctrl_V
3212 || lnum == VIsual.lnum
3213 || lnum == curwin->w_cursor.lnum)
3214 && c == NUL)
3215#ifdef FEAT_SEARCH_EXTRA
3216 // highlight 'hlsearch' match at end of line
3217 || (prevcol_hl_flag
3218# ifdef FEAT_SYN_HL
3219 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3220 && !(wp == curwin && VIsual_active))
3221# endif
3222# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224# endif
3225# if defined(LINE_ATTR)
3226 && did_line_attr <= 1
3227# endif
3228 )
3229#endif
3230 ))
3231 {
3232 int n = 0;
3233
3234#ifdef FEAT_RIGHTLEFT
3235 if (wp->w_p_rl)
3236 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003237 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 n = 1;
3239 }
3240 else
3241#endif
3242 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003243 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244 n = -1;
3245 }
3246 if (n != 0)
3247 {
3248 // At the window boundary, highlight the last character
3249 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003250 wlv.off += n;
3251 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 }
3253 else
3254 {
3255 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003256 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 }
3260#ifdef FEAT_SEARCH_EXTRA
3261 if (area_attr == 0)
3262 {
3263 // Use attributes from match with highest priority among
3264 // 'search_hl' and the match list.
3265 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 }
3268#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003269 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271#ifdef FEAT_RIGHTLEFT
3272 if (wp->w_p_rl)
3273 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003274 --wlv.col;
3275 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 }
3277 else
3278#endif
3279 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003280 ++wlv.col;
3281 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003283 ++wlv.vcol;
3284 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 }
3286 }
3287
3288 // At end of the text line.
3289 if (c == NUL)
3290 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292
3293 // Update w_cline_height and w_cline_folded if the cursor line was
3294 // updated (saves a call to plines() later).
3295 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3296 {
3297 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003298 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299#ifdef FEAT_FOLDING
3300 curwin->w_cline_folded = FALSE;
3301#endif
3302 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3303 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 break;
3305 }
3306
3307 // Show "extends" character from 'listchars' if beyond the line end and
3308 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003309 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 && wp->w_p_list
3312 && !wp->w_p_wrap
3313#ifdef FEAT_DIFF
3314 && filler_todo <= 0
3315#endif
3316 && (
3317#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003318 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003320 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003322 || lcs_eol_one > 0
3323 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003324 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003326 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003327 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 mb_c = c;
3329 if (enc_utf8 && utf_char2len(c) > 1)
3330 {
3331 mb_utf8 = TRUE;
3332 u8cc[0] = 0;
3333 c = 0xc0;
3334 }
3335 else
3336 mb_utf8 = FALSE;
3337 }
3338
3339#ifdef FEAT_SYN_HL
3340 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003341 if (wlv.draw_color_col)
3342 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343
3344 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3345 // highlight the cursor position itself.
3346 // Also highlight the 'colorcolumn' if it is different than
3347 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003348 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3349 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003351 if (((wlv.draw_state == WL_LINE
3352 || wlv.draw_state == WL_BRI
3353 || wlv.draw_state == WL_SBR)
3354 && !lnum_in_visual_area
3355 && search_attr == 0
3356 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003357# ifdef FEAT_DIFF
3358 && filler_todo <= 0
3359# endif
3360 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 {
3362 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3363 && lnum != wp->w_cursor.lnum)
3364 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003365 vcol_save_attr = wlv.char_attr;
3366 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3367 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003369 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003371 vcol_save_attr = wlv.char_attr;
3372 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 }
3374 }
3375#endif
3376
3377 // Store character to be displayed.
3378 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003379 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003380 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381 {
3382 // Store the character.
3383#if defined(FEAT_RIGHTLEFT)
3384 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3385 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003386 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003387 --wlv.off;
3388 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 }
3390#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 if (enc_dbcs == DBCS_JPNU)
3393 {
3394 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003395 ScreenLines[wlv.off] = 0x8e;
3396 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 }
3398 else if (enc_utf8)
3399 {
3400 if (mb_utf8)
3401 {
3402 int i;
3403
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003404 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 for (i = 0; i < Screen_mco; ++i)
3408 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 if (u8cc[i] == 0)
3411 break;
3412 }
3413 }
3414 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003415 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 }
3417 if (multi_attr)
3418 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003419 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 multi_attr = 0;
3421 }
3422 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003426
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3428 {
3429 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003430 ++wlv.off;
3431 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 if (enc_utf8)
3433 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003434 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435 else
3436 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003437 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439#ifdef FEAT_DIFF
3440 && filler_todo <= 0
3441#endif
3442 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 // When "tocol" is halfway a character, set it to the end of
3445 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003448
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003450
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451#ifdef FEAT_RIGHTLEFT
3452 if (wp->w_p_rl)
3453 {
3454 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 --wlv.off;
3456 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
3458#endif
3459 }
3460#ifdef FEAT_RIGHTLEFT
3461 if (wp->w_p_rl)
3462 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 --wlv.off;
3464 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 }
3466 else
3467#endif
3468 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 ++wlv.off;
3470 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 }
3472 }
3473#ifdef FEAT_CONCEAL
3474 else if (wp->w_p_cole > 0 && is_concealing)
3475 {
3476 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 if (wlv.n_extra > 0)
3479 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 if (wp->w_p_wrap)
3481 {
3482 // Special voodoo required if 'wrap' is on.
3483 //
3484 // Advance the column indicator to force the line
3485 // drawing to wrap early. This will make the line
3486 // take up the same screen space when parts are concealed,
3487 // so that cursor line computations aren't messed up.
3488 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 // trailing junk to be written out of the screen line
3491 // we are building, 'boguscols' keeps track of the number
3492 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003493 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003495 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496# ifdef FEAT_RIGHTLEFT
3497 if (wp->w_p_rl)
3498 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003499 wlv.col -= wlv.n_extra;
3500 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 }
3502 else
3503# endif
3504 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003505 wlv.col += wlv.n_extra;
3506 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003508 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 n_attr = 0;
3510 }
3511
3512
3513 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3514 {
3515 // Need to fill two screen columns.
3516# ifdef FEAT_RIGHTLEFT
3517 if (wp->w_p_rl)
3518 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 --wlv.boguscols;
3520 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 }
3522 else
3523# endif
3524 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 ++wlv.boguscols;
3526 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 }
3528 }
3529
3530# ifdef FEAT_RIGHTLEFT
3531 if (wp->w_p_rl)
3532 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003533 --wlv.boguscols;
3534 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 }
3536 else
3537# endif
3538 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003539 ++wlv.boguscols;
3540 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 }
3542 }
3543 else
3544 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003545 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003547 wlv.vcol += wlv.n_extra;
3548 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 n_attr = 0;
3550 }
3551 }
3552
3553 }
3554#endif // FEAT_CONCEAL
3555 else
3556 --n_skip;
3557
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003558 // Only advance the "wlv.vcol" when after the 'number' or
3559 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003560 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561#ifdef FEAT_DIFF
3562 && filler_todo <= 0
3563#endif
3564 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003565 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566
3567#ifdef FEAT_SYN_HL
3568 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003569 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570#endif
3571
3572 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003573 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3574 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575
3576 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003577 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003578 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003579 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003580 if (n_attr_skip > 0)
3581 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582
3583 // At end of screen line and there is more to come: Display the line
3584 // so far. If there is no more to display it is caught above.
3585 if ((
3586#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003587 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003590 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003591 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592#ifdef FEAT_DIFF
3593 || filler_todo > 0
3594#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003595#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003596 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003597#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003598 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003599 && wlv.p_extra != at_end_str)
3600 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3601 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 )
3603 {
3604#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003605 screen_line(wp, wlv.screen_row, wp->w_wincol,
3606 wlv.col - wlv.boguscols,
3607 wp->w_width, wlv.screen_line_flags);
3608 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3611 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ++wlv.row;
3614 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615
3616 // When not wrapping and finished diff lines, or when displayed
3617 // '$' and highlighting until last column, break here.
3618 if ((!wp->w_p_wrap
3619#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003620 && filler_todo <= 0
3621#endif
3622#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003623 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624#endif
3625 ) || lcs_eol_one == -1)
3626 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003627#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003628 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003629 {
3630 // do not output more of the line, only the "below" prop
3631 ptr += STRLEN(ptr);
3632# ifdef FEAT_LINEBREAK
3633 dont_use_showbreak = TRUE;
3634# endif
3635 }
3636#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637
3638 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003639 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640#ifdef FEAT_DIFF
3641 && filler_todo <= 0
3642#endif
3643 )
3644 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3646 draw_vsep_win(wp, wlv.row);
3647 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 }
3649
3650 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654 break;
3655 }
3656
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658#ifdef FEAT_DIFF
3659 && filler_todo <= 0
3660#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003661#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003662 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003663#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664 && wp->w_width == Columns)
3665 {
3666 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668
3669 // Special trick to make copy/paste of wrapped lines work with
3670 // xterm/screen: write an extra character beyond the end of
3671 // the line. This will work with all terminal types
3672 // (regardless of the xn,am settings).
3673 // Only do this on a fast tty.
3674 // Only do this if the cursor is on the current line
3675 // (something has been written in it).
3676 // Don't do this for the GUI.
3677 // Don't do this for double-width characters.
3678 // Don't do this for a window not at the right screen border.
3679 if (p_tf
3680#ifdef FEAT_GUI
3681 && !gui.in_use
3682#endif
3683 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3685 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003687 || (*mb_off2cells)(
3688 LineOffset[wlv.screen_row - 1]
3689 + (int)Columns - 2,
3690 LineOffset[wlv.screen_row]
3691 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 {
3693 // First make sure we are at the end of the screen line,
3694 // then output the same character again to let the
3695 // terminal know about the wrap. If the terminal doesn't
3696 // auto-wrap, we overwrite the character.
3697 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 screen_char(LineOffset[wlv.screen_row - 1]
3699 + (unsigned)Columns - 1,
3700 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701
3702 // When there is a multi-byte character, just output a
3703 // space to keep it simple.
3704 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706 out_char(' ');
3707 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003708 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 + (Columns - 1)]);
3710 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003711 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712 screen_start(); // don't know where cursor is now
3713 }
3714 }
3715
Bram Moolenaar1306b362022-08-06 15:59:06 +01003716 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717
Bram Moolenaareed9d462021-02-15 20:38:25 +01003718 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003720 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003722 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003724 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 need_showbreak = TRUE;
3726#endif
3727#ifdef FEAT_DIFF
3728 --filler_todo;
3729 // When the filler lines are actually below the last line of the
3730 // file, don't draw the line itself, break here.
3731 if (filler_todo == 0 && wp->w_botfill)
3732 break;
3733#endif
3734 }
3735
3736 } // for every character in the line
3737
3738#ifdef FEAT_SPELL
3739 // After an empty line check first word for capital.
3740 if (*skipwhite(line) == NUL)
3741 {
3742 capcol_lnum = lnum + 1;
3743 cap_col = 0;
3744 }
3745#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003746#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 vim_free(text_props);
3748 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003749 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750#endif
3751
3752 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003753 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754}