blob: c4237561786802784171f8bfa2baad9c418226fa [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +0100106
107 int screen_line_flags; // flags for screen_line()
108
109 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
110 int cul_screenline;
111
112 int char_attr; // attributes for the next character
113
114 int n_extra; // number of extra bytes
115 char_u *p_extra; // string of extra chars, plus NUL, only used
116 // when c_extra and c_final are NUL
117 int c_extra; // extra chars, all the same
118 int c_final; // final char, mandatory if set
119
120 // saved "extra" items for when draw_state becomes WL_LINE (again)
121 int saved_n_extra;
122 char_u *saved_p_extra;
123 int saved_c_extra;
124 int saved_c_final;
125 int saved_char_attr;
126
Bram Moolenaard7657e92022-09-20 18:59:30 +0100127 char_u extra[21]; // "%ld " and 'fdc' must fit in here
128
Bram Moolenaar1306b362022-08-06 15:59:06 +0100129#ifdef FEAT_DIFF
130 hlf_T diff_hlf; // type of diff highlighting
131#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100132 int filler_lines; // nr of filler lines to be drawn
133 int filler_todo; // nr of filler lines still to do + 1
134#ifdef FEAT_SIGNS
135 sign_attrs_T sattr;
136#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100137} winlinevars_T;
138
139// draw_state values for items that are drawn in sequence:
140#define WL_START 0 // nothing done yet, must be zero
141#ifdef FEAT_CMDWIN
142# define WL_CMDLINE (WL_START + 1) // cmdline window column
143#else
144# define WL_CMDLINE WL_START
145#endif
146#ifdef FEAT_FOLDING
147# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
148#else
149# define WL_FOLD WL_CMDLINE
150#endif
151#ifdef FEAT_SIGNS
152# define WL_SIGN (WL_FOLD + 1) // column for signs
153#else
154# define WL_SIGN WL_FOLD // column for signs
155#endif
156#define WL_NR (WL_SIGN + 1) // line number
157#ifdef FEAT_LINEBREAK
158# define WL_BRI (WL_NR + 1) // 'breakindent'
159#else
160# define WL_BRI WL_NR
161#endif
162#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
163# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
164#else
165# define WL_SBR WL_BRI
166#endif
167#define WL_LINE (WL_SBR + 1) // text in the line
168
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200169#ifdef FEAT_SIGNS
170/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000171 * Return TRUE if CursorLineSign highlight is to be used.
172 */
173 static int
174use_cursor_line_sign(win_T *wp, linenr_T lnum)
175{
176 return wp->w_p_cul
177 && lnum == wp->w_cursor.lnum
178 && (wp->w_p_culopt_flags & CULOPT_NBR);
179}
180
181/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100182 * Get information needed to display the sign in line "wlv->lnum" in window
183 * "wp".
184 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200185 * Otherwise the sign is going to be displayed in the sign column.
186 */
187 static void
188get_sign_display_info(
189 int nrcol,
190 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100191 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200192{
193 int text_sign;
194# ifdef FEAT_SIGN_ICONS
195 int icon_sign;
196# endif
197
198 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->c_extra = ' ';
200 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200201 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100202 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200203 else
204 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100205 if (use_cursor_line_sign(wp, wlv->lnum))
206 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000207 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100208 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210 }
211
Bram Moolenaar1306b362022-08-06 15:59:06 +0100212 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200213#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100214 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200215#endif
216 )
217 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100218 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200219# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100220 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200221 if (gui.in_use && icon_sign != 0)
222 {
223 // Use the image in this position.
224 if (nrcol)
225 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100226 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100227 sprintf((char *)wlv->extra, "%-*c ",
228 number_width(wp), SIGN_BYTE);
229 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100230 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200231 }
232 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100233 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200234# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100235 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
236 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200237 {
238 if (nrcol)
239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100240 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100241 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200242 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100243 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100244 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200245 }
246 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100247 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200248 }
249# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100250 wlv->c_final = NUL;
251 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200252 }
253 else
254# endif
255 if (text_sign != 0)
256 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100257 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100258 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200259 {
260 if (nrcol)
261 {
262 int n, width = number_width(wp) - 2;
263
264 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100265 wlv->extra[n] = ' ';
266 wlv->extra[n] = 0;
267 STRCAT(wlv->extra, wlv->p_extra);
268 STRCAT(wlv->extra, " ");
269 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200270 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100271 wlv->c_extra = NUL;
272 wlv->c_final = NUL;
273 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200274 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000275
Bram Moolenaard7657e92022-09-20 18:59:30 +0100276 if (use_cursor_line_sign(wp, wlv->lnum)
277 && wlv->sattr.sat_culhl > 0)
278 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000279 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281 }
282 }
283}
284#endif
285
Bram Moolenaard7657e92022-09-20 18:59:30 +0100286/*
287 * Display the absolute or relative line number. After the first row fill with
288 * blanks when the 'n' flag isn't in 'cpo'.
289 */
290 static void
291handle_lnum_col(
292 win_T *wp,
293 winlinevars_T *wlv,
294 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100295 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100296{
297 if ((wp->w_p_nu || wp->w_p_rnu)
298 && (wlv->row == wlv->startrow + wlv->filler_lines
299 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
300 {
301#ifdef FEAT_SIGNS
302 // If 'signcolumn' is set to 'number' and a sign is present
303 // in 'lnum', then display the sign instead of the line
304 // number.
305 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
306 get_sign_display_info(TRUE, wp, wlv);
307 else
308#endif
309 {
310 // Draw the line number (empty space after wrapping).
311 if (wlv->row == wlv->startrow + wlv->filler_lines)
312 {
313 long num;
314 char *fmt = "%*ld ";
315
316 if (wp->w_p_nu && !wp->w_p_rnu)
317 // 'number' + 'norelativenumber'
318 num = (long)wlv->lnum;
319 else
320 {
321 // 'relativenumber', don't use negative numbers
322 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
323 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
324 {
325 // 'number' + 'relativenumber'
326 num = wlv->lnum;
327 fmt = "%-*ld ";
328 }
329 }
330
331 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
332 if (wp->w_skipcol > 0)
333 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
334 ++wlv->p_extra)
335 *wlv->p_extra = '-';
336#ifdef FEAT_RIGHTLEFT
337 if (wp->w_p_rl) // reverse line numbers
338 {
339 char_u *p1, *p2;
340 int t;
341
342 // like rl_mirror(), but keep the space at the end
343 p2 = skipwhite(wlv->extra);
344 p2 = skiptowhite(p2) - 1;
345 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
346 {
347 t = *p1;
348 *p1 = *p2;
349 *p2 = t;
350 }
351 }
352#endif
353 wlv->p_extra = wlv->extra;
354 wlv->c_extra = NUL;
355 wlv->c_final = NUL;
356 }
357 else
358 {
359 wlv->c_extra = ' ';
360 wlv->c_final = NUL;
361 }
362 wlv->n_extra = number_width(wp) + 1;
363 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
364#ifdef FEAT_SYN_HL
365 // When 'cursorline' is set highlight the line number of
366 // the current line differently.
367 // When 'cursorlineopt' does not have "line" only
368 // highlight the line number itself.
369 // TODO: Can we use CursorLine instead of CursorLineNr
370 // when CursorLineNr isn't set?
371 if (wp->w_p_cul
372 && wlv->lnum == wp->w_cursor.lnum
373 && (wp->w_p_culopt_flags & CULOPT_NBR)
374 && (wlv->row == wlv->startrow + wlv->filler_lines
375 || (wlv->row > wlv->startrow + wlv->filler_lines
376 && (wp->w_p_culopt_flags & CULOPT_LINE))))
377 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
378#endif
379 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
380 && HL_ATTR(HLF_LNA) != 0)
381 // Use LineNrAbove
382 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
383 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
384 && HL_ATTR(HLF_LNB) != 0)
385 // Use LineNrBelow
386 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
387 }
388#ifdef FEAT_SIGNS
389 if (num_attr)
390 wlv->char_attr = num_attr;
391#endif
392 }
393}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100394
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100395#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100396/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100397 * Return the cell size of virtual text after truncation.
398 */
399 static int
400textprop_size_after_trunc(
401 win_T *wp,
402 int flags, // TP_FLAG_ALIGN_*
403 int added,
404 char_u *text,
405 int *n_used_ptr)
406{
407 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
408 ? wp->w_width : added;
409 int len = (int)STRLEN(text);
410 int strsize = 0;
411 int n_used;
412
413 // if the remaining size is to small wrap anyway and use the next line
414 if (space < PROP_TEXT_MIN_CELLS)
415 space += wp->w_width;
416 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
417 {
418 int clen = ptr2cells(text + n_used);
419
420 if (strsize + clen > space)
421 break;
422 strsize += clen;
423 }
424 *n_used_ptr = n_used;
425 return strsize;
426}
427
428/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100429 * Take care of padding, right-align and truncation of virtual text after a
430 * line.
431 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
432 * padding, right-align and truncation. Otherwise only the size is computed.
433 * When "n_attr" is NULL returns the number of screen cells used.
434 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100435 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100436 int
437text_prop_position(
438 win_T *wp,
439 textprop_T *tp,
440 int vcol, // current screen column
441 int *n_extra, // nr of bytes for virtual text
442 char_u **p_extra, // virtual text
443 int *n_attr, // attribute cells, NULL if not used
444 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200445{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100446 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100447 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100448 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
449 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
450 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
451 ? tp->tp_len - 1 : 0;
452 int col_with_padding = vcol + (below ? 0 : padding);
453 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100454 int before = room; // spaces before the text
455 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100456 int n_used = *n_extra;
457 char_u *l = NULL;
458 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100459 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
460 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200461
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100462 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100463 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100464 int col_off = win_col_off(wp) + win_col_off2(wp);
465 int skip_add = 0;
466
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100467 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100468 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100469 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100470 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100471 }
472 else
473 {
474 // Right-align: fill with before
475 if (right)
476 before -= cells;
477 if (before < 0
478 || !(right || below)
479 || (below
480 ? (col_with_padding == 0 || !wp->w_p_wrap)
481 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100482 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100483 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
484 {
485 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100486 before = wp->w_width - col_off - strsize + room;
487 if (before < 0)
488 before = 0;
489 else
490 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100491 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100492 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100493 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100494 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100495 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100496 else if (below && before > 0)
497 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100498 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100499 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100500
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100501 // With 'nowrap' add one to show the "extends" character if needed (it
502 // doesn't show if the text just fits).
503 if (!wp->w_p_wrap
504 && n_used < *n_extra
505 && wp->w_lcs_chars.ext != NUL
506 && wp->w_p_list)
507 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100508 if (!wp->w_p_wrap && below && padding > 0)
509 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100510
511 // add 1 for NUL, 2 for when '…' is used
512 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100513 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100514 if (n_attr == NULL || l != NULL)
515 {
516 int off = 0;
517
518 if (n_attr != NULL)
519 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100520 vim_memset(l, ' ', before);
521 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100522 if (padding > 0)
523 {
524 vim_memset(l + off, ' ', padding);
525 off += padding;
526 }
527 vim_strncpy(l + off, *p_extra, n_used);
528 off += n_used;
529 }
530 else
531 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100532 off = before + after + padding + n_used;
533 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100534 }
535 if (n_attr != NULL)
536 {
537 if (n_used < *n_extra && wp->w_p_wrap)
538 {
539 char_u *lp = l + off - 1;
540
541 if (has_mbyte)
542 {
543 // change last character to '…'
544 lp -= (*mb_head_off)(l, lp);
545 STRCPY(lp, "…");
546 n_used = lp - l + 3 - padding;
547 }
548 else
549 // change last character to '>'
550 *lp = '>';
551 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100552 else if (after > 0)
553 {
554 vim_memset(l + off, ' ', after);
555 l[off + after] = NUL;
556 }
557
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100558 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100559 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100560 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100561 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100562 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100563 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100564 }
565 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100566 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100567
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100568 if (n_attr == NULL)
569 return cells;
570 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200571}
572#endif
573
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100574/*
575 * Called when finished with the line: draw the screen line and handle any
576 * highlighting until the right of the window.
577 */
578 static void
579draw_screen_line(win_T *wp, winlinevars_T *wlv)
580{
581#ifdef FEAT_SYN_HL
582 long v;
583
584 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
585 if (wp->w_p_wrap)
586 v = wp->w_skipcol;
587 else
588 v = wp->w_leftcol;
589
590 // check if line ends before left margin
591 if (wlv->vcol < v + wlv->col - win_col_off(wp))
592 wlv->vcol = v + wlv->col - win_col_off(wp);
593# ifdef FEAT_CONCEAL
594 // Get rid of the boguscols now, we want to draw until the right
595 // edge for 'cursorcolumn'.
596 wlv->col -= wlv->boguscols;
597 wlv->boguscols = 0;
598# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
599# else
600# define VCOL_HLC (wlv->vcol)
601# endif
602
603 if (wlv->draw_color_col)
604 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
605
606 if (((wp->w_p_cuc
607 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
608 && (int)wp->w_virtcol <
609 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
610 && wlv->lnum != wp->w_cursor.lnum)
611 || wlv->draw_color_col
612 || wlv->win_attr != 0)
613# ifdef FEAT_RIGHTLEFT
614 && !wp->w_p_rl
615# endif
616 )
617 {
618 int rightmost_vcol = 0;
619 int i;
620
621 if (wp->w_p_cuc)
622 rightmost_vcol = wp->w_virtcol;
623 if (wlv->draw_color_col)
624 // determine rightmost colorcolumn to possibly draw
625 for (i = 0; wlv->color_cols[i] >= 0; ++i)
626 if (rightmost_vcol < wlv->color_cols[i])
627 rightmost_vcol = wlv->color_cols[i];
628
629 while (wlv->col < wp->w_width)
630 {
631 ScreenLines[wlv->off] = ' ';
632 if (enc_utf8)
633 ScreenLinesUC[wlv->off] = 0;
634 ScreenCols[wlv->off] = MAXCOL;
635 ++wlv->col;
636 if (wlv->draw_color_col)
637 wlv->draw_color_col = advance_color_col(
638 VCOL_HLC, &wlv->color_cols);
639
640 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
641 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
642 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
643 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
644 else
645 ScreenAttrs[wlv->off++] = wlv->win_attr;
646
647 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
648 break;
649
650 ++wlv->vcol;
651 }
652 }
653#endif
654
655 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
656 wp->w_width, wlv->screen_line_flags);
657 ++wlv->row;
658 ++wlv->screen_row;
659}
660#undef VCOL_HLC
661
662/*
663 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100664 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100665 */
666 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100667win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100668{
669 wlv->col = 0;
670 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
671
672#ifdef FEAT_RIGHTLEFT
673 if (wp->w_p_rl)
674 {
675 // Rightleft window: process the text in the normal direction, but put
676 // it in current_ScreenLine[] from right to left. Start at the
677 // rightmost column of the window.
678 wlv->col = wp->w_width - 1;
679 wlv->off += wlv->col;
680 wlv->screen_line_flags |= SLF_RIGHTLEFT;
681 }
682#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100683 if (save_extra)
684 {
685 // reset the drawing state for the start of a wrapped line
686 wlv->draw_state = WL_START;
687 wlv->saved_n_extra = wlv->n_extra;
688 wlv->saved_p_extra = wlv->p_extra;
689 wlv->saved_c_extra = wlv->c_extra;
690 wlv->saved_c_final = wlv->c_final;
691#ifdef FEAT_SYN_HL
692 if (!(wlv->cul_screenline
693# ifdef FEAT_DIFF
694 && wlv->diff_hlf == (hlf_T)0
695# endif
696 ))
697 wlv->saved_char_attr = wlv->char_attr;
698 else
699#endif
700 wlv->saved_char_attr = 0;
701 wlv->n_extra = 0;
702 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100703}
704
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705/*
706 * Display line "lnum" of window 'wp' on the screen.
707 * Start at row "startrow", stop when "endrow" is reached.
708 * wp->w_virtcol needs to be valid.
709 *
710 * Return the number of last row the line occupies.
711 */
712 int
713win_line(
714 win_T *wp,
715 linenr_T lnum,
716 int startrow,
717 int endrow,
718 int nochange UNUSED, // not updating for changed text
719 int number_only) // only update the number column
720{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100721 winlinevars_T wlv; // variables passed between functions
722
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200723 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200724#ifdef FEAT_LINEBREAK
725 long vcol_sbr = -1; // virtual column after showbreak
726#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100727 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200728 char_u *line; // current line
729 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200730
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200731 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100732#ifdef FEAT_PROP_POPUP
733 char_u *p_extra_free2 = NULL; // another p_extra to be freed
734#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200735 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000736#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000737 int in_linebreak = FALSE; // n_extra set for showing linebreak
738#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200739 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100740 // displaying eol at end-of-line
741 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000742 int lcs_prec_todo = wp->w_lcs_chars.prec;
743 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200744
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100745 int n_attr = 0; // chars with special attr
746 int n_attr_skip = 0; // chars to skip before using extra_attr
747 int saved_attr2 = 0; // char_attr saved for n_attr
748 int n_attr3 = 0; // chars with overruling special attr
749 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200750
751 int n_skip = 0; // nr of chars to skip for 'nowrap'
752
753 int fromcol = -10; // start of inverting
754 int tocol = MAXCOL; // end of inverting
755 int fromcol_prev = -2; // start of inverting after cursor
756 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200757 int lnum_in_visual_area = FALSE;
758 pos_T pos;
759 long v;
760
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200761 int attr_pri = FALSE; // char_attr has priority
762 int area_highlighting = FALSE; // Visual or incsearch highlighting
763 // in this line
764 int vi_attr = 0; // attributes for Visual and incsearch
765 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200766 int area_attr = 0; // attributes desired by highlighting
767 int search_attr = 0; // attributes desired by 'hlsearch'
768#ifdef FEAT_SYN_HL
769 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
770 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200771 int prev_syntax_col = -1; // column of prev_syntax_attr
772 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 int has_syntax = FALSE; // this buffer has syntax highl.
774 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100776#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200777 int text_prop_count;
778 int text_prop_next = 0; // next text property to use
779 textprop_T *text_props = NULL;
780 int *text_prop_idxs = NULL;
781 int text_props_active = 0;
782 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100783 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200784 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100785 int text_prop_attr_comb = 0; // text_prop_attr combined with
786 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100787 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100788 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100789 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100790 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100791 int saved_search_attr = 0; // search_attr to be used when n_extra
792 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100793 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200794#endif
795#ifdef FEAT_SPELL
796 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000797 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200798# define SPWORDLEN 150
799 char_u nextline[SPWORDLEN * 2];// text with start of the next line
800 int nextlinecol = 0; // column where nextline[] starts
801 int nextline_idx = 0; // index in nextline[] where next line
802 // starts
803 int spell_attr = 0; // attributes desired by spelling
804 int word_end = 0; // last byte with same spell_attr
805 static linenr_T checked_lnum = 0; // line number for "checked_col"
806 static int checked_col = 0; // column in "checked_lnum" up to which
807 // there are no spell errors
808 static int cap_col = -1; // column to check for Cap word
809 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
810 int cur_checked_col = 0; // checked column for current line
811#endif
812 int extra_check = 0; // has extra highlighting
813 int multi_attr = 0; // attributes desired by multibyte
814 int mb_l = 1; // multi-byte byte length
815 int mb_c = 0; // decoded multi-byte character
816 int mb_utf8 = FALSE; // screen char is UTF-8 char
817 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200818#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200819 int change_start = MAXCOL; // first col of changed area
820 int change_end = -1; // last col of changed area
821#endif
822 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100823 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200824 int in_multispace = FALSE; // in multiple consecutive spaces
825 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200826#ifdef FEAT_LINEBREAK
827 int need_showbreak = FALSE; // overlong line, skipping first x
828 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100829 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200830#endif
831#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
832 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
833# define LINE_ATTR
834 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100835 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200836#endif
837#ifdef FEAT_SIGNS
838 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +0000839 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200840#endif
841#ifdef FEAT_ARABIC
842 int prev_c = 0; // previous Arabic character
843 int prev_c1 = 0; // first composing char for prev_c
844#endif
845#if defined(LINE_ATTR)
846 int did_line_attr = 0;
847#endif
848#ifdef FEAT_TERMINAL
849 int get_term_attr = FALSE;
850#endif
851#ifdef FEAT_SYN_HL
852 int cul_attr = 0; // set when 'cursorline' active
853
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200854 // margin columns for the screen line, needed for when 'cursorlineopt'
855 // contains "screenline"
856 int left_curline_col = 0;
857 int right_curline_col = 0;
858#endif
859
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200860#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
861 int feedback_col = 0;
862 int feedback_old_attr = -1;
863#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200864
865#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
866 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000867 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200868#endif
869#ifdef FEAT_CONCEAL
870 int syntax_flags = 0;
871 int syntax_seqnr = 0;
872 int prev_syntax_id = 0;
873 int conceal_attr = HL_ATTR(HLF_CONCEAL);
874 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200875 int did_wcol = FALSE;
876 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100877# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200878# define FIX_FOR_BOGUSCOLS \
879 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100880 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100881 wlv.vcol -= wlv.vcol_off; \
882 wlv.vcol_off = 0; \
883 wlv.col -= wlv.boguscols; \
884 old_boguscols = wlv.boguscols; \
885 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200886 }
887#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100888# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200889#endif
890
891 if (startrow > endrow) // past the end already!
892 return startrow;
893
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894 CLEAR_FIELD(wlv);
895
896 wlv.lnum = lnum;
897 wlv.startrow = startrow;
898 wlv.row = startrow;
899 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200900
901 if (!number_only)
902 {
903 // To speed up the loop below, set extra_check when there is linebreak,
904 // trailing white space and/or syntax processing to be done.
905#ifdef FEAT_LINEBREAK
906 extra_check = wp->w_p_lbr;
907#endif
908#ifdef FEAT_SYN_HL
909 if (syntax_present(wp) && !wp->w_s->b_syn_error
910# ifdef SYN_TIME_LIMIT
911 && !wp->w_s->b_syn_slow
912# endif
913 )
914 {
915 // Prepare for syntax highlighting in this line. When there is an
916 // error, stop syntax highlighting.
917 save_did_emsg = did_emsg;
918 did_emsg = FALSE;
919 syntax_start(wp, lnum);
920 if (did_emsg)
921 wp->w_s->b_syn_error = TRUE;
922 else
923 {
924 did_emsg = save_did_emsg;
925#ifdef SYN_TIME_LIMIT
926 if (!wp->w_s->b_syn_slow)
927#endif
928 {
929 has_syntax = TRUE;
930 extra_check = TRUE;
931 }
932 }
933 }
934
935 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100936 wlv.color_cols = wp->w_p_cc_cols;
937 if (wlv.color_cols != NULL)
938 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200939#endif
940
941#ifdef FEAT_TERMINAL
942 if (term_show_buffer(wp->w_buffer))
943 {
944 extra_check = TRUE;
945 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100946 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 }
948#endif
949
950#ifdef FEAT_SPELL
951 if (wp->w_p_spell
952 && *wp->w_s->b_p_spl != NUL
953 && wp->w_s->b_langp.ga_len > 0
954 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
955 {
956 // Prepare for spell checking.
957 has_spell = TRUE;
958 extra_check = TRUE;
959
960 // Get the start of the next line, so that words that wrap to the
961 // next line are found too: "et<line-break>al.".
962 // Trick: skip a few chars for C/shell/Vim comments
963 nextline[SPWORDLEN] = NUL;
964 if (lnum < wp->w_buffer->b_ml.ml_line_count)
965 {
966 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
967 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
968 }
969
970 // When a word wrapped from the previous line the start of the
971 // current line is valid.
972 if (lnum == checked_lnum)
973 cur_checked_col = checked_col;
974 checked_lnum = 0;
975
976 // When there was a sentence end in the previous line may require a
977 // word starting with capital in this line. In line 1 always check
978 // the first word.
979 if (lnum != capcol_lnum)
980 cap_col = -1;
981 if (lnum == 1)
982 cap_col = 0;
983 capcol_lnum = 0;
984 }
985#endif
986
987 // handle Visual active in this window
988 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
989 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100990 pos_T *top, *bot;
991
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200992 if (LTOREQ_POS(curwin->w_cursor, VIsual))
993 {
994 // Visual is after curwin->w_cursor
995 top = &curwin->w_cursor;
996 bot = &VIsual;
997 }
998 else
999 {
1000 // Visual is before curwin->w_cursor
1001 top = &VIsual;
1002 bot = &curwin->w_cursor;
1003 }
1004 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1005 if (VIsual_mode == Ctrl_V)
1006 {
1007 // block mode
1008 if (lnum_in_visual_area)
1009 {
1010 fromcol = wp->w_old_cursor_fcol;
1011 tocol = wp->w_old_cursor_lcol;
1012 }
1013 }
1014 else
1015 {
1016 // non-block mode
1017 if (lnum > top->lnum && lnum <= bot->lnum)
1018 fromcol = 0;
1019 else if (lnum == top->lnum)
1020 {
1021 if (VIsual_mode == 'V') // linewise
1022 fromcol = 0;
1023 else
1024 {
1025 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
1026 if (gchar_pos(top) == NUL)
1027 tocol = fromcol + 1;
1028 }
1029 }
1030 if (VIsual_mode != 'V' && lnum == bot->lnum)
1031 {
1032 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1033 {
1034 fromcol = -10;
1035 tocol = MAXCOL;
1036 }
1037 else if (bot->col == MAXCOL)
1038 tocol = MAXCOL;
1039 else
1040 {
1041 pos = *bot;
1042 if (*p_sel == 'e')
1043 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
1044 else
1045 {
1046 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
1047 ++tocol;
1048 }
1049 }
1050 }
1051 }
1052
1053 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001054 if (!highlight_match && lnum == curwin->w_cursor.lnum
1055 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056#ifdef FEAT_GUI
1057 && !gui.in_use
1058#endif
1059 )
1060 noinvcur = TRUE;
1061
1062 // if inverting in this line set area_highlighting
1063 if (fromcol >= 0)
1064 {
1065 area_highlighting = TRUE;
1066 vi_attr = HL_ATTR(HLF_V);
1067#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1068 if ((clip_star.available && !clip_star.owned
1069 && clip_isautosel_star())
1070 || (clip_plus.available && !clip_plus.owned
1071 && clip_isautosel_plus()))
1072 vi_attr = HL_ATTR(HLF_VNC);
1073#endif
1074 }
1075 }
1076
1077 // handle 'incsearch' and ":s///c" highlighting
1078 else if (highlight_match
1079 && wp == curwin
1080 && lnum >= curwin->w_cursor.lnum
1081 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1082 {
1083 if (lnum == curwin->w_cursor.lnum)
1084 getvcol(curwin, &(curwin->w_cursor),
1085 (colnr_T *)&fromcol, NULL, NULL);
1086 else
1087 fromcol = 0;
1088 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1089 {
1090 pos.lnum = lnum;
1091 pos.col = search_match_endcol;
1092 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
1093 }
1094 else
1095 tocol = MAXCOL;
1096 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +01001097 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001098 tocol = fromcol + 1;
1099 area_highlighting = TRUE;
1100 vi_attr = HL_ATTR(HLF_I);
1101 }
1102 }
1103
1104#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001105 wlv.filler_lines = diff_check(wp, lnum);
1106 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001108 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 {
1110 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001111 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001113 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001115 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116 }
1117 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001118 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001119 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001120 area_highlighting = TRUE;
1121 }
1122 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001123 wlv.filler_lines = wp->w_topfill;
1124 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001125#endif
1126
1127#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001128 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001129 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001130 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131#endif
1132
1133#ifdef LINE_ATTR
1134# ifdef FEAT_SIGNS
1135 // If this line has a sign with line highlighting set line_attr.
1136 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001137 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138# endif
1139# if defined(FEAT_QUICKFIX)
1140 // Highlight the current line in the quickfix window.
1141 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1142 line_attr = HL_ATTR(HLF_QFL);
1143# endif
1144 if (line_attr != 0)
1145 area_highlighting = TRUE;
1146#endif
1147
1148 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1149 ptr = line;
1150
1151#ifdef FEAT_SPELL
1152 if (has_spell && !number_only)
1153 {
1154 // For checking first word with a capital skip white space.
1155 if (cap_col == 0)
1156 cap_col = getwhitecols(line);
1157
1158 // To be able to spell-check over line boundaries copy the end of the
1159 // current line into nextline[]. Above the start of the next line was
1160 // copied to nextline[SPWORDLEN].
1161 if (nextline[SPWORDLEN] == NUL)
1162 {
1163 // No next line or it is empty.
1164 nextlinecol = MAXCOL;
1165 nextline_idx = 0;
1166 }
1167 else
1168 {
1169 v = (long)STRLEN(line);
1170 if (v < SPWORDLEN)
1171 {
1172 // Short line, use it completely and append the start of the
1173 // next line.
1174 nextlinecol = 0;
1175 mch_memmove(nextline, line, (size_t)v);
1176 STRMOVE(nextline + v, nextline + SPWORDLEN);
1177 nextline_idx = v + 1;
1178 }
1179 else
1180 {
1181 // Long line, use only the last SPWORDLEN bytes.
1182 nextlinecol = v - SPWORDLEN;
1183 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1184 nextline_idx = SPWORDLEN + 1;
1185 }
1186 }
1187 }
1188#endif
1189
1190 if (wp->w_p_list)
1191 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001192 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001193 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001194 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001195 || wp->w_lcs_chars.trail
1196 || wp->w_lcs_chars.lead
1197 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001199
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001201 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202 {
1203 trailcol = (colnr_T)STRLEN(ptr);
1204 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1205 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001206 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001208 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001209 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001210 {
1211 leadcol = 0;
1212 while (VIM_ISWHITE(ptr[leadcol]))
1213 ++leadcol;
1214 if (ptr[leadcol] == NUL)
1215 // in a line full of spaces all of them are treated as trailing
1216 leadcol = (colnr_T)0;
1217 else
1218 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001219 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001220 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 }
1222
Bram Moolenaard7657e92022-09-20 18:59:30 +01001223 wlv.wcr_attr = get_wcr_attr(wp);
1224 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001226 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 area_highlighting = TRUE;
1228 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001229
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001230#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001232 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233#endif
1234
1235 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1236 // first character to be displayed.
1237 if (wp->w_p_wrap)
1238 v = wp->w_skipcol;
1239 else
1240 v = wp->w_leftcol;
1241 if (v > 0 && !number_only)
1242 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001243 char_u *prev_ptr = ptr;
1244 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001245 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001247 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001248 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001250 charsize = win_lbr_chartabsize(&cts, NULL);
1251 cts.cts_vcol += charsize;
1252 prev_ptr = cts.cts_ptr;
1253 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001255 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001256 ptr = cts.cts_ptr;
1257 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258
1259 // When:
1260 // - 'cuc' is set, or
1261 // - 'colorcolumn' is set, or
1262 // - 'virtualedit' is set, or
1263 // - the visual mode is active,
1264 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001265 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001267 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268#endif
1269 virtual_active() ||
1270 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001271 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272
1273 // Handle a character that's not completely on the screen: Put ptr at
1274 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001275 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001277 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 ptr = prev_ptr;
1279 // If the character fits on the screen, don't need to skip it.
1280 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001281 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1282 && wlv.col == 0)
1283 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 }
1285
1286 // Adjust for when the inverted text is before the screen,
1287 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001288 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001290 else if (fromcol >= 0 && fromcol < wlv.vcol)
1291 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292
1293#ifdef FEAT_LINEBREAK
1294 // When w_skipcol is non-zero, first line needs 'showbreak'
1295 if (wp->w_p_wrap)
1296 need_showbreak = TRUE;
1297#endif
1298#ifdef FEAT_SPELL
1299 // When spell checking a word we need to figure out the start of the
1300 // word and if it's badly spelled or not.
1301 if (has_spell)
1302 {
1303 int len;
1304 colnr_T linecol = (colnr_T)(ptr - line);
1305 hlf_T spell_hlf = HLF_COUNT;
1306
1307 pos = wp->w_cursor;
1308 wp->w_cursor.lnum = lnum;
1309 wp->w_cursor.col = linecol;
1310 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1311
1312 // spell_move_to() may call ml_get() and make "line" invalid
1313 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1314 ptr = line + linecol;
1315
1316 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1317 {
1318 // no bad word found at line start, don't check until end of a
1319 // word
1320 spell_hlf = HLF_COUNT;
1321 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1322 }
1323 else
1324 {
1325 // bad word found, use attributes until end of word
1326 word_end = wp->w_cursor.col + len + 1;
1327
1328 // Turn index into actual attributes.
1329 if (spell_hlf != HLF_COUNT)
1330 spell_attr = highlight_attr[spell_hlf];
1331 }
1332 wp->w_cursor = pos;
1333
1334# ifdef FEAT_SYN_HL
1335 // Need to restart syntax highlighting for this line.
1336 if (has_syntax)
1337 syntax_start(wp, lnum);
1338# endif
1339 }
1340#endif
1341 }
1342
1343 // Correct highlighting for cursor that can't be disabled.
1344 // Avoids having to check this for each character.
1345 if (fromcol >= 0)
1346 {
1347 if (noinvcur)
1348 {
1349 if ((colnr_T)fromcol == wp->w_virtcol)
1350 {
1351 // highlighting starts at cursor, let it start just after the
1352 // cursor
1353 fromcol_prev = fromcol;
1354 fromcol = -1;
1355 }
1356 else if ((colnr_T)fromcol < wp->w_virtcol)
1357 // restart highlighting after the cursor
1358 fromcol_prev = wp->w_virtcol;
1359 }
1360 if (fromcol >= tocol)
1361 fromcol = -1;
1362 }
1363
1364#ifdef FEAT_SEARCH_EXTRA
1365 if (!number_only)
1366 {
1367 v = (long)(ptr - line);
1368 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1369 &line, &screen_search_hl,
1370 &search_attr);
1371 ptr = line + v; // "line" may have been updated
1372 }
1373#endif
1374
1375#ifdef FEAT_SYN_HL
1376 // Cursor line highlighting for 'cursorline' in the current window.
1377 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1378 {
1379 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001380 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381 if (!(wp == curwin && VIsual_active)
1382 && wp->w_p_culopt_flags != CULOPT_NBR)
1383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001384 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1386
1387 // Only set line_attr here when "screenline" is not present in
1388 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001389 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390 {
1391 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001392# ifdef FEAT_SIGNS
1393 // Combine the 'cursorline' and sign highlighting, depending on
1394 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001395 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001396 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001397 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001398 line_attr = hl_combine_attr(cul_attr, line_attr);
1399 else
1400 line_attr = hl_combine_attr(line_attr, cul_attr);
1401 }
1402 else
1403# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001404# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001405 // let the line attribute overrule 'cursorline', otherwise
1406 // it disappears when both have background set;
1407 // 'cursorline' can use underline or bold to make it show
1408 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001409# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001410 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001411# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001412 }
1413 else
1414 {
1415 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1417 }
1418 area_highlighting = TRUE;
1419 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 }
1421#endif
1422
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001423#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 {
1425 char_u *prop_start;
1426
1427 text_prop_count = get_text_props(wp->w_buffer, lnum,
1428 &prop_start, FALSE);
1429 if (text_prop_count > 0)
1430 {
1431 // Make a copy of the properties, so that they are properly
1432 // aligned.
1433 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1434 if (text_props != NULL)
1435 mch_memmove(text_props, prop_start,
1436 text_prop_count * sizeof(textprop_T));
1437
1438 // Allocate an array for the indexes.
1439 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001440 if (text_prop_idxs == NULL)
1441 VIM_CLEAR(text_props);
1442
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443 area_highlighting = TRUE;
1444 extra_check = TRUE;
1445 }
1446 }
1447#endif
1448
Bram Moolenaar1306b362022-08-06 15:59:06 +01001449 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450
1451 // Repeat for the whole displayed line.
1452 for (;;)
1453 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001454 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001456 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457#endif
1458#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001459 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001461
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001463 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001465#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001466 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001467 {
1468 cul_attr = 0;
1469 line_attr = line_attr_save;
1470 }
1471#endif
1472
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001474 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001476 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 if (cmdwin_type != 0 && wp == curwin)
1478 {
1479 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001480 wlv.n_extra = 1;
1481 wlv.c_extra = cmdwin_type;
1482 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001483 wlv.char_attr =
1484 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 }
1486 }
1487#endif
1488
1489#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001490 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 {
1492 int fdc = compute_foldcolumn(wp, 0);
1493
Bram Moolenaar1306b362022-08-06 15:59:06 +01001494 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495 if (fdc > 0)
1496 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001497 // Draw the 'foldcolumn'. Allocate a buffer, "wlv.extra"
1498 // may already be in use.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001500 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 if (p_extra_free != NULL)
1502 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001503 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001504 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001505 p_extra_free[wlv.n_extra] = NUL;
1506 wlv.p_extra = p_extra_free;
1507 wlv.c_extra = NUL;
1508 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001509 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001510 wlv.char_attr =
Bram Moolenaard7657e92022-09-20 18:59:30 +01001511 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_CLF));
Bram Moolenaare413ea02021-11-24 16:20:13 +00001512 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001513 wlv.char_attr =
Bram Moolenaard7657e92022-09-20 18:59:30 +01001514 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 }
1516 }
1517 }
1518#endif
1519
1520#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001521 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001523 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001524 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001526 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 }
1528#endif
1529
Bram Moolenaar1306b362022-08-06 15:59:06 +01001530 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001532 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001533 wlv.draw_state = WL_NR;
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +01001534 handle_lnum_col(wp, &wlv,
1535#ifdef FEAT_SIGNS
1536 sign_present, num_attr
1537#else
1538 0, 0
1539#endif
1540 );
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541 }
1542
1543#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001544 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1545 && wlv.n_extra == 0
1546 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001548 wlv.draw_state = WL_BRI;
1549 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1550 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001552 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553
1554 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001555 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001557 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001559 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001561 && wlv.filler_lines == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001563# ifdef FEAT_PROP_POPUP
1564 && !dont_use_showbreak
1565# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 )
1567 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001568 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001570 if (wlv.diff_hlf != (hlf_T)0)
1571 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001573 wlv.p_extra = NULL;
1574 wlv.c_extra = ' ';
1575 wlv.c_final = NUL;
1576 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001578 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001579 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001580 wlv.n_extra -= win_col_off2(wp);
1581 if (wlv.n_extra < 0)
1582 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001583 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001584 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001585 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 // Correct end of highlighted area for 'breakindent',
1587 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001588 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001589 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001590 }
1591 }
1592#endif
1593
1594#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001595 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001597 char_u *sbr;
1598
Bram Moolenaar1306b362022-08-06 15:59:06 +01001599 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001601 if (wlv.filler_todo > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001602 {
1603 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001604 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001606 wlv.c_extra = '-';
1607 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608 }
1609 else
1610 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001611 wlv.c_extra = wp->w_fill_chars.diff;
1612 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613 }
1614# ifdef FEAT_RIGHTLEFT
1615 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001616 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 else
1618# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001619 wlv.n_extra = wp->w_width - wlv.col;
1620 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 }
1622# endif
1623# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001624 sbr = get_showbreak_value(wp);
1625 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 {
1627 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001628 wlv.p_extra = sbr;
1629 wlv.c_extra = NUL;
1630 wlv.c_final = NUL;
1631 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001632 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1633 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001634 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635 // Correct end of highlighted area for 'showbreak',
1636 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001637 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001638 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001639 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001640 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1641 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642# ifdef FEAT_SYN_HL
1643 // combine 'showbreak' with 'cursorline'
1644 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001645 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1646 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647# endif
1648 }
1649# endif
1650 }
1651#endif
1652
Bram Moolenaar1306b362022-08-06 15:59:06 +01001653 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001655 wlv.draw_state = WL_LINE;
1656 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 {
1658 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001659 wlv.n_extra = wlv.saved_n_extra;
1660 wlv.c_extra = wlv.saved_c_extra;
1661 wlv.c_final = wlv.saved_c_final;
1662 wlv.p_extra = wlv.saved_p_extra;
1663 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001664 }
1665 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001666 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667 }
1668 }
1669#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001670 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001671 && wlv.vcol >= left_curline_col
1672 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001674 cul_attr = HL_ATTR(HLF_CUL);
1675 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 }
1677#endif
1678
1679 // When still displaying '$' of change command, stop at cursor.
1680 // When only displaying the (relative) line number and that's done,
1681 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001682 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001683 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001684 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001686 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687#endif
1688 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001690 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1691 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 // Pretend we have finished updating the window. Except when
1693 // 'cursorcolumn' is set.
1694#ifdef FEAT_SYN_HL
1695 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001696 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697 else
1698#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001699 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 break;
1701 }
1702
Bram Moolenaar1306b362022-08-06 15:59:06 +01001703 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 {
1705 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001706 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 && (*mb_ptr2cells)(ptr) > 1)
1709 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001710 && vcol_prev < wlv.vcol // not at margin
1711 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 area_attr = vi_attr; // start highlighting
1713 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001714 && (wlv.vcol == tocol
1715 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 area_attr = 0; // stop highlighting
1717
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001718#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 if (text_props != NULL)
1720 {
1721 int pi;
1722 int bcol = (int)(ptr - line);
1723
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001725# ifdef FEAT_LINEBREAK
1726 && !in_linebreak
1727# endif
1728 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 --bcol; // still working on the previous char, e.g. Tab
1730
1731 // Check if any active property ends.
1732 for (pi = 0; pi < text_props_active; ++pi)
1733 {
1734 int tpi = text_prop_idxs[pi];
1735
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001736 if (text_props[tpi].tp_col != MAXCOL
1737 && bcol >= text_props[tpi].tp_col - 1
1738 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 {
1740 if (pi + 1 < text_props_active)
1741 mch_memmove(text_prop_idxs + pi,
1742 text_prop_idxs + pi + 1,
1743 sizeof(int)
1744 * (text_props_active - (pi + 1)));
1745 --text_props_active;
1746 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001747# ifdef FEAT_LINEBREAK
1748 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001749 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001750 syntax_attr = 0;
1751# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 }
1753 }
1754
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001755# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001757 // not on the next char yet, don't start another prop
1758 --bcol;
1759# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001761 // With 'nowrap' and not in the first screen line only "below"
1762 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001764 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001765 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001766 && (wp->w_p_wrap
1767 || wlv.row == startrow
1768 || (text_props[text_prop_next].tp_flags
1769 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001770 || (bcol == 0 &&
1771 (text_props[text_prop_next].tp_flags
1772 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001773 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001774 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001775 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001776 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1777 {
1778 // first display the '$' after the line
1779 text_prop_follows = TRUE;
1780 break;
1781 }
1782 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001783 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001784 + text_props[text_prop_next].tp_len)
1785 text_prop_idxs[text_props_active++] = text_prop_next;
1786 ++text_prop_next;
1787 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001789 if (wlv.n_extra == 0 || !extra_for_textprop)
1790 {
1791 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001792 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001793 text_prop_flags = 0;
1794 text_prop_type = NULL;
1795 text_prop_id = 0;
1796 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001797 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001799 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001800 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001801 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001802
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 // Sort the properties on priority and/or starting last.
1804 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001805 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001806 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001807 sort_text_props(wp->w_buffer, text_props,
1808 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809
1810 for (pi = 0; pi < text_props_active; ++pi)
1811 {
1812 int tpi = text_prop_idxs[pi];
1813 proptype_T *pt = text_prop_type_by_id(
1814 wp->w_buffer, text_props[tpi].tp_type);
1815
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001816 if (pt != NULL && (pt->pt_hl_id > 0
1817 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001818 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001820 if (pt->pt_hl_id > 0)
1821 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 text_prop_type = pt;
1823 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001824 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001825 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001826 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001827 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001828 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 }
1830 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001831 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001832 && -text_prop_id
1833 <= wp->w_buffer->b_textprop_text.ga_len)
1834 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001835 textprop_T *tp = &text_props[used_tpi];
1836 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001837 ->b_textprop_text.ga_data)[
1838 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001839 int above = (tp->tp_flags
1840 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841
1842 // reset the ID in the copy to avoid it being used
1843 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001844 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001845
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001846 if (p != NULL)
1847 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001848 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001849 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001850 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001851 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001852 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1853 int padding = tp->tp_col == MAXCOL
1854 && tp->tp_len > 1
1855 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001856
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001857 // Insert virtual text before the current
1858 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001859 wlv.p_extra = p;
1860 wlv.c_extra = NUL;
1861 wlv.c_final = NUL;
1862 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001863 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001864 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001865 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001866 // restore search_attr and area_attr when n_extra
1867 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001868 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001869 saved_area_attr = area_attr;
1870 search_attr = 0;
1871 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001872 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001873 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001874 if (*ptr == NUL)
1875 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001876 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001877#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001878 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001879 {
1880 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001881 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001882 need_showbreak = FALSE;
1883 dont_use_showbreak = TRUE;
1884 }
1885#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001886 if ((right || above || below || !wrap
1887 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001888 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001889 char_u *prev_p_extra = wlv.p_extra;
1890 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001891
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001892 // Take care of padding, right-align and
1893 // truncation.
1894 // Shared with win_lbr_chartabsize(), must do
1895 // exactly the same.
1896 start_line = text_prop_position(wp, tp,
1897 wlv.col,
1898 &wlv.n_extra, &wlv.p_extra,
1899 &n_attr, &n_attr_skip);
1900 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001901 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001902 // wlv.p_extra was allocated
1903 vim_free(p_extra_free2);
1904 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001905 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001906
Bram Moolenaara4abe512022-09-15 19:44:09 +01001907 if (lcs_eol_one < 0 && wlv.col
1908 + wlv.n_extra - 2 > wp->w_width)
1909 // don't bail out at end of line
1910 lcs_eol_one = 0;
1911
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001912 // When 'wrap' is off then for "below" we need
1913 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001914 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001915 {
1916 draw_screen_line(wp, &wlv);
1917
1918 // When line got too long for screen break
1919 // here.
1920 if (wlv.row == endrow)
1921 {
1922 ++wlv.row;
1923 break;
1924 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001925 win_line_start(wp, &wlv, TRUE);
1926 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001927 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001928 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001929 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001930
1931 // If another text prop follows the condition below at
1932 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001933 // If this is an "above" text prop and 'nowrap' the we
1934 // must wrap anyway.
1935 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001936 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001937 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001939 else if (text_prop_next < text_prop_count
1940 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001941 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1942 || (!wp->w_p_wrap
1943 && wlv.col == wp->w_width - 1
1944 && (text_props[text_prop_next].tp_flags
1945 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001946 // When at last-but-one character and a text property
1947 // follows after it, we may need to flush the line after
1948 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001949 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001950 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 }
1952#endif
1953
Bram Moolenaare38fc862022-08-11 17:24:50 +01001954#ifdef FEAT_SEARCH_EXTRA
1955 if (wlv.n_extra == 0)
1956 {
1957 // Check for start/end of 'hlsearch' and other matches.
1958 // After end, check for start/end of next match.
1959 // When another match, have to check for start again.
1960 v = (long)(ptr - line);
1961 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1962 &screen_search_hl, &has_match_conc,
1963 &match_conc, did_line_attr, lcs_eol_one,
1964 &on_last_col);
1965 ptr = line + v; // "line" may have been changed
1966 prev_ptr = ptr;
1967
1968 // Do not allow a conceal over EOL otherwise EOL will be missed
1969 // and bad things happen.
1970 if (*ptr == NUL)
1971 has_match_conc = 0;
1972 }
1973#endif
1974
1975#ifdef FEAT_DIFF
1976 if (wlv.diff_hlf != (hlf_T)0)
1977 {
1978 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1979 && wlv.n_extra == 0)
1980 wlv.diff_hlf = HLF_TXD; // changed text
1981 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1982 && wlv.n_extra == 0)
1983 wlv.diff_hlf = HLF_CHD; // changed line
1984 line_attr = HL_ATTR(wlv.diff_hlf);
1985 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1986 && wp->w_p_culopt_flags != CULOPT_NBR
1987 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1988 && wlv.vcol <= right_curline_col)))
1989 line_attr = hl_combine_attr(
1990 line_attr, HL_ATTR(HLF_CUL));
1991 }
1992#endif
1993
Bram Moolenaara74fda62019-10-19 17:38:03 +02001994#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001995 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001996 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001997 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001998# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001999 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002000 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002001# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002002 // Get syntax attribute.
2003 if (has_syntax)
2004 {
2005 // Get the syntax attribute for the character. If there
2006 // is an error, disable syntax highlighting.
2007 save_did_emsg = did_emsg;
2008 did_emsg = FALSE;
2009
2010 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002011 if (v == prev_syntax_col)
2012 // at same column again
2013 syntax_attr = prev_syntax_attr;
2014 else
2015 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002016# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002017 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002018# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002019 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002020# ifdef FEAT_SPELL
2021 has_spell ? &can_spell :
2022# endif
2023 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002024 prev_syntax_col = v;
2025 prev_syntax_attr = syntax_attr;
2026 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002027
Bram Moolenaar34390282019-10-16 14:38:26 +02002028 if (did_emsg)
2029 {
2030 wp->w_s->b_syn_error = TRUE;
2031 has_syntax = FALSE;
2032 syntax_attr = 0;
2033 }
2034 else
2035 did_emsg = save_did_emsg;
2036# ifdef SYN_TIME_LIMIT
2037 if (wp->w_s->b_syn_slow)
2038 has_syntax = FALSE;
2039# endif
2040
2041 // Need to get the line again, a multi-line regexp may
2042 // have made it invalid.
2043 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2044 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002045 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002046# ifdef FEAT_CONCEAL
2047 // no concealing past the end of the line, it interferes
2048 // with line highlighting
2049 if (*ptr == NUL)
2050 syntax_flags = 0;
2051 else
2052 syntax_flags = get_syntax_info(&syntax_seqnr);
2053# endif
2054 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002055 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002056# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002057 // Combine text property highlight into syntax highlight.
2058 if (text_prop_type != NULL)
2059 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002060 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002061 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2062 else
2063 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002064 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002065 }
2066# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002067#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002068
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 // Decide which of the highlight attributes to use.
2070 attr_pri = TRUE;
2071#ifdef LINE_ATTR
2072 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002073 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002074 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002075 if (!highlight_match)
2076 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002077 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002078# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002079 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002080# endif
2081 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002082 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002083 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002084 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002085# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002086 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002087# endif
2088 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002089 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002090 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2091 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092 {
2093 // Use line_attr when not in the Visual or 'incsearch' area
2094 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002095# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002096 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002097# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002098 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002099# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100 attr_pri = FALSE;
2101 }
2102#else
2103 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002104 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002105 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002106 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107#endif
2108 else
2109 {
2110 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002112 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002113#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002114 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002115#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002116 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002117#ifdef FEAT_PROP_POPUP
2118 // override with text property highlight when "override" is TRUE
2119 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002120 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002121#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002122 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002123
2124 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002125 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002126 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002127 if (wlv.char_attr == 0)
2128 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002129 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002131 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132
2133 // Get the next character to put on the screen.
2134
2135 // The "p_extra" points to the extra stuff that is inserted to
2136 // represent special characters (non-printable stuff) and other
2137 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002138 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002139 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2140 // "p_extra[n_extra]".
2141 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002142 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002143 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002146 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2147 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002148 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2149 if (enc_utf8 && utf_char2len(c) > 1)
2150 {
2151 mb_utf8 = TRUE;
2152 u8cc[0] = 0;
2153 c = 0xc0;
2154 }
2155 else
2156 mb_utf8 = FALSE;
2157 }
2158 else
2159 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002161 if (has_mbyte)
2162 {
2163 mb_c = c;
2164 if (enc_utf8)
2165 {
2166 // If the UTF-8 character is more than one byte:
2167 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 mb_l = 1;
2172 else if (mb_l > 1)
2173 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002174 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175 mb_utf8 = TRUE;
2176 c = 0xc0;
2177 }
2178 }
2179 else
2180 {
2181 // if this is a DBCS character, put it in "mb_c"
2182 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184 mb_l = 1;
2185 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002186 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 }
2188 if (mb_l == 0) // at the NUL at end-of-line
2189 mb_l = 1;
2190
2191 // If a double-width char doesn't fit display a '>' in the
2192 // last column.
2193 if ((
2194# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002195 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002197 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002198 && (*mb_char2cells)(mb_c) == 2)
2199 {
2200 c = '>';
2201 mb_c = c;
2202 mb_l = 1;
2203 mb_utf8 = FALSE;
2204 multi_attr = HL_ATTR(HLF_AT);
2205#ifdef FEAT_SYN_HL
2206 if (cul_attr)
2207 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2208#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002209 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002210
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 // put the pointer back to output the double-width
2212 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002213 ++wlv.n_extra;
2214 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215 }
2216 else
2217 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002218 wlv.n_extra -= mb_l - 1;
2219 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 }
2221 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002222 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002224 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002225#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002226 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002227 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002228 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002229 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002230 if (search_attr == 0)
2231 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002232 if (area_attr == 0 && *ptr != NUL)
2233 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002234 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002235#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236 }
2237 else
2238 {
2239#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002240 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002242 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 // Get a character from the line itself.
2245 c = *ptr;
2246#ifdef FEAT_LINEBREAK
2247 c0 = *ptr;
2248#endif
2249 if (has_mbyte)
2250 {
2251 mb_c = c;
2252 if (enc_utf8)
2253 {
2254 // If the UTF-8 character is more than one byte: Decode it
2255 // into "mb_c".
2256 mb_l = utfc_ptr2len(ptr);
2257 mb_utf8 = FALSE;
2258 if (mb_l > 1)
2259 {
2260 mb_c = utfc_ptr2char(ptr, u8cc);
2261 // Overlong encoded ASCII or ASCII with composing char
2262 // is displayed normally, except a NUL.
2263 if (mb_c < 0x80)
2264 {
2265 c = mb_c;
2266#ifdef FEAT_LINEBREAK
2267 c0 = mb_c;
2268#endif
2269 }
2270 mb_utf8 = TRUE;
2271
2272 // At start of the line we can have a composing char.
2273 // Draw it as a space with a composing char.
2274 if (utf_iscomposing(mb_c))
2275 {
2276 int i;
2277
2278 for (i = Screen_mco - 1; i > 0; --i)
2279 u8cc[i] = u8cc[i - 1];
2280 u8cc[0] = mb_c;
2281 mb_c = ' ';
2282 }
2283 }
2284
2285 if ((mb_l == 1 && c >= 0x80)
2286 || (mb_l >= 1 && mb_c == 0)
2287 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2288 {
2289 // Illegal UTF-8 byte: display as <xx>.
2290 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002291 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292# ifdef FEAT_RIGHTLEFT
2293 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002294 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002295# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002296 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002297 c = *wlv.p_extra;
2298 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002300 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2301 wlv.c_extra = NUL;
2302 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 if (area_attr == 0 && search_attr == 0)
2304 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002305 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002306 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002307 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002308 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 }
2310 }
2311 else if (mb_l == 0) // at the NUL at end-of-line
2312 mb_l = 1;
2313#ifdef FEAT_ARABIC
2314 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2315 {
2316 // Do Arabic shaping.
2317 int pc, pc1, nc;
2318 int pcc[MAX_MCO];
2319
2320 // The idea of what is the previous and next
2321 // character depends on 'rightleft'.
2322 if (wp->w_p_rl)
2323 {
2324 pc = prev_c;
2325 pc1 = prev_c1;
2326 nc = utf_ptr2char(ptr + mb_l);
2327 prev_c1 = u8cc[0];
2328 }
2329 else
2330 {
2331 pc = utfc_ptr2char(ptr + mb_l, pcc);
2332 nc = prev_c;
2333 pc1 = pcc[0];
2334 }
2335 prev_c = mb_c;
2336
2337 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2338 }
2339 else
2340 prev_c = mb_c;
2341#endif
2342 }
2343 else // enc_dbcs
2344 {
2345 mb_l = MB_BYTE2LEN(c);
2346 if (mb_l == 0) // at the NUL at end-of-line
2347 mb_l = 1;
2348 else if (mb_l > 1)
2349 {
2350 // We assume a second byte below 32 is illegal.
2351 // Hopefully this is OK for all double-byte encodings!
2352 if (ptr[1] >= 32)
2353 mb_c = (c << 8) + ptr[1];
2354 else
2355 {
2356 if (ptr[1] == NUL)
2357 {
2358 // head byte at end of line
2359 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002360 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361 }
2362 else
2363 {
2364 // illegal tail byte
2365 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002366 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002368 wlv.p_extra = wlv.extra;
2369 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 wlv.c_extra = NUL;
2371 wlv.c_final = NUL;
2372 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 if (area_attr == 0 && search_attr == 0)
2374 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002376 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002377 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 // save current attr
2379 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 }
2381 mb_c = c;
2382 }
2383 }
2384 }
2385 // If a double-width char doesn't fit display a '>' in the
2386 // last column; the character is displayed at the start of the
2387 // next line.
2388 if ((
2389# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002390 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002392 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 && (*mb_char2cells)(mb_c) == 2)
2394 {
2395 c = '>';
2396 mb_c = c;
2397 mb_utf8 = FALSE;
2398 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002399 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 // Put pointer back so that the character will be
2401 // displayed at the start of the next line.
2402 --ptr;
2403#ifdef FEAT_CONCEAL
2404 did_decrement_ptr = TRUE;
2405#endif
2406 }
2407 else if (*ptr != NUL)
2408 ptr += mb_l - 1;
2409
2410 // If a double-width char doesn't fit at the left side display
2411 // a '<' in the first column. Don't do this for unprintable
2412 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002413 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 wlv.n_extra = 1;
2416 wlv.c_extra = MB_FILLER_CHAR;
2417 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002418 c = ' ';
2419 if (area_attr == 0 && search_attr == 0)
2420 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002421 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002422 extra_attr = hl_combine_attr(
2423 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002424 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425 }
2426 mb_c = c;
2427 mb_utf8 = FALSE;
2428 mb_l = 1;
2429 }
2430
2431 }
2432 ++ptr;
2433
2434 if (extra_check)
2435 {
2436#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 // Check spelling (unless at the end of the line).
2438 // Only do this when there is no syntax highlighting, the
2439 // @Spell cluster is not used or the current syntax item
2440 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002441 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 if (has_spell && v >= word_end && v > cur_checked_col)
2443 {
2444 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002445 // do not calculate cap_col at the end of the line or when
2446 // only white space is following
2447 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448# ifdef FEAT_SYN_HL
2449 !has_syntax ||
2450# endif
2451 can_spell))
2452 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002453 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454 int len;
2455 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002456
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459
2460 // Use nextline[] if possible, it has the start of the
2461 // next line concatenated.
2462 if ((prev_ptr - line) - nextlinecol >= 0)
2463 p = nextline + (prev_ptr - line) - nextlinecol;
2464 else
2465 p = prev_ptr;
2466 cap_col -= (int)(prev_ptr - line);
2467 len = spell_check(wp, p, &spell_hlf, &cap_col,
2468 nochange);
2469 word_end = v + len;
2470
2471 // In Insert mode only highlight a word that
2472 // doesn't touch the cursor.
2473 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002474 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002475 && wp->w_cursor.lnum == lnum
2476 && wp->w_cursor.col >=
2477 (colnr_T)(prev_ptr - line)
2478 && wp->w_cursor.col < (colnr_T)word_end)
2479 {
2480 spell_hlf = HLF_COUNT;
2481 spell_redraw_lnum = lnum;
2482 }
2483
2484 if (spell_hlf == HLF_COUNT && p != prev_ptr
2485 && (p - nextline) + len > nextline_idx)
2486 {
2487 // Remember that the good word continues at the
2488 // start of the next line.
2489 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002490 checked_col = (int)((p - nextline)
2491 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 }
2493
2494 // Turn index into actual attributes.
2495 if (spell_hlf != HLF_COUNT)
2496 spell_attr = highlight_attr[spell_hlf];
2497
2498 if (cap_col > 0)
2499 {
2500 if (p != prev_ptr
2501 && (p - nextline) + cap_col >= nextline_idx)
2502 {
2503 // Remember that the word in the next line
2504 // must start with a capital.
2505 capcol_lnum = lnum + 1;
2506 cap_col = (int)((p - nextline) + cap_col
2507 - nextline_idx);
2508 }
2509 else
2510 // Compute the actual column.
2511 cap_col += (int)(prev_ptr - line);
2512 }
2513 }
2514 }
2515 if (spell_attr != 0)
2516 {
2517 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2519 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 wlv.char_attr = hl_combine_attr(spell_attr,
2522 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523 }
2524#endif
2525#ifdef FEAT_LINEBREAK
2526 // Found last space before word: check for line break.
2527 if (wp->w_p_lbr && c0 == c
2528 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2529 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002530 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2531 : 0;
2532 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002533 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002535 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002536# ifdef FEAT_PROP_POPUP
2537 // do not want virtual text counted here
2538 cts.cts_has_prop_with_text = FALSE;
2539# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002540 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002541 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002542
2543 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002544 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002545 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002546 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002547 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2548 if (wlv.n_extra < 0)
2549 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002550 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002551 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002552 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002553 // line break, but for TABs the highlighting should
2554 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002555 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002556
Bram Moolenaar1306b362022-08-06 15:59:06 +01002557 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002560 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 wp->w_buffer->b_p_vts_array) - 1;
2562# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002564 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565# endif
2566
Bram Moolenaar1306b362022-08-06 15:59:06 +01002567 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2568 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002569# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002570 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002571 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002572# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 if (VIM_ISWHITE(c))
2574 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002575# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002576 if (c == TAB)
2577 // See "Tab alignment" below.
2578 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002579# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580 if (!wp->w_p_list)
2581 c = ' ';
2582 }
2583 }
2584#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002585 in_multispace = c == ' '
2586 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2587 if (!in_multispace)
2588 multispace_pos = 0;
2589
Bram Moolenaareed9d462021-02-15 20:38:25 +01002590 // 'list': Change char 160 to 'nbsp' and space to 'space'
2591 // setting in 'listchars'. But not when the character is
2592 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 if (wp->w_p_list
2594 && ((((c == 160 && mb_l == 1)
2595 || (mb_utf8
2596 && ((mb_c == 160 && mb_l == 2)
2597 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002598 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599 || (c == ' '
2600 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002601 && (wp->w_lcs_chars.space
2602 || (in_multispace
2603 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002604 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605 && ptr - line <= trailcol)))
2606 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002607 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2608 {
2609 c = wp->w_lcs_chars.multispace[multispace_pos++];
2610 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2611 multispace_pos = 0;
2612 }
2613 else
2614 c = (c == ' ') ? wp->w_lcs_chars.space
2615 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 if (area_attr == 0 && search_attr == 0)
2617 {
2618 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002619 extra_attr = hl_combine_attr(wlv.win_attr,
2620 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002621 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 }
2623 mb_c = c;
2624 if (enc_utf8 && utf_char2len(c) > 1)
2625 {
2626 mb_utf8 = TRUE;
2627 u8cc[0] = 0;
2628 c = 0xc0;
2629 }
2630 else
2631 mb_utf8 = FALSE;
2632 }
2633
zeertzjq2e7cba32022-06-10 15:30:32 +01002634 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2635 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002637 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2638 && wp->w_lcs_chars.leadmultispace != NULL)
2639 {
2640 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002641 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2642 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002643 multispace_pos = 0;
2644 }
2645
2646 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2647 c = wp->w_lcs_chars.trail;
2648
2649 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2650 c = wp->w_lcs_chars.lead;
2651
zeertzjq2e7cba32022-06-10 15:30:32 +01002652 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002653 c = wp->w_lcs_chars.space;
2654
2655
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656 if (!attr_pri)
2657 {
2658 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002659 extra_attr = hl_combine_attr(wlv.win_attr,
2660 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002661 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 }
2663 mb_c = c;
2664 if (enc_utf8 && utf_char2len(c) > 1)
2665 {
2666 mb_utf8 = TRUE;
2667 u8cc[0] = 0;
2668 c = 0xc0;
2669 }
2670 else
2671 mb_utf8 = FALSE;
2672 }
2673 }
2674
2675 // Handling of non-printable characters.
2676 if (!vim_isprintc(c))
2677 {
2678 // when getting a character from the file, we may have to
2679 // turn it into something else on the way to putting it
2680 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002681 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682 {
2683 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002684 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002686 char_u *sbr = get_showbreak_value(wp);
2687
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 // only adjust the tab_len, when at the first column
2689 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002690 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2691 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002692#endif
2693 // tab amount depends on current column
2694#ifdef FEAT_VARTABS
2695 tab_len = tabstop_padding(vcol_adjusted,
2696 wp->w_buffer->b_p_ts,
2697 wp->w_buffer->b_p_vts_array) - 1;
2698#else
2699 tab_len = (int)wp->w_buffer->b_p_ts
2700 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2701#endif
2702
2703#ifdef FEAT_LINEBREAK
2704 if (!wp->w_p_lbr || !wp->w_p_list)
2705#endif
2706 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708#ifdef FEAT_LINEBREAK
2709 else
2710 {
2711 char_u *p;
2712 int len;
2713 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002714 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002716# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002717 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002718 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002719 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002720
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002722 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002723 && old_boguscols > 0
2724 && wlv.n_extra > tab_len)
2725 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002726# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002727 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002729 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002730 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002731 if (wp->w_lcs_chars.tab3)
2732 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002733 if (wlv.n_extra > 0)
2734 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002735 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002737 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002738 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002739 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002741 vim_memset(p, ' ', len);
2742 p[len] = NUL;
2743 vim_free(p_extra_free);
2744 p_extra_free = p;
2745 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002747 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002749 if (*p == NUL)
2750 {
2751 tab_len = i;
2752 break;
2753 }
2754
2755 // if tab3 is given, use it for the last char
2756 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2757 lcs = wp->w_lcs_chars.tab3;
2758 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002759 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002761 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002762 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002763# ifdef FEAT_CONCEAL
2764 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2765 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002766 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002768# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 }
2771#endif
2772#ifdef FEAT_CONCEAL
2773 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002774 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775
2776 // Tab alignment should be identical regardless of
2777 // 'conceallevel' value. So tab compensates of all
2778 // previous concealed characters, and thus resets
2779 // vcol_off and boguscols accumulated so far in the
2780 // line. Note that the tab can be longer than
2781 // 'tabstop' when there are concealed characters.
2782 FIX_FOR_BOGUSCOLS;
2783
2784 // Make sure, the highlighting for the tab char will be
2785 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002786 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002788 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 tab_len += vc_saved;
2790 }
2791#endif
2792 mb_utf8 = FALSE; // don't draw as UTF-8
2793 if (wp->w_p_list)
2794 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002795 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002796 ? wp->w_lcs_chars.tab3
2797 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798#ifdef FEAT_LINEBREAK
2799 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002800 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 else
2802#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002803 wlv.c_extra = wp->w_lcs_chars.tab2;
2804 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002806 extra_attr = hl_combine_attr(wlv.win_attr,
2807 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002808 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 mb_c = c;
2810 if (enc_utf8 && utf_char2len(c) > 1)
2811 {
2812 mb_utf8 = TRUE;
2813 u8cc[0] = 0;
2814 c = 0xc0;
2815 }
2816 }
2817 else
2818 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002819 wlv.c_final = NUL;
2820 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 c = ' ';
2822 }
2823 }
2824 else if (c == NUL
2825 && (wp->w_p_list
2826 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002827 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 && VIsual_mode != Ctrl_V
2829 && (
2830# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002831 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 && !(noinvcur
2835 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002836 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 && lcs_eol_one > 0)
2838 {
2839 // Display a '$' after the line or highlight an extra
2840 // character if the line break is included.
2841#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2842 // For a diff line the highlighting continues after the
2843 // "$".
2844 if (
2845# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002846 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847# ifdef LINE_ATTR
2848 &&
2849# endif
2850# endif
2851# ifdef LINE_ATTR
2852 line_attr == 0
2853# endif
2854 )
2855#endif
2856 {
2857 // In virtualedit, visual selections may extend
2858 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002859 if (!(area_highlighting && virtual_active()
2860 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002861 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002862 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002864 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2865 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866 else
2867 c = ' ';
2868 lcs_eol_one = -1;
2869 --ptr; // put it back at the NUL
2870 if (!attr_pri)
2871 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002872 extra_attr = hl_combine_attr(wlv.win_attr,
2873 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 n_attr = 1;
2875 }
2876 mb_c = c;
2877 if (enc_utf8 && utf_char2len(c) > 1)
2878 {
2879 mb_utf8 = TRUE;
2880 u8cc[0] = 0;
2881 c = 0xc0;
2882 }
2883 else
2884 mb_utf8 = FALSE; // don't draw as UTF-8
2885 }
2886 else if (c != NUL)
2887 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2889 if (wlv.n_extra == 0)
2890 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891#ifdef FEAT_RIGHTLEFT
2892 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002895 wlv.c_extra = NUL;
2896 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897#ifdef FEAT_LINEBREAK
2898 if (wp->w_p_lbr)
2899 {
2900 char_u *p;
2901
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 c = *wlv.p_extra;
2903 p = alloc(wlv.n_extra + 1);
2904 vim_memset(p, ' ', wlv.n_extra);
2905 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2906 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002908 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 }
2910 else
2911#endif
2912 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 wlv.n_extra = byte2cells(c) - 1;
2914 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 }
2916 if (!attr_pri)
2917 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002918 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002919 extra_attr = hl_combine_attr(wlv.win_attr,
2920 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002921 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 }
2923 mb_utf8 = FALSE; // don't draw as UTF-8
2924 }
2925 else if (VIsual_active
2926 && (VIsual_mode == Ctrl_V
2927 || VIsual_mode == 'v')
2928 && virtual_active()
2929 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002930 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 && (
2932#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002933 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002935 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 {
2937 c = ' ';
2938 --ptr; // put it back at the NUL
2939 }
2940#if defined(LINE_ATTR)
2941 else if ((
2942# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944# endif
2945# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002946 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947# endif
2948 line_attr != 0
2949 ) && (
2950# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002951 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002953 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002955 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956# endif
2957 < wp->w_width)))
2958 {
2959 // Highlight until the right side of the window
2960 c = ' ';
2961 --ptr; // put it back at the NUL
2962
2963 // Remember we do the char for line highlighting.
2964 ++did_line_attr;
2965
2966 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002969 || (wp->w_p_list &&
2970 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 wlv.diff_hlf = HLF_CHD;
2976 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002978 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2980 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002981 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002982 || (wlv.vcol >= left_curline_col
2983 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002984 wlv.char_attr = hl_combine_attr(
2985 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 }
2987 }
2988# endif
2989# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002990 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002992 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002993 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2994 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002996 if (!wlv.cul_screenline
2997 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002998 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002999 wlv.char_attr = hl_combine_attr(
3000 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 }
3002 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003003 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3004 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005 }
3006# endif
3007 }
3008#endif
3009 }
3010
3011#ifdef FEAT_CONCEAL
3012 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003013 && (wp != curwin || lnum != wp->w_cursor.lnum
3014 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3016 && !(lnum_in_visual_area
3017 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3018 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003020 if (((prev_syntax_id != syntax_seqnr
3021 && (syntax_flags & HL_CONCEAL) != 0)
3022 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003023 && (syn_get_sub_char() != NUL
3024 || (has_match_conc && match_conc)
3025 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 && wp->w_p_cole != 3)
3027 {
3028 // First time at this concealed item: display one
3029 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003030 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 c = match_conc;
3032 else if (syn_get_sub_char() != NUL)
3033 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003034 else if (wp->w_lcs_chars.conceal != NUL)
3035 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 else
3037 c = ' ';
3038
3039 prev_syntax_id = syntax_seqnr;
3040
Bram Moolenaar1306b362022-08-06 15:59:06 +01003041 if (wlv.n_extra > 0)
3042 wlv.vcol_off += wlv.n_extra;
3043 wlv.vcol += wlv.n_extra;
3044 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 {
3046# ifdef FEAT_RIGHTLEFT
3047 if (wp->w_p_rl)
3048 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 wlv.col -= wlv.n_extra;
3050 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 }
3052 else
3053# endif
3054 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 wlv.boguscols += wlv.n_extra;
3056 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 }
3058 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 n_attr = 0;
3061 }
3062 else if (n_skip == 0)
3063 {
3064 is_concealing = TRUE;
3065 n_skip = 1;
3066 }
3067 mb_c = c;
3068 if (enc_utf8 && utf_char2len(c) > 1)
3069 {
3070 mb_utf8 = TRUE;
3071 u8cc[0] = 0;
3072 c = 0xc0;
3073 }
3074 else
3075 mb_utf8 = FALSE; // don't draw as UTF-8
3076 }
3077 else
3078 {
3079 prev_syntax_id = 0;
3080 is_concealing = FALSE;
3081 }
3082
3083 if (n_skip > 0 && did_decrement_ptr)
3084 // not showing the '>', put pointer back to avoid getting stuck
3085 ++ptr;
3086
3087#endif // FEAT_CONCEAL
3088 }
3089
3090#ifdef FEAT_CONCEAL
3091 // In the cursor line and we may be concealing characters: correct
3092 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003093 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094 && wp == curwin && lnum == wp->w_cursor.lnum
3095 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003096 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003098# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003100 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003102# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003103 wp->w_wcol = wlv.col - wlv.boguscols;
3104 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 did_wcol = TRUE;
3106 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003107# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003108 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003109# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 }
3111#endif
3112
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003113 // Use "extra_attr", but don't override visual selection highlighting,
3114 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003115 // Don't use "extra_attr" until n_attr_skip is zero.
3116 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003117 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003118 && (!attr_pri
3119#ifdef FEAT_PROP_POPUP
3120 || (text_prop_flags & PT_FLAG_OVERRIDE)
3121#endif
3122 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 {
3124#ifdef LINE_ATTR
3125 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003126 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 else
3128#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003129 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 }
3131
3132#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3133 // XIM don't send preedit_start and preedit_end, but they send
3134 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3135 // im_is_preediting() here.
3136 if (p_imst == IM_ON_THE_SPOT
3137 && xic != NULL
3138 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003139 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 && !p_imdisable
3141 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003142 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143 {
3144 colnr_T tcol;
3145
3146 if (preedit_end_col == MAXCOL)
3147 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3148 else
3149 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003150 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 {
3152 if (feedback_old_attr < 0)
3153 {
3154 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003155 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003157 wlv.char_attr = im_get_feedback_attr(feedback_col);
3158 if (wlv.char_attr < 0)
3159 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 feedback_col++;
3161 }
3162 else if (feedback_old_attr >= 0)
3163 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 feedback_old_attr = -1;
3166 feedback_col = 0;
3167 }
3168 }
3169#endif
3170 // Handle the case where we are in column 0 but not on the first
3171 // character of the line and the user wants us to show us a
3172 // special character (via 'listchars' option "precedes:<char>".
3173 if (lcs_prec_todo != NUL
3174 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003175 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003177 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003179 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003181 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 && c != NUL)
3183 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003184 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 lcs_prec_todo = NUL;
3186 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3187 {
3188 // Double-width character being overwritten by the "precedes"
3189 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 wlv.c_extra = MB_FILLER_CHAR;
3191 wlv.c_final = NUL;
3192 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003194 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 }
3196 mb_c = c;
3197 if (enc_utf8 && utf_char2len(c) > 1)
3198 {
3199 mb_utf8 = TRUE;
3200 u8cc[0] = 0;
3201 c = 0xc0;
3202 }
3203 else
3204 mb_utf8 = FALSE; // don't draw as UTF-8
3205 if (!attr_pri)
3206 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 saved_attr3 = wlv.char_attr; // save current attr
3208 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 n_attr3 = 1;
3210 }
3211 }
3212
3213 // At end of the text line or just after the last character.
3214 if ((c == NUL
3215#if defined(LINE_ATTR)
3216 || did_line_attr == 1
3217#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003218 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 {
3220#ifdef FEAT_SEARCH_EXTRA
3221 // flag to indicate whether prevcol equals startcol of search_hl or
3222 // one of the matches
3223 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3224 (long)(ptr - line) - (c == NUL));
3225#endif
3226 // Invert at least one char, used for Visual and empty line or
3227 // highlight match at end of line. If it's beyond the last
3228 // char on the screen, just overwrite that one (tricky!) Not
3229 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003230 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003231 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 && (VIsual_mode != Ctrl_V
3233 || lnum == VIsual.lnum
3234 || lnum == curwin->w_cursor.lnum)
3235 && c == NUL)
3236#ifdef FEAT_SEARCH_EXTRA
3237 // highlight 'hlsearch' match at end of line
3238 || (prevcol_hl_flag
3239# ifdef FEAT_SYN_HL
3240 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3241 && !(wp == curwin && VIsual_active))
3242# endif
3243# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245# endif
3246# if defined(LINE_ATTR)
3247 && did_line_attr <= 1
3248# endif
3249 )
3250#endif
3251 ))
3252 {
3253 int n = 0;
3254
3255#ifdef FEAT_RIGHTLEFT
3256 if (wp->w_p_rl)
3257 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 n = 1;
3260 }
3261 else
3262#endif
3263 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 n = -1;
3266 }
3267 if (n != 0)
3268 {
3269 // At the window boundary, highlight the last character
3270 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003271 wlv.off += n;
3272 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 }
3274 else
3275 {
3276 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003277 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 }
3281#ifdef FEAT_SEARCH_EXTRA
3282 if (area_attr == 0)
3283 {
3284 // Use attributes from match with highest priority among
3285 // 'search_hl' and the match list.
3286 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003287 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 }
3289#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003290 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292#ifdef FEAT_RIGHTLEFT
3293 if (wp->w_p_rl)
3294 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003295 --wlv.col;
3296 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 }
3298 else
3299#endif
3300 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003301 ++wlv.col;
3302 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003304 ++wlv.vcol;
3305 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 }
3307 }
3308
3309 // At end of the text line.
3310 if (c == NUL)
3311 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003312 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313
3314 // Update w_cline_height and w_cline_folded if the cursor line was
3315 // updated (saves a call to plines() later).
3316 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3317 {
3318 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003319 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320#ifdef FEAT_FOLDING
3321 curwin->w_cline_folded = FALSE;
3322#endif
3323 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3324 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 break;
3326 }
3327
3328 // Show "extends" character from 'listchars' if beyond the line end and
3329 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003330 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003331 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 && wp->w_p_list
3333 && !wp->w_p_wrap
3334#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003335 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336#endif
3337 && (
3338#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003339 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003341 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003343 || lcs_eol_one > 0
3344 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003347 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003348 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 mb_c = c;
3350 if (enc_utf8 && utf_char2len(c) > 1)
3351 {
3352 mb_utf8 = TRUE;
3353 u8cc[0] = 0;
3354 c = 0xc0;
3355 }
3356 else
3357 mb_utf8 = FALSE;
3358 }
3359
3360#ifdef FEAT_SYN_HL
3361 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003362 if (wlv.draw_color_col)
3363 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364
3365 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3366 // highlight the cursor position itself.
3367 // Also highlight the 'colorcolumn' if it is different than
3368 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003369 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3370 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003372 if (((wlv.draw_state == WL_LINE
3373 || wlv.draw_state == WL_BRI
3374 || wlv.draw_state == WL_SBR)
3375 && !lnum_in_visual_area
3376 && search_attr == 0
3377 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003378# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003379 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003380# endif
3381 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 {
3383 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3384 && lnum != wp->w_cursor.lnum)
3385 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003386 vcol_save_attr = wlv.char_attr;
3387 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3388 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003390 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 vcol_save_attr = wlv.char_attr;
3393 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394 }
3395 }
3396#endif
3397
3398 // Store character to be displayed.
3399 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003400 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003401 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 {
3403 // Store the character.
3404#if defined(FEAT_RIGHTLEFT)
3405 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3406 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003407 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003408 --wlv.off;
3409 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 }
3411#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 if (enc_dbcs == DBCS_JPNU)
3414 {
3415 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003416 ScreenLines[wlv.off] = 0x8e;
3417 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 }
3419 else if (enc_utf8)
3420 {
3421 if (mb_utf8)
3422 {
3423 int i;
3424
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 for (i = 0; i < Screen_mco; ++i)
3429 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003430 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431 if (u8cc[i] == 0)
3432 break;
3433 }
3434 }
3435 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003436 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 }
3438 if (multi_attr)
3439 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003440 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 multi_attr = 0;
3442 }
3443 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003444 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003447
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3449 {
3450 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 ++wlv.off;
3452 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 if (enc_utf8)
3454 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 else
3457 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003458 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003461 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462#endif
3463 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003464 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 // When "tocol" is halfway a character, set it to the end of
3466 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003469
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003470 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003471
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472#ifdef FEAT_RIGHTLEFT
3473 if (wp->w_p_rl)
3474 {
3475 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003476 --wlv.off;
3477 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 }
3479#endif
3480 }
3481#ifdef FEAT_RIGHTLEFT
3482 if (wp->w_p_rl)
3483 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003484 --wlv.off;
3485 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 }
3487 else
3488#endif
3489 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003490 ++wlv.off;
3491 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 }
3493 }
3494#ifdef FEAT_CONCEAL
3495 else if (wp->w_p_cole > 0 && is_concealing)
3496 {
3497 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003499 if (wlv.n_extra > 0)
3500 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 if (wp->w_p_wrap)
3502 {
3503 // Special voodoo required if 'wrap' is on.
3504 //
3505 // Advance the column indicator to force the line
3506 // drawing to wrap early. This will make the line
3507 // take up the same screen space when parts are concealed,
3508 // so that cursor line computations aren't messed up.
3509 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003510 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 // trailing junk to be written out of the screen line
3512 // we are building, 'boguscols' keeps track of the number
3513 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003514 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003516 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517# ifdef FEAT_RIGHTLEFT
3518 if (wp->w_p_rl)
3519 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003520 wlv.col -= wlv.n_extra;
3521 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522 }
3523 else
3524# endif
3525 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003526 wlv.col += wlv.n_extra;
3527 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003529 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 n_attr = 0;
3531 }
3532
3533
3534 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3535 {
3536 // Need to fill two screen columns.
3537# ifdef FEAT_RIGHTLEFT
3538 if (wp->w_p_rl)
3539 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003540 --wlv.boguscols;
3541 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 }
3543 else
3544# endif
3545 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 ++wlv.boguscols;
3547 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 }
3549 }
3550
3551# ifdef FEAT_RIGHTLEFT
3552 if (wp->w_p_rl)
3553 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003554 --wlv.boguscols;
3555 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 }
3557 else
3558# endif
3559 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 ++wlv.boguscols;
3561 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 }
3563 }
3564 else
3565 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003566 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003568 wlv.vcol += wlv.n_extra;
3569 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 n_attr = 0;
3571 }
3572 }
3573
3574 }
3575#endif // FEAT_CONCEAL
3576 else
3577 --n_skip;
3578
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 // Only advance the "wlv.vcol" when after the 'number' or
3580 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003581 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003583 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584#endif
3585 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587
3588#ifdef FEAT_SYN_HL
3589 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003590 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591#endif
3592
3593 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003594 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3595 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596
3597 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003598 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003599 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003600 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003601 if (n_attr_skip > 0)
3602 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603
3604 // At end of screen line and there is more to come: Display the line
3605 // so far. If there is no more to display it is caught above.
3606 if ((
3607#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003608 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003612 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003614 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003616#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003617 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003618#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003619 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003620 && wlv.p_extra != at_end_str)
3621 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3622 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 )
3624 {
3625#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 screen_line(wp, wlv.screen_row, wp->w_wincol,
3627 wlv.col - wlv.boguscols,
3628 wp->w_width, wlv.screen_line_flags);
3629 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3632 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003634 ++wlv.row;
3635 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636
3637 // When not wrapping and finished diff lines, or when displayed
3638 // '$' and highlighting until last column, break here.
3639 if ((!wp->w_p_wrap
3640#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003641 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003642#endif
3643#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003644 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645#endif
3646 ) || lcs_eol_one == -1)
3647 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003648#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003649 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003650 {
3651 // do not output more of the line, only the "below" prop
3652 ptr += STRLEN(ptr);
3653# ifdef FEAT_LINEBREAK
3654 dont_use_showbreak = TRUE;
3655# endif
3656 }
3657#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658
3659 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003660 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003662 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663#endif
3664 )
3665 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003666 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3667 draw_vsep_win(wp, wlv.row);
3668 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 }
3670
3671 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003672 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003674 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675 break;
3676 }
3677
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003678 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003680 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003682#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003683 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003684#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 && wp->w_width == Columns)
3686 {
3687 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003688 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689
3690 // Special trick to make copy/paste of wrapped lines work with
3691 // xterm/screen: write an extra character beyond the end of
3692 // the line. This will work with all terminal types
3693 // (regardless of the xn,am settings).
3694 // Only do this on a fast tty.
3695 // Only do this if the cursor is on the current line
3696 // (something has been written in it).
3697 // Don't do this for the GUI.
3698 // Don't do this for double-width characters.
3699 // Don't do this for a window not at the right screen border.
3700 if (p_tf
3701#ifdef FEAT_GUI
3702 && !gui.in_use
3703#endif
3704 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3706 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003708 || (*mb_off2cells)(
3709 LineOffset[wlv.screen_row - 1]
3710 + (int)Columns - 2,
3711 LineOffset[wlv.screen_row]
3712 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003713 {
3714 // First make sure we are at the end of the screen line,
3715 // then output the same character again to let the
3716 // terminal know about the wrap. If the terminal doesn't
3717 // auto-wrap, we overwrite the character.
3718 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 screen_char(LineOffset[wlv.screen_row - 1]
3720 + (unsigned)Columns - 1,
3721 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722
3723 // When there is a multi-byte character, just output a
3724 // space to keep it simple.
3725 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003726 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727 out_char(' ');
3728 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003729 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 + (Columns - 1)]);
3731 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003732 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 screen_start(); // don't know where cursor is now
3734 }
3735 }
3736
Bram Moolenaar1306b362022-08-06 15:59:06 +01003737 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738
Bram Moolenaareed9d462021-02-15 20:38:25 +01003739 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003741 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003743 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003745 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 need_showbreak = TRUE;
3747#endif
3748#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003749 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750 // When the filler lines are actually below the last line of the
3751 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003752 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 break;
3754#endif
3755 }
3756
3757 } // for every character in the line
3758
3759#ifdef FEAT_SPELL
3760 // After an empty line check first word for capital.
3761 if (*skipwhite(line) == NUL)
3762 {
3763 capcol_lnum = lnum + 1;
3764 cap_col = 0;
3765 }
3766#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003767#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 vim_free(text_props);
3769 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003770 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771#endif
3772
3773 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003774 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775}