blob: 039a8c94d7d16e3535a641e00a7979c08531d45a [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 Moolenaarf396ce82022-08-23 18:39:37 +0100282 * Take care of padding, right-align and truncation of virtual text after a
283 * line.
284 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
285 * padding, right-align and truncation. Otherwise only the size is computed.
286 * When "n_attr" is NULL returns the number of screen cells used.
287 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100288 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100289 int
290text_prop_position(
291 win_T *wp,
292 textprop_T *tp,
293 int vcol, // current screen column
294 int *n_extra, // nr of bytes for virtual text
295 char_u **p_extra, // virtual text
296 int *n_attr, // attribute cells, NULL if not used
297 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100299 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
300 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
301 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
302 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
303 ? tp->tp_len - 1 : 0;
304 int col_with_padding = vcol + (below ? 0 : padding);
305 int room = wp->w_width - col_with_padding;
306 int added = room;
307 int n_used = *n_extra;
308 char_u *l = NULL;
309 int strsize = vim_strsize(*p_extra);
310 int cells = wrap ? strsize
311 : textprop_size_after_trunc(wp, below, added, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100313 if (wrap || right || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100314 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100315 // Right-align: fill with spaces
316 if (right)
317 added -= cells;
318 if (added < 0
319 || !(right || below)
320 || (below
321 ? (col_with_padding == 0 || !wp->w_p_wrap)
322 : (n_used < *n_extra)))
323 {
324 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
325 {
326 // right-align on next line instead of wrapping if possible
327 added = wp->w_width - strsize + room;
328 if (added < 0)
329 added = 0;
330 else
331 n_used = *n_extra;
332 }
333 else
334 added = 0;
335 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100336
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100337 // With 'nowrap' add one to show the "extends" character if needed (it
338 // doesn't show if the text just fits).
339 if (!wp->w_p_wrap
340 && n_used < *n_extra
341 && wp->w_lcs_chars.ext != NUL
342 && wp->w_p_list)
343 ++n_used;
344
345 // add 1 for NUL, 2 for when '…' is used
346 if (n_attr != NULL)
347 l = alloc(n_used + added + padding + 3);
348 if (n_attr == NULL || l != NULL)
349 {
350 int off = 0;
351
352 if (n_attr != NULL)
353 {
354 vim_memset(l, ' ', added);
355 off += added;
356 if (padding > 0)
357 {
358 vim_memset(l + off, ' ', padding);
359 off += padding;
360 }
361 vim_strncpy(l + off, *p_extra, n_used);
362 off += n_used;
363 }
364 else
365 {
366 off = added + padding + n_used;
367 cells += added + padding;
368 }
369 if (n_attr != NULL)
370 {
371 if (n_used < *n_extra && wp->w_p_wrap)
372 {
373 char_u *lp = l + off - 1;
374
375 if (has_mbyte)
376 {
377 // change last character to '…'
378 lp -= (*mb_head_off)(l, lp);
379 STRCPY(lp, "…");
380 n_used = lp - l + 3 - padding;
381 }
382 else
383 // change last character to '>'
384 *lp = '>';
385 }
386 *p_extra = l;
387 *n_extra = n_used + added + padding;
388 *n_attr = mb_charlen(*p_extra);
389 *n_attr_skip = added + padding;
390 }
391 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100392 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100393
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100394 if (n_attr == NULL)
395 return cells;
396 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200397}
398#endif
399
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100400/*
401 * Called when finished with the line: draw the screen line and handle any
402 * highlighting until the right of the window.
403 */
404 static void
405draw_screen_line(win_T *wp, winlinevars_T *wlv)
406{
407#ifdef FEAT_SYN_HL
408 long v;
409
410 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
411 if (wp->w_p_wrap)
412 v = wp->w_skipcol;
413 else
414 v = wp->w_leftcol;
415
416 // check if line ends before left margin
417 if (wlv->vcol < v + wlv->col - win_col_off(wp))
418 wlv->vcol = v + wlv->col - win_col_off(wp);
419# ifdef FEAT_CONCEAL
420 // Get rid of the boguscols now, we want to draw until the right
421 // edge for 'cursorcolumn'.
422 wlv->col -= wlv->boguscols;
423 wlv->boguscols = 0;
424# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
425# else
426# define VCOL_HLC (wlv->vcol)
427# endif
428
429 if (wlv->draw_color_col)
430 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
431
432 if (((wp->w_p_cuc
433 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
434 && (int)wp->w_virtcol <
435 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
436 && wlv->lnum != wp->w_cursor.lnum)
437 || wlv->draw_color_col
438 || wlv->win_attr != 0)
439# ifdef FEAT_RIGHTLEFT
440 && !wp->w_p_rl
441# endif
442 )
443 {
444 int rightmost_vcol = 0;
445 int i;
446
447 if (wp->w_p_cuc)
448 rightmost_vcol = wp->w_virtcol;
449 if (wlv->draw_color_col)
450 // determine rightmost colorcolumn to possibly draw
451 for (i = 0; wlv->color_cols[i] >= 0; ++i)
452 if (rightmost_vcol < wlv->color_cols[i])
453 rightmost_vcol = wlv->color_cols[i];
454
455 while (wlv->col < wp->w_width)
456 {
457 ScreenLines[wlv->off] = ' ';
458 if (enc_utf8)
459 ScreenLinesUC[wlv->off] = 0;
460 ScreenCols[wlv->off] = MAXCOL;
461 ++wlv->col;
462 if (wlv->draw_color_col)
463 wlv->draw_color_col = advance_color_col(
464 VCOL_HLC, &wlv->color_cols);
465
466 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
467 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
468 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
469 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
470 else
471 ScreenAttrs[wlv->off++] = wlv->win_attr;
472
473 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
474 break;
475
476 ++wlv->vcol;
477 }
478 }
479#endif
480
481 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
482 wp->w_width, wlv->screen_line_flags);
483 ++wlv->row;
484 ++wlv->screen_row;
485}
486#undef VCOL_HLC
487
488/*
489 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100490 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100491 */
492 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100493win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100494{
495 wlv->col = 0;
496 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
497
498#ifdef FEAT_RIGHTLEFT
499 if (wp->w_p_rl)
500 {
501 // Rightleft window: process the text in the normal direction, but put
502 // it in current_ScreenLine[] from right to left. Start at the
503 // rightmost column of the window.
504 wlv->col = wp->w_width - 1;
505 wlv->off += wlv->col;
506 wlv->screen_line_flags |= SLF_RIGHTLEFT;
507 }
508#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100509 if (save_extra)
510 {
511 // reset the drawing state for the start of a wrapped line
512 wlv->draw_state = WL_START;
513 wlv->saved_n_extra = wlv->n_extra;
514 wlv->saved_p_extra = wlv->p_extra;
515 wlv->saved_c_extra = wlv->c_extra;
516 wlv->saved_c_final = wlv->c_final;
517#ifdef FEAT_SYN_HL
518 if (!(wlv->cul_screenline
519# ifdef FEAT_DIFF
520 && wlv->diff_hlf == (hlf_T)0
521# endif
522 ))
523 wlv->saved_char_attr = wlv->char_attr;
524 else
525#endif
526 wlv->saved_char_attr = 0;
527 wlv->n_extra = 0;
528 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100529}
530
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200531/*
532 * Display line "lnum" of window 'wp' on the screen.
533 * Start at row "startrow", stop when "endrow" is reached.
534 * wp->w_virtcol needs to be valid.
535 *
536 * Return the number of last row the line occupies.
537 */
538 int
539win_line(
540 win_T *wp,
541 linenr_T lnum,
542 int startrow,
543 int endrow,
544 int nochange UNUSED, // not updating for changed text
545 int number_only) // only update the number column
546{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100547 winlinevars_T wlv; // variables passed between functions
548
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200549 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200550#ifdef FEAT_LINEBREAK
551 long vcol_sbr = -1; // virtual column after showbreak
552#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100553 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200554 char_u *line; // current line
555 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200556
557 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200558 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100559#ifdef FEAT_PROP_POPUP
560 char_u *p_extra_free2 = NULL; // another p_extra to be freed
561#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200562 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000563#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000564 int in_linebreak = FALSE; // n_extra set for showing linebreak
565#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200566 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100567 // displaying eol at end-of-line
568 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000569 int lcs_prec_todo = wp->w_lcs_chars.prec;
570 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200571
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100572 int n_attr = 0; // chars with special attr
573 int n_attr_skip = 0; // chars to skip before using extra_attr
574 int saved_attr2 = 0; // char_attr saved for n_attr
575 int n_attr3 = 0; // chars with overruling special attr
576 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200577
578 int n_skip = 0; // nr of chars to skip for 'nowrap'
579
580 int fromcol = -10; // start of inverting
581 int tocol = MAXCOL; // end of inverting
582 int fromcol_prev = -2; // start of inverting after cursor
583 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200584 int lnum_in_visual_area = FALSE;
585 pos_T pos;
586 long v;
587
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200588 int attr_pri = FALSE; // char_attr has priority
589 int area_highlighting = FALSE; // Visual or incsearch highlighting
590 // in this line
591 int vi_attr = 0; // attributes for Visual and incsearch
592 // highlighting
593 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200594 int area_attr = 0; // attributes desired by highlighting
595 int search_attr = 0; // attributes desired by 'hlsearch'
596#ifdef FEAT_SYN_HL
597 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
598 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200599 int prev_syntax_col = -1; // column of prev_syntax_attr
600 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200601 int has_syntax = FALSE; // this buffer has syntax highl.
602 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200603#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100604#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200605 int text_prop_count;
606 int text_prop_next = 0; // next text property to use
607 textprop_T *text_props = NULL;
608 int *text_prop_idxs = NULL;
609 int text_props_active = 0;
610 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100611 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200612 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100613 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100614 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100615 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100616 int saved_search_attr = 0; // search_attr to be used when n_extra
617 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200618#endif
619#ifdef FEAT_SPELL
620 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000621 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200622# define SPWORDLEN 150
623 char_u nextline[SPWORDLEN * 2];// text with start of the next line
624 int nextlinecol = 0; // column where nextline[] starts
625 int nextline_idx = 0; // index in nextline[] where next line
626 // starts
627 int spell_attr = 0; // attributes desired by spelling
628 int word_end = 0; // last byte with same spell_attr
629 static linenr_T checked_lnum = 0; // line number for "checked_col"
630 static int checked_col = 0; // column in "checked_lnum" up to which
631 // there are no spell errors
632 static int cap_col = -1; // column to check for Cap word
633 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
634 int cur_checked_col = 0; // checked column for current line
635#endif
636 int extra_check = 0; // has extra highlighting
637 int multi_attr = 0; // attributes desired by multibyte
638 int mb_l = 1; // multi-byte byte length
639 int mb_c = 0; // decoded multi-byte character
640 int mb_utf8 = FALSE; // screen char is UTF-8 char
641 int u8cc[MAX_MCO]; // composing UTF-8 chars
642#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
643 int filler_lines = 0; // nr of filler lines to be drawn
644 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000645#else
646# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200647#endif
648#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200649 int change_start = MAXCOL; // first col of changed area
650 int change_end = -1; // last col of changed area
651#endif
652 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100653 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200654 int in_multispace = FALSE; // in multiple consecutive spaces
655 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200656#ifdef FEAT_LINEBREAK
657 int need_showbreak = FALSE; // overlong line, skipping first x
658 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100659 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200660#endif
661#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
662 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
663# define LINE_ATTR
664 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100665 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200666#endif
667#ifdef FEAT_SIGNS
668 int sign_present = FALSE;
669 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000670 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200671#endif
672#ifdef FEAT_ARABIC
673 int prev_c = 0; // previous Arabic character
674 int prev_c1 = 0; // first composing char for prev_c
675#endif
676#if defined(LINE_ATTR)
677 int did_line_attr = 0;
678#endif
679#ifdef FEAT_TERMINAL
680 int get_term_attr = FALSE;
681#endif
682#ifdef FEAT_SYN_HL
683 int cul_attr = 0; // set when 'cursorline' active
684
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200685 // margin columns for the screen line, needed for when 'cursorlineopt'
686 // contains "screenline"
687 int left_curline_col = 0;
688 int right_curline_col = 0;
689#endif
690
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200691#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
692 int feedback_col = 0;
693 int feedback_old_attr = -1;
694#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200695
696#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
697 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000698 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200699#endif
700#ifdef FEAT_CONCEAL
701 int syntax_flags = 0;
702 int syntax_seqnr = 0;
703 int prev_syntax_id = 0;
704 int conceal_attr = HL_ATTR(HLF_CONCEAL);
705 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200706 int did_wcol = FALSE;
707 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100708# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200709# define FIX_FOR_BOGUSCOLS \
710 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100711 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100712 wlv.vcol -= wlv.vcol_off; \
713 wlv.vcol_off = 0; \
714 wlv.col -= wlv.boguscols; \
715 old_boguscols = wlv.boguscols; \
716 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200717 }
718#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100719# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200720#endif
721
722 if (startrow > endrow) // past the end already!
723 return startrow;
724
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100725 CLEAR_FIELD(wlv);
726
727 wlv.lnum = lnum;
728 wlv.startrow = startrow;
729 wlv.row = startrow;
730 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200731
732 if (!number_only)
733 {
734 // To speed up the loop below, set extra_check when there is linebreak,
735 // trailing white space and/or syntax processing to be done.
736#ifdef FEAT_LINEBREAK
737 extra_check = wp->w_p_lbr;
738#endif
739#ifdef FEAT_SYN_HL
740 if (syntax_present(wp) && !wp->w_s->b_syn_error
741# ifdef SYN_TIME_LIMIT
742 && !wp->w_s->b_syn_slow
743# endif
744 )
745 {
746 // Prepare for syntax highlighting in this line. When there is an
747 // error, stop syntax highlighting.
748 save_did_emsg = did_emsg;
749 did_emsg = FALSE;
750 syntax_start(wp, lnum);
751 if (did_emsg)
752 wp->w_s->b_syn_error = TRUE;
753 else
754 {
755 did_emsg = save_did_emsg;
756#ifdef SYN_TIME_LIMIT
757 if (!wp->w_s->b_syn_slow)
758#endif
759 {
760 has_syntax = TRUE;
761 extra_check = TRUE;
762 }
763 }
764 }
765
766 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100767 wlv.color_cols = wp->w_p_cc_cols;
768 if (wlv.color_cols != NULL)
769 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200770#endif
771
772#ifdef FEAT_TERMINAL
773 if (term_show_buffer(wp->w_buffer))
774 {
775 extra_check = TRUE;
776 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100777 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200778 }
779#endif
780
781#ifdef FEAT_SPELL
782 if (wp->w_p_spell
783 && *wp->w_s->b_p_spl != NUL
784 && wp->w_s->b_langp.ga_len > 0
785 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
786 {
787 // Prepare for spell checking.
788 has_spell = TRUE;
789 extra_check = TRUE;
790
791 // Get the start of the next line, so that words that wrap to the
792 // next line are found too: "et<line-break>al.".
793 // Trick: skip a few chars for C/shell/Vim comments
794 nextline[SPWORDLEN] = NUL;
795 if (lnum < wp->w_buffer->b_ml.ml_line_count)
796 {
797 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
798 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
799 }
800
801 // When a word wrapped from the previous line the start of the
802 // current line is valid.
803 if (lnum == checked_lnum)
804 cur_checked_col = checked_col;
805 checked_lnum = 0;
806
807 // When there was a sentence end in the previous line may require a
808 // word starting with capital in this line. In line 1 always check
809 // the first word.
810 if (lnum != capcol_lnum)
811 cap_col = -1;
812 if (lnum == 1)
813 cap_col = 0;
814 capcol_lnum = 0;
815 }
816#endif
817
818 // handle Visual active in this window
819 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
820 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100821 pos_T *top, *bot;
822
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200823 if (LTOREQ_POS(curwin->w_cursor, VIsual))
824 {
825 // Visual is after curwin->w_cursor
826 top = &curwin->w_cursor;
827 bot = &VIsual;
828 }
829 else
830 {
831 // Visual is before curwin->w_cursor
832 top = &VIsual;
833 bot = &curwin->w_cursor;
834 }
835 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
836 if (VIsual_mode == Ctrl_V)
837 {
838 // block mode
839 if (lnum_in_visual_area)
840 {
841 fromcol = wp->w_old_cursor_fcol;
842 tocol = wp->w_old_cursor_lcol;
843 }
844 }
845 else
846 {
847 // non-block mode
848 if (lnum > top->lnum && lnum <= bot->lnum)
849 fromcol = 0;
850 else if (lnum == top->lnum)
851 {
852 if (VIsual_mode == 'V') // linewise
853 fromcol = 0;
854 else
855 {
856 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
857 if (gchar_pos(top) == NUL)
858 tocol = fromcol + 1;
859 }
860 }
861 if (VIsual_mode != 'V' && lnum == bot->lnum)
862 {
863 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
864 {
865 fromcol = -10;
866 tocol = MAXCOL;
867 }
868 else if (bot->col == MAXCOL)
869 tocol = MAXCOL;
870 else
871 {
872 pos = *bot;
873 if (*p_sel == 'e')
874 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
875 else
876 {
877 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
878 ++tocol;
879 }
880 }
881 }
882 }
883
884 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200885 if (!highlight_match && lnum == curwin->w_cursor.lnum
886 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200887#ifdef FEAT_GUI
888 && !gui.in_use
889#endif
890 )
891 noinvcur = TRUE;
892
893 // if inverting in this line set area_highlighting
894 if (fromcol >= 0)
895 {
896 area_highlighting = TRUE;
897 vi_attr = HL_ATTR(HLF_V);
898#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
899 if ((clip_star.available && !clip_star.owned
900 && clip_isautosel_star())
901 || (clip_plus.available && !clip_plus.owned
902 && clip_isautosel_plus()))
903 vi_attr = HL_ATTR(HLF_VNC);
904#endif
905 }
906 }
907
908 // handle 'incsearch' and ":s///c" highlighting
909 else if (highlight_match
910 && wp == curwin
911 && lnum >= curwin->w_cursor.lnum
912 && lnum <= curwin->w_cursor.lnum + search_match_lines)
913 {
914 if (lnum == curwin->w_cursor.lnum)
915 getvcol(curwin, &(curwin->w_cursor),
916 (colnr_T *)&fromcol, NULL, NULL);
917 else
918 fromcol = 0;
919 if (lnum == curwin->w_cursor.lnum + search_match_lines)
920 {
921 pos.lnum = lnum;
922 pos.col = search_match_endcol;
923 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
924 }
925 else
926 tocol = MAXCOL;
927 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100928 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200929 tocol = fromcol + 1;
930 area_highlighting = TRUE;
931 vi_attr = HL_ATTR(HLF_I);
932 }
933 }
934
935#ifdef FEAT_DIFF
936 filler_lines = diff_check(wp, lnum);
937 if (filler_lines < 0)
938 {
939 if (filler_lines == -1)
940 {
941 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100942 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200943 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100944 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200945 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100946 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 }
948 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100949 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200950 filler_lines = 0;
951 area_highlighting = TRUE;
952 }
953 if (lnum == wp->w_topline)
954 filler_lines = wp->w_topfill;
955 filler_todo = filler_lines;
956#endif
957
958#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100959 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000960 if (sign_present)
961 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200962#endif
963
964#ifdef LINE_ATTR
965# ifdef FEAT_SIGNS
966 // If this line has a sign with line highlighting set line_attr.
967 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200968 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200969# endif
970# if defined(FEAT_QUICKFIX)
971 // Highlight the current line in the quickfix window.
972 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
973 line_attr = HL_ATTR(HLF_QFL);
974# endif
975 if (line_attr != 0)
976 area_highlighting = TRUE;
977#endif
978
979 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
980 ptr = line;
981
982#ifdef FEAT_SPELL
983 if (has_spell && !number_only)
984 {
985 // For checking first word with a capital skip white space.
986 if (cap_col == 0)
987 cap_col = getwhitecols(line);
988
989 // To be able to spell-check over line boundaries copy the end of the
990 // current line into nextline[]. Above the start of the next line was
991 // copied to nextline[SPWORDLEN].
992 if (nextline[SPWORDLEN] == NUL)
993 {
994 // No next line or it is empty.
995 nextlinecol = MAXCOL;
996 nextline_idx = 0;
997 }
998 else
999 {
1000 v = (long)STRLEN(line);
1001 if (v < SPWORDLEN)
1002 {
1003 // Short line, use it completely and append the start of the
1004 // next line.
1005 nextlinecol = 0;
1006 mch_memmove(nextline, line, (size_t)v);
1007 STRMOVE(nextline + v, nextline + SPWORDLEN);
1008 nextline_idx = v + 1;
1009 }
1010 else
1011 {
1012 // Long line, use only the last SPWORDLEN bytes.
1013 nextlinecol = v - SPWORDLEN;
1014 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1015 nextline_idx = SPWORDLEN + 1;
1016 }
1017 }
1018 }
1019#endif
1020
1021 if (wp->w_p_list)
1022 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001023 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001024 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001025 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001026 || wp->w_lcs_chars.trail
1027 || wp->w_lcs_chars.lead
1028 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001030
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001032 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 {
1034 trailcol = (colnr_T)STRLEN(ptr);
1035 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1036 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001037 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001039 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001040 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001041 {
1042 leadcol = 0;
1043 while (VIM_ISWHITE(ptr[leadcol]))
1044 ++leadcol;
1045 if (ptr[leadcol] == NUL)
1046 // in a line full of spaces all of them are treated as trailing
1047 leadcol = (colnr_T)0;
1048 else
1049 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001050 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001051 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052 }
1053
1054 wcr_attr = get_wcr_attr(wp);
1055 if (wcr_attr != 0)
1056 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001057 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058 area_highlighting = TRUE;
1059 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001060
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001061#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001063 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064#endif
1065
1066 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1067 // first character to be displayed.
1068 if (wp->w_p_wrap)
1069 v = wp->w_skipcol;
1070 else
1071 v = wp->w_leftcol;
1072 if (v > 0 && !number_only)
1073 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001074 char_u *prev_ptr = ptr;
1075 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001076 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001078 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001079 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001081 charsize = win_lbr_chartabsize(&cts, NULL);
1082 cts.cts_vcol += charsize;
1083 prev_ptr = cts.cts_ptr;
1084 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001086 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001087 ptr = cts.cts_ptr;
1088 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089
1090 // When:
1091 // - 'cuc' is set, or
1092 // - 'colorcolumn' is set, or
1093 // - 'virtualedit' is set, or
1094 // - the visual mode is active,
1095 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001096 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001097#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001098 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099#endif
1100 virtual_active() ||
1101 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001102 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103
1104 // Handle a character that's not completely on the screen: Put ptr at
1105 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001106 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001108 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 ptr = prev_ptr;
1110 // If the character fits on the screen, don't need to skip it.
1111 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001112 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1113 && wlv.col == 0)
1114 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115 }
1116
1117 // Adjust for when the inverted text is before the screen,
1118 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001119 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001121 else if (fromcol >= 0 && fromcol < wlv.vcol)
1122 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123
1124#ifdef FEAT_LINEBREAK
1125 // When w_skipcol is non-zero, first line needs 'showbreak'
1126 if (wp->w_p_wrap)
1127 need_showbreak = TRUE;
1128#endif
1129#ifdef FEAT_SPELL
1130 // When spell checking a word we need to figure out the start of the
1131 // word and if it's badly spelled or not.
1132 if (has_spell)
1133 {
1134 int len;
1135 colnr_T linecol = (colnr_T)(ptr - line);
1136 hlf_T spell_hlf = HLF_COUNT;
1137
1138 pos = wp->w_cursor;
1139 wp->w_cursor.lnum = lnum;
1140 wp->w_cursor.col = linecol;
1141 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1142
1143 // spell_move_to() may call ml_get() and make "line" invalid
1144 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1145 ptr = line + linecol;
1146
1147 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1148 {
1149 // no bad word found at line start, don't check until end of a
1150 // word
1151 spell_hlf = HLF_COUNT;
1152 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1153 }
1154 else
1155 {
1156 // bad word found, use attributes until end of word
1157 word_end = wp->w_cursor.col + len + 1;
1158
1159 // Turn index into actual attributes.
1160 if (spell_hlf != HLF_COUNT)
1161 spell_attr = highlight_attr[spell_hlf];
1162 }
1163 wp->w_cursor = pos;
1164
1165# ifdef FEAT_SYN_HL
1166 // Need to restart syntax highlighting for this line.
1167 if (has_syntax)
1168 syntax_start(wp, lnum);
1169# endif
1170 }
1171#endif
1172 }
1173
1174 // Correct highlighting for cursor that can't be disabled.
1175 // Avoids having to check this for each character.
1176 if (fromcol >= 0)
1177 {
1178 if (noinvcur)
1179 {
1180 if ((colnr_T)fromcol == wp->w_virtcol)
1181 {
1182 // highlighting starts at cursor, let it start just after the
1183 // cursor
1184 fromcol_prev = fromcol;
1185 fromcol = -1;
1186 }
1187 else if ((colnr_T)fromcol < wp->w_virtcol)
1188 // restart highlighting after the cursor
1189 fromcol_prev = wp->w_virtcol;
1190 }
1191 if (fromcol >= tocol)
1192 fromcol = -1;
1193 }
1194
1195#ifdef FEAT_SEARCH_EXTRA
1196 if (!number_only)
1197 {
1198 v = (long)(ptr - line);
1199 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1200 &line, &screen_search_hl,
1201 &search_attr);
1202 ptr = line + v; // "line" may have been updated
1203 }
1204#endif
1205
1206#ifdef FEAT_SYN_HL
1207 // Cursor line highlighting for 'cursorline' in the current window.
1208 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1209 {
1210 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001211 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212 if (!(wp == curwin && VIsual_active)
1213 && wp->w_p_culopt_flags != CULOPT_NBR)
1214 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001215 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1217
1218 // Only set line_attr here when "screenline" is not present in
1219 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001220 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 {
1222 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001223# ifdef FEAT_SIGNS
1224 // Combine the 'cursorline' and sign highlighting, depending on
1225 // the sign priority.
1226 if (sign_present && sattr.sat_linehl > 0)
1227 {
1228 if (sattr.sat_priority >= 100)
1229 line_attr = hl_combine_attr(cul_attr, line_attr);
1230 else
1231 line_attr = hl_combine_attr(line_attr, cul_attr);
1232 }
1233 else
1234# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001235# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001236 // let the line attribute overrule 'cursorline', otherwise
1237 // it disappears when both have background set;
1238 // 'cursorline' can use underline or bold to make it show
1239 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001240# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001241 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001242# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 }
1244 else
1245 {
1246 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1248 }
1249 area_highlighting = TRUE;
1250 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 }
1252#endif
1253
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001254#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 {
1256 char_u *prop_start;
1257
1258 text_prop_count = get_text_props(wp->w_buffer, lnum,
1259 &prop_start, FALSE);
1260 if (text_prop_count > 0)
1261 {
1262 // Make a copy of the properties, so that they are properly
1263 // aligned.
1264 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1265 if (text_props != NULL)
1266 mch_memmove(text_props, prop_start,
1267 text_prop_count * sizeof(textprop_T));
1268
1269 // Allocate an array for the indexes.
1270 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001271 if (text_prop_idxs == NULL)
1272 VIM_CLEAR(text_props);
1273
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 area_highlighting = TRUE;
1275 extra_check = TRUE;
1276 }
1277 }
1278#endif
1279
Bram Moolenaar1306b362022-08-06 15:59:06 +01001280 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281
1282 // Repeat for the whole displayed line.
1283 for (;;)
1284 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001285 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001287 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288#endif
1289#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001290 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001292
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001294 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001296#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001297 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001298 {
1299 cul_attr = 0;
1300 line_attr = line_attr_save;
1301 }
1302#endif
1303
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001305 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001307 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 if (cmdwin_type != 0 && wp == curwin)
1309 {
1310 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001311 wlv.n_extra = 1;
1312 wlv.c_extra = cmdwin_type;
1313 wlv.c_final = NUL;
1314 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 }
1316 }
1317#endif
1318
1319#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001320 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 {
1322 int fdc = compute_foldcolumn(wp, 0);
1323
Bram Moolenaar1306b362022-08-06 15:59:06 +01001324 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 if (fdc > 0)
1326 {
1327 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1328 // already be in use.
1329 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001330 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331 if (p_extra_free != NULL)
1332 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001333 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001334 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001335 p_extra_free[wlv.n_extra] = NUL;
1336 wlv.p_extra = p_extra_free;
1337 wlv.c_extra = NUL;
1338 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001339 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001340 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001341 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1342 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001343 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001344 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 }
1346 }
1347 }
1348#endif
1349
1350#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001351 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001353 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 // Show the sign column when there are any signs in this
1355 // buffer or when using Netbeans.
1356 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001357 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1358 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 }
1360#endif
1361
Bram Moolenaar1306b362022-08-06 15:59:06 +01001362 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001364 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 // Display the absolute or relative line number. After the
1366 // first fill with blanks when the 'n' flag isn't in 'cpo'
1367 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001368 && (wlv.row == startrow + filler_lines
1369 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 {
1371#ifdef FEAT_SIGNS
1372 // If 'signcolumn' is set to 'number' and a sign is present
1373 // in 'lnum', then display the sign instead of the line
1374 // number.
1375 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1376 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001377 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1378 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 else
1380#endif
1381 {
1382 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001383 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 {
1385 long num;
1386 char *fmt = "%*ld ";
1387
1388 if (wp->w_p_nu && !wp->w_p_rnu)
1389 // 'number' + 'norelativenumber'
1390 num = (long)lnum;
1391 else
1392 {
1393 // 'relativenumber', don't use negative numbers
1394 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1395 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1396 {
1397 // 'number' + 'relativenumber'
1398 num = lnum;
1399 fmt = "%-*ld ";
1400 }
1401 }
1402
1403 sprintf((char *)extra, fmt,
1404 number_width(wp), num);
1405 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001406 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1407 ++wlv.p_extra)
1408 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409#ifdef FEAT_RIGHTLEFT
1410 if (wp->w_p_rl) // reverse line numbers
1411 {
1412 char_u *p1, *p2;
1413 int t;
1414
1415 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001416 p2 = skipwhite(extra);
1417 p2 = skiptowhite(p2) - 1;
1418 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 {
1420 t = *p1;
1421 *p1 = *p2;
1422 *p2 = t;
1423 }
1424 }
1425#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001426 wlv.p_extra = extra;
1427 wlv.c_extra = NUL;
1428 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 }
1430 else
1431 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001432 wlv.c_extra = ' ';
1433 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001435 wlv.n_extra = number_width(wp) + 1;
1436 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437#ifdef FEAT_SYN_HL
1438 // When 'cursorline' is set highlight the line number of
1439 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001440 // When 'cursorlineopt' does not have "line" only
1441 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 // TODO: Can we use CursorLine instead of CursorLineNr
1443 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001444 if (wp->w_p_cul
1445 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001447 && (wlv.row == startrow + filler_lines
1448 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001449 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001450 wlv.char_attr = hl_combine_attr(wcr_attr,
1451 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001453 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1454 && HL_ATTR(HLF_LNA) != 0)
1455 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001456 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001457 HL_ATTR(HLF_LNA));
1458 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1459 && HL_ATTR(HLF_LNB) != 0)
1460 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001461 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001462 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 }
James McCoya80aad72021-12-22 19:45:28 +00001464#ifdef FEAT_SIGNS
1465 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001466 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001467#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 }
1469 }
1470
1471#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001472 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1473 && wlv.n_extra == 0
1474 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001476 wlv.draw_state = WL_BRI;
1477 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1478 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001480 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481
1482 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001483 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001485 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001487 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488# ifdef FEAT_DIFF
1489 && filler_lines == 0
1490# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001491# ifdef FEAT_PROP_POPUP
1492 && !dont_use_showbreak
1493# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 )
1495 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001496 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001498 if (wlv.diff_hlf != (hlf_T)0)
1499 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001501 wlv.p_extra = NULL;
1502 wlv.c_extra = ' ';
1503 wlv.c_final = NUL;
1504 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001506 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001507 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001508 wlv.n_extra -= win_col_off2(wp);
1509 if (wlv.n_extra < 0)
1510 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001511 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001512 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001513 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001514 // Correct end of highlighted area for 'breakindent',
1515 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001516 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001517 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 }
1519 }
1520#endif
1521
1522#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001523 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001525 char_u *sbr;
1526
Bram Moolenaar1306b362022-08-06 15:59:06 +01001527 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528# ifdef FEAT_DIFF
1529 if (filler_todo > 0)
1530 {
1531 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001532 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001534 wlv.c_extra = '-';
1535 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536 }
1537 else
1538 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001539 wlv.c_extra = wp->w_fill_chars.diff;
1540 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541 }
1542# ifdef FEAT_RIGHTLEFT
1543 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001544 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 else
1546# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001547 wlv.n_extra = wp->w_width - wlv.col;
1548 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 }
1550# endif
1551# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001552 sbr = get_showbreak_value(wp);
1553 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554 {
1555 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001556 wlv.p_extra = sbr;
1557 wlv.c_extra = NUL;
1558 wlv.c_final = NUL;
1559 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001560 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1561 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001562 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563 // Correct end of highlighted area for 'showbreak',
1564 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001565 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001566 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001568 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1569 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570# ifdef FEAT_SYN_HL
1571 // combine 'showbreak' with 'cursorline'
1572 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001573 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1574 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001575# endif
1576 }
1577# endif
1578 }
1579#endif
1580
Bram Moolenaar1306b362022-08-06 15:59:06 +01001581 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001583 wlv.draw_state = WL_LINE;
1584 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 {
1586 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001587 wlv.n_extra = wlv.saved_n_extra;
1588 wlv.c_extra = wlv.saved_c_extra;
1589 wlv.c_final = wlv.saved_c_final;
1590 wlv.p_extra = wlv.saved_p_extra;
1591 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 }
1593 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001594 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 }
1596 }
1597#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001598 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001599 && wlv.vcol >= left_curline_col
1600 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001602 cul_attr = HL_ATTR(HLF_CUL);
1603 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 }
1605#endif
1606
1607 // When still displaying '$' of change command, stop at cursor.
1608 // When only displaying the (relative) line number and that's done,
1609 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001610 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001611 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001612 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613#ifdef FEAT_DIFF
1614 && filler_todo <= 0
1615#endif
1616 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001618 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1619 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 // Pretend we have finished updating the window. Except when
1621 // 'cursorcolumn' is set.
1622#ifdef FEAT_SYN_HL
1623 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001624 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625 else
1626#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001627 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 break;
1629 }
1630
Bram Moolenaar1306b362022-08-06 15:59:06 +01001631 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 {
1633 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001634 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001635 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636 && (*mb_ptr2cells)(ptr) > 1)
1637 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001638 && vcol_prev < wlv.vcol // not at margin
1639 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640 area_attr = vi_attr; // start highlighting
1641 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001642 && (wlv.vcol == tocol
1643 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 area_attr = 0; // stop highlighting
1645
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001646#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 if (text_props != NULL)
1648 {
1649 int pi;
1650 int bcol = (int)(ptr - line);
1651
Bram Moolenaar1306b362022-08-06 15:59:06 +01001652 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001653# ifdef FEAT_LINEBREAK
1654 && !in_linebreak
1655# endif
1656 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 --bcol; // still working on the previous char, e.g. Tab
1658
1659 // Check if any active property ends.
1660 for (pi = 0; pi < text_props_active; ++pi)
1661 {
1662 int tpi = text_prop_idxs[pi];
1663
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001664 if (text_props[tpi].tp_col != MAXCOL
1665 && bcol >= text_props[tpi].tp_col - 1
1666 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667 {
1668 if (pi + 1 < text_props_active)
1669 mch_memmove(text_prop_idxs + pi,
1670 text_prop_idxs + pi + 1,
1671 sizeof(int)
1672 * (text_props_active - (pi + 1)));
1673 --text_props_active;
1674 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001675# ifdef FEAT_LINEBREAK
1676 // not exactly right but should work in most cases
1677 if (in_linebreak && syntax_attr == text_prop_attr)
1678 syntax_attr = 0;
1679# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 }
1681 }
1682
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001683# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001684 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001685 // not on the next char yet, don't start another prop
1686 --bcol;
1687# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001689 // With 'nowrap' and not in the first screen line only "below"
1690 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001692 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001693 ? (*ptr == NUL
1694 && (wp->w_p_wrap
1695 || wlv.row == startrow
1696 || (text_props[text_prop_next].tp_flags
1697 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001698 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001699 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001700 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001701 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1702 {
1703 // first display the '$' after the line
1704 text_prop_follows = TRUE;
1705 break;
1706 }
1707 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001708 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001709 + text_props[text_prop_next].tp_len)
1710 text_prop_idxs[text_props_active++] = text_prop_next;
1711 ++text_prop_next;
1712 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001714 if (wlv.n_extra == 0 || !extra_for_textprop)
1715 {
1716 text_prop_attr = 0;
1717 text_prop_flags = 0;
1718 text_prop_type = NULL;
1719 text_prop_id = 0;
1720 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001721 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001723 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001724 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001725 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001726
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 // Sort the properties on priority and/or starting last.
1728 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001729 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001730 sort_text_props(wp->w_buffer, text_props,
1731 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732
1733 for (pi = 0; pi < text_props_active; ++pi)
1734 {
1735 int tpi = text_prop_idxs[pi];
1736 proptype_T *pt = text_prop_type_by_id(
1737 wp->w_buffer, text_props[tpi].tp_type);
1738
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001739 if (pt != NULL && (pt->pt_hl_id > 0
1740 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001741 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001743 if (pt->pt_hl_id > 0)
1744 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 text_prop_type = pt;
1746 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001747 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001748 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001749 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001750 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001751 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 }
1753 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001754 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001755 && -text_prop_id
1756 <= wp->w_buffer->b_textprop_text.ga_len)
1757 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001758 textprop_T *tp = &text_props[used_tpi];
1759 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001760 ->b_textprop_text.ga_data)[
1761 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001762
1763 // reset the ID in the copy to avoid it being used
1764 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001765 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001766
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001767 if (p != NULL)
1768 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001769 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001770 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001771 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001772 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001773 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1774 int padding = tp->tp_col == MAXCOL
1775 && tp->tp_len > 1
1776 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001777
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001778 // Insert virtual text before the current
1779 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001780 wlv.p_extra = p;
1781 wlv.c_extra = NUL;
1782 wlv.c_final = NUL;
1783 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001784 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001785 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001786 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001787 saved_search_attr = search_attr;
1788 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001789 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001790 if (*ptr == NUL)
1791 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001792 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001793#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001794 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001795 {
1796 // no 'showbreak' before "below" text property
1797 // or after "right" text property
1798 need_showbreak = FALSE;
1799 dont_use_showbreak = TRUE;
1800 }
1801#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001802 // Keep in sync with where
1803 // textprop_size_after_trunc() is called in
1804 // win_lbr_chartabsize().
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001805 if ((right || below || !wrap || padding > 0)
1806 && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001807 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001808 char_u *prev_p_extra = wlv.p_extra;
1809 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001810
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001811 // Take care of padding, right-align and
1812 // truncation.
1813 // Shared with win_lbr_chartabsize(), must do
1814 // exactly the same.
1815 start_line = text_prop_position(wp, tp,
1816 wlv.col,
1817 &wlv.n_extra, &wlv.p_extra,
1818 &n_attr, &n_attr_skip);
1819 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001820 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001821 // wlv.p_extra was allocated
1822 vim_free(p_extra_free2);
1823 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001824 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001825
1826 // When 'wrap' is off then for "below" we need
1827 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001828 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001829 {
1830 draw_screen_line(wp, &wlv);
1831
1832 // When line got too long for screen break
1833 // here.
1834 if (wlv.row == endrow)
1835 {
1836 ++wlv.row;
1837 break;
1838 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001839 win_line_start(wp, &wlv, TRUE);
1840 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001841 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001842 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001843 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001844
1845 // If another text prop follows the condition below at
1846 // the last window column must know.
1847 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001848 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001850 else if (text_prop_next < text_prop_count
1851 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001852 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1853 || (!wp->w_p_wrap
1854 && wlv.col == wp->w_width - 1
1855 && (text_props[text_prop_next].tp_flags
1856 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001857 // When at last-but-one character and a text property
1858 // follows after it, we may need to flush the line after
1859 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001860 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001861 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 }
1863#endif
1864
Bram Moolenaare38fc862022-08-11 17:24:50 +01001865#ifdef FEAT_SEARCH_EXTRA
1866 if (wlv.n_extra == 0)
1867 {
1868 // Check for start/end of 'hlsearch' and other matches.
1869 // After end, check for start/end of next match.
1870 // When another match, have to check for start again.
1871 v = (long)(ptr - line);
1872 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1873 &screen_search_hl, &has_match_conc,
1874 &match_conc, did_line_attr, lcs_eol_one,
1875 &on_last_col);
1876 ptr = line + v; // "line" may have been changed
1877 prev_ptr = ptr;
1878
1879 // Do not allow a conceal over EOL otherwise EOL will be missed
1880 // and bad things happen.
1881 if (*ptr == NUL)
1882 has_match_conc = 0;
1883 }
1884#endif
1885
1886#ifdef FEAT_DIFF
1887 if (wlv.diff_hlf != (hlf_T)0)
1888 {
1889 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1890 && wlv.n_extra == 0)
1891 wlv.diff_hlf = HLF_TXD; // changed text
1892 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1893 && wlv.n_extra == 0)
1894 wlv.diff_hlf = HLF_CHD; // changed line
1895 line_attr = HL_ATTR(wlv.diff_hlf);
1896 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1897 && wp->w_p_culopt_flags != CULOPT_NBR
1898 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1899 && wlv.vcol <= right_curline_col)))
1900 line_attr = hl_combine_attr(
1901 line_attr, HL_ATTR(HLF_CUL));
1902 }
1903#endif
1904
Bram Moolenaara74fda62019-10-19 17:38:03 +02001905#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001906 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001907 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001908 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001909# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001910 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001911 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001912# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001913 // Get syntax attribute.
1914 if (has_syntax)
1915 {
1916 // Get the syntax attribute for the character. If there
1917 // is an error, disable syntax highlighting.
1918 save_did_emsg = did_emsg;
1919 did_emsg = FALSE;
1920
1921 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001922 if (v == prev_syntax_col)
1923 // at same column again
1924 syntax_attr = prev_syntax_attr;
1925 else
1926 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001927# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001928 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001929# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001930 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001931# ifdef FEAT_SPELL
1932 has_spell ? &can_spell :
1933# endif
1934 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001935 prev_syntax_col = v;
1936 prev_syntax_attr = syntax_attr;
1937 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001938
Bram Moolenaar34390282019-10-16 14:38:26 +02001939 if (did_emsg)
1940 {
1941 wp->w_s->b_syn_error = TRUE;
1942 has_syntax = FALSE;
1943 syntax_attr = 0;
1944 }
1945 else
1946 did_emsg = save_did_emsg;
1947# ifdef SYN_TIME_LIMIT
1948 if (wp->w_s->b_syn_slow)
1949 has_syntax = FALSE;
1950# endif
1951
1952 // Need to get the line again, a multi-line regexp may
1953 // have made it invalid.
1954 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1955 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001956 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001957# ifdef FEAT_CONCEAL
1958 // no concealing past the end of the line, it interferes
1959 // with line highlighting
1960 if (*ptr == NUL)
1961 syntax_flags = 0;
1962 else
1963 syntax_flags = get_syntax_info(&syntax_seqnr);
1964# endif
1965 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001966 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001967# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001968 // Combine text property highlight into syntax highlight.
1969 if (text_prop_type != NULL)
1970 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001971 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001972 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1973 else
1974 syntax_attr = text_prop_attr;
1975 }
1976# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001977#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001978
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001979 // Decide which of the highlight attributes to use.
1980 attr_pri = TRUE;
1981#ifdef LINE_ATTR
1982 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001983 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001984 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001985 if (!highlight_match)
1986 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001987 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001988# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001989 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001990# endif
1991 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001993 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001995# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001996 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001997# endif
1998 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001999 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002000 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2001 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002 {
2003 // Use line_attr when not in the Visual or 'incsearch' area
2004 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002005# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002006 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002007# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002008 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002009# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002010 attr_pri = FALSE;
2011 }
2012#else
2013 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002014 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002015 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002016 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017#endif
2018 else
2019 {
2020 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002022 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002023#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002024 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002025#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002026 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002027#ifdef FEAT_PROP_POPUP
2028 // override with text property highlight when "override" is TRUE
2029 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002030 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002031#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002033
2034 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002035 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002036 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002037 if (wlv.char_attr == 0)
2038 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002039 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002040 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002041 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002042
2043 // Get the next character to put on the screen.
2044
2045 // The "p_extra" points to the extra stuff that is inserted to
2046 // represent special characters (non-printable stuff) and other
2047 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002048 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2050 // "p_extra[n_extra]".
2051 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002052 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002054 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002056 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2057 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002058 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2059 if (enc_utf8 && utf_char2len(c) > 1)
2060 {
2061 mb_utf8 = TRUE;
2062 u8cc[0] = 0;
2063 c = 0xc0;
2064 }
2065 else
2066 mb_utf8 = FALSE;
2067 }
2068 else
2069 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 if (has_mbyte)
2072 {
2073 mb_c = c;
2074 if (enc_utf8)
2075 {
2076 // If the UTF-8 character is more than one byte:
2077 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002078 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002080 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002081 mb_l = 1;
2082 else if (mb_l > 1)
2083 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002084 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085 mb_utf8 = TRUE;
2086 c = 0xc0;
2087 }
2088 }
2089 else
2090 {
2091 // if this is a DBCS character, put it in "mb_c"
2092 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002093 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 mb_l = 1;
2095 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002096 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002097 }
2098 if (mb_l == 0) // at the NUL at end-of-line
2099 mb_l = 1;
2100
2101 // If a double-width char doesn't fit display a '>' in the
2102 // last column.
2103 if ((
2104# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002105 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002107 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002108 && (*mb_char2cells)(mb_c) == 2)
2109 {
2110 c = '>';
2111 mb_c = c;
2112 mb_l = 1;
2113 mb_utf8 = FALSE;
2114 multi_attr = HL_ATTR(HLF_AT);
2115#ifdef FEAT_SYN_HL
2116 if (cul_attr)
2117 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2118#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002119 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002120
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002121 // put the pointer back to output the double-width
2122 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002123 ++wlv.n_extra;
2124 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 }
2126 else
2127 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002128 wlv.n_extra -= mb_l - 1;
2129 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130 }
2131 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002132 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002133 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002134 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002135#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002136 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002137 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002138 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002139 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002140 if (search_attr == 0)
2141 search_attr = saved_search_attr;
2142 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002143#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002144 }
2145 else
2146 {
2147#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002148 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002149#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002150 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002152 // Get a character from the line itself.
2153 c = *ptr;
2154#ifdef FEAT_LINEBREAK
2155 c0 = *ptr;
2156#endif
2157 if (has_mbyte)
2158 {
2159 mb_c = c;
2160 if (enc_utf8)
2161 {
2162 // If the UTF-8 character is more than one byte: Decode it
2163 // into "mb_c".
2164 mb_l = utfc_ptr2len(ptr);
2165 mb_utf8 = FALSE;
2166 if (mb_l > 1)
2167 {
2168 mb_c = utfc_ptr2char(ptr, u8cc);
2169 // Overlong encoded ASCII or ASCII with composing char
2170 // is displayed normally, except a NUL.
2171 if (mb_c < 0x80)
2172 {
2173 c = mb_c;
2174#ifdef FEAT_LINEBREAK
2175 c0 = mb_c;
2176#endif
2177 }
2178 mb_utf8 = TRUE;
2179
2180 // At start of the line we can have a composing char.
2181 // Draw it as a space with a composing char.
2182 if (utf_iscomposing(mb_c))
2183 {
2184 int i;
2185
2186 for (i = Screen_mco - 1; i > 0; --i)
2187 u8cc[i] = u8cc[i - 1];
2188 u8cc[0] = mb_c;
2189 mb_c = ' ';
2190 }
2191 }
2192
2193 if ((mb_l == 1 && c >= 0x80)
2194 || (mb_l >= 1 && mb_c == 0)
2195 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2196 {
2197 // Illegal UTF-8 byte: display as <xx>.
2198 // Non-BMP character : display as ? or fullwidth ?.
2199 transchar_hex(extra, mb_c);
2200# ifdef FEAT_RIGHTLEFT
2201 if (wp->w_p_rl) // reverse
2202 rl_mirror(extra);
2203# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002204 wlv.p_extra = extra;
2205 c = *wlv.p_extra;
2206 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2209 wlv.c_extra = NUL;
2210 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 if (area_attr == 0 && search_attr == 0)
2212 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002213 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002214 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002215 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 }
2218 }
2219 else if (mb_l == 0) // at the NUL at end-of-line
2220 mb_l = 1;
2221#ifdef FEAT_ARABIC
2222 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2223 {
2224 // Do Arabic shaping.
2225 int pc, pc1, nc;
2226 int pcc[MAX_MCO];
2227
2228 // The idea of what is the previous and next
2229 // character depends on 'rightleft'.
2230 if (wp->w_p_rl)
2231 {
2232 pc = prev_c;
2233 pc1 = prev_c1;
2234 nc = utf_ptr2char(ptr + mb_l);
2235 prev_c1 = u8cc[0];
2236 }
2237 else
2238 {
2239 pc = utfc_ptr2char(ptr + mb_l, pcc);
2240 nc = prev_c;
2241 pc1 = pcc[0];
2242 }
2243 prev_c = mb_c;
2244
2245 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2246 }
2247 else
2248 prev_c = mb_c;
2249#endif
2250 }
2251 else // enc_dbcs
2252 {
2253 mb_l = MB_BYTE2LEN(c);
2254 if (mb_l == 0) // at the NUL at end-of-line
2255 mb_l = 1;
2256 else if (mb_l > 1)
2257 {
2258 // We assume a second byte below 32 is illegal.
2259 // Hopefully this is OK for all double-byte encodings!
2260 if (ptr[1] >= 32)
2261 mb_c = (c << 8) + ptr[1];
2262 else
2263 {
2264 if (ptr[1] == NUL)
2265 {
2266 // head byte at end of line
2267 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002268 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 }
2270 else
2271 {
2272 // illegal tail byte
2273 mb_l = 2;
2274 STRCPY(extra, "XX");
2275 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002276 wlv.p_extra = extra;
2277 wlv.n_extra = (int)STRLEN(extra) - 1;
2278 wlv.c_extra = NUL;
2279 wlv.c_final = NUL;
2280 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281 if (area_attr == 0 && search_attr == 0)
2282 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002284 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002285 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002286 // save current attr
2287 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 }
2289 mb_c = c;
2290 }
2291 }
2292 }
2293 // If a double-width char doesn't fit display a '>' in the
2294 // last column; the character is displayed at the start of the
2295 // next line.
2296 if ((
2297# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002298 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002300 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 && (*mb_char2cells)(mb_c) == 2)
2302 {
2303 c = '>';
2304 mb_c = c;
2305 mb_utf8 = FALSE;
2306 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002307 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 // Put pointer back so that the character will be
2309 // displayed at the start of the next line.
2310 --ptr;
2311#ifdef FEAT_CONCEAL
2312 did_decrement_ptr = TRUE;
2313#endif
2314 }
2315 else if (*ptr != NUL)
2316 ptr += mb_l - 1;
2317
2318 // If a double-width char doesn't fit at the left side display
2319 // a '<' in the first column. Don't do this for unprintable
2320 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002321 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002323 wlv.n_extra = 1;
2324 wlv.c_extra = MB_FILLER_CHAR;
2325 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326 c = ' ';
2327 if (area_attr == 0 && search_attr == 0)
2328 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002329 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002330 extra_attr = hl_combine_attr(
2331 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002332 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 }
2334 mb_c = c;
2335 mb_utf8 = FALSE;
2336 mb_l = 1;
2337 }
2338
2339 }
2340 ++ptr;
2341
2342 if (extra_check)
2343 {
2344#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 // Check spelling (unless at the end of the line).
2346 // Only do this when there is no syntax highlighting, the
2347 // @Spell cluster is not used or the current syntax item
2348 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002349 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002350 if (has_spell && v >= word_end && v > cur_checked_col)
2351 {
2352 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002353 // do not calculate cap_col at the end of the line or when
2354 // only white space is following
2355 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356# ifdef FEAT_SYN_HL
2357 !has_syntax ||
2358# endif
2359 can_spell))
2360 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002361 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002362 int len;
2363 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002364
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367
2368 // Use nextline[] if possible, it has the start of the
2369 // next line concatenated.
2370 if ((prev_ptr - line) - nextlinecol >= 0)
2371 p = nextline + (prev_ptr - line) - nextlinecol;
2372 else
2373 p = prev_ptr;
2374 cap_col -= (int)(prev_ptr - line);
2375 len = spell_check(wp, p, &spell_hlf, &cap_col,
2376 nochange);
2377 word_end = v + len;
2378
2379 // In Insert mode only highlight a word that
2380 // doesn't touch the cursor.
2381 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002382 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002383 && wp->w_cursor.lnum == lnum
2384 && wp->w_cursor.col >=
2385 (colnr_T)(prev_ptr - line)
2386 && wp->w_cursor.col < (colnr_T)word_end)
2387 {
2388 spell_hlf = HLF_COUNT;
2389 spell_redraw_lnum = lnum;
2390 }
2391
2392 if (spell_hlf == HLF_COUNT && p != prev_ptr
2393 && (p - nextline) + len > nextline_idx)
2394 {
2395 // Remember that the good word continues at the
2396 // start of the next line.
2397 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002398 checked_col = (int)((p - nextline)
2399 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 }
2401
2402 // Turn index into actual attributes.
2403 if (spell_hlf != HLF_COUNT)
2404 spell_attr = highlight_attr[spell_hlf];
2405
2406 if (cap_col > 0)
2407 {
2408 if (p != prev_ptr
2409 && (p - nextline) + cap_col >= nextline_idx)
2410 {
2411 // Remember that the word in the next line
2412 // must start with a capital.
2413 capcol_lnum = lnum + 1;
2414 cap_col = (int)((p - nextline) + cap_col
2415 - nextline_idx);
2416 }
2417 else
2418 // Compute the actual column.
2419 cap_col += (int)(prev_ptr - line);
2420 }
2421 }
2422 }
2423 if (spell_attr != 0)
2424 {
2425 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002426 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2427 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002428 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002429 wlv.char_attr = hl_combine_attr(spell_attr,
2430 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002431 }
2432#endif
2433#ifdef FEAT_LINEBREAK
2434 // Found last space before word: check for line break.
2435 if (wp->w_p_lbr && c0 == c
2436 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2437 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002438 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2439 : 0;
2440 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002441 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002443 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002444# ifdef FEAT_PROP_POPUP
2445 // do not want virtual text counted here
2446 cts.cts_has_prop_with_text = FALSE;
2447# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002449 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002450
2451 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002452 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002453 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002454 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002455 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2456 if (wlv.n_extra < 0)
2457 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002458 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002459 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002460 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002461 // line break, but for TABs the highlighting should
2462 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002463 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002464
Bram Moolenaar1306b362022-08-06 15:59:06 +01002465 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002467 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002468 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469 wp->w_buffer->b_p_vts_array) - 1;
2470# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002471 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002472 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473# endif
2474
Bram Moolenaar1306b362022-08-06 15:59:06 +01002475 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2476 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002477# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002478 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002479 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002480# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 if (VIM_ISWHITE(c))
2482 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002483# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484 if (c == TAB)
2485 // See "Tab alignment" below.
2486 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002487# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 if (!wp->w_p_list)
2489 c = ' ';
2490 }
2491 }
2492#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002493 in_multispace = c == ' '
2494 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2495 if (!in_multispace)
2496 multispace_pos = 0;
2497
Bram Moolenaareed9d462021-02-15 20:38:25 +01002498 // 'list': Change char 160 to 'nbsp' and space to 'space'
2499 // setting in 'listchars'. But not when the character is
2500 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 if (wp->w_p_list
2502 && ((((c == 160 && mb_l == 1)
2503 || (mb_utf8
2504 && ((mb_c == 160 && mb_l == 2)
2505 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002506 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 || (c == ' '
2508 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002509 && (wp->w_lcs_chars.space
2510 || (in_multispace
2511 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002512 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 && ptr - line <= trailcol)))
2514 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002515 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2516 {
2517 c = wp->w_lcs_chars.multispace[multispace_pos++];
2518 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2519 multispace_pos = 0;
2520 }
2521 else
2522 c = (c == ' ') ? wp->w_lcs_chars.space
2523 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 if (area_attr == 0 && search_attr == 0)
2525 {
2526 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002527 extra_attr = hl_combine_attr(wlv.win_attr,
2528 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530 }
2531 mb_c = c;
2532 if (enc_utf8 && utf_char2len(c) > 1)
2533 {
2534 mb_utf8 = TRUE;
2535 u8cc[0] = 0;
2536 c = 0xc0;
2537 }
2538 else
2539 mb_utf8 = FALSE;
2540 }
2541
zeertzjq2e7cba32022-06-10 15:30:32 +01002542 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2543 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002545 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2546 && wp->w_lcs_chars.leadmultispace != NULL)
2547 {
2548 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002549 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2550 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002551 multispace_pos = 0;
2552 }
2553
2554 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2555 c = wp->w_lcs_chars.trail;
2556
2557 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2558 c = wp->w_lcs_chars.lead;
2559
zeertzjq2e7cba32022-06-10 15:30:32 +01002560 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002561 c = wp->w_lcs_chars.space;
2562
2563
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 if (!attr_pri)
2565 {
2566 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002567 extra_attr = hl_combine_attr(wlv.win_attr,
2568 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 }
2571 mb_c = c;
2572 if (enc_utf8 && utf_char2len(c) > 1)
2573 {
2574 mb_utf8 = TRUE;
2575 u8cc[0] = 0;
2576 c = 0xc0;
2577 }
2578 else
2579 mb_utf8 = FALSE;
2580 }
2581 }
2582
2583 // Handling of non-printable characters.
2584 if (!vim_isprintc(c))
2585 {
2586 // when getting a character from the file, we may have to
2587 // turn it into something else on the way to putting it
2588 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002589 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 {
2591 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002592 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002594 char_u *sbr = get_showbreak_value(wp);
2595
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 // only adjust the tab_len, when at the first column
2597 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002598 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2599 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600#endif
2601 // tab amount depends on current column
2602#ifdef FEAT_VARTABS
2603 tab_len = tabstop_padding(vcol_adjusted,
2604 wp->w_buffer->b_p_ts,
2605 wp->w_buffer->b_p_vts_array) - 1;
2606#else
2607 tab_len = (int)wp->w_buffer->b_p_ts
2608 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2609#endif
2610
2611#ifdef FEAT_LINEBREAK
2612 if (!wp->w_p_lbr || !wp->w_p_list)
2613#endif
2614 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002615 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616#ifdef FEAT_LINEBREAK
2617 else
2618 {
2619 char_u *p;
2620 int len;
2621 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002622 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002624# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002625 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002627 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002628
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002630 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002631 && old_boguscols > 0
2632 && wlv.n_extra > tab_len)
2633 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002634# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002635 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002637 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002638 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002639 if (wp->w_lcs_chars.tab3)
2640 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002641 if (wlv.n_extra > 0)
2642 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002643 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002644 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002645 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002646 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002647 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002649 vim_memset(p, ' ', len);
2650 p[len] = NUL;
2651 vim_free(p_extra_free);
2652 p_extra_free = p;
2653 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002655 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002657 if (*p == NUL)
2658 {
2659 tab_len = i;
2660 break;
2661 }
2662
2663 // if tab3 is given, use it for the last char
2664 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2665 lcs = wp->w_lcs_chars.tab3;
2666 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002667 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002669 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002670 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002671# ifdef FEAT_CONCEAL
2672 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2673 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002674 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002675 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002676# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678 }
2679#endif
2680#ifdef FEAT_CONCEAL
2681 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002682 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683
2684 // Tab alignment should be identical regardless of
2685 // 'conceallevel' value. So tab compensates of all
2686 // previous concealed characters, and thus resets
2687 // vcol_off and boguscols accumulated so far in the
2688 // line. Note that the tab can be longer than
2689 // 'tabstop' when there are concealed characters.
2690 FIX_FOR_BOGUSCOLS;
2691
2692 // Make sure, the highlighting for the tab char will be
2693 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002694 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002695 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002696 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 tab_len += vc_saved;
2698 }
2699#endif
2700 mb_utf8 = FALSE; // don't draw as UTF-8
2701 if (wp->w_p_list)
2702 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002704 ? wp->w_lcs_chars.tab3
2705 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706#ifdef FEAT_LINEBREAK
2707 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002708 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 else
2710#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002711 wlv.c_extra = wp->w_lcs_chars.tab2;
2712 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002714 extra_attr = hl_combine_attr(wlv.win_attr,
2715 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002716 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 mb_c = c;
2718 if (enc_utf8 && utf_char2len(c) > 1)
2719 {
2720 mb_utf8 = TRUE;
2721 u8cc[0] = 0;
2722 c = 0xc0;
2723 }
2724 }
2725 else
2726 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002727 wlv.c_final = NUL;
2728 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 c = ' ';
2730 }
2731 }
2732 else if (c == NUL
2733 && (wp->w_p_list
2734 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002735 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736 && VIsual_mode != Ctrl_V
2737 && (
2738# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002739 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002741 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 && !(noinvcur
2743 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002744 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002745 && lcs_eol_one > 0)
2746 {
2747 // Display a '$' after the line or highlight an extra
2748 // character if the line break is included.
2749#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2750 // For a diff line the highlighting continues after the
2751 // "$".
2752 if (
2753# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002754 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755# ifdef LINE_ATTR
2756 &&
2757# endif
2758# endif
2759# ifdef LINE_ATTR
2760 line_attr == 0
2761# endif
2762 )
2763#endif
2764 {
2765 // In virtualedit, visual selections may extend
2766 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002767 if (!(area_highlighting && virtual_active()
2768 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002769 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002770 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002772 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2773 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 else
2775 c = ' ';
2776 lcs_eol_one = -1;
2777 --ptr; // put it back at the NUL
2778 if (!attr_pri)
2779 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002780 extra_attr = hl_combine_attr(wlv.win_attr,
2781 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 n_attr = 1;
2783 }
2784 mb_c = c;
2785 if (enc_utf8 && utf_char2len(c) > 1)
2786 {
2787 mb_utf8 = TRUE;
2788 u8cc[0] = 0;
2789 c = 0xc0;
2790 }
2791 else
2792 mb_utf8 = FALSE; // don't draw as UTF-8
2793 }
2794 else if (c != NUL)
2795 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2797 if (wlv.n_extra == 0)
2798 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799#ifdef FEAT_RIGHTLEFT
2800 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002803 wlv.c_extra = NUL;
2804 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805#ifdef FEAT_LINEBREAK
2806 if (wp->w_p_lbr)
2807 {
2808 char_u *p;
2809
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 c = *wlv.p_extra;
2811 p = alloc(wlv.n_extra + 1);
2812 vim_memset(p, ' ', wlv.n_extra);
2813 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2814 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002816 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 }
2818 else
2819#endif
2820 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002821 wlv.n_extra = byte2cells(c) - 1;
2822 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823 }
2824 if (!attr_pri)
2825 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002826 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002827 extra_attr = hl_combine_attr(wlv.win_attr,
2828 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002829 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 }
2831 mb_utf8 = FALSE; // don't draw as UTF-8
2832 }
2833 else if (VIsual_active
2834 && (VIsual_mode == Ctrl_V
2835 || VIsual_mode == 'v')
2836 && virtual_active()
2837 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002838 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 && (
2840#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002841 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002843 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844 {
2845 c = ' ';
2846 --ptr; // put it back at the NUL
2847 }
2848#if defined(LINE_ATTR)
2849 else if ((
2850# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002851 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852# endif
2853# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002854 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855# endif
2856 line_attr != 0
2857 ) && (
2858# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002859 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002860# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002861 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002863 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864# endif
2865 < wp->w_width)))
2866 {
2867 // Highlight until the right side of the window
2868 c = ' ';
2869 --ptr; // put it back at the NUL
2870
2871 // Remember we do the char for line highlighting.
2872 ++did_line_attr;
2873
2874 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002877 || (wp->w_p_list &&
2878 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002883 wlv.diff_hlf = HLF_CHD;
2884 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2888 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002889 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002890 || (wlv.vcol >= left_curline_col
2891 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.char_attr = hl_combine_attr(
2893 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 }
2895 }
2896# endif
2897# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002900 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002901 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2902 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 if (!wlv.cul_screenline
2905 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002906 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002907 wlv.char_attr = hl_combine_attr(
2908 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 }
2910 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2912 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 }
2914# endif
2915 }
2916#endif
2917 }
2918
2919#ifdef FEAT_CONCEAL
2920 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002921 && (wp != curwin || lnum != wp->w_cursor.lnum
2922 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2924 && !(lnum_in_visual_area
2925 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2926 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002927 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002928 if (((prev_syntax_id != syntax_seqnr
2929 && (syntax_flags & HL_CONCEAL) != 0)
2930 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002931 && (syn_get_sub_char() != NUL
2932 || (has_match_conc && match_conc)
2933 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934 && wp->w_p_cole != 3)
2935 {
2936 // First time at this concealed item: display one
2937 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002938 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 c = match_conc;
2940 else if (syn_get_sub_char() != NUL)
2941 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002942 else if (wp->w_lcs_chars.conceal != NUL)
2943 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 else
2945 c = ' ';
2946
2947 prev_syntax_id = syntax_seqnr;
2948
Bram Moolenaar1306b362022-08-06 15:59:06 +01002949 if (wlv.n_extra > 0)
2950 wlv.vcol_off += wlv.n_extra;
2951 wlv.vcol += wlv.n_extra;
2952 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 {
2954# ifdef FEAT_RIGHTLEFT
2955 if (wp->w_p_rl)
2956 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 wlv.col -= wlv.n_extra;
2958 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959 }
2960 else
2961# endif
2962 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 wlv.boguscols += wlv.n_extra;
2964 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 }
2966 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 n_attr = 0;
2969 }
2970 else if (n_skip == 0)
2971 {
2972 is_concealing = TRUE;
2973 n_skip = 1;
2974 }
2975 mb_c = c;
2976 if (enc_utf8 && utf_char2len(c) > 1)
2977 {
2978 mb_utf8 = TRUE;
2979 u8cc[0] = 0;
2980 c = 0xc0;
2981 }
2982 else
2983 mb_utf8 = FALSE; // don't draw as UTF-8
2984 }
2985 else
2986 {
2987 prev_syntax_id = 0;
2988 is_concealing = FALSE;
2989 }
2990
2991 if (n_skip > 0 && did_decrement_ptr)
2992 // not showing the '>', put pointer back to avoid getting stuck
2993 ++ptr;
2994
2995#endif // FEAT_CONCEAL
2996 }
2997
2998#ifdef FEAT_CONCEAL
2999 // In the cursor line and we may be concealing characters: correct
3000 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003001 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 && wp == curwin && lnum == wp->w_cursor.lnum
3003 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003004 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003006# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003008 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003010# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003011 wp->w_wcol = wlv.col - wlv.boguscols;
3012 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013 did_wcol = TRUE;
3014 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003015# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003016 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003017# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 }
3019#endif
3020
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003021 // Use "extra_attr", but don't override visual selection highlighting,
3022 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003023 // Don't use "extra_attr" until n_attr_skip is zero.
3024 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003025 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003026 && (!attr_pri
3027#ifdef FEAT_PROP_POPUP
3028 || (text_prop_flags & PT_FLAG_OVERRIDE)
3029#endif
3030 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 {
3032#ifdef LINE_ATTR
3033 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003034 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 else
3036#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003037 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 }
3039
3040#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3041 // XIM don't send preedit_start and preedit_end, but they send
3042 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3043 // im_is_preediting() here.
3044 if (p_imst == IM_ON_THE_SPOT
3045 && xic != NULL
3046 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003047 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 && !p_imdisable
3049 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 {
3052 colnr_T tcol;
3053
3054 if (preedit_end_col == MAXCOL)
3055 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3056 else
3057 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003058 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 {
3060 if (feedback_old_attr < 0)
3061 {
3062 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003063 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 wlv.char_attr = im_get_feedback_attr(feedback_col);
3066 if (wlv.char_attr < 0)
3067 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 feedback_col++;
3069 }
3070 else if (feedback_old_attr >= 0)
3071 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 feedback_old_attr = -1;
3074 feedback_col = 0;
3075 }
3076 }
3077#endif
3078 // Handle the case where we are in column 0 but not on the first
3079 // character of the line and the user wants us to show us a
3080 // special character (via 'listchars' option "precedes:<char>".
3081 if (lcs_prec_todo != NUL
3082 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003083 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003084 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003085 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086#ifdef FEAT_DIFF
3087 && filler_todo <= 0
3088#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003089 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 && c != NUL)
3091 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003092 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 lcs_prec_todo = NUL;
3094 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3095 {
3096 // Double-width character being overwritten by the "precedes"
3097 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003098 wlv.c_extra = MB_FILLER_CHAR;
3099 wlv.c_final = NUL;
3100 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003102 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 }
3104 mb_c = c;
3105 if (enc_utf8 && utf_char2len(c) > 1)
3106 {
3107 mb_utf8 = TRUE;
3108 u8cc[0] = 0;
3109 c = 0xc0;
3110 }
3111 else
3112 mb_utf8 = FALSE; // don't draw as UTF-8
3113 if (!attr_pri)
3114 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003115 saved_attr3 = wlv.char_attr; // save current attr
3116 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 n_attr3 = 1;
3118 }
3119 }
3120
3121 // At end of the text line or just after the last character.
3122 if ((c == NUL
3123#if defined(LINE_ATTR)
3124 || did_line_attr == 1
3125#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003126 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 {
3128#ifdef FEAT_SEARCH_EXTRA
3129 // flag to indicate whether prevcol equals startcol of search_hl or
3130 // one of the matches
3131 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3132 (long)(ptr - line) - (c == NUL));
3133#endif
3134 // Invert at least one char, used for Visual and empty line or
3135 // highlight match at end of line. If it's beyond the last
3136 // char on the screen, just overwrite that one (tricky!) Not
3137 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003138 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003139 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 && (VIsual_mode != Ctrl_V
3141 || lnum == VIsual.lnum
3142 || lnum == curwin->w_cursor.lnum)
3143 && c == NUL)
3144#ifdef FEAT_SEARCH_EXTRA
3145 // highlight 'hlsearch' match at end of line
3146 || (prevcol_hl_flag
3147# ifdef FEAT_SYN_HL
3148 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3149 && !(wp == curwin && VIsual_active))
3150# endif
3151# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153# endif
3154# if defined(LINE_ATTR)
3155 && did_line_attr <= 1
3156# endif
3157 )
3158#endif
3159 ))
3160 {
3161 int n = 0;
3162
3163#ifdef FEAT_RIGHTLEFT
3164 if (wp->w_p_rl)
3165 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003166 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 n = 1;
3168 }
3169 else
3170#endif
3171 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 n = -1;
3174 }
3175 if (n != 0)
3176 {
3177 // At the window boundary, highlight the last character
3178 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003179 wlv.off += n;
3180 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 }
3182 else
3183 {
3184 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003185 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003187 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 }
3189#ifdef FEAT_SEARCH_EXTRA
3190 if (area_attr == 0)
3191 {
3192 // Use attributes from match with highest priority among
3193 // 'search_hl' and the match list.
3194 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003195 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 }
3197#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003198 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003199 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200#ifdef FEAT_RIGHTLEFT
3201 if (wp->w_p_rl)
3202 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003203 --wlv.col;
3204 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 }
3206 else
3207#endif
3208 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003209 ++wlv.col;
3210 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003212 ++wlv.vcol;
3213 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 }
3215 }
3216
3217 // At end of the text line.
3218 if (c == NUL)
3219 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003220 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221
3222 // Update w_cline_height and w_cline_folded if the cursor line was
3223 // updated (saves a call to plines() later).
3224 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3225 {
3226 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003227 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228#ifdef FEAT_FOLDING
3229 curwin->w_cline_folded = FALSE;
3230#endif
3231 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3232 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 break;
3234 }
3235
3236 // Show "extends" character from 'listchars' if beyond the line end and
3237 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003238 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 && wp->w_p_list
3241 && !wp->w_p_wrap
3242#ifdef FEAT_DIFF
3243 && filler_todo <= 0
3244#endif
3245 && (
3246#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003247 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003251 || lcs_eol_one > 0
3252 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003253 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003255 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003256 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 mb_c = c;
3258 if (enc_utf8 && utf_char2len(c) > 1)
3259 {
3260 mb_utf8 = TRUE;
3261 u8cc[0] = 0;
3262 c = 0xc0;
3263 }
3264 else
3265 mb_utf8 = FALSE;
3266 }
3267
3268#ifdef FEAT_SYN_HL
3269 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 if (wlv.draw_color_col)
3271 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003272
3273 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3274 // highlight the cursor position itself.
3275 // Also highlight the 'colorcolumn' if it is different than
3276 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003277 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3278 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003280 if (((wlv.draw_state == WL_LINE
3281 || wlv.draw_state == WL_BRI
3282 || wlv.draw_state == WL_SBR)
3283 && !lnum_in_visual_area
3284 && search_attr == 0
3285 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003286# ifdef FEAT_DIFF
3287 && filler_todo <= 0
3288# endif
3289 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 {
3291 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3292 && lnum != wp->w_cursor.lnum)
3293 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003294 vcol_save_attr = wlv.char_attr;
3295 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3296 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003298 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003300 vcol_save_attr = wlv.char_attr;
3301 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302 }
3303 }
3304#endif
3305
3306 // Store character to be displayed.
3307 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003308 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003309 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310 {
3311 // Store the character.
3312#if defined(FEAT_RIGHTLEFT)
3313 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3314 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003315 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003316 --wlv.off;
3317 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 }
3319#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003320 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 if (enc_dbcs == DBCS_JPNU)
3322 {
3323 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 ScreenLines[wlv.off] = 0x8e;
3325 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 }
3327 else if (enc_utf8)
3328 {
3329 if (mb_utf8)
3330 {
3331 int i;
3332
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003333 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003335 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 for (i = 0; i < Screen_mco; ++i)
3337 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 if (u8cc[i] == 0)
3340 break;
3341 }
3342 }
3343 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003344 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 }
3346 if (multi_attr)
3347 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 multi_attr = 0;
3350 }
3351 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003354 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003355
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3357 {
3358 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003359 ++wlv.off;
3360 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 if (enc_utf8)
3362 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 else
3365 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003367 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368#ifdef FEAT_DIFF
3369 && filler_todo <= 0
3370#endif
3371 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003372 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 // When "tocol" is halfway a character, set it to the end of
3374 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003375 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003377
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003378 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003379
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380#ifdef FEAT_RIGHTLEFT
3381 if (wp->w_p_rl)
3382 {
3383 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 --wlv.off;
3385 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
3387#endif
3388 }
3389#ifdef FEAT_RIGHTLEFT
3390 if (wp->w_p_rl)
3391 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 --wlv.off;
3393 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394 }
3395 else
3396#endif
3397 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003398 ++wlv.off;
3399 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400 }
3401 }
3402#ifdef FEAT_CONCEAL
3403 else if (wp->w_p_cole > 0 && is_concealing)
3404 {
3405 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003407 if (wlv.n_extra > 0)
3408 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 if (wp->w_p_wrap)
3410 {
3411 // Special voodoo required if 'wrap' is on.
3412 //
3413 // Advance the column indicator to force the line
3414 // drawing to wrap early. This will make the line
3415 // take up the same screen space when parts are concealed,
3416 // so that cursor line computations aren't messed up.
3417 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 // trailing junk to be written out of the screen line
3420 // we are building, 'boguscols' keeps track of the number
3421 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003422 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003424 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425# ifdef FEAT_RIGHTLEFT
3426 if (wp->w_p_rl)
3427 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003428 wlv.col -= wlv.n_extra;
3429 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 }
3431 else
3432# endif
3433 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003434 wlv.col += wlv.n_extra;
3435 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003437 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 n_attr = 0;
3439 }
3440
3441
3442 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3443 {
3444 // Need to fill two screen columns.
3445# ifdef FEAT_RIGHTLEFT
3446 if (wp->w_p_rl)
3447 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 --wlv.boguscols;
3449 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 }
3451 else
3452# endif
3453 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003454 ++wlv.boguscols;
3455 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 }
3457 }
3458
3459# ifdef FEAT_RIGHTLEFT
3460 if (wp->w_p_rl)
3461 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003462 --wlv.boguscols;
3463 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 }
3465 else
3466# endif
3467 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 ++wlv.boguscols;
3469 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 }
3471 }
3472 else
3473 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003474 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 wlv.vcol += wlv.n_extra;
3477 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 n_attr = 0;
3479 }
3480 }
3481
3482 }
3483#endif // FEAT_CONCEAL
3484 else
3485 --n_skip;
3486
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 // Only advance the "wlv.vcol" when after the 'number' or
3488 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003489 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490#ifdef FEAT_DIFF
3491 && filler_todo <= 0
3492#endif
3493 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003494 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495
3496#ifdef FEAT_SYN_HL
3497 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003498 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499#endif
3500
3501 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003502 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3503 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504
3505 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003507 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003508 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003509 if (n_attr_skip > 0)
3510 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511
3512 // At end of screen line and there is more to come: Display the line
3513 // so far. If there is no more to display it is caught above.
3514 if ((
3515#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003516 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003518 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003519 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003520 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521#ifdef FEAT_DIFF
3522 || filler_todo > 0
3523#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003524#ifdef FEAT_PROP_POPUP
3525 || text_prop_follows
3526#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003527 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003528 && wlv.p_extra != at_end_str)
3529 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3530 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 )
3532 {
3533#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003534 screen_line(wp, wlv.screen_row, wp->w_wincol,
3535 wlv.col - wlv.boguscols,
3536 wp->w_width, wlv.screen_line_flags);
3537 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003539 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3540 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003542 ++wlv.row;
3543 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544
3545 // When not wrapping and finished diff lines, or when displayed
3546 // '$' and highlighting until last column, break here.
3547 if ((!wp->w_p_wrap
3548#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003549 && filler_todo <= 0
3550#endif
3551#ifdef FEAT_PROP_POPUP
3552 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553#endif
3554 ) || lcs_eol_one == -1)
3555 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003556#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003557 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003558 {
3559 // do not output more of the line, only the "below" prop
3560 ptr += STRLEN(ptr);
3561# ifdef FEAT_LINEBREAK
3562 dont_use_showbreak = TRUE;
3563# endif
3564 }
3565#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566
3567 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003568 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569#ifdef FEAT_DIFF
3570 && filler_todo <= 0
3571#endif
3572 )
3573 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003574 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3575 draw_vsep_win(wp, wlv.row);
3576 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 }
3578
3579 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003580 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003582 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 break;
3584 }
3585
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587#ifdef FEAT_DIFF
3588 && filler_todo <= 0
3589#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003590#ifdef FEAT_PROP_POPUP
3591 && !text_prop_follows
3592#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 && wp->w_width == Columns)
3594 {
3595 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597
3598 // Special trick to make copy/paste of wrapped lines work with
3599 // xterm/screen: write an extra character beyond the end of
3600 // the line. This will work with all terminal types
3601 // (regardless of the xn,am settings).
3602 // Only do this on a fast tty.
3603 // Only do this if the cursor is on the current line
3604 // (something has been written in it).
3605 // Don't do this for the GUI.
3606 // Don't do this for double-width characters.
3607 // Don't do this for a window not at the right screen border.
3608 if (p_tf
3609#ifdef FEAT_GUI
3610 && !gui.in_use
3611#endif
3612 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3614 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003616 || (*mb_off2cells)(
3617 LineOffset[wlv.screen_row - 1]
3618 + (int)Columns - 2,
3619 LineOffset[wlv.screen_row]
3620 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 {
3622 // First make sure we are at the end of the screen line,
3623 // then output the same character again to let the
3624 // terminal know about the wrap. If the terminal doesn't
3625 // auto-wrap, we overwrite the character.
3626 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003627 screen_char(LineOffset[wlv.screen_row - 1]
3628 + (unsigned)Columns - 1,
3629 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630
3631 // When there is a multi-byte character, just output a
3632 // space to keep it simple.
3633 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003634 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 out_char(' ');
3636 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 + (Columns - 1)]);
3639 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 screen_start(); // don't know where cursor is now
3642 }
3643 }
3644
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646
Bram Moolenaareed9d462021-02-15 20:38:25 +01003647 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003649 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003651 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003653 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654 need_showbreak = TRUE;
3655#endif
3656#ifdef FEAT_DIFF
3657 --filler_todo;
3658 // When the filler lines are actually below the last line of the
3659 // file, don't draw the line itself, break here.
3660 if (filler_todo == 0 && wp->w_botfill)
3661 break;
3662#endif
3663 }
3664
3665 } // for every character in the line
3666
3667#ifdef FEAT_SPELL
3668 // After an empty line check first word for capital.
3669 if (*skipwhite(line) == NUL)
3670 {
3671 capcol_lnum = lnum + 1;
3672 cap_col = 0;
3673 }
3674#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003675#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 vim_free(text_props);
3677 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003678 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679#endif
3680
3681 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003682 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683}