blob: e2849a1ff8ac1f29001a1cdd78f57f38c2cc971f [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 Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
99 int vcol_off; // offset for concealed characters
100#endif
101#ifdef FEAT_SYN_HL
102 int draw_color_col; // highlight colorcolumn
103 int *color_cols; // pointer to according columns array
104#endif
105 int eol_hl_off; // 1 if highlighted char after EOL
106
107 unsigned off; // offset in ScreenLines/ScreenAttrs
108
109 int win_attr; // background for the whole window, except
110 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100111 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100112#ifdef FEAT_SYN_HL
113 int cul_attr; // set when 'cursorline' active
114#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000115#ifdef LINE_ATTR
116 int line_attr; // for the whole line, includes 'cursorline'
117#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100118
119 int screen_line_flags; // flags for screen_line()
120
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100121 int fromcol; // start of inverting
122 int tocol; // end of inverting
123
124#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100125 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100126 int need_showbreak; // overlong line, skipping first x chars
127 int dont_use_showbreak; // do not use 'showbreak'
128#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100129#ifdef FEAT_PROP_POPUP
130 int text_prop_above_count;
131#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100132
Bram Moolenaar1306b362022-08-06 15:59:06 +0100133 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
134 int cul_screenline;
135
136 int char_attr; // attributes for the next character
137
138 int n_extra; // number of extra bytes
139 char_u *p_extra; // string of extra chars, plus NUL, only used
140 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100141 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000142 int extra_attr; // attributes for p_extra, should be combined
143 // with win_attr if needed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100144 int c_extra; // extra chars, all the same
145 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000146 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147
148 // saved "extra" items for when draw_state becomes WL_LINE (again)
149 int saved_n_extra;
150 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000151 int saved_extra_attr;
152 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100153 int saved_c_extra;
154 int saved_c_final;
155 int saved_char_attr;
156
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100157 char_u extra[NUMBUFLEN + MB_MAXBYTES];
158 // "%ld " and 'fdc' must fit in here, as well
159 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100160
Bram Moolenaar1306b362022-08-06 15:59:06 +0100161#ifdef FEAT_DIFF
162 hlf_T diff_hlf; // type of diff highlighting
163#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100164 int filler_lines; // nr of filler lines to be drawn
165 int filler_todo; // nr of filler lines still to do + 1
166#ifdef FEAT_SIGNS
167 sign_attrs_T sattr;
168#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100169} winlinevars_T;
170
171// draw_state values for items that are drawn in sequence:
172#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100173#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100174#ifdef FEAT_FOLDING
175# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
176#else
177# define WL_FOLD WL_CMDLINE
178#endif
179#ifdef FEAT_SIGNS
180# define WL_SIGN (WL_FOLD + 1) // column for signs
181#else
182# define WL_SIGN WL_FOLD // column for signs
183#endif
184#define WL_NR (WL_SIGN + 1) // line number
185#ifdef FEAT_LINEBREAK
186# define WL_BRI (WL_NR + 1) // 'breakindent'
187#else
188# define WL_BRI WL_NR
189#endif
190#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
191# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
192#else
193# define WL_SBR WL_BRI
194#endif
195#define WL_LINE (WL_SBR + 1) // text in the line
196
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100197#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000199 * Return TRUE if CursorLineSign highlight is to be used.
200 */
201 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100202use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000203{
204 return wp->w_p_cul
205 && lnum == wp->w_cursor.lnum
206 && (wp->w_p_culopt_flags & CULOPT_NBR);
207}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100208#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000209
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100210
211#ifdef FEAT_FOLDING
212/*
213 * Setup for drawing the 'foldcolumn', if there is one.
214 */
215 static void
216handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
217{
218 int fdc = compute_foldcolumn(wp, 0);
219
220 if (fdc <= 0)
221 return;
222
223 // Allocate a buffer, "wlv->extra[]" may already be in use.
224 vim_free(wlv->p_extra_free);
225 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
226 if (wlv->p_extra_free != NULL)
227 {
228 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
229 wp, FALSE, wlv->lnum);
230 wlv->p_extra_free[wlv->n_extra] = NUL;
231 wlv->p_extra = wlv->p_extra_free;
232 wlv->c_extra = NUL;
233 wlv->c_final = NUL;
234 if (use_cursor_line_highlight(wp, wlv->lnum))
235 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
236 else
237 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
238 }
239}
240#endif
241
242#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000243/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100244 * Get information needed to display the sign in line "wlv->lnum" in window
245 * "wp".
246 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 * Otherwise the sign is going to be displayed in the sign column.
248 */
249 static void
250get_sign_display_info(
251 int nrcol,
252 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100253 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254{
255 int text_sign;
256# ifdef FEAT_SIGN_ICONS
257 int icon_sign;
258# endif
259
260 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100261 wlv->c_extra = ' ';
262 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 else
266 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100267 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000269 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100270 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100271 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272 }
273
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100276 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200277#endif
278 )
279 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100282 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 if (gui.in_use && icon_sign != 0)
284 {
285 // Use the image in this position.
286 if (nrcol)
287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100288 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 sprintf((char *)wlv->extra, "%-*c ",
290 number_width(wp), SIGN_BYTE);
291 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 }
294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100297 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
298 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200299 {
300 if (nrcol)
301 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100303 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 }
308 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100309 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310 }
311# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_final = NUL;
313 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 }
315 else
316# endif
317 if (text_sign != 0)
318 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100319 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100320 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200321 {
322 if (nrcol)
323 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100324 int width = number_width(wp) - 2;
325 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200326
327 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100328 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100329 vim_snprintf((char *)wlv->extra + n,
330 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100331 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200332 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100333 wlv->c_extra = NUL;
334 wlv->c_final = NUL;
335 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000337
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100338 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100339 && wlv->sattr.sat_culhl > 0)
340 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000341 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100342 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343 }
344 }
345}
346#endif
347
Bram Moolenaard7657e92022-09-20 18:59:30 +0100348/*
349 * Display the absolute or relative line number. After the first row fill with
350 * blanks when the 'n' flag isn't in 'cpo'.
351 */
352 static void
353handle_lnum_col(
354 win_T *wp,
355 winlinevars_T *wlv,
356 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100357 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100358{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100359 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100360 int lnum_row = wlv->startrow + wlv->filler_lines
361#ifdef FEAT_PROP_POPUP
362 + wlv->text_prop_above_count
363#endif
364 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100365
Bram Moolenaard7657e92022-09-20 18:59:30 +0100366 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100367 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100368 // there is no line number in a wrapped line when "n" is in
369 // 'cpoptions', but 'breakindent' assumes it anyway.
370 && !((has_cpo_n
371#ifdef FEAT_LINEBREAK
372 && !wp->w_p_bri
373#endif
374 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100375 {
376#ifdef FEAT_SIGNS
377 // If 'signcolumn' is set to 'number' and a sign is present
378 // in 'lnum', then display the sign instead of the line
379 // number.
380 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
381 get_sign_display_info(TRUE, wp, wlv);
382 else
383#endif
384 {
385 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100386 // When there are text properties above the line put the line number
387 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100388 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100389 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
390 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100391 {
392 long num;
393 char *fmt = "%*ld ";
394
395 if (wp->w_p_nu && !wp->w_p_rnu)
396 // 'number' + 'norelativenumber'
397 num = (long)wlv->lnum;
398 else
399 {
400 // 'relativenumber', don't use negative numbers
401 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
402 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
403 {
404 // 'number' + 'relativenumber'
405 num = wlv->lnum;
406 fmt = "%-*ld ";
407 }
408 }
409
410 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100411 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100412 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
413 ++wlv->p_extra)
414 *wlv->p_extra = '-';
415#ifdef FEAT_RIGHTLEFT
416 if (wp->w_p_rl) // reverse line numbers
417 {
418 char_u *p1, *p2;
419 int t;
420
421 // like rl_mirror(), but keep the space at the end
422 p2 = skipwhite(wlv->extra);
423 p2 = skiptowhite(p2) - 1;
424 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
425 {
426 t = *p1;
427 *p1 = *p2;
428 *p2 = t;
429 }
430 }
431#endif
432 wlv->p_extra = wlv->extra;
433 wlv->c_extra = NUL;
434 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100435 }
436 else
437 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100438 wlv->c_extra = ' ';
439 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100440 }
441 wlv->n_extra = number_width(wp) + 1;
442 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
443#ifdef FEAT_SYN_HL
444 // When 'cursorline' is set highlight the line number of
445 // the current line differently.
446 // When 'cursorlineopt' does not have "line" only
447 // highlight the line number itself.
448 // TODO: Can we use CursorLine instead of CursorLineNr
449 // when CursorLineNr isn't set?
450 if (wp->w_p_cul
451 && wlv->lnum == wp->w_cursor.lnum
452 && (wp->w_p_culopt_flags & CULOPT_NBR)
453 && (wlv->row == wlv->startrow + wlv->filler_lines
454 || (wlv->row > wlv->startrow + wlv->filler_lines
455 && (wp->w_p_culopt_flags & CULOPT_LINE))))
456 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
457#endif
458 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
459 && HL_ATTR(HLF_LNA) != 0)
460 // Use LineNrAbove
461 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
462 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
463 && HL_ATTR(HLF_LNB) != 0)
464 // Use LineNrBelow
465 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
466 }
467#ifdef FEAT_SIGNS
468 if (num_attr)
469 wlv->char_attr = num_attr;
470#endif
471 }
472}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100473
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100474#ifdef FEAT_LINEBREAK
475 static void
476handle_breakindent(win_T *wp, winlinevars_T *wlv)
477{
478 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100479 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100480 // draw indent after showbreak value
481 wlv->draw_state = WL_BRI;
482 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
483 // After the showbreak, draw the breakindent
484 wlv->draw_state = WL_BRI - 1;
485
486 // draw 'breakindent': indent wrapped text accordingly
487 if (wlv->draw_state == WL_BRI - 1)
488 {
489 wlv->draw_state = WL_BRI;
490 // if wlv->need_showbreak is set, breakindent also applies
491 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
492# ifdef FEAT_DIFF
493 && wlv->filler_lines == 0
494# endif
495# ifdef FEAT_PROP_POPUP
496 && !wlv->dont_use_showbreak
497# endif
498 )
499 {
500 wlv->char_attr = 0;
501# ifdef FEAT_DIFF
502 if (wlv->diff_hlf != (hlf_T)0)
503 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
504# endif
505 wlv->p_extra = NULL;
506 wlv->c_extra = ' ';
507 wlv->c_final = NUL;
508 wlv->n_extra = get_breakindent_win(wp,
509 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
510 if (wlv->row == wlv->startrow)
511 {
512 wlv->n_extra -= win_col_off2(wp);
513 if (wlv->n_extra < 0)
514 wlv->n_extra = 0;
515 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100516 if (wp->w_skipcol > 0 && wlv->startrow == 0
517 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100518 wlv->need_showbreak = FALSE;
519 // Correct end of highlighted area for 'breakindent',
520 // required when 'linebreak' is also set.
521 if (wlv->tocol == wlv->vcol)
522 wlv->tocol += wlv->n_extra;
523 }
524 }
525}
526#endif
527
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100528#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
529 static void
530handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
531{
532# ifdef FEAT_DIFF
533 if (wlv->filler_todo > 0)
534 {
535 // Draw "deleted" diff line(s).
536 if (char2cells(wp->w_fill_chars.diff) > 1)
537 {
538 wlv->c_extra = '-';
539 wlv->c_final = NUL;
540 }
541 else
542 {
543 wlv->c_extra = wp->w_fill_chars.diff;
544 wlv->c_final = NUL;
545 }
546# ifdef FEAT_RIGHTLEFT
547 if (wp->w_p_rl)
548 wlv->n_extra = wlv->col + 1;
549 else
550# endif
551 wlv->n_extra = wp->w_width - wlv->col;
552 wlv->char_attr = HL_ATTR(HLF_DED);
553 }
554# endif
555
556# ifdef FEAT_LINEBREAK
557 char_u *sbr = get_showbreak_value(wp);
558 if (*sbr != NUL && wlv->need_showbreak)
559 {
560 // Draw 'showbreak' at the start of each broken line.
561 wlv->p_extra = sbr;
562 wlv->c_extra = NUL;
563 wlv->c_final = NUL;
564 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100565 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100566 wlv->need_showbreak = FALSE;
567 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
568 // Correct end of highlighted area for 'showbreak',
569 // required when 'linebreak' is also set.
570 if (wlv->tocol == wlv->vcol)
571 wlv->tocol += wlv->n_extra;
572 // combine 'showbreak' with 'wincolor'
573 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
574# ifdef FEAT_SYN_HL
575 // combine 'showbreak' with 'cursorline'
576 if (wlv->cul_attr != 0)
577 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
578# endif
579 }
580# endif
581}
582#endif
583
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100584#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100585/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100586 * Return the cell size of virtual text after truncation.
587 */
588 static int
589textprop_size_after_trunc(
590 win_T *wp,
591 int flags, // TP_FLAG_ALIGN_*
592 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100593 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100594 char_u *text,
595 int *n_used_ptr)
596{
597 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100598 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100599 int len = (int)STRLEN(text);
600 int strsize = 0;
601 int n_used;
602
Bram Moolenaar7e017462022-10-11 21:02:09 +0100603 // if the remaining size is to small and 'wrap' is set we wrap anyway and
604 // use the next line
605 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100606 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100607 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100608 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
610 {
611 int clen = ptr2cells(text + n_used);
612
613 if (strsize + clen > space)
614 break;
615 strsize += clen;
616 }
617 *n_used_ptr = n_used;
618 return strsize;
619}
620
621/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100622 * Take care of padding, right-align and truncation of virtual text after a
623 * line.
624 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
625 * padding, right-align and truncation. Otherwise only the size is computed.
626 * When "n_attr" is NULL returns the number of screen cells used.
627 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100628 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100629 int
630text_prop_position(
631 win_T *wp,
632 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000633 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100634 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100635 int *n_extra, // nr of bytes for virtual text
636 char_u **p_extra, // virtual text
637 int *n_attr, // attribute cells, NULL if not used
638 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200639{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100640 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100641 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100642 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
643 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
644 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000645 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100646 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100648 int before = room; // spaces before the text
649 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 int n_used = *n_extra;
651 char_u *l = NULL;
652 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100653 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100654 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100655 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
656 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200657
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100659 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100660 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100661 int skip_add = 0;
662
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100663 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100664 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100665 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100666 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 }
668 else
669 {
670 // Right-align: fill with before
671 if (right)
672 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000673
674 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000675 if (below && vcol == 0 && col_with_padding == col_off
676 && wp->w_width - col_off == before)
677 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000678
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 if (before < 0
680 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000681 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
682 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100683 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100684 if (right && (wrap
685 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 {
687 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 before = wp->w_width - col_off - strsize + room;
689 if (before < 0)
690 before = 0;
691 else
692 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100693 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100694 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100695 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100698 else if (below && before > 0)
699 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100700 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100701 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100702
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703 // With 'nowrap' add one to show the "extends" character if needed (it
704 // doesn't show if the text just fits).
705 if (!wp->w_p_wrap
706 && n_used < *n_extra
707 && wp->w_lcs_chars.ext != NUL
708 && wp->w_p_list)
709 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100710 if (!wp->w_p_wrap && below && padding > 0)
711 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712
713 // add 1 for NUL, 2 for when '…' is used
714 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100715 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100716 if (n_attr == NULL || l != NULL)
717 {
718 int off = 0;
719
720 if (n_attr != NULL)
721 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100722 vim_memset(l, ' ', before);
723 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100724 if (padding > 0)
725 {
726 vim_memset(l + off, ' ', padding);
727 off += padding;
728 }
729 vim_strncpy(l + off, *p_extra, n_used);
730 off += n_used;
731 }
732 else
733 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100734 off = before + after + padding + n_used;
735 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100736 }
737 if (n_attr != NULL)
738 {
739 if (n_used < *n_extra && wp->w_p_wrap)
740 {
741 char_u *lp = l + off - 1;
742
743 if (has_mbyte)
744 {
745 // change last character to '…'
746 lp -= (*mb_head_off)(l, lp);
747 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100748 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100749 }
750 else
751 // change last character to '>'
752 *lp = '>';
753 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100754 else if (after > 0)
755 {
756 vim_memset(l + off, ' ', after);
757 l[off + after] = NUL;
758 }
759
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100760 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100761 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100762 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100763 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100764 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100765
766 // Add "skip_add" when starting a new line or wrapping,
767 // n_attr_skip will then be decremented in the number column.
768 *n_attr_skip = before + padding
769 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100770 }
771 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100772 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100773
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100774 if (n_attr == NULL)
775 return cells;
776 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200777}
778#endif
779
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100780/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100781 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100782 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
783 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100784 */
785 static void
786wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
787{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100788 if (wlv->row == 0 && wp->w_skipcol > 0
789#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100790 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100791 && *get_showbreak_value(wp) == NUL
792#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100793 // do not overwrite the 'listchars' "precedes" text with "<<<"
794 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100795 {
796 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100797 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100798
Bram Moolenaareb4de622022-10-15 13:42:17 +0100799 if (wp->w_p_nu && wp->w_p_rnu)
800 // Do not overwrite the line number, change "123 text" to
801 // "123>>>xt".
802 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
803 {
804 ++off;
805 ++skip;
806 }
807
808 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100809 {
810 ScreenLines[off] = '<';
811 if (enc_utf8)
812 ScreenLinesUC[off] = 0;
813 ScreenAttrs[off] = HL_ATTR(HLF_AT);
814 ++off;
815 }
816 }
817
818 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
819 negative_width ? -wp->w_width : wp->w_width,
820 wlv->screen_line_flags);
821}
822
823/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100824 * Called when finished with the line: draw the screen line and handle any
825 * highlighting until the right of the window.
826 */
827 static void
828draw_screen_line(win_T *wp, winlinevars_T *wlv)
829{
830#ifdef FEAT_SYN_HL
831 long v;
832
833 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
834 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100835 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100836 else
837 v = wp->w_leftcol;
838
839 // check if line ends before left margin
840 if (wlv->vcol < v + wlv->col - win_col_off(wp))
841 wlv->vcol = v + wlv->col - win_col_off(wp);
842# ifdef FEAT_CONCEAL
843 // Get rid of the boguscols now, we want to draw until the right
844 // edge for 'cursorcolumn'.
845 wlv->col -= wlv->boguscols;
846 wlv->boguscols = 0;
847# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
848# else
849# define VCOL_HLC (wlv->vcol)
850# endif
851
852 if (wlv->draw_color_col)
853 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
854
855 if (((wp->w_p_cuc
856 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
857 && (int)wp->w_virtcol <
858 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
859 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000860 || wlv->draw_color_col
861# ifdef LINE_ATTR
862 || wlv->line_attr != 0
863# endif
864 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100865# ifdef FEAT_RIGHTLEFT
866 && !wp->w_p_rl
867# endif
868 )
869 {
870 int rightmost_vcol = 0;
871 int i;
872
873 if (wp->w_p_cuc)
874 rightmost_vcol = wp->w_virtcol;
875 if (wlv->draw_color_col)
876 // determine rightmost colorcolumn to possibly draw
877 for (i = 0; wlv->color_cols[i] >= 0; ++i)
878 if (rightmost_vcol < wlv->color_cols[i])
879 rightmost_vcol = wlv->color_cols[i];
880
881 while (wlv->col < wp->w_width)
882 {
883 ScreenLines[wlv->off] = ' ';
884 if (enc_utf8)
885 ScreenLinesUC[wlv->off] = 0;
886 ScreenCols[wlv->off] = MAXCOL;
887 ++wlv->col;
888 if (wlv->draw_color_col)
889 wlv->draw_color_col = advance_color_col(
890 VCOL_HLC, &wlv->color_cols);
891
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000892 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100893 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000894 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100895 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000896 attr = HL_ATTR(HLF_MC);
897# ifdef LINE_ATTR
898 else if (wlv->line_attr != 0)
899 attr = wlv->line_attr;
900# endif
901 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100902
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000903 if (VCOL_HLC >= rightmost_vcol
904# ifdef LINE_ATTR
905 && wlv->line_attr == 0
906# endif
907 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100908 break;
909
910 ++wlv->vcol;
911 }
912 }
913#endif
914
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100915 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100916 ++wlv->row;
917 ++wlv->screen_row;
918}
919#undef VCOL_HLC
920
921/*
922 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100923 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100924 */
925 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100926win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100927{
928 wlv->col = 0;
929 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
930
931#ifdef FEAT_RIGHTLEFT
932 if (wp->w_p_rl)
933 {
934 // Rightleft window: process the text in the normal direction, but put
935 // it in current_ScreenLine[] from right to left. Start at the
936 // rightmost column of the window.
937 wlv->col = wp->w_width - 1;
938 wlv->off += wlv->col;
939 wlv->screen_line_flags |= SLF_RIGHTLEFT;
940 }
941#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100942 if (save_extra)
943 {
944 // reset the drawing state for the start of a wrapped line
945 wlv->draw_state = WL_START;
946 wlv->saved_n_extra = wlv->n_extra;
947 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000948 wlv->saved_extra_attr = wlv->extra_attr;
949 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100950 wlv->saved_c_extra = wlv->c_extra;
951 wlv->saved_c_final = wlv->c_final;
952#ifdef FEAT_SYN_HL
953 if (!(wlv->cul_screenline
954# ifdef FEAT_DIFF
955 && wlv->diff_hlf == (hlf_T)0
956# endif
957 ))
958 wlv->saved_char_attr = wlv->char_attr;
959 else
960#endif
961 wlv->saved_char_attr = 0;
962 wlv->n_extra = 0;
963 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100964}
965
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200966/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100967 * Called when wlv->draw_state is set to WL_LINE.
968 */
969 static void
970win_line_continue(winlinevars_T *wlv)
971{
972 if (wlv->saved_n_extra > 0)
973 {
974 // Continue item from end of wrapped line.
975 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +0000976 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100977 wlv->c_extra = wlv->saved_c_extra;
978 wlv->c_final = wlv->saved_c_final;
979 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000980 wlv->extra_attr = wlv->saved_extra_attr;
981 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100982 wlv->char_attr = wlv->saved_char_attr;
983 }
984 else
985 wlv->char_attr = wlv->win_attr;
986}
987
988/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200989 * Display line "lnum" of window 'wp' on the screen.
990 * Start at row "startrow", stop when "endrow" is reached.
991 * wp->w_virtcol needs to be valid.
992 *
993 * Return the number of last row the line occupies.
994 */
995 int
996win_line(
997 win_T *wp,
998 linenr_T lnum,
999 int startrow,
1000 int endrow,
1001 int nochange UNUSED, // not updating for changed text
1002 int number_only) // only update the number column
1003{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001004 winlinevars_T wlv; // variables passed between functions
1005
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001007 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008 char_u *line; // current line
1009 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010
Bram Moolenaar1306b362022-08-06 15:59:06 +01001011#ifdef FEAT_PROP_POPUP
1012 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1013#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001014#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001015 int in_linebreak = FALSE; // n_extra set for showing linebreak
1016#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001018 // displaying eol at end-of-line
1019 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001020 int lcs_prec_todo = wp->w_lcs_chars.prec;
1021 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001023 int n_attr = 0; // chars with special attr
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001024 int n_attr_skip = 0; // chars to skip bef. using wlv.extra_attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001025 int saved_attr2 = 0; // char_attr saved for n_attr
1026 int n_attr3 = 0; // chars with overruling special attr
1027 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028
Bram Moolenaarcd105412022-10-10 19:50:42 +01001029 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1030 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001031#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001032 int skip_cells = 0; // nr of cells to skip for virtual text
1033 // after the line, when w_skipcol is
1034 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001035#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037 int fromcol_prev = -2; // start of inverting after cursor
1038 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001039 int lnum_in_visual_area = FALSE;
1040 pos_T pos;
1041 long v;
1042
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001043 int attr_pri = FALSE; // char_attr has priority
1044 int area_highlighting = FALSE; // Visual or incsearch highlighting
1045 // in this line
1046 int vi_attr = 0; // attributes for Visual and incsearch
1047 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048 int area_attr = 0; // attributes desired by highlighting
1049 int search_attr = 0; // attributes desired by 'hlsearch'
1050#ifdef FEAT_SYN_HL
1051 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1052 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001053 int prev_syntax_col = -1; // column of prev_syntax_attr
1054 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001055 int has_syntax = FALSE; // this buffer has syntax highl.
1056 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001057#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001058#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059 int text_prop_count;
1060 int text_prop_next = 0; // next text property to use
1061 textprop_T *text_props = NULL;
1062 int *text_prop_idxs = NULL;
1063 int text_props_active = 0;
1064 proptype_T *text_prop_type = NULL;
1065 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001066 int text_prop_attr_comb = 0; // text_prop_attr combined with
1067 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001068 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001069 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001070 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001071 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001072 int saved_search_attr = 0; // search_attr to be used when n_extra
1073 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001074 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001075 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076#endif
1077#ifdef FEAT_SPELL
1078 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001079 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080# define SPWORDLEN 150
1081 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1082 int nextlinecol = 0; // column where nextline[] starts
1083 int nextline_idx = 0; // index in nextline[] where next line
1084 // starts
1085 int spell_attr = 0; // attributes desired by spelling
1086 int word_end = 0; // last byte with same spell_attr
1087 static linenr_T checked_lnum = 0; // line number for "checked_col"
1088 static int checked_col = 0; // column in "checked_lnum" up to which
1089 // there are no spell errors
1090 static int cap_col = -1; // column to check for Cap word
1091 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1092 int cur_checked_col = 0; // checked column for current line
1093#endif
1094 int extra_check = 0; // has extra highlighting
1095 int multi_attr = 0; // attributes desired by multibyte
1096 int mb_l = 1; // multi-byte byte length
1097 int mb_c = 0; // decoded multi-byte character
1098 int mb_utf8 = FALSE; // screen char is UTF-8 char
1099 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101 int change_start = MAXCOL; // first col of changed area
1102 int change_end = -1; // last col of changed area
1103#endif
1104 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001105 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001106 int in_multispace = FALSE; // in multiple consecutive spaces
1107 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001108#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001109 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001112 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113#ifdef FEAT_ARABIC
1114 int prev_c = 0; // previous Arabic character
1115 int prev_c1 = 0; // first composing char for prev_c
1116#endif
1117#if defined(LINE_ATTR)
1118 int did_line_attr = 0;
1119#endif
1120#ifdef FEAT_TERMINAL
1121 int get_term_attr = FALSE;
1122#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123
Martin Tournoijba43e762022-10-13 22:12:15 +01001124#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001125 // margin columns for the screen line, needed for when 'cursorlineopt'
1126 // contains "screenline"
1127 int left_curline_col = 0;
1128 int right_curline_col = 0;
1129#endif
1130
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1132 int feedback_col = 0;
1133 int feedback_old_attr = -1;
1134#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135
1136#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1137 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001138#endif
1139#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001140 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141#endif
1142#ifdef FEAT_CONCEAL
1143 int syntax_flags = 0;
1144 int syntax_seqnr = 0;
1145 int prev_syntax_id = 0;
1146 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1147 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148 int did_wcol = FALSE;
1149 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001150# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151# define FIX_FOR_BOGUSCOLS \
1152 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001153 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001154 wlv.vcol -= wlv.vcol_off; \
1155 wlv.vcol_off = 0; \
1156 wlv.col -= wlv.boguscols; \
1157 old_boguscols = wlv.boguscols; \
1158 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159 }
1160#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001161# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162#endif
1163
1164 if (startrow > endrow) // past the end already!
1165 return startrow;
1166
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001167 CLEAR_FIELD(wlv);
1168
1169 wlv.lnum = lnum;
1170 wlv.startrow = startrow;
1171 wlv.row = startrow;
1172 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001173 wlv.fromcol = -10;
1174 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001175#ifdef FEAT_LINEBREAK
1176 wlv.vcol_sbr = -1;
1177#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178
1179 if (!number_only)
1180 {
1181 // To speed up the loop below, set extra_check when there is linebreak,
1182 // trailing white space and/or syntax processing to be done.
1183#ifdef FEAT_LINEBREAK
1184 extra_check = wp->w_p_lbr;
1185#endif
1186#ifdef FEAT_SYN_HL
1187 if (syntax_present(wp) && !wp->w_s->b_syn_error
1188# ifdef SYN_TIME_LIMIT
1189 && !wp->w_s->b_syn_slow
1190# endif
1191 )
1192 {
1193 // Prepare for syntax highlighting in this line. When there is an
1194 // error, stop syntax highlighting.
1195 save_did_emsg = did_emsg;
1196 did_emsg = FALSE;
1197 syntax_start(wp, lnum);
1198 if (did_emsg)
1199 wp->w_s->b_syn_error = TRUE;
1200 else
1201 {
1202 did_emsg = save_did_emsg;
1203#ifdef SYN_TIME_LIMIT
1204 if (!wp->w_s->b_syn_slow)
1205#endif
1206 {
1207 has_syntax = TRUE;
1208 extra_check = TRUE;
1209 }
1210 }
1211 }
1212
1213 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001214 wlv.color_cols = wp->w_p_cc_cols;
1215 if (wlv.color_cols != NULL)
1216 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217#endif
1218
1219#ifdef FEAT_TERMINAL
1220 if (term_show_buffer(wp->w_buffer))
1221 {
1222 extra_check = TRUE;
1223 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001224 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 }
1226#endif
1227
1228#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001229 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230 {
1231 // Prepare for spell checking.
1232 has_spell = TRUE;
1233 extra_check = TRUE;
1234
1235 // Get the start of the next line, so that words that wrap to the
1236 // next line are found too: "et<line-break>al.".
1237 // Trick: skip a few chars for C/shell/Vim comments
1238 nextline[SPWORDLEN] = NUL;
1239 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1240 {
1241 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1242 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1243 }
1244
1245 // When a word wrapped from the previous line the start of the
1246 // current line is valid.
1247 if (lnum == checked_lnum)
1248 cur_checked_col = checked_col;
1249 checked_lnum = 0;
1250
1251 // When there was a sentence end in the previous line may require a
1252 // word starting with capital in this line. In line 1 always check
1253 // the first word.
1254 if (lnum != capcol_lnum)
1255 cap_col = -1;
1256 if (lnum == 1)
1257 cap_col = 0;
1258 capcol_lnum = 0;
1259 }
1260#endif
1261
1262 // handle Visual active in this window
1263 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1264 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001265 pos_T *top, *bot;
1266
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1268 {
1269 // Visual is after curwin->w_cursor
1270 top = &curwin->w_cursor;
1271 bot = &VIsual;
1272 }
1273 else
1274 {
1275 // Visual is before curwin->w_cursor
1276 top = &VIsual;
1277 bot = &curwin->w_cursor;
1278 }
1279 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1280 if (VIsual_mode == Ctrl_V)
1281 {
1282 // block mode
1283 if (lnum_in_visual_area)
1284 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001285 wlv.fromcol = wp->w_old_cursor_fcol;
1286 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287 }
1288 }
1289 else
1290 {
1291 // non-block mode
1292 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001293 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 else if (lnum == top->lnum)
1295 {
1296 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001297 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 else
1299 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001300 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001302 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 }
1304 }
1305 if (VIsual_mode != 'V' && lnum == bot->lnum)
1306 {
1307 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1308 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001309 wlv.fromcol = -10;
1310 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 }
1312 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001313 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 else
1315 {
1316 pos = *bot;
1317 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001318 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1319 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 else
1321 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001322 getvvcol(wp, &pos, NULL, NULL,
1323 (colnr_T *)&wlv.tocol);
1324 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 }
1326 }
1327 }
1328 }
1329
1330 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001331 if (!highlight_match && lnum == curwin->w_cursor.lnum
1332 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333#ifdef FEAT_GUI
1334 && !gui.in_use
1335#endif
1336 )
1337 noinvcur = TRUE;
1338
1339 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001340 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 {
1342 area_highlighting = TRUE;
1343 vi_attr = HL_ATTR(HLF_V);
1344#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1345 if ((clip_star.available && !clip_star.owned
1346 && clip_isautosel_star())
1347 || (clip_plus.available && !clip_plus.owned
1348 && clip_isautosel_plus()))
1349 vi_attr = HL_ATTR(HLF_VNC);
1350#endif
1351 }
1352 }
1353
1354 // handle 'incsearch' and ":s///c" highlighting
1355 else if (highlight_match
1356 && wp == curwin
1357 && lnum >= curwin->w_cursor.lnum
1358 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1359 {
1360 if (lnum == curwin->w_cursor.lnum)
1361 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001362 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001364 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1366 {
1367 pos.lnum = lnum;
1368 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001369 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 }
1371 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001372 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001374 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1375 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001376 area_highlighting = TRUE;
1377 vi_attr = HL_ATTR(HLF_I);
1378 }
1379 }
1380
1381#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001382 wlv.filler_lines = diff_check(wp, lnum);
1383 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001385 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 {
1387 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001388 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001390 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001392 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393 }
1394 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001395 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001396 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 area_highlighting = TRUE;
1398 }
1399 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001400 wlv.filler_lines = wp->w_topfill;
1401 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402#endif
1403
1404#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001405 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001406 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001407 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408#endif
1409
1410#ifdef LINE_ATTR
1411# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001412 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001414 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415# endif
1416# if defined(FEAT_QUICKFIX)
1417 // Highlight the current line in the quickfix window.
1418 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001419 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001421 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 area_highlighting = TRUE;
1423#endif
1424
1425 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1426 ptr = line;
1427
1428#ifdef FEAT_SPELL
1429 if (has_spell && !number_only)
1430 {
1431 // For checking first word with a capital skip white space.
1432 if (cap_col == 0)
1433 cap_col = getwhitecols(line);
1434
1435 // To be able to spell-check over line boundaries copy the end of the
1436 // current line into nextline[]. Above the start of the next line was
1437 // copied to nextline[SPWORDLEN].
1438 if (nextline[SPWORDLEN] == NUL)
1439 {
1440 // No next line or it is empty.
1441 nextlinecol = MAXCOL;
1442 nextline_idx = 0;
1443 }
1444 else
1445 {
1446 v = (long)STRLEN(line);
1447 if (v < SPWORDLEN)
1448 {
1449 // Short line, use it completely and append the start of the
1450 // next line.
1451 nextlinecol = 0;
1452 mch_memmove(nextline, line, (size_t)v);
1453 STRMOVE(nextline + v, nextline + SPWORDLEN);
1454 nextline_idx = v + 1;
1455 }
1456 else
1457 {
1458 // Long line, use only the last SPWORDLEN bytes.
1459 nextlinecol = v - SPWORDLEN;
1460 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1461 nextline_idx = SPWORDLEN + 1;
1462 }
1463 }
1464 }
1465#endif
1466
1467 if (wp->w_p_list)
1468 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001469 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001470 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001471 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001472 || wp->w_lcs_chars.trail
1473 || wp->w_lcs_chars.lead
1474 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001476
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001478 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 {
1480 trailcol = (colnr_T)STRLEN(ptr);
1481 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1482 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001483 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001485 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001486 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001487 {
1488 leadcol = 0;
1489 while (VIM_ISWHITE(ptr[leadcol]))
1490 ++leadcol;
1491 if (ptr[leadcol] == NUL)
1492 // in a line full of spaces all of them are treated as trailing
1493 leadcol = (colnr_T)0;
1494 else
1495 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001496 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001497 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 }
1499
Bram Moolenaard7657e92022-09-20 18:59:30 +01001500 wlv.wcr_attr = get_wcr_attr(wp);
1501 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001503 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001504 area_highlighting = TRUE;
1505 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001506
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001507#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001509 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510#endif
1511
1512 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1513 // first character to be displayed.
1514 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001515 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001516 else
1517 v = wp->w_leftcol;
1518 if (v > 0 && !number_only)
1519 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001520 char_u *prev_ptr = ptr;
1521 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001522 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001523
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001524 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001525 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001527 charsize = win_lbr_chartabsize(&cts, NULL);
1528 cts.cts_vcol += charsize;
1529 prev_ptr = cts.cts_ptr;
1530 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001532 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001533 ptr = cts.cts_ptr;
1534 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535
1536 // When:
1537 // - 'cuc' is set, or
1538 // - 'colorcolumn' is set, or
1539 // - 'virtualedit' is set, or
1540 // - the visual mode is active,
1541 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001542 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001544 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545#endif
1546 virtual_active() ||
1547 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001548 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549
1550 // Handle a character that's not completely on the screen: Put ptr at
1551 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001552 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001554 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555 ptr = prev_ptr;
1556 // If the character fits on the screen, don't need to skip it.
1557 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001558 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1559 && wlv.col == 0)
1560 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 }
1562
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001563#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001564 // If there the text doesn't reach to the desired column, need to skip
1565 // "skip_cells" cells when virtual text follows.
1566 if (!wp->w_p_wrap && v > wlv.vcol)
1567 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001568#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001569
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 // Adjust for when the inverted text is before the screen,
1571 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001572 if (wlv.tocol <= wlv.vcol)
1573 wlv.fromcol = 0;
1574 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1575 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576
1577#ifdef FEAT_LINEBREAK
1578 // When w_skipcol is non-zero, first line needs 'showbreak'
1579 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001580 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001581#endif
1582#ifdef FEAT_SPELL
1583 // When spell checking a word we need to figure out the start of the
1584 // word and if it's badly spelled or not.
1585 if (has_spell)
1586 {
1587 int len;
1588 colnr_T linecol = (colnr_T)(ptr - line);
1589 hlf_T spell_hlf = HLF_COUNT;
1590
1591 pos = wp->w_cursor;
1592 wp->w_cursor.lnum = lnum;
1593 wp->w_cursor.col = linecol;
1594 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1595
1596 // spell_move_to() may call ml_get() and make "line" invalid
1597 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1598 ptr = line + linecol;
1599
1600 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1601 {
1602 // no bad word found at line start, don't check until end of a
1603 // word
1604 spell_hlf = HLF_COUNT;
1605 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1606 }
1607 else
1608 {
1609 // bad word found, use attributes until end of word
1610 word_end = wp->w_cursor.col + len + 1;
1611
1612 // Turn index into actual attributes.
1613 if (spell_hlf != HLF_COUNT)
1614 spell_attr = highlight_attr[spell_hlf];
1615 }
1616 wp->w_cursor = pos;
1617
1618# ifdef FEAT_SYN_HL
1619 // Need to restart syntax highlighting for this line.
1620 if (has_syntax)
1621 syntax_start(wp, lnum);
1622# endif
1623 }
1624#endif
1625 }
1626
1627 // Correct highlighting for cursor that can't be disabled.
1628 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001629 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 {
1631 if (noinvcur)
1632 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001633 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 {
1635 // highlighting starts at cursor, let it start just after the
1636 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001637 fromcol_prev = wlv.fromcol;
1638 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001639 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001640 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 // restart highlighting after the cursor
1642 fromcol_prev = wp->w_virtcol;
1643 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001644 if (wlv.fromcol >= wlv.tocol)
1645 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 }
1647
1648#ifdef FEAT_SEARCH_EXTRA
1649 if (!number_only)
1650 {
1651 v = (long)(ptr - line);
1652 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1653 &line, &screen_search_hl,
1654 &search_attr);
1655 ptr = line + v; // "line" may have been updated
1656 }
1657#endif
1658
1659#ifdef FEAT_SYN_HL
1660 // Cursor line highlighting for 'cursorline' in the current window.
1661 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1662 {
1663 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001664 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 if (!(wp == curwin && VIsual_active)
1666 && wp->w_p_culopt_flags != CULOPT_NBR)
1667 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001668 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1670
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001671 // Only set wlv.line_attr here when "screenline" is not present in
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001673 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001675 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001676# ifdef FEAT_SIGNS
1677 // Combine the 'cursorline' and sign highlighting, depending on
1678 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001679 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001680 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001681 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001682 wlv.line_attr = hl_combine_attr(
1683 wlv.cul_attr, wlv.line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001684 else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001685 wlv.line_attr = hl_combine_attr(
1686 wlv.line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001687 }
1688 else
1689# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001690# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001691 // let the line attribute overrule 'cursorline', otherwise
1692 // it disappears when both have background set;
1693 // 'cursorline' can use underline or bold to make it show
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001694 wlv.line_attr = hl_combine_attr(
1695 wlv.cul_attr, wlv.line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001696# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001697 wlv.line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001698# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 }
1700 else
1701 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001702 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1704 }
1705 area_highlighting = TRUE;
1706 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 }
1708#endif
1709
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001710#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 {
1712 char_u *prop_start;
1713
1714 text_prop_count = get_text_props(wp->w_buffer, lnum,
1715 &prop_start, FALSE);
1716 if (text_prop_count > 0)
1717 {
1718 // Make a copy of the properties, so that they are properly
1719 // aligned.
1720 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1721 if (text_props != NULL)
1722 mch_memmove(text_props, prop_start,
1723 text_prop_count * sizeof(textprop_T));
1724
1725 // Allocate an array for the indexes.
1726 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001727 if (text_prop_idxs == NULL)
1728 VIM_CLEAR(text_props);
1729
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001730 if (text_props != NULL)
1731 {
1732 area_highlighting = TRUE;
1733 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001734 // text props "above" move the line number down to where the
1735 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001736 for (int i = 0; i < text_prop_count; ++i)
1737 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1738 ++wlv.text_prop_above_count;
1739 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 }
1741 }
1742#endif
1743
Bram Moolenaar1306b362022-08-06 15:59:06 +01001744 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745
1746 // Repeat for the whole displayed line.
1747 for (;;)
1748 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001749 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001751 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752#endif
1753#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001754 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001756
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001760#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001761 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001762 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001763 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001764 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001765 }
1766#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001767 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 if (cmdwin_type != 0 && wp == curwin)
1771 {
1772 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001773 wlv.n_extra = 1;
1774 wlv.c_extra = cmdwin_type;
1775 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001776 wlv.char_attr =
1777 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 }
1779 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001781 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001783 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001784 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 }
1786#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001788 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001790 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001791 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001793 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 }
1795#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001796 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001798 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001800 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001803 // Check if 'breakindent' applies and show it.
1804 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1805 if (wlv.n_extra == 0)
1806 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001807#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001809 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001811 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001812 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 }
1814#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001815 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001817 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001818 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 }
1820 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001821
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001823 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001824 && wlv.vcol >= left_curline_col
1825 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001827 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001828 wlv.line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 }
1830#endif
1831
1832 // When still displaying '$' of change command, stop at cursor.
1833 // When only displaying the (relative) line number and that's done,
1834 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001835 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001836 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001837 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001839 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840#endif
1841 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001843 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 // Pretend we have finished updating the window. Except when
1845 // 'cursorcolumn' is set.
1846#ifdef FEAT_SYN_HL
1847 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001848 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 else
1850#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001851 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 break;
1853 }
1854
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 {
1857 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001858 if (wlv.vcol == wlv.fromcol
1859 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1860 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 && (*mb_ptr2cells)(ptr) > 1)
1862 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001863 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001864 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 area_attr = vi_attr; // start highlighting
1866 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001867 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001868 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001869 area_attr = 0; // stop highlighting
1870
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001871#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872 if (text_props != NULL)
1873 {
1874 int pi;
1875 int bcol = (int)(ptr - line);
1876
Bram Moolenaar1306b362022-08-06 15:59:06 +01001877 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001878# ifdef FEAT_LINEBREAK
1879 && !in_linebreak
1880# endif
1881 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 --bcol; // still working on the previous char, e.g. Tab
1883
1884 // Check if any active property ends.
1885 for (pi = 0; pi < text_props_active; ++pi)
1886 {
1887 int tpi = text_prop_idxs[pi];
1888
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001889 if (text_props[tpi].tp_col != MAXCOL
1890 && bcol >= text_props[tpi].tp_col - 1
1891 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 {
1893 if (pi + 1 < text_props_active)
1894 mch_memmove(text_prop_idxs + pi,
1895 text_prop_idxs + pi + 1,
1896 sizeof(int)
1897 * (text_props_active - (pi + 1)));
1898 --text_props_active;
1899 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001900# ifdef FEAT_LINEBREAK
1901 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001902 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001903 syntax_attr = 0;
1904# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 }
1906 }
1907
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001908# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001909 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001910 // not on the next char yet, don't start another prop
1911 --bcol;
1912# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001914 // With 'nowrap' and not in the first screen line only "below"
1915 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001917 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001918 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001919 && (wp->w_p_wrap
1920 || wlv.row == startrow
1921 || (text_props[text_prop_next].tp_flags
1922 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001923 || (bcol == 0 &&
1924 (text_props[text_prop_next].tp_flags
1925 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001926 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001927 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001928 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001929 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1930 {
1931 // first display the '$' after the line
1932 text_prop_follows = TRUE;
1933 break;
1934 }
1935 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001936 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001937 + text_props[text_prop_next].tp_len)
1938 text_prop_idxs[text_props_active++] = text_prop_next;
1939 ++text_prop_next;
1940 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001942 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001943 {
1944 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001945 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001946 text_prop_flags = 0;
1947 text_prop_type = NULL;
1948 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001949 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001950 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001951 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001952 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001953 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001954 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001955 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001956
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957 // Sort the properties on priority and/or starting last.
1958 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001959 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001960 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001961 sort_text_props(wp->w_buffer, text_props,
1962 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963
1964 for (pi = 0; pi < text_props_active; ++pi)
1965 {
1966 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001967 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001969 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970
Bram Moolenaarcd105412022-10-10 19:50:42 +01001971 // Only use a text property that can be displayed.
1972 // Skip "after" properties when wrap is off and at the
1973 // end of the window.
1974 if (pt != NULL
1975 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1976 && tp->tp_id != -MAXCOL
1977 && !(tp->tp_id < 0
1978 && !wp->w_p_wrap
1979 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1980 | TP_FLAG_ALIGN_ABOVE
1981 | TP_FLAG_ALIGN_BELOW)) == 0
1982 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001984 if (pt->pt_hl_id > 0)
1985 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986 text_prop_type = pt;
1987 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001988 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001989 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001990 text_prop_flags = pt->pt_flags;
1991 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001992 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993 }
1994 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001995 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001996 && -text_prop_id
1997 <= wp->w_buffer->b_textprop_text.ga_len)
1998 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001999 textprop_T *tp = &text_props[used_tpi];
2000 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002001 ->b_textprop_text.ga_data)[
2002 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002003 int above = (tp->tp_flags
2004 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002005 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002006
2007 // reset the ID in the copy to avoid it being used
2008 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002009 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002010
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002011 if (p != NULL)
2012 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002013 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002014 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002015 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002016 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002017 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2018 int padding = tp->tp_col == MAXCOL
2019 && tp->tp_len > 1
2020 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002021
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002022 // Insert virtual text before the current
2023 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002024 wlv.p_extra = p;
2025 wlv.c_extra = NUL;
2026 wlv.c_final = NUL;
2027 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002028 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002029 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2030 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002031 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002032 // restore search_attr and area_attr when n_extra
2033 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002034 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002035 saved_area_attr = area_attr;
2036 search_attr = 0;
2037 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002038 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002039 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040 if (*ptr == NUL)
2041 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002042 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002043#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002044 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002045 {
2046 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002047 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002048 wlv.need_showbreak = FALSE;
2049 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002050 }
2051#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002052 if ((right || above || below || !wrap
2053 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002054 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002055 char_u *prev_p_extra = wlv.p_extra;
2056 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002057
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002058 // Take care of padding, right-align and
2059 // truncation.
2060 // Shared with win_lbr_chartabsize(), must do
2061 // exactly the same.
2062 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002063 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002064 wlv.col,
2065 &wlv.n_extra, &wlv.p_extra,
2066 &n_attr, &n_attr_skip);
2067 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002068 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002069 // wlv.p_extra was allocated
2070 vim_free(p_extra_free2);
2071 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002072 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002073
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002074 if (lcs_eol_one < 0
2075 && wp->w_p_wrap
2076 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002077 + wlv.n_extra - 2 > wp->w_width)
2078 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002079 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002080
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002081 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002082 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002083 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002084 {
2085 draw_screen_line(wp, &wlv);
2086
2087 // When line got too long for screen break
2088 // here.
2089 if (wlv.row == endrow)
2090 {
2091 ++wlv.row;
2092 break;
2093 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002094 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002095 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002096 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002097 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002098 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002099
Bram Moolenaarcd105412022-10-10 19:50:42 +01002100 // If the text didn't reach until the first window
2101 // column we need to skip cells.
2102 if (skip_cells > 0)
2103 {
2104 if (wlv.n_extra > skip_cells)
2105 {
2106 wlv.n_extra -= skip_cells;
2107 wlv.p_extra += skip_cells;
2108 n_attr_skip -= skip_cells;
2109 if (n_attr_skip < 0)
2110 n_attr_skip = 0;
2111 skip_cells = 0;
2112 }
2113 else
2114 {
2115 // the whole text is left of the window, drop
2116 // it and advance to the next one
2117 skip_cells -= wlv.n_extra;
2118 wlv.n_extra = 0;
2119 n_attr_skip = 0;
2120 bail_out = TRUE;
2121 }
2122 }
2123
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002124 // If another text prop follows the condition below at
2125 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002126 // If this is an "above" text prop and 'nowrap' the we
2127 // must wrap anyway.
2128 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002129 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002130 && (wp->w_p_wrap
2131 || (text_props[other_tpi].tp_flags
2132 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002133
2134 if (bail_out)
2135 // starting a new line for "below"
2136 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002137 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002139 else if (text_prop_next < text_prop_count
2140 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002141 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2142 || (!wp->w_p_wrap
2143 && wlv.col == wp->w_width - 1
2144 && (text_props[text_prop_next].tp_flags
2145 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002146 // When at last-but-one character and a text property
2147 // follows after it, we may need to flush the line after
2148 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002149 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002150 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 }
2152#endif
2153
Bram Moolenaare38fc862022-08-11 17:24:50 +01002154#ifdef FEAT_SEARCH_EXTRA
2155 if (wlv.n_extra == 0)
2156 {
2157 // Check for start/end of 'hlsearch' and other matches.
2158 // After end, check for start/end of next match.
2159 // When another match, have to check for start again.
2160 v = (long)(ptr - line);
2161 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2162 &screen_search_hl, &has_match_conc,
2163 &match_conc, did_line_attr, lcs_eol_one,
2164 &on_last_col);
2165 ptr = line + v; // "line" may have been changed
2166 prev_ptr = ptr;
2167
2168 // Do not allow a conceal over EOL otherwise EOL will be missed
2169 // and bad things happen.
2170 if (*ptr == NUL)
2171 has_match_conc = 0;
2172 }
2173#endif
2174
2175#ifdef FEAT_DIFF
2176 if (wlv.diff_hlf != (hlf_T)0)
2177 {
2178 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2179 && wlv.n_extra == 0)
2180 wlv.diff_hlf = HLF_TXD; // changed text
2181 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2182 && wlv.n_extra == 0)
2183 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002184 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002185 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2186 && wp->w_p_culopt_flags != CULOPT_NBR
2187 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2188 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002189 wlv.line_attr = hl_combine_attr(
2190 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002191 }
2192#endif
2193
Bram Moolenaara74fda62019-10-19 17:38:03 +02002194#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002195 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002196 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002197 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002198# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002199 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002200 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002201# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002202 // Get syntax attribute.
2203 if (has_syntax)
2204 {
2205 // Get the syntax attribute for the character. If there
2206 // is an error, disable syntax highlighting.
2207 save_did_emsg = did_emsg;
2208 did_emsg = FALSE;
2209
2210 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002211 if (v == prev_syntax_col)
2212 // at same column again
2213 syntax_attr = prev_syntax_attr;
2214 else
2215 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002216# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002217 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002218# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002219 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002220# ifdef FEAT_SPELL
2221 has_spell ? &can_spell :
2222# endif
2223 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002224 prev_syntax_col = v;
2225 prev_syntax_attr = syntax_attr;
2226 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002227
Bram Moolenaar34390282019-10-16 14:38:26 +02002228 if (did_emsg)
2229 {
2230 wp->w_s->b_syn_error = TRUE;
2231 has_syntax = FALSE;
2232 syntax_attr = 0;
2233 }
2234 else
2235 did_emsg = save_did_emsg;
2236# ifdef SYN_TIME_LIMIT
2237 if (wp->w_s->b_syn_slow)
2238 has_syntax = FALSE;
2239# endif
2240
2241 // Need to get the line again, a multi-line regexp may
2242 // have made it invalid.
2243 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2244 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002245 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002246# ifdef FEAT_CONCEAL
2247 // no concealing past the end of the line, it interferes
2248 // with line highlighting
2249 if (*ptr == NUL)
2250 syntax_flags = 0;
2251 else
2252 syntax_flags = get_syntax_info(&syntax_seqnr);
2253# endif
2254 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002255 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002256# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002257 // Combine text property highlight into syntax highlight.
2258 if (text_prop_type != NULL)
2259 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002260 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002261 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2262 else
2263 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002264 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002265 }
2266# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002267#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002268
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 // Decide which of the highlight attributes to use.
2270 attr_pri = TRUE;
2271#ifdef LINE_ATTR
2272 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002273 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002274 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002275 if (!highlight_match)
2276 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002277 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002278# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002279 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002280# endif
2281 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002283 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002284 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002285# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002286 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002287# endif
2288 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002289 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002290 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2291 || wlv.vcol < wlv.fromcol
2292 || vcol_prev < fromcol_prev
2293 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002295 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002297# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002298 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002299# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002300 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002301# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002302 attr_pri = FALSE;
2303 }
2304#else
2305 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002306 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002307 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002308 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309#endif
2310 else
2311 {
2312 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002313#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002314 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002315#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002316 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002317#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002319#ifdef FEAT_PROP_POPUP
2320 // override with text property highlight when "override" is TRUE
2321 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002322 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002323#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002324 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002325
2326 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002327 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002328 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002329 if (wlv.char_attr == 0)
2330 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002331 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002332 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002333 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002334
2335 // Get the next character to put on the screen.
2336
2337 // The "p_extra" points to the extra stuff that is inserted to
2338 // represent special characters (non-printable stuff) and other
2339 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002340 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2342 // "p_extra[n_extra]".
2343 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002344 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002346 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002348 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2349 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002350 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2351 if (enc_utf8 && utf_char2len(c) > 1)
2352 {
2353 mb_utf8 = TRUE;
2354 u8cc[0] = 0;
2355 c = 0xc0;
2356 }
2357 else
2358 mb_utf8 = FALSE;
2359 }
2360 else
2361 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002362 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363 if (has_mbyte)
2364 {
2365 mb_c = c;
2366 if (enc_utf8)
2367 {
2368 // If the UTF-8 character is more than one byte:
2369 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002371 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 mb_l = 1;
2374 else if (mb_l > 1)
2375 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002376 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002377 mb_utf8 = TRUE;
2378 c = 0xc0;
2379 }
2380 }
2381 else
2382 {
2383 // if this is a DBCS character, put it in "mb_c"
2384 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002385 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386 mb_l = 1;
2387 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002388 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389 }
2390 if (mb_l == 0) // at the NUL at end-of-line
2391 mb_l = 1;
2392
2393 // If a double-width char doesn't fit display a '>' in the
2394 // last column.
2395 if ((
2396# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002397 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002399 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 && (*mb_char2cells)(mb_c) == 2)
2401 {
2402 c = '>';
2403 mb_c = c;
2404 mb_l = 1;
2405 mb_utf8 = FALSE;
2406 multi_attr = HL_ATTR(HLF_AT);
2407#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002408 if (wlv.cul_attr)
2409 multi_attr = hl_combine_attr(
2410 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002411#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002412 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002413
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 // put the pointer back to output the double-width
2415 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002416 ++wlv.n_extra;
2417 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002418 }
2419 else
2420 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002421 wlv.n_extra -= mb_l - 1;
2422 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 }
2424 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002425 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002427 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002428#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002429 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002430 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002431 // Only restore search_attr and area_attr after "n_extra" in
2432 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002433 if (wlv.saved_n_extra <= 0)
2434 {
2435 if (search_attr == 0)
2436 search_attr = saved_search_attr;
2437 if (area_attr == 0 && *ptr != NUL)
2438 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002439
2440 if (wlv.extra_for_textprop)
2441 // wlv.extra_attr should be used at this position but
2442 // not any further.
2443 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002444 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002445
2446 wlv.extra_for_textprop = FALSE;
2447 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002448 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002449#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 }
2451 else
2452 {
2453#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002454 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002456 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 // Get a character from the line itself.
2459 c = *ptr;
2460#ifdef FEAT_LINEBREAK
2461 c0 = *ptr;
2462#endif
2463 if (has_mbyte)
2464 {
2465 mb_c = c;
2466 if (enc_utf8)
2467 {
2468 // If the UTF-8 character is more than one byte: Decode it
2469 // into "mb_c".
2470 mb_l = utfc_ptr2len(ptr);
2471 mb_utf8 = FALSE;
2472 if (mb_l > 1)
2473 {
2474 mb_c = utfc_ptr2char(ptr, u8cc);
2475 // Overlong encoded ASCII or ASCII with composing char
2476 // is displayed normally, except a NUL.
2477 if (mb_c < 0x80)
2478 {
2479 c = mb_c;
2480#ifdef FEAT_LINEBREAK
2481 c0 = mb_c;
2482#endif
2483 }
2484 mb_utf8 = TRUE;
2485
2486 // At start of the line we can have a composing char.
2487 // Draw it as a space with a composing char.
2488 if (utf_iscomposing(mb_c))
2489 {
2490 int i;
2491
2492 for (i = Screen_mco - 1; i > 0; --i)
2493 u8cc[i] = u8cc[i - 1];
2494 u8cc[0] = mb_c;
2495 mb_c = ' ';
2496 }
2497 }
2498
2499 if ((mb_l == 1 && c >= 0x80)
2500 || (mb_l >= 1 && mb_c == 0)
2501 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2502 {
2503 // Illegal UTF-8 byte: display as <xx>.
2504 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002505 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506# ifdef FEAT_RIGHTLEFT
2507 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002508 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002510 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002511 c = *wlv.p_extra;
2512 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002514 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2515 wlv.c_extra = NUL;
2516 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002517 if (area_attr == 0 && search_attr == 0)
2518 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002519 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002520 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002521 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002522 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523 }
2524 }
2525 else if (mb_l == 0) // at the NUL at end-of-line
2526 mb_l = 1;
2527#ifdef FEAT_ARABIC
2528 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2529 {
2530 // Do Arabic shaping.
2531 int pc, pc1, nc;
2532 int pcc[MAX_MCO];
2533
2534 // The idea of what is the previous and next
2535 // character depends on 'rightleft'.
2536 if (wp->w_p_rl)
2537 {
2538 pc = prev_c;
2539 pc1 = prev_c1;
2540 nc = utf_ptr2char(ptr + mb_l);
2541 prev_c1 = u8cc[0];
2542 }
2543 else
2544 {
2545 pc = utfc_ptr2char(ptr + mb_l, pcc);
2546 nc = prev_c;
2547 pc1 = pcc[0];
2548 }
2549 prev_c = mb_c;
2550
2551 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2552 }
2553 else
2554 prev_c = mb_c;
2555#endif
2556 }
2557 else // enc_dbcs
2558 {
2559 mb_l = MB_BYTE2LEN(c);
2560 if (mb_l == 0) // at the NUL at end-of-line
2561 mb_l = 1;
2562 else if (mb_l > 1)
2563 {
2564 // We assume a second byte below 32 is illegal.
2565 // Hopefully this is OK for all double-byte encodings!
2566 if (ptr[1] >= 32)
2567 mb_c = (c << 8) + ptr[1];
2568 else
2569 {
2570 if (ptr[1] == NUL)
2571 {
2572 // head byte at end of line
2573 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002574 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 }
2576 else
2577 {
2578 // illegal tail byte
2579 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002580 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002582 wlv.p_extra = wlv.extra;
2583 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002584 wlv.c_extra = NUL;
2585 wlv.c_final = NUL;
2586 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002587 if (area_attr == 0 && search_attr == 0)
2588 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002590 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002591 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002592 // save current attr
2593 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 }
2595 mb_c = c;
2596 }
2597 }
2598 }
2599 // If a double-width char doesn't fit display a '>' in the
2600 // last column; the character is displayed at the start of the
2601 // next line.
2602 if ((
2603# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002604 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002606 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 && (*mb_char2cells)(mb_c) == 2)
2608 {
2609 c = '>';
2610 mb_c = c;
2611 mb_utf8 = FALSE;
2612 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002613 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 // Put pointer back so that the character will be
2615 // displayed at the start of the next line.
2616 --ptr;
2617#ifdef FEAT_CONCEAL
2618 did_decrement_ptr = TRUE;
2619#endif
2620 }
2621 else if (*ptr != NUL)
2622 ptr += mb_l - 1;
2623
2624 // If a double-width char doesn't fit at the left side display
2625 // a '<' in the first column. Don't do this for unprintable
2626 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002627 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002629 wlv.n_extra = 1;
2630 wlv.c_extra = MB_FILLER_CHAR;
2631 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632 c = ' ';
2633 if (area_attr == 0 && search_attr == 0)
2634 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002635 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002636 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002637 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002638 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 }
2640 mb_c = c;
2641 mb_utf8 = FALSE;
2642 mb_l = 1;
2643 }
2644
2645 }
2646 ++ptr;
2647
2648 if (extra_check)
2649 {
2650#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 // Check spelling (unless at the end of the line).
2652 // Only do this when there is no syntax highlighting, the
2653 // @Spell cluster is not used or the current syntax item
2654 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002655 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656 if (has_spell && v >= word_end && v > cur_checked_col)
2657 {
2658 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002659 // do not calculate cap_col at the end of the line or when
2660 // only white space is following
2661 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662# ifdef FEAT_SYN_HL
2663 !has_syntax ||
2664# endif
2665 can_spell))
2666 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002667 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 int len;
2669 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002670
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673
2674 // Use nextline[] if possible, it has the start of the
2675 // next line concatenated.
2676 if ((prev_ptr - line) - nextlinecol >= 0)
2677 p = nextline + (prev_ptr - line) - nextlinecol;
2678 else
2679 p = prev_ptr;
2680 cap_col -= (int)(prev_ptr - line);
2681 len = spell_check(wp, p, &spell_hlf, &cap_col,
2682 nochange);
2683 word_end = v + len;
2684
2685 // In Insert mode only highlight a word that
2686 // doesn't touch the cursor.
2687 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002688 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 && wp->w_cursor.lnum == lnum
2690 && wp->w_cursor.col >=
2691 (colnr_T)(prev_ptr - line)
2692 && wp->w_cursor.col < (colnr_T)word_end)
2693 {
2694 spell_hlf = HLF_COUNT;
2695 spell_redraw_lnum = lnum;
2696 }
2697
2698 if (spell_hlf == HLF_COUNT && p != prev_ptr
2699 && (p - nextline) + len > nextline_idx)
2700 {
2701 // Remember that the good word continues at the
2702 // start of the next line.
2703 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002704 checked_col = (int)((p - nextline)
2705 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706 }
2707
2708 // Turn index into actual attributes.
2709 if (spell_hlf != HLF_COUNT)
2710 spell_attr = highlight_attr[spell_hlf];
2711
2712 if (cap_col > 0)
2713 {
2714 if (p != prev_ptr
2715 && (p - nextline) + cap_col >= nextline_idx)
2716 {
2717 // Remember that the word in the next line
2718 // must start with a capital.
2719 capcol_lnum = lnum + 1;
2720 cap_col = (int)((p - nextline) + cap_col
2721 - nextline_idx);
2722 }
2723 else
2724 // Compute the actual column.
2725 cap_col += (int)(prev_ptr - line);
2726 }
2727 }
2728 }
2729 if (spell_attr != 0)
2730 {
2731 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002732 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2733 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002735 wlv.char_attr = hl_combine_attr(spell_attr,
2736 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 }
2738#endif
2739#ifdef FEAT_LINEBREAK
2740 // Found last space before word: check for line break.
2741 if (wp->w_p_lbr && c0 == c
2742 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2743 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002744 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2745 : 0;
2746 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002747 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002749 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002750# ifdef FEAT_PROP_POPUP
2751 // do not want virtual text counted here
2752 cts.cts_has_prop_with_text = FALSE;
2753# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002754 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002755 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002756
2757 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002758 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002759 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002760 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2762 if (wlv.n_extra < 0)
2763 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002764 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002765 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002766 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002767 // line break, but for TABs the highlighting should
2768 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002769 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002770
Bram Moolenaar1306b362022-08-06 15:59:06 +01002771 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002773 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002774 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775 wp->w_buffer->b_p_vts_array) - 1;
2776# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002777 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002778 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779# endif
2780
Bram Moolenaar1306b362022-08-06 15:59:06 +01002781 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2782 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002783# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002784 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002785 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002786# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 if (VIM_ISWHITE(c))
2788 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002789# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790 if (c == TAB)
2791 // See "Tab alignment" below.
2792 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002793# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 if (!wp->w_p_list)
2795 c = ' ';
2796 }
2797 }
2798#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002799 in_multispace = c == ' '
2800 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2801 if (!in_multispace)
2802 multispace_pos = 0;
2803
Bram Moolenaareed9d462021-02-15 20:38:25 +01002804 // 'list': Change char 160 to 'nbsp' and space to 'space'
2805 // setting in 'listchars'. But not when the character is
2806 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 if (wp->w_p_list
2808 && ((((c == 160 && mb_l == 1)
2809 || (mb_utf8
2810 && ((mb_c == 160 && mb_l == 2)
2811 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002812 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 || (c == ' '
2814 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002815 && (wp->w_lcs_chars.space
2816 || (in_multispace
2817 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002818 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 && ptr - line <= trailcol)))
2820 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002821 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2822 {
2823 c = wp->w_lcs_chars.multispace[multispace_pos++];
2824 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2825 multispace_pos = 0;
2826 }
2827 else
2828 c = (c == ' ') ? wp->w_lcs_chars.space
2829 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 if (area_attr == 0 && search_attr == 0)
2831 {
2832 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002833 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002834 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002835 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 }
2837 mb_c = c;
2838 if (enc_utf8 && utf_char2len(c) > 1)
2839 {
2840 mb_utf8 = TRUE;
2841 u8cc[0] = 0;
2842 c = 0xc0;
2843 }
2844 else
2845 mb_utf8 = FALSE;
2846 }
2847
zeertzjq2e7cba32022-06-10 15:30:32 +01002848 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2849 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002851 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2852 && wp->w_lcs_chars.leadmultispace != NULL)
2853 {
2854 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002855 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2856 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002857 multispace_pos = 0;
2858 }
2859
2860 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2861 c = wp->w_lcs_chars.trail;
2862
2863 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2864 c = wp->w_lcs_chars.lead;
2865
zeertzjq2e7cba32022-06-10 15:30:32 +01002866 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002867 c = wp->w_lcs_chars.space;
2868
2869
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870 if (!attr_pri)
2871 {
2872 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002873 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002874 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 }
2877 mb_c = c;
2878 if (enc_utf8 && utf_char2len(c) > 1)
2879 {
2880 mb_utf8 = TRUE;
2881 u8cc[0] = 0;
2882 c = 0xc0;
2883 }
2884 else
2885 mb_utf8 = FALSE;
2886 }
2887 }
2888
2889 // Handling of non-printable characters.
2890 if (!vim_isprintc(c))
2891 {
2892 // when getting a character from the file, we may have to
2893 // turn it into something else on the way to putting it
2894 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002895 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002897 int tab_len = 0;
2898 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002900 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002901
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 // only adjust the tab_len, when at the first column
2903 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002904 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002905 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906#endif
2907 // tab amount depends on current column
2908#ifdef FEAT_VARTABS
2909 tab_len = tabstop_padding(vcol_adjusted,
2910 wp->w_buffer->b_p_ts,
2911 wp->w_buffer->b_p_vts_array) - 1;
2912#else
2913 tab_len = (int)wp->w_buffer->b_p_ts
2914 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2915#endif
2916
2917#ifdef FEAT_LINEBREAK
2918 if (!wp->w_p_lbr || !wp->w_p_list)
2919#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002920 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002922 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002923 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002924#ifdef FEAT_LINEBREAK
2925 else
2926 {
2927 char_u *p;
2928 int len;
2929 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002930 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002932# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002933 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002935 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002936
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002938 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002939 && old_boguscols > 0
2940 && wlv.n_extra > tab_len)
2941 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002942# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002943 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002945 // If wlv.n_extra > 0, it gives the number of chars
2946 // to use for a tab, else we need to calculate the
2947 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002948 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2949 len = tab_len * tab2_len;
2950 if (wp->w_lcs_chars.tab3)
2951 len += mb_char2len(wp->w_lcs_chars.tab3)
2952 - tab2_len;
2953 if (wlv.n_extra > 0)
2954 len += wlv.n_extra - tab_len;
2955 c = wp->w_lcs_chars.tab1;
2956 p = alloc(len + 1);
2957 if (p == NULL)
2958 wlv.n_extra = 0;
2959 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002961 vim_memset(p, ' ', len);
2962 p[len] = NUL;
2963 vim_free(wlv.p_extra_free);
2964 wlv.p_extra_free = p;
2965 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002966 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002967 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002968
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002969 if (*p == NUL)
2970 {
2971 tab_len = i;
2972 break;
2973 }
2974
2975 // if tab3 is given, use it for the last
2976 // char
2977 if (wp->w_lcs_chars.tab3
2978 && i == tab_len - 1)
2979 lcs = wp->w_lcs_chars.tab3;
2980 p += mb_char2bytes(lcs, p);
2981 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002983 }
2984 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002985# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002986 // n_extra will be increased by
2987 // FIX_FOX_BOGUSCOLS macro below, so need to
2988 // adjust for that here
2989 if (wlv.vcol_off > 0)
2990 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002991# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002992 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 }
2995#endif
2996#ifdef FEAT_CONCEAL
2997 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002998 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999
3000 // Tab alignment should be identical regardless of
3001 // 'conceallevel' value. So tab compensates of all
3002 // previous concealed characters, and thus resets
3003 // vcol_off and boguscols accumulated so far in the
3004 // line. Note that the tab can be longer than
3005 // 'tabstop' when there are concealed characters.
3006 FIX_FOR_BOGUSCOLS;
3007
3008 // Make sure, the highlighting for the tab char will be
3009 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003010 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003011 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003012 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013 tab_len += vc_saved;
3014 }
3015#endif
3016 mb_utf8 = FALSE; // don't draw as UTF-8
3017 if (wp->w_p_list)
3018 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003020 ? wp->w_lcs_chars.tab3
3021 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003023 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003024 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 else
3026#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003027 wlv.c_extra = wp->w_lcs_chars.tab2;
3028 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003030 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003031 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003032 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033 mb_c = c;
3034 if (enc_utf8 && utf_char2len(c) > 1)
3035 {
3036 mb_utf8 = TRUE;
3037 u8cc[0] = 0;
3038 c = 0xc0;
3039 }
3040 }
3041 else
3042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.c_final = NUL;
3044 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 c = ' ';
3046 }
3047 }
3048 else if (c == NUL
3049 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003050 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3051 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 && VIsual_mode != Ctrl_V
3053 && (
3054# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003055 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003057 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 && !(noinvcur
3059 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003060 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061 && lcs_eol_one > 0)
3062 {
3063 // Display a '$' after the line or highlight an extra
3064 // character if the line break is included.
3065#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3066 // For a diff line the highlighting continues after the
3067 // "$".
3068 if (
3069# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071# ifdef LINE_ATTR
3072 &&
3073# endif
3074# endif
3075# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003076 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077# endif
3078 )
3079#endif
3080 {
3081 // In virtualedit, visual selections may extend
3082 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003083 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003084 && wlv.tocol != MAXCOL
3085 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003086 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003087 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003089 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3090 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 else
3092 c = ' ';
3093 lcs_eol_one = -1;
3094 --ptr; // put it back at the NUL
3095 if (!attr_pri)
3096 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003097 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003098 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 n_attr = 1;
3100 }
3101 mb_c = c;
3102 if (enc_utf8 && utf_char2len(c) > 1)
3103 {
3104 mb_utf8 = TRUE;
3105 u8cc[0] = 0;
3106 c = 0xc0;
3107 }
3108 else
3109 mb_utf8 = FALSE; // don't draw as UTF-8
3110 }
3111 else if (c != NUL)
3112 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003113 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3114 if (wlv.n_extra == 0)
3115 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116#ifdef FEAT_RIGHTLEFT
3117 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003118 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003120 wlv.c_extra = NUL;
3121 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122#ifdef FEAT_LINEBREAK
3123 if (wp->w_p_lbr)
3124 {
3125 char_u *p;
3126
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 c = *wlv.p_extra;
3128 p = alloc(wlv.n_extra + 1);
3129 vim_memset(p, ' ', wlv.n_extra);
3130 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3131 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003132 vim_free(wlv.p_extra_free);
3133 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 }
3135 else
3136#endif
3137 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003138 wlv.n_extra = byte2cells(c) - 1;
3139 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 }
3141 if (!attr_pri)
3142 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003143 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003144 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003145 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 }
3148 mb_utf8 = FALSE; // don't draw as UTF-8
3149 }
3150 else if (VIsual_active
3151 && (VIsual_mode == Ctrl_V
3152 || VIsual_mode == 'v')
3153 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003154 && wlv.tocol != MAXCOL
3155 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 && (
3157#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003158 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003160 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 {
3162 c = ' ';
3163 --ptr; // put it back at the NUL
3164 }
3165#if defined(LINE_ATTR)
3166 else if ((
3167# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003168 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169# endif
3170# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003171 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003173 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 ) && (
3175# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003178 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003180 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181# endif
3182 < wp->w_width)))
3183 {
3184 // Highlight until the right side of the window
3185 c = ' ';
3186 --ptr; // put it back at the NUL
3187
3188 // Remember we do the char for line highlighting.
3189 ++did_line_attr;
3190
3191 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003192 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003194 || (wp->w_p_list &&
3195 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003196 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003198 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003200 wlv.diff_hlf = HLF_CHD;
3201 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003203 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3205 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003206 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003207 || (wlv.vcol >= left_curline_col
3208 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 wlv.char_attr = hl_combine_attr(
3210 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 }
3212 }
3213# endif
3214# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003215 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003217 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003218 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3219 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003221 if (!wlv.cul_screenline
3222 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003223 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 wlv.char_attr = hl_combine_attr(
3225 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003227 else if (wlv.line_attr)
3228 wlv.char_attr = hl_combine_attr(
3229 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 }
3231# endif
3232 }
3233#endif
3234 }
3235
3236#ifdef FEAT_CONCEAL
3237 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003238 && (wp != curwin || lnum != wp->w_cursor.lnum
3239 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3241 && !(lnum_in_visual_area
3242 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3243 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003245 if (((prev_syntax_id != syntax_seqnr
3246 && (syntax_flags & HL_CONCEAL) != 0)
3247 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003248 && (syn_get_sub_char() != NUL
3249 || (has_match_conc && match_conc)
3250 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 && wp->w_p_cole != 3)
3252 {
3253 // First time at this concealed item: display one
3254 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003255 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 c = match_conc;
3257 else if (syn_get_sub_char() != NUL)
3258 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003259 else if (wp->w_lcs_chars.conceal != NUL)
3260 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 else
3262 c = ' ';
3263
3264 prev_syntax_id = syntax_seqnr;
3265
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 if (wlv.n_extra > 0)
3267 wlv.vcol_off += wlv.n_extra;
3268 wlv.vcol += wlv.n_extra;
3269 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 {
3271# ifdef FEAT_RIGHTLEFT
3272 if (wp->w_p_rl)
3273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 wlv.col -= wlv.n_extra;
3275 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 }
3277 else
3278# endif
3279 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003280 wlv.boguscols += wlv.n_extra;
3281 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 }
3283 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003284 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 n_attr = 0;
3286 }
3287 else if (n_skip == 0)
3288 {
3289 is_concealing = TRUE;
3290 n_skip = 1;
3291 }
3292 mb_c = c;
3293 if (enc_utf8 && utf_char2len(c) > 1)
3294 {
3295 mb_utf8 = TRUE;
3296 u8cc[0] = 0;
3297 c = 0xc0;
3298 }
3299 else
3300 mb_utf8 = FALSE; // don't draw as UTF-8
3301 }
3302 else
3303 {
3304 prev_syntax_id = 0;
3305 is_concealing = FALSE;
3306 }
3307
3308 if (n_skip > 0 && did_decrement_ptr)
3309 // not showing the '>', put pointer back to avoid getting stuck
3310 ++ptr;
3311
3312#endif // FEAT_CONCEAL
3313 }
3314
3315#ifdef FEAT_CONCEAL
3316 // In the cursor line and we may be concealing characters: correct
3317 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319 && wp == curwin && lnum == wp->w_cursor.lnum
3320 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003321 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003323# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003327# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003328 wp->w_wcol = wlv.col - wlv.boguscols;
3329 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 did_wcol = TRUE;
3331 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003332# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003333 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003334# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 }
3336#endif
3337
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003338 // Use "wlv.extra_attr", but don't override visual selection
3339 // highlighting, unless text property overrides.
3340 // Don't use "wlv.extra_attr" until n_attr_skip is zero.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003341 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003342 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003343 && (!attr_pri
3344#ifdef FEAT_PROP_POPUP
3345 || (text_prop_flags & PT_FLAG_OVERRIDE)
3346#endif
3347 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 {
3349#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003350 if (wlv.line_attr)
3351 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 else
3353#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003354 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003355#ifdef FEAT_PROP_POPUP
3356 if (reset_extra_attr)
3357 {
3358 reset_extra_attr = FALSE;
3359 wlv.extra_attr = 0;
3360 }
3361#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 }
3363
3364#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3365 // XIM don't send preedit_start and preedit_end, but they send
3366 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3367 // im_is_preediting() here.
3368 if (p_imst == IM_ON_THE_SPOT
3369 && xic != NULL
3370 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003371 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 && !p_imdisable
3373 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003374 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 {
3376 colnr_T tcol;
3377
3378 if (preedit_end_col == MAXCOL)
3379 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3380 else
3381 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003382 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 {
3384 if (feedback_old_attr < 0)
3385 {
3386 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003387 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003389 wlv.char_attr = im_get_feedback_attr(feedback_col);
3390 if (wlv.char_attr < 0)
3391 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 feedback_col++;
3393 }
3394 else if (feedback_old_attr >= 0)
3395 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003396 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 feedback_old_attr = -1;
3398 feedback_col = 0;
3399 }
3400 }
3401#endif
3402 // Handle the case where we are in column 0 but not on the first
3403 // character of the line and the user wants us to show us a
3404 // special character (via 'listchars' option "precedes:<char>".
3405 if (lcs_prec_todo != NUL
3406 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003407 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3408 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003410 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003412 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 && c != NUL)
3414 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003415 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 lcs_prec_todo = NUL;
3417 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3418 {
3419 // Double-width character being overwritten by the "precedes"
3420 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003421 wlv.c_extra = MB_FILLER_CHAR;
3422 wlv.c_final = NUL;
3423 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003425 wlv.extra_attr =
3426 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 }
3428 mb_c = c;
3429 if (enc_utf8 && utf_char2len(c) > 1)
3430 {
3431 mb_utf8 = TRUE;
3432 u8cc[0] = 0;
3433 c = 0xc0;
3434 }
3435 else
3436 mb_utf8 = FALSE; // don't draw as UTF-8
3437 if (!attr_pri)
3438 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 saved_attr3 = wlv.char_attr; // save current attr
3440 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 n_attr3 = 1;
3442 }
3443 }
3444
3445 // At end of the text line or just after the last character.
3446 if ((c == NUL
3447#if defined(LINE_ATTR)
3448 || did_line_attr == 1
3449#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003450 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 {
3452#ifdef FEAT_SEARCH_EXTRA
3453 // flag to indicate whether prevcol equals startcol of search_hl or
3454 // one of the matches
3455 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3456 (long)(ptr - line) - (c == NUL));
3457#endif
3458 // Invert at least one char, used for Visual and empty line or
3459 // highlight match at end of line. If it's beyond the last
3460 // char on the screen, just overwrite that one (tricky!) Not
3461 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003462 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003463 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 && (VIsual_mode != Ctrl_V
3465 || lnum == VIsual.lnum
3466 || lnum == curwin->w_cursor.lnum)
3467 && c == NUL)
3468#ifdef FEAT_SEARCH_EXTRA
3469 // highlight 'hlsearch' match at end of line
3470 || (prevcol_hl_flag
3471# ifdef FEAT_SYN_HL
3472 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3473 && !(wp == curwin && VIsual_active))
3474# endif
3475# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477# endif
3478# if defined(LINE_ATTR)
3479 && did_line_attr <= 1
3480# endif
3481 )
3482#endif
3483 ))
3484 {
3485 int n = 0;
3486
3487#ifdef FEAT_RIGHTLEFT
3488 if (wp->w_p_rl)
3489 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003490 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 n = 1;
3492 }
3493 else
3494#endif
3495 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003496 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 n = -1;
3498 }
3499 if (n != 0)
3500 {
3501 // At the window boundary, highlight the last character
3502 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003503 wlv.off += n;
3504 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 }
3506 else
3507 {
3508 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003509 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 }
3513#ifdef FEAT_SEARCH_EXTRA
3514 if (area_attr == 0)
3515 {
3516 // Use attributes from match with highest priority among
3517 // 'search_hl' and the match list.
3518 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003519 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 }
3521#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003522 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524#ifdef FEAT_RIGHTLEFT
3525 if (wp->w_p_rl)
3526 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003527 --wlv.col;
3528 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003529 }
3530 else
3531#endif
3532 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003533 ++wlv.col;
3534 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 ++wlv.vcol;
3537 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 }
3539 }
3540
3541 // At end of the text line.
3542 if (c == NUL)
3543 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545
3546 // Update w_cline_height and w_cline_folded if the cursor line was
3547 // updated (saves a call to plines() later).
3548 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3549 {
3550 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552#ifdef FEAT_FOLDING
3553 curwin->w_cline_folded = FALSE;
3554#endif
3555 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3556 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 break;
3558 }
3559
3560 // Show "extends" character from 'listchars' if beyond the line end and
3561 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003562 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003563 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 && wp->w_p_list
3565 && !wp->w_p_wrap
3566#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003567 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568#endif
3569 && (
3570#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003571 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003575 || lcs_eol_one > 0
3576 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003577 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003579 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003580 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 mb_c = c;
3582 if (enc_utf8 && utf_char2len(c) > 1)
3583 {
3584 mb_utf8 = TRUE;
3585 u8cc[0] = 0;
3586 c = 0xc0;
3587 }
3588 else
3589 mb_utf8 = FALSE;
3590 }
3591
3592#ifdef FEAT_SYN_HL
3593 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 if (wlv.draw_color_col)
3595 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596
3597 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3598 // highlight the cursor position itself.
3599 // Also highlight the 'colorcolumn' if it is different than
3600 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003601 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3602 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003604 if (((wlv.draw_state == WL_LINE
3605 || wlv.draw_state == WL_BRI
3606 || wlv.draw_state == WL_SBR)
3607 && !lnum_in_visual_area
3608 && search_attr == 0
3609 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003610# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003611 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003612# endif
3613 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 {
3615 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3616 && lnum != wp->w_cursor.lnum)
3617 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003618 vcol_save_attr = wlv.char_attr;
3619 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3620 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003622 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003624 vcol_save_attr = wlv.char_attr;
3625 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 }
3627 }
3628#endif
3629
3630 // Store character to be displayed.
3631 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003633 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 {
3635 // Store the character.
3636#if defined(FEAT_RIGHTLEFT)
3637 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3638 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003639 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 --wlv.off;
3641 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 if (enc_dbcs == DBCS_JPNU)
3646 {
3647 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003648 ScreenLines[wlv.off] = 0x8e;
3649 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 }
3651 else if (enc_utf8)
3652 {
3653 if (mb_utf8)
3654 {
3655 int i;
3656
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 for (i = 0; i < Screen_mco; ++i)
3661 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003662 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663 if (u8cc[i] == 0)
3664 break;
3665 }
3666 }
3667 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 }
3670 if (multi_attr)
3671 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003672 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 multi_attr = 0;
3674 }
3675 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003676 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003678 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003679
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3681 {
3682 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003683 ++wlv.off;
3684 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 if (enc_utf8)
3686 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003687 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688 else
3689 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003690 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003691 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003693 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694#endif
3695 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003697 // When "wlv.tocol" is halfway a character, set it to the end
3698 // of the character, otherwise highlighting won't stop.
3699 if (wlv.tocol == wlv.vcol)
3700 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003701
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003703
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704#ifdef FEAT_RIGHTLEFT
3705 if (wp->w_p_rl)
3706 {
3707 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003708 --wlv.off;
3709 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710 }
3711#endif
3712 }
3713#ifdef FEAT_RIGHTLEFT
3714 if (wp->w_p_rl)
3715 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003716 --wlv.off;
3717 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 }
3719 else
3720#endif
3721 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 ++wlv.off;
3723 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724 }
3725 }
3726#ifdef FEAT_CONCEAL
3727 else if (wp->w_p_cole > 0 && is_concealing)
3728 {
3729 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003730 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003731 if (wlv.n_extra > 0)
3732 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 if (wp->w_p_wrap)
3734 {
3735 // Special voodoo required if 'wrap' is on.
3736 //
3737 // Advance the column indicator to force the line
3738 // drawing to wrap early. This will make the line
3739 // take up the same screen space when parts are concealed,
3740 // so that cursor line computations aren't messed up.
3741 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003742 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743 // trailing junk to be written out of the screen line
3744 // we are building, 'boguscols' keeps track of the number
3745 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003746 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003748 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749# ifdef FEAT_RIGHTLEFT
3750 if (wp->w_p_rl)
3751 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 wlv.col -= wlv.n_extra;
3753 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 }
3755 else
3756# endif
3757 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003758 wlv.col += wlv.n_extra;
3759 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003761 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762 n_attr = 0;
3763 }
3764
3765
3766 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3767 {
3768 // Need to fill two screen columns.
3769# ifdef FEAT_RIGHTLEFT
3770 if (wp->w_p_rl)
3771 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003772 --wlv.boguscols;
3773 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774 }
3775 else
3776# endif
3777 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 ++wlv.boguscols;
3779 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 }
3781 }
3782
3783# ifdef FEAT_RIGHTLEFT
3784 if (wp->w_p_rl)
3785 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003786 --wlv.boguscols;
3787 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 }
3789 else
3790# endif
3791 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003792 ++wlv.boguscols;
3793 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794 }
3795 }
3796 else
3797 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003798 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003800 wlv.vcol += wlv.n_extra;
3801 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 n_attr = 0;
3803 }
3804 }
3805
3806 }
3807#endif // FEAT_CONCEAL
3808 else
3809 --n_skip;
3810
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003811 // Only advance the "wlv.vcol" when after the 'number' or
3812 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003813 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003815 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816#endif
3817 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003818 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819
3820#ifdef FEAT_SYN_HL
3821 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003822 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823#endif
3824
3825 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003826 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3827 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828
3829 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003830 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003831 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003832 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003833 if (n_attr_skip > 0)
3834 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835
3836 // At end of screen line and there is more to come: Display the line
3837 // so far. If there is no more to display it is caught above.
3838 if ((
3839#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003840 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003842 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003843 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003844 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003846 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003848#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003849 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003850#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003851 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003852 && wlv.p_extra != at_end_str)
3853 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3854 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 )
3856 {
3857#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003858 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003859 wlv_screen_line(wp, &wlv, FALSE);
3860 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003861 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003863 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 ++wlv.row;
3866 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003867
3868 // When not wrapping and finished diff lines, or when displayed
3869 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003870 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003871#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003872 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003873#endif
3874#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003875 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003877 ) || lcs_eol_one == -1)
3878#ifdef FEAT_PROP_POPUP
3879 && !text_prop_follows
3880#endif
3881 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003883#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003884 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003885 {
3886 // do not output more of the line, only the "below" prop
3887 ptr += STRLEN(ptr);
3888# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003889 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003890# endif
3891 }
3892#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893
3894 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003895 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003897 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898#endif
3899 )
3900 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003901 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3902 draw_vsep_win(wp, wlv.row);
3903 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904 }
3905
3906 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003907 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003909 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910 break;
3911 }
3912
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003913 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003915 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003917#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003918 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003919#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 && wp->w_width == Columns)
3921 {
3922 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003923 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003924
3925 // Special trick to make copy/paste of wrapped lines work with
3926 // xterm/screen: write an extra character beyond the end of
3927 // the line. This will work with all terminal types
3928 // (regardless of the xn,am settings).
3929 // Only do this on a fast tty.
3930 // Only do this if the cursor is on the current line
3931 // (something has been written in it).
3932 // Don't do this for the GUI.
3933 // Don't do this for double-width characters.
3934 // Don't do this for a window not at the right screen border.
3935 if (p_tf
3936#ifdef FEAT_GUI
3937 && !gui.in_use
3938#endif
3939 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003940 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3941 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003942 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 || (*mb_off2cells)(
3944 LineOffset[wlv.screen_row - 1]
3945 + (int)Columns - 2,
3946 LineOffset[wlv.screen_row]
3947 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948 {
3949 // First make sure we are at the end of the screen line,
3950 // then output the same character again to let the
3951 // terminal know about the wrap. If the terminal doesn't
3952 // auto-wrap, we overwrite the character.
3953 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003954 screen_char(LineOffset[wlv.screen_row - 1]
3955 + (unsigned)Columns - 1,
3956 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003957
3958 // When there is a multi-byte character, just output a
3959 // space to keep it simple.
3960 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003961 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962 out_char(' ');
3963 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003964 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003965 + (Columns - 1)]);
3966 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003967 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968 screen_start(); // don't know where cursor is now
3969 }
3970 }
3971
Bram Moolenaar1306b362022-08-06 15:59:06 +01003972 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973
Bram Moolenaareed9d462021-02-15 20:38:25 +01003974 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003976 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003977# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003978 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003980 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003981 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982#endif
3983#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003984 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003985 // When the filler lines are actually below the last line of the
3986 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003987 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003988 break;
3989#endif
3990 }
3991
3992 } // for every character in the line
3993
3994#ifdef FEAT_SPELL
3995 // After an empty line check first word for capital.
3996 if (*skipwhite(line) == NUL)
3997 {
3998 capcol_lnum = lnum + 1;
3999 cap_col = 0;
4000 }
4001#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004002#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004003 vim_free(text_props);
4004 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004005 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004006#endif
4007
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004008 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004009 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004010}