blob: 6c298b6f481562ceea8febe8eb1a47854147839e [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);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100305 int col_off = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100306 int room = wp->w_width - col_with_padding;
307 int added = room;
308 int n_used = *n_extra;
309 char_u *l = NULL;
310 int strsize = vim_strsize(*p_extra);
311 int cells = wrap ? strsize
312 : textprop_size_after_trunc(wp, below, added, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100314 if (wrap || right || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100315 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100316 // Right-align: fill with spaces
317 if (right)
318 added -= cells;
319 if (added < 0
320 || !(right || below)
321 || (below
322 ? (col_with_padding == 0 || !wp->w_p_wrap)
323 : (n_used < *n_extra)))
324 {
325 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
326 {
327 // right-align on next line instead of wrapping if possible
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100328 col_off = win_col_off(wp) + win_col_off2(wp);
329 added = wp->w_width - col_off - strsize + room;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100330 if (added < 0)
331 added = 0;
332 else
333 n_used = *n_extra;
334 }
335 else
336 added = 0;
337 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100338
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100339 // With 'nowrap' add one to show the "extends" character if needed (it
340 // doesn't show if the text just fits).
341 if (!wp->w_p_wrap
342 && n_used < *n_extra
343 && wp->w_lcs_chars.ext != NUL
344 && wp->w_p_list)
345 ++n_used;
346
347 // add 1 for NUL, 2 for when '…' is used
348 if (n_attr != NULL)
349 l = alloc(n_used + added + padding + 3);
350 if (n_attr == NULL || l != NULL)
351 {
352 int off = 0;
353
354 if (n_attr != NULL)
355 {
356 vim_memset(l, ' ', added);
357 off += added;
358 if (padding > 0)
359 {
360 vim_memset(l + off, ' ', padding);
361 off += padding;
362 }
363 vim_strncpy(l + off, *p_extra, n_used);
364 off += n_used;
365 }
366 else
367 {
368 off = added + padding + n_used;
369 cells += added + padding;
370 }
371 if (n_attr != NULL)
372 {
373 if (n_used < *n_extra && wp->w_p_wrap)
374 {
375 char_u *lp = l + off - 1;
376
377 if (has_mbyte)
378 {
379 // change last character to '…'
380 lp -= (*mb_head_off)(l, lp);
381 STRCPY(lp, "…");
382 n_used = lp - l + 3 - padding;
383 }
384 else
385 // change last character to '>'
386 *lp = '>';
387 }
388 *p_extra = l;
389 *n_extra = n_used + added + padding;
390 *n_attr = mb_charlen(*p_extra);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100391 *n_attr_skip = added + padding + col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100392 }
393 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100394 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100395
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100396 if (n_attr == NULL)
397 return cells;
398 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200399}
400#endif
401
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100402/*
403 * Called when finished with the line: draw the screen line and handle any
404 * highlighting until the right of the window.
405 */
406 static void
407draw_screen_line(win_T *wp, winlinevars_T *wlv)
408{
409#ifdef FEAT_SYN_HL
410 long v;
411
412 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
413 if (wp->w_p_wrap)
414 v = wp->w_skipcol;
415 else
416 v = wp->w_leftcol;
417
418 // check if line ends before left margin
419 if (wlv->vcol < v + wlv->col - win_col_off(wp))
420 wlv->vcol = v + wlv->col - win_col_off(wp);
421# ifdef FEAT_CONCEAL
422 // Get rid of the boguscols now, we want to draw until the right
423 // edge for 'cursorcolumn'.
424 wlv->col -= wlv->boguscols;
425 wlv->boguscols = 0;
426# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
427# else
428# define VCOL_HLC (wlv->vcol)
429# endif
430
431 if (wlv->draw_color_col)
432 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
433
434 if (((wp->w_p_cuc
435 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
436 && (int)wp->w_virtcol <
437 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
438 && wlv->lnum != wp->w_cursor.lnum)
439 || wlv->draw_color_col
440 || wlv->win_attr != 0)
441# ifdef FEAT_RIGHTLEFT
442 && !wp->w_p_rl
443# endif
444 )
445 {
446 int rightmost_vcol = 0;
447 int i;
448
449 if (wp->w_p_cuc)
450 rightmost_vcol = wp->w_virtcol;
451 if (wlv->draw_color_col)
452 // determine rightmost colorcolumn to possibly draw
453 for (i = 0; wlv->color_cols[i] >= 0; ++i)
454 if (rightmost_vcol < wlv->color_cols[i])
455 rightmost_vcol = wlv->color_cols[i];
456
457 while (wlv->col < wp->w_width)
458 {
459 ScreenLines[wlv->off] = ' ';
460 if (enc_utf8)
461 ScreenLinesUC[wlv->off] = 0;
462 ScreenCols[wlv->off] = MAXCOL;
463 ++wlv->col;
464 if (wlv->draw_color_col)
465 wlv->draw_color_col = advance_color_col(
466 VCOL_HLC, &wlv->color_cols);
467
468 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
469 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
470 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
471 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
472 else
473 ScreenAttrs[wlv->off++] = wlv->win_attr;
474
475 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
476 break;
477
478 ++wlv->vcol;
479 }
480 }
481#endif
482
483 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
484 wp->w_width, wlv->screen_line_flags);
485 ++wlv->row;
486 ++wlv->screen_row;
487}
488#undef VCOL_HLC
489
490/*
491 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100492 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100493 */
494 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100495win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100496{
497 wlv->col = 0;
498 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
499
500#ifdef FEAT_RIGHTLEFT
501 if (wp->w_p_rl)
502 {
503 // Rightleft window: process the text in the normal direction, but put
504 // it in current_ScreenLine[] from right to left. Start at the
505 // rightmost column of the window.
506 wlv->col = wp->w_width - 1;
507 wlv->off += wlv->col;
508 wlv->screen_line_flags |= SLF_RIGHTLEFT;
509 }
510#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100511 if (save_extra)
512 {
513 // reset the drawing state for the start of a wrapped line
514 wlv->draw_state = WL_START;
515 wlv->saved_n_extra = wlv->n_extra;
516 wlv->saved_p_extra = wlv->p_extra;
517 wlv->saved_c_extra = wlv->c_extra;
518 wlv->saved_c_final = wlv->c_final;
519#ifdef FEAT_SYN_HL
520 if (!(wlv->cul_screenline
521# ifdef FEAT_DIFF
522 && wlv->diff_hlf == (hlf_T)0
523# endif
524 ))
525 wlv->saved_char_attr = wlv->char_attr;
526 else
527#endif
528 wlv->saved_char_attr = 0;
529 wlv->n_extra = 0;
530 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100531}
532
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200533/*
534 * Display line "lnum" of window 'wp' on the screen.
535 * Start at row "startrow", stop when "endrow" is reached.
536 * wp->w_virtcol needs to be valid.
537 *
538 * Return the number of last row the line occupies.
539 */
540 int
541win_line(
542 win_T *wp,
543 linenr_T lnum,
544 int startrow,
545 int endrow,
546 int nochange UNUSED, // not updating for changed text
547 int number_only) // only update the number column
548{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100549 winlinevars_T wlv; // variables passed between functions
550
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200551 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200552#ifdef FEAT_LINEBREAK
553 long vcol_sbr = -1; // virtual column after showbreak
554#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100555 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200556 char_u *line; // current line
557 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200558
559 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200560 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100561#ifdef FEAT_PROP_POPUP
562 char_u *p_extra_free2 = NULL; // another p_extra to be freed
563#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200564 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000565#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000566 int in_linebreak = FALSE; // n_extra set for showing linebreak
567#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200568 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100569 // displaying eol at end-of-line
570 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000571 int lcs_prec_todo = wp->w_lcs_chars.prec;
572 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200573
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100574 int n_attr = 0; // chars with special attr
575 int n_attr_skip = 0; // chars to skip before using extra_attr
576 int saved_attr2 = 0; // char_attr saved for n_attr
577 int n_attr3 = 0; // chars with overruling special attr
578 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200579
580 int n_skip = 0; // nr of chars to skip for 'nowrap'
581
582 int fromcol = -10; // start of inverting
583 int tocol = MAXCOL; // end of inverting
584 int fromcol_prev = -2; // start of inverting after cursor
585 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200586 int lnum_in_visual_area = FALSE;
587 pos_T pos;
588 long v;
589
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200590 int attr_pri = FALSE; // char_attr has priority
591 int area_highlighting = FALSE; // Visual or incsearch highlighting
592 // in this line
593 int vi_attr = 0; // attributes for Visual and incsearch
594 // highlighting
595 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200596 int area_attr = 0; // attributes desired by highlighting
597 int search_attr = 0; // attributes desired by 'hlsearch'
598#ifdef FEAT_SYN_HL
599 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
600 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200601 int prev_syntax_col = -1; // column of prev_syntax_attr
602 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200603 int has_syntax = FALSE; // this buffer has syntax highl.
604 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200605#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100606#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200607 int text_prop_count;
608 int text_prop_next = 0; // next text property to use
609 textprop_T *text_props = NULL;
610 int *text_prop_idxs = NULL;
611 int text_props_active = 0;
612 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100613 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200614 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100615 int text_prop_attr_comb = 0; // text_prop_attr combined with
616 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100617 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100618 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100619 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100620 int saved_search_attr = 0; // search_attr to be used when n_extra
621 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200622#endif
623#ifdef FEAT_SPELL
624 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000625 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200626# define SPWORDLEN 150
627 char_u nextline[SPWORDLEN * 2];// text with start of the next line
628 int nextlinecol = 0; // column where nextline[] starts
629 int nextline_idx = 0; // index in nextline[] where next line
630 // starts
631 int spell_attr = 0; // attributes desired by spelling
632 int word_end = 0; // last byte with same spell_attr
633 static linenr_T checked_lnum = 0; // line number for "checked_col"
634 static int checked_col = 0; // column in "checked_lnum" up to which
635 // there are no spell errors
636 static int cap_col = -1; // column to check for Cap word
637 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
638 int cur_checked_col = 0; // checked column for current line
639#endif
640 int extra_check = 0; // has extra highlighting
641 int multi_attr = 0; // attributes desired by multibyte
642 int mb_l = 1; // multi-byte byte length
643 int mb_c = 0; // decoded multi-byte character
644 int mb_utf8 = FALSE; // screen char is UTF-8 char
645 int u8cc[MAX_MCO]; // composing UTF-8 chars
646#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
647 int filler_lines = 0; // nr of filler lines to be drawn
648 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000649#else
650# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200651#endif
652#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200653 int change_start = MAXCOL; // first col of changed area
654 int change_end = -1; // last col of changed area
655#endif
656 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100657 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200658 int in_multispace = FALSE; // in multiple consecutive spaces
659 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200660#ifdef FEAT_LINEBREAK
661 int need_showbreak = FALSE; // overlong line, skipping first x
662 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100663 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200664#endif
665#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
666 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
667# define LINE_ATTR
668 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100669 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200670#endif
671#ifdef FEAT_SIGNS
672 int sign_present = FALSE;
673 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000674 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200675#endif
676#ifdef FEAT_ARABIC
677 int prev_c = 0; // previous Arabic character
678 int prev_c1 = 0; // first composing char for prev_c
679#endif
680#if defined(LINE_ATTR)
681 int did_line_attr = 0;
682#endif
683#ifdef FEAT_TERMINAL
684 int get_term_attr = FALSE;
685#endif
686#ifdef FEAT_SYN_HL
687 int cul_attr = 0; // set when 'cursorline' active
688
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200689 // margin columns for the screen line, needed for when 'cursorlineopt'
690 // contains "screenline"
691 int left_curline_col = 0;
692 int right_curline_col = 0;
693#endif
694
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200695#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
696 int feedback_col = 0;
697 int feedback_old_attr = -1;
698#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200699
700#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
701 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000702 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200703#endif
704#ifdef FEAT_CONCEAL
705 int syntax_flags = 0;
706 int syntax_seqnr = 0;
707 int prev_syntax_id = 0;
708 int conceal_attr = HL_ATTR(HLF_CONCEAL);
709 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200710 int did_wcol = FALSE;
711 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100712# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200713# define FIX_FOR_BOGUSCOLS \
714 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100715 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100716 wlv.vcol -= wlv.vcol_off; \
717 wlv.vcol_off = 0; \
718 wlv.col -= wlv.boguscols; \
719 old_boguscols = wlv.boguscols; \
720 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200721 }
722#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100723# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200724#endif
725
726 if (startrow > endrow) // past the end already!
727 return startrow;
728
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100729 CLEAR_FIELD(wlv);
730
731 wlv.lnum = lnum;
732 wlv.startrow = startrow;
733 wlv.row = startrow;
734 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200735
736 if (!number_only)
737 {
738 // To speed up the loop below, set extra_check when there is linebreak,
739 // trailing white space and/or syntax processing to be done.
740#ifdef FEAT_LINEBREAK
741 extra_check = wp->w_p_lbr;
742#endif
743#ifdef FEAT_SYN_HL
744 if (syntax_present(wp) && !wp->w_s->b_syn_error
745# ifdef SYN_TIME_LIMIT
746 && !wp->w_s->b_syn_slow
747# endif
748 )
749 {
750 // Prepare for syntax highlighting in this line. When there is an
751 // error, stop syntax highlighting.
752 save_did_emsg = did_emsg;
753 did_emsg = FALSE;
754 syntax_start(wp, lnum);
755 if (did_emsg)
756 wp->w_s->b_syn_error = TRUE;
757 else
758 {
759 did_emsg = save_did_emsg;
760#ifdef SYN_TIME_LIMIT
761 if (!wp->w_s->b_syn_slow)
762#endif
763 {
764 has_syntax = TRUE;
765 extra_check = TRUE;
766 }
767 }
768 }
769
770 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100771 wlv.color_cols = wp->w_p_cc_cols;
772 if (wlv.color_cols != NULL)
773 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200774#endif
775
776#ifdef FEAT_TERMINAL
777 if (term_show_buffer(wp->w_buffer))
778 {
779 extra_check = TRUE;
780 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100781 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200782 }
783#endif
784
785#ifdef FEAT_SPELL
786 if (wp->w_p_spell
787 && *wp->w_s->b_p_spl != NUL
788 && wp->w_s->b_langp.ga_len > 0
789 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
790 {
791 // Prepare for spell checking.
792 has_spell = TRUE;
793 extra_check = TRUE;
794
795 // Get the start of the next line, so that words that wrap to the
796 // next line are found too: "et<line-break>al.".
797 // Trick: skip a few chars for C/shell/Vim comments
798 nextline[SPWORDLEN] = NUL;
799 if (lnum < wp->w_buffer->b_ml.ml_line_count)
800 {
801 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
802 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
803 }
804
805 // When a word wrapped from the previous line the start of the
806 // current line is valid.
807 if (lnum == checked_lnum)
808 cur_checked_col = checked_col;
809 checked_lnum = 0;
810
811 // When there was a sentence end in the previous line may require a
812 // word starting with capital in this line. In line 1 always check
813 // the first word.
814 if (lnum != capcol_lnum)
815 cap_col = -1;
816 if (lnum == 1)
817 cap_col = 0;
818 capcol_lnum = 0;
819 }
820#endif
821
822 // handle Visual active in this window
823 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
824 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100825 pos_T *top, *bot;
826
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200827 if (LTOREQ_POS(curwin->w_cursor, VIsual))
828 {
829 // Visual is after curwin->w_cursor
830 top = &curwin->w_cursor;
831 bot = &VIsual;
832 }
833 else
834 {
835 // Visual is before curwin->w_cursor
836 top = &VIsual;
837 bot = &curwin->w_cursor;
838 }
839 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
840 if (VIsual_mode == Ctrl_V)
841 {
842 // block mode
843 if (lnum_in_visual_area)
844 {
845 fromcol = wp->w_old_cursor_fcol;
846 tocol = wp->w_old_cursor_lcol;
847 }
848 }
849 else
850 {
851 // non-block mode
852 if (lnum > top->lnum && lnum <= bot->lnum)
853 fromcol = 0;
854 else if (lnum == top->lnum)
855 {
856 if (VIsual_mode == 'V') // linewise
857 fromcol = 0;
858 else
859 {
860 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
861 if (gchar_pos(top) == NUL)
862 tocol = fromcol + 1;
863 }
864 }
865 if (VIsual_mode != 'V' && lnum == bot->lnum)
866 {
867 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
868 {
869 fromcol = -10;
870 tocol = MAXCOL;
871 }
872 else if (bot->col == MAXCOL)
873 tocol = MAXCOL;
874 else
875 {
876 pos = *bot;
877 if (*p_sel == 'e')
878 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
879 else
880 {
881 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
882 ++tocol;
883 }
884 }
885 }
886 }
887
888 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200889 if (!highlight_match && lnum == curwin->w_cursor.lnum
890 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200891#ifdef FEAT_GUI
892 && !gui.in_use
893#endif
894 )
895 noinvcur = TRUE;
896
897 // if inverting in this line set area_highlighting
898 if (fromcol >= 0)
899 {
900 area_highlighting = TRUE;
901 vi_attr = HL_ATTR(HLF_V);
902#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
903 if ((clip_star.available && !clip_star.owned
904 && clip_isautosel_star())
905 || (clip_plus.available && !clip_plus.owned
906 && clip_isautosel_plus()))
907 vi_attr = HL_ATTR(HLF_VNC);
908#endif
909 }
910 }
911
912 // handle 'incsearch' and ":s///c" highlighting
913 else if (highlight_match
914 && wp == curwin
915 && lnum >= curwin->w_cursor.lnum
916 && lnum <= curwin->w_cursor.lnum + search_match_lines)
917 {
918 if (lnum == curwin->w_cursor.lnum)
919 getvcol(curwin, &(curwin->w_cursor),
920 (colnr_T *)&fromcol, NULL, NULL);
921 else
922 fromcol = 0;
923 if (lnum == curwin->w_cursor.lnum + search_match_lines)
924 {
925 pos.lnum = lnum;
926 pos.col = search_match_endcol;
927 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
928 }
929 else
930 tocol = MAXCOL;
931 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100932 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200933 tocol = fromcol + 1;
934 area_highlighting = TRUE;
935 vi_attr = HL_ATTR(HLF_I);
936 }
937 }
938
939#ifdef FEAT_DIFF
940 filler_lines = diff_check(wp, lnum);
941 if (filler_lines < 0)
942 {
943 if (filler_lines == -1)
944 {
945 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100946 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100948 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200949 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100950 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200951 }
952 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100953 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200954 filler_lines = 0;
955 area_highlighting = TRUE;
956 }
957 if (lnum == wp->w_topline)
958 filler_lines = wp->w_topfill;
959 filler_todo = filler_lines;
960#endif
961
962#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100963 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000964 if (sign_present)
965 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200966#endif
967
968#ifdef LINE_ATTR
969# ifdef FEAT_SIGNS
970 // If this line has a sign with line highlighting set line_attr.
971 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200972 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200973# endif
974# if defined(FEAT_QUICKFIX)
975 // Highlight the current line in the quickfix window.
976 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
977 line_attr = HL_ATTR(HLF_QFL);
978# endif
979 if (line_attr != 0)
980 area_highlighting = TRUE;
981#endif
982
983 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
984 ptr = line;
985
986#ifdef FEAT_SPELL
987 if (has_spell && !number_only)
988 {
989 // For checking first word with a capital skip white space.
990 if (cap_col == 0)
991 cap_col = getwhitecols(line);
992
993 // To be able to spell-check over line boundaries copy the end of the
994 // current line into nextline[]. Above the start of the next line was
995 // copied to nextline[SPWORDLEN].
996 if (nextline[SPWORDLEN] == NUL)
997 {
998 // No next line or it is empty.
999 nextlinecol = MAXCOL;
1000 nextline_idx = 0;
1001 }
1002 else
1003 {
1004 v = (long)STRLEN(line);
1005 if (v < SPWORDLEN)
1006 {
1007 // Short line, use it completely and append the start of the
1008 // next line.
1009 nextlinecol = 0;
1010 mch_memmove(nextline, line, (size_t)v);
1011 STRMOVE(nextline + v, nextline + SPWORDLEN);
1012 nextline_idx = v + 1;
1013 }
1014 else
1015 {
1016 // Long line, use only the last SPWORDLEN bytes.
1017 nextlinecol = v - SPWORDLEN;
1018 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1019 nextline_idx = SPWORDLEN + 1;
1020 }
1021 }
1022 }
1023#endif
1024
1025 if (wp->w_p_list)
1026 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001027 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001028 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001029 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001030 || wp->w_lcs_chars.trail
1031 || wp->w_lcs_chars.lead
1032 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001034
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001036 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037 {
1038 trailcol = (colnr_T)STRLEN(ptr);
1039 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1040 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001041 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001043 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001044 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001045 {
1046 leadcol = 0;
1047 while (VIM_ISWHITE(ptr[leadcol]))
1048 ++leadcol;
1049 if (ptr[leadcol] == NUL)
1050 // in a line full of spaces all of them are treated as trailing
1051 leadcol = (colnr_T)0;
1052 else
1053 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001054 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001055 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056 }
1057
1058 wcr_attr = get_wcr_attr(wp);
1059 if (wcr_attr != 0)
1060 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001061 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062 area_highlighting = TRUE;
1063 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001064
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001065#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001067 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068#endif
1069
1070 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1071 // first character to be displayed.
1072 if (wp->w_p_wrap)
1073 v = wp->w_skipcol;
1074 else
1075 v = wp->w_leftcol;
1076 if (v > 0 && !number_only)
1077 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001078 char_u *prev_ptr = ptr;
1079 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001080 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001082 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001083 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001084 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001085 charsize = win_lbr_chartabsize(&cts, NULL);
1086 cts.cts_vcol += charsize;
1087 prev_ptr = cts.cts_ptr;
1088 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001090 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001091 ptr = cts.cts_ptr;
1092 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093
1094 // When:
1095 // - 'cuc' is set, or
1096 // - 'colorcolumn' is set, or
1097 // - 'virtualedit' is set, or
1098 // - the visual mode is active,
1099 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001100 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001102 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103#endif
1104 virtual_active() ||
1105 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001106 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107
1108 // Handle a character that's not completely on the screen: Put ptr at
1109 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001110 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001112 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 ptr = prev_ptr;
1114 // If the character fits on the screen, don't need to skip it.
1115 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001116 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1117 && wlv.col == 0)
1118 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 }
1120
1121 // Adjust for when the inverted text is before the screen,
1122 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001123 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001125 else if (fromcol >= 0 && fromcol < wlv.vcol)
1126 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127
1128#ifdef FEAT_LINEBREAK
1129 // When w_skipcol is non-zero, first line needs 'showbreak'
1130 if (wp->w_p_wrap)
1131 need_showbreak = TRUE;
1132#endif
1133#ifdef FEAT_SPELL
1134 // When spell checking a word we need to figure out the start of the
1135 // word and if it's badly spelled or not.
1136 if (has_spell)
1137 {
1138 int len;
1139 colnr_T linecol = (colnr_T)(ptr - line);
1140 hlf_T spell_hlf = HLF_COUNT;
1141
1142 pos = wp->w_cursor;
1143 wp->w_cursor.lnum = lnum;
1144 wp->w_cursor.col = linecol;
1145 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1146
1147 // spell_move_to() may call ml_get() and make "line" invalid
1148 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1149 ptr = line + linecol;
1150
1151 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1152 {
1153 // no bad word found at line start, don't check until end of a
1154 // word
1155 spell_hlf = HLF_COUNT;
1156 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1157 }
1158 else
1159 {
1160 // bad word found, use attributes until end of word
1161 word_end = wp->w_cursor.col + len + 1;
1162
1163 // Turn index into actual attributes.
1164 if (spell_hlf != HLF_COUNT)
1165 spell_attr = highlight_attr[spell_hlf];
1166 }
1167 wp->w_cursor = pos;
1168
1169# ifdef FEAT_SYN_HL
1170 // Need to restart syntax highlighting for this line.
1171 if (has_syntax)
1172 syntax_start(wp, lnum);
1173# endif
1174 }
1175#endif
1176 }
1177
1178 // Correct highlighting for cursor that can't be disabled.
1179 // Avoids having to check this for each character.
1180 if (fromcol >= 0)
1181 {
1182 if (noinvcur)
1183 {
1184 if ((colnr_T)fromcol == wp->w_virtcol)
1185 {
1186 // highlighting starts at cursor, let it start just after the
1187 // cursor
1188 fromcol_prev = fromcol;
1189 fromcol = -1;
1190 }
1191 else if ((colnr_T)fromcol < wp->w_virtcol)
1192 // restart highlighting after the cursor
1193 fromcol_prev = wp->w_virtcol;
1194 }
1195 if (fromcol >= tocol)
1196 fromcol = -1;
1197 }
1198
1199#ifdef FEAT_SEARCH_EXTRA
1200 if (!number_only)
1201 {
1202 v = (long)(ptr - line);
1203 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1204 &line, &screen_search_hl,
1205 &search_attr);
1206 ptr = line + v; // "line" may have been updated
1207 }
1208#endif
1209
1210#ifdef FEAT_SYN_HL
1211 // Cursor line highlighting for 'cursorline' in the current window.
1212 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1213 {
1214 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001215 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 if (!(wp == curwin && VIsual_active)
1217 && wp->w_p_culopt_flags != CULOPT_NBR)
1218 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001219 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1221
1222 // Only set line_attr here when "screenline" is not present in
1223 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001224 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 {
1226 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001227# ifdef FEAT_SIGNS
1228 // Combine the 'cursorline' and sign highlighting, depending on
1229 // the sign priority.
1230 if (sign_present && sattr.sat_linehl > 0)
1231 {
1232 if (sattr.sat_priority >= 100)
1233 line_attr = hl_combine_attr(cul_attr, line_attr);
1234 else
1235 line_attr = hl_combine_attr(line_attr, cul_attr);
1236 }
1237 else
1238# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001239# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001240 // let the line attribute overrule 'cursorline', otherwise
1241 // it disappears when both have background set;
1242 // 'cursorline' can use underline or bold to make it show
1243 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001244# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001245 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001246# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247 }
1248 else
1249 {
1250 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1252 }
1253 area_highlighting = TRUE;
1254 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 }
1256#endif
1257
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001258#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259 {
1260 char_u *prop_start;
1261
1262 text_prop_count = get_text_props(wp->w_buffer, lnum,
1263 &prop_start, FALSE);
1264 if (text_prop_count > 0)
1265 {
1266 // Make a copy of the properties, so that they are properly
1267 // aligned.
1268 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1269 if (text_props != NULL)
1270 mch_memmove(text_props, prop_start,
1271 text_prop_count * sizeof(textprop_T));
1272
1273 // Allocate an array for the indexes.
1274 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001275 if (text_prop_idxs == NULL)
1276 VIM_CLEAR(text_props);
1277
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 area_highlighting = TRUE;
1279 extra_check = TRUE;
1280 }
1281 }
1282#endif
1283
Bram Moolenaar1306b362022-08-06 15:59:06 +01001284 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285
1286 // Repeat for the whole displayed line.
1287 for (;;)
1288 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001289 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001291 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292#endif
1293#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001294 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001296
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001298 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001300#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001301 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001302 {
1303 cul_attr = 0;
1304 line_attr = line_attr_save;
1305 }
1306#endif
1307
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001309 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001311 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001312 if (cmdwin_type != 0 && wp == curwin)
1313 {
1314 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001315 wlv.n_extra = 1;
1316 wlv.c_extra = cmdwin_type;
1317 wlv.c_final = NUL;
1318 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 }
1320 }
1321#endif
1322
1323#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001324 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 {
1326 int fdc = compute_foldcolumn(wp, 0);
1327
Bram Moolenaar1306b362022-08-06 15:59:06 +01001328 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329 if (fdc > 0)
1330 {
1331 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1332 // already be in use.
1333 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001334 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 if (p_extra_free != NULL)
1336 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001337 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001338 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001339 p_extra_free[wlv.n_extra] = NUL;
1340 wlv.p_extra = p_extra_free;
1341 wlv.c_extra = NUL;
1342 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001343 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001344 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001345 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1346 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001347 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001348 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 }
1350 }
1351 }
1352#endif
1353
1354#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001355 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001357 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 // Show the sign column when there are any signs in this
1359 // buffer or when using Netbeans.
1360 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001361 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1362 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 }
1364#endif
1365
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001368 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 // Display the absolute or relative line number. After the
1370 // first fill with blanks when the 'n' flag isn't in 'cpo'
1371 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001372 && (wlv.row == startrow + filler_lines
1373 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 {
1375#ifdef FEAT_SIGNS
1376 // If 'signcolumn' is set to 'number' and a sign is present
1377 // in 'lnum', then display the sign instead of the line
1378 // number.
1379 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1380 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001381 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1382 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 else
1384#endif
1385 {
1386 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001387 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 {
1389 long num;
1390 char *fmt = "%*ld ";
1391
1392 if (wp->w_p_nu && !wp->w_p_rnu)
1393 // 'number' + 'norelativenumber'
1394 num = (long)lnum;
1395 else
1396 {
1397 // 'relativenumber', don't use negative numbers
1398 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1399 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1400 {
1401 // 'number' + 'relativenumber'
1402 num = lnum;
1403 fmt = "%-*ld ";
1404 }
1405 }
1406
1407 sprintf((char *)extra, fmt,
1408 number_width(wp), num);
1409 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001410 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1411 ++wlv.p_extra)
1412 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413#ifdef FEAT_RIGHTLEFT
1414 if (wp->w_p_rl) // reverse line numbers
1415 {
1416 char_u *p1, *p2;
1417 int t;
1418
1419 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001420 p2 = skipwhite(extra);
1421 p2 = skiptowhite(p2) - 1;
1422 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 {
1424 t = *p1;
1425 *p1 = *p2;
1426 *p2 = t;
1427 }
1428 }
1429#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001430 wlv.p_extra = extra;
1431 wlv.c_extra = NUL;
1432 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 }
1434 else
1435 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001436 wlv.c_extra = ' ';
1437 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001439 wlv.n_extra = number_width(wp) + 1;
1440 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441#ifdef FEAT_SYN_HL
1442 // When 'cursorline' is set highlight the line number of
1443 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001444 // When 'cursorlineopt' does not have "line" only
1445 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 // TODO: Can we use CursorLine instead of CursorLineNr
1447 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001448 if (wp->w_p_cul
1449 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001451 && (wlv.row == startrow + filler_lines
1452 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001453 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001454 wlv.char_attr = hl_combine_attr(wcr_attr,
1455 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001457 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1458 && HL_ATTR(HLF_LNA) != 0)
1459 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001460 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001461 HL_ATTR(HLF_LNA));
1462 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1463 && HL_ATTR(HLF_LNB) != 0)
1464 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001465 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001466 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 }
James McCoya80aad72021-12-22 19:45:28 +00001468#ifdef FEAT_SIGNS
1469 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001470 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001471#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472 }
1473 }
1474
1475#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001476 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1477 && wlv.n_extra == 0
1478 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001480 wlv.draw_state = WL_BRI;
1481 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1482 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001484 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485
1486 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001487 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001489 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001491 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492# ifdef FEAT_DIFF
1493 && filler_lines == 0
1494# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001495# ifdef FEAT_PROP_POPUP
1496 && !dont_use_showbreak
1497# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 )
1499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001500 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001502 if (wlv.diff_hlf != (hlf_T)0)
1503 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001504# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001505 wlv.p_extra = NULL;
1506 wlv.c_extra = ' ';
1507 wlv.c_final = NUL;
1508 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001510 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001511 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001512 wlv.n_extra -= win_col_off2(wp);
1513 if (wlv.n_extra < 0)
1514 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001515 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001516 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001517 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 // Correct end of highlighted area for 'breakindent',
1519 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001520 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001521 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 }
1523 }
1524#endif
1525
1526#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001527 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001529 char_u *sbr;
1530
Bram Moolenaar1306b362022-08-06 15:59:06 +01001531 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532# ifdef FEAT_DIFF
1533 if (filler_todo > 0)
1534 {
1535 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001536 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001538 wlv.c_extra = '-';
1539 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 }
1541 else
1542 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001543 wlv.c_extra = wp->w_fill_chars.diff;
1544 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 }
1546# ifdef FEAT_RIGHTLEFT
1547 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001548 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 else
1550# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001551 wlv.n_extra = wp->w_width - wlv.col;
1552 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 }
1554# endif
1555# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001556 sbr = get_showbreak_value(wp);
1557 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 {
1559 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001560 wlv.p_extra = sbr;
1561 wlv.c_extra = NUL;
1562 wlv.c_final = NUL;
1563 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001564 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1565 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001566 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 // Correct end of highlighted area for 'showbreak',
1568 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001569 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001570 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001572 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1573 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574# ifdef FEAT_SYN_HL
1575 // combine 'showbreak' with 'cursorline'
1576 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001577 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1578 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579# endif
1580 }
1581# endif
1582 }
1583#endif
1584
Bram Moolenaar1306b362022-08-06 15:59:06 +01001585 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001587 wlv.draw_state = WL_LINE;
1588 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 {
1590 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001591 wlv.n_extra = wlv.saved_n_extra;
1592 wlv.c_extra = wlv.saved_c_extra;
1593 wlv.c_final = wlv.saved_c_final;
1594 wlv.p_extra = wlv.saved_p_extra;
1595 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 }
1597 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001598 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 }
1600 }
1601#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001602 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001603 && wlv.vcol >= left_curline_col
1604 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001606 cul_attr = HL_ATTR(HLF_CUL);
1607 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 }
1609#endif
1610
1611 // When still displaying '$' of change command, stop at cursor.
1612 // When only displaying the (relative) line number and that's done,
1613 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001614 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001615 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001616 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617#ifdef FEAT_DIFF
1618 && filler_todo <= 0
1619#endif
1620 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001622 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1623 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001624 // Pretend we have finished updating the window. Except when
1625 // 'cursorcolumn' is set.
1626#ifdef FEAT_SYN_HL
1627 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001628 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629 else
1630#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001631 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 break;
1633 }
1634
Bram Moolenaar1306b362022-08-06 15:59:06 +01001635 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636 {
1637 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001638 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001639 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640 && (*mb_ptr2cells)(ptr) > 1)
1641 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001642 && vcol_prev < wlv.vcol // not at margin
1643 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 area_attr = vi_attr; // start highlighting
1645 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001646 && (wlv.vcol == tocol
1647 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 area_attr = 0; // stop highlighting
1649
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001650#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651 if (text_props != NULL)
1652 {
1653 int pi;
1654 int bcol = (int)(ptr - line);
1655
Bram Moolenaar1306b362022-08-06 15:59:06 +01001656 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001657# ifdef FEAT_LINEBREAK
1658 && !in_linebreak
1659# endif
1660 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 --bcol; // still working on the previous char, e.g. Tab
1662
1663 // Check if any active property ends.
1664 for (pi = 0; pi < text_props_active; ++pi)
1665 {
1666 int tpi = text_prop_idxs[pi];
1667
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001668 if (text_props[tpi].tp_col != MAXCOL
1669 && bcol >= text_props[tpi].tp_col - 1
1670 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 {
1672 if (pi + 1 < text_props_active)
1673 mch_memmove(text_prop_idxs + pi,
1674 text_prop_idxs + pi + 1,
1675 sizeof(int)
1676 * (text_props_active - (pi + 1)));
1677 --text_props_active;
1678 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001679# ifdef FEAT_LINEBREAK
1680 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001681 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001682 syntax_attr = 0;
1683# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 }
1685 }
1686
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001687# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001688 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001689 // not on the next char yet, don't start another prop
1690 --bcol;
1691# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001693 // With 'nowrap' and not in the first screen line only "below"
1694 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001696 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001697 ? (*ptr == NUL
1698 && (wp->w_p_wrap
1699 || wlv.row == startrow
1700 || (text_props[text_prop_next].tp_flags
1701 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001702 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001703 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001704 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001705 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1706 {
1707 // first display the '$' after the line
1708 text_prop_follows = TRUE;
1709 break;
1710 }
1711 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001712 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001713 + text_props[text_prop_next].tp_len)
1714 text_prop_idxs[text_props_active++] = text_prop_next;
1715 ++text_prop_next;
1716 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001718 if (wlv.n_extra == 0 || !extra_for_textprop)
1719 {
1720 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001721 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001722 text_prop_flags = 0;
1723 text_prop_type = NULL;
1724 text_prop_id = 0;
1725 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001728 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001729 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001730 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001731
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 // Sort the properties on priority and/or starting last.
1733 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001734 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001735 sort_text_props(wp->w_buffer, text_props,
1736 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737
1738 for (pi = 0; pi < text_props_active; ++pi)
1739 {
1740 int tpi = text_prop_idxs[pi];
1741 proptype_T *pt = text_prop_type_by_id(
1742 wp->w_buffer, text_props[tpi].tp_type);
1743
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001744 if (pt != NULL && (pt->pt_hl_id > 0
1745 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001746 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001748 if (pt->pt_hl_id > 0)
1749 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 text_prop_type = pt;
1751 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001752 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001753 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001754 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001755 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001756 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 }
1758 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001759 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001760 && -text_prop_id
1761 <= wp->w_buffer->b_textprop_text.ga_len)
1762 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001763 textprop_T *tp = &text_props[used_tpi];
1764 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001765 ->b_textprop_text.ga_data)[
1766 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001767
1768 // reset the ID in the copy to avoid it being used
1769 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001770 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001771
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001772 if (p != NULL)
1773 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001774 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001775 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001776 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001777 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001778 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1779 int padding = tp->tp_col == MAXCOL
1780 && tp->tp_len > 1
1781 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001782
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001783 // Insert virtual text before the current
1784 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001785 wlv.p_extra = p;
1786 wlv.c_extra = NUL;
1787 wlv.c_final = NUL;
1788 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001789 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001790 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001791 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001792 saved_search_attr = search_attr;
1793 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001794 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001795 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001796 if (*ptr == NUL)
1797 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001798 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001799#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001800 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001801 {
1802 // no 'showbreak' before "below" text property
1803 // or after "right" text property
1804 need_showbreak = FALSE;
1805 dont_use_showbreak = TRUE;
1806 }
1807#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001808 // Keep in sync with where
1809 // textprop_size_after_trunc() is called in
1810 // win_lbr_chartabsize().
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001811 if ((right || below || !wrap || padding > 0)
1812 && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001813 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001814 char_u *prev_p_extra = wlv.p_extra;
1815 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001816
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001817 // Take care of padding, right-align and
1818 // truncation.
1819 // Shared with win_lbr_chartabsize(), must do
1820 // exactly the same.
1821 start_line = text_prop_position(wp, tp,
1822 wlv.col,
1823 &wlv.n_extra, &wlv.p_extra,
1824 &n_attr, &n_attr_skip);
1825 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001826 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001827 // wlv.p_extra was allocated
1828 vim_free(p_extra_free2);
1829 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001830 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001831
1832 // When 'wrap' is off then for "below" we need
1833 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001834 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001835 {
1836 draw_screen_line(wp, &wlv);
1837
1838 // When line got too long for screen break
1839 // here.
1840 if (wlv.row == endrow)
1841 {
1842 ++wlv.row;
1843 break;
1844 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001845 win_line_start(wp, &wlv, TRUE);
1846 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001847 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001848 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001849 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001850
1851 // If another text prop follows the condition below at
1852 // the last window column must know.
1853 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001854 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001856 else if (text_prop_next < text_prop_count
1857 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001858 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1859 || (!wp->w_p_wrap
1860 && wlv.col == wp->w_width - 1
1861 && (text_props[text_prop_next].tp_flags
1862 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001863 // When at last-but-one character and a text property
1864 // follows after it, we may need to flush the line after
1865 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001866 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001867 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 }
1869#endif
1870
Bram Moolenaare38fc862022-08-11 17:24:50 +01001871#ifdef FEAT_SEARCH_EXTRA
1872 if (wlv.n_extra == 0)
1873 {
1874 // Check for start/end of 'hlsearch' and other matches.
1875 // After end, check for start/end of next match.
1876 // When another match, have to check for start again.
1877 v = (long)(ptr - line);
1878 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1879 &screen_search_hl, &has_match_conc,
1880 &match_conc, did_line_attr, lcs_eol_one,
1881 &on_last_col);
1882 ptr = line + v; // "line" may have been changed
1883 prev_ptr = ptr;
1884
1885 // Do not allow a conceal over EOL otherwise EOL will be missed
1886 // and bad things happen.
1887 if (*ptr == NUL)
1888 has_match_conc = 0;
1889 }
1890#endif
1891
1892#ifdef FEAT_DIFF
1893 if (wlv.diff_hlf != (hlf_T)0)
1894 {
1895 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1896 && wlv.n_extra == 0)
1897 wlv.diff_hlf = HLF_TXD; // changed text
1898 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1899 && wlv.n_extra == 0)
1900 wlv.diff_hlf = HLF_CHD; // changed line
1901 line_attr = HL_ATTR(wlv.diff_hlf);
1902 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1903 && wp->w_p_culopt_flags != CULOPT_NBR
1904 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1905 && wlv.vcol <= right_curline_col)))
1906 line_attr = hl_combine_attr(
1907 line_attr, HL_ATTR(HLF_CUL));
1908 }
1909#endif
1910
Bram Moolenaara74fda62019-10-19 17:38:03 +02001911#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001912 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001913 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001914 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001915# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001916 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001917 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001918# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001919 // Get syntax attribute.
1920 if (has_syntax)
1921 {
1922 // Get the syntax attribute for the character. If there
1923 // is an error, disable syntax highlighting.
1924 save_did_emsg = did_emsg;
1925 did_emsg = FALSE;
1926
1927 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001928 if (v == prev_syntax_col)
1929 // at same column again
1930 syntax_attr = prev_syntax_attr;
1931 else
1932 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001933# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001934 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001935# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001936 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001937# ifdef FEAT_SPELL
1938 has_spell ? &can_spell :
1939# endif
1940 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001941 prev_syntax_col = v;
1942 prev_syntax_attr = syntax_attr;
1943 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001944
Bram Moolenaar34390282019-10-16 14:38:26 +02001945 if (did_emsg)
1946 {
1947 wp->w_s->b_syn_error = TRUE;
1948 has_syntax = FALSE;
1949 syntax_attr = 0;
1950 }
1951 else
1952 did_emsg = save_did_emsg;
1953# ifdef SYN_TIME_LIMIT
1954 if (wp->w_s->b_syn_slow)
1955 has_syntax = FALSE;
1956# endif
1957
1958 // Need to get the line again, a multi-line regexp may
1959 // have made it invalid.
1960 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1961 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001962 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001963# ifdef FEAT_CONCEAL
1964 // no concealing past the end of the line, it interferes
1965 // with line highlighting
1966 if (*ptr == NUL)
1967 syntax_flags = 0;
1968 else
1969 syntax_flags = get_syntax_info(&syntax_seqnr);
1970# endif
1971 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001972 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001973# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001974 // Combine text property highlight into syntax highlight.
1975 if (text_prop_type != NULL)
1976 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001977 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001978 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1979 else
1980 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001981 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01001982 }
1983# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001984#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001985
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986 // Decide which of the highlight attributes to use.
1987 attr_pri = TRUE;
1988#ifdef LINE_ATTR
1989 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001990 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001991 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001992 if (!highlight_match)
1993 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_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 (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002000 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002001 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002002# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002003 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002004# endif
2005 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002006 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002007 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2008 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002009 {
2010 // Use line_attr when not in the Visual or 'incsearch' area
2011 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002012# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002013 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002014# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002015 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002016# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017 attr_pri = FALSE;
2018 }
2019#else
2020 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002021 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002023 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002024#endif
2025 else
2026 {
2027 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002029 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002030#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002031 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002032#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002034#ifdef FEAT_PROP_POPUP
2035 // override with text property highlight when "override" is TRUE
2036 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002037 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002038#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002040
2041 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002042 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002043 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002044 if (wlv.char_attr == 0)
2045 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002046 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002047 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002048 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049
2050 // Get the next character to put on the screen.
2051
2052 // The "p_extra" points to the extra stuff that is inserted to
2053 // represent special characters (non-printable stuff) and other
2054 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002055 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2057 // "p_extra[n_extra]".
2058 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002059 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002061 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002062 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002063 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2064 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2066 if (enc_utf8 && utf_char2len(c) > 1)
2067 {
2068 mb_utf8 = TRUE;
2069 u8cc[0] = 0;
2070 c = 0xc0;
2071 }
2072 else
2073 mb_utf8 = FALSE;
2074 }
2075 else
2076 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002077 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078 if (has_mbyte)
2079 {
2080 mb_c = c;
2081 if (enc_utf8)
2082 {
2083 // If the UTF-8 character is more than one byte:
2084 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002085 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002086 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002087 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002088 mb_l = 1;
2089 else if (mb_l > 1)
2090 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002091 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 mb_utf8 = TRUE;
2093 c = 0xc0;
2094 }
2095 }
2096 else
2097 {
2098 // if this is a DBCS character, put it in "mb_c"
2099 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002100 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002101 mb_l = 1;
2102 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002103 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002104 }
2105 if (mb_l == 0) // at the NUL at end-of-line
2106 mb_l = 1;
2107
2108 // If a double-width char doesn't fit display a '>' in the
2109 // last column.
2110 if ((
2111# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002112 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002114 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002115 && (*mb_char2cells)(mb_c) == 2)
2116 {
2117 c = '>';
2118 mb_c = c;
2119 mb_l = 1;
2120 mb_utf8 = FALSE;
2121 multi_attr = HL_ATTR(HLF_AT);
2122#ifdef FEAT_SYN_HL
2123 if (cul_attr)
2124 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2125#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002126 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002127
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 // put the pointer back to output the double-width
2129 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 ++wlv.n_extra;
2131 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 }
2133 else
2134 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002135 wlv.n_extra -= mb_l - 1;
2136 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137 }
2138 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002139 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002140 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002141 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002142#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002143 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002144 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002145 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002146 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002147 if (search_attr == 0)
2148 search_attr = saved_search_attr;
2149 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002150#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 }
2152 else
2153 {
2154#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002155 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002156#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002157 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002158
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159 // Get a character from the line itself.
2160 c = *ptr;
2161#ifdef FEAT_LINEBREAK
2162 c0 = *ptr;
2163#endif
2164 if (has_mbyte)
2165 {
2166 mb_c = c;
2167 if (enc_utf8)
2168 {
2169 // If the UTF-8 character is more than one byte: Decode it
2170 // into "mb_c".
2171 mb_l = utfc_ptr2len(ptr);
2172 mb_utf8 = FALSE;
2173 if (mb_l > 1)
2174 {
2175 mb_c = utfc_ptr2char(ptr, u8cc);
2176 // Overlong encoded ASCII or ASCII with composing char
2177 // is displayed normally, except a NUL.
2178 if (mb_c < 0x80)
2179 {
2180 c = mb_c;
2181#ifdef FEAT_LINEBREAK
2182 c0 = mb_c;
2183#endif
2184 }
2185 mb_utf8 = TRUE;
2186
2187 // At start of the line we can have a composing char.
2188 // Draw it as a space with a composing char.
2189 if (utf_iscomposing(mb_c))
2190 {
2191 int i;
2192
2193 for (i = Screen_mco - 1; i > 0; --i)
2194 u8cc[i] = u8cc[i - 1];
2195 u8cc[0] = mb_c;
2196 mb_c = ' ';
2197 }
2198 }
2199
2200 if ((mb_l == 1 && c >= 0x80)
2201 || (mb_l >= 1 && mb_c == 0)
2202 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2203 {
2204 // Illegal UTF-8 byte: display as <xx>.
2205 // Non-BMP character : display as ? or fullwidth ?.
2206 transchar_hex(extra, mb_c);
2207# ifdef FEAT_RIGHTLEFT
2208 if (wp->w_p_rl) // reverse
2209 rl_mirror(extra);
2210# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002211 wlv.p_extra = extra;
2212 c = *wlv.p_extra;
2213 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002214 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2216 wlv.c_extra = NUL;
2217 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002218 if (area_attr == 0 && search_attr == 0)
2219 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002220 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002221 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002222 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002223 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002224 }
2225 }
2226 else if (mb_l == 0) // at the NUL at end-of-line
2227 mb_l = 1;
2228#ifdef FEAT_ARABIC
2229 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2230 {
2231 // Do Arabic shaping.
2232 int pc, pc1, nc;
2233 int pcc[MAX_MCO];
2234
2235 // The idea of what is the previous and next
2236 // character depends on 'rightleft'.
2237 if (wp->w_p_rl)
2238 {
2239 pc = prev_c;
2240 pc1 = prev_c1;
2241 nc = utf_ptr2char(ptr + mb_l);
2242 prev_c1 = u8cc[0];
2243 }
2244 else
2245 {
2246 pc = utfc_ptr2char(ptr + mb_l, pcc);
2247 nc = prev_c;
2248 pc1 = pcc[0];
2249 }
2250 prev_c = mb_c;
2251
2252 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2253 }
2254 else
2255 prev_c = mb_c;
2256#endif
2257 }
2258 else // enc_dbcs
2259 {
2260 mb_l = MB_BYTE2LEN(c);
2261 if (mb_l == 0) // at the NUL at end-of-line
2262 mb_l = 1;
2263 else if (mb_l > 1)
2264 {
2265 // We assume a second byte below 32 is illegal.
2266 // Hopefully this is OK for all double-byte encodings!
2267 if (ptr[1] >= 32)
2268 mb_c = (c << 8) + ptr[1];
2269 else
2270 {
2271 if (ptr[1] == NUL)
2272 {
2273 // head byte at end of line
2274 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002275 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276 }
2277 else
2278 {
2279 // illegal tail byte
2280 mb_l = 2;
2281 STRCPY(extra, "XX");
2282 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 wlv.p_extra = extra;
2284 wlv.n_extra = (int)STRLEN(extra) - 1;
2285 wlv.c_extra = NUL;
2286 wlv.c_final = NUL;
2287 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 if (area_attr == 0 && search_attr == 0)
2289 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002291 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002292 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002293 // save current attr
2294 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002295 }
2296 mb_c = c;
2297 }
2298 }
2299 }
2300 // If a double-width char doesn't fit display a '>' in the
2301 // last column; the character is displayed at the start of the
2302 // next line.
2303 if ((
2304# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002305 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002306# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002307 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 && (*mb_char2cells)(mb_c) == 2)
2309 {
2310 c = '>';
2311 mb_c = c;
2312 mb_utf8 = FALSE;
2313 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002314 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315 // Put pointer back so that the character will be
2316 // displayed at the start of the next line.
2317 --ptr;
2318#ifdef FEAT_CONCEAL
2319 did_decrement_ptr = TRUE;
2320#endif
2321 }
2322 else if (*ptr != NUL)
2323 ptr += mb_l - 1;
2324
2325 // If a double-width char doesn't fit at the left side display
2326 // a '<' in the first column. Don't do this for unprintable
2327 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002328 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002330 wlv.n_extra = 1;
2331 wlv.c_extra = MB_FILLER_CHAR;
2332 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 c = ' ';
2334 if (area_attr == 0 && search_attr == 0)
2335 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002336 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002337 extra_attr = hl_combine_attr(
2338 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002339 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002340 }
2341 mb_c = c;
2342 mb_utf8 = FALSE;
2343 mb_l = 1;
2344 }
2345
2346 }
2347 ++ptr;
2348
2349 if (extra_check)
2350 {
2351#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 // Check spelling (unless at the end of the line).
2353 // Only do this when there is no syntax highlighting, the
2354 // @Spell cluster is not used or the current syntax item
2355 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002356 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 if (has_spell && v >= word_end && v > cur_checked_col)
2358 {
2359 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002360 // do not calculate cap_col at the end of the line or when
2361 // only white space is following
2362 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363# ifdef FEAT_SYN_HL
2364 !has_syntax ||
2365# endif
2366 can_spell))
2367 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002368 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 int len;
2370 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002371
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002374
2375 // Use nextline[] if possible, it has the start of the
2376 // next line concatenated.
2377 if ((prev_ptr - line) - nextlinecol >= 0)
2378 p = nextline + (prev_ptr - line) - nextlinecol;
2379 else
2380 p = prev_ptr;
2381 cap_col -= (int)(prev_ptr - line);
2382 len = spell_check(wp, p, &spell_hlf, &cap_col,
2383 nochange);
2384 word_end = v + len;
2385
2386 // In Insert mode only highlight a word that
2387 // doesn't touch the cursor.
2388 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002389 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 && wp->w_cursor.lnum == lnum
2391 && wp->w_cursor.col >=
2392 (colnr_T)(prev_ptr - line)
2393 && wp->w_cursor.col < (colnr_T)word_end)
2394 {
2395 spell_hlf = HLF_COUNT;
2396 spell_redraw_lnum = lnum;
2397 }
2398
2399 if (spell_hlf == HLF_COUNT && p != prev_ptr
2400 && (p - nextline) + len > nextline_idx)
2401 {
2402 // Remember that the good word continues at the
2403 // start of the next line.
2404 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002405 checked_col = (int)((p - nextline)
2406 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 }
2408
2409 // Turn index into actual attributes.
2410 if (spell_hlf != HLF_COUNT)
2411 spell_attr = highlight_attr[spell_hlf];
2412
2413 if (cap_col > 0)
2414 {
2415 if (p != prev_ptr
2416 && (p - nextline) + cap_col >= nextline_idx)
2417 {
2418 // Remember that the word in the next line
2419 // must start with a capital.
2420 capcol_lnum = lnum + 1;
2421 cap_col = (int)((p - nextline) + cap_col
2422 - nextline_idx);
2423 }
2424 else
2425 // Compute the actual column.
2426 cap_col += (int)(prev_ptr - line);
2427 }
2428 }
2429 }
2430 if (spell_attr != 0)
2431 {
2432 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002433 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2434 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 wlv.char_attr = hl_combine_attr(spell_attr,
2437 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 }
2439#endif
2440#ifdef FEAT_LINEBREAK
2441 // Found last space before word: check for line break.
2442 if (wp->w_p_lbr && c0 == c
2443 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2444 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002445 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2446 : 0;
2447 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002448 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002450 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002451# ifdef FEAT_PROP_POPUP
2452 // do not want virtual text counted here
2453 cts.cts_has_prop_with_text = FALSE;
2454# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002455 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002456 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002457
2458 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002459 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002460 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002462 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2463 if (wlv.n_extra < 0)
2464 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002465 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002466 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002467 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002468 // line break, but for TABs the highlighting should
2469 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002470 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002471
Bram Moolenaar1306b362022-08-06 15:59:06 +01002472 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002474 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002475 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 wp->w_buffer->b_p_vts_array) - 1;
2477# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002478 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002479 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480# endif
2481
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2483 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002484# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002485 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002486 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002487# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 if (VIM_ISWHITE(c))
2489 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002490# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 if (c == TAB)
2492 // See "Tab alignment" below.
2493 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002494# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495 if (!wp->w_p_list)
2496 c = ' ';
2497 }
2498 }
2499#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002500 in_multispace = c == ' '
2501 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2502 if (!in_multispace)
2503 multispace_pos = 0;
2504
Bram Moolenaareed9d462021-02-15 20:38:25 +01002505 // 'list': Change char 160 to 'nbsp' and space to 'space'
2506 // setting in 'listchars'. But not when the character is
2507 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508 if (wp->w_p_list
2509 && ((((c == 160 && mb_l == 1)
2510 || (mb_utf8
2511 && ((mb_c == 160 && mb_l == 2)
2512 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002513 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 || (c == ' '
2515 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002516 && (wp->w_lcs_chars.space
2517 || (in_multispace
2518 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002519 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 && ptr - line <= trailcol)))
2521 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002522 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2523 {
2524 c = wp->w_lcs_chars.multispace[multispace_pos++];
2525 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2526 multispace_pos = 0;
2527 }
2528 else
2529 c = (c == ' ') ? wp->w_lcs_chars.space
2530 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531 if (area_attr == 0 && search_attr == 0)
2532 {
2533 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002534 extra_attr = hl_combine_attr(wlv.win_attr,
2535 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002536 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 }
2538 mb_c = c;
2539 if (enc_utf8 && utf_char2len(c) > 1)
2540 {
2541 mb_utf8 = TRUE;
2542 u8cc[0] = 0;
2543 c = 0xc0;
2544 }
2545 else
2546 mb_utf8 = FALSE;
2547 }
2548
zeertzjq2e7cba32022-06-10 15:30:32 +01002549 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2550 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002552 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2553 && wp->w_lcs_chars.leadmultispace != NULL)
2554 {
2555 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002556 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2557 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002558 multispace_pos = 0;
2559 }
2560
2561 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2562 c = wp->w_lcs_chars.trail;
2563
2564 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2565 c = wp->w_lcs_chars.lead;
2566
zeertzjq2e7cba32022-06-10 15:30:32 +01002567 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002568 c = wp->w_lcs_chars.space;
2569
2570
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 if (!attr_pri)
2572 {
2573 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002574 extra_attr = hl_combine_attr(wlv.win_attr,
2575 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002576 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 }
2578 mb_c = c;
2579 if (enc_utf8 && utf_char2len(c) > 1)
2580 {
2581 mb_utf8 = TRUE;
2582 u8cc[0] = 0;
2583 c = 0xc0;
2584 }
2585 else
2586 mb_utf8 = FALSE;
2587 }
2588 }
2589
2590 // Handling of non-printable characters.
2591 if (!vim_isprintc(c))
2592 {
2593 // when getting a character from the file, we may have to
2594 // turn it into something else on the way to putting it
2595 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002596 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 {
2598 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002599 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002601 char_u *sbr = get_showbreak_value(wp);
2602
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 // only adjust the tab_len, when at the first column
2604 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002605 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2606 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607#endif
2608 // tab amount depends on current column
2609#ifdef FEAT_VARTABS
2610 tab_len = tabstop_padding(vcol_adjusted,
2611 wp->w_buffer->b_p_ts,
2612 wp->w_buffer->b_p_vts_array) - 1;
2613#else
2614 tab_len = (int)wp->w_buffer->b_p_ts
2615 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2616#endif
2617
2618#ifdef FEAT_LINEBREAK
2619 if (!wp->w_p_lbr || !wp->w_p_list)
2620#endif
2621 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002622 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623#ifdef FEAT_LINEBREAK
2624 else
2625 {
2626 char_u *p;
2627 int len;
2628 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002629 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002631# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002632 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002634 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002635
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002637 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002638 && old_boguscols > 0
2639 && wlv.n_extra > tab_len)
2640 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002641# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002642 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002644 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002645 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002646 if (wp->w_lcs_chars.tab3)
2647 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 if (wlv.n_extra > 0)
2649 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002650 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002652 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002653 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002654 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002656 vim_memset(p, ' ', len);
2657 p[len] = NUL;
2658 vim_free(p_extra_free);
2659 p_extra_free = p;
2660 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002661 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002662 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002664 if (*p == NUL)
2665 {
2666 tab_len = i;
2667 break;
2668 }
2669
2670 // if tab3 is given, use it for the last char
2671 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2672 lcs = wp->w_lcs_chars.tab3;
2673 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002674 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002676 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002677 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002678# ifdef FEAT_CONCEAL
2679 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2680 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002681 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002682 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002683# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 }
2686#endif
2687#ifdef FEAT_CONCEAL
2688 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002689 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690
2691 // Tab alignment should be identical regardless of
2692 // 'conceallevel' value. So tab compensates of all
2693 // previous concealed characters, and thus resets
2694 // vcol_off and boguscols accumulated so far in the
2695 // line. Note that the tab can be longer than
2696 // 'tabstop' when there are concealed characters.
2697 FIX_FOR_BOGUSCOLS;
2698
2699 // Make sure, the highlighting for the tab char will be
2700 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002701 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002703 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704 tab_len += vc_saved;
2705 }
2706#endif
2707 mb_utf8 = FALSE; // don't draw as UTF-8
2708 if (wp->w_p_list)
2709 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002711 ? wp->w_lcs_chars.tab3
2712 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713#ifdef FEAT_LINEBREAK
2714 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002715 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002716 else
2717#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 wlv.c_extra = wp->w_lcs_chars.tab2;
2719 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002721 extra_attr = hl_combine_attr(wlv.win_attr,
2722 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002723 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724 mb_c = c;
2725 if (enc_utf8 && utf_char2len(c) > 1)
2726 {
2727 mb_utf8 = TRUE;
2728 u8cc[0] = 0;
2729 c = 0xc0;
2730 }
2731 }
2732 else
2733 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 wlv.c_final = NUL;
2735 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736 c = ' ';
2737 }
2738 }
2739 else if (c == NUL
2740 && (wp->w_p_list
2741 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002742 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002743 && VIsual_mode != Ctrl_V
2744 && (
2745# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002746 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002748 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002749 && !(noinvcur
2750 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002751 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 && lcs_eol_one > 0)
2753 {
2754 // Display a '$' after the line or highlight an extra
2755 // character if the line break is included.
2756#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2757 // For a diff line the highlighting continues after the
2758 // "$".
2759 if (
2760# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762# ifdef LINE_ATTR
2763 &&
2764# endif
2765# endif
2766# ifdef LINE_ATTR
2767 line_attr == 0
2768# endif
2769 )
2770#endif
2771 {
2772 // In virtualedit, visual selections may extend
2773 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002774 if (!(area_highlighting && virtual_active()
2775 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002776 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002777 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002779 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2780 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 else
2782 c = ' ';
2783 lcs_eol_one = -1;
2784 --ptr; // put it back at the NUL
2785 if (!attr_pri)
2786 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002787 extra_attr = hl_combine_attr(wlv.win_attr,
2788 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 n_attr = 1;
2790 }
2791 mb_c = c;
2792 if (enc_utf8 && utf_char2len(c) > 1)
2793 {
2794 mb_utf8 = TRUE;
2795 u8cc[0] = 0;
2796 c = 0xc0;
2797 }
2798 else
2799 mb_utf8 = FALSE; // don't draw as UTF-8
2800 }
2801 else if (c != NUL)
2802 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002803 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2804 if (wlv.n_extra == 0)
2805 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806#ifdef FEAT_RIGHTLEFT
2807 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002808 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 wlv.c_extra = NUL;
2811 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812#ifdef FEAT_LINEBREAK
2813 if (wp->w_p_lbr)
2814 {
2815 char_u *p;
2816
Bram Moolenaar1306b362022-08-06 15:59:06 +01002817 c = *wlv.p_extra;
2818 p = alloc(wlv.n_extra + 1);
2819 vim_memset(p, ' ', wlv.n_extra);
2820 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2821 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002823 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 }
2825 else
2826#endif
2827 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002828 wlv.n_extra = byte2cells(c) - 1;
2829 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 }
2831 if (!attr_pri)
2832 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002833 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002834 extra_attr = hl_combine_attr(wlv.win_attr,
2835 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002836 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 }
2838 mb_utf8 = FALSE; // don't draw as UTF-8
2839 }
2840 else if (VIsual_active
2841 && (VIsual_mode == Ctrl_V
2842 || VIsual_mode == 'v')
2843 && virtual_active()
2844 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 && (
2847#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002848 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002850 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 {
2852 c = ' ';
2853 --ptr; // put it back at the NUL
2854 }
2855#if defined(LINE_ATTR)
2856 else if ((
2857# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002858 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859# endif
2860# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002861 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862# endif
2863 line_attr != 0
2864 ) && (
2865# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002866 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002868 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871# endif
2872 < wp->w_width)))
2873 {
2874 // Highlight until the right side of the window
2875 c = ' ';
2876 --ptr; // put it back at the NUL
2877
2878 // Remember we do the char for line highlighting.
2879 ++did_line_attr;
2880
2881 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002882 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002884 || (wp->w_p_list &&
2885 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002890 wlv.diff_hlf = HLF_CHD;
2891 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2895 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002896 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002897 || (wlv.vcol >= left_curline_col
2898 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002899 wlv.char_attr = hl_combine_attr(
2900 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 }
2902 }
2903# endif
2904# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002905 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002907 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002908 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2909 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 if (!wlv.cul_screenline
2912 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002913 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002914 wlv.char_attr = hl_combine_attr(
2915 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 }
2917 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002918 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2919 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920 }
2921# endif
2922 }
2923#endif
2924 }
2925
2926#ifdef FEAT_CONCEAL
2927 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002928 && (wp != curwin || lnum != wp->w_cursor.lnum
2929 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002930 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2931 && !(lnum_in_visual_area
2932 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2933 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002934 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002935 if (((prev_syntax_id != syntax_seqnr
2936 && (syntax_flags & HL_CONCEAL) != 0)
2937 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002938 && (syn_get_sub_char() != NUL
2939 || (has_match_conc && match_conc)
2940 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941 && wp->w_p_cole != 3)
2942 {
2943 // First time at this concealed item: display one
2944 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002945 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 c = match_conc;
2947 else if (syn_get_sub_char() != NUL)
2948 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002949 else if (wp->w_lcs_chars.conceal != NUL)
2950 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 else
2952 c = ' ';
2953
2954 prev_syntax_id = syntax_seqnr;
2955
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 if (wlv.n_extra > 0)
2957 wlv.vcol_off += wlv.n_extra;
2958 wlv.vcol += wlv.n_extra;
2959 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 {
2961# ifdef FEAT_RIGHTLEFT
2962 if (wp->w_p_rl)
2963 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 wlv.col -= wlv.n_extra;
2965 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 }
2967 else
2968# endif
2969 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 wlv.boguscols += wlv.n_extra;
2971 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 }
2973 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002974 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 n_attr = 0;
2976 }
2977 else if (n_skip == 0)
2978 {
2979 is_concealing = TRUE;
2980 n_skip = 1;
2981 }
2982 mb_c = c;
2983 if (enc_utf8 && utf_char2len(c) > 1)
2984 {
2985 mb_utf8 = TRUE;
2986 u8cc[0] = 0;
2987 c = 0xc0;
2988 }
2989 else
2990 mb_utf8 = FALSE; // don't draw as UTF-8
2991 }
2992 else
2993 {
2994 prev_syntax_id = 0;
2995 is_concealing = FALSE;
2996 }
2997
2998 if (n_skip > 0 && did_decrement_ptr)
2999 // not showing the '>', put pointer back to avoid getting stuck
3000 ++ptr;
3001
3002#endif // FEAT_CONCEAL
3003 }
3004
3005#ifdef FEAT_CONCEAL
3006 // In the cursor line and we may be concealing characters: correct
3007 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 && wp == curwin && lnum == wp->w_cursor.lnum
3010 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003011 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003013# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003015 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003017# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003018 wp->w_wcol = wlv.col - wlv.boguscols;
3019 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 did_wcol = TRUE;
3021 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003022# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003023 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003024# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 }
3026#endif
3027
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003028 // Use "extra_attr", but don't override visual selection highlighting,
3029 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003030 // Don't use "extra_attr" until n_attr_skip is zero.
3031 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003032 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003033 && (!attr_pri
3034#ifdef FEAT_PROP_POPUP
3035 || (text_prop_flags & PT_FLAG_OVERRIDE)
3036#endif
3037 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 {
3039#ifdef LINE_ATTR
3040 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003041 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 else
3043#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003044 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 }
3046
3047#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3048 // XIM don't send preedit_start and preedit_end, but they send
3049 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3050 // im_is_preediting() here.
3051 if (p_imst == IM_ON_THE_SPOT
3052 && xic != NULL
3053 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003054 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 && !p_imdisable
3056 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003057 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 {
3059 colnr_T tcol;
3060
3061 if (preedit_end_col == MAXCOL)
3062 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3063 else
3064 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003065 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 {
3067 if (feedback_old_attr < 0)
3068 {
3069 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 wlv.char_attr = im_get_feedback_attr(feedback_col);
3073 if (wlv.char_attr < 0)
3074 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 feedback_col++;
3076 }
3077 else if (feedback_old_attr >= 0)
3078 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003079 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 feedback_old_attr = -1;
3081 feedback_col = 0;
3082 }
3083 }
3084#endif
3085 // Handle the case where we are in column 0 but not on the first
3086 // character of the line and the user wants us to show us a
3087 // special character (via 'listchars' option "precedes:<char>".
3088 if (lcs_prec_todo != NUL
3089 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003090 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003091 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003092 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093#ifdef FEAT_DIFF
3094 && filler_todo <= 0
3095#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003096 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 && c != NUL)
3098 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003099 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003100 lcs_prec_todo = NUL;
3101 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3102 {
3103 // Double-width character being overwritten by the "precedes"
3104 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003105 wlv.c_extra = MB_FILLER_CHAR;
3106 wlv.c_final = NUL;
3107 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003109 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 }
3111 mb_c = c;
3112 if (enc_utf8 && utf_char2len(c) > 1)
3113 {
3114 mb_utf8 = TRUE;
3115 u8cc[0] = 0;
3116 c = 0xc0;
3117 }
3118 else
3119 mb_utf8 = FALSE; // don't draw as UTF-8
3120 if (!attr_pri)
3121 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 saved_attr3 = wlv.char_attr; // save current attr
3123 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 n_attr3 = 1;
3125 }
3126 }
3127
3128 // At end of the text line or just after the last character.
3129 if ((c == NUL
3130#if defined(LINE_ATTR)
3131 || did_line_attr == 1
3132#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003133 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 {
3135#ifdef FEAT_SEARCH_EXTRA
3136 // flag to indicate whether prevcol equals startcol of search_hl or
3137 // one of the matches
3138 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3139 (long)(ptr - line) - (c == NUL));
3140#endif
3141 // Invert at least one char, used for Visual and empty line or
3142 // highlight match at end of line. If it's beyond the last
3143 // char on the screen, just overwrite that one (tricky!) Not
3144 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003145 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003146 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 && (VIsual_mode != Ctrl_V
3148 || lnum == VIsual.lnum
3149 || lnum == curwin->w_cursor.lnum)
3150 && c == NUL)
3151#ifdef FEAT_SEARCH_EXTRA
3152 // highlight 'hlsearch' match at end of line
3153 || (prevcol_hl_flag
3154# ifdef FEAT_SYN_HL
3155 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3156 && !(wp == curwin && VIsual_active))
3157# endif
3158# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003159 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160# endif
3161# if defined(LINE_ATTR)
3162 && did_line_attr <= 1
3163# endif
3164 )
3165#endif
3166 ))
3167 {
3168 int n = 0;
3169
3170#ifdef FEAT_RIGHTLEFT
3171 if (wp->w_p_rl)
3172 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003173 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 n = 1;
3175 }
3176 else
3177#endif
3178 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003179 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 n = -1;
3181 }
3182 if (n != 0)
3183 {
3184 // At the window boundary, highlight the last character
3185 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003186 wlv.off += n;
3187 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 }
3189 else
3190 {
3191 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003192 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003194 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 }
3196#ifdef FEAT_SEARCH_EXTRA
3197 if (area_attr == 0)
3198 {
3199 // Use attributes from match with highest priority among
3200 // 'search_hl' and the match list.
3201 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 }
3204#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003206 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207#ifdef FEAT_RIGHTLEFT
3208 if (wp->w_p_rl)
3209 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003210 --wlv.col;
3211 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 }
3213 else
3214#endif
3215 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003216 ++wlv.col;
3217 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003219 ++wlv.vcol;
3220 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 }
3222 }
3223
3224 // At end of the text line.
3225 if (c == NUL)
3226 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003227 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228
3229 // Update w_cline_height and w_cline_folded if the cursor line was
3230 // updated (saves a call to plines() later).
3231 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3232 {
3233 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003234 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235#ifdef FEAT_FOLDING
3236 curwin->w_cline_folded = FALSE;
3237#endif
3238 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3239 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 break;
3241 }
3242
3243 // Show "extends" character from 'listchars' if beyond the line end and
3244 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003245 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003246 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 && wp->w_p_list
3248 && !wp->w_p_wrap
3249#ifdef FEAT_DIFF
3250 && filler_todo <= 0
3251#endif
3252 && (
3253#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003254 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003256 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003258 || lcs_eol_one > 0
3259 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003260 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003262 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 mb_c = c;
3265 if (enc_utf8 && utf_char2len(c) > 1)
3266 {
3267 mb_utf8 = TRUE;
3268 u8cc[0] = 0;
3269 c = 0xc0;
3270 }
3271 else
3272 mb_utf8 = FALSE;
3273 }
3274
3275#ifdef FEAT_SYN_HL
3276 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003277 if (wlv.draw_color_col)
3278 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279
3280 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3281 // highlight the cursor position itself.
3282 // Also highlight the 'colorcolumn' if it is different than
3283 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003284 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3285 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003287 if (((wlv.draw_state == WL_LINE
3288 || wlv.draw_state == WL_BRI
3289 || wlv.draw_state == WL_SBR)
3290 && !lnum_in_visual_area
3291 && search_attr == 0
3292 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003293# ifdef FEAT_DIFF
3294 && filler_todo <= 0
3295# endif
3296 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 {
3298 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3299 && lnum != wp->w_cursor.lnum)
3300 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003301 vcol_save_attr = wlv.char_attr;
3302 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3303 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003307 vcol_save_attr = wlv.char_attr;
3308 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 }
3310 }
3311#endif
3312
3313 // Store character to be displayed.
3314 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003315 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003316 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317 {
3318 // Store the character.
3319#if defined(FEAT_RIGHTLEFT)
3320 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3321 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003322 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003323 --wlv.off;
3324 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 }
3326#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003327 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 if (enc_dbcs == DBCS_JPNU)
3329 {
3330 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003331 ScreenLines[wlv.off] = 0x8e;
3332 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 }
3334 else if (enc_utf8)
3335 {
3336 if (mb_utf8)
3337 {
3338 int i;
3339
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003340 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 for (i = 0; i < Screen_mco; ++i)
3344 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003345 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 if (u8cc[i] == 0)
3347 break;
3348 }
3349 }
3350 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 }
3353 if (multi_attr)
3354 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 multi_attr = 0;
3357 }
3358 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003361 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003362
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3364 {
3365 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 ++wlv.off;
3367 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 if (enc_utf8)
3369 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003370 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 else
3372 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003373 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003374 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375#ifdef FEAT_DIFF
3376 && filler_todo <= 0
3377#endif
3378 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003379 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 // When "tocol" is halfway a character, set it to the end of
3381 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003382 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003384
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003386
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387#ifdef FEAT_RIGHTLEFT
3388 if (wp->w_p_rl)
3389 {
3390 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 --wlv.off;
3392 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 }
3394#endif
3395 }
3396#ifdef FEAT_RIGHTLEFT
3397 if (wp->w_p_rl)
3398 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003399 --wlv.off;
3400 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401 }
3402 else
3403#endif
3404 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 ++wlv.off;
3406 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 }
3408 }
3409#ifdef FEAT_CONCEAL
3410 else if (wp->w_p_cole > 0 && is_concealing)
3411 {
3412 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003413 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003414 if (wlv.n_extra > 0)
3415 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 if (wp->w_p_wrap)
3417 {
3418 // Special voodoo required if 'wrap' is on.
3419 //
3420 // Advance the column indicator to force the line
3421 // drawing to wrap early. This will make the line
3422 // take up the same screen space when parts are concealed,
3423 // so that cursor line computations aren't messed up.
3424 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 // trailing junk to be written out of the screen line
3427 // we are building, 'boguscols' keeps track of the number
3428 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003429 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003431 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432# ifdef FEAT_RIGHTLEFT
3433 if (wp->w_p_rl)
3434 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 wlv.col -= wlv.n_extra;
3436 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 }
3438 else
3439# endif
3440 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003441 wlv.col += wlv.n_extra;
3442 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003444 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 n_attr = 0;
3446 }
3447
3448
3449 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3450 {
3451 // Need to fill two screen columns.
3452# ifdef FEAT_RIGHTLEFT
3453 if (wp->w_p_rl)
3454 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 --wlv.boguscols;
3456 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
3458 else
3459# endif
3460 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003461 ++wlv.boguscols;
3462 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463 }
3464 }
3465
3466# ifdef FEAT_RIGHTLEFT
3467 if (wp->w_p_rl)
3468 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 --wlv.boguscols;
3470 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 }
3472 else
3473# endif
3474 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 ++wlv.boguscols;
3476 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477 }
3478 }
3479 else
3480 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003481 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 wlv.vcol += wlv.n_extra;
3484 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 n_attr = 0;
3486 }
3487 }
3488
3489 }
3490#endif // FEAT_CONCEAL
3491 else
3492 --n_skip;
3493
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003494 // Only advance the "wlv.vcol" when after the 'number' or
3495 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003496 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497#ifdef FEAT_DIFF
3498 && filler_todo <= 0
3499#endif
3500 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502
3503#ifdef FEAT_SYN_HL
3504 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003505 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506#endif
3507
3508 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003509 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3510 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511
3512 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003513 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003514 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003515 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003516 if (n_attr_skip > 0)
3517 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518
3519 // At end of screen line and there is more to come: Display the line
3520 // so far. If there is no more to display it is caught above.
3521 if ((
3522#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003526 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003527 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528#ifdef FEAT_DIFF
3529 || filler_todo > 0
3530#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003531#ifdef FEAT_PROP_POPUP
3532 || text_prop_follows
3533#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003534 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003535 && wlv.p_extra != at_end_str)
3536 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3537 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 )
3539 {
3540#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003541 screen_line(wp, wlv.screen_row, wp->w_wincol,
3542 wlv.col - wlv.boguscols,
3543 wp->w_width, wlv.screen_line_flags);
3544 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3547 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003549 ++wlv.row;
3550 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551
3552 // When not wrapping and finished diff lines, or when displayed
3553 // '$' and highlighting until last column, break here.
3554 if ((!wp->w_p_wrap
3555#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003556 && filler_todo <= 0
3557#endif
3558#ifdef FEAT_PROP_POPUP
3559 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003560#endif
3561 ) || lcs_eol_one == -1)
3562 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003563#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003564 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003565 {
3566 // do not output more of the line, only the "below" prop
3567 ptr += STRLEN(ptr);
3568# ifdef FEAT_LINEBREAK
3569 dont_use_showbreak = TRUE;
3570# endif
3571 }
3572#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573
3574 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003575 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576#ifdef FEAT_DIFF
3577 && filler_todo <= 0
3578#endif
3579 )
3580 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3582 draw_vsep_win(wp, wlv.row);
3583 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 }
3585
3586 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003587 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590 break;
3591 }
3592
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594#ifdef FEAT_DIFF
3595 && filler_todo <= 0
3596#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003597#ifdef FEAT_PROP_POPUP
3598 && !text_prop_follows
3599#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 && wp->w_width == Columns)
3601 {
3602 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604
3605 // Special trick to make copy/paste of wrapped lines work with
3606 // xterm/screen: write an extra character beyond the end of
3607 // the line. This will work with all terminal types
3608 // (regardless of the xn,am settings).
3609 // Only do this on a fast tty.
3610 // Only do this if the cursor is on the current line
3611 // (something has been written in it).
3612 // Don't do this for the GUI.
3613 // Don't do this for double-width characters.
3614 // Don't do this for a window not at the right screen border.
3615 if (p_tf
3616#ifdef FEAT_GUI
3617 && !gui.in_use
3618#endif
3619 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3621 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003623 || (*mb_off2cells)(
3624 LineOffset[wlv.screen_row - 1]
3625 + (int)Columns - 2,
3626 LineOffset[wlv.screen_row]
3627 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 {
3629 // First make sure we are at the end of the screen line,
3630 // then output the same character again to let the
3631 // terminal know about the wrap. If the terminal doesn't
3632 // auto-wrap, we overwrite the character.
3633 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003634 screen_char(LineOffset[wlv.screen_row - 1]
3635 + (unsigned)Columns - 1,
3636 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637
3638 // When there is a multi-byte character, just output a
3639 // space to keep it simple.
3640 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003641 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 out_char(' ');
3643 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 + (Columns - 1)]);
3646 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003647 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 screen_start(); // don't know where cursor is now
3649 }
3650 }
3651
Bram Moolenaar1306b362022-08-06 15:59:06 +01003652 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653
Bram Moolenaareed9d462021-02-15 20:38:25 +01003654 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003656 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003658 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003660 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 need_showbreak = TRUE;
3662#endif
3663#ifdef FEAT_DIFF
3664 --filler_todo;
3665 // When the filler lines are actually below the last line of the
3666 // file, don't draw the line itself, break here.
3667 if (filler_todo == 0 && wp->w_botfill)
3668 break;
3669#endif
3670 }
3671
3672 } // for every character in the line
3673
3674#ifdef FEAT_SPELL
3675 // After an empty line check first word for capital.
3676 if (*skipwhite(line) == NUL)
3677 {
3678 capcol_lnum = lnum + 1;
3679 cap_col = 0;
3680 }
3681#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003682#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683 vim_free(text_props);
3684 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003685 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686#endif
3687
3688 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003689 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690}