blob: d3eff8460512efa30a113b3b77f726f80dfea6ac [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,
295 int num_attr)
296{
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 Moolenaarf396ce82022-08-23 18:39:37 +0100394#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100395/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100396 * Return the cell size of virtual text after truncation.
397 */
398 static int
399textprop_size_after_trunc(
400 win_T *wp,
401 int flags, // TP_FLAG_ALIGN_*
402 int added,
403 char_u *text,
404 int *n_used_ptr)
405{
406 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
407 ? wp->w_width : added;
408 int len = (int)STRLEN(text);
409 int strsize = 0;
410 int n_used;
411
412 // if the remaining size is to small wrap anyway and use the next line
413 if (space < PROP_TEXT_MIN_CELLS)
414 space += wp->w_width;
415 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
416 {
417 int clen = ptr2cells(text + n_used);
418
419 if (strsize + clen > space)
420 break;
421 strsize += clen;
422 }
423 *n_used_ptr = n_used;
424 return strsize;
425}
426
427/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100428 * Take care of padding, right-align and truncation of virtual text after a
429 * line.
430 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
431 * padding, right-align and truncation. Otherwise only the size is computed.
432 * When "n_attr" is NULL returns the number of screen cells used.
433 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100434 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100435 int
436text_prop_position(
437 win_T *wp,
438 textprop_T *tp,
439 int vcol, // current screen column
440 int *n_extra, // nr of bytes for virtual text
441 char_u **p_extra, // virtual text
442 int *n_attr, // attribute cells, NULL if not used
443 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200444{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100445 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100446 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100447 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
448 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
449 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
450 ? tp->tp_len - 1 : 0;
451 int col_with_padding = vcol + (below ? 0 : padding);
452 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100453 int before = room; // spaces before the text
454 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100455 int n_used = *n_extra;
456 char_u *l = NULL;
457 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100458 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
459 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200460
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100461 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100462 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100463 int col_off = win_col_off(wp) + win_col_off2(wp);
464 int skip_add = 0;
465
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100466 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100467 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100468 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100469 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100470 }
471 else
472 {
473 // Right-align: fill with before
474 if (right)
475 before -= cells;
476 if (before < 0
477 || !(right || below)
478 || (below
479 ? (col_with_padding == 0 || !wp->w_p_wrap)
480 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100481 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100482 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
483 {
484 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100485 before = wp->w_width - col_off - strsize + room;
486 if (before < 0)
487 before = 0;
488 else
489 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100490 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100491 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100492 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100493 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100494 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100495 else if (below && before > 0)
496 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100497 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100498 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100499
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100500 // With 'nowrap' add one to show the "extends" character if needed (it
501 // doesn't show if the text just fits).
502 if (!wp->w_p_wrap
503 && n_used < *n_extra
504 && wp->w_lcs_chars.ext != NUL
505 && wp->w_p_list)
506 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100507 if (!wp->w_p_wrap && below && padding > 0)
508 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100509
510 // add 1 for NUL, 2 for when '…' is used
511 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100512 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100513 if (n_attr == NULL || l != NULL)
514 {
515 int off = 0;
516
517 if (n_attr != NULL)
518 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100519 vim_memset(l, ' ', before);
520 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100521 if (padding > 0)
522 {
523 vim_memset(l + off, ' ', padding);
524 off += padding;
525 }
526 vim_strncpy(l + off, *p_extra, n_used);
527 off += n_used;
528 }
529 else
530 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100531 off = before + after + padding + n_used;
532 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100533 }
534 if (n_attr != NULL)
535 {
536 if (n_used < *n_extra && wp->w_p_wrap)
537 {
538 char_u *lp = l + off - 1;
539
540 if (has_mbyte)
541 {
542 // change last character to '…'
543 lp -= (*mb_head_off)(l, lp);
544 STRCPY(lp, "…");
545 n_used = lp - l + 3 - padding;
546 }
547 else
548 // change last character to '>'
549 *lp = '>';
550 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100551 else if (after > 0)
552 {
553 vim_memset(l + off, ' ', after);
554 l[off + after] = NUL;
555 }
556
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100557 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100558 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100559 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100560 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100561 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100562 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100563 }
564 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100565 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100566
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100567 if (n_attr == NULL)
568 return cells;
569 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200570}
571#endif
572
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100573/*
574 * Called when finished with the line: draw the screen line and handle any
575 * highlighting until the right of the window.
576 */
577 static void
578draw_screen_line(win_T *wp, winlinevars_T *wlv)
579{
580#ifdef FEAT_SYN_HL
581 long v;
582
583 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
584 if (wp->w_p_wrap)
585 v = wp->w_skipcol;
586 else
587 v = wp->w_leftcol;
588
589 // check if line ends before left margin
590 if (wlv->vcol < v + wlv->col - win_col_off(wp))
591 wlv->vcol = v + wlv->col - win_col_off(wp);
592# ifdef FEAT_CONCEAL
593 // Get rid of the boguscols now, we want to draw until the right
594 // edge for 'cursorcolumn'.
595 wlv->col -= wlv->boguscols;
596 wlv->boguscols = 0;
597# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
598# else
599# define VCOL_HLC (wlv->vcol)
600# endif
601
602 if (wlv->draw_color_col)
603 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
604
605 if (((wp->w_p_cuc
606 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
607 && (int)wp->w_virtcol <
608 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
609 && wlv->lnum != wp->w_cursor.lnum)
610 || wlv->draw_color_col
611 || wlv->win_attr != 0)
612# ifdef FEAT_RIGHTLEFT
613 && !wp->w_p_rl
614# endif
615 )
616 {
617 int rightmost_vcol = 0;
618 int i;
619
620 if (wp->w_p_cuc)
621 rightmost_vcol = wp->w_virtcol;
622 if (wlv->draw_color_col)
623 // determine rightmost colorcolumn to possibly draw
624 for (i = 0; wlv->color_cols[i] >= 0; ++i)
625 if (rightmost_vcol < wlv->color_cols[i])
626 rightmost_vcol = wlv->color_cols[i];
627
628 while (wlv->col < wp->w_width)
629 {
630 ScreenLines[wlv->off] = ' ';
631 if (enc_utf8)
632 ScreenLinesUC[wlv->off] = 0;
633 ScreenCols[wlv->off] = MAXCOL;
634 ++wlv->col;
635 if (wlv->draw_color_col)
636 wlv->draw_color_col = advance_color_col(
637 VCOL_HLC, &wlv->color_cols);
638
639 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
640 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
641 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
642 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
643 else
644 ScreenAttrs[wlv->off++] = wlv->win_attr;
645
646 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
647 break;
648
649 ++wlv->vcol;
650 }
651 }
652#endif
653
654 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
655 wp->w_width, wlv->screen_line_flags);
656 ++wlv->row;
657 ++wlv->screen_row;
658}
659#undef VCOL_HLC
660
661/*
662 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100663 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100664 */
665 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100666win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100667{
668 wlv->col = 0;
669 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
670
671#ifdef FEAT_RIGHTLEFT
672 if (wp->w_p_rl)
673 {
674 // Rightleft window: process the text in the normal direction, but put
675 // it in current_ScreenLine[] from right to left. Start at the
676 // rightmost column of the window.
677 wlv->col = wp->w_width - 1;
678 wlv->off += wlv->col;
679 wlv->screen_line_flags |= SLF_RIGHTLEFT;
680 }
681#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100682 if (save_extra)
683 {
684 // reset the drawing state for the start of a wrapped line
685 wlv->draw_state = WL_START;
686 wlv->saved_n_extra = wlv->n_extra;
687 wlv->saved_p_extra = wlv->p_extra;
688 wlv->saved_c_extra = wlv->c_extra;
689 wlv->saved_c_final = wlv->c_final;
690#ifdef FEAT_SYN_HL
691 if (!(wlv->cul_screenline
692# ifdef FEAT_DIFF
693 && wlv->diff_hlf == (hlf_T)0
694# endif
695 ))
696 wlv->saved_char_attr = wlv->char_attr;
697 else
698#endif
699 wlv->saved_char_attr = 0;
700 wlv->n_extra = 0;
701 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100702}
703
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200704/*
705 * Display line "lnum" of window 'wp' on the screen.
706 * Start at row "startrow", stop when "endrow" is reached.
707 * wp->w_virtcol needs to be valid.
708 *
709 * Return the number of last row the line occupies.
710 */
711 int
712win_line(
713 win_T *wp,
714 linenr_T lnum,
715 int startrow,
716 int endrow,
717 int nochange UNUSED, // not updating for changed text
718 int number_only) // only update the number column
719{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100720 winlinevars_T wlv; // variables passed between functions
721
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200722 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200723#ifdef FEAT_LINEBREAK
724 long vcol_sbr = -1; // virtual column after showbreak
725#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100726 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200727 char_u *line; // current line
728 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200729
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200730 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100731#ifdef FEAT_PROP_POPUP
732 char_u *p_extra_free2 = NULL; // another p_extra to be freed
733#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200734 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000735#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000736 int in_linebreak = FALSE; // n_extra set for showing linebreak
737#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200738 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100739 // displaying eol at end-of-line
740 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000741 int lcs_prec_todo = wp->w_lcs_chars.prec;
742 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200743
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100744 int n_attr = 0; // chars with special attr
745 int n_attr_skip = 0; // chars to skip before using extra_attr
746 int saved_attr2 = 0; // char_attr saved for n_attr
747 int n_attr3 = 0; // chars with overruling special attr
748 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200749
750 int n_skip = 0; // nr of chars to skip for 'nowrap'
751
752 int fromcol = -10; // start of inverting
753 int tocol = MAXCOL; // end of inverting
754 int fromcol_prev = -2; // start of inverting after cursor
755 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200756 int lnum_in_visual_area = FALSE;
757 pos_T pos;
758 long v;
759
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200760 int attr_pri = FALSE; // char_attr has priority
761 int area_highlighting = FALSE; // Visual or incsearch highlighting
762 // in this line
763 int vi_attr = 0; // attributes for Visual and incsearch
764 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200765 int area_attr = 0; // attributes desired by highlighting
766 int search_attr = 0; // attributes desired by 'hlsearch'
767#ifdef FEAT_SYN_HL
768 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
769 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200770 int prev_syntax_col = -1; // column of prev_syntax_attr
771 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772 int has_syntax = FALSE; // this buffer has syntax highl.
773 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200774#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100775#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200776 int text_prop_count;
777 int text_prop_next = 0; // next text property to use
778 textprop_T *text_props = NULL;
779 int *text_prop_idxs = NULL;
780 int text_props_active = 0;
781 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100782 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200783 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100784 int text_prop_attr_comb = 0; // text_prop_attr combined with
785 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100786 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100787 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100788 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100789 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100790 int saved_search_attr = 0; // search_attr to be used when n_extra
791 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100792 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200793#endif
794#ifdef FEAT_SPELL
795 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000796 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200797# define SPWORDLEN 150
798 char_u nextline[SPWORDLEN * 2];// text with start of the next line
799 int nextlinecol = 0; // column where nextline[] starts
800 int nextline_idx = 0; // index in nextline[] where next line
801 // starts
802 int spell_attr = 0; // attributes desired by spelling
803 int word_end = 0; // last byte with same spell_attr
804 static linenr_T checked_lnum = 0; // line number for "checked_col"
805 static int checked_col = 0; // column in "checked_lnum" up to which
806 // there are no spell errors
807 static int cap_col = -1; // column to check for Cap word
808 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
809 int cur_checked_col = 0; // checked column for current line
810#endif
811 int extra_check = 0; // has extra highlighting
812 int multi_attr = 0; // attributes desired by multibyte
813 int mb_l = 1; // multi-byte byte length
814 int mb_c = 0; // decoded multi-byte character
815 int mb_utf8 = FALSE; // screen char is UTF-8 char
816 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200817#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200818 int change_start = MAXCOL; // first col of changed area
819 int change_end = -1; // last col of changed area
820#endif
821 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100822 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200823 int in_multispace = FALSE; // in multiple consecutive spaces
824 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200825#ifdef FEAT_LINEBREAK
826 int need_showbreak = FALSE; // overlong line, skipping first x
827 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100828 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200829#endif
830#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
831 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
832# define LINE_ATTR
833 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100834 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200835#endif
836#ifdef FEAT_SIGNS
837 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +0000838 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200839#endif
840#ifdef FEAT_ARABIC
841 int prev_c = 0; // previous Arabic character
842 int prev_c1 = 0; // first composing char for prev_c
843#endif
844#if defined(LINE_ATTR)
845 int did_line_attr = 0;
846#endif
847#ifdef FEAT_TERMINAL
848 int get_term_attr = FALSE;
849#endif
850#ifdef FEAT_SYN_HL
851 int cul_attr = 0; // set when 'cursorline' active
852
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200853 // margin columns for the screen line, needed for when 'cursorlineopt'
854 // contains "screenline"
855 int left_curline_col = 0;
856 int right_curline_col = 0;
857#endif
858
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200859#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
860 int feedback_col = 0;
861 int feedback_old_attr = -1;
862#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200863
864#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
865 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000866 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200867#endif
868#ifdef FEAT_CONCEAL
869 int syntax_flags = 0;
870 int syntax_seqnr = 0;
871 int prev_syntax_id = 0;
872 int conceal_attr = HL_ATTR(HLF_CONCEAL);
873 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200874 int did_wcol = FALSE;
875 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100876# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200877# define FIX_FOR_BOGUSCOLS \
878 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100879 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100880 wlv.vcol -= wlv.vcol_off; \
881 wlv.vcol_off = 0; \
882 wlv.col -= wlv.boguscols; \
883 old_boguscols = wlv.boguscols; \
884 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200885 }
886#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100887# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200888#endif
889
890 if (startrow > endrow) // past the end already!
891 return startrow;
892
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100893 CLEAR_FIELD(wlv);
894
895 wlv.lnum = lnum;
896 wlv.startrow = startrow;
897 wlv.row = startrow;
898 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200899
900 if (!number_only)
901 {
902 // To speed up the loop below, set extra_check when there is linebreak,
903 // trailing white space and/or syntax processing to be done.
904#ifdef FEAT_LINEBREAK
905 extra_check = wp->w_p_lbr;
906#endif
907#ifdef FEAT_SYN_HL
908 if (syntax_present(wp) && !wp->w_s->b_syn_error
909# ifdef SYN_TIME_LIMIT
910 && !wp->w_s->b_syn_slow
911# endif
912 )
913 {
914 // Prepare for syntax highlighting in this line. When there is an
915 // error, stop syntax highlighting.
916 save_did_emsg = did_emsg;
917 did_emsg = FALSE;
918 syntax_start(wp, lnum);
919 if (did_emsg)
920 wp->w_s->b_syn_error = TRUE;
921 else
922 {
923 did_emsg = save_did_emsg;
924#ifdef SYN_TIME_LIMIT
925 if (!wp->w_s->b_syn_slow)
926#endif
927 {
928 has_syntax = TRUE;
929 extra_check = TRUE;
930 }
931 }
932 }
933
934 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100935 wlv.color_cols = wp->w_p_cc_cols;
936 if (wlv.color_cols != NULL)
937 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200938#endif
939
940#ifdef FEAT_TERMINAL
941 if (term_show_buffer(wp->w_buffer))
942 {
943 extra_check = TRUE;
944 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100945 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200946 }
947#endif
948
949#ifdef FEAT_SPELL
950 if (wp->w_p_spell
951 && *wp->w_s->b_p_spl != NUL
952 && wp->w_s->b_langp.ga_len > 0
953 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
954 {
955 // Prepare for spell checking.
956 has_spell = TRUE;
957 extra_check = TRUE;
958
959 // Get the start of the next line, so that words that wrap to the
960 // next line are found too: "et<line-break>al.".
961 // Trick: skip a few chars for C/shell/Vim comments
962 nextline[SPWORDLEN] = NUL;
963 if (lnum < wp->w_buffer->b_ml.ml_line_count)
964 {
965 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
966 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
967 }
968
969 // When a word wrapped from the previous line the start of the
970 // current line is valid.
971 if (lnum == checked_lnum)
972 cur_checked_col = checked_col;
973 checked_lnum = 0;
974
975 // When there was a sentence end in the previous line may require a
976 // word starting with capital in this line. In line 1 always check
977 // the first word.
978 if (lnum != capcol_lnum)
979 cap_col = -1;
980 if (lnum == 1)
981 cap_col = 0;
982 capcol_lnum = 0;
983 }
984#endif
985
986 // handle Visual active in this window
987 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
988 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100989 pos_T *top, *bot;
990
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200991 if (LTOREQ_POS(curwin->w_cursor, VIsual))
992 {
993 // Visual is after curwin->w_cursor
994 top = &curwin->w_cursor;
995 bot = &VIsual;
996 }
997 else
998 {
999 // Visual is before curwin->w_cursor
1000 top = &VIsual;
1001 bot = &curwin->w_cursor;
1002 }
1003 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1004 if (VIsual_mode == Ctrl_V)
1005 {
1006 // block mode
1007 if (lnum_in_visual_area)
1008 {
1009 fromcol = wp->w_old_cursor_fcol;
1010 tocol = wp->w_old_cursor_lcol;
1011 }
1012 }
1013 else
1014 {
1015 // non-block mode
1016 if (lnum > top->lnum && lnum <= bot->lnum)
1017 fromcol = 0;
1018 else if (lnum == top->lnum)
1019 {
1020 if (VIsual_mode == 'V') // linewise
1021 fromcol = 0;
1022 else
1023 {
1024 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
1025 if (gchar_pos(top) == NUL)
1026 tocol = fromcol + 1;
1027 }
1028 }
1029 if (VIsual_mode != 'V' && lnum == bot->lnum)
1030 {
1031 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1032 {
1033 fromcol = -10;
1034 tocol = MAXCOL;
1035 }
1036 else if (bot->col == MAXCOL)
1037 tocol = MAXCOL;
1038 else
1039 {
1040 pos = *bot;
1041 if (*p_sel == 'e')
1042 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
1043 else
1044 {
1045 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
1046 ++tocol;
1047 }
1048 }
1049 }
1050 }
1051
1052 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001053 if (!highlight_match && lnum == curwin->w_cursor.lnum
1054 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001055#ifdef FEAT_GUI
1056 && !gui.in_use
1057#endif
1058 )
1059 noinvcur = TRUE;
1060
1061 // if inverting in this line set area_highlighting
1062 if (fromcol >= 0)
1063 {
1064 area_highlighting = TRUE;
1065 vi_attr = HL_ATTR(HLF_V);
1066#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1067 if ((clip_star.available && !clip_star.owned
1068 && clip_isautosel_star())
1069 || (clip_plus.available && !clip_plus.owned
1070 && clip_isautosel_plus()))
1071 vi_attr = HL_ATTR(HLF_VNC);
1072#endif
1073 }
1074 }
1075
1076 // handle 'incsearch' and ":s///c" highlighting
1077 else if (highlight_match
1078 && wp == curwin
1079 && lnum >= curwin->w_cursor.lnum
1080 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1081 {
1082 if (lnum == curwin->w_cursor.lnum)
1083 getvcol(curwin, &(curwin->w_cursor),
1084 (colnr_T *)&fromcol, NULL, NULL);
1085 else
1086 fromcol = 0;
1087 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1088 {
1089 pos.lnum = lnum;
1090 pos.col = search_match_endcol;
1091 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
1092 }
1093 else
1094 tocol = MAXCOL;
1095 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +01001096 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001097 tocol = fromcol + 1;
1098 area_highlighting = TRUE;
1099 vi_attr = HL_ATTR(HLF_I);
1100 }
1101 }
1102
1103#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001104 wlv.filler_lines = diff_check(wp, lnum);
1105 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001107 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001108 {
1109 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001110 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001112 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001114 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115 }
1116 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001117 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001118 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 area_highlighting = TRUE;
1120 }
1121 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001122 wlv.filler_lines = wp->w_topfill;
1123 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124#endif
1125
1126#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001127 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001128 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001129 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130#endif
1131
1132#ifdef LINE_ATTR
1133# ifdef FEAT_SIGNS
1134 // If this line has a sign with line highlighting set line_attr.
1135 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001136 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137# endif
1138# if defined(FEAT_QUICKFIX)
1139 // Highlight the current line in the quickfix window.
1140 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1141 line_attr = HL_ATTR(HLF_QFL);
1142# endif
1143 if (line_attr != 0)
1144 area_highlighting = TRUE;
1145#endif
1146
1147 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1148 ptr = line;
1149
1150#ifdef FEAT_SPELL
1151 if (has_spell && !number_only)
1152 {
1153 // For checking first word with a capital skip white space.
1154 if (cap_col == 0)
1155 cap_col = getwhitecols(line);
1156
1157 // To be able to spell-check over line boundaries copy the end of the
1158 // current line into nextline[]. Above the start of the next line was
1159 // copied to nextline[SPWORDLEN].
1160 if (nextline[SPWORDLEN] == NUL)
1161 {
1162 // No next line or it is empty.
1163 nextlinecol = MAXCOL;
1164 nextline_idx = 0;
1165 }
1166 else
1167 {
1168 v = (long)STRLEN(line);
1169 if (v < SPWORDLEN)
1170 {
1171 // Short line, use it completely and append the start of the
1172 // next line.
1173 nextlinecol = 0;
1174 mch_memmove(nextline, line, (size_t)v);
1175 STRMOVE(nextline + v, nextline + SPWORDLEN);
1176 nextline_idx = v + 1;
1177 }
1178 else
1179 {
1180 // Long line, use only the last SPWORDLEN bytes.
1181 nextlinecol = v - SPWORDLEN;
1182 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1183 nextline_idx = SPWORDLEN + 1;
1184 }
1185 }
1186 }
1187#endif
1188
1189 if (wp->w_p_list)
1190 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001191 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001192 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001193 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001194 || wp->w_lcs_chars.trail
1195 || wp->w_lcs_chars.lead
1196 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001198
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001200 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201 {
1202 trailcol = (colnr_T)STRLEN(ptr);
1203 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1204 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001205 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001207 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001208 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001209 {
1210 leadcol = 0;
1211 while (VIM_ISWHITE(ptr[leadcol]))
1212 ++leadcol;
1213 if (ptr[leadcol] == NUL)
1214 // in a line full of spaces all of them are treated as trailing
1215 leadcol = (colnr_T)0;
1216 else
1217 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001218 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001219 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220 }
1221
Bram Moolenaard7657e92022-09-20 18:59:30 +01001222 wlv.wcr_attr = get_wcr_attr(wp);
1223 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001225 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 area_highlighting = TRUE;
1227 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001228
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001229#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001231 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232#endif
1233
1234 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1235 // first character to be displayed.
1236 if (wp->w_p_wrap)
1237 v = wp->w_skipcol;
1238 else
1239 v = wp->w_leftcol;
1240 if (v > 0 && !number_only)
1241 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001242 char_u *prev_ptr = ptr;
1243 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001244 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001246 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001247 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001249 charsize = win_lbr_chartabsize(&cts, NULL);
1250 cts.cts_vcol += charsize;
1251 prev_ptr = cts.cts_ptr;
1252 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001254 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001255 ptr = cts.cts_ptr;
1256 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257
1258 // When:
1259 // - 'cuc' is set, or
1260 // - 'colorcolumn' is set, or
1261 // - 'virtualedit' is set, or
1262 // - the visual mode is active,
1263 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001264 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001266 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267#endif
1268 virtual_active() ||
1269 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001270 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271
1272 // Handle a character that's not completely on the screen: Put ptr at
1273 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001274 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001276 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 ptr = prev_ptr;
1278 // If the character fits on the screen, don't need to skip it.
1279 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001280 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1281 && wlv.col == 0)
1282 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283 }
1284
1285 // Adjust for when the inverted text is before the screen,
1286 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001287 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001289 else if (fromcol >= 0 && fromcol < wlv.vcol)
1290 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291
1292#ifdef FEAT_LINEBREAK
1293 // When w_skipcol is non-zero, first line needs 'showbreak'
1294 if (wp->w_p_wrap)
1295 need_showbreak = TRUE;
1296#endif
1297#ifdef FEAT_SPELL
1298 // When spell checking a word we need to figure out the start of the
1299 // word and if it's badly spelled or not.
1300 if (has_spell)
1301 {
1302 int len;
1303 colnr_T linecol = (colnr_T)(ptr - line);
1304 hlf_T spell_hlf = HLF_COUNT;
1305
1306 pos = wp->w_cursor;
1307 wp->w_cursor.lnum = lnum;
1308 wp->w_cursor.col = linecol;
1309 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1310
1311 // spell_move_to() may call ml_get() and make "line" invalid
1312 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1313 ptr = line + linecol;
1314
1315 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1316 {
1317 // no bad word found at line start, don't check until end of a
1318 // word
1319 spell_hlf = HLF_COUNT;
1320 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1321 }
1322 else
1323 {
1324 // bad word found, use attributes until end of word
1325 word_end = wp->w_cursor.col + len + 1;
1326
1327 // Turn index into actual attributes.
1328 if (spell_hlf != HLF_COUNT)
1329 spell_attr = highlight_attr[spell_hlf];
1330 }
1331 wp->w_cursor = pos;
1332
1333# ifdef FEAT_SYN_HL
1334 // Need to restart syntax highlighting for this line.
1335 if (has_syntax)
1336 syntax_start(wp, lnum);
1337# endif
1338 }
1339#endif
1340 }
1341
1342 // Correct highlighting for cursor that can't be disabled.
1343 // Avoids having to check this for each character.
1344 if (fromcol >= 0)
1345 {
1346 if (noinvcur)
1347 {
1348 if ((colnr_T)fromcol == wp->w_virtcol)
1349 {
1350 // highlighting starts at cursor, let it start just after the
1351 // cursor
1352 fromcol_prev = fromcol;
1353 fromcol = -1;
1354 }
1355 else if ((colnr_T)fromcol < wp->w_virtcol)
1356 // restart highlighting after the cursor
1357 fromcol_prev = wp->w_virtcol;
1358 }
1359 if (fromcol >= tocol)
1360 fromcol = -1;
1361 }
1362
1363#ifdef FEAT_SEARCH_EXTRA
1364 if (!number_only)
1365 {
1366 v = (long)(ptr - line);
1367 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1368 &line, &screen_search_hl,
1369 &search_attr);
1370 ptr = line + v; // "line" may have been updated
1371 }
1372#endif
1373
1374#ifdef FEAT_SYN_HL
1375 // Cursor line highlighting for 'cursorline' in the current window.
1376 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1377 {
1378 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001379 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 if (!(wp == curwin && VIsual_active)
1381 && wp->w_p_culopt_flags != CULOPT_NBR)
1382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001383 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1385
1386 // Only set line_attr here when "screenline" is not present in
1387 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001388 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 {
1390 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001391# ifdef FEAT_SIGNS
1392 // Combine the 'cursorline' and sign highlighting, depending on
1393 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001394 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001395 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001396 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001397 line_attr = hl_combine_attr(cul_attr, line_attr);
1398 else
1399 line_attr = hl_combine_attr(line_attr, cul_attr);
1400 }
1401 else
1402# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001403# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001404 // let the line attribute overrule 'cursorline', otherwise
1405 // it disappears when both have background set;
1406 // 'cursorline' can use underline or bold to make it show
1407 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001408# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001409 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001410# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 }
1412 else
1413 {
1414 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1416 }
1417 area_highlighting = TRUE;
1418 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 }
1420#endif
1421
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001422#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 {
1424 char_u *prop_start;
1425
1426 text_prop_count = get_text_props(wp->w_buffer, lnum,
1427 &prop_start, FALSE);
1428 if (text_prop_count > 0)
1429 {
1430 // Make a copy of the properties, so that they are properly
1431 // aligned.
1432 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1433 if (text_props != NULL)
1434 mch_memmove(text_props, prop_start,
1435 text_prop_count * sizeof(textprop_T));
1436
1437 // Allocate an array for the indexes.
1438 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001439 if (text_prop_idxs == NULL)
1440 VIM_CLEAR(text_props);
1441
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 area_highlighting = TRUE;
1443 extra_check = TRUE;
1444 }
1445 }
1446#endif
1447
Bram Moolenaar1306b362022-08-06 15:59:06 +01001448 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449
1450 // Repeat for the whole displayed line.
1451 for (;;)
1452 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001453 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001455 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456#endif
1457#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001458 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001460
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001462 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001464#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001465 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001466 {
1467 cul_attr = 0;
1468 line_attr = line_attr_save;
1469 }
1470#endif
1471
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001473 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001475 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 if (cmdwin_type != 0 && wp == curwin)
1477 {
1478 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001479 wlv.n_extra = 1;
1480 wlv.c_extra = cmdwin_type;
1481 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001482 wlv.char_attr =
1483 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 }
1485 }
1486#endif
1487
1488#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001489 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 {
1491 int fdc = compute_foldcolumn(wp, 0);
1492
Bram Moolenaar1306b362022-08-06 15:59:06 +01001493 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 if (fdc > 0)
1495 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001496 // Draw the 'foldcolumn'. Allocate a buffer, "wlv.extra"
1497 // may already be in use.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001499 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500 if (p_extra_free != NULL)
1501 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001502 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001503 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001504 p_extra_free[wlv.n_extra] = NUL;
1505 wlv.p_extra = p_extra_free;
1506 wlv.c_extra = NUL;
1507 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001508 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001509 wlv.char_attr =
Bram Moolenaard7657e92022-09-20 18:59:30 +01001510 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_CLF));
Bram Moolenaare413ea02021-11-24 16:20:13 +00001511 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001512 wlv.char_attr =
Bram Moolenaard7657e92022-09-20 18:59:30 +01001513 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001514 }
1515 }
1516 }
1517#endif
1518
1519#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001520 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001521 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001522 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001523 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001525 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526 }
1527#endif
1528
Bram Moolenaar1306b362022-08-06 15:59:06 +01001529 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001531 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001532 wlv.draw_state = WL_NR;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001533 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 }
1535
1536#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001537 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1538 && wlv.n_extra == 0
1539 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001541 wlv.draw_state = WL_BRI;
1542 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1543 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001545 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546
1547 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001548 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001550 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001552 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001554 && wlv.filler_lines == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001556# ifdef FEAT_PROP_POPUP
1557 && !dont_use_showbreak
1558# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559 )
1560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001561 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001563 if (wlv.diff_hlf != (hlf_T)0)
1564 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001566 wlv.p_extra = NULL;
1567 wlv.c_extra = ' ';
1568 wlv.c_final = NUL;
1569 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001571 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001572 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001573 wlv.n_extra -= win_col_off2(wp);
1574 if (wlv.n_extra < 0)
1575 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001576 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001577 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001578 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 // Correct end of highlighted area for 'breakindent',
1580 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001581 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001582 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 }
1584 }
1585#endif
1586
1587#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001588 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001590 char_u *sbr;
1591
Bram Moolenaar1306b362022-08-06 15:59:06 +01001592 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001594 if (wlv.filler_todo > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 {
1596 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001597 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001599 wlv.c_extra = '-';
1600 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 }
1602 else
1603 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001604 wlv.c_extra = wp->w_fill_chars.diff;
1605 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 }
1607# ifdef FEAT_RIGHTLEFT
1608 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001609 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 else
1611# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001612 wlv.n_extra = wp->w_width - wlv.col;
1613 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 }
1615# endif
1616# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001617 sbr = get_showbreak_value(wp);
1618 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 {
1620 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001621 wlv.p_extra = sbr;
1622 wlv.c_extra = NUL;
1623 wlv.c_final = NUL;
1624 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001625 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1626 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001627 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 // Correct end of highlighted area for 'showbreak',
1629 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001630 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001631 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001633 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1634 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635# ifdef FEAT_SYN_HL
1636 // combine 'showbreak' with 'cursorline'
1637 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001638 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1639 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640# endif
1641 }
1642# endif
1643 }
1644#endif
1645
Bram Moolenaar1306b362022-08-06 15:59:06 +01001646 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001648 wlv.draw_state = WL_LINE;
1649 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 {
1651 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001652 wlv.n_extra = wlv.saved_n_extra;
1653 wlv.c_extra = wlv.saved_c_extra;
1654 wlv.c_final = wlv.saved_c_final;
1655 wlv.p_extra = wlv.saved_p_extra;
1656 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657 }
1658 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001659 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660 }
1661 }
1662#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001663 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001664 && wlv.vcol >= left_curline_col
1665 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001667 cul_attr = HL_ATTR(HLF_CUL);
1668 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 }
1670#endif
1671
1672 // When still displaying '$' of change command, stop at cursor.
1673 // When only displaying the (relative) line number and that's done,
1674 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001675 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001676 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001677 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001679 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680#endif
1681 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001683 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1684 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 // Pretend we have finished updating the window. Except when
1686 // 'cursorcolumn' is set.
1687#ifdef FEAT_SYN_HL
1688 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001689 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 else
1691#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001692 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 break;
1694 }
1695
Bram Moolenaar1306b362022-08-06 15:59:06 +01001696 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697 {
1698 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001699 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001700 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701 && (*mb_ptr2cells)(ptr) > 1)
1702 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001703 && vcol_prev < wlv.vcol // not at margin
1704 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 area_attr = vi_attr; // start highlighting
1706 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001707 && (wlv.vcol == tocol
1708 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 area_attr = 0; // stop highlighting
1710
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001711#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 if (text_props != NULL)
1713 {
1714 int pi;
1715 int bcol = (int)(ptr - line);
1716
Bram Moolenaar1306b362022-08-06 15:59:06 +01001717 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001718# ifdef FEAT_LINEBREAK
1719 && !in_linebreak
1720# endif
1721 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 --bcol; // still working on the previous char, e.g. Tab
1723
1724 // Check if any active property ends.
1725 for (pi = 0; pi < text_props_active; ++pi)
1726 {
1727 int tpi = text_prop_idxs[pi];
1728
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001729 if (text_props[tpi].tp_col != MAXCOL
1730 && bcol >= text_props[tpi].tp_col - 1
1731 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
1733 if (pi + 1 < text_props_active)
1734 mch_memmove(text_prop_idxs + pi,
1735 text_prop_idxs + pi + 1,
1736 sizeof(int)
1737 * (text_props_active - (pi + 1)));
1738 --text_props_active;
1739 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001740# ifdef FEAT_LINEBREAK
1741 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001742 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001743 syntax_attr = 0;
1744# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 }
1746 }
1747
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001748# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001749 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001750 // not on the next char yet, don't start another prop
1751 --bcol;
1752# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001754 // With 'nowrap' and not in the first screen line only "below"
1755 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001756 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001757 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001758 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001759 && (wp->w_p_wrap
1760 || wlv.row == startrow
1761 || (text_props[text_prop_next].tp_flags
1762 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001763 || (bcol == 0 &&
1764 (text_props[text_prop_next].tp_flags
1765 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001766 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001767 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001768 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001769 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1770 {
1771 // first display the '$' after the line
1772 text_prop_follows = TRUE;
1773 break;
1774 }
1775 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001776 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001777 + text_props[text_prop_next].tp_len)
1778 text_prop_idxs[text_props_active++] = text_prop_next;
1779 ++text_prop_next;
1780 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001782 if (wlv.n_extra == 0 || !extra_for_textprop)
1783 {
1784 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001785 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001786 text_prop_flags = 0;
1787 text_prop_type = NULL;
1788 text_prop_id = 0;
1789 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001790 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001792 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001793 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001794 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001795
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796 // Sort the properties on priority and/or starting last.
1797 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001798 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001799 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001800 sort_text_props(wp->w_buffer, text_props,
1801 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802
1803 for (pi = 0; pi < text_props_active; ++pi)
1804 {
1805 int tpi = text_prop_idxs[pi];
1806 proptype_T *pt = text_prop_type_by_id(
1807 wp->w_buffer, text_props[tpi].tp_type);
1808
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001809 if (pt != NULL && (pt->pt_hl_id > 0
1810 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001811 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001813 if (pt->pt_hl_id > 0)
1814 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 text_prop_type = pt;
1816 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001817 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001818 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001819 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001820 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001821 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 }
1823 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001824 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001825 && -text_prop_id
1826 <= wp->w_buffer->b_textprop_text.ga_len)
1827 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001828 textprop_T *tp = &text_props[used_tpi];
1829 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001830 ->b_textprop_text.ga_data)[
1831 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001832 int above = (tp->tp_flags
1833 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001834
1835 // reset the ID in the copy to avoid it being used
1836 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001837 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001838
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001839 if (p != NULL)
1840 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001841 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001842 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001843 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001844 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001845 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1846 int padding = tp->tp_col == MAXCOL
1847 && tp->tp_len > 1
1848 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001849
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001850 // Insert virtual text before the current
1851 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001852 wlv.p_extra = p;
1853 wlv.c_extra = NUL;
1854 wlv.c_final = NUL;
1855 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001856 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001857 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001858 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001859 // restore search_attr and area_attr when n_extra
1860 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001861 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001862 saved_area_attr = area_attr;
1863 search_attr = 0;
1864 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001865 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001866 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001867 if (*ptr == NUL)
1868 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001869 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001870#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001871 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001872 {
1873 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001874 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001875 need_showbreak = FALSE;
1876 dont_use_showbreak = TRUE;
1877 }
1878#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001879 if ((right || above || below || !wrap
1880 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001881 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001882 char_u *prev_p_extra = wlv.p_extra;
1883 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001884
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001885 // Take care of padding, right-align and
1886 // truncation.
1887 // Shared with win_lbr_chartabsize(), must do
1888 // exactly the same.
1889 start_line = text_prop_position(wp, tp,
1890 wlv.col,
1891 &wlv.n_extra, &wlv.p_extra,
1892 &n_attr, &n_attr_skip);
1893 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001894 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001895 // wlv.p_extra was allocated
1896 vim_free(p_extra_free2);
1897 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001898 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001899
Bram Moolenaara4abe512022-09-15 19:44:09 +01001900 if (lcs_eol_one < 0 && wlv.col
1901 + wlv.n_extra - 2 > wp->w_width)
1902 // don't bail out at end of line
1903 lcs_eol_one = 0;
1904
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001905 // When 'wrap' is off then for "below" we need
1906 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001907 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001908 {
1909 draw_screen_line(wp, &wlv);
1910
1911 // When line got too long for screen break
1912 // here.
1913 if (wlv.row == endrow)
1914 {
1915 ++wlv.row;
1916 break;
1917 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001918 win_line_start(wp, &wlv, TRUE);
1919 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001920 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001921 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001922 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001923
1924 // If another text prop follows the condition below at
1925 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001926 // If this is an "above" text prop and 'nowrap' the we
1927 // must wrap anyway.
1928 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001929 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001930 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001932 else if (text_prop_next < text_prop_count
1933 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001934 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1935 || (!wp->w_p_wrap
1936 && wlv.col == wp->w_width - 1
1937 && (text_props[text_prop_next].tp_flags
1938 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001939 // When at last-but-one character and a text property
1940 // follows after it, we may need to flush the line after
1941 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001942 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001943 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 }
1945#endif
1946
Bram Moolenaare38fc862022-08-11 17:24:50 +01001947#ifdef FEAT_SEARCH_EXTRA
1948 if (wlv.n_extra == 0)
1949 {
1950 // Check for start/end of 'hlsearch' and other matches.
1951 // After end, check for start/end of next match.
1952 // When another match, have to check for start again.
1953 v = (long)(ptr - line);
1954 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1955 &screen_search_hl, &has_match_conc,
1956 &match_conc, did_line_attr, lcs_eol_one,
1957 &on_last_col);
1958 ptr = line + v; // "line" may have been changed
1959 prev_ptr = ptr;
1960
1961 // Do not allow a conceal over EOL otherwise EOL will be missed
1962 // and bad things happen.
1963 if (*ptr == NUL)
1964 has_match_conc = 0;
1965 }
1966#endif
1967
1968#ifdef FEAT_DIFF
1969 if (wlv.diff_hlf != (hlf_T)0)
1970 {
1971 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1972 && wlv.n_extra == 0)
1973 wlv.diff_hlf = HLF_TXD; // changed text
1974 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1975 && wlv.n_extra == 0)
1976 wlv.diff_hlf = HLF_CHD; // changed line
1977 line_attr = HL_ATTR(wlv.diff_hlf);
1978 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1979 && wp->w_p_culopt_flags != CULOPT_NBR
1980 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1981 && wlv.vcol <= right_curline_col)))
1982 line_attr = hl_combine_attr(
1983 line_attr, HL_ATTR(HLF_CUL));
1984 }
1985#endif
1986
Bram Moolenaara74fda62019-10-19 17:38:03 +02001987#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001988 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001989 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001990 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001991# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001992 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001993 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001994# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001995 // Get syntax attribute.
1996 if (has_syntax)
1997 {
1998 // Get the syntax attribute for the character. If there
1999 // is an error, disable syntax highlighting.
2000 save_did_emsg = did_emsg;
2001 did_emsg = FALSE;
2002
2003 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002004 if (v == prev_syntax_col)
2005 // at same column again
2006 syntax_attr = prev_syntax_attr;
2007 else
2008 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002009# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002010 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002011# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002012 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002013# ifdef FEAT_SPELL
2014 has_spell ? &can_spell :
2015# endif
2016 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002017 prev_syntax_col = v;
2018 prev_syntax_attr = syntax_attr;
2019 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002020
Bram Moolenaar34390282019-10-16 14:38:26 +02002021 if (did_emsg)
2022 {
2023 wp->w_s->b_syn_error = TRUE;
2024 has_syntax = FALSE;
2025 syntax_attr = 0;
2026 }
2027 else
2028 did_emsg = save_did_emsg;
2029# ifdef SYN_TIME_LIMIT
2030 if (wp->w_s->b_syn_slow)
2031 has_syntax = FALSE;
2032# endif
2033
2034 // Need to get the line again, a multi-line regexp may
2035 // have made it invalid.
2036 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2037 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002038 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002039# ifdef FEAT_CONCEAL
2040 // no concealing past the end of the line, it interferes
2041 // with line highlighting
2042 if (*ptr == NUL)
2043 syntax_flags = 0;
2044 else
2045 syntax_flags = get_syntax_info(&syntax_seqnr);
2046# endif
2047 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002048 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002049# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002050 // Combine text property highlight into syntax highlight.
2051 if (text_prop_type != NULL)
2052 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002053 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002054 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2055 else
2056 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002057 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002058 }
2059# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002060#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002061
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002062 // Decide which of the highlight attributes to use.
2063 attr_pri = TRUE;
2064#ifdef LINE_ATTR
2065 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002066 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002067 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002068 if (!highlight_match)
2069 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002071# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002072 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002073# endif
2074 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002076 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002077 wlv.char_attr = hl_combine_attr(line_attr, search_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 (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002083 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2084 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085 {
2086 // Use line_attr when not in the Visual or 'incsearch' area
2087 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002088# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002089 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002090# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002091 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002092# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 attr_pri = FALSE;
2094 }
2095#else
2096 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002097 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002099 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100#endif
2101 else
2102 {
2103 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002104#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002105 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002106#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002107 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002108#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002109 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002110#ifdef FEAT_PROP_POPUP
2111 // override with text property highlight when "override" is TRUE
2112 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002113 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002114#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002115 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002116
2117 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002118 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002119 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002120 if (wlv.char_attr == 0)
2121 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002122 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002123 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002124 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125
2126 // Get the next character to put on the screen.
2127
2128 // The "p_extra" points to the extra stuff that is inserted to
2129 // represent special characters (non-printable stuff) and other
2130 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002131 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2133 // "p_extra[n_extra]".
2134 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002135 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002136 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002139 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2140 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002141 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2142 if (enc_utf8 && utf_char2len(c) > 1)
2143 {
2144 mb_utf8 = TRUE;
2145 u8cc[0] = 0;
2146 c = 0xc0;
2147 }
2148 else
2149 mb_utf8 = FALSE;
2150 }
2151 else
2152 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002154 if (has_mbyte)
2155 {
2156 mb_c = c;
2157 if (enc_utf8)
2158 {
2159 // If the UTF-8 character is more than one byte:
2160 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002161 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002163 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164 mb_l = 1;
2165 else if (mb_l > 1)
2166 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002167 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002168 mb_utf8 = TRUE;
2169 c = 0xc0;
2170 }
2171 }
2172 else
2173 {
2174 // if this is a DBCS character, put it in "mb_c"
2175 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002176 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 mb_l = 1;
2178 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002179 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180 }
2181 if (mb_l == 0) // at the NUL at end-of-line
2182 mb_l = 1;
2183
2184 // If a double-width char doesn't fit display a '>' in the
2185 // last column.
2186 if ((
2187# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002188 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002190 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002191 && (*mb_char2cells)(mb_c) == 2)
2192 {
2193 c = '>';
2194 mb_c = c;
2195 mb_l = 1;
2196 mb_utf8 = FALSE;
2197 multi_attr = HL_ATTR(HLF_AT);
2198#ifdef FEAT_SYN_HL
2199 if (cul_attr)
2200 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2201#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002202 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002203
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 // put the pointer back to output the double-width
2205 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002206 ++wlv.n_extra;
2207 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 }
2209 else
2210 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002211 wlv.n_extra -= mb_l - 1;
2212 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002213 }
2214 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002217 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002218#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002219 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002220 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002221 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002222 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002223 if (search_attr == 0)
2224 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002225 if (area_attr == 0 && *ptr != NUL)
2226 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002227 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002228#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002229 }
2230 else
2231 {
2232#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002233 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002234#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002235 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 // Get a character from the line itself.
2238 c = *ptr;
2239#ifdef FEAT_LINEBREAK
2240 c0 = *ptr;
2241#endif
2242 if (has_mbyte)
2243 {
2244 mb_c = c;
2245 if (enc_utf8)
2246 {
2247 // If the UTF-8 character is more than one byte: Decode it
2248 // into "mb_c".
2249 mb_l = utfc_ptr2len(ptr);
2250 mb_utf8 = FALSE;
2251 if (mb_l > 1)
2252 {
2253 mb_c = utfc_ptr2char(ptr, u8cc);
2254 // Overlong encoded ASCII or ASCII with composing char
2255 // is displayed normally, except a NUL.
2256 if (mb_c < 0x80)
2257 {
2258 c = mb_c;
2259#ifdef FEAT_LINEBREAK
2260 c0 = mb_c;
2261#endif
2262 }
2263 mb_utf8 = TRUE;
2264
2265 // At start of the line we can have a composing char.
2266 // Draw it as a space with a composing char.
2267 if (utf_iscomposing(mb_c))
2268 {
2269 int i;
2270
2271 for (i = Screen_mco - 1; i > 0; --i)
2272 u8cc[i] = u8cc[i - 1];
2273 u8cc[0] = mb_c;
2274 mb_c = ' ';
2275 }
2276 }
2277
2278 if ((mb_l == 1 && c >= 0x80)
2279 || (mb_l >= 1 && mb_c == 0)
2280 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2281 {
2282 // Illegal UTF-8 byte: display as <xx>.
2283 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002284 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002285# ifdef FEAT_RIGHTLEFT
2286 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002287 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002289 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 c = *wlv.p_extra;
2291 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002293 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2294 wlv.c_extra = NUL;
2295 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296 if (area_attr == 0 && search_attr == 0)
2297 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002298 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002299 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002300 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002301 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002302 }
2303 }
2304 else if (mb_l == 0) // at the NUL at end-of-line
2305 mb_l = 1;
2306#ifdef FEAT_ARABIC
2307 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2308 {
2309 // Do Arabic shaping.
2310 int pc, pc1, nc;
2311 int pcc[MAX_MCO];
2312
2313 // The idea of what is the previous and next
2314 // character depends on 'rightleft'.
2315 if (wp->w_p_rl)
2316 {
2317 pc = prev_c;
2318 pc1 = prev_c1;
2319 nc = utf_ptr2char(ptr + mb_l);
2320 prev_c1 = u8cc[0];
2321 }
2322 else
2323 {
2324 pc = utfc_ptr2char(ptr + mb_l, pcc);
2325 nc = prev_c;
2326 pc1 = pcc[0];
2327 }
2328 prev_c = mb_c;
2329
2330 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2331 }
2332 else
2333 prev_c = mb_c;
2334#endif
2335 }
2336 else // enc_dbcs
2337 {
2338 mb_l = MB_BYTE2LEN(c);
2339 if (mb_l == 0) // at the NUL at end-of-line
2340 mb_l = 1;
2341 else if (mb_l > 1)
2342 {
2343 // We assume a second byte below 32 is illegal.
2344 // Hopefully this is OK for all double-byte encodings!
2345 if (ptr[1] >= 32)
2346 mb_c = (c << 8) + ptr[1];
2347 else
2348 {
2349 if (ptr[1] == NUL)
2350 {
2351 // head byte at end of line
2352 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002353 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354 }
2355 else
2356 {
2357 // illegal tail byte
2358 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002359 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002361 wlv.p_extra = wlv.extra;
2362 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002363 wlv.c_extra = NUL;
2364 wlv.c_final = NUL;
2365 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366 if (area_attr == 0 && search_attr == 0)
2367 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002369 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002370 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002371 // save current attr
2372 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 }
2374 mb_c = c;
2375 }
2376 }
2377 }
2378 // If a double-width char doesn't fit display a '>' in the
2379 // last column; the character is displayed at the start of the
2380 // next line.
2381 if ((
2382# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002383 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002385 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386 && (*mb_char2cells)(mb_c) == 2)
2387 {
2388 c = '>';
2389 mb_c = c;
2390 mb_utf8 = FALSE;
2391 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002392 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 // Put pointer back so that the character will be
2394 // displayed at the start of the next line.
2395 --ptr;
2396#ifdef FEAT_CONCEAL
2397 did_decrement_ptr = TRUE;
2398#endif
2399 }
2400 else if (*ptr != NUL)
2401 ptr += mb_l - 1;
2402
2403 // If a double-width char doesn't fit at the left side display
2404 // a '<' in the first column. Don't do this for unprintable
2405 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002406 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002408 wlv.n_extra = 1;
2409 wlv.c_extra = MB_FILLER_CHAR;
2410 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002411 c = ' ';
2412 if (area_attr == 0 && search_attr == 0)
2413 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002414 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002415 extra_attr = hl_combine_attr(
2416 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002418 }
2419 mb_c = c;
2420 mb_utf8 = FALSE;
2421 mb_l = 1;
2422 }
2423
2424 }
2425 ++ptr;
2426
2427 if (extra_check)
2428 {
2429#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430 // Check spelling (unless at the end of the line).
2431 // Only do this when there is no syntax highlighting, the
2432 // @Spell cluster is not used or the current syntax item
2433 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002434 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435 if (has_spell && v >= word_end && v > cur_checked_col)
2436 {
2437 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002438 // do not calculate cap_col at the end of the line or when
2439 // only white space is following
2440 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441# ifdef FEAT_SYN_HL
2442 !has_syntax ||
2443# endif
2444 can_spell))
2445 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002446 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447 int len;
2448 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002449
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002452
2453 // Use nextline[] if possible, it has the start of the
2454 // next line concatenated.
2455 if ((prev_ptr - line) - nextlinecol >= 0)
2456 p = nextline + (prev_ptr - line) - nextlinecol;
2457 else
2458 p = prev_ptr;
2459 cap_col -= (int)(prev_ptr - line);
2460 len = spell_check(wp, p, &spell_hlf, &cap_col,
2461 nochange);
2462 word_end = v + len;
2463
2464 // In Insert mode only highlight a word that
2465 // doesn't touch the cursor.
2466 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002467 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002468 && wp->w_cursor.lnum == lnum
2469 && wp->w_cursor.col >=
2470 (colnr_T)(prev_ptr - line)
2471 && wp->w_cursor.col < (colnr_T)word_end)
2472 {
2473 spell_hlf = HLF_COUNT;
2474 spell_redraw_lnum = lnum;
2475 }
2476
2477 if (spell_hlf == HLF_COUNT && p != prev_ptr
2478 && (p - nextline) + len > nextline_idx)
2479 {
2480 // Remember that the good word continues at the
2481 // start of the next line.
2482 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002483 checked_col = (int)((p - nextline)
2484 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 }
2486
2487 // Turn index into actual attributes.
2488 if (spell_hlf != HLF_COUNT)
2489 spell_attr = highlight_attr[spell_hlf];
2490
2491 if (cap_col > 0)
2492 {
2493 if (p != prev_ptr
2494 && (p - nextline) + cap_col >= nextline_idx)
2495 {
2496 // Remember that the word in the next line
2497 // must start with a capital.
2498 capcol_lnum = lnum + 1;
2499 cap_col = (int)((p - nextline) + cap_col
2500 - nextline_idx);
2501 }
2502 else
2503 // Compute the actual column.
2504 cap_col += (int)(prev_ptr - line);
2505 }
2506 }
2507 }
2508 if (spell_attr != 0)
2509 {
2510 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002511 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2512 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002514 wlv.char_attr = hl_combine_attr(spell_attr,
2515 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002516 }
2517#endif
2518#ifdef FEAT_LINEBREAK
2519 // Found last space before word: check for line break.
2520 if (wp->w_p_lbr && c0 == c
2521 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2522 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002523 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2524 : 0;
2525 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002526 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002527
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002528 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002529# ifdef FEAT_PROP_POPUP
2530 // do not want virtual text counted here
2531 cts.cts_has_prop_with_text = FALSE;
2532# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002533 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002534 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002535
2536 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002537 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002538 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002539 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002540 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2541 if (wlv.n_extra < 0)
2542 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002543 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002544 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002545 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002546 // line break, but for TABs the highlighting should
2547 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002548 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002549
Bram Moolenaar1306b362022-08-06 15:59:06 +01002550 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002552 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002553 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 wp->w_buffer->b_p_vts_array) - 1;
2555# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002556 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002557 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558# endif
2559
Bram Moolenaar1306b362022-08-06 15:59:06 +01002560 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2561 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002562# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002564 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002565# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 if (VIM_ISWHITE(c))
2567 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002568# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 if (c == TAB)
2570 // See "Tab alignment" below.
2571 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002572# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 if (!wp->w_p_list)
2574 c = ' ';
2575 }
2576 }
2577#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002578 in_multispace = c == ' '
2579 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2580 if (!in_multispace)
2581 multispace_pos = 0;
2582
Bram Moolenaareed9d462021-02-15 20:38:25 +01002583 // 'list': Change char 160 to 'nbsp' and space to 'space'
2584 // setting in 'listchars'. But not when the character is
2585 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 if (wp->w_p_list
2587 && ((((c == 160 && mb_l == 1)
2588 || (mb_utf8
2589 && ((mb_c == 160 && mb_l == 2)
2590 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002591 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 || (c == ' '
2593 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002594 && (wp->w_lcs_chars.space
2595 || (in_multispace
2596 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002597 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 && ptr - line <= trailcol)))
2599 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002600 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2601 {
2602 c = wp->w_lcs_chars.multispace[multispace_pos++];
2603 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2604 multispace_pos = 0;
2605 }
2606 else
2607 c = (c == ' ') ? wp->w_lcs_chars.space
2608 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 if (area_attr == 0 && search_attr == 0)
2610 {
2611 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002612 extra_attr = hl_combine_attr(wlv.win_attr,
2613 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002614 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 }
2616 mb_c = c;
2617 if (enc_utf8 && utf_char2len(c) > 1)
2618 {
2619 mb_utf8 = TRUE;
2620 u8cc[0] = 0;
2621 c = 0xc0;
2622 }
2623 else
2624 mb_utf8 = FALSE;
2625 }
2626
zeertzjq2e7cba32022-06-10 15:30:32 +01002627 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2628 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002630 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2631 && wp->w_lcs_chars.leadmultispace != NULL)
2632 {
2633 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002634 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2635 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002636 multispace_pos = 0;
2637 }
2638
2639 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2640 c = wp->w_lcs_chars.trail;
2641
2642 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2643 c = wp->w_lcs_chars.lead;
2644
zeertzjq2e7cba32022-06-10 15:30:32 +01002645 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002646 c = wp->w_lcs_chars.space;
2647
2648
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 if (!attr_pri)
2650 {
2651 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002652 extra_attr = hl_combine_attr(wlv.win_attr,
2653 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002654 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 }
2656 mb_c = c;
2657 if (enc_utf8 && utf_char2len(c) > 1)
2658 {
2659 mb_utf8 = TRUE;
2660 u8cc[0] = 0;
2661 c = 0xc0;
2662 }
2663 else
2664 mb_utf8 = FALSE;
2665 }
2666 }
2667
2668 // Handling of non-printable characters.
2669 if (!vim_isprintc(c))
2670 {
2671 // when getting a character from the file, we may have to
2672 // turn it into something else on the way to putting it
2673 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002674 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 {
2676 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002677 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002679 char_u *sbr = get_showbreak_value(wp);
2680
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 // only adjust the tab_len, when at the first column
2682 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002683 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2684 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685#endif
2686 // tab amount depends on current column
2687#ifdef FEAT_VARTABS
2688 tab_len = tabstop_padding(vcol_adjusted,
2689 wp->w_buffer->b_p_ts,
2690 wp->w_buffer->b_p_vts_array) - 1;
2691#else
2692 tab_len = (int)wp->w_buffer->b_p_ts
2693 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2694#endif
2695
2696#ifdef FEAT_LINEBREAK
2697 if (!wp->w_p_lbr || !wp->w_p_list)
2698#endif
2699 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002700 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701#ifdef FEAT_LINEBREAK
2702 else
2703 {
2704 char_u *p;
2705 int len;
2706 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002709# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002710 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002712 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002713
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002715 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002716 && old_boguscols > 0
2717 && wlv.n_extra > tab_len)
2718 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002719# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002720 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002722 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002723 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002724 if (wp->w_lcs_chars.tab3)
2725 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002726 if (wlv.n_extra > 0)
2727 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002728 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002730 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002732 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002734 vim_memset(p, ' ', len);
2735 p[len] = NUL;
2736 vim_free(p_extra_free);
2737 p_extra_free = p;
2738 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002740 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002742 if (*p == NUL)
2743 {
2744 tab_len = i;
2745 break;
2746 }
2747
2748 // if tab3 is given, use it for the last char
2749 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2750 lcs = wp->w_lcs_chars.tab3;
2751 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002752 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002754 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002755 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002756# ifdef FEAT_CONCEAL
2757 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2758 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002759 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002760 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002761# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763 }
2764#endif
2765#ifdef FEAT_CONCEAL
2766 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002767 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768
2769 // Tab alignment should be identical regardless of
2770 // 'conceallevel' value. So tab compensates of all
2771 // previous concealed characters, and thus resets
2772 // vcol_off and boguscols accumulated so far in the
2773 // line. Note that the tab can be longer than
2774 // 'tabstop' when there are concealed characters.
2775 FIX_FOR_BOGUSCOLS;
2776
2777 // Make sure, the highlighting for the tab char will be
2778 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002779 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002781 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 tab_len += vc_saved;
2783 }
2784#endif
2785 mb_utf8 = FALSE; // don't draw as UTF-8
2786 if (wp->w_p_list)
2787 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002788 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002789 ? wp->w_lcs_chars.tab3
2790 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791#ifdef FEAT_LINEBREAK
2792 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 else
2795#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 wlv.c_extra = wp->w_lcs_chars.tab2;
2797 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002799 extra_attr = hl_combine_attr(wlv.win_attr,
2800 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 mb_c = c;
2803 if (enc_utf8 && utf_char2len(c) > 1)
2804 {
2805 mb_utf8 = TRUE;
2806 u8cc[0] = 0;
2807 c = 0xc0;
2808 }
2809 }
2810 else
2811 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002812 wlv.c_final = NUL;
2813 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814 c = ' ';
2815 }
2816 }
2817 else if (c == NUL
2818 && (wp->w_p_list
2819 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002820 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 && VIsual_mode != Ctrl_V
2822 && (
2823# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002826 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827 && !(noinvcur
2828 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002829 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 && lcs_eol_one > 0)
2831 {
2832 // Display a '$' after the line or highlight an extra
2833 // character if the line break is included.
2834#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2835 // For a diff line the highlighting continues after the
2836 // "$".
2837 if (
2838# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002839 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840# ifdef LINE_ATTR
2841 &&
2842# endif
2843# endif
2844# ifdef LINE_ATTR
2845 line_attr == 0
2846# endif
2847 )
2848#endif
2849 {
2850 // In virtualedit, visual selections may extend
2851 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002852 if (!(area_highlighting && virtual_active()
2853 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002854 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002855 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002857 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2858 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859 else
2860 c = ' ';
2861 lcs_eol_one = -1;
2862 --ptr; // put it back at the NUL
2863 if (!attr_pri)
2864 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002865 extra_attr = hl_combine_attr(wlv.win_attr,
2866 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 n_attr = 1;
2868 }
2869 mb_c = c;
2870 if (enc_utf8 && utf_char2len(c) > 1)
2871 {
2872 mb_utf8 = TRUE;
2873 u8cc[0] = 0;
2874 c = 0xc0;
2875 }
2876 else
2877 mb_utf8 = FALSE; // don't draw as UTF-8
2878 }
2879 else if (c != NUL)
2880 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2882 if (wlv.n_extra == 0)
2883 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884#ifdef FEAT_RIGHTLEFT
2885 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 wlv.c_extra = NUL;
2889 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890#ifdef FEAT_LINEBREAK
2891 if (wp->w_p_lbr)
2892 {
2893 char_u *p;
2894
Bram Moolenaar1306b362022-08-06 15:59:06 +01002895 c = *wlv.p_extra;
2896 p = alloc(wlv.n_extra + 1);
2897 vim_memset(p, ' ', wlv.n_extra);
2898 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2899 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002901 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 }
2903 else
2904#endif
2905 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002906 wlv.n_extra = byte2cells(c) - 1;
2907 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 }
2909 if (!attr_pri)
2910 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002912 extra_attr = hl_combine_attr(wlv.win_attr,
2913 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002914 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 }
2916 mb_utf8 = FALSE; // don't draw as UTF-8
2917 }
2918 else if (VIsual_active
2919 && (VIsual_mode == Ctrl_V
2920 || VIsual_mode == 'v')
2921 && virtual_active()
2922 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002923 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002924 && (
2925#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002926 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002928 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 {
2930 c = ' ';
2931 --ptr; // put it back at the NUL
2932 }
2933#if defined(LINE_ATTR)
2934 else if ((
2935# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002936 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937# endif
2938# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002939 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940# endif
2941 line_attr != 0
2942 ) && (
2943# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002944 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002946 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002948 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002949# endif
2950 < wp->w_width)))
2951 {
2952 // Highlight until the right side of the window
2953 c = ' ';
2954 --ptr; // put it back at the NUL
2955
2956 // Remember we do the char for line highlighting.
2957 ++did_line_attr;
2958
2959 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002962 || (wp->w_p_list &&
2963 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 wlv.diff_hlf = HLF_CHD;
2969 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2973 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002974 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002975 || (wlv.vcol >= left_curline_col
2976 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002977 wlv.char_attr = hl_combine_attr(
2978 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 }
2980 }
2981# endif
2982# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002983 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002985 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002986 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2987 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002989 if (!wlv.cul_screenline
2990 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002991 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002992 wlv.char_attr = hl_combine_attr(
2993 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 }
2995 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002996 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2997 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 }
2999# endif
3000 }
3001#endif
3002 }
3003
3004#ifdef FEAT_CONCEAL
3005 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003006 && (wp != curwin || lnum != wp->w_cursor.lnum
3007 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3009 && !(lnum_in_visual_area
3010 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3011 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003012 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003013 if (((prev_syntax_id != syntax_seqnr
3014 && (syntax_flags & HL_CONCEAL) != 0)
3015 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003016 && (syn_get_sub_char() != NUL
3017 || (has_match_conc && match_conc)
3018 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019 && wp->w_p_cole != 3)
3020 {
3021 // First time at this concealed item: display one
3022 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003023 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 c = match_conc;
3025 else if (syn_get_sub_char() != NUL)
3026 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003027 else if (wp->w_lcs_chars.conceal != NUL)
3028 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 else
3030 c = ' ';
3031
3032 prev_syntax_id = syntax_seqnr;
3033
Bram Moolenaar1306b362022-08-06 15:59:06 +01003034 if (wlv.n_extra > 0)
3035 wlv.vcol_off += wlv.n_extra;
3036 wlv.vcol += wlv.n_extra;
3037 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 {
3039# ifdef FEAT_RIGHTLEFT
3040 if (wp->w_p_rl)
3041 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003042 wlv.col -= wlv.n_extra;
3043 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044 }
3045 else
3046# endif
3047 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 wlv.boguscols += wlv.n_extra;
3049 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050 }
3051 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003052 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 n_attr = 0;
3054 }
3055 else if (n_skip == 0)
3056 {
3057 is_concealing = TRUE;
3058 n_skip = 1;
3059 }
3060 mb_c = c;
3061 if (enc_utf8 && utf_char2len(c) > 1)
3062 {
3063 mb_utf8 = TRUE;
3064 u8cc[0] = 0;
3065 c = 0xc0;
3066 }
3067 else
3068 mb_utf8 = FALSE; // don't draw as UTF-8
3069 }
3070 else
3071 {
3072 prev_syntax_id = 0;
3073 is_concealing = FALSE;
3074 }
3075
3076 if (n_skip > 0 && did_decrement_ptr)
3077 // not showing the '>', put pointer back to avoid getting stuck
3078 ++ptr;
3079
3080#endif // FEAT_CONCEAL
3081 }
3082
3083#ifdef FEAT_CONCEAL
3084 // In the cursor line and we may be concealing characters: correct
3085 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003086 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087 && wp == curwin && lnum == wp->w_cursor.lnum
3088 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003089 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003091# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003093 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003095# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003096 wp->w_wcol = wlv.col - wlv.boguscols;
3097 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098 did_wcol = TRUE;
3099 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003100# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003101 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003102# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 }
3104#endif
3105
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003106 // Use "extra_attr", but don't override visual selection highlighting,
3107 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003108 // Don't use "extra_attr" until n_attr_skip is zero.
3109 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003110 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003111 && (!attr_pri
3112#ifdef FEAT_PROP_POPUP
3113 || (text_prop_flags & PT_FLAG_OVERRIDE)
3114#endif
3115 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 {
3117#ifdef LINE_ATTR
3118 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003119 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120 else
3121#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 }
3124
3125#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3126 // XIM don't send preedit_start and preedit_end, but they send
3127 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3128 // im_is_preediting() here.
3129 if (p_imst == IM_ON_THE_SPOT
3130 && xic != NULL
3131 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003132 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133 && !p_imdisable
3134 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003135 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 {
3137 colnr_T tcol;
3138
3139 if (preedit_end_col == MAXCOL)
3140 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3141 else
3142 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003143 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 {
3145 if (feedback_old_attr < 0)
3146 {
3147 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003150 wlv.char_attr = im_get_feedback_attr(feedback_col);
3151 if (wlv.char_attr < 0)
3152 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 feedback_col++;
3154 }
3155 else if (feedback_old_attr >= 0)
3156 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003157 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 feedback_old_attr = -1;
3159 feedback_col = 0;
3160 }
3161 }
3162#endif
3163 // Handle the case where we are in column 0 but not on the first
3164 // character of the line and the user wants us to show us a
3165 // special character (via 'listchars' option "precedes:<char>".
3166 if (lcs_prec_todo != NUL
3167 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003168 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003169 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003170 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003172 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 && c != NUL)
3176 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003177 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 lcs_prec_todo = NUL;
3179 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3180 {
3181 // Double-width character being overwritten by the "precedes"
3182 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003183 wlv.c_extra = MB_FILLER_CHAR;
3184 wlv.c_final = NUL;
3185 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003187 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 }
3189 mb_c = c;
3190 if (enc_utf8 && utf_char2len(c) > 1)
3191 {
3192 mb_utf8 = TRUE;
3193 u8cc[0] = 0;
3194 c = 0xc0;
3195 }
3196 else
3197 mb_utf8 = FALSE; // don't draw as UTF-8
3198 if (!attr_pri)
3199 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003200 saved_attr3 = wlv.char_attr; // save current attr
3201 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202 n_attr3 = 1;
3203 }
3204 }
3205
3206 // At end of the text line or just after the last character.
3207 if ((c == NUL
3208#if defined(LINE_ATTR)
3209 || did_line_attr == 1
3210#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003211 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 {
3213#ifdef FEAT_SEARCH_EXTRA
3214 // flag to indicate whether prevcol equals startcol of search_hl or
3215 // one of the matches
3216 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3217 (long)(ptr - line) - (c == NUL));
3218#endif
3219 // Invert at least one char, used for Visual and empty line or
3220 // highlight match at end of line. If it's beyond the last
3221 // char on the screen, just overwrite that one (tricky!) Not
3222 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003223 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003224 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 && (VIsual_mode != Ctrl_V
3226 || lnum == VIsual.lnum
3227 || lnum == curwin->w_cursor.lnum)
3228 && c == NUL)
3229#ifdef FEAT_SEARCH_EXTRA
3230 // highlight 'hlsearch' match at end of line
3231 || (prevcol_hl_flag
3232# ifdef FEAT_SYN_HL
3233 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3234 && !(wp == curwin && VIsual_active))
3235# endif
3236# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238# endif
3239# if defined(LINE_ATTR)
3240 && did_line_attr <= 1
3241# endif
3242 )
3243#endif
3244 ))
3245 {
3246 int n = 0;
3247
3248#ifdef FEAT_RIGHTLEFT
3249 if (wp->w_p_rl)
3250 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 n = 1;
3253 }
3254 else
3255#endif
3256 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 n = -1;
3259 }
3260 if (n != 0)
3261 {
3262 // At the window boundary, highlight the last character
3263 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 wlv.off += n;
3265 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 }
3267 else
3268 {
3269 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003272 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 }
3274#ifdef FEAT_SEARCH_EXTRA
3275 if (area_attr == 0)
3276 {
3277 // Use attributes from match with highest priority among
3278 // 'search_hl' and the match list.
3279 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003280 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281 }
3282#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003283 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285#ifdef FEAT_RIGHTLEFT
3286 if (wp->w_p_rl)
3287 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 --wlv.col;
3289 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 }
3291 else
3292#endif
3293 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003294 ++wlv.col;
3295 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 ++wlv.vcol;
3298 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 }
3300 }
3301
3302 // At end of the text line.
3303 if (c == NUL)
3304 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306
3307 // Update w_cline_height and w_cline_folded if the cursor line was
3308 // updated (saves a call to plines() later).
3309 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3310 {
3311 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003312 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313#ifdef FEAT_FOLDING
3314 curwin->w_cline_folded = FALSE;
3315#endif
3316 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3317 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 break;
3319 }
3320
3321 // Show "extends" character from 'listchars' if beyond the line end and
3322 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003323 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003324 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 && wp->w_p_list
3326 && !wp->w_p_wrap
3327#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003328 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329#endif
3330 && (
3331#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003332 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003334 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003336 || lcs_eol_one > 0
3337 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003340 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 mb_c = c;
3343 if (enc_utf8 && utf_char2len(c) > 1)
3344 {
3345 mb_utf8 = TRUE;
3346 u8cc[0] = 0;
3347 c = 0xc0;
3348 }
3349 else
3350 mb_utf8 = FALSE;
3351 }
3352
3353#ifdef FEAT_SYN_HL
3354 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 if (wlv.draw_color_col)
3356 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357
3358 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3359 // highlight the cursor position itself.
3360 // Also highlight the 'colorcolumn' if it is different than
3361 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003362 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3363 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003365 if (((wlv.draw_state == WL_LINE
3366 || wlv.draw_state == WL_BRI
3367 || wlv.draw_state == WL_SBR)
3368 && !lnum_in_visual_area
3369 && search_attr == 0
3370 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003371# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003372 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003373# endif
3374 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 {
3376 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3377 && lnum != wp->w_cursor.lnum)
3378 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003379 vcol_save_attr = wlv.char_attr;
3380 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3381 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 vcol_save_attr = wlv.char_attr;
3386 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 }
3388 }
3389#endif
3390
3391 // Store character to be displayed.
3392 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003393 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003394 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 {
3396 // Store the character.
3397#if defined(FEAT_RIGHTLEFT)
3398 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3399 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003400 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003401 --wlv.off;
3402 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003403 }
3404#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 if (enc_dbcs == DBCS_JPNU)
3407 {
3408 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 ScreenLines[wlv.off] = 0x8e;
3410 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411 }
3412 else if (enc_utf8)
3413 {
3414 if (mb_utf8)
3415 {
3416 int i;
3417
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 for (i = 0; i < Screen_mco; ++i)
3422 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 if (u8cc[i] == 0)
3425 break;
3426 }
3427 }
3428 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 }
3431 if (multi_attr)
3432 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 multi_attr = 0;
3435 }
3436 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003437 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003439 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003440
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3442 {
3443 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 ++wlv.off;
3445 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 if (enc_utf8)
3447 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 else
3450 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003452 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003454 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455#endif
3456 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 // When "tocol" is halfway a character, set it to the end of
3459 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003462
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003464
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465#ifdef FEAT_RIGHTLEFT
3466 if (wp->w_p_rl)
3467 {
3468 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 --wlv.off;
3470 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 }
3472#endif
3473 }
3474#ifdef FEAT_RIGHTLEFT
3475 if (wp->w_p_rl)
3476 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 --wlv.off;
3478 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 }
3480 else
3481#endif
3482 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 ++wlv.off;
3484 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486 }
3487#ifdef FEAT_CONCEAL
3488 else if (wp->w_p_cole > 0 && is_concealing)
3489 {
3490 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003491 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003492 if (wlv.n_extra > 0)
3493 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 if (wp->w_p_wrap)
3495 {
3496 // Special voodoo required if 'wrap' is on.
3497 //
3498 // Advance the column indicator to force the line
3499 // drawing to wrap early. This will make the line
3500 // take up the same screen space when parts are concealed,
3501 // so that cursor line computations aren't messed up.
3502 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003503 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 // trailing junk to be written out of the screen line
3505 // we are building, 'boguscols' keeps track of the number
3506 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003507 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003509 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510# ifdef FEAT_RIGHTLEFT
3511 if (wp->w_p_rl)
3512 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003513 wlv.col -= wlv.n_extra;
3514 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 }
3516 else
3517# endif
3518 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003519 wlv.col += wlv.n_extra;
3520 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003522 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 n_attr = 0;
3524 }
3525
3526
3527 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3528 {
3529 // Need to fill two screen columns.
3530# ifdef FEAT_RIGHTLEFT
3531 if (wp->w_p_rl)
3532 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003533 --wlv.boguscols;
3534 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 }
3536 else
3537# endif
3538 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003539 ++wlv.boguscols;
3540 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 }
3542 }
3543
3544# ifdef FEAT_RIGHTLEFT
3545 if (wp->w_p_rl)
3546 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003547 --wlv.boguscols;
3548 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 }
3550 else
3551# endif
3552 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003553 ++wlv.boguscols;
3554 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 }
3556 }
3557 else
3558 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 wlv.vcol += wlv.n_extra;
3562 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 n_attr = 0;
3564 }
3565 }
3566
3567 }
3568#endif // FEAT_CONCEAL
3569 else
3570 --n_skip;
3571
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003572 // Only advance the "wlv.vcol" when after the 'number' or
3573 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003574 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003576 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577#endif
3578 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580
3581#ifdef FEAT_SYN_HL
3582 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003583 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584#endif
3585
3586 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003587 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3588 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589
3590 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003591 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003592 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003593 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003594 if (n_attr_skip > 0)
3595 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596
3597 // At end of screen line and there is more to come: Display the line
3598 // so far. If there is no more to display it is caught above.
3599 if ((
3600#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003601 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003604 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003605 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003607 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003609#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003610 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003611#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003612 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003613 && wlv.p_extra != at_end_str)
3614 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3615 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 )
3617 {
3618#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003619 screen_line(wp, wlv.screen_row, wp->w_wincol,
3620 wlv.col - wlv.boguscols,
3621 wp->w_width, wlv.screen_line_flags);
3622 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3625 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003627 ++wlv.row;
3628 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629
3630 // When not wrapping and finished diff lines, or when displayed
3631 // '$' and highlighting until last column, break here.
3632 if ((!wp->w_p_wrap
3633#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003634 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003635#endif
3636#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003637 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638#endif
3639 ) || lcs_eol_one == -1)
3640 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003641#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003642 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003643 {
3644 // do not output more of the line, only the "below" prop
3645 ptr += STRLEN(ptr);
3646# ifdef FEAT_LINEBREAK
3647 dont_use_showbreak = TRUE;
3648# endif
3649 }
3650#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651
3652 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003655 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656#endif
3657 )
3658 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3660 draw_vsep_win(wp, wlv.row);
3661 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 }
3663
3664 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003665 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 break;
3669 }
3670
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003671 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003673 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003675#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003676 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003677#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 && wp->w_width == Columns)
3679 {
3680 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682
3683 // Special trick to make copy/paste of wrapped lines work with
3684 // xterm/screen: write an extra character beyond the end of
3685 // the line. This will work with all terminal types
3686 // (regardless of the xn,am settings).
3687 // Only do this on a fast tty.
3688 // Only do this if the cursor is on the current line
3689 // (something has been written in it).
3690 // Don't do this for the GUI.
3691 // Don't do this for double-width characters.
3692 // Don't do this for a window not at the right screen border.
3693 if (p_tf
3694#ifdef FEAT_GUI
3695 && !gui.in_use
3696#endif
3697 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3699 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003701 || (*mb_off2cells)(
3702 LineOffset[wlv.screen_row - 1]
3703 + (int)Columns - 2,
3704 LineOffset[wlv.screen_row]
3705 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706 {
3707 // First make sure we are at the end of the screen line,
3708 // then output the same character again to let the
3709 // terminal know about the wrap. If the terminal doesn't
3710 // auto-wrap, we overwrite the character.
3711 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003712 screen_char(LineOffset[wlv.screen_row - 1]
3713 + (unsigned)Columns - 1,
3714 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715
3716 // When there is a multi-byte character, just output a
3717 // space to keep it simple.
3718 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 out_char(' ');
3721 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 + (Columns - 1)]);
3724 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003725 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726 screen_start(); // don't know where cursor is now
3727 }
3728 }
3729
Bram Moolenaar1306b362022-08-06 15:59:06 +01003730 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731
Bram Moolenaareed9d462021-02-15 20:38:25 +01003732 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003734 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003736 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003738 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 need_showbreak = TRUE;
3740#endif
3741#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003742 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743 // When the filler lines are actually below the last line of the
3744 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003745 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 break;
3747#endif
3748 }
3749
3750 } // for every character in the line
3751
3752#ifdef FEAT_SPELL
3753 // After an empty line check first word for capital.
3754 if (*skipwhite(line) == NUL)
3755 {
3756 capcol_lnum = lnum + 1;
3757 cap_col = 0;
3758 }
3759#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003760#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 vim_free(text_props);
3762 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003763 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003764#endif
3765
3766 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003767 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768}