blob: 9dfa1749def5d05195813dca3b9480aee39b1e38 [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 Moolenaar7528d1f2019-09-19 23:06:20 +0200673#endif
674#ifdef FEAT_SPELL
675 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000676 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200677# define SPWORDLEN 150
678 char_u nextline[SPWORDLEN * 2];// text with start of the next line
679 int nextlinecol = 0; // column where nextline[] starts
680 int nextline_idx = 0; // index in nextline[] where next line
681 // starts
682 int spell_attr = 0; // attributes desired by spelling
683 int word_end = 0; // last byte with same spell_attr
684 static linenr_T checked_lnum = 0; // line number for "checked_col"
685 static int checked_col = 0; // column in "checked_lnum" up to which
686 // there are no spell errors
687 static int cap_col = -1; // column to check for Cap word
688 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
689 int cur_checked_col = 0; // checked column for current line
690#endif
691 int extra_check = 0; // has extra highlighting
692 int multi_attr = 0; // attributes desired by multibyte
693 int mb_l = 1; // multi-byte byte length
694 int mb_c = 0; // decoded multi-byte character
695 int mb_utf8 = FALSE; // screen char is UTF-8 char
696 int u8cc[MAX_MCO]; // composing UTF-8 chars
697#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
698 int filler_lines = 0; // nr of filler lines to be drawn
699 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000700#else
701# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200702#endif
703#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200704 int change_start = MAXCOL; // first col of changed area
705 int change_end = -1; // last col of changed area
706#endif
707 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100708 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200709 int in_multispace = FALSE; // in multiple consecutive spaces
710 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200711#ifdef FEAT_LINEBREAK
712 int need_showbreak = FALSE; // overlong line, skipping first x
713 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100714 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200715#endif
716#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
717 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
718# define LINE_ATTR
719 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100720 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200721#endif
722#ifdef FEAT_SIGNS
723 int sign_present = FALSE;
724 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000725 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200726#endif
727#ifdef FEAT_ARABIC
728 int prev_c = 0; // previous Arabic character
729 int prev_c1 = 0; // first composing char for prev_c
730#endif
731#if defined(LINE_ATTR)
732 int did_line_attr = 0;
733#endif
734#ifdef FEAT_TERMINAL
735 int get_term_attr = FALSE;
736#endif
737#ifdef FEAT_SYN_HL
738 int cul_attr = 0; // set when 'cursorline' active
739
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200740 // margin columns for the screen line, needed for when 'cursorlineopt'
741 // contains "screenline"
742 int left_curline_col = 0;
743 int right_curline_col = 0;
744#endif
745
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200746#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
747 int feedback_col = 0;
748 int feedback_old_attr = -1;
749#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200750
751#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
752 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000753 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200754#endif
755#ifdef FEAT_CONCEAL
756 int syntax_flags = 0;
757 int syntax_seqnr = 0;
758 int prev_syntax_id = 0;
759 int conceal_attr = HL_ATTR(HLF_CONCEAL);
760 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200761 int did_wcol = FALSE;
762 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100763# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200764# define FIX_FOR_BOGUSCOLS \
765 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100766 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100767 wlv.vcol -= wlv.vcol_off; \
768 wlv.vcol_off = 0; \
769 wlv.col -= wlv.boguscols; \
770 old_boguscols = wlv.boguscols; \
771 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772 }
773#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100774# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775#endif
776
777 if (startrow > endrow) // past the end already!
778 return startrow;
779
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100780 CLEAR_FIELD(wlv);
781
782 wlv.lnum = lnum;
783 wlv.startrow = startrow;
784 wlv.row = startrow;
785 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200786
787 if (!number_only)
788 {
789 // To speed up the loop below, set extra_check when there is linebreak,
790 // trailing white space and/or syntax processing to be done.
791#ifdef FEAT_LINEBREAK
792 extra_check = wp->w_p_lbr;
793#endif
794#ifdef FEAT_SYN_HL
795 if (syntax_present(wp) && !wp->w_s->b_syn_error
796# ifdef SYN_TIME_LIMIT
797 && !wp->w_s->b_syn_slow
798# endif
799 )
800 {
801 // Prepare for syntax highlighting in this line. When there is an
802 // error, stop syntax highlighting.
803 save_did_emsg = did_emsg;
804 did_emsg = FALSE;
805 syntax_start(wp, lnum);
806 if (did_emsg)
807 wp->w_s->b_syn_error = TRUE;
808 else
809 {
810 did_emsg = save_did_emsg;
811#ifdef SYN_TIME_LIMIT
812 if (!wp->w_s->b_syn_slow)
813#endif
814 {
815 has_syntax = TRUE;
816 extra_check = TRUE;
817 }
818 }
819 }
820
821 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100822 wlv.color_cols = wp->w_p_cc_cols;
823 if (wlv.color_cols != NULL)
824 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200825#endif
826
827#ifdef FEAT_TERMINAL
828 if (term_show_buffer(wp->w_buffer))
829 {
830 extra_check = TRUE;
831 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100832 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200833 }
834#endif
835
836#ifdef FEAT_SPELL
837 if (wp->w_p_spell
838 && *wp->w_s->b_p_spl != NUL
839 && wp->w_s->b_langp.ga_len > 0
840 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
841 {
842 // Prepare for spell checking.
843 has_spell = TRUE;
844 extra_check = TRUE;
845
846 // Get the start of the next line, so that words that wrap to the
847 // next line are found too: "et<line-break>al.".
848 // Trick: skip a few chars for C/shell/Vim comments
849 nextline[SPWORDLEN] = NUL;
850 if (lnum < wp->w_buffer->b_ml.ml_line_count)
851 {
852 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
853 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
854 }
855
856 // When a word wrapped from the previous line the start of the
857 // current line is valid.
858 if (lnum == checked_lnum)
859 cur_checked_col = checked_col;
860 checked_lnum = 0;
861
862 // When there was a sentence end in the previous line may require a
863 // word starting with capital in this line. In line 1 always check
864 // the first word.
865 if (lnum != capcol_lnum)
866 cap_col = -1;
867 if (lnum == 1)
868 cap_col = 0;
869 capcol_lnum = 0;
870 }
871#endif
872
873 // handle Visual active in this window
874 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
875 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100876 pos_T *top, *bot;
877
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200878 if (LTOREQ_POS(curwin->w_cursor, VIsual))
879 {
880 // Visual is after curwin->w_cursor
881 top = &curwin->w_cursor;
882 bot = &VIsual;
883 }
884 else
885 {
886 // Visual is before curwin->w_cursor
887 top = &VIsual;
888 bot = &curwin->w_cursor;
889 }
890 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
891 if (VIsual_mode == Ctrl_V)
892 {
893 // block mode
894 if (lnum_in_visual_area)
895 {
896 fromcol = wp->w_old_cursor_fcol;
897 tocol = wp->w_old_cursor_lcol;
898 }
899 }
900 else
901 {
902 // non-block mode
903 if (lnum > top->lnum && lnum <= bot->lnum)
904 fromcol = 0;
905 else if (lnum == top->lnum)
906 {
907 if (VIsual_mode == 'V') // linewise
908 fromcol = 0;
909 else
910 {
911 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
912 if (gchar_pos(top) == NUL)
913 tocol = fromcol + 1;
914 }
915 }
916 if (VIsual_mode != 'V' && lnum == bot->lnum)
917 {
918 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
919 {
920 fromcol = -10;
921 tocol = MAXCOL;
922 }
923 else if (bot->col == MAXCOL)
924 tocol = MAXCOL;
925 else
926 {
927 pos = *bot;
928 if (*p_sel == 'e')
929 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
930 else
931 {
932 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
933 ++tocol;
934 }
935 }
936 }
937 }
938
939 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200940 if (!highlight_match && lnum == curwin->w_cursor.lnum
941 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200942#ifdef FEAT_GUI
943 && !gui.in_use
944#endif
945 )
946 noinvcur = TRUE;
947
948 // if inverting in this line set area_highlighting
949 if (fromcol >= 0)
950 {
951 area_highlighting = TRUE;
952 vi_attr = HL_ATTR(HLF_V);
953#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
954 if ((clip_star.available && !clip_star.owned
955 && clip_isautosel_star())
956 || (clip_plus.available && !clip_plus.owned
957 && clip_isautosel_plus()))
958 vi_attr = HL_ATTR(HLF_VNC);
959#endif
960 }
961 }
962
963 // handle 'incsearch' and ":s///c" highlighting
964 else if (highlight_match
965 && wp == curwin
966 && lnum >= curwin->w_cursor.lnum
967 && lnum <= curwin->w_cursor.lnum + search_match_lines)
968 {
969 if (lnum == curwin->w_cursor.lnum)
970 getvcol(curwin, &(curwin->w_cursor),
971 (colnr_T *)&fromcol, NULL, NULL);
972 else
973 fromcol = 0;
974 if (lnum == curwin->w_cursor.lnum + search_match_lines)
975 {
976 pos.lnum = lnum;
977 pos.col = search_match_endcol;
978 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
979 }
980 else
981 tocol = MAXCOL;
982 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100983 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 tocol = fromcol + 1;
985 area_highlighting = TRUE;
986 vi_attr = HL_ATTR(HLF_I);
987 }
988 }
989
990#ifdef FEAT_DIFF
991 filler_lines = diff_check(wp, lnum);
992 if (filler_lines < 0)
993 {
994 if (filler_lines == -1)
995 {
996 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100997 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100999 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001000 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001001 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002 }
1003 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001004 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001005 filler_lines = 0;
1006 area_highlighting = TRUE;
1007 }
1008 if (lnum == wp->w_topline)
1009 filler_lines = wp->w_topfill;
1010 filler_todo = filler_lines;
1011#endif
1012
1013#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01001014 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +00001015 if (sign_present)
1016 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017#endif
1018
1019#ifdef LINE_ATTR
1020# ifdef FEAT_SIGNS
1021 // If this line has a sign with line highlighting set line_attr.
1022 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001023 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001024# endif
1025# if defined(FEAT_QUICKFIX)
1026 // Highlight the current line in the quickfix window.
1027 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1028 line_attr = HL_ATTR(HLF_QFL);
1029# endif
1030 if (line_attr != 0)
1031 area_highlighting = TRUE;
1032#endif
1033
1034 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1035 ptr = line;
1036
1037#ifdef FEAT_SPELL
1038 if (has_spell && !number_only)
1039 {
1040 // For checking first word with a capital skip white space.
1041 if (cap_col == 0)
1042 cap_col = getwhitecols(line);
1043
1044 // To be able to spell-check over line boundaries copy the end of the
1045 // current line into nextline[]. Above the start of the next line was
1046 // copied to nextline[SPWORDLEN].
1047 if (nextline[SPWORDLEN] == NUL)
1048 {
1049 // No next line or it is empty.
1050 nextlinecol = MAXCOL;
1051 nextline_idx = 0;
1052 }
1053 else
1054 {
1055 v = (long)STRLEN(line);
1056 if (v < SPWORDLEN)
1057 {
1058 // Short line, use it completely and append the start of the
1059 // next line.
1060 nextlinecol = 0;
1061 mch_memmove(nextline, line, (size_t)v);
1062 STRMOVE(nextline + v, nextline + SPWORDLEN);
1063 nextline_idx = v + 1;
1064 }
1065 else
1066 {
1067 // Long line, use only the last SPWORDLEN bytes.
1068 nextlinecol = v - SPWORDLEN;
1069 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1070 nextline_idx = SPWORDLEN + 1;
1071 }
1072 }
1073 }
1074#endif
1075
1076 if (wp->w_p_list)
1077 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001078 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001079 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001080 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001081 || wp->w_lcs_chars.trail
1082 || wp->w_lcs_chars.lead
1083 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001084 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001085
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001087 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088 {
1089 trailcol = (colnr_T)STRLEN(ptr);
1090 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1091 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001092 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001094 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001095 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001096 {
1097 leadcol = 0;
1098 while (VIM_ISWHITE(ptr[leadcol]))
1099 ++leadcol;
1100 if (ptr[leadcol] == NUL)
1101 // in a line full of spaces all of them are treated as trailing
1102 leadcol = (colnr_T)0;
1103 else
1104 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001105 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001106 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107 }
1108
1109 wcr_attr = get_wcr_attr(wp);
1110 if (wcr_attr != 0)
1111 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001112 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 area_highlighting = TRUE;
1114 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001115
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001116#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001118 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119#endif
1120
1121 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1122 // first character to be displayed.
1123 if (wp->w_p_wrap)
1124 v = wp->w_skipcol;
1125 else
1126 v = wp->w_leftcol;
1127 if (v > 0 && !number_only)
1128 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001129 char_u *prev_ptr = ptr;
1130 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001131 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001132
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001133 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001134 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001136 charsize = win_lbr_chartabsize(&cts, NULL);
1137 cts.cts_vcol += charsize;
1138 prev_ptr = cts.cts_ptr;
1139 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001141 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001142 ptr = cts.cts_ptr;
1143 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144
1145 // When:
1146 // - 'cuc' is set, or
1147 // - 'colorcolumn' is set, or
1148 // - 'virtualedit' is set, or
1149 // - the visual mode is active,
1150 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001151 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001152#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001153 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154#endif
1155 virtual_active() ||
1156 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001157 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158
1159 // Handle a character that's not completely on the screen: Put ptr at
1160 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001161 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001163 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164 ptr = prev_ptr;
1165 // If the character fits on the screen, don't need to skip it.
1166 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001167 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1168 && wlv.col == 0)
1169 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001170 }
1171
1172 // Adjust for when the inverted text is before the screen,
1173 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001174 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001175 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001176 else if (fromcol >= 0 && fromcol < wlv.vcol)
1177 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178
1179#ifdef FEAT_LINEBREAK
1180 // When w_skipcol is non-zero, first line needs 'showbreak'
1181 if (wp->w_p_wrap)
1182 need_showbreak = TRUE;
1183#endif
1184#ifdef FEAT_SPELL
1185 // When spell checking a word we need to figure out the start of the
1186 // word and if it's badly spelled or not.
1187 if (has_spell)
1188 {
1189 int len;
1190 colnr_T linecol = (colnr_T)(ptr - line);
1191 hlf_T spell_hlf = HLF_COUNT;
1192
1193 pos = wp->w_cursor;
1194 wp->w_cursor.lnum = lnum;
1195 wp->w_cursor.col = linecol;
1196 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1197
1198 // spell_move_to() may call ml_get() and make "line" invalid
1199 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1200 ptr = line + linecol;
1201
1202 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1203 {
1204 // no bad word found at line start, don't check until end of a
1205 // word
1206 spell_hlf = HLF_COUNT;
1207 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1208 }
1209 else
1210 {
1211 // bad word found, use attributes until end of word
1212 word_end = wp->w_cursor.col + len + 1;
1213
1214 // Turn index into actual attributes.
1215 if (spell_hlf != HLF_COUNT)
1216 spell_attr = highlight_attr[spell_hlf];
1217 }
1218 wp->w_cursor = pos;
1219
1220# ifdef FEAT_SYN_HL
1221 // Need to restart syntax highlighting for this line.
1222 if (has_syntax)
1223 syntax_start(wp, lnum);
1224# endif
1225 }
1226#endif
1227 }
1228
1229 // Correct highlighting for cursor that can't be disabled.
1230 // Avoids having to check this for each character.
1231 if (fromcol >= 0)
1232 {
1233 if (noinvcur)
1234 {
1235 if ((colnr_T)fromcol == wp->w_virtcol)
1236 {
1237 // highlighting starts at cursor, let it start just after the
1238 // cursor
1239 fromcol_prev = fromcol;
1240 fromcol = -1;
1241 }
1242 else if ((colnr_T)fromcol < wp->w_virtcol)
1243 // restart highlighting after the cursor
1244 fromcol_prev = wp->w_virtcol;
1245 }
1246 if (fromcol >= tocol)
1247 fromcol = -1;
1248 }
1249
1250#ifdef FEAT_SEARCH_EXTRA
1251 if (!number_only)
1252 {
1253 v = (long)(ptr - line);
1254 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1255 &line, &screen_search_hl,
1256 &search_attr);
1257 ptr = line + v; // "line" may have been updated
1258 }
1259#endif
1260
1261#ifdef FEAT_SYN_HL
1262 // Cursor line highlighting for 'cursorline' in the current window.
1263 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1264 {
1265 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001266 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 if (!(wp == curwin && VIsual_active)
1268 && wp->w_p_culopt_flags != CULOPT_NBR)
1269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001270 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1272
1273 // Only set line_attr here when "screenline" is not present in
1274 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001275 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 {
1277 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001278# ifdef FEAT_SIGNS
1279 // Combine the 'cursorline' and sign highlighting, depending on
1280 // the sign priority.
1281 if (sign_present && sattr.sat_linehl > 0)
1282 {
1283 if (sattr.sat_priority >= 100)
1284 line_attr = hl_combine_attr(cul_attr, line_attr);
1285 else
1286 line_attr = hl_combine_attr(line_attr, cul_attr);
1287 }
1288 else
1289# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001290# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001291 // let the line attribute overrule 'cursorline', otherwise
1292 // it disappears when both have background set;
1293 // 'cursorline' can use underline or bold to make it show
1294 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001295# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001296 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001297# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 }
1299 else
1300 {
1301 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1303 }
1304 area_highlighting = TRUE;
1305 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 }
1307#endif
1308
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001309#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 {
1311 char_u *prop_start;
1312
1313 text_prop_count = get_text_props(wp->w_buffer, lnum,
1314 &prop_start, FALSE);
1315 if (text_prop_count > 0)
1316 {
1317 // Make a copy of the properties, so that they are properly
1318 // aligned.
1319 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1320 if (text_props != NULL)
1321 mch_memmove(text_props, prop_start,
1322 text_prop_count * sizeof(textprop_T));
1323
1324 // Allocate an array for the indexes.
1325 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001326 if (text_prop_idxs == NULL)
1327 VIM_CLEAR(text_props);
1328
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329 area_highlighting = TRUE;
1330 extra_check = TRUE;
1331 }
1332 }
1333#endif
1334
Bram Moolenaar1306b362022-08-06 15:59:06 +01001335 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001336
1337 // Repeat for the whole displayed line.
1338 for (;;)
1339 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001340 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001342 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343#endif
1344#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001345 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001347
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001349 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001351#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001352 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001353 {
1354 cul_attr = 0;
1355 line_attr = line_attr_save;
1356 }
1357#endif
1358
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001360 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001362 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 if (cmdwin_type != 0 && wp == curwin)
1364 {
1365 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 wlv.n_extra = 1;
1367 wlv.c_extra = cmdwin_type;
1368 wlv.c_final = NUL;
1369 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 }
1371 }
1372#endif
1373
1374#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001375 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001376 {
1377 int fdc = compute_foldcolumn(wp, 0);
1378
Bram Moolenaar1306b362022-08-06 15:59:06 +01001379 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 if (fdc > 0)
1381 {
1382 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1383 // already be in use.
1384 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001385 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 if (p_extra_free != NULL)
1387 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001388 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001389 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001390 p_extra_free[wlv.n_extra] = NUL;
1391 wlv.p_extra = p_extra_free;
1392 wlv.c_extra = NUL;
1393 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001394 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001395 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001396 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1397 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001398 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001399 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 }
1401 }
1402 }
1403#endif
1404
1405#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001406 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001408 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 // Show the sign column when there are any signs in this
1410 // buffer or when using Netbeans.
1411 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001412 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1413 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 }
1415#endif
1416
Bram Moolenaar1306b362022-08-06 15:59:06 +01001417 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001419 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 // Display the absolute or relative line number. After the
1421 // first fill with blanks when the 'n' flag isn't in 'cpo'
1422 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001423 && (wlv.row == startrow + filler_lines
1424 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 {
1426#ifdef FEAT_SIGNS
1427 // If 'signcolumn' is set to 'number' and a sign is present
1428 // in 'lnum', then display the sign instead of the line
1429 // number.
1430 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1431 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001432 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1433 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 else
1435#endif
1436 {
1437 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001438 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439 {
1440 long num;
1441 char *fmt = "%*ld ";
1442
1443 if (wp->w_p_nu && !wp->w_p_rnu)
1444 // 'number' + 'norelativenumber'
1445 num = (long)lnum;
1446 else
1447 {
1448 // 'relativenumber', don't use negative numbers
1449 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1450 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1451 {
1452 // 'number' + 'relativenumber'
1453 num = lnum;
1454 fmt = "%-*ld ";
1455 }
1456 }
1457
1458 sprintf((char *)extra, fmt,
1459 number_width(wp), num);
1460 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001461 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1462 ++wlv.p_extra)
1463 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464#ifdef FEAT_RIGHTLEFT
1465 if (wp->w_p_rl) // reverse line numbers
1466 {
1467 char_u *p1, *p2;
1468 int t;
1469
1470 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001471 p2 = skipwhite(extra);
1472 p2 = skiptowhite(p2) - 1;
1473 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 {
1475 t = *p1;
1476 *p1 = *p2;
1477 *p2 = t;
1478 }
1479 }
1480#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001481 wlv.p_extra = extra;
1482 wlv.c_extra = NUL;
1483 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 }
1485 else
1486 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001487 wlv.c_extra = ' ';
1488 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001490 wlv.n_extra = number_width(wp) + 1;
1491 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492#ifdef FEAT_SYN_HL
1493 // When 'cursorline' is set highlight the line number of
1494 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001495 // When 'cursorlineopt' does not have "line" only
1496 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 // TODO: Can we use CursorLine instead of CursorLineNr
1498 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001499 if (wp->w_p_cul
1500 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001502 && (wlv.row == startrow + filler_lines
1503 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001504 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001505 wlv.char_attr = hl_combine_attr(wcr_attr,
1506 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001508 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1509 && HL_ATTR(HLF_LNA) != 0)
1510 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001511 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001512 HL_ATTR(HLF_LNA));
1513 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1514 && HL_ATTR(HLF_LNB) != 0)
1515 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001516 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001517 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 }
James McCoya80aad72021-12-22 19:45:28 +00001519#ifdef FEAT_SIGNS
1520 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001521 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001522#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001523 }
1524 }
1525
1526#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001527 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1528 && wlv.n_extra == 0
1529 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001531 wlv.draw_state = WL_BRI;
1532 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1533 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001535 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536
1537 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001538 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001540 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001542 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543# ifdef FEAT_DIFF
1544 && filler_lines == 0
1545# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001546# ifdef FEAT_PROP_POPUP
1547 && !dont_use_showbreak
1548# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 )
1550 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001551 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001553 if (wlv.diff_hlf != (hlf_T)0)
1554 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001556 wlv.p_extra = NULL;
1557 wlv.c_extra = ' ';
1558 wlv.c_final = NUL;
1559 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001561 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001562 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001563 wlv.n_extra -= win_col_off2(wp);
1564 if (wlv.n_extra < 0)
1565 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001566 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001567 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001568 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 // Correct end of highlighted area for 'breakindent',
1570 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001571 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001572 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001573 }
1574 }
1575#endif
1576
1577#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001578 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001580 char_u *sbr;
1581
Bram Moolenaar1306b362022-08-06 15:59:06 +01001582 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583# ifdef FEAT_DIFF
1584 if (filler_todo > 0)
1585 {
1586 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001587 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001589 wlv.c_extra = '-';
1590 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 }
1592 else
1593 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001594 wlv.c_extra = wp->w_fill_chars.diff;
1595 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 }
1597# ifdef FEAT_RIGHTLEFT
1598 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001599 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 else
1601# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001602 wlv.n_extra = wp->w_width - wlv.col;
1603 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 }
1605# endif
1606# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001607 sbr = get_showbreak_value(wp);
1608 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001609 {
1610 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001611 wlv.p_extra = sbr;
1612 wlv.c_extra = NUL;
1613 wlv.c_final = NUL;
1614 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001615 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1616 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001617 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001618 // Correct end of highlighted area for 'showbreak',
1619 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001620 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001621 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001623 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1624 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625# ifdef FEAT_SYN_HL
1626 // combine 'showbreak' with 'cursorline'
1627 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001628 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1629 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630# endif
1631 }
1632# endif
1633 }
1634#endif
1635
Bram Moolenaar1306b362022-08-06 15:59:06 +01001636 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001638 wlv.draw_state = WL_LINE;
1639 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640 {
1641 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001642 wlv.n_extra = wlv.saved_n_extra;
1643 wlv.c_extra = wlv.saved_c_extra;
1644 wlv.c_final = wlv.saved_c_final;
1645 wlv.p_extra = wlv.saved_p_extra;
1646 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 }
1648 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001649 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 }
1651 }
1652#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001653 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001654 && wlv.vcol >= left_curline_col
1655 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001656 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001657 cul_attr = HL_ATTR(HLF_CUL);
1658 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 }
1660#endif
1661
1662 // When still displaying '$' of change command, stop at cursor.
1663 // When only displaying the (relative) line number and that's done,
1664 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001665 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001666 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001667 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668#ifdef FEAT_DIFF
1669 && filler_todo <= 0
1670#endif
1671 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001673 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1674 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 // Pretend we have finished updating the window. Except when
1676 // 'cursorcolumn' is set.
1677#ifdef FEAT_SYN_HL
1678 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001679 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 else
1681#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001682 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 break;
1684 }
1685
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 {
1688 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001689 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001690 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 && (*mb_ptr2cells)(ptr) > 1)
1692 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001693 && vcol_prev < wlv.vcol // not at margin
1694 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 area_attr = vi_attr; // start highlighting
1696 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001697 && (wlv.vcol == tocol
1698 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 area_attr = 0; // stop highlighting
1700
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001701#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 if (text_props != NULL)
1703 {
1704 int pi;
1705 int bcol = (int)(ptr - line);
1706
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001708# ifdef FEAT_LINEBREAK
1709 && !in_linebreak
1710# endif
1711 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 --bcol; // still working on the previous char, e.g. Tab
1713
1714 // Check if any active property ends.
1715 for (pi = 0; pi < text_props_active; ++pi)
1716 {
1717 int tpi = text_prop_idxs[pi];
1718
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001719 if (text_props[tpi].tp_col != MAXCOL
1720 && bcol >= text_props[tpi].tp_col - 1
1721 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 {
1723 if (pi + 1 < text_props_active)
1724 mch_memmove(text_prop_idxs + pi,
1725 text_prop_idxs + pi + 1,
1726 sizeof(int)
1727 * (text_props_active - (pi + 1)));
1728 --text_props_active;
1729 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001730# ifdef FEAT_LINEBREAK
1731 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001732 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001733 syntax_attr = 0;
1734# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 }
1736 }
1737
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001738# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001739 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001740 // not on the next char yet, don't start another prop
1741 --bcol;
1742# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001744 // With 'nowrap' and not in the first screen line only "below"
1745 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001747 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001748 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001749 && (wp->w_p_wrap
1750 || wlv.row == startrow
1751 || (text_props[text_prop_next].tp_flags
1752 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001753 || (bcol == 0 &&
1754 (text_props[text_prop_next].tp_flags
1755 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001756 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001757 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001758 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001759 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1760 {
1761 // first display the '$' after the line
1762 text_prop_follows = TRUE;
1763 break;
1764 }
1765 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001766 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001767 + text_props[text_prop_next].tp_len)
1768 text_prop_idxs[text_props_active++] = text_prop_next;
1769 ++text_prop_next;
1770 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001772 if (wlv.n_extra == 0 || !extra_for_textprop)
1773 {
1774 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001775 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001776 text_prop_flags = 0;
1777 text_prop_type = NULL;
1778 text_prop_id = 0;
1779 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001780 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001782 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001783 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001784 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001785
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 // Sort the properties on priority and/or starting last.
1787 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001788 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001789 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001790 sort_text_props(wp->w_buffer, text_props,
1791 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792
1793 for (pi = 0; pi < text_props_active; ++pi)
1794 {
1795 int tpi = text_prop_idxs[pi];
1796 proptype_T *pt = text_prop_type_by_id(
1797 wp->w_buffer, text_props[tpi].tp_type);
1798
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001799 if (pt != NULL && (pt->pt_hl_id > 0
1800 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001801 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001803 if (pt->pt_hl_id > 0)
1804 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001805 text_prop_type = pt;
1806 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001807 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001808 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001809 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001810 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001811 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 }
1813 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001814 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001815 && -text_prop_id
1816 <= wp->w_buffer->b_textprop_text.ga_len)
1817 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001818 textprop_T *tp = &text_props[used_tpi];
1819 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001820 ->b_textprop_text.ga_data)[
1821 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001822 int above = (tp->tp_flags
1823 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001824
1825 // reset the ID in the copy to avoid it being used
1826 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001827 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001828
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001829 if (p != NULL)
1830 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001831 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001832 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001833 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001834 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001835 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1836 int padding = tp->tp_col == MAXCOL
1837 && tp->tp_len > 1
1838 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001839
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001840 // Insert virtual text before the current
1841 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001842 wlv.p_extra = p;
1843 wlv.c_extra = NUL;
1844 wlv.c_final = NUL;
1845 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001846 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001847 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001848 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001849 saved_search_attr = search_attr;
1850 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001851 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001852 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001853 if (*ptr == NUL)
1854 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001855 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001856#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001857 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001858 {
1859 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001860 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001861 need_showbreak = FALSE;
1862 dont_use_showbreak = TRUE;
1863 }
1864#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001865 if ((right || above || below || !wrap
1866 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001867 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001868 char_u *prev_p_extra = wlv.p_extra;
1869 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001870
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001871 // Take care of padding, right-align and
1872 // truncation.
1873 // Shared with win_lbr_chartabsize(), must do
1874 // exactly the same.
1875 start_line = text_prop_position(wp, tp,
1876 wlv.col,
1877 &wlv.n_extra, &wlv.p_extra,
1878 &n_attr, &n_attr_skip);
1879 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001880 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001881 // wlv.p_extra was allocated
1882 vim_free(p_extra_free2);
1883 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001884 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001885
1886 // When 'wrap' is off then for "below" we need
1887 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001888 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001889 {
1890 draw_screen_line(wp, &wlv);
1891
1892 // When line got too long for screen break
1893 // here.
1894 if (wlv.row == endrow)
1895 {
1896 ++wlv.row;
1897 break;
1898 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001899 win_line_start(wp, &wlv, TRUE);
1900 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001901 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001902 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001903 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001904
1905 // If another text prop follows the condition below at
1906 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001907 // If this is an "above" text prop and 'nowrap' the we
1908 // must wrap anyway.
1909 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001910 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001911 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001913 else if (text_prop_next < text_prop_count
1914 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001915 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1916 || (!wp->w_p_wrap
1917 && wlv.col == wp->w_width - 1
1918 && (text_props[text_prop_next].tp_flags
1919 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001920 // When at last-but-one character and a text property
1921 // follows after it, we may need to flush the line after
1922 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001923 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001924 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 }
1926#endif
1927
Bram Moolenaare38fc862022-08-11 17:24:50 +01001928#ifdef FEAT_SEARCH_EXTRA
1929 if (wlv.n_extra == 0)
1930 {
1931 // Check for start/end of 'hlsearch' and other matches.
1932 // After end, check for start/end of next match.
1933 // When another match, have to check for start again.
1934 v = (long)(ptr - line);
1935 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1936 &screen_search_hl, &has_match_conc,
1937 &match_conc, did_line_attr, lcs_eol_one,
1938 &on_last_col);
1939 ptr = line + v; // "line" may have been changed
1940 prev_ptr = ptr;
1941
1942 // Do not allow a conceal over EOL otherwise EOL will be missed
1943 // and bad things happen.
1944 if (*ptr == NUL)
1945 has_match_conc = 0;
1946 }
1947#endif
1948
1949#ifdef FEAT_DIFF
1950 if (wlv.diff_hlf != (hlf_T)0)
1951 {
1952 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1953 && wlv.n_extra == 0)
1954 wlv.diff_hlf = HLF_TXD; // changed text
1955 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1956 && wlv.n_extra == 0)
1957 wlv.diff_hlf = HLF_CHD; // changed line
1958 line_attr = HL_ATTR(wlv.diff_hlf);
1959 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1960 && wp->w_p_culopt_flags != CULOPT_NBR
1961 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1962 && wlv.vcol <= right_curline_col)))
1963 line_attr = hl_combine_attr(
1964 line_attr, HL_ATTR(HLF_CUL));
1965 }
1966#endif
1967
Bram Moolenaara74fda62019-10-19 17:38:03 +02001968#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001969 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001970 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001971 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001972# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001973 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001974 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001975# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001976 // Get syntax attribute.
1977 if (has_syntax)
1978 {
1979 // Get the syntax attribute for the character. If there
1980 // is an error, disable syntax highlighting.
1981 save_did_emsg = did_emsg;
1982 did_emsg = FALSE;
1983
1984 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001985 if (v == prev_syntax_col)
1986 // at same column again
1987 syntax_attr = prev_syntax_attr;
1988 else
1989 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001990# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001991 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001992# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001993 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001994# ifdef FEAT_SPELL
1995 has_spell ? &can_spell :
1996# endif
1997 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001998 prev_syntax_col = v;
1999 prev_syntax_attr = syntax_attr;
2000 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002001
Bram Moolenaar34390282019-10-16 14:38:26 +02002002 if (did_emsg)
2003 {
2004 wp->w_s->b_syn_error = TRUE;
2005 has_syntax = FALSE;
2006 syntax_attr = 0;
2007 }
2008 else
2009 did_emsg = save_did_emsg;
2010# ifdef SYN_TIME_LIMIT
2011 if (wp->w_s->b_syn_slow)
2012 has_syntax = FALSE;
2013# endif
2014
2015 // Need to get the line again, a multi-line regexp may
2016 // have made it invalid.
2017 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2018 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002019 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002020# ifdef FEAT_CONCEAL
2021 // no concealing past the end of the line, it interferes
2022 // with line highlighting
2023 if (*ptr == NUL)
2024 syntax_flags = 0;
2025 else
2026 syntax_flags = get_syntax_info(&syntax_seqnr);
2027# endif
2028 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002029 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002030# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002031 // Combine text property highlight into syntax highlight.
2032 if (text_prop_type != NULL)
2033 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002034 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002035 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2036 else
2037 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002038 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002039 }
2040# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002041#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002042
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002043 // Decide which of the highlight attributes to use.
2044 attr_pri = TRUE;
2045#ifdef LINE_ATTR
2046 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002047 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002048 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002049 if (!highlight_match)
2050 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002051 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002052# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002053 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002054# endif
2055 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002058 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002059# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002060 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002061# endif
2062 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002063 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002064 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2065 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 {
2067 // Use line_attr when not in the Visual or 'incsearch' area
2068 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002069# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002071# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002072 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002073# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074 attr_pri = FALSE;
2075 }
2076#else
2077 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002078 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002080 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002081#endif
2082 else
2083 {
2084 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002086 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002087#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002088 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002089#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002091#ifdef FEAT_PROP_POPUP
2092 // override with text property highlight when "override" is TRUE
2093 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002094 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002095#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002097
2098 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002099 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002100 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002101 if (wlv.char_attr == 0)
2102 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002103 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002104 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002105 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106
2107 // Get the next character to put on the screen.
2108
2109 // The "p_extra" points to the extra stuff that is inserted to
2110 // represent special characters (non-printable stuff) and other
2111 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002112 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2114 // "p_extra[n_extra]".
2115 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002116 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002117 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002118 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002119 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002120 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2121 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002122 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2123 if (enc_utf8 && utf_char2len(c) > 1)
2124 {
2125 mb_utf8 = TRUE;
2126 u8cc[0] = 0;
2127 c = 0xc0;
2128 }
2129 else
2130 mb_utf8 = FALSE;
2131 }
2132 else
2133 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002134 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002135 if (has_mbyte)
2136 {
2137 mb_c = c;
2138 if (enc_utf8)
2139 {
2140 // If the UTF-8 character is more than one byte:
2141 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002142 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002143 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 mb_l = 1;
2146 else if (mb_l > 1)
2147 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002148 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002149 mb_utf8 = TRUE;
2150 c = 0xc0;
2151 }
2152 }
2153 else
2154 {
2155 // if this is a DBCS character, put it in "mb_c"
2156 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002157 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002158 mb_l = 1;
2159 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002161 }
2162 if (mb_l == 0) // at the NUL at end-of-line
2163 mb_l = 1;
2164
2165 // If a double-width char doesn't fit display a '>' in the
2166 // last column.
2167 if ((
2168# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002169 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002171 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002172 && (*mb_char2cells)(mb_c) == 2)
2173 {
2174 c = '>';
2175 mb_c = c;
2176 mb_l = 1;
2177 mb_utf8 = FALSE;
2178 multi_attr = HL_ATTR(HLF_AT);
2179#ifdef FEAT_SYN_HL
2180 if (cul_attr)
2181 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2182#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002183 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002184
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002185 // put the pointer back to output the double-width
2186 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002187 ++wlv.n_extra;
2188 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189 }
2190 else
2191 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 wlv.n_extra -= mb_l - 1;
2193 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 }
2195 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002196 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002197 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002198 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002199#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002200 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002201 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002202 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002203 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002204 if (search_attr == 0)
2205 search_attr = saved_search_attr;
2206 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002207#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 }
2209 else
2210 {
2211#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002212 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002213#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002214 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 // Get a character from the line itself.
2217 c = *ptr;
2218#ifdef FEAT_LINEBREAK
2219 c0 = *ptr;
2220#endif
2221 if (has_mbyte)
2222 {
2223 mb_c = c;
2224 if (enc_utf8)
2225 {
2226 // If the UTF-8 character is more than one byte: Decode it
2227 // into "mb_c".
2228 mb_l = utfc_ptr2len(ptr);
2229 mb_utf8 = FALSE;
2230 if (mb_l > 1)
2231 {
2232 mb_c = utfc_ptr2char(ptr, u8cc);
2233 // Overlong encoded ASCII or ASCII with composing char
2234 // is displayed normally, except a NUL.
2235 if (mb_c < 0x80)
2236 {
2237 c = mb_c;
2238#ifdef FEAT_LINEBREAK
2239 c0 = mb_c;
2240#endif
2241 }
2242 mb_utf8 = TRUE;
2243
2244 // At start of the line we can have a composing char.
2245 // Draw it as a space with a composing char.
2246 if (utf_iscomposing(mb_c))
2247 {
2248 int i;
2249
2250 for (i = Screen_mco - 1; i > 0; --i)
2251 u8cc[i] = u8cc[i - 1];
2252 u8cc[0] = mb_c;
2253 mb_c = ' ';
2254 }
2255 }
2256
2257 if ((mb_l == 1 && c >= 0x80)
2258 || (mb_l >= 1 && mb_c == 0)
2259 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2260 {
2261 // Illegal UTF-8 byte: display as <xx>.
2262 // Non-BMP character : display as ? or fullwidth ?.
2263 transchar_hex(extra, mb_c);
2264# ifdef FEAT_RIGHTLEFT
2265 if (wp->w_p_rl) // reverse
2266 rl_mirror(extra);
2267# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002268 wlv.p_extra = extra;
2269 c = *wlv.p_extra;
2270 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2273 wlv.c_extra = NUL;
2274 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275 if (area_attr == 0 && search_attr == 0)
2276 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002277 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002278 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002279 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002280 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281 }
2282 }
2283 else if (mb_l == 0) // at the NUL at end-of-line
2284 mb_l = 1;
2285#ifdef FEAT_ARABIC
2286 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2287 {
2288 // Do Arabic shaping.
2289 int pc, pc1, nc;
2290 int pcc[MAX_MCO];
2291
2292 // The idea of what is the previous and next
2293 // character depends on 'rightleft'.
2294 if (wp->w_p_rl)
2295 {
2296 pc = prev_c;
2297 pc1 = prev_c1;
2298 nc = utf_ptr2char(ptr + mb_l);
2299 prev_c1 = u8cc[0];
2300 }
2301 else
2302 {
2303 pc = utfc_ptr2char(ptr + mb_l, pcc);
2304 nc = prev_c;
2305 pc1 = pcc[0];
2306 }
2307 prev_c = mb_c;
2308
2309 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2310 }
2311 else
2312 prev_c = mb_c;
2313#endif
2314 }
2315 else // enc_dbcs
2316 {
2317 mb_l = MB_BYTE2LEN(c);
2318 if (mb_l == 0) // at the NUL at end-of-line
2319 mb_l = 1;
2320 else if (mb_l > 1)
2321 {
2322 // We assume a second byte below 32 is illegal.
2323 // Hopefully this is OK for all double-byte encodings!
2324 if (ptr[1] >= 32)
2325 mb_c = (c << 8) + ptr[1];
2326 else
2327 {
2328 if (ptr[1] == NUL)
2329 {
2330 // head byte at end of line
2331 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002332 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 }
2334 else
2335 {
2336 // illegal tail byte
2337 mb_l = 2;
2338 STRCPY(extra, "XX");
2339 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002340 wlv.p_extra = extra;
2341 wlv.n_extra = (int)STRLEN(extra) - 1;
2342 wlv.c_extra = NUL;
2343 wlv.c_final = NUL;
2344 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 if (area_attr == 0 && search_attr == 0)
2346 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002347 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002348 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002349 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002350 // save current attr
2351 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 }
2353 mb_c = c;
2354 }
2355 }
2356 }
2357 // If a double-width char doesn't fit display a '>' in the
2358 // last column; the character is displayed at the start of the
2359 // next line.
2360 if ((
2361# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002362 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002364 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365 && (*mb_char2cells)(mb_c) == 2)
2366 {
2367 c = '>';
2368 mb_c = c;
2369 mb_utf8 = FALSE;
2370 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002371 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 // Put pointer back so that the character will be
2373 // displayed at the start of the next line.
2374 --ptr;
2375#ifdef FEAT_CONCEAL
2376 did_decrement_ptr = TRUE;
2377#endif
2378 }
2379 else if (*ptr != NUL)
2380 ptr += mb_l - 1;
2381
2382 // If a double-width char doesn't fit at the left side display
2383 // a '<' in the first column. Don't do this for unprintable
2384 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002385 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002387 wlv.n_extra = 1;
2388 wlv.c_extra = MB_FILLER_CHAR;
2389 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 c = ' ';
2391 if (area_attr == 0 && search_attr == 0)
2392 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002393 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002394 extra_attr = hl_combine_attr(
2395 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397 }
2398 mb_c = c;
2399 mb_utf8 = FALSE;
2400 mb_l = 1;
2401 }
2402
2403 }
2404 ++ptr;
2405
2406 if (extra_check)
2407 {
2408#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002409 // Check spelling (unless at the end of the line).
2410 // Only do this when there is no syntax highlighting, the
2411 // @Spell cluster is not used or the current syntax item
2412 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002413 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 if (has_spell && v >= word_end && v > cur_checked_col)
2415 {
2416 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002417 // do not calculate cap_col at the end of the line or when
2418 // only white space is following
2419 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420# ifdef FEAT_SYN_HL
2421 !has_syntax ||
2422# endif
2423 can_spell))
2424 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002425 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 int len;
2427 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002428
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002431
2432 // Use nextline[] if possible, it has the start of the
2433 // next line concatenated.
2434 if ((prev_ptr - line) - nextlinecol >= 0)
2435 p = nextline + (prev_ptr - line) - nextlinecol;
2436 else
2437 p = prev_ptr;
2438 cap_col -= (int)(prev_ptr - line);
2439 len = spell_check(wp, p, &spell_hlf, &cap_col,
2440 nochange);
2441 word_end = v + len;
2442
2443 // In Insert mode only highlight a word that
2444 // doesn't touch the cursor.
2445 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002446 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447 && wp->w_cursor.lnum == lnum
2448 && wp->w_cursor.col >=
2449 (colnr_T)(prev_ptr - line)
2450 && wp->w_cursor.col < (colnr_T)word_end)
2451 {
2452 spell_hlf = HLF_COUNT;
2453 spell_redraw_lnum = lnum;
2454 }
2455
2456 if (spell_hlf == HLF_COUNT && p != prev_ptr
2457 && (p - nextline) + len > nextline_idx)
2458 {
2459 // Remember that the good word continues at the
2460 // start of the next line.
2461 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002462 checked_col = (int)((p - nextline)
2463 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 }
2465
2466 // Turn index into actual attributes.
2467 if (spell_hlf != HLF_COUNT)
2468 spell_attr = highlight_attr[spell_hlf];
2469
2470 if (cap_col > 0)
2471 {
2472 if (p != prev_ptr
2473 && (p - nextline) + cap_col >= nextline_idx)
2474 {
2475 // Remember that the word in the next line
2476 // must start with a capital.
2477 capcol_lnum = lnum + 1;
2478 cap_col = (int)((p - nextline) + cap_col
2479 - nextline_idx);
2480 }
2481 else
2482 // Compute the actual column.
2483 cap_col += (int)(prev_ptr - line);
2484 }
2485 }
2486 }
2487 if (spell_attr != 0)
2488 {
2489 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2491 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002493 wlv.char_attr = hl_combine_attr(spell_attr,
2494 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495 }
2496#endif
2497#ifdef FEAT_LINEBREAK
2498 // Found last space before word: check for line break.
2499 if (wp->w_p_lbr && c0 == c
2500 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2501 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002502 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2503 : 0;
2504 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002505 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002507 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002508# ifdef FEAT_PROP_POPUP
2509 // do not want virtual text counted here
2510 cts.cts_has_prop_with_text = FALSE;
2511# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002513 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002514
2515 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002516 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002517 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002518 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002519 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2520 if (wlv.n_extra < 0)
2521 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002522 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002523 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002524 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002525 // line break, but for TABs the highlighting should
2526 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002527 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002528
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002532 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002533 wp->w_buffer->b_p_vts_array) - 1;
2534# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002535 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002536 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537# endif
2538
Bram Moolenaar1306b362022-08-06 15:59:06 +01002539 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2540 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002541# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002543 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002544# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 if (VIM_ISWHITE(c))
2546 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002547# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 if (c == TAB)
2549 // See "Tab alignment" below.
2550 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002551# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 if (!wp->w_p_list)
2553 c = ' ';
2554 }
2555 }
2556#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002557 in_multispace = c == ' '
2558 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2559 if (!in_multispace)
2560 multispace_pos = 0;
2561
Bram Moolenaareed9d462021-02-15 20:38:25 +01002562 // 'list': Change char 160 to 'nbsp' and space to 'space'
2563 // setting in 'listchars'. But not when the character is
2564 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 if (wp->w_p_list
2566 && ((((c == 160 && mb_l == 1)
2567 || (mb_utf8
2568 && ((mb_c == 160 && mb_l == 2)
2569 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002570 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 || (c == ' '
2572 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002573 && (wp->w_lcs_chars.space
2574 || (in_multispace
2575 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002576 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 && ptr - line <= trailcol)))
2578 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002579 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2580 {
2581 c = wp->w_lcs_chars.multispace[multispace_pos++];
2582 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2583 multispace_pos = 0;
2584 }
2585 else
2586 c = (c == ' ') ? wp->w_lcs_chars.space
2587 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588 if (area_attr == 0 && search_attr == 0)
2589 {
2590 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002591 extra_attr = hl_combine_attr(wlv.win_attr,
2592 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 }
2595 mb_c = c;
2596 if (enc_utf8 && utf_char2len(c) > 1)
2597 {
2598 mb_utf8 = TRUE;
2599 u8cc[0] = 0;
2600 c = 0xc0;
2601 }
2602 else
2603 mb_utf8 = FALSE;
2604 }
2605
zeertzjq2e7cba32022-06-10 15:30:32 +01002606 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2607 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002609 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2610 && wp->w_lcs_chars.leadmultispace != NULL)
2611 {
2612 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002613 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2614 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002615 multispace_pos = 0;
2616 }
2617
2618 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2619 c = wp->w_lcs_chars.trail;
2620
2621 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2622 c = wp->w_lcs_chars.lead;
2623
zeertzjq2e7cba32022-06-10 15:30:32 +01002624 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002625 c = wp->w_lcs_chars.space;
2626
2627
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 if (!attr_pri)
2629 {
2630 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002631 extra_attr = hl_combine_attr(wlv.win_attr,
2632 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 }
2635 mb_c = c;
2636 if (enc_utf8 && utf_char2len(c) > 1)
2637 {
2638 mb_utf8 = TRUE;
2639 u8cc[0] = 0;
2640 c = 0xc0;
2641 }
2642 else
2643 mb_utf8 = FALSE;
2644 }
2645 }
2646
2647 // Handling of non-printable characters.
2648 if (!vim_isprintc(c))
2649 {
2650 // when getting a character from the file, we may have to
2651 // turn it into something else on the way to putting it
2652 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002653 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 {
2655 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002656 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002658 char_u *sbr = get_showbreak_value(wp);
2659
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002660 // only adjust the tab_len, when at the first column
2661 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002662 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2663 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664#endif
2665 // tab amount depends on current column
2666#ifdef FEAT_VARTABS
2667 tab_len = tabstop_padding(vcol_adjusted,
2668 wp->w_buffer->b_p_ts,
2669 wp->w_buffer->b_p_vts_array) - 1;
2670#else
2671 tab_len = (int)wp->w_buffer->b_p_ts
2672 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2673#endif
2674
2675#ifdef FEAT_LINEBREAK
2676 if (!wp->w_p_lbr || !wp->w_p_list)
2677#endif
2678 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002679 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680#ifdef FEAT_LINEBREAK
2681 else
2682 {
2683 char_u *p;
2684 int len;
2685 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002688# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002689 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002691 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002692
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002694 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002695 && old_boguscols > 0
2696 && wlv.n_extra > tab_len)
2697 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002698# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002701 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002702 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002703 if (wp->w_lcs_chars.tab3)
2704 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 if (wlv.n_extra > 0)
2706 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002707 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002709 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002711 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002713 vim_memset(p, ' ', len);
2714 p[len] = NUL;
2715 vim_free(p_extra_free);
2716 p_extra_free = p;
2717 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002718 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002719 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002721 if (*p == NUL)
2722 {
2723 tab_len = i;
2724 break;
2725 }
2726
2727 // if tab3 is given, use it for the last char
2728 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2729 lcs = wp->w_lcs_chars.tab3;
2730 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002732 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002733 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002735# ifdef FEAT_CONCEAL
2736 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2737 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002738 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002739 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002740# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 }
2743#endif
2744#ifdef FEAT_CONCEAL
2745 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002746 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747
2748 // Tab alignment should be identical regardless of
2749 // 'conceallevel' value. So tab compensates of all
2750 // previous concealed characters, and thus resets
2751 // vcol_off and boguscols accumulated so far in the
2752 // line. Note that the tab can be longer than
2753 // 'tabstop' when there are concealed characters.
2754 FIX_FOR_BOGUSCOLS;
2755
2756 // Make sure, the highlighting for the tab char will be
2757 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002758 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002759 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002760 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761 tab_len += vc_saved;
2762 }
2763#endif
2764 mb_utf8 = FALSE; // don't draw as UTF-8
2765 if (wp->w_p_list)
2766 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002768 ? wp->w_lcs_chars.tab3
2769 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770#ifdef FEAT_LINEBREAK
2771 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002772 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002773 else
2774#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002775 wlv.c_extra = wp->w_lcs_chars.tab2;
2776 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002778 extra_attr = hl_combine_attr(wlv.win_attr,
2779 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 mb_c = c;
2782 if (enc_utf8 && utf_char2len(c) > 1)
2783 {
2784 mb_utf8 = TRUE;
2785 u8cc[0] = 0;
2786 c = 0xc0;
2787 }
2788 }
2789 else
2790 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002791 wlv.c_final = NUL;
2792 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 c = ' ';
2794 }
2795 }
2796 else if (c == NUL
2797 && (wp->w_p_list
2798 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002799 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 && VIsual_mode != Ctrl_V
2801 && (
2802# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002803 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002805 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 && !(noinvcur
2807 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002808 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 && lcs_eol_one > 0)
2810 {
2811 // Display a '$' after the line or highlight an extra
2812 // character if the line break is included.
2813#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2814 // For a diff line the highlighting continues after the
2815 // "$".
2816 if (
2817# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002818 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819# ifdef LINE_ATTR
2820 &&
2821# endif
2822# endif
2823# ifdef LINE_ATTR
2824 line_attr == 0
2825# endif
2826 )
2827#endif
2828 {
2829 // In virtualedit, visual selections may extend
2830 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002831 if (!(area_highlighting && virtual_active()
2832 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002833 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002834 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002836 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2837 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 else
2839 c = ' ';
2840 lcs_eol_one = -1;
2841 --ptr; // put it back at the NUL
2842 if (!attr_pri)
2843 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002844 extra_attr = hl_combine_attr(wlv.win_attr,
2845 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 n_attr = 1;
2847 }
2848 mb_c = c;
2849 if (enc_utf8 && utf_char2len(c) > 1)
2850 {
2851 mb_utf8 = TRUE;
2852 u8cc[0] = 0;
2853 c = 0xc0;
2854 }
2855 else
2856 mb_utf8 = FALSE; // don't draw as UTF-8
2857 }
2858 else if (c != NUL)
2859 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002860 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2861 if (wlv.n_extra == 0)
2862 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863#ifdef FEAT_RIGHTLEFT
2864 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 wlv.c_extra = NUL;
2868 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869#ifdef FEAT_LINEBREAK
2870 if (wp->w_p_lbr)
2871 {
2872 char_u *p;
2873
Bram Moolenaar1306b362022-08-06 15:59:06 +01002874 c = *wlv.p_extra;
2875 p = alloc(wlv.n_extra + 1);
2876 vim_memset(p, ' ', wlv.n_extra);
2877 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2878 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002880 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881 }
2882 else
2883#endif
2884 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002885 wlv.n_extra = byte2cells(c) - 1;
2886 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 }
2888 if (!attr_pri)
2889 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002890 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002891 extra_attr = hl_combine_attr(wlv.win_attr,
2892 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 }
2895 mb_utf8 = FALSE; // don't draw as UTF-8
2896 }
2897 else if (VIsual_active
2898 && (VIsual_mode == Ctrl_V
2899 || VIsual_mode == 'v')
2900 && virtual_active()
2901 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002902 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 && (
2904#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002905 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002907 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 {
2909 c = ' ';
2910 --ptr; // put it back at the NUL
2911 }
2912#if defined(LINE_ATTR)
2913 else if ((
2914# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002915 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916# endif
2917# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002918 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919# endif
2920 line_attr != 0
2921 ) && (
2922# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002923 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002924# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002925 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002927 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928# endif
2929 < wp->w_width)))
2930 {
2931 // Highlight until the right side of the window
2932 c = ' ';
2933 --ptr; // put it back at the NUL
2934
2935 // Remember we do the char for line highlighting.
2936 ++did_line_attr;
2937
2938 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002939 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002941 || (wp->w_p_list &&
2942 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002945 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002947 wlv.diff_hlf = HLF_CHD;
2948 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002949 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002950 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2952 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002953 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002954 || (wlv.vcol >= left_curline_col
2955 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 wlv.char_attr = hl_combine_attr(
2957 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 }
2959 }
2960# endif
2961# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002962 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002965 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2966 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 if (!wlv.cul_screenline
2969 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002970 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 wlv.char_attr = hl_combine_attr(
2972 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002973 }
2974 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2976 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 }
2978# endif
2979 }
2980#endif
2981 }
2982
2983#ifdef FEAT_CONCEAL
2984 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002985 && (wp != curwin || lnum != wp->w_cursor.lnum
2986 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2988 && !(lnum_in_visual_area
2989 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2990 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002991 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002992 if (((prev_syntax_id != syntax_seqnr
2993 && (syntax_flags & HL_CONCEAL) != 0)
2994 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002995 && (syn_get_sub_char() != NUL
2996 || (has_match_conc && match_conc)
2997 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 && wp->w_p_cole != 3)
2999 {
3000 // First time at this concealed item: display one
3001 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003002 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 c = match_conc;
3004 else if (syn_get_sub_char() != NUL)
3005 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003006 else if (wp->w_lcs_chars.conceal != NUL)
3007 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 else
3009 c = ' ';
3010
3011 prev_syntax_id = syntax_seqnr;
3012
Bram Moolenaar1306b362022-08-06 15:59:06 +01003013 if (wlv.n_extra > 0)
3014 wlv.vcol_off += wlv.n_extra;
3015 wlv.vcol += wlv.n_extra;
3016 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 {
3018# ifdef FEAT_RIGHTLEFT
3019 if (wp->w_p_rl)
3020 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003021 wlv.col -= wlv.n_extra;
3022 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 }
3024 else
3025# endif
3026 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003027 wlv.boguscols += wlv.n_extra;
3028 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 }
3030 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 n_attr = 0;
3033 }
3034 else if (n_skip == 0)
3035 {
3036 is_concealing = TRUE;
3037 n_skip = 1;
3038 }
3039 mb_c = c;
3040 if (enc_utf8 && utf_char2len(c) > 1)
3041 {
3042 mb_utf8 = TRUE;
3043 u8cc[0] = 0;
3044 c = 0xc0;
3045 }
3046 else
3047 mb_utf8 = FALSE; // don't draw as UTF-8
3048 }
3049 else
3050 {
3051 prev_syntax_id = 0;
3052 is_concealing = FALSE;
3053 }
3054
3055 if (n_skip > 0 && did_decrement_ptr)
3056 // not showing the '>', put pointer back to avoid getting stuck
3057 ++ptr;
3058
3059#endif // FEAT_CONCEAL
3060 }
3061
3062#ifdef FEAT_CONCEAL
3063 // In the cursor line and we may be concealing characters: correct
3064 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 && wp == curwin && lnum == wp->w_cursor.lnum
3067 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003068 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003070# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003072 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003074# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003075 wp->w_wcol = wlv.col - wlv.boguscols;
3076 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 did_wcol = TRUE;
3078 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003079# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003080 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003081# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003082 }
3083#endif
3084
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003085 // Use "extra_attr", but don't override visual selection highlighting,
3086 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003087 // Don't use "extra_attr" until n_attr_skip is zero.
3088 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003089 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003090 && (!attr_pri
3091#ifdef FEAT_PROP_POPUP
3092 || (text_prop_flags & PT_FLAG_OVERRIDE)
3093#endif
3094 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 {
3096#ifdef LINE_ATTR
3097 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003098 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 else
3100#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003101 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102 }
3103
3104#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3105 // XIM don't send preedit_start and preedit_end, but they send
3106 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3107 // im_is_preediting() here.
3108 if (p_imst == IM_ON_THE_SPOT
3109 && xic != NULL
3110 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003111 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 && !p_imdisable
3113 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003114 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115 {
3116 colnr_T tcol;
3117
3118 if (preedit_end_col == MAXCOL)
3119 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3120 else
3121 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003122 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 {
3124 if (feedback_old_attr < 0)
3125 {
3126 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003129 wlv.char_attr = im_get_feedback_attr(feedback_col);
3130 if (wlv.char_attr < 0)
3131 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 feedback_col++;
3133 }
3134 else if (feedback_old_attr >= 0)
3135 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003136 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137 feedback_old_attr = -1;
3138 feedback_col = 0;
3139 }
3140 }
3141#endif
3142 // Handle the case where we are in column 0 but not on the first
3143 // character of the line and the user wants us to show us a
3144 // special character (via 'listchars' option "precedes:<char>".
3145 if (lcs_prec_todo != NUL
3146 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003147 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003148 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003149 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150#ifdef FEAT_DIFF
3151 && filler_todo <= 0
3152#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 && c != NUL)
3155 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003156 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 lcs_prec_todo = NUL;
3158 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3159 {
3160 // Double-width character being overwritten by the "precedes"
3161 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003162 wlv.c_extra = MB_FILLER_CHAR;
3163 wlv.c_final = NUL;
3164 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003166 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 }
3168 mb_c = c;
3169 if (enc_utf8 && utf_char2len(c) > 1)
3170 {
3171 mb_utf8 = TRUE;
3172 u8cc[0] = 0;
3173 c = 0xc0;
3174 }
3175 else
3176 mb_utf8 = FALSE; // don't draw as UTF-8
3177 if (!attr_pri)
3178 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003179 saved_attr3 = wlv.char_attr; // save current attr
3180 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 n_attr3 = 1;
3182 }
3183 }
3184
3185 // At end of the text line or just after the last character.
3186 if ((c == NUL
3187#if defined(LINE_ATTR)
3188 || did_line_attr == 1
3189#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003190 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 {
3192#ifdef FEAT_SEARCH_EXTRA
3193 // flag to indicate whether prevcol equals startcol of search_hl or
3194 // one of the matches
3195 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3196 (long)(ptr - line) - (c == NUL));
3197#endif
3198 // Invert at least one char, used for Visual and empty line or
3199 // highlight match at end of line. If it's beyond the last
3200 // char on the screen, just overwrite that one (tricky!) Not
3201 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003202 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003203 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 && (VIsual_mode != Ctrl_V
3205 || lnum == VIsual.lnum
3206 || lnum == curwin->w_cursor.lnum)
3207 && c == NUL)
3208#ifdef FEAT_SEARCH_EXTRA
3209 // highlight 'hlsearch' match at end of line
3210 || (prevcol_hl_flag
3211# ifdef FEAT_SYN_HL
3212 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3213 && !(wp == curwin && VIsual_active))
3214# endif
3215# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003216 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217# endif
3218# if defined(LINE_ATTR)
3219 && did_line_attr <= 1
3220# endif
3221 )
3222#endif
3223 ))
3224 {
3225 int n = 0;
3226
3227#ifdef FEAT_RIGHTLEFT
3228 if (wp->w_p_rl)
3229 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003230 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 n = 1;
3232 }
3233 else
3234#endif
3235 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003236 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 n = -1;
3238 }
3239 if (n != 0)
3240 {
3241 // At the window boundary, highlight the last character
3242 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003243 wlv.off += n;
3244 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 }
3246 else
3247 {
3248 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 }
3253#ifdef FEAT_SEARCH_EXTRA
3254 if (area_attr == 0)
3255 {
3256 // Use attributes from match with highest priority among
3257 // 'search_hl' and the match list.
3258 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 }
3261#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003262 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003263 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264#ifdef FEAT_RIGHTLEFT
3265 if (wp->w_p_rl)
3266 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003267 --wlv.col;
3268 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 }
3270 else
3271#endif
3272 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 ++wlv.col;
3274 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003276 ++wlv.vcol;
3277 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 }
3279 }
3280
3281 // At end of the text line.
3282 if (c == NUL)
3283 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285
3286 // Update w_cline_height and w_cline_folded if the cursor line was
3287 // updated (saves a call to plines() later).
3288 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3289 {
3290 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292#ifdef FEAT_FOLDING
3293 curwin->w_cline_folded = FALSE;
3294#endif
3295 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3296 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 break;
3298 }
3299
3300 // Show "extends" character from 'listchars' if beyond the line end and
3301 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003302 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003303 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 && wp->w_p_list
3305 && !wp->w_p_wrap
3306#ifdef FEAT_DIFF
3307 && filler_todo <= 0
3308#endif
3309 && (
3310#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003311 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003313 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003315 || lcs_eol_one > 0
3316 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003317 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003319 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003320 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 mb_c = c;
3322 if (enc_utf8 && utf_char2len(c) > 1)
3323 {
3324 mb_utf8 = TRUE;
3325 u8cc[0] = 0;
3326 c = 0xc0;
3327 }
3328 else
3329 mb_utf8 = FALSE;
3330 }
3331
3332#ifdef FEAT_SYN_HL
3333 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003334 if (wlv.draw_color_col)
3335 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336
3337 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3338 // highlight the cursor position itself.
3339 // Also highlight the 'colorcolumn' if it is different than
3340 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003341 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3342 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003344 if (((wlv.draw_state == WL_LINE
3345 || wlv.draw_state == WL_BRI
3346 || wlv.draw_state == WL_SBR)
3347 && !lnum_in_visual_area
3348 && search_attr == 0
3349 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003350# ifdef FEAT_DIFF
3351 && filler_todo <= 0
3352# endif
3353 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354 {
3355 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3356 && lnum != wp->w_cursor.lnum)
3357 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003358 vcol_save_attr = wlv.char_attr;
3359 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3360 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003362 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003364 vcol_save_attr = wlv.char_attr;
3365 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 }
3367 }
3368#endif
3369
3370 // Store character to be displayed.
3371 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003372 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003373 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 {
3375 // Store the character.
3376#if defined(FEAT_RIGHTLEFT)
3377 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3378 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003379 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003380 --wlv.off;
3381 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 }
3383#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 if (enc_dbcs == DBCS_JPNU)
3386 {
3387 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003388 ScreenLines[wlv.off] = 0x8e;
3389 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003390 }
3391 else if (enc_utf8)
3392 {
3393 if (mb_utf8)
3394 {
3395 int i;
3396
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003397 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003399 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400 for (i = 0; i < Screen_mco; ++i)
3401 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003402 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 if (u8cc[i] == 0)
3404 break;
3405 }
3406 }
3407 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003408 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 }
3410 if (multi_attr)
3411 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 multi_attr = 0;
3414 }
3415 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003416 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003419
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3421 {
3422 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 ++wlv.off;
3424 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 if (enc_utf8)
3426 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 else
3429 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003430 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003431 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432#ifdef FEAT_DIFF
3433 && filler_todo <= 0
3434#endif
3435 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003436 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 // When "tocol" is halfway a character, set it to the end of
3438 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003439 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003441
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003442 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003443
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444#ifdef FEAT_RIGHTLEFT
3445 if (wp->w_p_rl)
3446 {
3447 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 --wlv.off;
3449 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 }
3451#endif
3452 }
3453#ifdef FEAT_RIGHTLEFT
3454 if (wp->w_p_rl)
3455 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003456 --wlv.off;
3457 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 }
3459 else
3460#endif
3461 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003462 ++wlv.off;
3463 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 }
3465 }
3466#ifdef FEAT_CONCEAL
3467 else if (wp->w_p_cole > 0 && is_concealing)
3468 {
3469 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003470 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003471 if (wlv.n_extra > 0)
3472 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 if (wp->w_p_wrap)
3474 {
3475 // Special voodoo required if 'wrap' is on.
3476 //
3477 // Advance the column indicator to force the line
3478 // drawing to wrap early. This will make the line
3479 // take up the same screen space when parts are concealed,
3480 // so that cursor line computations aren't messed up.
3481 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 // trailing junk to be written out of the screen line
3484 // we are building, 'boguscols' keeps track of the number
3485 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003486 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003488 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489# ifdef FEAT_RIGHTLEFT
3490 if (wp->w_p_rl)
3491 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003492 wlv.col -= wlv.n_extra;
3493 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 }
3495 else
3496# endif
3497 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003498 wlv.col += wlv.n_extra;
3499 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003500 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003501 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 n_attr = 0;
3503 }
3504
3505
3506 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3507 {
3508 // Need to fill two screen columns.
3509# ifdef FEAT_RIGHTLEFT
3510 if (wp->w_p_rl)
3511 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 --wlv.boguscols;
3513 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 }
3515 else
3516# endif
3517 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003518 ++wlv.boguscols;
3519 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 }
3521 }
3522
3523# ifdef FEAT_RIGHTLEFT
3524 if (wp->w_p_rl)
3525 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003526 --wlv.boguscols;
3527 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 }
3529 else
3530# endif
3531 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003532 ++wlv.boguscols;
3533 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 }
3535 }
3536 else
3537 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003540 wlv.vcol += wlv.n_extra;
3541 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 n_attr = 0;
3543 }
3544 }
3545
3546 }
3547#endif // FEAT_CONCEAL
3548 else
3549 --n_skip;
3550
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 // Only advance the "wlv.vcol" when after the 'number' or
3552 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554#ifdef FEAT_DIFF
3555 && filler_todo <= 0
3556#endif
3557 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003558 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559
3560#ifdef FEAT_SYN_HL
3561 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003562 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563#endif
3564
3565 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003566 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3567 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568
3569 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003570 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003571 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003572 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003573 if (n_attr_skip > 0)
3574 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575
3576 // At end of screen line and there is more to come: Display the line
3577 // so far. If there is no more to display it is caught above.
3578 if ((
3579#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003580 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003582 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003583 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003584 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585#ifdef FEAT_DIFF
3586 || filler_todo > 0
3587#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003588#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003589 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003590#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003591 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003592 && wlv.p_extra != at_end_str)
3593 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3594 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 )
3596 {
3597#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 screen_line(wp, wlv.screen_row, wp->w_wincol,
3599 wlv.col - wlv.boguscols,
3600 wp->w_width, wlv.screen_line_flags);
3601 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3604 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 ++wlv.row;
3607 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608
3609 // When not wrapping and finished diff lines, or when displayed
3610 // '$' and highlighting until last column, break here.
3611 if ((!wp->w_p_wrap
3612#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003613 && filler_todo <= 0
3614#endif
3615#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003616 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617#endif
3618 ) || lcs_eol_one == -1)
3619 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003620#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003621 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003622 {
3623 // do not output more of the line, only the "below" prop
3624 ptr += STRLEN(ptr);
3625# ifdef FEAT_LINEBREAK
3626 dont_use_showbreak = TRUE;
3627# endif
3628 }
3629#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630
3631 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633#ifdef FEAT_DIFF
3634 && filler_todo <= 0
3635#endif
3636 )
3637 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003638 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3639 draw_vsep_win(wp, wlv.row);
3640 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 }
3642
3643 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 break;
3648 }
3649
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651#ifdef FEAT_DIFF
3652 && filler_todo <= 0
3653#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003654#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003655 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003656#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657 && wp->w_width == Columns)
3658 {
3659 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003660 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661
3662 // Special trick to make copy/paste of wrapped lines work with
3663 // xterm/screen: write an extra character beyond the end of
3664 // the line. This will work with all terminal types
3665 // (regardless of the xn,am settings).
3666 // Only do this on a fast tty.
3667 // Only do this if the cursor is on the current line
3668 // (something has been written in it).
3669 // Don't do this for the GUI.
3670 // Don't do this for double-width characters.
3671 // Don't do this for a window not at the right screen border.
3672 if (p_tf
3673#ifdef FEAT_GUI
3674 && !gui.in_use
3675#endif
3676 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003677 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3678 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 || (*mb_off2cells)(
3681 LineOffset[wlv.screen_row - 1]
3682 + (int)Columns - 2,
3683 LineOffset[wlv.screen_row]
3684 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 {
3686 // First make sure we are at the end of the screen line,
3687 // then output the same character again to let the
3688 // terminal know about the wrap. If the terminal doesn't
3689 // auto-wrap, we overwrite the character.
3690 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003691 screen_char(LineOffset[wlv.screen_row - 1]
3692 + (unsigned)Columns - 1,
3693 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694
3695 // When there is a multi-byte character, just output a
3696 // space to keep it simple.
3697 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 out_char(' ');
3700 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003701 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 + (Columns - 1)]);
3703 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003704 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705 screen_start(); // don't know where cursor is now
3706 }
3707 }
3708
Bram Moolenaar1306b362022-08-06 15:59:06 +01003709 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710
Bram Moolenaareed9d462021-02-15 20:38:25 +01003711 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003713 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003715 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003717 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 need_showbreak = TRUE;
3719#endif
3720#ifdef FEAT_DIFF
3721 --filler_todo;
3722 // When the filler lines are actually below the last line of the
3723 // file, don't draw the line itself, break here.
3724 if (filler_todo == 0 && wp->w_botfill)
3725 break;
3726#endif
3727 }
3728
3729 } // for every character in the line
3730
3731#ifdef FEAT_SPELL
3732 // After an empty line check first word for capital.
3733 if (*skipwhite(line) == NUL)
3734 {
3735 capcol_lnum = lnum + 1;
3736 cap_col = 0;
3737 }
3738#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003739#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 vim_free(text_props);
3741 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003742 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743#endif
3744
3745 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003746 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747}