blob: 0300f373a61764e8f409a04e905f257575bce2be [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.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * 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 Moolenaar05ad5ff2019-11-30 22:48:27 +0100280#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281static textprop_T *current_text_props = NULL;
282static buf_T *current_buf = NULL;
283
284 static int
285text_prop_compare(const void *s1, const void *s2)
286{
287 int idx1, idx2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100288 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 proptype_T *pt1, *pt2;
290 colnr_T col1, col2;
291
292 idx1 = *(int *)s1;
293 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100294 tp1 = &current_text_props[idx1];
295 tp2 = &current_text_props[idx2];
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100296 col1 = tp1->tp_col;
297 col2 = tp2->tp_col;
298 if (col1 == MAXCOL && col2 == MAXCOL)
299 {
300 int flags1 = 0;
301 int flags2 = 0;
302
303 // order on 0: after, 1: right, 2: below
304 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
305 flags1 = 1;
306 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
307 flags1 = 2;
308 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
309 flags2 = 1;
310 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
311 flags2 = 2;
312 if (flags1 != flags2)
313 return flags1 < flags2 ? 1 : -1;
314 }
Bram Moolenaardb9b96d2022-08-06 17:38:53 +0100315 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
316 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
317 if (pt1 == pt2)
318 return 0;
319 if (pt1 == NULL)
320 return -1;
321 if (pt2 == NULL)
322 return 1;
323 if (pt1->pt_priority != pt2->pt_priority)
324 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200325 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
326}
327#endif
328
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100329/*
330 * Called when finished with the line: draw the screen line and handle any
331 * highlighting until the right of the window.
332 */
333 static void
334draw_screen_line(win_T *wp, winlinevars_T *wlv)
335{
336#ifdef FEAT_SYN_HL
337 long v;
338
339 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
340 if (wp->w_p_wrap)
341 v = wp->w_skipcol;
342 else
343 v = wp->w_leftcol;
344
345 // check if line ends before left margin
346 if (wlv->vcol < v + wlv->col - win_col_off(wp))
347 wlv->vcol = v + wlv->col - win_col_off(wp);
348# ifdef FEAT_CONCEAL
349 // Get rid of the boguscols now, we want to draw until the right
350 // edge for 'cursorcolumn'.
351 wlv->col -= wlv->boguscols;
352 wlv->boguscols = 0;
353# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
354# else
355# define VCOL_HLC (wlv->vcol)
356# endif
357
358 if (wlv->draw_color_col)
359 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
360
361 if (((wp->w_p_cuc
362 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
363 && (int)wp->w_virtcol <
364 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
365 && wlv->lnum != wp->w_cursor.lnum)
366 || wlv->draw_color_col
367 || wlv->win_attr != 0)
368# ifdef FEAT_RIGHTLEFT
369 && !wp->w_p_rl
370# endif
371 )
372 {
373 int rightmost_vcol = 0;
374 int i;
375
376 if (wp->w_p_cuc)
377 rightmost_vcol = wp->w_virtcol;
378 if (wlv->draw_color_col)
379 // determine rightmost colorcolumn to possibly draw
380 for (i = 0; wlv->color_cols[i] >= 0; ++i)
381 if (rightmost_vcol < wlv->color_cols[i])
382 rightmost_vcol = wlv->color_cols[i];
383
384 while (wlv->col < wp->w_width)
385 {
386 ScreenLines[wlv->off] = ' ';
387 if (enc_utf8)
388 ScreenLinesUC[wlv->off] = 0;
389 ScreenCols[wlv->off] = MAXCOL;
390 ++wlv->col;
391 if (wlv->draw_color_col)
392 wlv->draw_color_col = advance_color_col(
393 VCOL_HLC, &wlv->color_cols);
394
395 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
396 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
397 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
398 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
399 else
400 ScreenAttrs[wlv->off++] = wlv->win_attr;
401
402 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
403 break;
404
405 ++wlv->vcol;
406 }
407 }
408#endif
409
410 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
411 wp->w_width, wlv->screen_line_flags);
412 ++wlv->row;
413 ++wlv->screen_row;
414}
415#undef VCOL_HLC
416
417/*
418 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100419 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100420 */
421 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100422win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100423{
424 wlv->col = 0;
425 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
426
427#ifdef FEAT_RIGHTLEFT
428 if (wp->w_p_rl)
429 {
430 // Rightleft window: process the text in the normal direction, but put
431 // it in current_ScreenLine[] from right to left. Start at the
432 // rightmost column of the window.
433 wlv->col = wp->w_width - 1;
434 wlv->off += wlv->col;
435 wlv->screen_line_flags |= SLF_RIGHTLEFT;
436 }
437#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100438 if (save_extra)
439 {
440 // reset the drawing state for the start of a wrapped line
441 wlv->draw_state = WL_START;
442 wlv->saved_n_extra = wlv->n_extra;
443 wlv->saved_p_extra = wlv->p_extra;
444 wlv->saved_c_extra = wlv->c_extra;
445 wlv->saved_c_final = wlv->c_final;
446#ifdef FEAT_SYN_HL
447 if (!(wlv->cul_screenline
448# ifdef FEAT_DIFF
449 && wlv->diff_hlf == (hlf_T)0
450# endif
451 ))
452 wlv->saved_char_attr = wlv->char_attr;
453 else
454#endif
455 wlv->saved_char_attr = 0;
456 wlv->n_extra = 0;
457 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100458}
459
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200460/*
461 * Display line "lnum" of window 'wp' on the screen.
462 * Start at row "startrow", stop when "endrow" is reached.
463 * wp->w_virtcol needs to be valid.
464 *
465 * Return the number of last row the line occupies.
466 */
467 int
468win_line(
469 win_T *wp,
470 linenr_T lnum,
471 int startrow,
472 int endrow,
473 int nochange UNUSED, // not updating for changed text
474 int number_only) // only update the number column
475{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100476 winlinevars_T wlv; // variables passed between functions
477
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200478 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200479#ifdef FEAT_LINEBREAK
480 long vcol_sbr = -1; // virtual column after showbreak
481#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100482 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200483 char_u *line; // current line
484 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200485
486 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200487 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100488#ifdef FEAT_PROP_POPUP
489 char_u *p_extra_free2 = NULL; // another p_extra to be freed
490#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200491 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000492#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000493 int in_linebreak = FALSE; // n_extra set for showing linebreak
494#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200495 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100496 // displaying eol at end-of-line
497 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000498 int lcs_prec_todo = wp->w_lcs_chars.prec;
499 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200500
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100501 int n_attr = 0; // chars with special attr
502 int n_attr_skip = 0; // chars to skip before using extra_attr
503 int saved_attr2 = 0; // char_attr saved for n_attr
504 int n_attr3 = 0; // chars with overruling special attr
505 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200506
507 int n_skip = 0; // nr of chars to skip for 'nowrap'
508
509 int fromcol = -10; // start of inverting
510 int tocol = MAXCOL; // end of inverting
511 int fromcol_prev = -2; // start of inverting after cursor
512 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200513 int lnum_in_visual_area = FALSE;
514 pos_T pos;
515 long v;
516
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200517 int attr_pri = FALSE; // char_attr has priority
518 int area_highlighting = FALSE; // Visual or incsearch highlighting
519 // in this line
520 int vi_attr = 0; // attributes for Visual and incsearch
521 // highlighting
522 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200523 int area_attr = 0; // attributes desired by highlighting
524 int search_attr = 0; // attributes desired by 'hlsearch'
525#ifdef FEAT_SYN_HL
526 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
527 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200528 int prev_syntax_col = -1; // column of prev_syntax_attr
529 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200530 int has_syntax = FALSE; // this buffer has syntax highl.
531 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200532#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100533#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200534 int text_prop_count;
535 int text_prop_next = 0; // next text property to use
536 textprop_T *text_props = NULL;
537 int *text_prop_idxs = NULL;
538 int text_props_active = 0;
539 proptype_T *text_prop_type = NULL;
540 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100541 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100542 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100543 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200544#endif
545#ifdef FEAT_SPELL
546 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000547 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200548# define SPWORDLEN 150
549 char_u nextline[SPWORDLEN * 2];// text with start of the next line
550 int nextlinecol = 0; // column where nextline[] starts
551 int nextline_idx = 0; // index in nextline[] where next line
552 // starts
553 int spell_attr = 0; // attributes desired by spelling
554 int word_end = 0; // last byte with same spell_attr
555 static linenr_T checked_lnum = 0; // line number for "checked_col"
556 static int checked_col = 0; // column in "checked_lnum" up to which
557 // there are no spell errors
558 static int cap_col = -1; // column to check for Cap word
559 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
560 int cur_checked_col = 0; // checked column for current line
561#endif
562 int extra_check = 0; // has extra highlighting
563 int multi_attr = 0; // attributes desired by multibyte
564 int mb_l = 1; // multi-byte byte length
565 int mb_c = 0; // decoded multi-byte character
566 int mb_utf8 = FALSE; // screen char is UTF-8 char
567 int u8cc[MAX_MCO]; // composing UTF-8 chars
568#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
569 int filler_lines = 0; // nr of filler lines to be drawn
570 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000571#else
572# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200573#endif
574#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200575 int change_start = MAXCOL; // first col of changed area
576 int change_end = -1; // last col of changed area
577#endif
578 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100579 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200580 int in_multispace = FALSE; // in multiple consecutive spaces
581 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200582#ifdef FEAT_LINEBREAK
583 int need_showbreak = FALSE; // overlong line, skipping first x
584 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100585 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200586#endif
587#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
588 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
589# define LINE_ATTR
590 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100591 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200592#endif
593#ifdef FEAT_SIGNS
594 int sign_present = FALSE;
595 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000596 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200597#endif
598#ifdef FEAT_ARABIC
599 int prev_c = 0; // previous Arabic character
600 int prev_c1 = 0; // first composing char for prev_c
601#endif
602#if defined(LINE_ATTR)
603 int did_line_attr = 0;
604#endif
605#ifdef FEAT_TERMINAL
606 int get_term_attr = FALSE;
607#endif
608#ifdef FEAT_SYN_HL
609 int cul_attr = 0; // set when 'cursorline' active
610
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200611 // margin columns for the screen line, needed for when 'cursorlineopt'
612 // contains "screenline"
613 int left_curline_col = 0;
614 int right_curline_col = 0;
615#endif
616
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
618 int feedback_col = 0;
619 int feedback_old_attr = -1;
620#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621
622#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
623 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000624 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200625#endif
626#ifdef FEAT_CONCEAL
627 int syntax_flags = 0;
628 int syntax_seqnr = 0;
629 int prev_syntax_id = 0;
630 int conceal_attr = HL_ATTR(HLF_CONCEAL);
631 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200632 int did_wcol = FALSE;
633 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100634# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200635# define FIX_FOR_BOGUSCOLS \
636 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100637 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100638 wlv.vcol -= wlv.vcol_off; \
639 wlv.vcol_off = 0; \
640 wlv.col -= wlv.boguscols; \
641 old_boguscols = wlv.boguscols; \
642 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643 }
644#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100645# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200646#endif
647
648 if (startrow > endrow) // past the end already!
649 return startrow;
650
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100651 CLEAR_FIELD(wlv);
652
653 wlv.lnum = lnum;
654 wlv.startrow = startrow;
655 wlv.row = startrow;
656 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200657
658 if (!number_only)
659 {
660 // To speed up the loop below, set extra_check when there is linebreak,
661 // trailing white space and/or syntax processing to be done.
662#ifdef FEAT_LINEBREAK
663 extra_check = wp->w_p_lbr;
664#endif
665#ifdef FEAT_SYN_HL
666 if (syntax_present(wp) && !wp->w_s->b_syn_error
667# ifdef SYN_TIME_LIMIT
668 && !wp->w_s->b_syn_slow
669# endif
670 )
671 {
672 // Prepare for syntax highlighting in this line. When there is an
673 // error, stop syntax highlighting.
674 save_did_emsg = did_emsg;
675 did_emsg = FALSE;
676 syntax_start(wp, lnum);
677 if (did_emsg)
678 wp->w_s->b_syn_error = TRUE;
679 else
680 {
681 did_emsg = save_did_emsg;
682#ifdef SYN_TIME_LIMIT
683 if (!wp->w_s->b_syn_slow)
684#endif
685 {
686 has_syntax = TRUE;
687 extra_check = TRUE;
688 }
689 }
690 }
691
692 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100693 wlv.color_cols = wp->w_p_cc_cols;
694 if (wlv.color_cols != NULL)
695 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200696#endif
697
698#ifdef FEAT_TERMINAL
699 if (term_show_buffer(wp->w_buffer))
700 {
701 extra_check = TRUE;
702 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100703 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200704 }
705#endif
706
707#ifdef FEAT_SPELL
708 if (wp->w_p_spell
709 && *wp->w_s->b_p_spl != NUL
710 && wp->w_s->b_langp.ga_len > 0
711 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
712 {
713 // Prepare for spell checking.
714 has_spell = TRUE;
715 extra_check = TRUE;
716
717 // Get the start of the next line, so that words that wrap to the
718 // next line are found too: "et<line-break>al.".
719 // Trick: skip a few chars for C/shell/Vim comments
720 nextline[SPWORDLEN] = NUL;
721 if (lnum < wp->w_buffer->b_ml.ml_line_count)
722 {
723 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
724 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
725 }
726
727 // When a word wrapped from the previous line the start of the
728 // current line is valid.
729 if (lnum == checked_lnum)
730 cur_checked_col = checked_col;
731 checked_lnum = 0;
732
733 // When there was a sentence end in the previous line may require a
734 // word starting with capital in this line. In line 1 always check
735 // the first word.
736 if (lnum != capcol_lnum)
737 cap_col = -1;
738 if (lnum == 1)
739 cap_col = 0;
740 capcol_lnum = 0;
741 }
742#endif
743
744 // handle Visual active in this window
745 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
746 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100747 pos_T *top, *bot;
748
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200749 if (LTOREQ_POS(curwin->w_cursor, VIsual))
750 {
751 // Visual is after curwin->w_cursor
752 top = &curwin->w_cursor;
753 bot = &VIsual;
754 }
755 else
756 {
757 // Visual is before curwin->w_cursor
758 top = &VIsual;
759 bot = &curwin->w_cursor;
760 }
761 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
762 if (VIsual_mode == Ctrl_V)
763 {
764 // block mode
765 if (lnum_in_visual_area)
766 {
767 fromcol = wp->w_old_cursor_fcol;
768 tocol = wp->w_old_cursor_lcol;
769 }
770 }
771 else
772 {
773 // non-block mode
774 if (lnum > top->lnum && lnum <= bot->lnum)
775 fromcol = 0;
776 else if (lnum == top->lnum)
777 {
778 if (VIsual_mode == 'V') // linewise
779 fromcol = 0;
780 else
781 {
782 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
783 if (gchar_pos(top) == NUL)
784 tocol = fromcol + 1;
785 }
786 }
787 if (VIsual_mode != 'V' && lnum == bot->lnum)
788 {
789 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
790 {
791 fromcol = -10;
792 tocol = MAXCOL;
793 }
794 else if (bot->col == MAXCOL)
795 tocol = MAXCOL;
796 else
797 {
798 pos = *bot;
799 if (*p_sel == 'e')
800 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
801 else
802 {
803 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
804 ++tocol;
805 }
806 }
807 }
808 }
809
810 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200811 if (!highlight_match && lnum == curwin->w_cursor.lnum
812 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200813#ifdef FEAT_GUI
814 && !gui.in_use
815#endif
816 )
817 noinvcur = TRUE;
818
819 // if inverting in this line set area_highlighting
820 if (fromcol >= 0)
821 {
822 area_highlighting = TRUE;
823 vi_attr = HL_ATTR(HLF_V);
824#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
825 if ((clip_star.available && !clip_star.owned
826 && clip_isautosel_star())
827 || (clip_plus.available && !clip_plus.owned
828 && clip_isautosel_plus()))
829 vi_attr = HL_ATTR(HLF_VNC);
830#endif
831 }
832 }
833
834 // handle 'incsearch' and ":s///c" highlighting
835 else if (highlight_match
836 && wp == curwin
837 && lnum >= curwin->w_cursor.lnum
838 && lnum <= curwin->w_cursor.lnum + search_match_lines)
839 {
840 if (lnum == curwin->w_cursor.lnum)
841 getvcol(curwin, &(curwin->w_cursor),
842 (colnr_T *)&fromcol, NULL, NULL);
843 else
844 fromcol = 0;
845 if (lnum == curwin->w_cursor.lnum + search_match_lines)
846 {
847 pos.lnum = lnum;
848 pos.col = search_match_endcol;
849 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
850 }
851 else
852 tocol = MAXCOL;
853 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100854 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200855 tocol = fromcol + 1;
856 area_highlighting = TRUE;
857 vi_attr = HL_ATTR(HLF_I);
858 }
859 }
860
861#ifdef FEAT_DIFF
862 filler_lines = diff_check(wp, lnum);
863 if (filler_lines < 0)
864 {
865 if (filler_lines == -1)
866 {
867 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100868 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200869 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100870 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200871 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100872 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200873 }
874 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100875 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200876 filler_lines = 0;
877 area_highlighting = TRUE;
878 }
879 if (lnum == wp->w_topline)
880 filler_lines = wp->w_topfill;
881 filler_todo = filler_lines;
882#endif
883
884#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100885 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000886 if (sign_present)
887 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200888#endif
889
890#ifdef LINE_ATTR
891# ifdef FEAT_SIGNS
892 // If this line has a sign with line highlighting set line_attr.
893 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200894 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200895# endif
896# if defined(FEAT_QUICKFIX)
897 // Highlight the current line in the quickfix window.
898 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
899 line_attr = HL_ATTR(HLF_QFL);
900# endif
901 if (line_attr != 0)
902 area_highlighting = TRUE;
903#endif
904
905 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
906 ptr = line;
907
908#ifdef FEAT_SPELL
909 if (has_spell && !number_only)
910 {
911 // For checking first word with a capital skip white space.
912 if (cap_col == 0)
913 cap_col = getwhitecols(line);
914
915 // To be able to spell-check over line boundaries copy the end of the
916 // current line into nextline[]. Above the start of the next line was
917 // copied to nextline[SPWORDLEN].
918 if (nextline[SPWORDLEN] == NUL)
919 {
920 // No next line or it is empty.
921 nextlinecol = MAXCOL;
922 nextline_idx = 0;
923 }
924 else
925 {
926 v = (long)STRLEN(line);
927 if (v < SPWORDLEN)
928 {
929 // Short line, use it completely and append the start of the
930 // next line.
931 nextlinecol = 0;
932 mch_memmove(nextline, line, (size_t)v);
933 STRMOVE(nextline + v, nextline + SPWORDLEN);
934 nextline_idx = v + 1;
935 }
936 else
937 {
938 // Long line, use only the last SPWORDLEN bytes.
939 nextlinecol = v - SPWORDLEN;
940 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
941 nextline_idx = SPWORDLEN + 1;
942 }
943 }
944 }
945#endif
946
947 if (wp->w_p_list)
948 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100949 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200950 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100951 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100952 || wp->w_lcs_chars.trail
953 || wp->w_lcs_chars.lead
954 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200955 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100956
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200957 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100958 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200959 {
960 trailcol = (colnr_T)STRLEN(ptr);
961 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
962 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100963 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100965 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100966 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100967 {
968 leadcol = 0;
969 while (VIM_ISWHITE(ptr[leadcol]))
970 ++leadcol;
971 if (ptr[leadcol] == NUL)
972 // in a line full of spaces all of them are treated as trailing
973 leadcol = (colnr_T)0;
974 else
975 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100976 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100977 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200978 }
979
980 wcr_attr = get_wcr_attr(wp);
981 if (wcr_attr != 0)
982 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100983 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 area_highlighting = TRUE;
985 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200986
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100987#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100989 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990#endif
991
992 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
993 // first character to be displayed.
994 if (wp->w_p_wrap)
995 v = wp->w_skipcol;
996 else
997 v = wp->w_leftcol;
998 if (v > 0 && !number_only)
999 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001000 char_u *prev_ptr = ptr;
1001 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001002 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001004 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001005 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001007 charsize = win_lbr_chartabsize(&cts, NULL);
1008 cts.cts_vcol += charsize;
1009 prev_ptr = cts.cts_ptr;
1010 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001012 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001013 ptr = cts.cts_ptr;
1014 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015
1016 // When:
1017 // - 'cuc' is set, or
1018 // - 'colorcolumn' is set, or
1019 // - 'virtualedit' is set, or
1020 // - the visual mode is active,
1021 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001022 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001024 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025#endif
1026 virtual_active() ||
1027 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001028 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029
1030 // Handle a character that's not completely on the screen: Put ptr at
1031 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001032 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001034 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035 ptr = prev_ptr;
1036 // If the character fits on the screen, don't need to skip it.
1037 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001038 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1039 && wlv.col == 0)
1040 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041 }
1042
1043 // Adjust for when the inverted text is before the screen,
1044 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001045 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001046 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001047 else if (fromcol >= 0 && fromcol < wlv.vcol)
1048 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049
1050#ifdef FEAT_LINEBREAK
1051 // When w_skipcol is non-zero, first line needs 'showbreak'
1052 if (wp->w_p_wrap)
1053 need_showbreak = TRUE;
1054#endif
1055#ifdef FEAT_SPELL
1056 // When spell checking a word we need to figure out the start of the
1057 // word and if it's badly spelled or not.
1058 if (has_spell)
1059 {
1060 int len;
1061 colnr_T linecol = (colnr_T)(ptr - line);
1062 hlf_T spell_hlf = HLF_COUNT;
1063
1064 pos = wp->w_cursor;
1065 wp->w_cursor.lnum = lnum;
1066 wp->w_cursor.col = linecol;
1067 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1068
1069 // spell_move_to() may call ml_get() and make "line" invalid
1070 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1071 ptr = line + linecol;
1072
1073 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1074 {
1075 // no bad word found at line start, don't check until end of a
1076 // word
1077 spell_hlf = HLF_COUNT;
1078 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1079 }
1080 else
1081 {
1082 // bad word found, use attributes until end of word
1083 word_end = wp->w_cursor.col + len + 1;
1084
1085 // Turn index into actual attributes.
1086 if (spell_hlf != HLF_COUNT)
1087 spell_attr = highlight_attr[spell_hlf];
1088 }
1089 wp->w_cursor = pos;
1090
1091# ifdef FEAT_SYN_HL
1092 // Need to restart syntax highlighting for this line.
1093 if (has_syntax)
1094 syntax_start(wp, lnum);
1095# endif
1096 }
1097#endif
1098 }
1099
1100 // Correct highlighting for cursor that can't be disabled.
1101 // Avoids having to check this for each character.
1102 if (fromcol >= 0)
1103 {
1104 if (noinvcur)
1105 {
1106 if ((colnr_T)fromcol == wp->w_virtcol)
1107 {
1108 // highlighting starts at cursor, let it start just after the
1109 // cursor
1110 fromcol_prev = fromcol;
1111 fromcol = -1;
1112 }
1113 else if ((colnr_T)fromcol < wp->w_virtcol)
1114 // restart highlighting after the cursor
1115 fromcol_prev = wp->w_virtcol;
1116 }
1117 if (fromcol >= tocol)
1118 fromcol = -1;
1119 }
1120
1121#ifdef FEAT_SEARCH_EXTRA
1122 if (!number_only)
1123 {
1124 v = (long)(ptr - line);
1125 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1126 &line, &screen_search_hl,
1127 &search_attr);
1128 ptr = line + v; // "line" may have been updated
1129 }
1130#endif
1131
1132#ifdef FEAT_SYN_HL
1133 // Cursor line highlighting for 'cursorline' in the current window.
1134 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1135 {
1136 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001137 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 if (!(wp == curwin && VIsual_active)
1139 && wp->w_p_culopt_flags != CULOPT_NBR)
1140 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001141 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001142 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1143
1144 // Only set line_attr here when "screenline" is not present in
1145 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001146 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147 {
1148 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001149# ifdef FEAT_SIGNS
1150 // Combine the 'cursorline' and sign highlighting, depending on
1151 // the sign priority.
1152 if (sign_present && sattr.sat_linehl > 0)
1153 {
1154 if (sattr.sat_priority >= 100)
1155 line_attr = hl_combine_attr(cul_attr, line_attr);
1156 else
1157 line_attr = hl_combine_attr(line_attr, cul_attr);
1158 }
1159 else
1160# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001161# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001162 // let the line attribute overrule 'cursorline', otherwise
1163 // it disappears when both have background set;
1164 // 'cursorline' can use underline or bold to make it show
1165 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001166# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001167 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001168# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 }
1170 else
1171 {
1172 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001173 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1174 }
1175 area_highlighting = TRUE;
1176 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177 }
1178#endif
1179
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001180#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181 {
1182 char_u *prop_start;
1183
1184 text_prop_count = get_text_props(wp->w_buffer, lnum,
1185 &prop_start, FALSE);
1186 if (text_prop_count > 0)
1187 {
1188 // Make a copy of the properties, so that they are properly
1189 // aligned.
1190 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1191 if (text_props != NULL)
1192 mch_memmove(text_props, prop_start,
1193 text_prop_count * sizeof(textprop_T));
1194
1195 // Allocate an array for the indexes.
1196 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1197 area_highlighting = TRUE;
1198 extra_check = TRUE;
1199 }
1200 }
1201#endif
1202
Bram Moolenaar1306b362022-08-06 15:59:06 +01001203 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204
1205 // Repeat for the whole displayed line.
1206 for (;;)
1207 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001208 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001210 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211#endif
1212#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001213 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001215
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001217 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001219#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001220 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001221 {
1222 cul_attr = 0;
1223 line_attr = line_attr_save;
1224 }
1225#endif
1226
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001228 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001230 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231 if (cmdwin_type != 0 && wp == curwin)
1232 {
1233 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001234 wlv.n_extra = 1;
1235 wlv.c_extra = cmdwin_type;
1236 wlv.c_final = NUL;
1237 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 }
1239 }
1240#endif
1241
1242#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001243 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244 {
1245 int fdc = compute_foldcolumn(wp, 0);
1246
Bram Moolenaar1306b362022-08-06 15:59:06 +01001247 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 if (fdc > 0)
1249 {
1250 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1251 // already be in use.
1252 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001253 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 if (p_extra_free != NULL)
1255 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001256 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001257 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001258 p_extra_free[wlv.n_extra] = NUL;
1259 wlv.p_extra = p_extra_free;
1260 wlv.c_extra = NUL;
1261 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001262 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001263 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001264 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1265 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001266 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001267 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 }
1269 }
1270 }
1271#endif
1272
1273#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001274 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001276 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 // Show the sign column when there are any signs in this
1278 // buffer or when using Netbeans.
1279 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001280 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1281 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001282 }
1283#endif
1284
Bram Moolenaar1306b362022-08-06 15:59:06 +01001285 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001287 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 // Display the absolute or relative line number. After the
1289 // first fill with blanks when the 'n' flag isn't in 'cpo'
1290 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001291 && (wlv.row == startrow + filler_lines
1292 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 {
1294#ifdef FEAT_SIGNS
1295 // If 'signcolumn' is set to 'number' and a sign is present
1296 // in 'lnum', then display the sign instead of the line
1297 // number.
1298 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1299 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001300 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1301 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 else
1303#endif
1304 {
1305 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001306 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 {
1308 long num;
1309 char *fmt = "%*ld ";
1310
1311 if (wp->w_p_nu && !wp->w_p_rnu)
1312 // 'number' + 'norelativenumber'
1313 num = (long)lnum;
1314 else
1315 {
1316 // 'relativenumber', don't use negative numbers
1317 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1318 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1319 {
1320 // 'number' + 'relativenumber'
1321 num = lnum;
1322 fmt = "%-*ld ";
1323 }
1324 }
1325
1326 sprintf((char *)extra, fmt,
1327 number_width(wp), num);
1328 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001329 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1330 ++wlv.p_extra)
1331 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332#ifdef FEAT_RIGHTLEFT
1333 if (wp->w_p_rl) // reverse line numbers
1334 {
1335 char_u *p1, *p2;
1336 int t;
1337
1338 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001339 p2 = skipwhite(extra);
1340 p2 = skiptowhite(p2) - 1;
1341 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 {
1343 t = *p1;
1344 *p1 = *p2;
1345 *p2 = t;
1346 }
1347 }
1348#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001349 wlv.p_extra = extra;
1350 wlv.c_extra = NUL;
1351 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 }
1353 else
1354 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001355 wlv.c_extra = ' ';
1356 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001357 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001358 wlv.n_extra = number_width(wp) + 1;
1359 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360#ifdef FEAT_SYN_HL
1361 // When 'cursorline' is set highlight the line number of
1362 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001363 // When 'cursorlineopt' does not have "line" only
1364 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 // TODO: Can we use CursorLine instead of CursorLineNr
1366 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001367 if (wp->w_p_cul
1368 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001370 && (wlv.row == startrow + filler_lines
1371 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001372 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001373 wlv.char_attr = hl_combine_attr(wcr_attr,
1374 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001376 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1377 && HL_ATTR(HLF_LNA) != 0)
1378 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001379 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001380 HL_ATTR(HLF_LNA));
1381 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1382 && HL_ATTR(HLF_LNB) != 0)
1383 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001384 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001385 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 }
James McCoya80aad72021-12-22 19:45:28 +00001387#ifdef FEAT_SIGNS
1388 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001389 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001390#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391 }
1392 }
1393
1394#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001395 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1396 && wlv.n_extra == 0
1397 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001398 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001399 wlv.draw_state = WL_BRI;
1400 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1401 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001403 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404
1405 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001406 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001408 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001410 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411# ifdef FEAT_DIFF
1412 && filler_lines == 0
1413# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001414# ifdef FEAT_PROP_POPUP
1415 && !dont_use_showbreak
1416# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 )
1418 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001419 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001421 if (wlv.diff_hlf != (hlf_T)0)
1422 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001424 wlv.p_extra = NULL;
1425 wlv.c_extra = ' ';
1426 wlv.c_final = NUL;
1427 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001429 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001430 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001431 wlv.n_extra -= win_col_off2(wp);
1432 if (wlv.n_extra < 0)
1433 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001434 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001435 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001436 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437 // Correct end of highlighted area for 'breakindent',
1438 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001439 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001440 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441 }
1442 }
1443#endif
1444
1445#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001446 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001448 char_u *sbr;
1449
Bram Moolenaar1306b362022-08-06 15:59:06 +01001450 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451# ifdef FEAT_DIFF
1452 if (filler_todo > 0)
1453 {
1454 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001455 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001457 wlv.c_extra = '-';
1458 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459 }
1460 else
1461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001462 wlv.c_extra = wp->w_fill_chars.diff;
1463 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 }
1465# ifdef FEAT_RIGHTLEFT
1466 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001467 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 else
1469# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001470 wlv.n_extra = wp->w_width - wlv.col;
1471 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472 }
1473# endif
1474# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001475 sbr = get_showbreak_value(wp);
1476 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 {
1478 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001479 wlv.p_extra = sbr;
1480 wlv.c_extra = NUL;
1481 wlv.c_final = NUL;
1482 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001483 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1484 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001485 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486 // Correct end of highlighted area for 'showbreak',
1487 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001488 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001489 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001491 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1492 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493# ifdef FEAT_SYN_HL
1494 // combine 'showbreak' with 'cursorline'
1495 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001496 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1497 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498# endif
1499 }
1500# endif
1501 }
1502#endif
1503
Bram Moolenaar1306b362022-08-06 15:59:06 +01001504 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001506 wlv.draw_state = WL_LINE;
1507 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508 {
1509 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001510 wlv.n_extra = wlv.saved_n_extra;
1511 wlv.c_extra = wlv.saved_c_extra;
1512 wlv.c_final = wlv.saved_c_final;
1513 wlv.p_extra = wlv.saved_p_extra;
1514 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 }
1516 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001517 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 }
1519 }
1520#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001521 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001522 && wlv.vcol >= left_curline_col
1523 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001525 cul_attr = HL_ATTR(HLF_CUL);
1526 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 }
1528#endif
1529
1530 // When still displaying '$' of change command, stop at cursor.
1531 // When only displaying the (relative) line number and that's done,
1532 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001533 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001534 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001535 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536#ifdef FEAT_DIFF
1537 && filler_todo <= 0
1538#endif
1539 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001541 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1542 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 // Pretend we have finished updating the window. Except when
1544 // 'cursorcolumn' is set.
1545#ifdef FEAT_SYN_HL
1546 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001547 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548 else
1549#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001550 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 break;
1552 }
1553
Bram Moolenaar1306b362022-08-06 15:59:06 +01001554 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555 {
1556 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001557 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001558 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559 && (*mb_ptr2cells)(ptr) > 1)
1560 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001561 && vcol_prev < wlv.vcol // not at margin
1562 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563 area_attr = vi_attr; // start highlighting
1564 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001565 && (wlv.vcol == tocol
1566 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 area_attr = 0; // stop highlighting
1568
1569#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar1306b362022-08-06 15:59:06 +01001570 if (!wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 {
1572 // Check for start/end of 'hlsearch' and other matches.
1573 // After end, check for start/end of next match.
1574 // When another match, have to check for start again.
1575 v = (long)(ptr - line);
1576 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1577 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001578 &match_conc, did_line_attr, lcs_eol_one,
1579 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001581 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001582
1583 // Do not allow a conceal over EOL otherwise EOL will be missed
1584 // and bad things happen.
1585 if (*ptr == NUL)
1586 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 }
1588#endif
1589
1590#ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001591 if (wlv.diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001593 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1594 && wlv.n_extra == 0)
1595 wlv.diff_hlf = HLF_TXD; // changed text
1596 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1597 && wlv.n_extra == 0)
1598 wlv.diff_hlf = HLF_CHD; // changed line
1599 line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1601 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01001602 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001603 && wlv.vcol <= right_curline_col)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 line_attr = hl_combine_attr(
1605 line_attr, HL_ATTR(HLF_CUL));
1606 }
1607#endif
1608
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001609#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 if (text_props != NULL)
1611 {
1612 int pi;
1613 int bcol = (int)(ptr - line);
1614
Bram Moolenaar1306b362022-08-06 15:59:06 +01001615 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001616# ifdef FEAT_LINEBREAK
1617 && !in_linebreak
1618# endif
1619 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 --bcol; // still working on the previous char, e.g. Tab
1621
1622 // Check if any active property ends.
1623 for (pi = 0; pi < text_props_active; ++pi)
1624 {
1625 int tpi = text_prop_idxs[pi];
1626
1627 if (bcol >= text_props[tpi].tp_col - 1
1628 + text_props[tpi].tp_len)
1629 {
1630 if (pi + 1 < text_props_active)
1631 mch_memmove(text_prop_idxs + pi,
1632 text_prop_idxs + pi + 1,
1633 sizeof(int)
1634 * (text_props_active - (pi + 1)));
1635 --text_props_active;
1636 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001637# ifdef FEAT_LINEBREAK
1638 // not exactly right but should work in most cases
1639 if (in_linebreak && syntax_attr == text_prop_attr)
1640 syntax_attr = 0;
1641# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642 }
1643 }
1644
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001645# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001646 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001647 // not on the next char yet, don't start another prop
1648 --bcol;
1649# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001651 // With 'nowrap' and not in the first screen line only "below"
1652 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001654 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001655 ? (*ptr == NUL
1656 && (wp->w_p_wrap
1657 || wlv.row == startrow
1658 || (text_props[text_prop_next].tp_flags
1659 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001660 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001661 {
1662 if (bcol <= text_props[text_prop_next].tp_col - 1
1663 + text_props[text_prop_next].tp_len)
1664 text_prop_idxs[text_props_active++] = text_prop_next;
1665 ++text_prop_next;
1666 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667
1668 text_prop_attr = 0;
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001669 text_prop_flags = 0;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001670 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001671 text_prop_id = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001672 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001674 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001675 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001676 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001677
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 // Sort the properties on priority and/or starting last.
1679 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001680 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 current_text_props = text_props;
1682 current_buf = wp->w_buffer;
1683 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1684 sizeof(int), text_prop_compare);
1685
1686 for (pi = 0; pi < text_props_active; ++pi)
1687 {
1688 int tpi = text_prop_idxs[pi];
1689 proptype_T *pt = text_prop_type_by_id(
1690 wp->w_buffer, text_props[tpi].tp_type);
1691
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001692 if (pt != NULL && pt->pt_hl_id > 0
1693 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001695 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 text_prop_type = pt;
1697 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001698 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001699 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001700 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001701 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001702 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 }
1704 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001705 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001706 && -text_prop_id
1707 <= wp->w_buffer->b_textprop_text.ga_len)
1708 {
1709 char_u *p = ((char_u **)wp->w_buffer
1710 ->b_textprop_text.ga_data)[
1711 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001712
1713 // reset the ID in the copy to avoid it being used
1714 // again
1715 text_props[used_tpi].tp_id = -MAXCOL;
1716
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001717 if (p != NULL)
1718 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001719 int right = (text_props[used_tpi].tp_flags
1720 & TP_FLAG_ALIGN_RIGHT);
1721 int below = (text_props[used_tpi].tp_flags
1722 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001723 int wrap = (text_props[used_tpi].tp_flags
1724 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001725
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 wlv.p_extra = p;
1727 wlv.c_extra = NUL;
1728 wlv.c_final = NUL;
1729 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001730 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001731 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001732 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001733 if (*ptr == NUL)
1734 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001735 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001736#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001737 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001738 {
1739 // no 'showbreak' before "below" text property
1740 // or after "right" text property
1741 need_showbreak = FALSE;
1742 dont_use_showbreak = TRUE;
1743 }
1744#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001745 // Keep in sync with where
1746 // textprop_size_after_trunc() is called in
1747 // win_lbr_chartabsize().
1748 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001750 int added = wp->w_width - wlv.col;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001751 int n_used = wlv.n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001752 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001753 int strsize = wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001754 ? vim_strsize(wlv.p_extra)
1755 : textprop_size_after_trunc(wp,
1756 below, added, wlv.p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001757
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 if (wrap || right || below
1759 || n_used < wlv.n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001760 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001761 // Right-align: fill with spaces
1762 if (right)
1763 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001764 if (added < 0
1765 || (below
1766 ? wlv.col == 0 || !wp->w_p_wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001767 : n_used < wlv.n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001768 added = 0;
1769 // add 1 for NUL, 2 for when '…' is used
1770 l = alloc(n_used + added + 3);
1771 if (l != NULL)
1772 {
1773 vim_memset(l, ' ', added);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001774 vim_strncpy(l + added, wlv.p_extra,
1775 n_used);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001776 if (n_used < wlv.n_extra
1777 && wp->w_p_wrap)
Bram Moolenaar398649e2022-08-04 15:03:48 +01001778 {
1779 char_u *lp = l + added + n_used - 1;
1780
1781 if (has_mbyte)
1782 {
1783 // change last character to '…'
1784 lp -= (*mb_head_off)(l, lp);
1785 STRCPY(lp, "…");
1786 n_used = lp - l + 3;
1787 }
1788 else
1789 // change last character to '>'
1790 *lp = '>';
1791 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001792 vim_free(p_extra_free2);
1793 wlv.p_extra = p_extra_free2 = l;
1794 wlv.n_extra = n_used + added;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001795 n_attr_skip = added;
1796 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001797 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001798
1799 // When 'wrap' is off then for "below" we need
1800 // to start a new line explictly.
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01001801 if (below && wlv.col > win_col_off(wp)
1802 && !wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001803 {
1804 draw_screen_line(wp, &wlv);
1805
1806 // When line got too long for screen break
1807 // here.
1808 if (wlv.row == endrow)
1809 {
1810 ++wlv.row;
1811 break;
1812 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001813 win_line_start(wp, &wlv, TRUE);
1814 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001815 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001816 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001817 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001818
1819 // If another text prop follows the condition below at
1820 // the last window column must know.
1821 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001822 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001824 else if (text_prop_next < text_prop_count
1825 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001826 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1827 || (!wp->w_p_wrap
1828 && wlv.col == wp->w_width - 1
1829 && (text_props[text_prop_next].tp_flags
1830 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001831 // When at last-but-one character and a text property
1832 // follows after it, we may need to flush the line after
1833 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001834 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001835 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 }
1837#endif
1838
Bram Moolenaara74fda62019-10-19 17:38:03 +02001839#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001840 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001841 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001842 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001843# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001844 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001845 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001846# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001847 // Get syntax attribute.
1848 if (has_syntax)
1849 {
1850 // Get the syntax attribute for the character. If there
1851 // is an error, disable syntax highlighting.
1852 save_did_emsg = did_emsg;
1853 did_emsg = FALSE;
1854
1855 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001856 if (v == prev_syntax_col)
1857 // at same column again
1858 syntax_attr = prev_syntax_attr;
1859 else
1860 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001861# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001862 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001863# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001864 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001865# ifdef FEAT_SPELL
1866 has_spell ? &can_spell :
1867# endif
1868 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001869 prev_syntax_col = v;
1870 prev_syntax_attr = syntax_attr;
1871 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001872
Bram Moolenaar34390282019-10-16 14:38:26 +02001873 if (did_emsg)
1874 {
1875 wp->w_s->b_syn_error = TRUE;
1876 has_syntax = FALSE;
1877 syntax_attr = 0;
1878 }
1879 else
1880 did_emsg = save_did_emsg;
1881# ifdef SYN_TIME_LIMIT
1882 if (wp->w_s->b_syn_slow)
1883 has_syntax = FALSE;
1884# endif
1885
1886 // Need to get the line again, a multi-line regexp may
1887 // have made it invalid.
1888 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1889 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001890 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001891# ifdef FEAT_CONCEAL
1892 // no concealing past the end of the line, it interferes
1893 // with line highlighting
1894 if (*ptr == NUL)
1895 syntax_flags = 0;
1896 else
1897 syntax_flags = get_syntax_info(&syntax_seqnr);
1898# endif
1899 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001900 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001901# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001902 // Combine text property highlight into syntax highlight.
1903 if (text_prop_type != NULL)
1904 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001905 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001906 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1907 else
1908 syntax_attr = text_prop_attr;
1909 }
1910# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001911#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001912
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 // Decide which of the highlight attributes to use.
1914 attr_pri = TRUE;
1915#ifdef LINE_ATTR
1916 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001917 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001918 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001919 if (!highlight_match)
1920 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001921 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001922# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001924# endif
1925 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001927 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001928 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001929# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001930 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001931# endif
1932 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001934 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1935 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001936 {
1937 // Use line_attr when not in the Visual or 'incsearch' area
1938 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001939# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001940 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01001941# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001942 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001943# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 attr_pri = FALSE;
1945 }
1946#else
1947 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001948 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001949 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001950 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951#endif
1952 else
1953 {
1954 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001956 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001957#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001958 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001959#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001960 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001961#ifdef FEAT_PROP_POPUP
1962 // override with text property highlight when "override" is TRUE
1963 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001964 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001965#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001966 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001967
1968 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001969 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001970 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001971 if (wlv.char_attr == 0)
1972 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001973 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001974 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001975 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976
1977 // Get the next character to put on the screen.
1978
1979 // The "p_extra" points to the extra stuff that is inserted to
1980 // represent special characters (non-printable stuff) and other
1981 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001982 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1984 // "p_extra[n_extra]".
1985 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001988 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001990 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
1991 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1993 if (enc_utf8 && utf_char2len(c) > 1)
1994 {
1995 mb_utf8 = TRUE;
1996 u8cc[0] = 0;
1997 c = 0xc0;
1998 }
1999 else
2000 mb_utf8 = FALSE;
2001 }
2002 else
2003 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002004 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002005 if (has_mbyte)
2006 {
2007 mb_c = c;
2008 if (enc_utf8)
2009 {
2010 // If the UTF-8 character is more than one byte:
2011 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002012 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002014 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002015 mb_l = 1;
2016 else if (mb_l > 1)
2017 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002018 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 mb_utf8 = TRUE;
2020 c = 0xc0;
2021 }
2022 }
2023 else
2024 {
2025 // if this is a DBCS character, put it in "mb_c"
2026 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002027 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028 mb_l = 1;
2029 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002030 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002031 }
2032 if (mb_l == 0) // at the NUL at end-of-line
2033 mb_l = 1;
2034
2035 // If a double-width char doesn't fit display a '>' in the
2036 // last column.
2037 if ((
2038# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002039 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002041 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002042 && (*mb_char2cells)(mb_c) == 2)
2043 {
2044 c = '>';
2045 mb_c = c;
2046 mb_l = 1;
2047 mb_utf8 = FALSE;
2048 multi_attr = HL_ATTR(HLF_AT);
2049#ifdef FEAT_SYN_HL
2050 if (cul_attr)
2051 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2052#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002053 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002054
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 // put the pointer back to output the double-width
2056 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002057 ++wlv.n_extra;
2058 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059 }
2060 else
2061 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002062 wlv.n_extra -= mb_l - 1;
2063 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002064 }
2065 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002066 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002068 --wlv.n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002069#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 if (wlv.n_extra <= 0)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002071 in_linebreak = FALSE;
2072#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073 }
2074 else
2075 {
2076#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002077 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002079 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002080
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002081 // Get a character from the line itself.
2082 c = *ptr;
2083#ifdef FEAT_LINEBREAK
2084 c0 = *ptr;
2085#endif
2086 if (has_mbyte)
2087 {
2088 mb_c = c;
2089 if (enc_utf8)
2090 {
2091 // If the UTF-8 character is more than one byte: Decode it
2092 // into "mb_c".
2093 mb_l = utfc_ptr2len(ptr);
2094 mb_utf8 = FALSE;
2095 if (mb_l > 1)
2096 {
2097 mb_c = utfc_ptr2char(ptr, u8cc);
2098 // Overlong encoded ASCII or ASCII with composing char
2099 // is displayed normally, except a NUL.
2100 if (mb_c < 0x80)
2101 {
2102 c = mb_c;
2103#ifdef FEAT_LINEBREAK
2104 c0 = mb_c;
2105#endif
2106 }
2107 mb_utf8 = TRUE;
2108
2109 // At start of the line we can have a composing char.
2110 // Draw it as a space with a composing char.
2111 if (utf_iscomposing(mb_c))
2112 {
2113 int i;
2114
2115 for (i = Screen_mco - 1; i > 0; --i)
2116 u8cc[i] = u8cc[i - 1];
2117 u8cc[0] = mb_c;
2118 mb_c = ' ';
2119 }
2120 }
2121
2122 if ((mb_l == 1 && c >= 0x80)
2123 || (mb_l >= 1 && mb_c == 0)
2124 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2125 {
2126 // Illegal UTF-8 byte: display as <xx>.
2127 // Non-BMP character : display as ? or fullwidth ?.
2128 transchar_hex(extra, mb_c);
2129# ifdef FEAT_RIGHTLEFT
2130 if (wp->w_p_rl) // reverse
2131 rl_mirror(extra);
2132# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002133 wlv.p_extra = extra;
2134 c = *wlv.p_extra;
2135 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002136 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2138 wlv.c_extra = NUL;
2139 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002140 if (area_attr == 0 && search_attr == 0)
2141 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002142 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002143 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002144 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002145 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002146 }
2147 }
2148 else if (mb_l == 0) // at the NUL at end-of-line
2149 mb_l = 1;
2150#ifdef FEAT_ARABIC
2151 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2152 {
2153 // Do Arabic shaping.
2154 int pc, pc1, nc;
2155 int pcc[MAX_MCO];
2156
2157 // The idea of what is the previous and next
2158 // character depends on 'rightleft'.
2159 if (wp->w_p_rl)
2160 {
2161 pc = prev_c;
2162 pc1 = prev_c1;
2163 nc = utf_ptr2char(ptr + mb_l);
2164 prev_c1 = u8cc[0];
2165 }
2166 else
2167 {
2168 pc = utfc_ptr2char(ptr + mb_l, pcc);
2169 nc = prev_c;
2170 pc1 = pcc[0];
2171 }
2172 prev_c = mb_c;
2173
2174 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2175 }
2176 else
2177 prev_c = mb_c;
2178#endif
2179 }
2180 else // enc_dbcs
2181 {
2182 mb_l = MB_BYTE2LEN(c);
2183 if (mb_l == 0) // at the NUL at end-of-line
2184 mb_l = 1;
2185 else if (mb_l > 1)
2186 {
2187 // We assume a second byte below 32 is illegal.
2188 // Hopefully this is OK for all double-byte encodings!
2189 if (ptr[1] >= 32)
2190 mb_c = (c << 8) + ptr[1];
2191 else
2192 {
2193 if (ptr[1] == NUL)
2194 {
2195 // head byte at end of line
2196 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002197 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002198 }
2199 else
2200 {
2201 // illegal tail byte
2202 mb_l = 2;
2203 STRCPY(extra, "XX");
2204 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002205 wlv.p_extra = extra;
2206 wlv.n_extra = (int)STRLEN(extra) - 1;
2207 wlv.c_extra = NUL;
2208 wlv.c_final = NUL;
2209 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210 if (area_attr == 0 && search_attr == 0)
2211 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002212 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002213 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002214 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 // save current attr
2216 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 }
2218 mb_c = c;
2219 }
2220 }
2221 }
2222 // If a double-width char doesn't fit display a '>' in the
2223 // last column; the character is displayed at the start of the
2224 // next line.
2225 if ((
2226# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002227 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002228# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002229 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002230 && (*mb_char2cells)(mb_c) == 2)
2231 {
2232 c = '>';
2233 mb_c = c;
2234 mb_utf8 = FALSE;
2235 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002236 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 // Put pointer back so that the character will be
2238 // displayed at the start of the next line.
2239 --ptr;
2240#ifdef FEAT_CONCEAL
2241 did_decrement_ptr = TRUE;
2242#endif
2243 }
2244 else if (*ptr != NUL)
2245 ptr += mb_l - 1;
2246
2247 // If a double-width char doesn't fit at the left side display
2248 // a '<' in the first column. Don't do this for unprintable
2249 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002250 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002252 wlv.n_extra = 1;
2253 wlv.c_extra = MB_FILLER_CHAR;
2254 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002255 c = ' ';
2256 if (area_attr == 0 && search_attr == 0)
2257 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002258 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002259 extra_attr = hl_combine_attr(
2260 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002261 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002262 }
2263 mb_c = c;
2264 mb_utf8 = FALSE;
2265 mb_l = 1;
2266 }
2267
2268 }
2269 ++ptr;
2270
2271 if (extra_check)
2272 {
2273#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 // Check spelling (unless at the end of the line).
2275 // Only do this when there is no syntax highlighting, the
2276 // @Spell cluster is not used or the current syntax item
2277 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002278 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002279 if (has_spell && v >= word_end && v > cur_checked_col)
2280 {
2281 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002282 // do not calculate cap_col at the end of the line or when
2283 // only white space is following
2284 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002285# ifdef FEAT_SYN_HL
2286 !has_syntax ||
2287# endif
2288 can_spell))
2289 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002290 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002291 int len;
2292 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002293
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002295 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296
2297 // Use nextline[] if possible, it has the start of the
2298 // next line concatenated.
2299 if ((prev_ptr - line) - nextlinecol >= 0)
2300 p = nextline + (prev_ptr - line) - nextlinecol;
2301 else
2302 p = prev_ptr;
2303 cap_col -= (int)(prev_ptr - line);
2304 len = spell_check(wp, p, &spell_hlf, &cap_col,
2305 nochange);
2306 word_end = v + len;
2307
2308 // In Insert mode only highlight a word that
2309 // doesn't touch the cursor.
2310 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002311 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002312 && wp->w_cursor.lnum == lnum
2313 && wp->w_cursor.col >=
2314 (colnr_T)(prev_ptr - line)
2315 && wp->w_cursor.col < (colnr_T)word_end)
2316 {
2317 spell_hlf = HLF_COUNT;
2318 spell_redraw_lnum = lnum;
2319 }
2320
2321 if (spell_hlf == HLF_COUNT && p != prev_ptr
2322 && (p - nextline) + len > nextline_idx)
2323 {
2324 // Remember that the good word continues at the
2325 // start of the next line.
2326 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002327 checked_col = (int)((p - nextline)
2328 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 }
2330
2331 // Turn index into actual attributes.
2332 if (spell_hlf != HLF_COUNT)
2333 spell_attr = highlight_attr[spell_hlf];
2334
2335 if (cap_col > 0)
2336 {
2337 if (p != prev_ptr
2338 && (p - nextline) + cap_col >= nextline_idx)
2339 {
2340 // Remember that the word in the next line
2341 // must start with a capital.
2342 capcol_lnum = lnum + 1;
2343 cap_col = (int)((p - nextline) + cap_col
2344 - nextline_idx);
2345 }
2346 else
2347 // Compute the actual column.
2348 cap_col += (int)(prev_ptr - line);
2349 }
2350 }
2351 }
2352 if (spell_attr != 0)
2353 {
2354 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002355 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2356 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002358 wlv.char_attr = hl_combine_attr(spell_attr,
2359 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360 }
2361#endif
2362#ifdef FEAT_LINEBREAK
2363 // Found last space before word: check for line break.
2364 if (wp->w_p_lbr && c0 == c
2365 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2366 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002367 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2368 : 0;
2369 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002370 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002371
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002372 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002373# ifdef FEAT_PROP_POPUP
2374 // do not want virtual text counted here
2375 cts.cts_has_prop_with_text = FALSE;
2376# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002378 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002379
2380 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002381 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002382 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002384 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2385 if (wlv.n_extra < 0)
2386 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002387 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002388 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002389 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002390 // line break, but for TABs the highlighting should
2391 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002392 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002393
Bram Moolenaar1306b362022-08-06 15:59:06 +01002394 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002397 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 wp->w_buffer->b_p_vts_array) - 1;
2399# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002400 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002401 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402# endif
2403
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2405 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002406# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002407 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002408 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002409# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 if (VIM_ISWHITE(c))
2411 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002412# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002413 if (c == TAB)
2414 // See "Tab alignment" below.
2415 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002416# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002417 if (!wp->w_p_list)
2418 c = ' ';
2419 }
2420 }
2421#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002422 in_multispace = c == ' '
2423 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2424 if (!in_multispace)
2425 multispace_pos = 0;
2426
Bram Moolenaareed9d462021-02-15 20:38:25 +01002427 // 'list': Change char 160 to 'nbsp' and space to 'space'
2428 // setting in 'listchars'. But not when the character is
2429 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430 if (wp->w_p_list
2431 && ((((c == 160 && mb_l == 1)
2432 || (mb_utf8
2433 && ((mb_c == 160 && mb_l == 2)
2434 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002435 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002436 || (c == ' '
2437 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002438 && (wp->w_lcs_chars.space
2439 || (in_multispace
2440 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002441 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 && ptr - line <= trailcol)))
2443 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002444 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2445 {
2446 c = wp->w_lcs_chars.multispace[multispace_pos++];
2447 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2448 multispace_pos = 0;
2449 }
2450 else
2451 c = (c == ' ') ? wp->w_lcs_chars.space
2452 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 if (area_attr == 0 && search_attr == 0)
2454 {
2455 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002456 extra_attr = hl_combine_attr(wlv.win_attr,
2457 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 }
2460 mb_c = c;
2461 if (enc_utf8 && utf_char2len(c) > 1)
2462 {
2463 mb_utf8 = TRUE;
2464 u8cc[0] = 0;
2465 c = 0xc0;
2466 }
2467 else
2468 mb_utf8 = FALSE;
2469 }
2470
zeertzjq2e7cba32022-06-10 15:30:32 +01002471 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2472 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002474 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2475 && wp->w_lcs_chars.leadmultispace != NULL)
2476 {
2477 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002478 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2479 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002480 multispace_pos = 0;
2481 }
2482
2483 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2484 c = wp->w_lcs_chars.trail;
2485
2486 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2487 c = wp->w_lcs_chars.lead;
2488
zeertzjq2e7cba32022-06-10 15:30:32 +01002489 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002490 c = wp->w_lcs_chars.space;
2491
2492
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 if (!attr_pri)
2494 {
2495 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002496 extra_attr = hl_combine_attr(wlv.win_attr,
2497 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002498 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 }
2500 mb_c = c;
2501 if (enc_utf8 && utf_char2len(c) > 1)
2502 {
2503 mb_utf8 = TRUE;
2504 u8cc[0] = 0;
2505 c = 0xc0;
2506 }
2507 else
2508 mb_utf8 = FALSE;
2509 }
2510 }
2511
2512 // Handling of non-printable characters.
2513 if (!vim_isprintc(c))
2514 {
2515 // when getting a character from the file, we may have to
2516 // turn it into something else on the way to putting it
2517 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002518 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 {
2520 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002521 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002523 char_u *sbr = get_showbreak_value(wp);
2524
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 // only adjust the tab_len, when at the first column
2526 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002527 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2528 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529#endif
2530 // tab amount depends on current column
2531#ifdef FEAT_VARTABS
2532 tab_len = tabstop_padding(vcol_adjusted,
2533 wp->w_buffer->b_p_ts,
2534 wp->w_buffer->b_p_vts_array) - 1;
2535#else
2536 tab_len = (int)wp->w_buffer->b_p_ts
2537 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2538#endif
2539
2540#ifdef FEAT_LINEBREAK
2541 if (!wp->w_p_lbr || !wp->w_p_list)
2542#endif
2543 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002544 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545#ifdef FEAT_LINEBREAK
2546 else
2547 {
2548 char_u *p;
2549 int len;
2550 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002551 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002553# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002554 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002555 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002556 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002557
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002559 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002560 && old_boguscols > 0
2561 && wlv.n_extra > tab_len)
2562 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002563# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002566 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002567 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002568 if (wp->w_lcs_chars.tab3)
2569 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002570 if (wlv.n_extra > 0)
2571 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002572 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002574 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002575 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002576 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002578 vim_memset(p, ' ', len);
2579 p[len] = NUL;
2580 vim_free(p_extra_free);
2581 p_extra_free = p;
2582 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002584 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002586 if (*p == NUL)
2587 {
2588 tab_len = i;
2589 break;
2590 }
2591
2592 // if tab3 is given, use it for the last char
2593 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2594 lcs = wp->w_lcs_chars.tab3;
2595 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002596 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002598 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002600# ifdef FEAT_CONCEAL
2601 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2602 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002603 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002605# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 }
2608#endif
2609#ifdef FEAT_CONCEAL
2610 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002611 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612
2613 // Tab alignment should be identical regardless of
2614 // 'conceallevel' value. So tab compensates of all
2615 // previous concealed characters, and thus resets
2616 // vcol_off and boguscols accumulated so far in the
2617 // line. Note that the tab can be longer than
2618 // 'tabstop' when there are concealed characters.
2619 FIX_FOR_BOGUSCOLS;
2620
2621 // Make sure, the highlighting for the tab char will be
2622 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002623 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002624 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002625 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 tab_len += vc_saved;
2627 }
2628#endif
2629 mb_utf8 = FALSE; // don't draw as UTF-8
2630 if (wp->w_p_list)
2631 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002632 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002633 ? wp->w_lcs_chars.tab3
2634 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635#ifdef FEAT_LINEBREAK
2636 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002637 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 else
2639#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002640 wlv.c_extra = wp->w_lcs_chars.tab2;
2641 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002643 extra_attr = hl_combine_attr(wlv.win_attr,
2644 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002645 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 mb_c = c;
2647 if (enc_utf8 && utf_char2len(c) > 1)
2648 {
2649 mb_utf8 = TRUE;
2650 u8cc[0] = 0;
2651 c = 0xc0;
2652 }
2653 }
2654 else
2655 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002656 wlv.c_final = NUL;
2657 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658 c = ' ';
2659 }
2660 }
2661 else if (c == NUL
2662 && (wp->w_p_list
2663 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002664 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 && VIsual_mode != Ctrl_V
2666 && (
2667# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002668 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002670 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 && !(noinvcur
2672 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002673 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674 && lcs_eol_one > 0)
2675 {
2676 // Display a '$' after the line or highlight an extra
2677 // character if the line break is included.
2678#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2679 // For a diff line the highlighting continues after the
2680 // "$".
2681 if (
2682# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002683 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684# ifdef LINE_ATTR
2685 &&
2686# endif
2687# endif
2688# ifdef LINE_ATTR
2689 line_attr == 0
2690# endif
2691 )
2692#endif
2693 {
2694 // In virtualedit, visual selections may extend
2695 // beyond end of line.
2696 if (area_highlighting && virtual_active()
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002697 && tocol != MAXCOL && wlv.vcol < tocol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002698 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699 else
2700 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002701 wlv.p_extra = at_end_str;
2702 wlv.n_extra = 1;
2703 wlv.c_extra = NUL;
2704 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 }
2706 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002707 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2708 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 else
2710 c = ' ';
2711 lcs_eol_one = -1;
2712 --ptr; // put it back at the NUL
2713 if (!attr_pri)
2714 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002715 extra_attr = hl_combine_attr(wlv.win_attr,
2716 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 n_attr = 1;
2718 }
2719 mb_c = c;
2720 if (enc_utf8 && utf_char2len(c) > 1)
2721 {
2722 mb_utf8 = TRUE;
2723 u8cc[0] = 0;
2724 c = 0xc0;
2725 }
2726 else
2727 mb_utf8 = FALSE; // don't draw as UTF-8
2728 }
2729 else if (c != NUL)
2730 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2732 if (wlv.n_extra == 0)
2733 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734#ifdef FEAT_RIGHTLEFT
2735 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002736 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002738 wlv.c_extra = NUL;
2739 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740#ifdef FEAT_LINEBREAK
2741 if (wp->w_p_lbr)
2742 {
2743 char_u *p;
2744
Bram Moolenaar1306b362022-08-06 15:59:06 +01002745 c = *wlv.p_extra;
2746 p = alloc(wlv.n_extra + 1);
2747 vim_memset(p, ' ', wlv.n_extra);
2748 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2749 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002751 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 }
2753 else
2754#endif
2755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 wlv.n_extra = byte2cells(c) - 1;
2757 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758 }
2759 if (!attr_pri)
2760 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002762 extra_attr = hl_combine_attr(wlv.win_attr,
2763 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002764 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765 }
2766 mb_utf8 = FALSE; // don't draw as UTF-8
2767 }
2768 else if (VIsual_active
2769 && (VIsual_mode == Ctrl_V
2770 || VIsual_mode == 'v')
2771 && virtual_active()
2772 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002773 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 && (
2775#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002776 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002778 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779 {
2780 c = ' ';
2781 --ptr; // put it back at the NUL
2782 }
2783#if defined(LINE_ATTR)
2784 else if ((
2785# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002786 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787# endif
2788# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002789 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790# endif
2791 line_attr != 0
2792 ) && (
2793# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002794 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002796 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002798 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799# endif
2800 < wp->w_width)))
2801 {
2802 // Highlight until the right side of the window
2803 c = ' ';
2804 --ptr; // put it back at the NUL
2805
2806 // Remember we do the char for line highlighting.
2807 ++did_line_attr;
2808
2809 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002812 || (wp->w_p_list &&
2813 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002814 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002816 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002818 wlv.diff_hlf = HLF_CHD;
2819 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002820 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002821 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2823 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002824 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002825 || (wlv.vcol >= left_curline_col
2826 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002827 wlv.char_attr = hl_combine_attr(
2828 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002829 }
2830 }
2831# endif
2832# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002835 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002836 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2837 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002839 if (!wlv.cul_screenline
2840 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002841 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002842 wlv.char_attr = hl_combine_attr(
2843 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844 }
2845 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002846 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2847 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 }
2849# endif
2850 }
2851#endif
2852 }
2853
2854#ifdef FEAT_CONCEAL
2855 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002856 && (wp != curwin || lnum != wp->w_cursor.lnum
2857 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2859 && !(lnum_in_visual_area
2860 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2861 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002863 if (((prev_syntax_id != syntax_seqnr
2864 && (syntax_flags & HL_CONCEAL) != 0)
2865 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002866 && (syn_get_sub_char() != NUL
2867 || (has_match_conc && match_conc)
2868 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 && wp->w_p_cole != 3)
2870 {
2871 // First time at this concealed item: display one
2872 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002873 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 c = match_conc;
2875 else if (syn_get_sub_char() != NUL)
2876 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002877 else if (wp->w_lcs_chars.conceal != NUL)
2878 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879 else
2880 c = ' ';
2881
2882 prev_syntax_id = syntax_seqnr;
2883
Bram Moolenaar1306b362022-08-06 15:59:06 +01002884 if (wlv.n_extra > 0)
2885 wlv.vcol_off += wlv.n_extra;
2886 wlv.vcol += wlv.n_extra;
2887 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 {
2889# ifdef FEAT_RIGHTLEFT
2890 if (wp->w_p_rl)
2891 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.col -= wlv.n_extra;
2893 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 }
2895 else
2896# endif
2897 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002898 wlv.boguscols += wlv.n_extra;
2899 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 }
2901 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 n_attr = 0;
2904 }
2905 else if (n_skip == 0)
2906 {
2907 is_concealing = TRUE;
2908 n_skip = 1;
2909 }
2910 mb_c = c;
2911 if (enc_utf8 && utf_char2len(c) > 1)
2912 {
2913 mb_utf8 = TRUE;
2914 u8cc[0] = 0;
2915 c = 0xc0;
2916 }
2917 else
2918 mb_utf8 = FALSE; // don't draw as UTF-8
2919 }
2920 else
2921 {
2922 prev_syntax_id = 0;
2923 is_concealing = FALSE;
2924 }
2925
2926 if (n_skip > 0 && did_decrement_ptr)
2927 // not showing the '>', put pointer back to avoid getting stuck
2928 ++ptr;
2929
2930#endif // FEAT_CONCEAL
2931 }
2932
2933#ifdef FEAT_CONCEAL
2934 // In the cursor line and we may be concealing characters: correct
2935 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002936 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 && wp == curwin && lnum == wp->w_cursor.lnum
2938 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002939 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002941# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002943 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002945# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002946 wp->w_wcol = wlv.col - wlv.boguscols;
2947 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002948 did_wcol = TRUE;
2949 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002950# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002951 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002952# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 }
2954#endif
2955
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002956 // Use "extra_attr", but don't override visual selection highlighting.
2957 // Don't use "extra_attr" until n_attr_skip is zero.
2958 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01002959 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 && !attr_pri)
2961 {
2962#ifdef LINE_ATTR
2963 if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 wlv.char_attr = hl_combine_attr(extra_attr, line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 else
2966#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 }
2969
2970#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2971 // XIM don't send preedit_start and preedit_end, but they send
2972 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2973 // im_is_preediting() here.
2974 if (p_imst == IM_ON_THE_SPOT
2975 && xic != NULL
2976 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002977 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 && !p_imdisable
2979 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01002980 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981 {
2982 colnr_T tcol;
2983
2984 if (preedit_end_col == MAXCOL)
2985 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2986 else
2987 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002988 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 {
2990 if (feedback_old_attr < 0)
2991 {
2992 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002993 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002995 wlv.char_attr = im_get_feedback_attr(feedback_col);
2996 if (wlv.char_attr < 0)
2997 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 feedback_col++;
2999 }
3000 else if (feedback_old_attr >= 0)
3001 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003002 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 feedback_old_attr = -1;
3004 feedback_col = 0;
3005 }
3006 }
3007#endif
3008 // Handle the case where we are in column 0 but not on the first
3009 // character of the line and the user wants us to show us a
3010 // special character (via 'listchars' option "precedes:<char>".
3011 if (lcs_prec_todo != NUL
3012 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003013 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003014 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003015 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016#ifdef FEAT_DIFF
3017 && filler_todo <= 0
3018#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 && c != NUL)
3021 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003022 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 lcs_prec_todo = NUL;
3024 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3025 {
3026 // Double-width character being overwritten by the "precedes"
3027 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003028 wlv.c_extra = MB_FILLER_CHAR;
3029 wlv.c_final = NUL;
3030 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003032 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033 }
3034 mb_c = c;
3035 if (enc_utf8 && utf_char2len(c) > 1)
3036 {
3037 mb_utf8 = TRUE;
3038 u8cc[0] = 0;
3039 c = 0xc0;
3040 }
3041 else
3042 mb_utf8 = FALSE; // don't draw as UTF-8
3043 if (!attr_pri)
3044 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 saved_attr3 = wlv.char_attr; // save current attr
3046 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 n_attr3 = 1;
3048 }
3049 }
3050
3051 // At end of the text line or just after the last character.
3052 if ((c == NUL
3053#if defined(LINE_ATTR)
3054 || did_line_attr == 1
3055#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003056 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 {
3058#ifdef FEAT_SEARCH_EXTRA
3059 // flag to indicate whether prevcol equals startcol of search_hl or
3060 // one of the matches
3061 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3062 (long)(ptr - line) - (c == NUL));
3063#endif
3064 // Invert at least one char, used for Visual and empty line or
3065 // highlight match at end of line. If it's beyond the last
3066 // char on the screen, just overwrite that one (tricky!) Not
3067 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003068 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003069 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003070 && (VIsual_mode != Ctrl_V
3071 || lnum == VIsual.lnum
3072 || lnum == curwin->w_cursor.lnum)
3073 && c == NUL)
3074#ifdef FEAT_SEARCH_EXTRA
3075 // highlight 'hlsearch' match at end of line
3076 || (prevcol_hl_flag
3077# ifdef FEAT_SYN_HL
3078 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3079 && !(wp == curwin && VIsual_active))
3080# endif
3081# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003082 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083# endif
3084# if defined(LINE_ATTR)
3085 && did_line_attr <= 1
3086# endif
3087 )
3088#endif
3089 ))
3090 {
3091 int n = 0;
3092
3093#ifdef FEAT_RIGHTLEFT
3094 if (wp->w_p_rl)
3095 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003096 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 n = 1;
3098 }
3099 else
3100#endif
3101 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003102 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 n = -1;
3104 }
3105 if (n != 0)
3106 {
3107 // At the window boundary, highlight the last character
3108 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003109 wlv.off += n;
3110 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 }
3112 else
3113 {
3114 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003115 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003117 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 }
3119#ifdef FEAT_SEARCH_EXTRA
3120 if (area_attr == 0)
3121 {
3122 // Use attributes from match with highest priority among
3123 // 'search_hl' and the match list.
3124 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003125 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 }
3127#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003129 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130#ifdef FEAT_RIGHTLEFT
3131 if (wp->w_p_rl)
3132 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003133 --wlv.col;
3134 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 }
3136 else
3137#endif
3138 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003139 ++wlv.col;
3140 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003142 ++wlv.vcol;
3143 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 }
3145 }
3146
3147 // At end of the text line.
3148 if (c == NUL)
3149 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003150 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151
3152 // Update w_cline_height and w_cline_folded if the cursor line was
3153 // updated (saves a call to plines() later).
3154 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3155 {
3156 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003157 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158#ifdef FEAT_FOLDING
3159 curwin->w_cline_folded = FALSE;
3160#endif
3161 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3162 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 break;
3164 }
3165
3166 // Show "extends" character from 'listchars' if beyond the line end and
3167 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003168 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003169 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 && wp->w_p_list
3171 && !wp->w_p_wrap
3172#ifdef FEAT_DIFF
3173 && filler_todo <= 0
3174#endif
3175 && (
3176#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003177 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003179 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 && (*ptr != NUL
3181 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003182 || (wlv.n_extra && (wlv.c_extra != NUL
3183 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003185 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003186 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 mb_c = c;
3188 if (enc_utf8 && utf_char2len(c) > 1)
3189 {
3190 mb_utf8 = TRUE;
3191 u8cc[0] = 0;
3192 c = 0xc0;
3193 }
3194 else
3195 mb_utf8 = FALSE;
3196 }
3197
3198#ifdef FEAT_SYN_HL
3199 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003200 if (wlv.draw_color_col)
3201 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202
3203 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3204 // highlight the cursor position itself.
3205 // Also highlight the 'colorcolumn' if it is different than
3206 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003207 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3208 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003210 if (((wlv.draw_state == WL_LINE
3211 || wlv.draw_state == WL_BRI
3212 || wlv.draw_state == WL_SBR)
3213 && !lnum_in_visual_area
3214 && search_attr == 0
3215 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003216# ifdef FEAT_DIFF
3217 && filler_todo <= 0
3218# endif
3219 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 {
3221 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3222 && lnum != wp->w_cursor.lnum)
3223 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 vcol_save_attr = wlv.char_attr;
3225 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3226 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003228 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 vcol_save_attr = wlv.char_attr;
3231 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 }
3233 }
3234#endif
3235
3236 // Store character to be displayed.
3237 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003238 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 {
3241 // Store the character.
3242#if defined(FEAT_RIGHTLEFT)
3243 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3244 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003245 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003246 --wlv.off;
3247 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 }
3249#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003250 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 if (enc_dbcs == DBCS_JPNU)
3252 {
3253 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003254 ScreenLines[wlv.off] = 0x8e;
3255 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 }
3257 else if (enc_utf8)
3258 {
3259 if (mb_utf8)
3260 {
3261 int i;
3262
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003263 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003265 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 for (i = 0; i < Screen_mco; ++i)
3267 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 if (u8cc[i] == 0)
3270 break;
3271 }
3272 }
3273 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003274 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 }
3276 if (multi_attr)
3277 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003278 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 multi_attr = 0;
3280 }
3281 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003282 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003285
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3287 {
3288 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003289 ++wlv.off;
3290 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 if (enc_utf8)
3292 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294 else
3295 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003296 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003297 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298#ifdef FEAT_DIFF
3299 && filler_todo <= 0
3300#endif
3301 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003302 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 // When "tocol" is halfway a character, set it to the end of
3304 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003307
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003308 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003309
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310#ifdef FEAT_RIGHTLEFT
3311 if (wp->w_p_rl)
3312 {
3313 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003314 --wlv.off;
3315 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 }
3317#endif
3318 }
3319#ifdef FEAT_RIGHTLEFT
3320 if (wp->w_p_rl)
3321 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003322 --wlv.off;
3323 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 }
3325 else
3326#endif
3327 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003328 ++wlv.off;
3329 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 }
3331 }
3332#ifdef FEAT_CONCEAL
3333 else if (wp->w_p_cole > 0 && is_concealing)
3334 {
3335 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003337 if (wlv.n_extra > 0)
3338 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 if (wp->w_p_wrap)
3340 {
3341 // Special voodoo required if 'wrap' is on.
3342 //
3343 // Advance the column indicator to force the line
3344 // drawing to wrap early. This will make the line
3345 // take up the same screen space when parts are concealed,
3346 // so that cursor line computations aren't messed up.
3347 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 // trailing junk to be written out of the screen line
3350 // we are building, 'boguscols' keeps track of the number
3351 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003354 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355# ifdef FEAT_RIGHTLEFT
3356 if (wp->w_p_rl)
3357 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003358 wlv.col -= wlv.n_extra;
3359 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 }
3361 else
3362# endif
3363 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003364 wlv.col += wlv.n_extra;
3365 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003367 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 n_attr = 0;
3369 }
3370
3371
3372 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3373 {
3374 // Need to fill two screen columns.
3375# ifdef FEAT_RIGHTLEFT
3376 if (wp->w_p_rl)
3377 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003378 --wlv.boguscols;
3379 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 }
3381 else
3382# endif
3383 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 ++wlv.boguscols;
3385 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
3387 }
3388
3389# ifdef FEAT_RIGHTLEFT
3390 if (wp->w_p_rl)
3391 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 --wlv.boguscols;
3393 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394 }
3395 else
3396# endif
3397 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003398 ++wlv.boguscols;
3399 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400 }
3401 }
3402 else
3403 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003404 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003406 wlv.vcol += wlv.n_extra;
3407 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 n_attr = 0;
3409 }
3410 }
3411
3412 }
3413#endif // FEAT_CONCEAL
3414 else
3415 --n_skip;
3416
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003417 // Only advance the "wlv.vcol" when after the 'number' or
3418 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003419 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420#ifdef FEAT_DIFF
3421 && filler_todo <= 0
3422#endif
3423 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003424 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425
3426#ifdef FEAT_SYN_HL
3427 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003428 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429#endif
3430
3431 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003432 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3433 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434
3435 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003437 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003439 if (n_attr_skip > 0)
3440 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441
3442 // At end of screen line and there is more to come: Display the line
3443 // so far. If there is no more to display it is caught above.
3444 if ((
3445#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003449 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003450 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451#ifdef FEAT_DIFF
3452 || filler_todo > 0
3453#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003454#ifdef FEAT_PROP_POPUP
3455 || text_prop_follows
3456#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003457 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 && wlv.p_extra != at_end_str)
3459 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3460 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 )
3462 {
3463#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003464 screen_line(wp, wlv.screen_row, wp->w_wincol,
3465 wlv.col - wlv.boguscols,
3466 wp->w_width, wlv.screen_line_flags);
3467 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3470 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003472 ++wlv.row;
3473 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474
3475 // When not wrapping and finished diff lines, or when displayed
3476 // '$' and highlighting until last column, break here.
3477 if ((!wp->w_p_wrap
3478#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003479 && filler_todo <= 0
3480#endif
3481#ifdef FEAT_PROP_POPUP
3482 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483#endif
3484 ) || lcs_eol_one == -1)
3485 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003486#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003487 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003488 {
3489 // do not output more of the line, only the "below" prop
3490 ptr += STRLEN(ptr);
3491# ifdef FEAT_LINEBREAK
3492 dont_use_showbreak = TRUE;
3493# endif
3494 }
3495#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496
3497 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003498 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499#ifdef FEAT_DIFF
3500 && filler_todo <= 0
3501#endif
3502 )
3503 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003504 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3505 draw_vsep_win(wp, wlv.row);
3506 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 }
3508
3509 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003510 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 break;
3514 }
3515
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003516 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517#ifdef FEAT_DIFF
3518 && filler_todo <= 0
3519#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003520#ifdef FEAT_PROP_POPUP
3521 && !text_prop_follows
3522#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 && wp->w_width == Columns)
3524 {
3525 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003526 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527
3528 // Special trick to make copy/paste of wrapped lines work with
3529 // xterm/screen: write an extra character beyond the end of
3530 // the line. This will work with all terminal types
3531 // (regardless of the xn,am settings).
3532 // Only do this on a fast tty.
3533 // Only do this if the cursor is on the current line
3534 // (something has been written in it).
3535 // Don't do this for the GUI.
3536 // Don't do this for double-width characters.
3537 // Don't do this for a window not at the right screen border.
3538 if (p_tf
3539#ifdef FEAT_GUI
3540 && !gui.in_use
3541#endif
3542 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003543 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3544 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 || (*mb_off2cells)(
3547 LineOffset[wlv.screen_row - 1]
3548 + (int)Columns - 2,
3549 LineOffset[wlv.screen_row]
3550 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 {
3552 // First make sure we are at the end of the screen line,
3553 // then output the same character again to let the
3554 // terminal know about the wrap. If the terminal doesn't
3555 // auto-wrap, we overwrite the character.
3556 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 screen_char(LineOffset[wlv.screen_row - 1]
3558 + (unsigned)Columns - 1,
3559 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003560
3561 // When there is a multi-byte character, just output a
3562 // space to keep it simple.
3563 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 out_char(' ');
3566 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 + (Columns - 1)]);
3569 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571 screen_start(); // don't know where cursor is now
3572 }
3573 }
3574
Bram Moolenaar1306b362022-08-06 15:59:06 +01003575 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576
Bram Moolenaareed9d462021-02-15 20:38:25 +01003577 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003579 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003581 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003583 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 need_showbreak = TRUE;
3585#endif
3586#ifdef FEAT_DIFF
3587 --filler_todo;
3588 // When the filler lines are actually below the last line of the
3589 // file, don't draw the line itself, break here.
3590 if (filler_todo == 0 && wp->w_botfill)
3591 break;
3592#endif
3593 }
3594
3595 } // for every character in the line
3596
3597#ifdef FEAT_SPELL
3598 // After an empty line check first word for capital.
3599 if (*skipwhite(line) == NUL)
3600 {
3601 capcol_lnum = lnum + 1;
3602 cap_col = 0;
3603 }
3604#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003605#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 vim_free(text_props);
3607 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003608 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609#endif
3610
3611 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003612 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613}