blob: ceea6cd91a07120af02aafa0ad5743ccaa8cb212 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
120
Bram Moolenaar1306b362022-08-06 15:59:06 +0100121 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
122 int cul_screenline;
123
124 int char_attr; // attributes for the next character
125
126 int n_extra; // number of extra bytes
127 char_u *p_extra; // string of extra chars, plus NUL, only used
128 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100129 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100130 int c_extra; // extra chars, all the same
131 int c_final; // final char, mandatory if set
132
133 // saved "extra" items for when draw_state becomes WL_LINE (again)
134 int saved_n_extra;
135 char_u *saved_p_extra;
136 int saved_c_extra;
137 int saved_c_final;
138 int saved_char_attr;
139
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100140 char_u extra[NUMBUFLEN + MB_MAXBYTES];
141 // "%ld " and 'fdc' must fit in here, as well
142 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100143
Bram Moolenaar1306b362022-08-06 15:59:06 +0100144#ifdef FEAT_DIFF
145 hlf_T diff_hlf; // type of diff highlighting
146#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100147 int filler_lines; // nr of filler lines to be drawn
148 int filler_todo; // nr of filler lines still to do + 1
149#ifdef FEAT_SIGNS
150 sign_attrs_T sattr;
151#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100152} winlinevars_T;
153
154// draw_state values for items that are drawn in sequence:
155#define WL_START 0 // nothing done yet, must be zero
156#ifdef FEAT_CMDWIN
157# define WL_CMDLINE (WL_START + 1) // cmdline window column
158#else
159# define WL_CMDLINE WL_START
160#endif
161#ifdef FEAT_FOLDING
162# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
163#else
164# define WL_FOLD WL_CMDLINE
165#endif
166#ifdef FEAT_SIGNS
167# define WL_SIGN (WL_FOLD + 1) // column for signs
168#else
169# define WL_SIGN WL_FOLD // column for signs
170#endif
171#define WL_NR (WL_SIGN + 1) // line number
172#ifdef FEAT_LINEBREAK
173# define WL_BRI (WL_NR + 1) // 'breakindent'
174#else
175# define WL_BRI WL_NR
176#endif
177#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
178# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
179#else
180# define WL_SBR WL_BRI
181#endif
182#define WL_LINE (WL_SBR + 1) // text in the line
183
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100184#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200185/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000186 * Return TRUE if CursorLineSign highlight is to be used.
187 */
188 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100189use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000190{
191 return wp->w_p_cul
192 && lnum == wp->w_cursor.lnum
193 && (wp->w_p_culopt_flags & CULOPT_NBR);
194}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100195#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000196
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100197
198#ifdef FEAT_FOLDING
199/*
200 * Setup for drawing the 'foldcolumn', if there is one.
201 */
202 static void
203handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
204{
205 int fdc = compute_foldcolumn(wp, 0);
206
207 if (fdc <= 0)
208 return;
209
210 // Allocate a buffer, "wlv->extra[]" may already be in use.
211 vim_free(wlv->p_extra_free);
212 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
213 if (wlv->p_extra_free != NULL)
214 {
215 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
216 wp, FALSE, wlv->lnum);
217 wlv->p_extra_free[wlv->n_extra] = NUL;
218 wlv->p_extra = wlv->p_extra_free;
219 wlv->c_extra = NUL;
220 wlv->c_final = NUL;
221 if (use_cursor_line_highlight(wp, wlv->lnum))
222 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
223 else
224 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
225 }
226}
227#endif
228
229#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000230/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100231 * Get information needed to display the sign in line "wlv->lnum" in window
232 * "wp".
233 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200234 * Otherwise the sign is going to be displayed in the sign column.
235 */
236 static void
237get_sign_display_info(
238 int nrcol,
239 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100240 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200241{
242 int text_sign;
243# ifdef FEAT_SIGN_ICONS
244 int icon_sign;
245# endif
246
247 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100248 wlv->c_extra = ' ';
249 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200250 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100251 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200252 else
253 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100254 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100255 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000256 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100257 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100258 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200259 }
260
Bram Moolenaar1306b362022-08-06 15:59:06 +0100261 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200262#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100263 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200264#endif
265 )
266 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100267 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100269 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200270 if (gui.in_use && icon_sign != 0)
271 {
272 // Use the image in this position.
273 if (nrcol)
274 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100275 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100276 sprintf((char *)wlv->extra, "%-*c ",
277 number_width(wp), SIGN_BYTE);
278 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200280 }
281 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100282 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100284 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
285 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286 {
287 if (nrcol)
288 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100289 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100290 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100293 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 }
295 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100296 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200297 }
298# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100299 wlv->c_final = NUL;
300 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301 }
302 else
303# endif
304 if (text_sign != 0)
305 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100306 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100307 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200308 {
309 if (nrcol)
310 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100311 int width = number_width(wp) - 2;
312 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313
314 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100315 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100316 vim_snprintf((char *)wlv->extra + n,
317 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100318 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200319 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100320 wlv->c_extra = NUL;
321 wlv->c_final = NUL;
322 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200323 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000324
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100325 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100326 && wlv->sattr.sat_culhl > 0)
327 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000328 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330 }
331 }
332}
333#endif
334
Bram Moolenaard7657e92022-09-20 18:59:30 +0100335/*
336 * Display the absolute or relative line number. After the first row fill with
337 * blanks when the 'n' flag isn't in 'cpo'.
338 */
339 static void
340handle_lnum_col(
341 win_T *wp,
342 winlinevars_T *wlv,
343 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100344 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100345{
346 if ((wp->w_p_nu || wp->w_p_rnu)
347 && (wlv->row == wlv->startrow + wlv->filler_lines
348 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
349 {
350#ifdef FEAT_SIGNS
351 // If 'signcolumn' is set to 'number' and a sign is present
352 // in 'lnum', then display the sign instead of the line
353 // number.
354 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
355 get_sign_display_info(TRUE, wp, wlv);
356 else
357#endif
358 {
359 // Draw the line number (empty space after wrapping).
360 if (wlv->row == wlv->startrow + wlv->filler_lines)
361 {
362 long num;
363 char *fmt = "%*ld ";
364
365 if (wp->w_p_nu && !wp->w_p_rnu)
366 // 'number' + 'norelativenumber'
367 num = (long)wlv->lnum;
368 else
369 {
370 // 'relativenumber', don't use negative numbers
371 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
372 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
373 {
374 // 'number' + 'relativenumber'
375 num = wlv->lnum;
376 fmt = "%-*ld ";
377 }
378 }
379
380 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
381 if (wp->w_skipcol > 0)
382 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
383 ++wlv->p_extra)
384 *wlv->p_extra = '-';
385#ifdef FEAT_RIGHTLEFT
386 if (wp->w_p_rl) // reverse line numbers
387 {
388 char_u *p1, *p2;
389 int t;
390
391 // like rl_mirror(), but keep the space at the end
392 p2 = skipwhite(wlv->extra);
393 p2 = skiptowhite(p2) - 1;
394 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
395 {
396 t = *p1;
397 *p1 = *p2;
398 *p2 = t;
399 }
400 }
401#endif
402 wlv->p_extra = wlv->extra;
403 wlv->c_extra = NUL;
404 wlv->c_final = NUL;
405 }
406 else
407 {
408 wlv->c_extra = ' ';
409 wlv->c_final = NUL;
410 }
411 wlv->n_extra = number_width(wp) + 1;
412 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
413#ifdef FEAT_SYN_HL
414 // When 'cursorline' is set highlight the line number of
415 // the current line differently.
416 // When 'cursorlineopt' does not have "line" only
417 // highlight the line number itself.
418 // TODO: Can we use CursorLine instead of CursorLineNr
419 // when CursorLineNr isn't set?
420 if (wp->w_p_cul
421 && wlv->lnum == wp->w_cursor.lnum
422 && (wp->w_p_culopt_flags & CULOPT_NBR)
423 && (wlv->row == wlv->startrow + wlv->filler_lines
424 || (wlv->row > wlv->startrow + wlv->filler_lines
425 && (wp->w_p_culopt_flags & CULOPT_LINE))))
426 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
427#endif
428 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
429 && HL_ATTR(HLF_LNA) != 0)
430 // Use LineNrAbove
431 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
432 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
433 && HL_ATTR(HLF_LNB) != 0)
434 // Use LineNrBelow
435 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
436 }
437#ifdef FEAT_SIGNS
438 if (num_attr)
439 wlv->char_attr = num_attr;
440#endif
441 }
442}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100443
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100444#ifdef FEAT_LINEBREAK
445 static void
446handle_breakindent(win_T *wp, winlinevars_T *wlv)
447{
448 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
449 && *get_showbreak_value(wp) != NUL)
450 // draw indent after showbreak value
451 wlv->draw_state = WL_BRI;
452 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
453 // After the showbreak, draw the breakindent
454 wlv->draw_state = WL_BRI - 1;
455
456 // draw 'breakindent': indent wrapped text accordingly
457 if (wlv->draw_state == WL_BRI - 1)
458 {
459 wlv->draw_state = WL_BRI;
460 // if wlv->need_showbreak is set, breakindent also applies
461 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
462# ifdef FEAT_DIFF
463 && wlv->filler_lines == 0
464# endif
465# ifdef FEAT_PROP_POPUP
466 && !wlv->dont_use_showbreak
467# endif
468 )
469 {
470 wlv->char_attr = 0;
471# ifdef FEAT_DIFF
472 if (wlv->diff_hlf != (hlf_T)0)
473 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
474# endif
475 wlv->p_extra = NULL;
476 wlv->c_extra = ' ';
477 wlv->c_final = NUL;
478 wlv->n_extra = get_breakindent_win(wp,
479 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
480 if (wlv->row == wlv->startrow)
481 {
482 wlv->n_extra -= win_col_off2(wp);
483 if (wlv->n_extra < 0)
484 wlv->n_extra = 0;
485 }
486 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
487 wlv->need_showbreak = FALSE;
488 // Correct end of highlighted area for 'breakindent',
489 // required when 'linebreak' is also set.
490 if (wlv->tocol == wlv->vcol)
491 wlv->tocol += wlv->n_extra;
492 }
493 }
494}
495#endif
496
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100497#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
498 static void
499handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
500{
501# ifdef FEAT_DIFF
502 if (wlv->filler_todo > 0)
503 {
504 // Draw "deleted" diff line(s).
505 if (char2cells(wp->w_fill_chars.diff) > 1)
506 {
507 wlv->c_extra = '-';
508 wlv->c_final = NUL;
509 }
510 else
511 {
512 wlv->c_extra = wp->w_fill_chars.diff;
513 wlv->c_final = NUL;
514 }
515# ifdef FEAT_RIGHTLEFT
516 if (wp->w_p_rl)
517 wlv->n_extra = wlv->col + 1;
518 else
519# endif
520 wlv->n_extra = wp->w_width - wlv->col;
521 wlv->char_attr = HL_ATTR(HLF_DED);
522 }
523# endif
524
525# ifdef FEAT_LINEBREAK
526 char_u *sbr = get_showbreak_value(wp);
527 if (*sbr != NUL && wlv->need_showbreak)
528 {
529 // Draw 'showbreak' at the start of each broken line.
530 wlv->p_extra = sbr;
531 wlv->c_extra = NUL;
532 wlv->c_final = NUL;
533 wlv->n_extra = (int)STRLEN(sbr);
534 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
535 wlv->need_showbreak = FALSE;
536 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
537 // Correct end of highlighted area for 'showbreak',
538 // required when 'linebreak' is also set.
539 if (wlv->tocol == wlv->vcol)
540 wlv->tocol += wlv->n_extra;
541 // combine 'showbreak' with 'wincolor'
542 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
543# ifdef FEAT_SYN_HL
544 // combine 'showbreak' with 'cursorline'
545 if (wlv->cul_attr != 0)
546 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
547# endif
548 }
549# endif
550}
551#endif
552
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100553#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100554/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100555 * Return the cell size of virtual text after truncation.
556 */
557 static int
558textprop_size_after_trunc(
559 win_T *wp,
560 int flags, // TP_FLAG_ALIGN_*
561 int added,
562 char_u *text,
563 int *n_used_ptr)
564{
565 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
566 ? wp->w_width : added;
567 int len = (int)STRLEN(text);
568 int strsize = 0;
569 int n_used;
570
571 // if the remaining size is to small wrap anyway and use the next line
572 if (space < PROP_TEXT_MIN_CELLS)
573 space += wp->w_width;
574 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
575 {
576 int clen = ptr2cells(text + n_used);
577
578 if (strsize + clen > space)
579 break;
580 strsize += clen;
581 }
582 *n_used_ptr = n_used;
583 return strsize;
584}
585
586/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100587 * Take care of padding, right-align and truncation of virtual text after a
588 * line.
589 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
590 * padding, right-align and truncation. Otherwise only the size is computed.
591 * When "n_attr" is NULL returns the number of screen cells used.
592 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100593 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100594 int
595text_prop_position(
596 win_T *wp,
597 textprop_T *tp,
598 int vcol, // current screen column
599 int *n_extra, // nr of bytes for virtual text
600 char_u **p_extra, // virtual text
601 int *n_attr, // attribute cells, NULL if not used
602 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200603{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100604 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100605 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100606 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
607 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
608 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
609 ? tp->tp_len - 1 : 0;
610 int col_with_padding = vcol + (below ? 0 : padding);
611 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 int before = room; // spaces before the text
613 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100614 int n_used = *n_extra;
615 char_u *l = NULL;
616 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100617 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
618 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200619
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100620 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100621 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100622 int col_off = win_col_off(wp) + win_col_off2(wp);
623 int skip_add = 0;
624
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100625 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100627 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100628 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100629 }
630 else
631 {
632 // Right-align: fill with before
633 if (right)
634 before -= cells;
635 if (before < 0
636 || !(right || below)
637 || (below
638 ? (col_with_padding == 0 || !wp->w_p_wrap)
639 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100640 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100641 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
642 {
643 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 before = wp->w_width - col_off - strsize + room;
645 if (before < 0)
646 before = 0;
647 else
648 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100649 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100650 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100653 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100654 else if (below && before > 0)
655 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100656 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100658
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100659 // With 'nowrap' add one to show the "extends" character if needed (it
660 // doesn't show if the text just fits).
661 if (!wp->w_p_wrap
662 && n_used < *n_extra
663 && wp->w_lcs_chars.ext != NUL
664 && wp->w_p_list)
665 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100666 if (!wp->w_p_wrap && below && padding > 0)
667 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668
669 // add 1 for NUL, 2 for when '…' is used
670 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100671 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100672 if (n_attr == NULL || l != NULL)
673 {
674 int off = 0;
675
676 if (n_attr != NULL)
677 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100678 vim_memset(l, ' ', before);
679 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100680 if (padding > 0)
681 {
682 vim_memset(l + off, ' ', padding);
683 off += padding;
684 }
685 vim_strncpy(l + off, *p_extra, n_used);
686 off += n_used;
687 }
688 else
689 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100690 off = before + after + padding + n_used;
691 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100692 }
693 if (n_attr != NULL)
694 {
695 if (n_used < *n_extra && wp->w_p_wrap)
696 {
697 char_u *lp = l + off - 1;
698
699 if (has_mbyte)
700 {
701 // change last character to '…'
702 lp -= (*mb_head_off)(l, lp);
703 STRCPY(lp, "…");
704 n_used = lp - l + 3 - padding;
705 }
706 else
707 // change last character to '>'
708 *lp = '>';
709 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100710 else if (after > 0)
711 {
712 vim_memset(l + off, ' ', after);
713 l[off + after] = NUL;
714 }
715
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100716 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100718 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100719 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100720 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100721 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100722 }
723 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100724 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100725
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100726 if (n_attr == NULL)
727 return cells;
728 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200729}
730#endif
731
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100732/*
733 * Called when finished with the line: draw the screen line and handle any
734 * highlighting until the right of the window.
735 */
736 static void
737draw_screen_line(win_T *wp, winlinevars_T *wlv)
738{
739#ifdef FEAT_SYN_HL
740 long v;
741
742 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
743 if (wp->w_p_wrap)
744 v = wp->w_skipcol;
745 else
746 v = wp->w_leftcol;
747
748 // check if line ends before left margin
749 if (wlv->vcol < v + wlv->col - win_col_off(wp))
750 wlv->vcol = v + wlv->col - win_col_off(wp);
751# ifdef FEAT_CONCEAL
752 // Get rid of the boguscols now, we want to draw until the right
753 // edge for 'cursorcolumn'.
754 wlv->col -= wlv->boguscols;
755 wlv->boguscols = 0;
756# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
757# else
758# define VCOL_HLC (wlv->vcol)
759# endif
760
761 if (wlv->draw_color_col)
762 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
763
764 if (((wp->w_p_cuc
765 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
766 && (int)wp->w_virtcol <
767 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
768 && wlv->lnum != wp->w_cursor.lnum)
769 || wlv->draw_color_col
770 || wlv->win_attr != 0)
771# ifdef FEAT_RIGHTLEFT
772 && !wp->w_p_rl
773# endif
774 )
775 {
776 int rightmost_vcol = 0;
777 int i;
778
779 if (wp->w_p_cuc)
780 rightmost_vcol = wp->w_virtcol;
781 if (wlv->draw_color_col)
782 // determine rightmost colorcolumn to possibly draw
783 for (i = 0; wlv->color_cols[i] >= 0; ++i)
784 if (rightmost_vcol < wlv->color_cols[i])
785 rightmost_vcol = wlv->color_cols[i];
786
787 while (wlv->col < wp->w_width)
788 {
789 ScreenLines[wlv->off] = ' ';
790 if (enc_utf8)
791 ScreenLinesUC[wlv->off] = 0;
792 ScreenCols[wlv->off] = MAXCOL;
793 ++wlv->col;
794 if (wlv->draw_color_col)
795 wlv->draw_color_col = advance_color_col(
796 VCOL_HLC, &wlv->color_cols);
797
798 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
799 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
800 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
801 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
802 else
803 ScreenAttrs[wlv->off++] = wlv->win_attr;
804
805 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
806 break;
807
808 ++wlv->vcol;
809 }
810 }
811#endif
812
813 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
814 wp->w_width, wlv->screen_line_flags);
815 ++wlv->row;
816 ++wlv->screen_row;
817}
818#undef VCOL_HLC
819
820/*
821 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100822 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100823 */
824 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100825win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100826{
827 wlv->col = 0;
828 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
829
830#ifdef FEAT_RIGHTLEFT
831 if (wp->w_p_rl)
832 {
833 // Rightleft window: process the text in the normal direction, but put
834 // it in current_ScreenLine[] from right to left. Start at the
835 // rightmost column of the window.
836 wlv->col = wp->w_width - 1;
837 wlv->off += wlv->col;
838 wlv->screen_line_flags |= SLF_RIGHTLEFT;
839 }
840#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100841 if (save_extra)
842 {
843 // reset the drawing state for the start of a wrapped line
844 wlv->draw_state = WL_START;
845 wlv->saved_n_extra = wlv->n_extra;
846 wlv->saved_p_extra = wlv->p_extra;
847 wlv->saved_c_extra = wlv->c_extra;
848 wlv->saved_c_final = wlv->c_final;
849#ifdef FEAT_SYN_HL
850 if (!(wlv->cul_screenline
851# ifdef FEAT_DIFF
852 && wlv->diff_hlf == (hlf_T)0
853# endif
854 ))
855 wlv->saved_char_attr = wlv->char_attr;
856 else
857#endif
858 wlv->saved_char_attr = 0;
859 wlv->n_extra = 0;
860 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100861}
862
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200863/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100864 * Called when wlv->draw_state is set to WL_LINE.
865 */
866 static void
867win_line_continue(winlinevars_T *wlv)
868{
869 if (wlv->saved_n_extra > 0)
870 {
871 // Continue item from end of wrapped line.
872 wlv->n_extra = wlv->saved_n_extra;
873 wlv->c_extra = wlv->saved_c_extra;
874 wlv->c_final = wlv->saved_c_final;
875 wlv->p_extra = wlv->saved_p_extra;
876 wlv->char_attr = wlv->saved_char_attr;
877 }
878 else
879 wlv->char_attr = wlv->win_attr;
880}
881
882/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200883 * Display line "lnum" of window 'wp' on the screen.
884 * Start at row "startrow", stop when "endrow" is reached.
885 * wp->w_virtcol needs to be valid.
886 *
887 * Return the number of last row the line occupies.
888 */
889 int
890win_line(
891 win_T *wp,
892 linenr_T lnum,
893 int startrow,
894 int endrow,
895 int nochange UNUSED, // not updating for changed text
896 int number_only) // only update the number column
897{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100898 winlinevars_T wlv; // variables passed between functions
899
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200900 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100901 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200902 char_u *line; // current line
903 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200904
Bram Moolenaar1306b362022-08-06 15:59:06 +0100905#ifdef FEAT_PROP_POPUP
906 char_u *p_extra_free2 = NULL; // another p_extra to be freed
907#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200908 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000909#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000910 int in_linebreak = FALSE; // n_extra set for showing linebreak
911#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200912 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100913 // displaying eol at end-of-line
914 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000915 int lcs_prec_todo = wp->w_lcs_chars.prec;
916 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200917
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100918 int n_attr = 0; // chars with special attr
919 int n_attr_skip = 0; // chars to skip before using extra_attr
920 int saved_attr2 = 0; // char_attr saved for n_attr
921 int n_attr3 = 0; // chars with overruling special attr
922 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200923
924 int n_skip = 0; // nr of chars to skip for 'nowrap'
925
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200926 int fromcol_prev = -2; // start of inverting after cursor
927 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200928 int lnum_in_visual_area = FALSE;
929 pos_T pos;
930 long v;
931
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200932 int attr_pri = FALSE; // char_attr has priority
933 int area_highlighting = FALSE; // Visual or incsearch highlighting
934 // in this line
935 int vi_attr = 0; // attributes for Visual and incsearch
936 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200937 int area_attr = 0; // attributes desired by highlighting
938 int search_attr = 0; // attributes desired by 'hlsearch'
939#ifdef FEAT_SYN_HL
940 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
941 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200942 int prev_syntax_col = -1; // column of prev_syntax_attr
943 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200944 int has_syntax = FALSE; // this buffer has syntax highl.
945 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200946#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100947#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200948 int text_prop_count;
949 int text_prop_next = 0; // next text property to use
950 textprop_T *text_props = NULL;
951 int *text_prop_idxs = NULL;
952 int text_props_active = 0;
953 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100954 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200955 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100956 int text_prop_attr_comb = 0; // text_prop_attr combined with
957 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100958 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100959 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100960 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100961 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100962 int saved_search_attr = 0; // search_attr to be used when n_extra
963 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100964 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200965#endif
966#ifdef FEAT_SPELL
967 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000968 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200969# define SPWORDLEN 150
970 char_u nextline[SPWORDLEN * 2];// text with start of the next line
971 int nextlinecol = 0; // column where nextline[] starts
972 int nextline_idx = 0; // index in nextline[] where next line
973 // starts
974 int spell_attr = 0; // attributes desired by spelling
975 int word_end = 0; // last byte with same spell_attr
976 static linenr_T checked_lnum = 0; // line number for "checked_col"
977 static int checked_col = 0; // column in "checked_lnum" up to which
978 // there are no spell errors
979 static int cap_col = -1; // column to check for Cap word
980 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
981 int cur_checked_col = 0; // checked column for current line
982#endif
983 int extra_check = 0; // has extra highlighting
984 int multi_attr = 0; // attributes desired by multibyte
985 int mb_l = 1; // multi-byte byte length
986 int mb_c = 0; // decoded multi-byte character
987 int mb_utf8 = FALSE; // screen char is UTF-8 char
988 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200989#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 int change_start = MAXCOL; // first col of changed area
991 int change_end = -1; // last col of changed area
992#endif
993 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100994 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200995 int in_multispace = FALSE; // in multiple consecutive spaces
996 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
998 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
999# define LINE_ATTR
1000 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001001 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001004 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001005#ifdef FEAT_ARABIC
1006 int prev_c = 0; // previous Arabic character
1007 int prev_c1 = 0; // first composing char for prev_c
1008#endif
1009#if defined(LINE_ATTR)
1010 int did_line_attr = 0;
1011#endif
1012#ifdef FEAT_TERMINAL
1013 int get_term_attr = FALSE;
1014#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001016#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 // margin columns for the screen line, needed for when 'cursorlineopt'
1018 // contains "screenline"
1019 int left_curline_col = 0;
1020 int right_curline_col = 0;
1021#endif
1022
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1024 int feedback_col = 0;
1025 int feedback_old_attr = -1;
1026#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001027
1028#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1029 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001030 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031#endif
1032#ifdef FEAT_CONCEAL
1033 int syntax_flags = 0;
1034 int syntax_seqnr = 0;
1035 int prev_syntax_id = 0;
1036 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1037 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038 int did_wcol = FALSE;
1039 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001040# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041# define FIX_FOR_BOGUSCOLS \
1042 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001043 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001044 wlv.vcol -= wlv.vcol_off; \
1045 wlv.vcol_off = 0; \
1046 wlv.col -= wlv.boguscols; \
1047 old_boguscols = wlv.boguscols; \
1048 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049 }
1050#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001051# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052#endif
1053
1054 if (startrow > endrow) // past the end already!
1055 return startrow;
1056
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001057 CLEAR_FIELD(wlv);
1058
1059 wlv.lnum = lnum;
1060 wlv.startrow = startrow;
1061 wlv.row = startrow;
1062 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001063 wlv.fromcol = -10;
1064 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001065#ifdef FEAT_LINEBREAK
1066 wlv.vcol_sbr = -1;
1067#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068
1069 if (!number_only)
1070 {
1071 // To speed up the loop below, set extra_check when there is linebreak,
1072 // trailing white space and/or syntax processing to be done.
1073#ifdef FEAT_LINEBREAK
1074 extra_check = wp->w_p_lbr;
1075#endif
1076#ifdef FEAT_SYN_HL
1077 if (syntax_present(wp) && !wp->w_s->b_syn_error
1078# ifdef SYN_TIME_LIMIT
1079 && !wp->w_s->b_syn_slow
1080# endif
1081 )
1082 {
1083 // Prepare for syntax highlighting in this line. When there is an
1084 // error, stop syntax highlighting.
1085 save_did_emsg = did_emsg;
1086 did_emsg = FALSE;
1087 syntax_start(wp, lnum);
1088 if (did_emsg)
1089 wp->w_s->b_syn_error = TRUE;
1090 else
1091 {
1092 did_emsg = save_did_emsg;
1093#ifdef SYN_TIME_LIMIT
1094 if (!wp->w_s->b_syn_slow)
1095#endif
1096 {
1097 has_syntax = TRUE;
1098 extra_check = TRUE;
1099 }
1100 }
1101 }
1102
1103 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001104 wlv.color_cols = wp->w_p_cc_cols;
1105 if (wlv.color_cols != NULL)
1106 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107#endif
1108
1109#ifdef FEAT_TERMINAL
1110 if (term_show_buffer(wp->w_buffer))
1111 {
1112 extra_check = TRUE;
1113 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001114 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115 }
1116#endif
1117
1118#ifdef FEAT_SPELL
1119 if (wp->w_p_spell
1120 && *wp->w_s->b_p_spl != NUL
1121 && wp->w_s->b_langp.ga_len > 0
1122 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
1123 {
1124 // Prepare for spell checking.
1125 has_spell = TRUE;
1126 extra_check = TRUE;
1127
1128 // Get the start of the next line, so that words that wrap to the
1129 // next line are found too: "et<line-break>al.".
1130 // Trick: skip a few chars for C/shell/Vim comments
1131 nextline[SPWORDLEN] = NUL;
1132 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1133 {
1134 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1135 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1136 }
1137
1138 // When a word wrapped from the previous line the start of the
1139 // current line is valid.
1140 if (lnum == checked_lnum)
1141 cur_checked_col = checked_col;
1142 checked_lnum = 0;
1143
1144 // When there was a sentence end in the previous line may require a
1145 // word starting with capital in this line. In line 1 always check
1146 // the first word.
1147 if (lnum != capcol_lnum)
1148 cap_col = -1;
1149 if (lnum == 1)
1150 cap_col = 0;
1151 capcol_lnum = 0;
1152 }
1153#endif
1154
1155 // handle Visual active in this window
1156 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1157 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001158 pos_T *top, *bot;
1159
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1161 {
1162 // Visual is after curwin->w_cursor
1163 top = &curwin->w_cursor;
1164 bot = &VIsual;
1165 }
1166 else
1167 {
1168 // Visual is before curwin->w_cursor
1169 top = &VIsual;
1170 bot = &curwin->w_cursor;
1171 }
1172 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1173 if (VIsual_mode == Ctrl_V)
1174 {
1175 // block mode
1176 if (lnum_in_visual_area)
1177 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001178 wlv.fromcol = wp->w_old_cursor_fcol;
1179 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001180 }
1181 }
1182 else
1183 {
1184 // non-block mode
1185 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001186 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187 else if (lnum == top->lnum)
1188 {
1189 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001190 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001191 else
1192 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001193 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001195 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 }
1197 }
1198 if (VIsual_mode != 'V' && lnum == bot->lnum)
1199 {
1200 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1201 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001202 wlv.fromcol = -10;
1203 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204 }
1205 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001206 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207 else
1208 {
1209 pos = *bot;
1210 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001211 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1212 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 else
1214 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001215 getvvcol(wp, &pos, NULL, NULL,
1216 (colnr_T *)&wlv.tocol);
1217 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 }
1219 }
1220 }
1221 }
1222
1223 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001224 if (!highlight_match && lnum == curwin->w_cursor.lnum
1225 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226#ifdef FEAT_GUI
1227 && !gui.in_use
1228#endif
1229 )
1230 noinvcur = TRUE;
1231
1232 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001233 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234 {
1235 area_highlighting = TRUE;
1236 vi_attr = HL_ATTR(HLF_V);
1237#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1238 if ((clip_star.available && !clip_star.owned
1239 && clip_isautosel_star())
1240 || (clip_plus.available && !clip_plus.owned
1241 && clip_isautosel_plus()))
1242 vi_attr = HL_ATTR(HLF_VNC);
1243#endif
1244 }
1245 }
1246
1247 // handle 'incsearch' and ":s///c" highlighting
1248 else if (highlight_match
1249 && wp == curwin
1250 && lnum >= curwin->w_cursor.lnum
1251 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1252 {
1253 if (lnum == curwin->w_cursor.lnum)
1254 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001255 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001257 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1259 {
1260 pos.lnum = lnum;
1261 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001262 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 }
1264 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001265 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001267 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1268 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 area_highlighting = TRUE;
1270 vi_attr = HL_ATTR(HLF_I);
1271 }
1272 }
1273
1274#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001275 wlv.filler_lines = diff_check(wp, lnum);
1276 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001278 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 {
1280 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001281 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001282 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001283 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001285 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 }
1287 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001288 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001289 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 area_highlighting = TRUE;
1291 }
1292 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001293 wlv.filler_lines = wp->w_topfill;
1294 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295#endif
1296
1297#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001298 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001299 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001300 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301#endif
1302
1303#ifdef LINE_ATTR
1304# ifdef FEAT_SIGNS
1305 // If this line has a sign with line highlighting set line_attr.
1306 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001307 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308# endif
1309# if defined(FEAT_QUICKFIX)
1310 // Highlight the current line in the quickfix window.
1311 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1312 line_attr = HL_ATTR(HLF_QFL);
1313# endif
1314 if (line_attr != 0)
1315 area_highlighting = TRUE;
1316#endif
1317
1318 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1319 ptr = line;
1320
1321#ifdef FEAT_SPELL
1322 if (has_spell && !number_only)
1323 {
1324 // For checking first word with a capital skip white space.
1325 if (cap_col == 0)
1326 cap_col = getwhitecols(line);
1327
1328 // To be able to spell-check over line boundaries copy the end of the
1329 // current line into nextline[]. Above the start of the next line was
1330 // copied to nextline[SPWORDLEN].
1331 if (nextline[SPWORDLEN] == NUL)
1332 {
1333 // No next line or it is empty.
1334 nextlinecol = MAXCOL;
1335 nextline_idx = 0;
1336 }
1337 else
1338 {
1339 v = (long)STRLEN(line);
1340 if (v < SPWORDLEN)
1341 {
1342 // Short line, use it completely and append the start of the
1343 // next line.
1344 nextlinecol = 0;
1345 mch_memmove(nextline, line, (size_t)v);
1346 STRMOVE(nextline + v, nextline + SPWORDLEN);
1347 nextline_idx = v + 1;
1348 }
1349 else
1350 {
1351 // Long line, use only the last SPWORDLEN bytes.
1352 nextlinecol = v - SPWORDLEN;
1353 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1354 nextline_idx = SPWORDLEN + 1;
1355 }
1356 }
1357 }
1358#endif
1359
1360 if (wp->w_p_list)
1361 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001362 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001363 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001364 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001365 || wp->w_lcs_chars.trail
1366 || wp->w_lcs_chars.lead
1367 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001368 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001369
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001371 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 {
1373 trailcol = (colnr_T)STRLEN(ptr);
1374 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1375 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001376 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001378 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001379 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001380 {
1381 leadcol = 0;
1382 while (VIM_ISWHITE(ptr[leadcol]))
1383 ++leadcol;
1384 if (ptr[leadcol] == NUL)
1385 // in a line full of spaces all of them are treated as trailing
1386 leadcol = (colnr_T)0;
1387 else
1388 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001389 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001390 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391 }
1392
Bram Moolenaard7657e92022-09-20 18:59:30 +01001393 wlv.wcr_attr = get_wcr_attr(wp);
1394 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001396 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 area_highlighting = TRUE;
1398 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001399
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001400#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001402 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403#endif
1404
1405 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1406 // first character to be displayed.
1407 if (wp->w_p_wrap)
1408 v = wp->w_skipcol;
1409 else
1410 v = wp->w_leftcol;
1411 if (v > 0 && !number_only)
1412 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001413 char_u *prev_ptr = ptr;
1414 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001415 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001417 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001418 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001420 charsize = win_lbr_chartabsize(&cts, NULL);
1421 cts.cts_vcol += charsize;
1422 prev_ptr = cts.cts_ptr;
1423 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001425 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001426 ptr = cts.cts_ptr;
1427 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428
1429 // When:
1430 // - 'cuc' is set, or
1431 // - 'colorcolumn' is set, or
1432 // - 'virtualedit' is set, or
1433 // - the visual mode is active,
1434 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001435 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001437 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438#endif
1439 virtual_active() ||
1440 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001441 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442
1443 // Handle a character that's not completely on the screen: Put ptr at
1444 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001445 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001447 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 ptr = prev_ptr;
1449 // If the character fits on the screen, don't need to skip it.
1450 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001451 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1452 && wlv.col == 0)
1453 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 }
1455
1456 // Adjust for when the inverted text is before the screen,
1457 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001458 if (wlv.tocol <= wlv.vcol)
1459 wlv.fromcol = 0;
1460 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1461 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462
1463#ifdef FEAT_LINEBREAK
1464 // When w_skipcol is non-zero, first line needs 'showbreak'
1465 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001466 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467#endif
1468#ifdef FEAT_SPELL
1469 // When spell checking a word we need to figure out the start of the
1470 // word and if it's badly spelled or not.
1471 if (has_spell)
1472 {
1473 int len;
1474 colnr_T linecol = (colnr_T)(ptr - line);
1475 hlf_T spell_hlf = HLF_COUNT;
1476
1477 pos = wp->w_cursor;
1478 wp->w_cursor.lnum = lnum;
1479 wp->w_cursor.col = linecol;
1480 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1481
1482 // spell_move_to() may call ml_get() and make "line" invalid
1483 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1484 ptr = line + linecol;
1485
1486 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1487 {
1488 // no bad word found at line start, don't check until end of a
1489 // word
1490 spell_hlf = HLF_COUNT;
1491 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1492 }
1493 else
1494 {
1495 // bad word found, use attributes until end of word
1496 word_end = wp->w_cursor.col + len + 1;
1497
1498 // Turn index into actual attributes.
1499 if (spell_hlf != HLF_COUNT)
1500 spell_attr = highlight_attr[spell_hlf];
1501 }
1502 wp->w_cursor = pos;
1503
1504# ifdef FEAT_SYN_HL
1505 // Need to restart syntax highlighting for this line.
1506 if (has_syntax)
1507 syntax_start(wp, lnum);
1508# endif
1509 }
1510#endif
1511 }
1512
1513 // Correct highlighting for cursor that can't be disabled.
1514 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001515 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001516 {
1517 if (noinvcur)
1518 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001519 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 {
1521 // highlighting starts at cursor, let it start just after the
1522 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001523 fromcol_prev = wlv.fromcol;
1524 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001526 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 // restart highlighting after the cursor
1528 fromcol_prev = wp->w_virtcol;
1529 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001530 if (wlv.fromcol >= wlv.tocol)
1531 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532 }
1533
1534#ifdef FEAT_SEARCH_EXTRA
1535 if (!number_only)
1536 {
1537 v = (long)(ptr - line);
1538 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1539 &line, &screen_search_hl,
1540 &search_attr);
1541 ptr = line + v; // "line" may have been updated
1542 }
1543#endif
1544
1545#ifdef FEAT_SYN_HL
1546 // Cursor line highlighting for 'cursorline' in the current window.
1547 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1548 {
1549 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001550 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 if (!(wp == curwin && VIsual_active)
1552 && wp->w_p_culopt_flags != CULOPT_NBR)
1553 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001554 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1556
1557 // Only set line_attr here when "screenline" is not present in
1558 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001559 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001561 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001562# ifdef FEAT_SIGNS
1563 // Combine the 'cursorline' and sign highlighting, depending on
1564 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001565 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001566 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001567 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001568 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001569 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001570 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001571 }
1572 else
1573# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001574# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001575 // let the line attribute overrule 'cursorline', otherwise
1576 // it disappears when both have background set;
1577 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001578 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001579# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001580 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001581# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582 }
1583 else
1584 {
1585 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1587 }
1588 area_highlighting = TRUE;
1589 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001590 }
1591#endif
1592
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001593#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594 {
1595 char_u *prop_start;
1596
1597 text_prop_count = get_text_props(wp->w_buffer, lnum,
1598 &prop_start, FALSE);
1599 if (text_prop_count > 0)
1600 {
1601 // Make a copy of the properties, so that they are properly
1602 // aligned.
1603 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1604 if (text_props != NULL)
1605 mch_memmove(text_props, prop_start,
1606 text_prop_count * sizeof(textprop_T));
1607
1608 // Allocate an array for the indexes.
1609 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001610 if (text_prop_idxs == NULL)
1611 VIM_CLEAR(text_props);
1612
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613 area_highlighting = TRUE;
1614 extra_check = TRUE;
1615 }
1616 }
1617#endif
1618
Bram Moolenaar1306b362022-08-06 15:59:06 +01001619 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620
1621 // Repeat for the whole displayed line.
1622 for (;;)
1623 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001624 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001626 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627#endif
1628#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001629 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001631
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001633 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001635#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001636 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001637 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001638 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001639 line_attr = line_attr_save;
1640 }
1641#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001643 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001645 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 if (cmdwin_type != 0 && wp == curwin)
1647 {
1648 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001649 wlv.n_extra = 1;
1650 wlv.c_extra = cmdwin_type;
1651 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001652 wlv.char_attr =
1653 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 }
1655 }
1656#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001658 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001660 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001661 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662 }
1663#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001664#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001665 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001667 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001668 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001670 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 }
1672#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001673 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001675 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001676 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001677 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001680 // Check if 'breakindent' applies and show it.
1681 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1682 if (wlv.n_extra == 0)
1683 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001688 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001689 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 }
1691#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001692 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001694 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001695 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 }
1697 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001698
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001700 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001701 && wlv.vcol >= left_curline_col
1702 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001704 wlv.cul_attr = HL_ATTR(HLF_CUL);
1705 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 }
1707#endif
1708
1709 // When still displaying '$' of change command, stop at cursor.
1710 // When only displaying the (relative) line number and that's done,
1711 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001712 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001713 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001714 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001716 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717#endif
1718 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001720 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1721 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 // Pretend we have finished updating the window. Except when
1723 // 'cursorcolumn' is set.
1724#ifdef FEAT_SYN_HL
1725 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001726 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 else
1728#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001729 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 break;
1731 }
1732
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 {
1735 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001736 if (wlv.vcol == wlv.fromcol
1737 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1738 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 && (*mb_ptr2cells)(ptr) > 1)
1740 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001741 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001742 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 area_attr = vi_attr; // start highlighting
1744 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001745 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001746 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 area_attr = 0; // stop highlighting
1748
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001749#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 if (text_props != NULL)
1751 {
1752 int pi;
1753 int bcol = (int)(ptr - line);
1754
Bram Moolenaar1306b362022-08-06 15:59:06 +01001755 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001756# ifdef FEAT_LINEBREAK
1757 && !in_linebreak
1758# endif
1759 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 --bcol; // still working on the previous char, e.g. Tab
1761
1762 // Check if any active property ends.
1763 for (pi = 0; pi < text_props_active; ++pi)
1764 {
1765 int tpi = text_prop_idxs[pi];
1766
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001767 if (text_props[tpi].tp_col != MAXCOL
1768 && bcol >= text_props[tpi].tp_col - 1
1769 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 {
1771 if (pi + 1 < text_props_active)
1772 mch_memmove(text_prop_idxs + pi,
1773 text_prop_idxs + pi + 1,
1774 sizeof(int)
1775 * (text_props_active - (pi + 1)));
1776 --text_props_active;
1777 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001778# ifdef FEAT_LINEBREAK
1779 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001780 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001781 syntax_attr = 0;
1782# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 }
1784 }
1785
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001786# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001787 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001788 // not on the next char yet, don't start another prop
1789 --bcol;
1790# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001792 // With 'nowrap' and not in the first screen line only "below"
1793 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001795 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001796 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001797 && (wp->w_p_wrap
1798 || wlv.row == startrow
1799 || (text_props[text_prop_next].tp_flags
1800 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001801 || (bcol == 0 &&
1802 (text_props[text_prop_next].tp_flags
1803 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001804 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001805 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001806 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001807 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1808 {
1809 // first display the '$' after the line
1810 text_prop_follows = TRUE;
1811 break;
1812 }
1813 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001814 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001815 + text_props[text_prop_next].tp_len)
1816 text_prop_idxs[text_props_active++] = text_prop_next;
1817 ++text_prop_next;
1818 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001820 if (wlv.n_extra == 0 || !extra_for_textprop)
1821 {
1822 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001823 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001824 text_prop_flags = 0;
1825 text_prop_type = NULL;
1826 text_prop_id = 0;
1827 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001828 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001830 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001831 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001832 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001833
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834 // Sort the properties on priority and/or starting last.
1835 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001836 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001837 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001838 sort_text_props(wp->w_buffer, text_props,
1839 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840
1841 for (pi = 0; pi < text_props_active; ++pi)
1842 {
1843 int tpi = text_prop_idxs[pi];
1844 proptype_T *pt = text_prop_type_by_id(
1845 wp->w_buffer, text_props[tpi].tp_type);
1846
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001847 if (pt != NULL && (pt->pt_hl_id > 0
1848 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001849 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001851 if (pt->pt_hl_id > 0)
1852 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853 text_prop_type = pt;
1854 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001855 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001856 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001857 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001858 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001859 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 }
1861 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001862 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001863 && -text_prop_id
1864 <= wp->w_buffer->b_textprop_text.ga_len)
1865 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001866 textprop_T *tp = &text_props[used_tpi];
1867 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001868 ->b_textprop_text.ga_data)[
1869 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001870 int above = (tp->tp_flags
1871 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001872
1873 // reset the ID in the copy to avoid it being used
1874 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001875 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001876
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001877 if (p != NULL)
1878 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001879 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001880 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001881 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001882 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001883 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1884 int padding = tp->tp_col == MAXCOL
1885 && tp->tp_len > 1
1886 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001887
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001888 // Insert virtual text before the current
1889 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001890 wlv.p_extra = p;
1891 wlv.c_extra = NUL;
1892 wlv.c_final = NUL;
1893 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001894 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001895 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001896 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001897 // restore search_attr and area_attr when n_extra
1898 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001899 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001900 saved_area_attr = area_attr;
1901 search_attr = 0;
1902 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001903 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001904 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001905 if (*ptr == NUL)
1906 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001907 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001908#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001909 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001910 {
1911 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001912 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001913 wlv.need_showbreak = FALSE;
1914 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001915 }
1916#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001917 if ((right || above || below || !wrap
1918 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001919 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001920 char_u *prev_p_extra = wlv.p_extra;
1921 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001922
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001923 // Take care of padding, right-align and
1924 // truncation.
1925 // Shared with win_lbr_chartabsize(), must do
1926 // exactly the same.
1927 start_line = text_prop_position(wp, tp,
1928 wlv.col,
1929 &wlv.n_extra, &wlv.p_extra,
1930 &n_attr, &n_attr_skip);
1931 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001932 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001933 // wlv.p_extra was allocated
1934 vim_free(p_extra_free2);
1935 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001936 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001937
Bram Moolenaara4abe512022-09-15 19:44:09 +01001938 if (lcs_eol_one < 0 && wlv.col
1939 + wlv.n_extra - 2 > wp->w_width)
1940 // don't bail out at end of line
1941 lcs_eol_one = 0;
1942
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001943 // When 'wrap' is off then for "below" we need
1944 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001945 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001946 {
1947 draw_screen_line(wp, &wlv);
1948
1949 // When line got too long for screen break
1950 // here.
1951 if (wlv.row == endrow)
1952 {
1953 ++wlv.row;
1954 break;
1955 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001956 win_line_start(wp, &wlv, TRUE);
1957 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001958 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001959 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001960 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001961
1962 // If another text prop follows the condition below at
1963 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001964 // If this is an "above" text prop and 'nowrap' the we
1965 // must wrap anyway.
1966 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001967 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001968 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001970 else if (text_prop_next < text_prop_count
1971 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001972 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1973 || (!wp->w_p_wrap
1974 && wlv.col == wp->w_width - 1
1975 && (text_props[text_prop_next].tp_flags
1976 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001977 // When at last-but-one character and a text property
1978 // follows after it, we may need to flush the line after
1979 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001980 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001981 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 }
1983#endif
1984
Bram Moolenaare38fc862022-08-11 17:24:50 +01001985#ifdef FEAT_SEARCH_EXTRA
1986 if (wlv.n_extra == 0)
1987 {
1988 // Check for start/end of 'hlsearch' and other matches.
1989 // After end, check for start/end of next match.
1990 // When another match, have to check for start again.
1991 v = (long)(ptr - line);
1992 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1993 &screen_search_hl, &has_match_conc,
1994 &match_conc, did_line_attr, lcs_eol_one,
1995 &on_last_col);
1996 ptr = line + v; // "line" may have been changed
1997 prev_ptr = ptr;
1998
1999 // Do not allow a conceal over EOL otherwise EOL will be missed
2000 // and bad things happen.
2001 if (*ptr == NUL)
2002 has_match_conc = 0;
2003 }
2004#endif
2005
2006#ifdef FEAT_DIFF
2007 if (wlv.diff_hlf != (hlf_T)0)
2008 {
2009 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2010 && wlv.n_extra == 0)
2011 wlv.diff_hlf = HLF_TXD; // changed text
2012 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2013 && wlv.n_extra == 0)
2014 wlv.diff_hlf = HLF_CHD; // changed line
2015 line_attr = HL_ATTR(wlv.diff_hlf);
2016 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2017 && wp->w_p_culopt_flags != CULOPT_NBR
2018 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2019 && wlv.vcol <= right_curline_col)))
2020 line_attr = hl_combine_attr(
2021 line_attr, HL_ATTR(HLF_CUL));
2022 }
2023#endif
2024
Bram Moolenaara74fda62019-10-19 17:38:03 +02002025#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002026 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002027 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002028 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002029# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002030 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002031 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002032# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002033 // Get syntax attribute.
2034 if (has_syntax)
2035 {
2036 // Get the syntax attribute for the character. If there
2037 // is an error, disable syntax highlighting.
2038 save_did_emsg = did_emsg;
2039 did_emsg = FALSE;
2040
2041 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002042 if (v == prev_syntax_col)
2043 // at same column again
2044 syntax_attr = prev_syntax_attr;
2045 else
2046 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002047# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002048 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002049# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002050 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002051# ifdef FEAT_SPELL
2052 has_spell ? &can_spell :
2053# endif
2054 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002055 prev_syntax_col = v;
2056 prev_syntax_attr = syntax_attr;
2057 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002058
Bram Moolenaar34390282019-10-16 14:38:26 +02002059 if (did_emsg)
2060 {
2061 wp->w_s->b_syn_error = TRUE;
2062 has_syntax = FALSE;
2063 syntax_attr = 0;
2064 }
2065 else
2066 did_emsg = save_did_emsg;
2067# ifdef SYN_TIME_LIMIT
2068 if (wp->w_s->b_syn_slow)
2069 has_syntax = FALSE;
2070# endif
2071
2072 // Need to get the line again, a multi-line regexp may
2073 // have made it invalid.
2074 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2075 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002076 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002077# ifdef FEAT_CONCEAL
2078 // no concealing past the end of the line, it interferes
2079 // with line highlighting
2080 if (*ptr == NUL)
2081 syntax_flags = 0;
2082 else
2083 syntax_flags = get_syntax_info(&syntax_seqnr);
2084# endif
2085 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002086 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002087# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002088 // Combine text property highlight into syntax highlight.
2089 if (text_prop_type != NULL)
2090 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002091 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002092 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2093 else
2094 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002095 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002096 }
2097# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002098#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002099
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002100 // Decide which of the highlight attributes to use.
2101 attr_pri = TRUE;
2102#ifdef LINE_ATTR
2103 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002104 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002105 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002106 if (!highlight_match)
2107 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002108 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002109# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002110 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002111# endif
2112 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002114 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002115 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002116# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002117 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002118# endif
2119 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002120 else if (line_attr != 0
2121 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2122 || wlv.vcol < wlv.fromcol
2123 || vcol_prev < fromcol_prev
2124 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 {
2126 // Use line_attr when not in the Visual or 'incsearch' area
2127 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002128# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002130# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002131 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002132# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002133 attr_pri = FALSE;
2134 }
2135#else
2136 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002139 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002140#endif
2141 else
2142 {
2143 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002144#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002145 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002146#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002147 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002148#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002149 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002150#ifdef FEAT_PROP_POPUP
2151 // override with text property highlight when "override" is TRUE
2152 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002154#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002155 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002156
2157 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002158 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002159 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 if (wlv.char_attr == 0)
2161 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002162 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002163 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002164 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165
2166 // Get the next character to put on the screen.
2167
2168 // The "p_extra" points to the extra stuff that is inserted to
2169 // represent special characters (non-printable stuff) and other
2170 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002171 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002172 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2173 // "p_extra[n_extra]".
2174 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002175 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002177 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002178 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002179 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2180 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002181 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2182 if (enc_utf8 && utf_char2len(c) > 1)
2183 {
2184 mb_utf8 = TRUE;
2185 u8cc[0] = 0;
2186 c = 0xc0;
2187 }
2188 else
2189 mb_utf8 = FALSE;
2190 }
2191 else
2192 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002193 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 if (has_mbyte)
2195 {
2196 mb_c = c;
2197 if (enc_utf8)
2198 {
2199 // If the UTF-8 character is more than one byte:
2200 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002201 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002203 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 mb_l = 1;
2205 else if (mb_l > 1)
2206 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002207 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 mb_utf8 = TRUE;
2209 c = 0xc0;
2210 }
2211 }
2212 else
2213 {
2214 // if this is a DBCS character, put it in "mb_c"
2215 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 mb_l = 1;
2218 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002219 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 }
2221 if (mb_l == 0) // at the NUL at end-of-line
2222 mb_l = 1;
2223
2224 // If a double-width char doesn't fit display a '>' in the
2225 // last column.
2226 if ((
2227# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002228 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002229# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002230 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 && (*mb_char2cells)(mb_c) == 2)
2232 {
2233 c = '>';
2234 mb_c = c;
2235 mb_l = 1;
2236 mb_utf8 = FALSE;
2237 multi_attr = HL_ATTR(HLF_AT);
2238#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002239 if (wlv.cul_attr)
2240 multi_attr = hl_combine_attr(
2241 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002242#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002243 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002244
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245 // put the pointer back to output the double-width
2246 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 ++wlv.n_extra;
2248 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 }
2250 else
2251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002252 wlv.n_extra -= mb_l - 1;
2253 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254 }
2255 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002256 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002258 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002259#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002260 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002261 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002262 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002263 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002264 if (search_attr == 0)
2265 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002266 if (area_attr == 0 && *ptr != NUL)
2267 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002268 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002269#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 }
2271 else
2272 {
2273#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002274 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002276 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 // Get a character from the line itself.
2279 c = *ptr;
2280#ifdef FEAT_LINEBREAK
2281 c0 = *ptr;
2282#endif
2283 if (has_mbyte)
2284 {
2285 mb_c = c;
2286 if (enc_utf8)
2287 {
2288 // If the UTF-8 character is more than one byte: Decode it
2289 // into "mb_c".
2290 mb_l = utfc_ptr2len(ptr);
2291 mb_utf8 = FALSE;
2292 if (mb_l > 1)
2293 {
2294 mb_c = utfc_ptr2char(ptr, u8cc);
2295 // Overlong encoded ASCII or ASCII with composing char
2296 // is displayed normally, except a NUL.
2297 if (mb_c < 0x80)
2298 {
2299 c = mb_c;
2300#ifdef FEAT_LINEBREAK
2301 c0 = mb_c;
2302#endif
2303 }
2304 mb_utf8 = TRUE;
2305
2306 // At start of the line we can have a composing char.
2307 // Draw it as a space with a composing char.
2308 if (utf_iscomposing(mb_c))
2309 {
2310 int i;
2311
2312 for (i = Screen_mco - 1; i > 0; --i)
2313 u8cc[i] = u8cc[i - 1];
2314 u8cc[0] = mb_c;
2315 mb_c = ' ';
2316 }
2317 }
2318
2319 if ((mb_l == 1 && c >= 0x80)
2320 || (mb_l >= 1 && mb_c == 0)
2321 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2322 {
2323 // Illegal UTF-8 byte: display as <xx>.
2324 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002325 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326# ifdef FEAT_RIGHTLEFT
2327 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002328 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002330 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002331 c = *wlv.p_extra;
2332 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002334 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2335 wlv.c_extra = NUL;
2336 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 if (area_attr == 0 && search_attr == 0)
2338 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002339 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002340 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002341 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002342 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343 }
2344 }
2345 else if (mb_l == 0) // at the NUL at end-of-line
2346 mb_l = 1;
2347#ifdef FEAT_ARABIC
2348 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2349 {
2350 // Do Arabic shaping.
2351 int pc, pc1, nc;
2352 int pcc[MAX_MCO];
2353
2354 // The idea of what is the previous and next
2355 // character depends on 'rightleft'.
2356 if (wp->w_p_rl)
2357 {
2358 pc = prev_c;
2359 pc1 = prev_c1;
2360 nc = utf_ptr2char(ptr + mb_l);
2361 prev_c1 = u8cc[0];
2362 }
2363 else
2364 {
2365 pc = utfc_ptr2char(ptr + mb_l, pcc);
2366 nc = prev_c;
2367 pc1 = pcc[0];
2368 }
2369 prev_c = mb_c;
2370
2371 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2372 }
2373 else
2374 prev_c = mb_c;
2375#endif
2376 }
2377 else // enc_dbcs
2378 {
2379 mb_l = MB_BYTE2LEN(c);
2380 if (mb_l == 0) // at the NUL at end-of-line
2381 mb_l = 1;
2382 else if (mb_l > 1)
2383 {
2384 // We assume a second byte below 32 is illegal.
2385 // Hopefully this is OK for all double-byte encodings!
2386 if (ptr[1] >= 32)
2387 mb_c = (c << 8) + ptr[1];
2388 else
2389 {
2390 if (ptr[1] == NUL)
2391 {
2392 // head byte at end of line
2393 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002394 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 }
2396 else
2397 {
2398 // illegal tail byte
2399 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002400 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002402 wlv.p_extra = wlv.extra;
2403 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 wlv.c_extra = NUL;
2405 wlv.c_final = NUL;
2406 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 if (area_attr == 0 && search_attr == 0)
2408 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002409 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002410 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002411 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 // save current attr
2413 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 }
2415 mb_c = c;
2416 }
2417 }
2418 }
2419 // If a double-width char doesn't fit display a '>' in the
2420 // last column; the character is displayed at the start of the
2421 // next line.
2422 if ((
2423# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002424 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002426 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 && (*mb_char2cells)(mb_c) == 2)
2428 {
2429 c = '>';
2430 mb_c = c;
2431 mb_utf8 = FALSE;
2432 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002433 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 // Put pointer back so that the character will be
2435 // displayed at the start of the next line.
2436 --ptr;
2437#ifdef FEAT_CONCEAL
2438 did_decrement_ptr = TRUE;
2439#endif
2440 }
2441 else if (*ptr != NUL)
2442 ptr += mb_l - 1;
2443
2444 // If a double-width char doesn't fit at the left side display
2445 // a '<' in the first column. Don't do this for unprintable
2446 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002447 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002449 wlv.n_extra = 1;
2450 wlv.c_extra = MB_FILLER_CHAR;
2451 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002452 c = ' ';
2453 if (area_attr == 0 && search_attr == 0)
2454 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002455 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002456 extra_attr = hl_combine_attr(
2457 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 }
2460 mb_c = c;
2461 mb_utf8 = FALSE;
2462 mb_l = 1;
2463 }
2464
2465 }
2466 ++ptr;
2467
2468 if (extra_check)
2469 {
2470#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 // Check spelling (unless at the end of the line).
2472 // Only do this when there is no syntax highlighting, the
2473 // @Spell cluster is not used or the current syntax item
2474 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002475 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 if (has_spell && v >= word_end && v > cur_checked_col)
2477 {
2478 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002479 // do not calculate cap_col at the end of the line or when
2480 // only white space is following
2481 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002482# ifdef FEAT_SYN_HL
2483 !has_syntax ||
2484# endif
2485 can_spell))
2486 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002487 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 int len;
2489 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002490
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493
2494 // Use nextline[] if possible, it has the start of the
2495 // next line concatenated.
2496 if ((prev_ptr - line) - nextlinecol >= 0)
2497 p = nextline + (prev_ptr - line) - nextlinecol;
2498 else
2499 p = prev_ptr;
2500 cap_col -= (int)(prev_ptr - line);
2501 len = spell_check(wp, p, &spell_hlf, &cap_col,
2502 nochange);
2503 word_end = v + len;
2504
2505 // In Insert mode only highlight a word that
2506 // doesn't touch the cursor.
2507 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002508 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 && wp->w_cursor.lnum == lnum
2510 && wp->w_cursor.col >=
2511 (colnr_T)(prev_ptr - line)
2512 && wp->w_cursor.col < (colnr_T)word_end)
2513 {
2514 spell_hlf = HLF_COUNT;
2515 spell_redraw_lnum = lnum;
2516 }
2517
2518 if (spell_hlf == HLF_COUNT && p != prev_ptr
2519 && (p - nextline) + len > nextline_idx)
2520 {
2521 // Remember that the good word continues at the
2522 // start of the next line.
2523 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002524 checked_col = (int)((p - nextline)
2525 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 }
2527
2528 // Turn index into actual attributes.
2529 if (spell_hlf != HLF_COUNT)
2530 spell_attr = highlight_attr[spell_hlf];
2531
2532 if (cap_col > 0)
2533 {
2534 if (p != prev_ptr
2535 && (p - nextline) + cap_col >= nextline_idx)
2536 {
2537 // Remember that the word in the next line
2538 // must start with a capital.
2539 capcol_lnum = lnum + 1;
2540 cap_col = (int)((p - nextline) + cap_col
2541 - nextline_idx);
2542 }
2543 else
2544 // Compute the actual column.
2545 cap_col += (int)(prev_ptr - line);
2546 }
2547 }
2548 }
2549 if (spell_attr != 0)
2550 {
2551 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002552 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2553 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002555 wlv.char_attr = hl_combine_attr(spell_attr,
2556 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 }
2558#endif
2559#ifdef FEAT_LINEBREAK
2560 // Found last space before word: check for line break.
2561 if (wp->w_p_lbr && c0 == c
2562 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2563 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002564 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2565 : 0;
2566 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002567 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002568
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002569 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002570# ifdef FEAT_PROP_POPUP
2571 // do not want virtual text counted here
2572 cts.cts_has_prop_with_text = FALSE;
2573# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002574 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002575 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002576
2577 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002578 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002579 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002580 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002581 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2582 if (wlv.n_extra < 0)
2583 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002584 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002585 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002586 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002587 // line break, but for TABs the highlighting should
2588 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002589 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002590
Bram Moolenaar1306b362022-08-06 15:59:06 +01002591 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002594 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 wp->w_buffer->b_p_vts_array) - 1;
2596# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002597 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002598 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599# endif
2600
Bram Moolenaar1306b362022-08-06 15:59:06 +01002601 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2602 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002603# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002605 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002606# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 if (VIM_ISWHITE(c))
2608 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002609# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 if (c == TAB)
2611 // See "Tab alignment" below.
2612 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002613# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 if (!wp->w_p_list)
2615 c = ' ';
2616 }
2617 }
2618#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002619 in_multispace = c == ' '
2620 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2621 if (!in_multispace)
2622 multispace_pos = 0;
2623
Bram Moolenaareed9d462021-02-15 20:38:25 +01002624 // 'list': Change char 160 to 'nbsp' and space to 'space'
2625 // setting in 'listchars'. But not when the character is
2626 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 if (wp->w_p_list
2628 && ((((c == 160 && mb_l == 1)
2629 || (mb_utf8
2630 && ((mb_c == 160 && mb_l == 2)
2631 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002632 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 || (c == ' '
2634 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002635 && (wp->w_lcs_chars.space
2636 || (in_multispace
2637 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002638 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 && ptr - line <= trailcol)))
2640 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002641 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2642 {
2643 c = wp->w_lcs_chars.multispace[multispace_pos++];
2644 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2645 multispace_pos = 0;
2646 }
2647 else
2648 c = (c == ' ') ? wp->w_lcs_chars.space
2649 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002650 if (area_attr == 0 && search_attr == 0)
2651 {
2652 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002653 extra_attr = hl_combine_attr(wlv.win_attr,
2654 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002655 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656 }
2657 mb_c = c;
2658 if (enc_utf8 && utf_char2len(c) > 1)
2659 {
2660 mb_utf8 = TRUE;
2661 u8cc[0] = 0;
2662 c = 0xc0;
2663 }
2664 else
2665 mb_utf8 = FALSE;
2666 }
2667
zeertzjq2e7cba32022-06-10 15:30:32 +01002668 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2669 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002670 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002671 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2672 && wp->w_lcs_chars.leadmultispace != NULL)
2673 {
2674 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002675 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2676 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002677 multispace_pos = 0;
2678 }
2679
2680 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2681 c = wp->w_lcs_chars.trail;
2682
2683 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2684 c = wp->w_lcs_chars.lead;
2685
zeertzjq2e7cba32022-06-10 15:30:32 +01002686 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002687 c = wp->w_lcs_chars.space;
2688
2689
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 if (!attr_pri)
2691 {
2692 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002693 extra_attr = hl_combine_attr(wlv.win_attr,
2694 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002695 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002696 }
2697 mb_c = c;
2698 if (enc_utf8 && utf_char2len(c) > 1)
2699 {
2700 mb_utf8 = TRUE;
2701 u8cc[0] = 0;
2702 c = 0xc0;
2703 }
2704 else
2705 mb_utf8 = FALSE;
2706 }
2707 }
2708
2709 // Handling of non-printable characters.
2710 if (!vim_isprintc(c))
2711 {
2712 // when getting a character from the file, we may have to
2713 // turn it into something else on the way to putting it
2714 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002715 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002716 {
2717 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002718 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002720 char_u *sbr = get_showbreak_value(wp);
2721
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 // only adjust the tab_len, when at the first column
2723 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002724 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002725 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726#endif
2727 // tab amount depends on current column
2728#ifdef FEAT_VARTABS
2729 tab_len = tabstop_padding(vcol_adjusted,
2730 wp->w_buffer->b_p_ts,
2731 wp->w_buffer->b_p_vts_array) - 1;
2732#else
2733 tab_len = (int)wp->w_buffer->b_p_ts
2734 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2735#endif
2736
2737#ifdef FEAT_LINEBREAK
2738 if (!wp->w_p_lbr || !wp->w_p_list)
2739#endif
2740 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002741 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742#ifdef FEAT_LINEBREAK
2743 else
2744 {
2745 char_u *p;
2746 int len;
2747 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002748 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002749
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002750# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002751 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002753 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002754
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002756 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002757 && old_boguscols > 0
2758 && wlv.n_extra > tab_len)
2759 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002760# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002763 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002764 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002765 if (wp->w_lcs_chars.tab3)
2766 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 if (wlv.n_extra > 0)
2768 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002769 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002771 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002772 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002773 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002775 vim_memset(p, ' ', len);
2776 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002777 vim_free(wlv.p_extra_free);
2778 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002779 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002781 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002783 if (*p == NUL)
2784 {
2785 tab_len = i;
2786 break;
2787 }
2788
2789 // if tab3 is given, use it for the last char
2790 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2791 lcs = wp->w_lcs_chars.tab3;
2792 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002795 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002796 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002797# ifdef FEAT_CONCEAL
2798 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2799 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002800 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002802# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804 }
2805#endif
2806#ifdef FEAT_CONCEAL
2807 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002808 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809
2810 // Tab alignment should be identical regardless of
2811 // 'conceallevel' value. So tab compensates of all
2812 // previous concealed characters, and thus resets
2813 // vcol_off and boguscols accumulated so far in the
2814 // line. Note that the tab can be longer than
2815 // 'tabstop' when there are concealed characters.
2816 FIX_FOR_BOGUSCOLS;
2817
2818 // Make sure, the highlighting for the tab char will be
2819 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002820 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002821 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002822 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823 tab_len += vc_saved;
2824 }
2825#endif
2826 mb_utf8 = FALSE; // don't draw as UTF-8
2827 if (wp->w_p_list)
2828 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002829 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002830 ? wp->w_lcs_chars.tab3
2831 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832#ifdef FEAT_LINEBREAK
2833 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002834 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 else
2836#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002837 wlv.c_extra = wp->w_lcs_chars.tab2;
2838 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002840 extra_attr = hl_combine_attr(wlv.win_attr,
2841 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002842 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002843 mb_c = c;
2844 if (enc_utf8 && utf_char2len(c) > 1)
2845 {
2846 mb_utf8 = TRUE;
2847 u8cc[0] = 0;
2848 c = 0xc0;
2849 }
2850 }
2851 else
2852 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 wlv.c_final = NUL;
2854 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 c = ' ';
2856 }
2857 }
2858 else if (c == NUL
2859 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002860 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2861 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 && VIsual_mode != Ctrl_V
2863 && (
2864# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002865 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002867 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 && !(noinvcur
2869 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 && lcs_eol_one > 0)
2872 {
2873 // Display a '$' after the line or highlight an extra
2874 // character if the line break is included.
2875#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2876 // For a diff line the highlighting continues after the
2877 // "$".
2878 if (
2879# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002880 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881# ifdef LINE_ATTR
2882 &&
2883# endif
2884# endif
2885# ifdef LINE_ATTR
2886 line_attr == 0
2887# endif
2888 )
2889#endif
2890 {
2891 // In virtualedit, visual selections may extend
2892 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002893 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002894 && wlv.tocol != MAXCOL
2895 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002896 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002897 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002899 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2900 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 else
2902 c = ' ';
2903 lcs_eol_one = -1;
2904 --ptr; // put it back at the NUL
2905 if (!attr_pri)
2906 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002907 extra_attr = hl_combine_attr(wlv.win_attr,
2908 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 n_attr = 1;
2910 }
2911 mb_c = c;
2912 if (enc_utf8 && utf_char2len(c) > 1)
2913 {
2914 mb_utf8 = TRUE;
2915 u8cc[0] = 0;
2916 c = 0xc0;
2917 }
2918 else
2919 mb_utf8 = FALSE; // don't draw as UTF-8
2920 }
2921 else if (c != NUL)
2922 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002923 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2924 if (wlv.n_extra == 0)
2925 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926#ifdef FEAT_RIGHTLEFT
2927 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002928 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002930 wlv.c_extra = NUL;
2931 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932#ifdef FEAT_LINEBREAK
2933 if (wp->w_p_lbr)
2934 {
2935 char_u *p;
2936
Bram Moolenaar1306b362022-08-06 15:59:06 +01002937 c = *wlv.p_extra;
2938 p = alloc(wlv.n_extra + 1);
2939 vim_memset(p, ' ', wlv.n_extra);
2940 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2941 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002942 vim_free(wlv.p_extra_free);
2943 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 }
2945 else
2946#endif
2947 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002948 wlv.n_extra = byte2cells(c) - 1;
2949 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950 }
2951 if (!attr_pri)
2952 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002953 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002954 extra_attr = hl_combine_attr(wlv.win_attr,
2955 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 }
2958 mb_utf8 = FALSE; // don't draw as UTF-8
2959 }
2960 else if (VIsual_active
2961 && (VIsual_mode == Ctrl_V
2962 || VIsual_mode == 'v')
2963 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002964 && wlv.tocol != MAXCOL
2965 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 && (
2967#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002968 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002970 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 {
2972 c = ' ';
2973 --ptr; // put it back at the NUL
2974 }
2975#if defined(LINE_ATTR)
2976 else if ((
2977# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002978 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979# endif
2980# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002981 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982# endif
2983 line_attr != 0
2984 ) && (
2985# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002986 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002988 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002990 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991# endif
2992 < wp->w_width)))
2993 {
2994 // Highlight until the right side of the window
2995 c = ' ';
2996 --ptr; // put it back at the NUL
2997
2998 // Remember we do the char for line highlighting.
2999 ++did_line_attr;
3000
3001 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003002 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003004 || (wp->w_p_list &&
3005 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003006 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003010 wlv.diff_hlf = HLF_CHD;
3011 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003013 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3015 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003017 || (wlv.vcol >= left_curline_col
3018 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 wlv.char_attr = hl_combine_attr(
3020 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 }
3022 }
3023# endif
3024# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003027 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003028 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3029 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003030 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 if (!wlv.cul_screenline
3032 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003033 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003034 wlv.char_attr = hl_combine_attr(
3035 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 }
3037 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3039 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 }
3041# endif
3042 }
3043#endif
3044 }
3045
3046#ifdef FEAT_CONCEAL
3047 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003048 && (wp != curwin || lnum != wp->w_cursor.lnum
3049 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3051 && !(lnum_in_visual_area
3052 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3053 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003054 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003055 if (((prev_syntax_id != syntax_seqnr
3056 && (syntax_flags & HL_CONCEAL) != 0)
3057 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003058 && (syn_get_sub_char() != NUL
3059 || (has_match_conc && match_conc)
3060 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061 && wp->w_p_cole != 3)
3062 {
3063 // First time at this concealed item: display one
3064 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003065 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 c = match_conc;
3067 else if (syn_get_sub_char() != NUL)
3068 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003069 else if (wp->w_lcs_chars.conceal != NUL)
3070 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 else
3072 c = ' ';
3073
3074 prev_syntax_id = syntax_seqnr;
3075
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 if (wlv.n_extra > 0)
3077 wlv.vcol_off += wlv.n_extra;
3078 wlv.vcol += wlv.n_extra;
3079 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 {
3081# ifdef FEAT_RIGHTLEFT
3082 if (wp->w_p_rl)
3083 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003084 wlv.col -= wlv.n_extra;
3085 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 }
3087 else
3088# endif
3089 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003090 wlv.boguscols += wlv.n_extra;
3091 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 }
3093 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003094 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 n_attr = 0;
3096 }
3097 else if (n_skip == 0)
3098 {
3099 is_concealing = TRUE;
3100 n_skip = 1;
3101 }
3102 mb_c = c;
3103 if (enc_utf8 && utf_char2len(c) > 1)
3104 {
3105 mb_utf8 = TRUE;
3106 u8cc[0] = 0;
3107 c = 0xc0;
3108 }
3109 else
3110 mb_utf8 = FALSE; // don't draw as UTF-8
3111 }
3112 else
3113 {
3114 prev_syntax_id = 0;
3115 is_concealing = FALSE;
3116 }
3117
3118 if (n_skip > 0 && did_decrement_ptr)
3119 // not showing the '>', put pointer back to avoid getting stuck
3120 ++ptr;
3121
3122#endif // FEAT_CONCEAL
3123 }
3124
3125#ifdef FEAT_CONCEAL
3126 // In the cursor line and we may be concealing characters: correct
3127 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 && wp == curwin && lnum == wp->w_cursor.lnum
3130 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003131 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003133# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003135 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003137# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003138 wp->w_wcol = wlv.col - wlv.boguscols;
3139 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 did_wcol = TRUE;
3141 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003142# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003143 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003144# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 }
3146#endif
3147
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003148 // Use "extra_attr", but don't override visual selection highlighting,
3149 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003150 // Don't use "extra_attr" until n_attr_skip is zero.
3151 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003153 && (!attr_pri
3154#ifdef FEAT_PROP_POPUP
3155 || (text_prop_flags & PT_FLAG_OVERRIDE)
3156#endif
3157 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 {
3159#ifdef LINE_ATTR
3160 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003161 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 else
3163#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 }
3166
3167#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3168 // XIM don't send preedit_start and preedit_end, but they send
3169 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3170 // im_is_preediting() here.
3171 if (p_imst == IM_ON_THE_SPOT
3172 && xic != NULL
3173 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003174 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 && !p_imdisable
3176 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003177 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 {
3179 colnr_T tcol;
3180
3181 if (preedit_end_col == MAXCOL)
3182 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3183 else
3184 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003185 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 {
3187 if (feedback_old_attr < 0)
3188 {
3189 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003192 wlv.char_attr = im_get_feedback_attr(feedback_col);
3193 if (wlv.char_attr < 0)
3194 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 feedback_col++;
3196 }
3197 else if (feedback_old_attr >= 0)
3198 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003199 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 feedback_old_attr = -1;
3201 feedback_col = 0;
3202 }
3203 }
3204#endif
3205 // Handle the case where we are in column 0 but not on the first
3206 // character of the line and the user wants us to show us a
3207 // special character (via 'listchars' option "precedes:<char>".
3208 if (lcs_prec_todo != NUL
3209 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003210 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003211 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003212 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003214 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003216 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 && c != NUL)
3218 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003219 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 lcs_prec_todo = NUL;
3221 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3222 {
3223 // Double-width character being overwritten by the "precedes"
3224 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003225 wlv.c_extra = MB_FILLER_CHAR;
3226 wlv.c_final = NUL;
3227 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003229 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 }
3231 mb_c = c;
3232 if (enc_utf8 && utf_char2len(c) > 1)
3233 {
3234 mb_utf8 = TRUE;
3235 u8cc[0] = 0;
3236 c = 0xc0;
3237 }
3238 else
3239 mb_utf8 = FALSE; // don't draw as UTF-8
3240 if (!attr_pri)
3241 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003242 saved_attr3 = wlv.char_attr; // save current attr
3243 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244 n_attr3 = 1;
3245 }
3246 }
3247
3248 // At end of the text line or just after the last character.
3249 if ((c == NUL
3250#if defined(LINE_ATTR)
3251 || did_line_attr == 1
3252#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003253 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 {
3255#ifdef FEAT_SEARCH_EXTRA
3256 // flag to indicate whether prevcol equals startcol of search_hl or
3257 // one of the matches
3258 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3259 (long)(ptr - line) - (c == NUL));
3260#endif
3261 // Invert at least one char, used for Visual and empty line or
3262 // highlight match at end of line. If it's beyond the last
3263 // char on the screen, just overwrite that one (tricky!) Not
3264 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003265 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003266 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 && (VIsual_mode != Ctrl_V
3268 || lnum == VIsual.lnum
3269 || lnum == curwin->w_cursor.lnum)
3270 && c == NUL)
3271#ifdef FEAT_SEARCH_EXTRA
3272 // highlight 'hlsearch' match at end of line
3273 || (prevcol_hl_flag
3274# ifdef FEAT_SYN_HL
3275 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3276 && !(wp == curwin && VIsual_active))
3277# endif
3278# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280# endif
3281# if defined(LINE_ATTR)
3282 && did_line_attr <= 1
3283# endif
3284 )
3285#endif
3286 ))
3287 {
3288 int n = 0;
3289
3290#ifdef FEAT_RIGHTLEFT
3291 if (wp->w_p_rl)
3292 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294 n = 1;
3295 }
3296 else
3297#endif
3298 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 n = -1;
3301 }
3302 if (n != 0)
3303 {
3304 // At the window boundary, highlight the last character
3305 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 wlv.off += n;
3307 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 }
3309 else
3310 {
3311 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003312 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003314 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 }
3316#ifdef FEAT_SEARCH_EXTRA
3317 if (area_attr == 0)
3318 {
3319 // Use attributes from match with highest priority among
3320 // 'search_hl' and the match list.
3321 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003322 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 }
3324#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003325 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003326 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327#ifdef FEAT_RIGHTLEFT
3328 if (wp->w_p_rl)
3329 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003330 --wlv.col;
3331 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 }
3333 else
3334#endif
3335 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 ++wlv.col;
3337 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003339 ++wlv.vcol;
3340 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 }
3342 }
3343
3344 // At end of the text line.
3345 if (c == NUL)
3346 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003347 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348
3349 // Update w_cline_height and w_cline_folded if the cursor line was
3350 // updated (saves a call to plines() later).
3351 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3352 {
3353 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003354 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355#ifdef FEAT_FOLDING
3356 curwin->w_cline_folded = FALSE;
3357#endif
3358 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3359 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 break;
3361 }
3362
3363 // Show "extends" character from 'listchars' if beyond the line end and
3364 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003365 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 && wp->w_p_list
3368 && !wp->w_p_wrap
3369#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003370 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371#endif
3372 && (
3373#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003374 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003376 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003378 || lcs_eol_one > 0
3379 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003380 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003382 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 mb_c = c;
3385 if (enc_utf8 && utf_char2len(c) > 1)
3386 {
3387 mb_utf8 = TRUE;
3388 u8cc[0] = 0;
3389 c = 0xc0;
3390 }
3391 else
3392 mb_utf8 = FALSE;
3393 }
3394
3395#ifdef FEAT_SYN_HL
3396 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003397 if (wlv.draw_color_col)
3398 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399
3400 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3401 // highlight the cursor position itself.
3402 // Also highlight the 'colorcolumn' if it is different than
3403 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003404 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3405 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003407 if (((wlv.draw_state == WL_LINE
3408 || wlv.draw_state == WL_BRI
3409 || wlv.draw_state == WL_SBR)
3410 && !lnum_in_visual_area
3411 && search_attr == 0
3412 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003413# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003414 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003415# endif
3416 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417 {
3418 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3419 && lnum != wp->w_cursor.lnum)
3420 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003421 vcol_save_attr = wlv.char_attr;
3422 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3423 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003427 vcol_save_attr = wlv.char_attr;
3428 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 }
3430 }
3431#endif
3432
3433 // Store character to be displayed.
3434 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 {
3438 // Store the character.
3439#if defined(FEAT_RIGHTLEFT)
3440 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3441 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003442 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003443 --wlv.off;
3444 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 }
3446#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003447 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448 if (enc_dbcs == DBCS_JPNU)
3449 {
3450 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 ScreenLines[wlv.off] = 0x8e;
3452 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 }
3454 else if (enc_utf8)
3455 {
3456 if (mb_utf8)
3457 {
3458 int i;
3459
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003462 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463 for (i = 0; i < Screen_mco; ++i)
3464 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003465 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 if (u8cc[i] == 0)
3467 break;
3468 }
3469 }
3470 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 }
3473 if (multi_attr)
3474 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 multi_attr = 0;
3477 }
3478 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003479 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003481 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003482
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3484 {
3485 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003486 ++wlv.off;
3487 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 if (enc_utf8)
3489 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003490 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 else
3492 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003494 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003496 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497#endif
3498 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003499 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003500 // When "wlv.tocol" is halfway a character, set it to the end
3501 // of the character, otherwise highlighting won't stop.
3502 if (wlv.tocol == wlv.vcol)
3503 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003504
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003506
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507#ifdef FEAT_RIGHTLEFT
3508 if (wp->w_p_rl)
3509 {
3510 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 --wlv.off;
3512 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 }
3514#endif
3515 }
3516#ifdef FEAT_RIGHTLEFT
3517 if (wp->w_p_rl)
3518 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 --wlv.off;
3520 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 }
3522 else
3523#endif
3524 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 ++wlv.off;
3526 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 }
3528 }
3529#ifdef FEAT_CONCEAL
3530 else if (wp->w_p_cole > 0 && is_concealing)
3531 {
3532 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003533 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003534 if (wlv.n_extra > 0)
3535 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 if (wp->w_p_wrap)
3537 {
3538 // Special voodoo required if 'wrap' is on.
3539 //
3540 // Advance the column indicator to force the line
3541 // drawing to wrap early. This will make the line
3542 // take up the same screen space when parts are concealed,
3543 // so that cursor line computations aren't messed up.
3544 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 // trailing junk to be written out of the screen line
3547 // we are building, 'boguscols' keeps track of the number
3548 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003549 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003551 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552# ifdef FEAT_RIGHTLEFT
3553 if (wp->w_p_rl)
3554 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003555 wlv.col -= wlv.n_extra;
3556 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 }
3558 else
3559# endif
3560 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 wlv.col += wlv.n_extra;
3562 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003564 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 n_attr = 0;
3566 }
3567
3568
3569 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3570 {
3571 // Need to fill two screen columns.
3572# ifdef FEAT_RIGHTLEFT
3573 if (wp->w_p_rl)
3574 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 --wlv.boguscols;
3576 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 }
3578 else
3579# endif
3580 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 ++wlv.boguscols;
3582 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 }
3584 }
3585
3586# ifdef FEAT_RIGHTLEFT
3587 if (wp->w_p_rl)
3588 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 --wlv.boguscols;
3590 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 }
3592 else
3593# endif
3594 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003595 ++wlv.boguscols;
3596 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 }
3598 }
3599 else
3600 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003601 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003603 wlv.vcol += wlv.n_extra;
3604 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605 n_attr = 0;
3606 }
3607 }
3608
3609 }
3610#endif // FEAT_CONCEAL
3611 else
3612 --n_skip;
3613
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003614 // Only advance the "wlv.vcol" when after the 'number' or
3615 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003616 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003618 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619#endif
3620 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003621 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622
3623#ifdef FEAT_SYN_HL
3624 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003625 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626#endif
3627
3628 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003629 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3630 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631
3632 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003633 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003634 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003635 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003636 if (n_attr_skip > 0)
3637 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638
3639 // At end of screen line and there is more to come: Display the line
3640 // so far. If there is no more to display it is caught above.
3641 if ((
3642#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003644#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003646 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003647 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003649 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003651#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003652 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003653#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003654 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003655 && wlv.p_extra != at_end_str)
3656 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3657 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 )
3659 {
3660#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003661 screen_line(wp, wlv.screen_row, wp->w_wincol,
3662 wlv.col - wlv.boguscols,
3663 wp->w_width, wlv.screen_line_flags);
3664 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003666 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3667 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003669 ++wlv.row;
3670 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003671
3672 // When not wrapping and finished diff lines, or when displayed
3673 // '$' and highlighting until last column, break here.
3674 if ((!wp->w_p_wrap
3675#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003676 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003677#endif
3678#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003679 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#endif
3681 ) || lcs_eol_one == -1)
3682 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003683#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003684 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003685 {
3686 // do not output more of the line, only the "below" prop
3687 ptr += STRLEN(ptr);
3688# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003689 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003690# endif
3691 }
3692#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003693
3694 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003695 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003697 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698#endif
3699 )
3700 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003701 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3702 draw_vsep_win(wp, wlv.row);
3703 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 }
3705
3706 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003709 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710 break;
3711 }
3712
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003715 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003717#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003718 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003719#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 && wp->w_width == Columns)
3721 {
3722 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003723 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724
3725 // Special trick to make copy/paste of wrapped lines work with
3726 // xterm/screen: write an extra character beyond the end of
3727 // the line. This will work with all terminal types
3728 // (regardless of the xn,am settings).
3729 // Only do this on a fast tty.
3730 // Only do this if the cursor is on the current line
3731 // (something has been written in it).
3732 // Don't do this for the GUI.
3733 // Don't do this for double-width characters.
3734 // Don't do this for a window not at the right screen border.
3735 if (p_tf
3736#ifdef FEAT_GUI
3737 && !gui.in_use
3738#endif
3739 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3741 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 || (*mb_off2cells)(
3744 LineOffset[wlv.screen_row - 1]
3745 + (int)Columns - 2,
3746 LineOffset[wlv.screen_row]
3747 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748 {
3749 // First make sure we are at the end of the screen line,
3750 // then output the same character again to let the
3751 // terminal know about the wrap. If the terminal doesn't
3752 // auto-wrap, we overwrite the character.
3753 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003754 screen_char(LineOffset[wlv.screen_row - 1]
3755 + (unsigned)Columns - 1,
3756 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757
3758 // When there is a multi-byte character, just output a
3759 // space to keep it simple.
3760 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003761 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762 out_char(' ');
3763 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003764 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765 + (Columns - 1)]);
3766 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003767 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 screen_start(); // don't know where cursor is now
3769 }
3770 }
3771
Bram Moolenaar1306b362022-08-06 15:59:06 +01003772 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773
Bram Moolenaareed9d462021-02-15 20:38:25 +01003774 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003776 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003778 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003780 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003781 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782#endif
3783#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003784 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785 // When the filler lines are actually below the last line of the
3786 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003787 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 break;
3789#endif
3790 }
3791
3792 } // for every character in the line
3793
3794#ifdef FEAT_SPELL
3795 // After an empty line check first word for capital.
3796 if (*skipwhite(line) == NUL)
3797 {
3798 capcol_lnum = lnum + 1;
3799 cap_col = 0;
3800 }
3801#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003802#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803 vim_free(text_props);
3804 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003805 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806#endif
3807
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003808 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003809 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810}